From 0b40589e7390a1595ea912184e4cad426b3da694 Mon Sep 17 00:00:00 2001 From: "vitalyr@chromium.org" Date: Fri, 1 Apr 2011 14:46:30 +0000 Subject: [PATCH] Fix multi-isolate build: o Make ia32 macro assembler work without an isolate and use it in the custom memcpy creation code. o Remove isolate-dependent code from the custom memcpy and modulo functions creation code. Review URL: http://codereview.chromium.org/6788007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7482 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/builtins.cc | 9 +++++---- src/code-stubs.cc | 4 ++-- src/codegen.cc | 2 +- src/deoptimizer.cc | 2 +- src/full-codegen.cc | 2 +- src/hydrogen.cc | 2 +- src/ia32/codegen-ia32.cc | 3 +-- src/ia32/macro-assembler-ia32.cc | 15 ++++++++++----- src/ia32/macro-assembler-ia32.h | 11 +++++++++-- src/ia32/regexp-macro-assembler-ia32.cc | 2 +- src/platform-posix.cc | 3 ++- src/platform-win32.cc | 6 ++++-- src/stub-cache.h | 3 ++- test/cctest/test-assembler-ia32.cc | 2 +- 14 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/builtins.cc b/src/builtins.cc index 72f9d57..ae3dab4 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -1594,10 +1594,11 @@ void Builtins::InitBuiltinFunctionTable() { void Builtins::Setup(bool create_heap_objects) { ASSERT(!initialized_); - Heap* heap = Isolate::Current()->heap(); + Isolate* isolate = Isolate::Current(); + Heap* heap = isolate->heap(); // Create a scope for the handles in the builtins. - HandleScope scope; + HandleScope scope(isolate); const BuiltinDesc* functions = BuiltinFunctionTable::functions(); @@ -1609,7 +1610,7 @@ void Builtins::Setup(bool create_heap_objects) { // separate code object for each one. for (int i = 0; i < builtin_count; i++) { if (create_heap_objects) { - MacroAssembler masm(buffer, sizeof buffer); + MacroAssembler masm(isolate, buffer, sizeof buffer); // Generate the code/adaptor. typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments); Generator g = FUNCTION_CAST(functions[i].generator); @@ -1634,7 +1635,7 @@ void Builtins::Setup(bool create_heap_objects) { } } // Log the event and add the code to the builtins array. - PROFILE(ISOLATE, + PROFILE(isolate, CodeCreateEvent(Logger::BUILTIN_TAG, Code::cast(code), functions[i].s_name)); diff --git a/src/code-stubs.cc b/src/code-stubs.cc index 2ecd336..f680c60 100644 --- a/src/code-stubs.cc +++ b/src/code-stubs.cc @@ -95,7 +95,7 @@ Handle CodeStub::GetCode() { HandleScope scope(isolate); // Generate the new code. - MacroAssembler masm(NULL, 256); + MacroAssembler masm(isolate, NULL, 256); GenerateCode(&masm); // Create the code object. @@ -132,7 +132,7 @@ MaybeObject* CodeStub::TryGetCode() { Code* code; if (!FindCodeInCache(&code)) { // Generate the new code. - MacroAssembler masm(NULL, 256); + MacroAssembler masm(Isolate::Current(), NULL, 256); GenerateCode(&masm); Heap* heap = masm.isolate()->heap(); diff --git a/src/codegen.cc b/src/codegen.cc index 03f64a1..d2e7f23 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -248,7 +248,7 @@ bool CodeGenerator::MakeCode(CompilationInfo* info) { MakeCodePrologue(info); // Generate code. const int kInitialBufferSize = 4 * KB; - MacroAssembler masm(NULL, kInitialBufferSize); + MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize); #ifdef ENABLE_GDB_JIT_INTERFACE masm.positions_recorder()->StartGDBJITLineInfoRecording(); #endif diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc index 63b82b7..0fed391 100644 --- a/src/deoptimizer.cc +++ b/src/deoptimizer.cc @@ -933,7 +933,7 @@ LargeObjectChunk* Deoptimizer::CreateCode(BailoutType type) { // isn't meant to be serialized at all. ASSERT(!Serializer::enabled()); - MacroAssembler masm(NULL, 16 * KB); + MacroAssembler masm(Isolate::Current(), NULL, 16 * KB); masm.set_emit_debug_code(false); GenerateDeoptimizationEntries(&masm, kNumberOfEntries, type); CodeDesc desc; diff --git a/src/full-codegen.cc b/src/full-codegen.cc index d509cd5..b896fc8 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -286,7 +286,7 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info) { } CodeGenerator::MakeCodePrologue(info); const int kInitialBufferSize = 4 * KB; - MacroAssembler masm(NULL, kInitialBufferSize); + MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize); #ifdef ENABLE_GDB_JIT_INTERFACE masm.positions_recorder()->StartGDBJITLineInfoRecording(); #endif diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 94340c6..433618f 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -606,7 +606,7 @@ Handle HGraph::Compile(CompilationInfo* info) { if (!FLAG_use_lithium) return Handle::null(); - MacroAssembler assembler(NULL, 0); + MacroAssembler assembler(info->isolate(), NULL, 0); LCodeGen generator(chunk, &assembler, info); if (FLAG_eliminate_empty_blocks) { diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index b31a63a..8a47e72 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -10176,14 +10176,13 @@ static void MemCopyWrapper(void* dest, const void* src, size_t size) { OS::MemCopyFunction CreateMemCopyFunction() { - HandleScope scope; size_t actual_size; // Allocate buffer in executable space. byte* buffer = static_cast(OS::Allocate(1 * KB, &actual_size, true)); if (buffer == NULL) return &MemCopyWrapper; - MacroAssembler masm(buffer, static_cast(actual_size)); + MacroAssembler masm(NULL, buffer, static_cast(actual_size)); // Generated code is put into a fixed, unmovable, buffer, and not into // the V8 heap. We can't, and don't, refer to any relocatable addresses diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index af0067c..4055498 100644 --- a/src/ia32/macro-assembler-ia32.cc +++ b/src/ia32/macro-assembler-ia32.cc @@ -41,11 +41,14 @@ namespace internal { // ------------------------------------------------------------------------- // MacroAssembler implementation. -MacroAssembler::MacroAssembler(void* buffer, int size) - : Assembler(Isolate::Current(), buffer, size), +MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) + : Assembler(arg_isolate, buffer, size), generating_stub_(false), - allow_stub_calls_(true), - code_object_(isolate()->heap()->undefined_value()) { + allow_stub_calls_(true) { + if (isolate() != NULL) { + code_object_ = Handle(isolate()->heap()->undefined_value(), + isolate()); + } } @@ -2028,7 +2031,9 @@ void MacroAssembler::CallCFunction(Register function, CodePatcher::CodePatcher(byte* address, int size) - : address_(address), size_(size), masm_(address, size + Assembler::kGap) { + : address_(address), + size_(size), + masm_(Isolate::Current(), address, size + Assembler::kGap) { // Create a new macro assembler pointing to the address of the code to patch. // The size is adjusted with kGap on order for the assembler to generate size // bytes of instructions without failing with buffer size constraints. diff --git a/src/ia32/macro-assembler-ia32.h b/src/ia32/macro-assembler-ia32.h index bafb175..946022a 100644 --- a/src/ia32/macro-assembler-ia32.h +++ b/src/ia32/macro-assembler-ia32.h @@ -56,7 +56,11 @@ class PostCallGenerator; // MacroAssembler implements a collection of frequently used macros. class MacroAssembler: public Assembler { public: - MacroAssembler(void* buffer, int size); + // The isolate parameter can be NULL if the macro assembler should + // not use isolate-dependent functionality. In this case, it's the + // responsibility of the caller to never invoke such function on the + // macro assembler. + MacroAssembler(Isolate* isolate, void* buffer, int size); // --------------------------------------------------------------------------- // GC Support @@ -580,7 +584,10 @@ class MacroAssembler: public Assembler { void Move(Register target, Handle value); - Handle CodeObject() { return code_object_; } + Handle CodeObject() { + ASSERT(!code_object_.is_null()); + return code_object_; + } // --------------------------------------------------------------------------- diff --git a/src/ia32/regexp-macro-assembler-ia32.cc b/src/ia32/regexp-macro-assembler-ia32.cc index 866c8a2..067f8c8 100644 --- a/src/ia32/regexp-macro-assembler-ia32.cc +++ b/src/ia32/regexp-macro-assembler-ia32.cc @@ -99,7 +99,7 @@ namespace internal { RegExpMacroAssemblerIA32::RegExpMacroAssemblerIA32( Mode mode, int registers_to_save) - : masm_(new MacroAssembler(NULL, kRegExpCodeSize)), + : masm_(new MacroAssembler(Isolate::Current(), NULL, kRegExpCodeSize)), mode_(mode), num_registers_(registers_to_save), num_saved_registers_(registers_to_save), diff --git a/src/platform-posix.cc b/src/platform-posix.cc index 9cf8b57..c4b0fb8 100644 --- a/src/platform-posix.cc +++ b/src/platform-posix.cc @@ -215,13 +215,14 @@ OS::MemCopyFunction CreateMemCopyFunction(); void OS::MemCopy(void* dest, const void* src, size_t size) { if (memcopy_function == NULL) { ScopedLock lock(memcopy_function_mutex); - Isolate::EnsureDefaultIsolate(); if (memcopy_function == NULL) { OS::MemCopyFunction temp = CreateMemCopyFunction(); MemoryBarrier(); memcopy_function = temp; } } + // Note: here we rely on dependent reads being ordered. This is true + // on all architectures we currently support. (*memcopy_function)(dest, src, size); #ifdef DEBUG CHECK_EQ(0, memcmp(dest, src, size)); diff --git a/src/platform-win32.cc b/src/platform-win32.cc index e23ebe5..ab03e3d 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -186,13 +186,14 @@ OS::MemCopyFunction CreateMemCopyFunction(); void OS::MemCopy(void* dest, const void* src, size_t size) { if (memcopy_function == NULL) { ScopedLock lock(memcopy_function_mutex); - Isolate::EnsureDefaultIsolate(); if (memcopy_function == NULL) { OS::MemCopyFunction temp = CreateMemCopyFunction(); MemoryBarrier(); memcopy_function = temp; } } + // Note: here we rely on dependent reads being ordered. This is true + // on all architectures we currently support. (*memcopy_function)(dest, src, size); #ifdef DEBUG CHECK_EQ(0, memcmp(dest, src, size)); @@ -210,13 +211,14 @@ ModuloFunction CreateModuloFunction(); double modulo(double x, double y) { if (modulo_function == NULL) { ScopedLock lock(modulo_function_mutex); - Isolate::EnsureDefaultIsolate(); if (modulo_function == NULL) { ModuloFunction temp = CreateModuloFunction(); MemoryBarrier(); modulo_function = temp; } } + // Note: here we rely on dependent reads being ordered. This is true + // on all architectures we currently support. return (*modulo_function)(x, y); } #else // Win32 diff --git a/src/stub-cache.h b/src/stub-cache.h index e8f362f..c5dcf36 100644 --- a/src/stub-cache.h +++ b/src/stub-cache.h @@ -408,7 +408,8 @@ DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); // The stub compiler compiles stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: - StubCompiler() : scope_(), masm_(NULL, 256), failure_(NULL) { } + StubCompiler() + : scope_(), masm_(Isolate::Current(), NULL, 256), failure_(NULL) { } MUST_USE_RESULT MaybeObject* CompileCallInitialize(Code::Flags flags); MUST_USE_RESULT MaybeObject* CompileCallPreMonomorphic(Code::Flags flags); diff --git a/test/cctest/test-assembler-ia32.cc b/test/cctest/test-assembler-ia32.cc index 1cd2ddc..576739b 100644 --- a/test/cctest/test-assembler-ia32.cc +++ b/test/cctest/test-assembler-ia32.cc @@ -345,7 +345,7 @@ TEST(AssemblerIa329) { InitializeVM(); v8::HandleScope scope; v8::internal::byte buffer[256]; - MacroAssembler assm(buffer, sizeof buffer); + MacroAssembler assm(Isolate::Current(), buffer, sizeof buffer); enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 }; Label equal_l, less_l, greater_l, nan_l; __ fld_d(Operand(esp, 3 * kPointerSize)); -- 2.7.4