From 9ba5fe028f5420012cd161820ff0a6fa0e1e8a68 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 29 Apr 2015 02:54:34 -0700 Subject: [PATCH] Pass ArrayBuffer::Allocator via Isolate::CreateParams We shouldn't have shared state between isolates by default. The embedder is free to pass the same allocator to all isolates it creates. BUG=none R=dcarney@chromium.org LOG=y Review URL: https://codereview.chromium.org/1116633002 Cr-Commit-Position: refs/heads/master@{#28127} --- include/v8.h | 25 +++++++--- samples/process.cc | 7 +-- samples/shell.cc | 5 +- src/api.cc | 28 +++++++++++ src/bootstrapper.cc | 2 +- src/d8.cc | 74 ++++++++++++++++------------- src/extensions/free-buffer-extension.cc | 4 +- src/isolate.h | 11 ++++- src/runtime/runtime-typedarray.cc | 16 +++---- src/snapshot/mksnapshot.cc | 13 ----- test/cctest/cctest.cc | 7 ++- test/cctest/cctest.h | 10 ++++ test/cctest/test-api.cc | 50 ++++++++++++++----- test/cctest/test-debug.cc | 8 +++- test/cctest/test-deoptimization.cc | 36 ++++++++++---- test/cctest/test-heap.cc | 12 +++-- test/cctest/test-lockers.cc | 45 +++++++++++++----- test/cctest/test-log.cc | 68 ++++++++++++++------------ test/cctest/test-mark-compact.cc | 4 +- test/cctest/test-microtask-delivery.cc | 4 +- test/cctest/test-random-number-generator.cc | 4 +- test/cctest/test-serialize.cc | 35 ++++++++++---- test/cctest/test-spaces.cc | 4 +- test/cctest/test-strings.cc | 1 + test/cctest/test-typedarrays.cc | 4 +- test/unittests/run-all-unittests.cc | 12 ----- test/unittests/test-utils.cc | 20 +++++++- test/unittests/test-utils.h | 3 ++ tools/parser-shell.cc | 7 +-- 29 files changed, 349 insertions(+), 170 deletions(-) diff --git a/include/v8.h b/include/v8.h index 208b557..89c9042 100644 --- a/include/v8.h +++ b/include/v8.h @@ -3236,8 +3236,8 @@ class V8_EXPORT ArrayBuffer : public Object { public: /** * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. - * The allocator is a global V8 setting. It should be set with - * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. + * The allocator is a global V8 setting. It has to be set via + * Isolate::CreateParams. * * This API is experimental and may change significantly. */ @@ -3269,7 +3269,7 @@ class V8_EXPORT ArrayBuffer : public Object { * and byte length. * * The Data pointer of ArrayBuffer::Contents is always allocated with - * Allocator::Allocate that is set with V8::SetArrayBufferAllocator. + * Allocator::Allocate that is set via Isolate::CreateParams. * * This API is experimental and may change significantly. */ @@ -3337,7 +3337,7 @@ class V8_EXPORT ArrayBuffer : public Object { * should take steps to free memory when it is no longer needed. * * The memory block is guaranteed to be allocated with |Allocator::Allocate| - * that has been set with V8::SetArrayBufferAllocator. + * that has been set via Isolate::CreateParams. */ Contents Externalize(); @@ -4953,7 +4953,8 @@ class V8_EXPORT Isolate { snapshot_blob(NULL), counter_lookup_callback(NULL), create_histogram_callback(NULL), - add_histogram_sample_callback(NULL) {} + add_histogram_sample_callback(NULL), + array_buffer_allocator(NULL) {} /** * The optional entry_hook allows the host application to provide the @@ -4995,6 +4996,12 @@ class V8_EXPORT Isolate { */ CreateHistogramCallback create_histogram_callback; AddHistogramSampleCallback add_histogram_sample_callback; + + /** + * The ArrayBuffer::Allocator to use for allocating and freeing the backing + * store of ArrayBuffers. + */ + ArrayBuffer::Allocator* array_buffer_allocator; }; @@ -5114,7 +5121,9 @@ class V8_EXPORT Isolate { * * V8::Initialize() must have run prior to this. */ - static Isolate* New(const CreateParams& params = CreateParams()); + static Isolate* New(const CreateParams& params); + + static V8_DEPRECATED("Always pass CreateParams", Isolate* New()); /** * Returns the entered isolate for the current thread or NULL in @@ -5704,7 +5713,9 @@ class V8_EXPORT V8 { * before any code tha uses ArrayBuffers is executed. * This allocator is used in all isolates. */ - static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator); + static V8_DEPRECATE_SOON( + "Use isolate version", + void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator)); /** * Check if V8 is dead and therefore unusable. This is the case after diff --git a/samples/process.cc b/samples/process.cc index 5f74b44..8d1cebe 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -662,8 +662,6 @@ int main(int argc, char* argv[]) { v8::V8::InitializeICU(); v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); - ArrayBufferAllocator array_buffer_allocator; - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); v8::V8::Initialize(); map options; string file; @@ -672,7 +670,10 @@ int main(int argc, char* argv[]) { fprintf(stderr, "No script was specified.\n"); return 1; } - Isolate* isolate = Isolate::New(); + ArrayBufferAllocator array_buffer_allocator; + Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &array_buffer_allocator; + Isolate* isolate = Isolate::New(create_params); Isolate::Scope isolate_scope(isolate); HandleScope scope(isolate); Handle source = ReadFile(isolate, file); diff --git a/samples/shell.cc b/samples/shell.cc index a061aa4..48c042c 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -82,8 +82,9 @@ int main(int argc, char* argv[]) { v8::V8::Initialize(); v8::V8::SetFlagsFromCommandLine(&argc, argv, true); ShellArrayBufferAllocator array_buffer_allocator; - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &array_buffer_allocator; + v8::Isolate* isolate = v8::Isolate::New(create_params); run_shell = (argc == 1); int result; { diff --git a/src/api.cc b/src/api.cc index ab57ce2..de0b007 100644 --- a/src/api.cc +++ b/src/api.cc @@ -320,8 +320,25 @@ bool RunExtraCode(Isolate* isolate, const char* utf8_source) { } +namespace { + +class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + virtual void* Allocate(size_t length) { + void* data = AllocateUninitialized(length); + return data == NULL ? data : memset(data, 0, length); + } + virtual void* AllocateUninitialized(size_t length) { return malloc(length); } + virtual void Free(void* data, size_t) { free(data); } +}; + +} // namespace + + StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { i::Isolate* internal_isolate = new i::Isolate(true); + ArrayBufferAllocator allocator; + internal_isolate->set_array_buffer_allocator(&allocator); Isolate* isolate = reinterpret_cast(internal_isolate); StartupData result = {NULL, 0}; { @@ -6742,9 +6759,20 @@ Isolate* Isolate::GetCurrent() { } +Isolate* Isolate::New() { + Isolate::CreateParams create_params; + return New(create_params); +} + + Isolate* Isolate::New(const Isolate::CreateParams& params) { i::Isolate* isolate = new i::Isolate(false); Isolate* v8_isolate = reinterpret_cast(isolate); + if (params.array_buffer_allocator != NULL) { + isolate->set_array_buffer_allocator(params.array_buffer_allocator); + } else { + isolate->set_array_buffer_allocator(i::V8::ArrayBufferAllocator()); + } if (params.snapshot_blob != NULL) { isolate->set_snapshot_blob(params.snapshot_blob); } else { diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 1658d64..2c5e9a8 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1606,7 +1606,7 @@ Data* SetBuiltinTypedArray(Isolate* isolate, Handle builtins, bool is_external = data != nullptr; if (!is_external) { data = reinterpret_cast( - V8::ArrayBufferAllocator()->Allocate(byte_length)); + isolate->array_buffer_allocator()->Allocate(byte_length)); } Runtime::SetupArrayBuffer(isolate, buffer, is_external, data, byte_length); diff --git a/src/d8.cc b/src/d8.cc index ff6e1d3..75bbf1d 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -73,7 +73,37 @@ namespace v8 { namespace { + +const int MB = 1024 * 1024; + + +class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + virtual void* Allocate(size_t length) { + void* data = AllocateUninitialized(length); + return data == NULL ? data : memset(data, 0, length); + } + virtual void* AllocateUninitialized(size_t length) { return malloc(length); } + virtual void Free(void* data, size_t) { free(data); } +}; + + +class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + void* Allocate(size_t length) override { + size_t actual_length = length > 10 * MB ? 1 : length; + void* data = AllocateUninitialized(actual_length); + return data == NULL ? data : memset(data, 0, actual_length); + } + void* AllocateUninitialized(size_t length) override { + return length > 10 * MB ? malloc(1) : malloc(length); + } + void Free(void* p, size_t) override { free(p); } +}; + + v8::Platform* g_platform = NULL; + } // namespace @@ -166,7 +196,6 @@ Persistent Shell::utility_context_; Persistent Shell::evaluation_context_; ShellOptions Shell::options; const char* Shell::kPrompt = "d8> "; -const int MB = 1024 * 1024; #ifndef V8_SHARED bool CounterMap::Match(void* key1, void* key2) { @@ -197,7 +226,10 @@ ScriptCompiler::CachedData* CompileForCachedData( name_buffer = new uint16_t[name_length]; name_string->Write(name_buffer, 0, name_length); } - Isolate* temp_isolate = Isolate::New(); + ShellArrayBufferAllocator allocator; + Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &allocator; + Isolate* temp_isolate = Isolate::New(create_params); ScriptCompiler::CachedData* result = NULL; { Isolate::Scope isolate_scope(temp_isolate); @@ -1287,7 +1319,10 @@ base::Thread::Options SourceGroup::GetThreadOptions() { void SourceGroup::ExecuteInThread() { - Isolate* isolate = Isolate::New(); + ShellArrayBufferAllocator allocator; + Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &allocator; + Isolate* isolate = Isolate::New(create_params); do { next_semaphore_.Wait(); { @@ -1584,31 +1619,6 @@ static void DumpHeapConstants(i::Isolate* isolate) { #endif // !V8_SHARED -class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - virtual void* Allocate(size_t length) { - void* data = AllocateUninitialized(length); - return data == NULL ? data : memset(data, 0, length); - } - virtual void* AllocateUninitialized(size_t length) { return malloc(length); } - virtual void Free(void* data, size_t) { free(data); } -}; - - -class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - void* Allocate(size_t length) override { - size_t actual_length = length > 10 * MB ? 1 : length; - void* data = AllocateUninitialized(actual_length); - return data == NULL ? data : memset(data, 0, actual_length); - } - void* AllocateUninitialized(size_t length) override { - return length > 10 * MB ? malloc(1) : malloc(length); - } - void Free(void* p, size_t) override { free(p); } -}; - - int Shell::Main(int argc, char* argv[]) { #if (defined(_WIN32) || defined(_WIN64)) UINT new_flags = @@ -1637,15 +1647,15 @@ int Shell::Main(int argc, char* argv[]) { SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); SetFlagsFromString("--redirect-code-traces-to=code.asm"); + int result = 0; + Isolate::CreateParams create_params; ShellArrayBufferAllocator array_buffer_allocator; MockArrayBufferAllocator mock_arraybuffer_allocator; if (options.mock_arraybuffer_allocator) { - v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); + create_params.array_buffer_allocator = &mock_arraybuffer_allocator; } else { - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); + create_params.array_buffer_allocator = &array_buffer_allocator; } - int result = 0; - Isolate::CreateParams create_params; #if !defined(V8_SHARED) && defined(ENABLE_GDB_JIT_INTERFACE) if (i::FLAG_gdbjit) { create_params.code_event_handler = i::GDBJITInterface::EventHandler; diff --git a/src/extensions/free-buffer-extension.cc b/src/extensions/free-buffer-extension.cc index e8c7732..c880d75 100644 --- a/src/extensions/free-buffer-extension.cc +++ b/src/extensions/free-buffer-extension.cc @@ -22,7 +22,9 @@ void FreeBufferExtension::FreeBuffer( const v8::FunctionCallbackInfo& args) { v8::Handle arrayBuffer = args[0].As(); v8::ArrayBuffer::Contents contents = arrayBuffer->Externalize(); - V8::ArrayBufferAllocator()->Free(contents.Data(), contents.ByteLength()); + Isolate* isolate = reinterpret_cast(args.GetIsolate()); + isolate->array_buffer_allocator()->Free(contents.Data(), + contents.ByteLength()); } } } // namespace v8::internal diff --git a/src/isolate.h b/src/isolate.h index ff03db8..b9f842e 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1114,8 +1114,6 @@ class Isolate { BasicBlockProfiler* GetOrCreateBasicBlockProfiler(); BasicBlockProfiler* basic_block_profiler() { return basic_block_profiler_; } - static Isolate* NewForTesting() { return new Isolate(false); } - std::string GetTurboCfgFileName(); #if TRACE_MAPS @@ -1145,6 +1143,13 @@ class Isolate { List* partial_snapshot_cache() { return &partial_snapshot_cache_; } + void set_array_buffer_allocator(v8::ArrayBuffer::Allocator* allocator) { + array_buffer_allocator_ = allocator; + } + v8::ArrayBuffer::Allocator* array_buffer_allocator() const { + return array_buffer_allocator_; + } + protected: explicit Isolate(bool enable_serializer); @@ -1369,6 +1374,8 @@ class Isolate { List partial_snapshot_cache_; + v8::ArrayBuffer::Allocator* array_buffer_allocator_; + friend class ExecutionAccess; friend class HandleScopeImplementer; friend class OptimizingCompileDispatcher; diff --git a/src/runtime/runtime-typedarray.cc b/src/runtime/runtime-typedarray.cc index 26e37ac..036ee41 100644 --- a/src/runtime/runtime-typedarray.cc +++ b/src/runtime/runtime-typedarray.cc @@ -22,9 +22,9 @@ void Runtime::FreeArrayBuffer(Isolate* isolate, reinterpret_cast(isolate) ->AdjustAmountOfExternalAllocatedMemory( -static_cast(allocated_length)); - CHECK(V8::ArrayBufferAllocator() != NULL); - V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store(), - allocated_length); + CHECK(isolate->array_buffer_allocator() != NULL); + isolate->array_buffer_allocator()->Free(phantom_array_buffer->backing_store(), + allocated_length); } @@ -67,15 +67,15 @@ bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, size_t allocated_length, bool initialize) { void* data; - CHECK(V8::ArrayBufferAllocator() != NULL); + CHECK(isolate->array_buffer_allocator() != NULL); // Prevent creating array buffers when serializing. DCHECK(!isolate->serializer_enabled()); if (allocated_length != 0) { if (initialize) { - data = V8::ArrayBufferAllocator()->Allocate(allocated_length); + data = isolate->array_buffer_allocator()->Allocate(allocated_length); } else { - data = - V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length); + data = isolate->array_buffer_allocator()->AllocateUninitialized( + allocated_length); } if (data == NULL) return false; } else { @@ -173,7 +173,7 @@ RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); array_buffer->set_is_external(true); Runtime::NeuterArrayBuffer(array_buffer); - V8::ArrayBufferAllocator()->Free(backing_store, byte_length); + isolate->array_buffer_allocator()->Free(backing_store, byte_length); return isolate->heap()->undefined_value(); } diff --git a/src/snapshot/mksnapshot.cc b/src/snapshot/mksnapshot.cc index 25ada29..f44eca5 100644 --- a/src/snapshot/mksnapshot.cc +++ b/src/snapshot/mksnapshot.cc @@ -109,17 +109,6 @@ class SnapshotWriter { }; -class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - virtual void* Allocate(size_t length) { - void* data = AllocateUninitialized(length); - return data == NULL ? data : memset(data, 0, length); - } - virtual void* AllocateUninitialized(size_t length) { return malloc(length); } - virtual void Free(void* data, size_t) { free(data); } -}; - - char* GetExtraCode(char* filename) { if (filename == NULL || strlen(filename) == 0) return NULL; ::printf("Embedding extra script: %s\n", filename); @@ -164,8 +153,6 @@ int main(int argc, char** argv) { V8::InitializeICU(); v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); - ArrayBufferAllocator array_buffer_allocator; - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); v8::V8::Initialize(); { diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index 08fb01b..b5771ff 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -52,6 +52,7 @@ static bool disable_automatic_dispose_ = false; CcTest* CcTest::last_ = NULL; bool CcTest::initialize_called_ = false; v8::base::Atomic32 CcTest::isolate_used_ = 0; +v8::ArrayBuffer::Allocator* CcTest::allocator_ = NULL; v8::Isolate* CcTest::isolate_ = NULL; @@ -88,7 +89,9 @@ void CcTest::Run() { CHECK(initialization_state_ != kUnintialized); initialization_state_ = kInitialized; if (isolate_ == NULL) { - isolate_ = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = allocator_; + isolate_ = v8::Isolate::New(create_params); } isolate_->Enter(); } @@ -175,7 +178,7 @@ int main(int argc, char* argv[]) { #endif CcTestArrayBufferAllocator array_buffer_allocator; - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); + CcTest::set_array_buffer_allocator(&array_buffer_allocator); i::PrintExtension print_extension; v8::RegisterExtension(&print_extension); diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h index 634552c..bade263 100644 --- a/test/cctest/cctest.h +++ b/test/cctest/cctest.h @@ -145,6 +145,15 @@ class CcTest { return isolate()->GetCurrentContext()->Global(); } + static v8::ArrayBuffer::Allocator* array_buffer_allocator() { + return allocator_; + } + + static void set_array_buffer_allocator( + v8::ArrayBuffer::Allocator* allocator) { + allocator_ = allocator; + } + // TODO(dcarney): Remove. // This must be called first in a test. static void InitializeVM() { @@ -178,6 +187,7 @@ class CcTest { bool initialize_; CcTest* prev_; static CcTest* last_; + static v8::ArrayBuffer::Allocator* allocator_; static v8::Isolate* isolate_; static bool initialize_called_; static v8::base::Atomic32 isolate_used_; diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 7fd75a2..f544288 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -12148,6 +12148,7 @@ void SetFunctionEntryHookTest::RunTest() { v8::Isolate::CreateParams create_params; create_params.entry_hook = EntryHook; create_params.code_event_handler = JitEvent; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); v8::Isolate* isolate = v8::Isolate::New(create_params); { @@ -12170,7 +12171,9 @@ void SetFunctionEntryHookTest::RunTest() { Reset(); // Make sure a second isolate is unaffected by the previous entry hook. - isolate = v8::Isolate::New(); + create_params = v8::Isolate::CreateParams(); + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope scope(isolate); @@ -12351,7 +12354,9 @@ UNINITIALIZED_TEST(SetJitCodeEventHandler) { // Run this test in a new isolate to make sure we don't // have remnants of state from other code. - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); isolate->Enter(); i::Isolate* i_isolate = reinterpret_cast(isolate); i::Heap* heap = i_isolate->heap(); @@ -12407,7 +12412,7 @@ UNINITIALIZED_TEST(SetJitCodeEventHandler) { isolate->Dispose(); // Do this in a new isolate. - isolate = v8::Isolate::New(); + isolate = v8::Isolate::New(create_params); isolate->Enter(); // Verify that we get callbacks for existing code objects when we @@ -15261,7 +15266,9 @@ TEST(VisitExternalStrings) { TEST(ExternalStringCollectedAtTearDown) { int destroyed = 0; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); const char* s = "One string to test them all, one string to find them."; @@ -15281,7 +15288,9 @@ TEST(ExternalStringCollectedAtTearDown) { TEST(ExternalInternalizedStringCollectedAtTearDown) { int destroyed = 0; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); LocalContext env(isolate); v8::HandleScope handle_scope(isolate); @@ -16522,7 +16531,9 @@ TEST(GCInFailedAccessCheckCallback) { TEST(IsolateNewDispose) { v8::Isolate* current_isolate = CcTest::isolate(); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); CHECK(isolate != NULL); CHECK(current_isolate != isolate); CHECK(current_isolate == CcTest::isolate()); @@ -16536,7 +16547,9 @@ TEST(IsolateNewDispose) { UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope scope(isolate); @@ -16555,7 +16568,9 @@ UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { static void BreakArrayGuarantees(const char* script) { - v8::Isolate* isolate1 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); isolate1->Enter(); v8::Persistent context1; { @@ -16604,7 +16619,9 @@ TEST(VerifyArrayPrototypeGuarantees) { TEST(RunTwoIsolatesOnSingleThread) { // Run isolate 1. - v8::Isolate* isolate1 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); isolate1->Enter(); v8::Persistent context1; { @@ -16623,7 +16640,7 @@ TEST(RunTwoIsolatesOnSingleThread) { } // Run isolate 2. - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); v8::Persistent context2; { @@ -16748,7 +16765,9 @@ class IsolateThread : public v8::base::Thread { : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {} void Run() { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); result_ = CalcFibonacci(isolate, fib_limit_); isolate->Dispose(); } @@ -16785,7 +16804,9 @@ TEST(MultipleIsolatesOnIndividualThreads) { TEST(IsolateDifferentContexts) { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); Local context; { v8::Isolate::Scope isolate_scope(isolate); @@ -16825,6 +16846,7 @@ class InitDefaultIsolateThread : public v8::base::Thread { void Run() { v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); switch (testCase_) { case SetResourceConstraints: { create_params.constraints.set_max_semi_space_size(1); @@ -18271,7 +18293,9 @@ TEST(StaticGetters) { UNINITIALIZED_TEST(IsolateEmbedderData) { CcTest::DisableAutomaticDispose(); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); isolate->Enter(); i::Isolate* i_isolate = reinterpret_cast(isolate); for (uint32_t slot = 0; slot < v8::Isolate::GetNumberOfDataSlots(); ++slot) { diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index 3b2437d..2f6cf6e 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -5236,7 +5236,9 @@ void V8Thread::Run() { "\n" "foo();\n"; - isolate_ = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + isolate_ = v8::Isolate::New(create_params); threaded_debugging_barriers.barrier_3.Wait(); { v8::Isolate::Scope isolate_scope(isolate_); @@ -5367,7 +5369,9 @@ void BreakpointsV8Thread::Run() { const char* source_2 = "cat(17);\n" "cat(19);\n"; - isolate_ = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + isolate_ = v8::Isolate::New(create_params); breakpoints_barriers->barrier_3.Wait(); { v8::Isolate::Scope isolate_scope(isolate_); diff --git a/test/cctest/test-deoptimization.cc b/test/cctest/test-deoptimization.cc index 2db5870..6742915 100644 --- a/test/cctest/test-deoptimization.cc +++ b/test/cctest/test-deoptimization.cc @@ -349,7 +349,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationADDString) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; AllowNativesSyntaxNoInlining options; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -451,7 +453,9 @@ static void TestDeoptimizeBinaryOpHelper(LocalContext* env, UNINITIALIZED_TEST(DeoptimizeBinaryOperationADD) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -472,7 +476,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationADD) { UNINITIALIZED_TEST(DeoptimizeBinaryOperationSUB) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -493,7 +499,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationSUB) { UNINITIALIZED_TEST(DeoptimizeBinaryOperationMUL) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -514,7 +522,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationMUL) { UNINITIALIZED_TEST(DeoptimizeBinaryOperationDIV) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -535,7 +545,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationDIV) { UNINITIALIZED_TEST(DeoptimizeBinaryOperationMOD) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -556,7 +568,9 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationMOD) { UNINITIALIZED_TEST(DeoptimizeCompare) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -611,7 +625,9 @@ UNINITIALIZED_TEST(DeoptimizeCompare) { UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { @@ -702,7 +718,9 @@ UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) { UNINITIALIZED_TEST(DeoptimizeLoadICStoreICNested) { i::FLAG_turbo_deoptimization = true; i::FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); { diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 906b4fe..7bc1a88 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -1018,7 +1018,9 @@ UNINITIALIZED_TEST(TestCodeFlushing) { if (!FLAG_flush_code) return; i::FLAG_allow_natives_syntax = true; i::FLAG_optimize_for_size = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); isolate->Enter(); Factory* factory = i_isolate->factory(); @@ -3684,7 +3686,9 @@ UNINITIALIZED_TEST(ReleaseStackTraceData) { } FLAG_use_ic = false; // ICs retain objects. FLAG_concurrent_recompilation = false; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); @@ -4997,7 +5001,9 @@ TEST(ArrayShiftSweeping) { UNINITIALIZED_TEST(PromotionQueue) { i::FLAG_expose_gc = true; i::FLAG_max_semi_space_size = 2 * (Page::kPageSize / MB); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::Isolate* i_isolate = reinterpret_cast(isolate); { v8::Isolate::Scope isolate_scope(isolate); diff --git a/test/cctest/test-lockers.cc b/test/cctest/test-lockers.cc index c53ac5c..c86a9d6 100644 --- a/test/cctest/test-lockers.cc +++ b/test/cctest/test-lockers.cc @@ -98,7 +98,9 @@ class KangarooThread : public v8::base::Thread { // Migrates an isolate from one thread to another TEST(KangarooIsolates) { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::SmartPointer thread1; { v8::Locker locker(isolate); @@ -216,7 +218,9 @@ TEST(IsolateLockingStress) { const int kNThreads = 100; #endif i::List threads(kNThreads); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); for (int i = 0; i < kNThreads; i++) { threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); } @@ -257,7 +261,9 @@ TEST(IsolateNestedLocking) { #else const int kNThreads = 100; #endif - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::List threads(kNThreads); for (int i = 0; i < kNThreads; i++) { threads.Add(new IsolateNestedLockingThread(isolate)); @@ -300,8 +306,10 @@ TEST(SeparateIsolatesLocksNonexclusive) { #else const int kNThreads = 100; #endif - v8::Isolate* isolate1 = v8::Isolate::New(); - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); i::List threads(kNThreads); for (int i = 0; i < kNThreads; i++) { threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, @@ -379,7 +387,9 @@ TEST(LockerUnlocker) { const int kNThreads = 100; #endif i::List threads(kNThreads); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); for (int i = 0; i < kNThreads; i++) { threads.Add(new LockerUnlockerThread(isolate)); } @@ -434,7 +444,9 @@ TEST(LockTwiceAndUnlock) { const int kNThreads = 100; #endif i::List threads(kNThreads); - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); for (int i = 0; i < kNThreads; i++) { threads.Add(new LockTwiceAndUnlockThread(isolate)); } @@ -496,8 +508,10 @@ class LockAndUnlockDifferentIsolatesThread : public JoinableThread { // Lock two isolates and unlock one of them. TEST(LockAndUnlockDifferentIsolates) { - v8::Isolate* isolate1 = v8::Isolate::New(); - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); thread.Start(); thread.Join(); @@ -556,7 +570,9 @@ TEST(LockUnlockLockMultithreaded) { #else const int kNThreads = 100; #endif - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); i::List threads(kNThreads); { v8::Locker locker_(isolate); @@ -631,7 +647,9 @@ TEST(LockUnlockLockDefaultIsolateMultithreaded) { TEST(Regress1433) { for (int i = 0; i < 10; i++) { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Locker lock(isolate); v8::Isolate::Scope isolate_scope(isolate); @@ -662,7 +680,9 @@ class IsolateGenesisThread : public JoinableThread { {} virtual void Run() { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); CHECK(!i::Isolate::Current()->has_installed_extensions()); @@ -673,6 +693,7 @@ class IsolateGenesisThread : public JoinableThread { } isolate->Dispose(); } + private: int count_; const char** extension_names_; diff --git a/test/cctest/test-log.cc b/test/cctest/test-log.cc index 2386cec..cbc1c00 100644 --- a/test/cctest/test-log.cc +++ b/test/cctest/test-log.cc @@ -54,19 +54,26 @@ using v8::internal::StrLength; namespace { +#define SETUP_FLAGS() \ + bool saved_log = i::FLAG_log; \ + bool saved_prof = i::FLAG_prof; \ + i::FLAG_log = true; \ + i::FLAG_prof = true; \ + i::FLAG_logfile = i::Log::kLogToTemporaryFile; \ + i::FLAG_logfile_per_isolate = false + + class ScopedLoggerInitializer { public: - ScopedLoggerInitializer() - : saved_log_(i::FLAG_log), - saved_prof_(i::FLAG_prof), + ScopedLoggerInitializer(bool saved_log, bool saved_prof, v8::Isolate* isolate) + : saved_log_(saved_log), + saved_prof_(saved_prof), temp_file_(NULL), - // Need to run this prior to creating the scope. - trick_to_run_init_flags_(init_flags_()), - isolate_(v8::Isolate::New()), - isolate_scope_(isolate_), - scope_(isolate_), - env_(v8::Context::New(isolate_)), - logger_(reinterpret_cast(isolate_)->logger()) { + isolate_(isolate), + isolate_scope_(isolate), + scope_(isolate), + env_(v8::Context::New(isolate)), + logger_(reinterpret_cast(isolate)->logger()) { env_->Enter(); } @@ -93,18 +100,9 @@ class ScopedLoggerInitializer { } private: - static bool init_flags_() { - i::FLAG_log = true; - i::FLAG_prof = true; - i::FLAG_logfile = i::Log::kLogToTemporaryFile; - i::FLAG_logfile_per_isolate = false; - return false; - } - const bool saved_log_; const bool saved_prof_; FILE* temp_file_; - const bool trick_to_run_init_flags_; v8::Isolate* isolate_; v8::Isolate::Scope isolate_scope_; v8::HandleScope scope_; @@ -337,10 +335,12 @@ static void ObjMethod1(const v8::FunctionCallbackInfo& args) { TEST(LogCallbacks) { - v8::Isolate* isolate; + SETUP_FLAGS(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { - ScopedLoggerInitializer initialize_logger; - isolate = initialize_logger.isolate(); + ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); Logger* logger = initialize_logger.logger(); v8::Local obj = v8::Local::New( @@ -390,10 +390,12 @@ static void Prop2Getter(v8::Local property, TEST(LogAccessorCallbacks) { - v8::Isolate* isolate; + SETUP_FLAGS(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { - ScopedLoggerInitializer initialize_logger; - isolate = initialize_logger.isolate(); + ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); Logger* logger = initialize_logger.logger(); v8::Local obj = v8::Local::New( @@ -446,10 +448,12 @@ TEST(EquivalenceOfLoggingAndTraversal) { // are using V8. // Start with profiling to capture all code events from the beginning. - v8::Isolate* isolate; + SETUP_FLAGS(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { - ScopedLoggerInitializer initialize_logger; - isolate = initialize_logger.isolate(); + ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); Logger* logger = initialize_logger.logger(); // Compile and run a function that creates other functions. @@ -508,10 +512,12 @@ TEST(EquivalenceOfLoggingAndTraversal) { TEST(LogVersion) { - v8::Isolate* isolate; + SETUP_FLAGS(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { - ScopedLoggerInitializer initialize_logger; - isolate = initialize_logger.isolate(); + ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); bool exists = false; i::Vector log( i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc index ec70a4c..a8cc6c7 100644 --- a/test/cctest/test-mark-compact.cc +++ b/test/cctest/test-mark-compact.cc @@ -470,7 +470,9 @@ static intptr_t MemoryInUse() { intptr_t ShortLivingIsolate() { - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); v8::Locker lock(isolate); v8::HandleScope handle_scope(isolate); diff --git a/test/cctest/test-microtask-delivery.cc b/test/cctest/test-microtask-delivery.cc index 082bc1a..601290c 100644 --- a/test/cctest/test-microtask-delivery.cc +++ b/test/cctest/test-microtask-delivery.cc @@ -36,7 +36,9 @@ namespace { class HarmonyIsolate { public: HarmonyIsolate() { - isolate_ = Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + isolate_ = Isolate::New(create_params); isolate_->Enter(); } diff --git a/test/cctest/test-random-number-generator.cc b/test/cctest/test-random-number-generator.cc index cc94930..0ebe091 100644 --- a/test/cctest/test-random-number-generator.cc +++ b/test/cctest/test-random-number-generator.cc @@ -39,7 +39,9 @@ static const int64_t kRandomSeeds[] = {-1, 1, 42, 100, 1234567890, 987654321}; TEST(RandomSeedFlagIsUsed) { for (unsigned n = 0; n < arraysize(kRandomSeeds); ++n) { FLAG_random_seed = static_cast(kRandomSeeds[n]); - v8::Isolate* i = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* i = v8::Isolate::New(create_params); v8::base::RandomNumberGenerator& rng = *reinterpret_cast(i)->random_number_generator(); CHECK_EQ(kRandomSeeds[n], rng.initial_seed()); diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc index 8d3621d..4b76324 100644 --- a/test/cctest/test-serialize.cc +++ b/test/cctest/test-serialize.cc @@ -68,7 +68,9 @@ class TestIsolate : public Isolate { isolate->Init(NULL); return v8_isolate; } - explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) {} + explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) { + set_array_buffer_allocator(CcTest::array_buffer_allocator()); + } }; @@ -669,6 +671,8 @@ TEST(PerIsolateSnapshotBlobs) { v8::Isolate::CreateParams params1; params1.snapshot_blob = &data1; + params1.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(params1); { v8::Isolate::Scope i_scope(isolate1); @@ -683,6 +687,7 @@ TEST(PerIsolateSnapshotBlobs) { v8::Isolate::CreateParams params2; params2.snapshot_blob = &data2; + params2.array_buffer_allocator = CcTest::array_buffer_allocator(); v8::Isolate* isolate2 = v8::Isolate::New(params2); { v8::Isolate::Scope i_scope(isolate2); @@ -699,7 +704,9 @@ TEST(PerIsolateSnapshotBlobs) { TEST(PerIsolateSnapshotBlobsWithLocker) { DisableTurbofan(); - v8::Isolate* isolate0 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate0 = v8::Isolate::New(create_params); { v8::Locker locker(isolate0); v8::Isolate::Scope i_scope(isolate0); @@ -716,6 +723,7 @@ TEST(PerIsolateSnapshotBlobsWithLocker) { v8::Isolate::CreateParams params1; params1.snapshot_blob = &data1; + params1.array_buffer_allocator = CcTest::array_buffer_allocator(); v8::Isolate* isolate1 = v8::Isolate::New(params1); { v8::Locker locker(isolate1); @@ -1303,7 +1311,9 @@ static void SerializerCodeEventListener(const v8::JitCodeEvent* event) { v8::ScriptCompiler::CachedData* ProduceCache(const char* source) { v8::ScriptCompiler::CachedData* cache; - v8::Isolate* isolate1 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); { v8::Isolate::Scope iscope(isolate1); v8::HandleScope scope(isolate1); @@ -1337,7 +1347,9 @@ TEST(SerializeToplevelIsolates) { const char* source = "function f() { return 'abc'; }; f() + 'def'"; v8::ScriptCompiler::CachedData* cache = ProduceCache(source); - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault, SerializerCodeEventListener); toplevel_test_code_event_found = false; @@ -1371,7 +1383,9 @@ TEST(SerializeToplevelFlagChange) { const char* source = "function f() { return 'abc'; }; f() + 'def'"; v8::ScriptCompiler::CachedData* cache = ProduceCache(source); - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); FLAG_allow_natives_syntax = true; // Flag change should trigger cache reject. FlagList::EnforceFlagImplications(); @@ -1401,7 +1415,9 @@ TEST(SerializeToplevelBitFlip) { // Random bit flip. const_cast(cache->data)[337] ^= 0x40; - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); { v8::Isolate::Scope iscope(isolate2); v8::HandleScope scope(isolate2); @@ -1428,7 +1444,9 @@ TEST(SerializeWithHarmonyScoping) { v8::ScriptCompiler::CachedData* cache; - v8::Isolate* isolate1 = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate1 = v8::Isolate::New(create_params); { v8::Isolate::Scope iscope(isolate1); v8::HandleScope scope(isolate1); @@ -1456,7 +1474,7 @@ TEST(SerializeWithHarmonyScoping) { } isolate1->Dispose(); - v8::Isolate* isolate2 = v8::Isolate::New(); + v8::Isolate* isolate2 = v8::Isolate::New(create_params); { v8::Isolate::Scope iscope(isolate2); v8::HandleScope scope(isolate2); @@ -1519,6 +1537,7 @@ TEST(SerializeInternalReference) { v8::Isolate::CreateParams params; params.snapshot_blob = &data; + params.array_buffer_allocator = CcTest::array_buffer_allocator(); v8::Isolate* isolate = v8::Isolate::New(params); { v8::Isolate::Scope i_scope(isolate); diff --git a/test/cctest/test-spaces.cc b/test/cctest/test-spaces.cc index 25d19d5..9d22327 100644 --- a/test/cctest/test-spaces.cc +++ b/test/cctest/test-spaces.cc @@ -462,7 +462,9 @@ UNINITIALIZED_TEST(NewSpaceGrowsToTargetCapacity) { FLAG_target_semi_space_size = 2 * (Page::kPageSize / MB); if (FLAG_optimize_for_size) return; - v8::Isolate* isolate = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc index 9d39711..1713e91 100644 --- a/test/cctest/test-strings.cc +++ b/test/cctest/test-strings.cc @@ -1211,6 +1211,7 @@ UNINITIALIZED_TEST(OneByteArrayJoin) { // Set heap limits. create_params.constraints.set_max_semi_space_size(1); create_params.constraints.set_max_old_space_size(6); + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); v8::Isolate* isolate = v8::Isolate::New(create_params); isolate->Enter(); diff --git a/test/cctest/test-typedarrays.cc b/test/cctest/test-typedarrays.cc index d031048..d371673 100644 --- a/test/cctest/test-typedarrays.cc +++ b/test/cctest/test-typedarrays.cc @@ -72,7 +72,9 @@ TEST(CopyContentsView) { TEST(AllocateNotExternal) { LocalContext env; v8::HandleScope scope(env->GetIsolate()); - void* memory = V8::ArrayBufferAllocator()->Allocate(1024); + void* memory = reinterpret_cast(env->GetIsolate()) + ->array_buffer_allocator() + ->Allocate(1024); v8::Local buffer = v8::ArrayBuffer::New(env->GetIsolate(), memory, 1024, v8::ArrayBufferCreationMode::kInternalized); diff --git a/test/unittests/run-all-unittests.cc b/test/unittests/run-all-unittests.cc index 9c67cfa..08d2656 100644 --- a/test/unittests/run-all-unittests.cc +++ b/test/unittests/run-all-unittests.cc @@ -13,16 +13,6 @@ namespace { -class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - virtual void* Allocate(size_t length) { - void* data = AllocateUninitialized(length); - return data == NULL ? data : memset(data, 0, length); - } - virtual void* AllocateUninitialized(size_t length) { return malloc(length); } - virtual void Free(void* data, size_t) { free(data); } -}; - class DefaultPlatformEnvironment final : public ::testing::Environment { public: DefaultPlatformEnvironment() : platform_(NULL) {} @@ -33,7 +23,6 @@ class DefaultPlatformEnvironment final : public ::testing::Environment { platform_ = v8::platform::CreateDefaultPlatform(); ASSERT_TRUE(platform_ != NULL); v8::V8::InitializePlatform(platform_); - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator_); ASSERT_TRUE(v8::V8::Initialize()); } @@ -47,7 +36,6 @@ class DefaultPlatformEnvironment final : public ::testing::Environment { private: v8::Platform* platform_; - ArrayBufferAllocator array_buffer_allocator_; }; } // namespace diff --git a/test/unittests/test-utils.cc b/test/unittests/test-utils.cc index aa37b2f..fd52a4b 100644 --- a/test/unittests/test-utils.cc +++ b/test/unittests/test-utils.cc @@ -11,6 +11,20 @@ namespace v8 { +class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + virtual void* Allocate(size_t length) { + void* data = AllocateUninitialized(length); + return data == NULL ? data : memset(data, 0, length); + } + virtual void* AllocateUninitialized(size_t length) { return malloc(length); } + virtual void Free(void* data, size_t) { free(data); } +}; + + +// static +ArrayBufferAllocator* TestWithIsolate::array_buffer_allocator_ = NULL; + // static Isolate* TestWithIsolate::isolate_ = NULL; @@ -26,7 +40,10 @@ TestWithIsolate::~TestWithIsolate() {} void TestWithIsolate::SetUpTestCase() { Test::SetUpTestCase(); EXPECT_EQ(NULL, isolate_); - isolate_ = v8::Isolate::New(); + v8::Isolate::CreateParams create_params; + array_buffer_allocator_ = new ArrayBufferAllocator; + create_params.array_buffer_allocator = array_buffer_allocator_; + isolate_ = v8::Isolate::New(create_params); EXPECT_TRUE(isolate_ != NULL); } @@ -36,6 +53,7 @@ void TestWithIsolate::TearDownTestCase() { ASSERT_TRUE(isolate_ != NULL); isolate_->Dispose(); isolate_ = NULL; + delete array_buffer_allocator_; Test::TearDownTestCase(); } diff --git a/test/unittests/test-utils.h b/test/unittests/test-utils.h index 547a34e..78283bf 100644 --- a/test/unittests/test-utils.h +++ b/test/unittests/test-utils.h @@ -13,6 +13,8 @@ namespace v8 { +class ArrayBufferAllocator; + class TestWithIsolate : public virtual ::testing::Test { public: @@ -25,6 +27,7 @@ class TestWithIsolate : public virtual ::testing::Test { static void TearDownTestCase(); private: + static ArrayBufferAllocator* array_buffer_allocator_; static Isolate* isolate_; Isolate::Scope isolate_scope_; HandleScope handle_scope_; diff --git a/tools/parser-shell.cc b/tools/parser-shell.cc index e2cae0f..7e33d8c 100644 --- a/tools/parser-shell.cc +++ b/tools/parser-shell.cc @@ -141,8 +141,6 @@ int main(int argc, char* argv[]) { v8::V8::InitializeICU(); v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); - ArrayBufferAllocator array_buffer_allocator; - v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); v8::V8::Initialize(); Encoding encoding = LATIN1; std::vector fnames; @@ -164,7 +162,10 @@ int main(int argc, char* argv[]) { fnames.push_back(std::string(argv[i])); } } - v8::Isolate* isolate = v8::Isolate::New(); + ArrayBufferAllocator array_buffer_allocator; + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &array_buffer_allocator; + v8::Isolate* isolate = v8::Isolate::New(create_params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); -- 2.7.4