diff --git a/src/api/api.cc b/src/api/api.cc index 10e7941782..0d3d7a1a81 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -9395,7 +9395,7 @@ JSEntryStubs Isolate::GetJSEntryStubs() { {i::Builtin::kJSRunMicrotasksEntry, &entry_stubs.js_run_microtasks_entry_stub}}}; for (auto& pair : stubs) { - i::Code js_entry = FromCodeT(i_isolate->builtins()->code(pair.first)); + i::CodeT js_entry = i_isolate->builtins()->code(pair.first); pair.second->code.start = reinterpret_cast(js_entry.InstructionStart()); pair.second->code.length_in_bytes = js_entry.InstructionSize(); diff --git a/src/builtins/setup-builtins-internal.cc b/src/builtins/setup-builtins-internal.cc index 9bda722588..210df4b1f7 100644 --- a/src/builtins/setup-builtins-internal.cc +++ b/src/builtins/setup-builtins-internal.cc @@ -363,9 +363,8 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { ReplacePlaceholders(isolate); -// TODO(v8:11880): avoid roundtrips between cdc and code. #define SET_PROMISE_REJECTION_PREDICTION(Name) \ - FromCodeT(builtins->code(Builtin::k##Name)).set_is_promise_rejection(true); + builtins->code(Builtin::k##Name).set_is_promise_rejection(true); BUILTIN_PROMISE_REJECTION_PREDICTION_LIST(SET_PROMISE_REJECTION_PREDICTION) #undef SET_PROMISE_REJECTION_PREDICTION diff --git a/src/compiler/heap-refs.cc b/src/compiler/heap-refs.cc index 71b090f9e5..7365cad65f 100644 --- a/src/compiler/heap-refs.cc +++ b/src/compiler/heap-refs.cc @@ -2166,11 +2166,9 @@ BIMODAL_ACCESSOR(JSFunction, SharedFunctionInfo, shared) #undef JSFUNCTION_BIMODAL_ACCESSOR_WITH_DEP #undef JSFUNCTION_BIMODAL_ACCESSOR_WITH_DEP_C -CodeRef JSFunctionRef::code() const { +CodeTRef JSFunctionRef::code() const { CodeT code = object()->code(kAcquireLoad); - // Safe to do a relaxed conversion to Code here since CodeT::code field is - // modified only by GC and the CodeT was acquire-loaded. - return MakeRefAssumeMemoryFence(broker(), FromCodeT(code, kRelaxedLoad)); + return MakeRefAssumeMemoryFence(broker(), code); } NativeContextRef JSFunctionRef::native_context() const { @@ -2252,16 +2250,40 @@ std::ostream& operator<<(std::ostream& os, const ObjectRef& ref) { } } -unsigned CodeRef::GetInlinedBytecodeSize() const { - unsigned value = object()->inlined_bytecode_size(); +namespace { + +unsigned GetInlinedBytecodeSizeImpl(Code code) { + unsigned value = code.inlined_bytecode_size(); if (value > 0) { // Don't report inlined bytecode size if the code object was already // deoptimized. - value = object()->marked_for_deoptimization() ? 0 : value; + value = code.marked_for_deoptimization() ? 0 : value; } return value; } +} // namespace + +unsigned CodeRef::GetInlinedBytecodeSize() const { + return GetInlinedBytecodeSizeImpl(*object()); +} + +unsigned CodeDataContainerRef::GetInlinedBytecodeSize() const { +#ifdef V8_EXTERNAL_CODE_SPACE + CodeDataContainer codet = *object(); + if (codet.is_off_heap_trampoline()) { + return 0; + } + + // Safe to do a relaxed conversion to Code here since CodeT::code field is + // modified only by GC and the CodeT was acquire-loaded. + Code code = codet.code(kRelaxedLoad); + return GetInlinedBytecodeSizeImpl(code); +#else + UNREACHABLE(); +#endif // V8_EXTERNAL_CODE_SPACE +} + #undef BIMODAL_ACCESSOR #undef BIMODAL_ACCESSOR_B #undef BIMODAL_ACCESSOR_C diff --git a/src/compiler/heap-refs.h b/src/compiler/heap-refs.h index 7bcf64774c..5cee9e8f29 100644 --- a/src/compiler/heap-refs.h +++ b/src/compiler/heap-refs.h @@ -456,7 +456,7 @@ class V8_EXPORT_PRIVATE JSFunctionRef : public JSObjectRef { ContextRef context() const; NativeContextRef native_context() const; SharedFunctionInfoRef shared() const; - CodeRef code() const; + CodeTRef code() const; bool has_initial_map(CompilationDependencies* dependencies) const; bool PrototypeRequiresRuntimeLookup( @@ -1015,6 +1015,8 @@ class CodeDataContainerRef : public HeapObjectRef { DEFINE_REF_CONSTRUCTOR(CodeDataContainer, HeapObjectRef) Handle object() const; + + unsigned GetInlinedBytecodeSize() const; }; class InternalizedStringRef : public StringRef { diff --git a/src/execution/simulator.h b/src/execution/simulator.h index 1f93e1b6e2..4472ad8bd4 100644 --- a/src/execution/simulator.h +++ b/src/execution/simulator.h @@ -112,7 +112,8 @@ class GeneratedCode { return GeneratedCode(isolate, reinterpret_cast(buffer)); } - static GeneratedCode FromCode(Code code) { + template + static GeneratedCode FromCode(CodeOrCodeT code) { return FromAddress(code.GetIsolate(), code.entry()); } diff --git a/src/regexp/regexp-macro-assembler.cc b/src/regexp/regexp-macro-assembler.cc index f25a5ffc16..36618c2f8a 100644 --- a/src/regexp/regexp-macro-assembler.cc +++ b/src/regexp/regexp-macro-assembler.cc @@ -432,7 +432,7 @@ int NativeRegExpMacroAssembler::Execute( RegExpStackScope stack_scope(isolate); bool is_one_byte = String::IsOneByteRepresentationUnderneath(input); - Code code = FromCodeT(CodeT::cast(regexp.code(is_one_byte))); + CodeT code = CodeT::cast(regexp.code(is_one_byte)); RegExp::CallOrigin call_origin = RegExp::CallOrigin::kFromRuntime; using RegexpMatcherSig = diff --git a/test/unittests/logging/log-unittest.cc b/test/unittests/logging/log-unittest.cc index 4eb38dbd83..4712236749 100644 --- a/test/unittests/logging/log-unittest.cc +++ b/test/unittests/logging/log-unittest.cc @@ -1211,9 +1211,7 @@ TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) { logger.StopLogging(); i::Isolate* i_isolate = logger.i_isolate(); - i::Handle builtin = FromCodeT( - i_isolate->builtins()->code_handle(i::Builtin::kBooleanConstructor), - i_isolate); + i::Handle builtin = BUILTIN_CODE(i_isolate, BooleanConstructor); v8::base::EmbeddedVector buffer; // Should only be logged as "Builtin" with a name, never as "Function".