Don't create Static memories larger than the Tunables' static bound size.

This commit is contained in:
Dan Gohman
2018-12-24 21:57:43 -08:00
parent 57a1618742
commit f997cde2db

View File

@@ -54,22 +54,23 @@ impl MemoryStyle {
/// Decide on an implementation style for the given `Memory`. /// Decide on an implementation style for the given `Memory`.
pub fn for_memory(memory: Memory, tunables: &Tunables) -> (Self, u64) { pub fn for_memory(memory: Memory, tunables: &Tunables) -> (Self, u64) {
if let Some(maximum) = memory.maximum { if let Some(maximum) = memory.maximum {
// A heap with a declared maximum is prepared to be used with if maximum <= tunables.static_memory_bound {
// threads and therefore be immovable, so make it static. // A heap with a declared maximum can be immovable, so make
( // it static.
MemoryStyle::Static { return (
bound: cmp::max(tunables.static_memory_bound, maximum), MemoryStyle::Static {
}, bound: tunables.static_memory_bound,
tunables.static_memory_offset_guard_size, },
) tunables.static_memory_offset_guard_size,
} else { );
// A heap without a declared maximum is likely to want to be small }
// at least some of the time, so make it dynamic.
(
MemoryStyle::Dynamic,
tunables.dynamic_memory_offset_guard_size,
)
} }
// Otherwise, make it dynamic.
(
MemoryStyle::Dynamic,
tunables.dynamic_memory_offset_guard_size,
)
} }
} }