From 8db737a58302d90b414d572953fe8cdb0dddc452 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Wed, 13 Mar 2013 13:15:09 +0000 Subject: [PATCH] Made AdjustAmountOfExternalAllocatedMemory an instance method of Isolate 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 | 31 +++++++++++++++++-------------- src/api.cc | 11 +++++++++-- src/d8.cc | 6 +++--- test/cctest/test-api.cc | 5 +++-- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/include/v8.h b/include/v8.h index 7016cb5..bfc56f1 100644 --- a/include/v8.h +++ b/include/v8.h @@ -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); diff --git a/src/api.cc b/src/api.cc index 4ec3936..9441810 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5783,14 +5783,21 @@ void V8::AddImplicitReferences(Persistent parent, } +intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory( + intptr_t change_in_bytes) { + i::Heap* heap = reinterpret_cast(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); + return isolate_ext->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); } diff --git a/src/d8.cc b/src/d8.cc index 24c89e9..5010acb 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -389,7 +389,7 @@ Handle Shell::CreateExternalArrayBuffer(Isolate* isolate, Persistent::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(data); object.Dispose(isolate); } @@ -1446,7 +1446,7 @@ Handle Shell::ReadBuffer(const Arguments& args) { Persistent::New(isolate, buffer); persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); persistent_buffer.MarkIndependent(isolate); - V8::AdjustAmountOfExternalAllocatedMemory(length); + isolate->AdjustAmountOfExternalAllocatedMemory(length); buffer->SetIndexedPropertiesToExternalArrayData( data, kExternalUnsignedByteArray, length); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index f6bee09..8a25432 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -11861,9 +11861,10 @@ THREADED_TEST(ExternalAllocatedMemory) { v8::Persistent 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)); } -- 2.7.4