Made AdjustAmountOfExternalAllocatedMemory an instance method of Isolate
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 13 Mar 2013 13:15:09 +0000 (13:15 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 13 Mar 2013 13:15:09 +0000 (13:15 +0000)
BUG=v8:2487

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13933 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc
src/d8.cc
test/cctest/test-api.cc

index 7016cb5..bfc56f1 100644 (file)
@@ -3007,6 +3007,21 @@ class V8EXPORT Isolate {
    */
   void GetHeapStatistics(HeapStatistics* heap_statistics);
 
+  /**
+   * Adjusts the amount of registered external memory. Used to give V8 an
+   * indication of the amount of externally allocated memory that is kept alive
+   * by JavaScript objects. V8 uses this to decide when to perform global
+   * garbage collections. Registering externally allocated memory will trigger
+   * global garbage collections more often than it would otherwise in an attempt
+   * to garbage collect the JavaScript objects that keep the externally
+   * allocated memory alive.
+   *
+   * \param change_in_bytes the change in externally allocated memory that is
+   *   kept alive by JavaScript objects.
+   * \returns the adjusted value.
+   */
+  intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
+
  private:
   Isolate();
   Isolate(const Isolate&);
@@ -3487,20 +3502,8 @@ class V8EXPORT V8 {
   static void SetJitCodeEventHandler(JitCodeEventOptions options,
                                      JitCodeEventHandler event_handler);
 
-  /**
-   * Adjusts the amount of registered external memory.  Used to give
-   * V8 an indication of the amount of externally allocated memory
-   * that is kept alive by JavaScript objects.  V8 uses this to decide
-   * when to perform global garbage collections.  Registering
-   * externally allocated memory will trigger global garbage
-   * collections more often than otherwise in an attempt to garbage
-   * collect the JavaScript objects keeping the externally allocated
-   * memory alive.
-   *
-   * \param change_in_bytes the change in externally allocated memory
-   *   that is kept alive by JavaScript objects.
-   * \returns the adjusted value.
-   */
+  // TODO(svenpanne) Really deprecate me when Chrome is fixed.
+  /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */
   static intptr_t AdjustAmountOfExternalAllocatedMemory(
       intptr_t change_in_bytes);
 
index 4ec3936..9441810 100644 (file)
@@ -5783,14 +5783,21 @@ void V8::AddImplicitReferences(Persistent<Object> parent,
 }
 
 
+intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory(
+    intptr_t change_in_bytes) {
+  i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
+  return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
+}
+
+
 intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) {
   i::Isolate* isolate = i::Isolate::UncheckedCurrent();
   if (isolate == NULL || !isolate->IsInitialized() ||
       IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
     return 0;
   }
-  return isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
-      change_in_bytes);
+  Isolate* isolate_ext = reinterpret_cast<Isolate*>(isolate);
+  return isolate_ext->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
 }
 
 
index 24c89e9..5010acb 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -389,7 +389,7 @@ Handle<Value> Shell::CreateExternalArrayBuffer(Isolate* isolate,
       Persistent<Object>::New(isolate, buffer);
   persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback);
   persistent_array.MarkIndependent(isolate);
-  V8::AdjustAmountOfExternalAllocatedMemory(length);
+  isolate->AdjustAmountOfExternalAllocatedMemory(length);
 
   buffer->SetIndexedPropertiesToExternalArrayData(
       data, v8::kExternalByteArray, length);
@@ -830,7 +830,7 @@ void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
   HandleScope scope;
   int32_t length =
       object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value();
-  V8::AdjustAmountOfExternalAllocatedMemory(-length);
+  isolate->AdjustAmountOfExternalAllocatedMemory(-length);
   delete[] static_cast<uint8_t*>(data);
   object.Dispose(isolate);
 }
@@ -1446,7 +1446,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) {
       Persistent<Object>::New(isolate, buffer);
   persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback);
   persistent_buffer.MarkIndependent(isolate);
-  V8::AdjustAmountOfExternalAllocatedMemory(length);
+  isolate->AdjustAmountOfExternalAllocatedMemory(length);
 
   buffer->SetIndexedPropertiesToExternalArrayData(
       data, kExternalUnsignedByteArray, length);
index f6bee09..8a25432 100644 (file)
@@ -11861,9 +11861,10 @@ THREADED_TEST(ExternalAllocatedMemory) {
   v8::Persistent<Context> env(Context::New());
   CHECK(!env.IsEmpty());
   const intptr_t kSize = 1024*1024;
-  CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)),
+  v8::Isolate* isolate = env->GetIsolate();
+  CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)),
            cast(kSize));
-  CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize)),
+  CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize)),
            cast(0));
 }