Reviewers: Sven Panne,

Message:
Hi Sven, could you please review this change. An example of how this flag will
be used is in https://codereview.chromium.org/23480031/.

Description:
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

Please review this at https://codereview.chromium.org/23464022/

SVN Base: https://v8.googlecode.com/svn/trunk

Affected files:
  M include/v8.h
  M src/api.cc
  M src/isolate.h


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index eb166ab68d2e53745f8659ae1c1648785488d215..6d5f00dc952bcc5802158d731f46c5e140930fd4 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3763,11 +3763,16 @@ class V8EXPORT ResourceConstraints {
   uint32_t* stack_limit() const { return stack_limit_; }
   // Sets an address beyond which the VM's stack may not grow.
   void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
+  bool is_memory_constrained() { return is_memory_constrained_; }
+ // If set to true, V8 will limit it's memory usage, at the potential cost of
+  // lower performance.
+ void set_memory_constrained(bool value) { is_memory_constrained_ = value; }
  private:
   int max_young_space_size_;
   int max_old_space_size_;
   int max_executable_size_;
   uint32_t* stack_limit_;
+  bool is_memory_constrained_;
 };


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index d587b81fd3461202a807bcdd0b68ab7f25f6d5a4..6cfea2a3484157384ad71a7d20f746407b0347d5 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -620,7 +620,8 @@ ResourceConstraints::ResourceConstraints()
   : max_young_space_size_(0),
     max_old_space_size_(0),
     max_executable_size_(0),
-    stack_limit_(NULL) { }
+    stack_limit_(NULL),
+    is_memory_constrained_(false) { }


 bool SetResourceConstraints(ResourceConstraints* constraints) {
@@ -641,6 +642,7 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
     isolate->stack_guard()->SetStackLimit(limit);
   }
+  isolate->setIsMemoryConstrained(constraints->is_memory_constrained());
   return true;
 }

Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index c0083177373e0afcd5f899cb92d46e236936dd59..b80f46c3fc54d8a991a88896706a4250f553290d 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -1138,6 +1138,13 @@ class Isolate {
   // Given an address occupied by a live code object, return that object.
   Object* FindCodeObject(Address a);

+  bool isMemoryConstrained() {
+    return is_memory_constrained_;
+  }
+  void setIsMemoryConstrained(bool value) {
+    is_memory_constrained_ = value;
+  }
+
  private:
   Isolate();

@@ -1313,6 +1320,7 @@ class Isolate {
   DateCache* date_cache_;
unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_;
   CodeStubInterfaceDescriptor* code_stub_interface_descriptors_;
+  bool is_memory_constrained_;

   // The garbage collector should be a little more aggressive when it knows
   // that a context was recently exited.


--
--
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.

Reply via email to