diff options
Diffstat (limited to 'deps/v8/src/builtins/setup-builtins-internal.cc')
-rw-r--r-- | deps/v8/src/builtins/setup-builtins-internal.cc | 141 |
1 files changed, 74 insertions, 67 deletions
diff --git a/deps/v8/src/builtins/setup-builtins-internal.cc b/deps/v8/src/builtins/setup-builtins-internal.cc index 630473f407..cf7aa704f2 100644 --- a/deps/v8/src/builtins/setup-builtins-internal.cc +++ b/deps/v8/src/builtins/setup-builtins-internal.cc @@ -8,35 +8,32 @@ #include "src/builtins/builtins.h" #include "src/code-events.h" #include "src/compiler/code-assembler.h" + #include "src/handles-inl.h" #include "src/interface-descriptors.h" #include "src/interpreter/bytecodes.h" #include "src/interpreter/interpreter-generator.h" #include "src/interpreter/interpreter.h" #include "src/isolate.h" +#include "src/macro-assembler.h" #include "src/objects-inl.h" #include "src/objects/shared-function-info.h" +#include "src/objects/smi.h" namespace v8 { namespace internal { // Forward declarations for C++ builtins. #define FORWARD_DECLARE(Name) \ - Object* Builtin_##Name(int argc, Object** args, Isolate* isolate); + Address Builtin_##Name(int argc, Address* args, Isolate* isolate); BUILTIN_LIST_C(FORWARD_DECLARE) #undef FORWARD_DECLARE namespace { -void PostBuildProfileAndTracing(Isolate* isolate, Code* code, - const char* name) { +void PostBuildProfileAndTracing(Isolate* isolate, Code code, const char* name) { PROFILE(isolate, CodeCreateEvent(CodeEventListener::BUILTIN_TAG, AbstractCode::cast(code), name)); -#ifdef ENABLE_DISASSEMBLER - if (FLAG_print_builtin_code) { - code->PrintBuiltinCode(isolate, name); - } -#endif } AssemblerOptions BuiltinAssemblerOptions(Isolate* isolate, @@ -54,7 +51,8 @@ AssemblerOptions BuiltinAssemblerOptions(Isolate* isolate, isolate->heap()->memory_allocator()->code_range(); bool pc_relative_calls_fit_in_code_range = !code_range.is_empty() && - code_range.size() <= kMaxPCRelativeCodeRangeInMB * MB; + std::ceil(static_cast<float>(code_range.size() / MB)) <= + kMaxPCRelativeCodeRangeInMB; options.isolate_independent_code = true; options.use_pc_relative_calls_and_jumps = pc_relative_calls_fit_in_code_range; @@ -67,15 +65,16 @@ typedef void (*CodeAssemblerGenerator)(compiler::CodeAssemblerState*); Handle<Code> BuildPlaceholder(Isolate* isolate, int32_t builtin_index) { HandleScope scope(isolate); - const size_t buffer_size = 1 * KB; - byte buffer[buffer_size]; // NOLINT(runtime/arrays) - MacroAssembler masm(isolate, buffer, buffer_size, CodeObjectRequired::kYes); + constexpr int kBufferSize = 1 * KB; + byte buffer[kBufferSize]; + MacroAssembler masm(isolate, CodeObjectRequired::kYes, + ExternalAssemblerBuffer(buffer, kBufferSize)); DCHECK(!masm.has_frame()); { FrameScope scope(&masm, StackFrame::NONE); // The contents of placeholder don't matter, as long as they don't create // embedded constants or external references. - masm.Move(kJavaScriptCallCodeStartRegister, Smi::kZero); + masm.Move(kJavaScriptCallCodeStartRegister, Smi::zero()); masm.Call(kJavaScriptCallCodeStartRegister); } CodeDesc desc; @@ -85,40 +84,65 @@ Handle<Code> BuildPlaceholder(Isolate* isolate, int32_t builtin_index) { return scope.CloseAndEscape(code); } -Code* BuildWithMacroAssembler(Isolate* isolate, int32_t builtin_index, - MacroAssemblerGenerator generator, - const char* s_name) { +Code BuildWithMacroAssembler(Isolate* isolate, int32_t builtin_index, + MacroAssemblerGenerator generator, + const char* s_name) { HandleScope scope(isolate); // Canonicalize handles, so that we can share constant pool entries pointing // to code targets without dereferencing their handles. CanonicalHandleScope canonical(isolate); - const size_t buffer_size = 32 * KB; - byte buffer[buffer_size]; // NOLINT(runtime/arrays) + constexpr int kBufferSize = 32 * KB; + byte buffer[kBufferSize]; MacroAssembler masm(isolate, BuiltinAssemblerOptions(isolate, builtin_index), - buffer, buffer_size, CodeObjectRequired::kYes); + CodeObjectRequired::kYes, + ExternalAssemblerBuffer(buffer, kBufferSize)); masm.set_builtin_index(builtin_index); DCHECK(!masm.has_frame()); generator(&masm); + + int handler_table_offset = 0; + + // JSEntry builtins are a special case and need to generate a handler table. + DCHECK_EQ(Builtins::KindOf(Builtins::kJSEntry), Builtins::ASM); + DCHECK_EQ(Builtins::KindOf(Builtins::kJSConstructEntry), Builtins::ASM); + DCHECK_EQ(Builtins::KindOf(Builtins::kJSRunMicrotasksEntry), Builtins::ASM); + if (Builtins::IsJSEntryVariant(builtin_index)) { + static constexpr int kJSEntryHandlerCount = 1; + handler_table_offset = + HandlerTable::EmitReturnTableStart(&masm, kJSEntryHandlerCount); + HandlerTable::EmitReturnEntry( + &masm, 0, isolate->builtins()->js_entry_handler_offset()); + } + CodeDesc desc; masm.GetCode(isolate, &desc); + + static constexpr bool kIsNotTurbofanned = false; + static constexpr int kStackSlots = 0; + static constexpr int kSafepointTableOffset = 0; + Handle<Code> code = isolate->factory()->NewCode( - desc, Code::BUILTIN, masm.CodeObject(), builtin_index); + desc, Code::BUILTIN, masm.CodeObject(), builtin_index, + MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate), kMovable, + kIsNotTurbofanned, kStackSlots, kSafepointTableOffset, + handler_table_offset); PostBuildProfileAndTracing(isolate, *code, s_name); return *code; } -Code* BuildAdaptor(Isolate* isolate, int32_t builtin_index, - Address builtin_address, - Builtins::ExitFrameType exit_frame_type, const char* name) { +Code BuildAdaptor(Isolate* isolate, int32_t builtin_index, + Address builtin_address, + Builtins::ExitFrameType exit_frame_type, const char* name) { HandleScope scope(isolate); // Canonicalize handles, so that we can share constant pool entries pointing // to code targets without dereferencing their handles. CanonicalHandleScope canonical(isolate); - const size_t buffer_size = 32 * KB; - byte buffer[buffer_size]; // NOLINT(runtime/arrays) + constexpr int kBufferSize = 32 * KB; + byte buffer[kBufferSize]; MacroAssembler masm(isolate, BuiltinAssemblerOptions(isolate, builtin_index), - buffer, buffer_size, CodeObjectRequired::kYes); + CodeObjectRequired::kYes, + ExternalAssemblerBuffer(buffer, kBufferSize)); masm.set_builtin_index(builtin_index); DCHECK(!masm.has_frame()); Builtins::Generate_Adaptor(&masm, builtin_address, exit_frame_type); @@ -131,9 +155,9 @@ Code* BuildAdaptor(Isolate* isolate, int32_t builtin_index, } // Builder for builtins implemented in TurboFan with JS linkage. -Code* BuildWithCodeStubAssemblerJS(Isolate* isolate, int32_t builtin_index, - CodeAssemblerGenerator generator, int argc, - const char* name) { +Code BuildWithCodeStubAssemblerJS(Isolate* isolate, int32_t builtin_index, + CodeAssemblerGenerator generator, int argc, + const char* name) { HandleScope scope(isolate); // Canonicalize handles, so that we can share constant pool entries pointing // to code targets without dereferencing their handles. @@ -156,10 +180,10 @@ Code* BuildWithCodeStubAssemblerJS(Isolate* isolate, int32_t builtin_index, } // Builder for builtins implemented in TurboFan with CallStub linkage. -Code* BuildWithCodeStubAssemblerCS(Isolate* isolate, int32_t builtin_index, - CodeAssemblerGenerator generator, - CallDescriptors::Key interface_descriptor, - const char* name, int result_size) { +Code BuildWithCodeStubAssemblerCS(Isolate* isolate, int32_t builtin_index, + CodeAssemblerGenerator generator, + CallDescriptors::Key interface_descriptor, + const char* name, int result_size) { HandleScope scope(isolate); // Canonicalize handles, so that we can share constant pool entries pointing // to code targets without dereferencing their handles. @@ -176,7 +200,7 @@ Code* BuildWithCodeStubAssemblerCS(Isolate* isolate, int32_t builtin_index, DCHECK_LE(0, descriptor.GetRegisterParameterCount()); compiler::CodeAssemblerState state( isolate, &zone, descriptor, Code::BUILTIN, name, - PoisoningMitigationLevel::kDontPoison, 0, builtin_index); + PoisoningMitigationLevel::kDontPoison, builtin_index); generator(&state); Handle<Code> code = compiler::CodeAssembler::GenerateCode( &state, BuiltinAssemblerOptions(isolate, builtin_index)); @@ -188,7 +212,7 @@ Code* BuildWithCodeStubAssemblerCS(Isolate* isolate, int32_t builtin_index, // static void SetupIsolateDelegate::AddBuiltin(Builtins* builtins, int index, - Code* code) { + Code code) { DCHECK_EQ(index, code->builtin_index()); builtins->set_builtin(index, code); } @@ -217,27 +241,28 @@ void SetupIsolateDelegate::ReplacePlaceholders(Isolate* isolate) { RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | RelocInfo::ModeMask(RelocInfo::RELATIVE_CODE_TARGET); HeapIterator iterator(isolate->heap()); - while (HeapObject* obj = iterator.next()) { + for (HeapObject obj = iterator.next(); !obj.is_null(); + obj = iterator.next()) { if (!obj->IsCode()) continue; - Code* code = Code::cast(obj); + Code code = Code::cast(obj); bool flush_icache = false; for (RelocIterator it(code, kRelocMask); !it.done(); it.next()) { RelocInfo* rinfo = it.rinfo(); if (RelocInfo::IsCodeTargetMode(rinfo->rmode())) { - Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); + Code target = Code::GetCodeFromTargetAddress(rinfo->target_address()); DCHECK_IMPLIES(RelocInfo::IsRelativeCodeTarget(rinfo->rmode()), Builtins::IsIsolateIndependent(target->builtin_index())); if (!target->is_builtin()) continue; - Code* new_target = builtins->builtin(target->builtin_index()); + Code new_target = builtins->builtin(target->builtin_index()); rinfo->set_target_address(new_target->raw_instruction_start(), UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); } else { DCHECK(RelocInfo::IsEmbeddedObject(rinfo->rmode())); - Object* object = rinfo->target_object(); + Object object = rinfo->target_object(); if (!object->IsCode()) continue; - Code* target = Code::cast(object); + Code target = Code::cast(object); if (!target->is_builtin()) continue; - Code* new_target = builtins->builtin(target->builtin_index()); + Code new_target = builtins->builtin(target->builtin_index()); rinfo->set_target_object(isolate->heap(), new_target, UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); } @@ -252,10 +277,10 @@ void SetupIsolateDelegate::ReplacePlaceholders(Isolate* isolate) { namespace { -Code* GenerateBytecodeHandler(Isolate* isolate, int builtin_index, - const char* name, - interpreter::OperandScale operand_scale, - interpreter::Bytecode bytecode) { +Code GenerateBytecodeHandler(Isolate* isolate, int builtin_index, + const char* name, + interpreter::OperandScale operand_scale, + interpreter::Bytecode bytecode) { DCHECK(interpreter::Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); Handle<Code> code = interpreter::GenerateBytecodeHandler( @@ -267,18 +292,6 @@ Code* GenerateBytecodeHandler(Isolate* isolate, int builtin_index, return *code; } -Code* GenerateLazyBytecodeHandler(Isolate* isolate, int builtin_index, - const char* name, - interpreter::OperandScale operand_scale) { - Handle<Code> code = interpreter::GenerateDeserializeLazyHandler( - isolate, operand_scale, builtin_index, - BuiltinAssemblerOptions(isolate, builtin_index)); - - PostBuildProfileAndTracing(isolate, *code, name); - - return *code; -} - } // namespace // static @@ -292,7 +305,7 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { HandleScope scope(isolate); int index = 0; - Code* code; + Code code; #define BUILD_CPP(Name) \ code = BuildAdaptor(isolate, index, FUNCTION_ADDR(Builtin_##Name), \ Builtins::BUILTIN_EXIT, #Name); \ @@ -328,18 +341,13 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { OperandScale, Bytecode); \ AddBuiltin(builtins, index++, code); -#define BUILD_DLH(Name, OperandScale) \ - code = GenerateLazyBytecodeHandler(isolate, index, Builtins::name(index), \ - OperandScale); \ - AddBuiltin(builtins, index++, code); - -#define BUILD_ASM(Name) \ +#define BUILD_ASM(Name, InterfaceDescriptor) \ code = BuildWithMacroAssembler(isolate, index, Builtins::Generate_##Name, \ #Name); \ AddBuiltin(builtins, index++, code); BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFC, BUILD_TFS, BUILD_TFH, - BUILD_BCH, BUILD_DLH, BUILD_ASM); + BUILD_BCH, BUILD_ASM); #undef BUILD_CPP #undef BUILD_API @@ -348,7 +356,6 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { #undef BUILD_TFS #undef BUILD_TFH #undef BUILD_BCH -#undef BUILD_DLH #undef BUILD_ASM CHECK_EQ(Builtins::builtin_count, index); |