Add a ResourceConstraint for the embedder to specify that V8 is running on a...

Add a ResourceConstraint for the embedder to specify that V8 is running on a memory constrained device.

This enables us to specialize certain operations such that we limit memory
usage on low-memory devices, without reducing performance on devices which
are not memory constrained.

BUG=chromium:280984
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/23464022

Patch from Ross McIlroy <rmcilroy@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16608 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d9bc6f70
...@@ -3763,11 +3763,20 @@ class V8_EXPORT ResourceConstraints { ...@@ -3763,11 +3763,20 @@ class V8_EXPORT ResourceConstraints {
uint32_t* stack_limit() const { return stack_limit_; } uint32_t* stack_limit() const { return stack_limit_; }
// Sets an address beyond which the VM's stack may not grow. // Sets an address beyond which the VM's stack may not grow.
void set_stack_limit(uint32_t* value) { stack_limit_ = value; } void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
Maybe<bool> is_memory_constrained() const { return is_memory_constrained_; }
// If set to true, V8 will limit it's memory usage, at the potential cost of
// lower performance. Note, this option is a tentative addition to the API
// and may be removed or modified without warning.
void set_memory_constrained(bool value) {
is_memory_constrained_ = Maybe<bool>(value);
}
private: private:
int max_young_space_size_; int max_young_space_size_;
int max_old_space_size_; int max_old_space_size_;
int max_executable_size_; int max_executable_size_;
uint32_t* stack_limit_; uint32_t* stack_limit_;
Maybe<bool> is_memory_constrained_;
}; };
......
...@@ -624,7 +624,8 @@ ResourceConstraints::ResourceConstraints() ...@@ -624,7 +624,8 @@ ResourceConstraints::ResourceConstraints()
: max_young_space_size_(0), : max_young_space_size_(0),
max_old_space_size_(0), max_old_space_size_(0),
max_executable_size_(0), max_executable_size_(0),
stack_limit_(NULL) { } stack_limit_(NULL),
is_memory_constrained_() { }
bool SetResourceConstraints(ResourceConstraints* constraints) { bool SetResourceConstraints(ResourceConstraints* constraints) {
...@@ -645,6 +646,10 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { ...@@ -645,6 +646,10 @@ bool SetResourceConstraints(ResourceConstraints* constraints) {
uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
isolate->stack_guard()->SetStackLimit(limit); isolate->stack_guard()->SetStackLimit(limit);
} }
if (constraints->is_memory_constrained().has_value) {
isolate->set_is_memory_constrained(
constraints->is_memory_constrained().value);
}
return true; return true;
} }
......
...@@ -1128,6 +1128,13 @@ class Isolate { ...@@ -1128,6 +1128,13 @@ class Isolate {
// Given an address occupied by a live code object, return that object. // Given an address occupied by a live code object, return that object.
Object* FindCodeObject(Address a); Object* FindCodeObject(Address a);
bool is_memory_constrained() const {
return is_memory_constrained_;
}
void set_is_memory_constrained(bool value) {
is_memory_constrained_ = value;
}
private: private:
Isolate(); Isolate();
...@@ -1299,6 +1306,7 @@ class Isolate { ...@@ -1299,6 +1306,7 @@ class Isolate {
DateCache* date_cache_; DateCache* date_cache_;
unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_; unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_;
CodeStubInterfaceDescriptor* code_stub_interface_descriptors_; CodeStubInterfaceDescriptor* code_stub_interface_descriptors_;
bool is_memory_constrained_;
// True if fatal error has been signaled for this isolate. // True if fatal error has been signaled for this isolate.
bool has_fatal_error_; bool has_fatal_error_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment