Reviewers: Hannes Payer,
Description:
Lower heap space size limits if is_memory_constrained().
BUG=292928
Please review this at https://codereview.chromium.org/24269003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+50, -21 lines):
M src/api.cc
M src/heap.h
M src/heap.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
0a38fa9f32b2b3e3932a178d756c80b44b1a0c1e..00147c3b3255195ac5e17335c21baa6a8fdfc72d
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -609,10 +609,19 @@ ResourceConstraints::ResourceConstraints()
bool SetResourceConstraints(ResourceConstraints* constraints) {
i::Isolate* isolate = EnterIsolateIfNeeded();
+ bool changed_memory_constrained = false;
+ if (constraints->is_memory_constrained().has_value &&
+ !i::FLAG_force_memory_constrained.has_value) {
+ isolate->set_is_memory_constrained(
+ constraints->is_memory_constrained().value);
+ changed_memory_constrained = true;
+ }
+
int young_space_size = constraints->max_young_space_size();
int old_gen_size = constraints->max_old_space_size();
int max_executable_size = constraints->max_executable_size();
- if (young_space_size != 0 || old_gen_size != 0 || max_executable_size !=
0) {
+ if (young_space_size != 0 || old_gen_size != 0 || max_executable_size !=
0 ||
+ changed_memory_constrained) {
// After initialization it's too late to change Heap constraints.
ASSERT(!isolate->IsInitialized());
bool result = isolate->heap()->ConfigureHeap(young_space_size / 2,
@@ -624,11 +633,6 @@ bool SetResourceConstraints(ResourceConstraints*
constraints) {
uintptr_t limit =
reinterpret_cast<uintptr_t>(constraints->stack_limit());
isolate->stack_guard()->SetStackLimit(limit);
}
- if (constraints->is_memory_constrained().has_value &&
- !i::FLAG_force_memory_constrained.has_value) {
- isolate->set_is_memory_constrained(
- constraints->is_memory_constrained().value);
- }
return true;
}
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
23b7c89c4eace42a55d398bdf6ee9e68dbeab15d..f5f5d04602df5253e03fd802b8abdef74642505e
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -65,31 +65,36 @@ namespace v8 {
namespace internal {
-Heap::Heap()
- : isolate_(NULL),
// semispace_size_ should be a power of 2 and old_generation_size_ should
be
// a multiple of Page::kPageSize.
#if V8_TARGET_ARCH_X64
#define LUMP_OF_MEMORY (2 * MB)
- code_range_size_(512*MB),
#else
#define LUMP_OF_MEMORY MB
- code_range_size_(0),
#endif
#if defined(ANDROID) || V8_TARGET_ARCH_MIPS
- reserved_semispace_size_(4 * Max(LUMP_OF_MEMORY, Page::kPageSize)),
- max_semispace_size_(4 * Max(LUMP_OF_MEMORY, Page::kPageSize)),
- initial_semispace_size_(Page::kPageSize),
- max_old_generation_size_(192*MB),
- max_executable_size_(max_old_generation_size_),
+#define DEFAULT_SEMISPACE_MAX_SIZE (4 * Max(LUMP_OF_MEMORY,
Page::kPageSize))
+#define DEFAULT_OLD_GENERATION_MAX_SIZE (192*MB)
+#define DEFAULT_EXECUTABLE_MAX_SIZE (192*MB)
#else
- reserved_semispace_size_(8 * Max(LUMP_OF_MEMORY, Page::kPageSize)),
- max_semispace_size_(8 * Max(LUMP_OF_MEMORY, Page::kPageSize)),
- initial_semispace_size_(Page::kPageSize),
- max_old_generation_size_(700ul * LUMP_OF_MEMORY),
- max_executable_size_(256l * LUMP_OF_MEMORY),
+#define DEFAULT_SEMISPACE_MAX_SIZE (8 * Max(LUMP_OF_MEMORY,
Page::kPageSize))
+#define DEFAULT_OLD_GENERATION_MAX_SIZE (700ul * LUMP_OF_MEMORY)
+#define DEFAULT_EXECUTABLE_MAX_SIZE (256l * LUMP_OF_MEMORY)
#endif
+
+Heap::Heap()
+ : isolate_(NULL),
+#if V8_TARGET_ARCH_X64
+ code_range_size_(512*MB),
+#else
+ code_range_size_(0),
+#endif
+ reserved_semispace_size_(DEFAULT_SEMISPACE_MAX_SIZE),
+ max_semispace_size_(DEFAULT_SEMISPACE_MAX_SIZE),
+ initial_semispace_size_(Page::kPageSize),
+ max_old_generation_size_(DEFAULT_OLD_GENERATION_MAX_SIZE),
+ max_executable_size_(DEFAULT_EXECUTABLE_MAX_SIZE),
// Variables set based on semispace_size_ and old_generation_size_ in
// ConfigureHeap (survived_since_last_expansion_,
external_allocation_limit_)
// Will be 4 * reserved_semispace_size_ to ensure that young
@@ -161,6 +166,7 @@ Heap::Heap()
#endif
promotion_queue_(this),
configured_(false),
+ limits_changed_from_defaults_(false),
chunks_queued_for_free_(NULL),
relocation_mutex_(NULL) {
// Allow build-time customization of the max semispace size. Building
@@ -169,7 +175,6 @@ Heap::Heap()
#if defined(V8_MAX_SEMISPACE_SIZE)
max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE;
#endif
-
intptr_t max_virtual = OS::MaxVirtualMemory();
if (max_virtual > 0) {
@@ -6673,6 +6678,16 @@ bool Heap::ConfigureHeap(int max_semispace_size,
intptr_t max_executable_size) {
if (HasBeenSetUp()) return false;
+ if (isolate_->is_memory_constrained() && !limits_changed_from_defaults_)
{
+ // Update the default values if this is a memory constrained device.
+ // TODO(rmcilroy): Ideally these should be set correctly in the
constructor
+ // based on this flag, but the flag isn't setup correctly at that
point.
+ max_semispace_size_ = DEFAULT_SEMISPACE_MAX_SIZE / 4;
+ reserved_semispace_size_ = DEFAULT_SEMISPACE_MAX_SIZE / 4;
+ max_old_generation_size_ = DEFAULT_OLD_GENERATION_MAX_SIZE / 2;
+ max_executable_size_ = DEFAULT_EXECUTABLE_MAX_SIZE / 2;
+ }
+
if (FLAG_stress_compaction) {
// This will cause more frequent GCs when stressing.
max_semispace_size_ = Page::kPageSize;
@@ -6713,6 +6728,12 @@ bool Heap::ConfigureHeap(int max_semispace_size,
max_executable_size_ = RoundUp(max_executable_size, Page::kPageSize);
}
+ if (max_semispace_size > 0 || max_old_gen_size > 0 ||
+ max_executable_size_ > 0) {
+ // Did we change anything from their defaults.
+ limits_changed_from_defaults_ = true;
+ }
+
// The max executable size must be less than or equal to the max old
// generation size.
if (max_executable_size_ > max_old_generation_size_) {
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
fd361fc7a4655709385ab0f560b750caf8990c8a..c98237a1f59c4bdb575478542be1d52cde5529e1
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -2337,6 +2337,10 @@ class Heap {
// configured through the API until it is set up.
bool configured_;
+ // Flag is set if the heap has been configured with any value different
from
+ // the default values.
+ bool limits_changed_from_defaults_;
+
ExternalStringTable external_string_table_;
VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_;
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.