From 046b58d6e72fa2b8b76e8df75392258eb46bde79 Mon Sep 17 00:00:00 2001 From: Igor Sheludko Date: Thu, 17 Jun 2021 17:47:09 +0200 Subject: [PATCH] [ext-code-space] Migrate Baseline/InterpreterData's code fields to CodeT This CL migrates BaselineData::baseline_code field and InterpreterData::interpreter_trampoline field to CodeT. Bug: v8:11880 Change-Id: Ibd202f0dcd4266e5b98aa5c46754ba8a4fadff43 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2968415 Reviewed-by: Toon Verwaest Commit-Queue: Igor Sheludko Cr-Commit-Position: refs/heads/master@{#75233} --- src/builtins/x64/builtins-x64.cc | 14 ++++++++------ src/codegen/code-stub-assembler.cc | 18 +++++++++++------- src/objects/shared-function-info-inl.h | 19 ++++++++++++++++++- src/objects/shared-function-info.h | 5 +++++ src/objects/shared-function-info.tq | 6 ++++-- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/builtins/x64/builtins-x64.cc b/src/builtins/x64/builtins-x64.cc index 0205e7ae96..f6597a0d91 100644 --- a/src/builtins/x64/builtins-x64.cc +++ b/src/builtins/x64/builtins-x64.cc @@ -1351,11 +1351,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) { __ LoadTaggedPointerField(rcx, FieldOperand(kInterpreterBytecodeArrayRegister, BaselineData::kBaselineCodeOffset)); - if (V8_EXTERNAL_CODE_SPACE_BOOL) { - // At this point |rcx| is still Code object, so "convert" it to CodeT. - __ LoadTaggedPointerField( - rcx, FieldOperand(rcx, Code::kCodeDataContainerOffset)); - } static_assert(kJavaScriptCallCodeStartRegister == rcx, "ABI mismatch"); ReplaceClosureCodeWithOptimizedCode( masm, rcx, closure, kInterpreterBytecodeArrayRegister, @@ -1544,7 +1539,11 @@ static void Generate_InterpreterEnterBytecode(MacroAssembler* masm) { __ LoadTaggedPointerField( rbx, FieldOperand(rbx, InterpreterData::kInterpreterTrampolineOffset)); - __ addq(rbx, Immediate(Code::kHeaderSize - kHeapObjectTag)); + if (V8_EXTERNAL_CODE_SPACE_BOOL) { + __ LoadCodeDataContainerEntry(rbx, rbx); + } else { + __ addq(rbx, Immediate(Code::kHeaderSize - kHeapObjectTag)); + } __ jmp(&trampoline_loaded, Label::kNear); __ bind(&builtin_trampoline); @@ -4433,6 +4432,9 @@ void Generate_BaselineEntry(MacroAssembler* masm, bool next_bytecode, FieldOperand(code_obj, SharedFunctionInfo::kFunctionDataOffset)); __ LoadTaggedPointerField( code_obj, FieldOperand(code_obj, BaselineData::kBaselineCodeOffset)); + if (V8_EXTERNAL_CODE_SPACE_BOOL) { + __ LoadCodeDataContainerCodeNonBuiltin(code_obj, code_obj); + } // Compute baseline pc for bytecode offset. ExternalReference get_baseline_pc_extref; diff --git a/src/codegen/code-stub-assembler.cc b/src/codegen/code-stub-assembler.cc index 896835c174..ba21b20b2f 100644 --- a/src/codegen/code-stub-assembler.cc +++ b/src/codegen/code-stub-assembler.cc @@ -14240,11 +14240,11 @@ TNode CodeStubAssembler::GetSharedFunctionInfoCode( // IsBaselineData: Execute baseline code BIND(&check_is_baseline_data); - TNode baseline_data = CAST(sfi_data); - TNode baseline_code = - CAST(LoadObjectField(baseline_data, BaselineData::kBaselineCodeOffset)); - sfi_code = baseline_code; - Goto(&done); + { + TNode baseline_code = LoadBaselineDataBaselineCode(CAST(sfi_data)); + sfi_code = FromCodeT(baseline_code); + Goto(&done); + } // IsUncompiledDataWithPreparseData | IsUncompiledDataWithoutPreparseData: // Compile lazy @@ -14264,8 +14264,11 @@ TNode CodeStubAssembler::GetSharedFunctionInfoCode( // This is the default branch, so assert that we have the expected data type. CSA_ASSERT(this, Word32Equal(data_type, Int32Constant(INTERPRETER_DATA_TYPE))); - sfi_code = CAST(LoadObjectField( - CAST(sfi_data), InterpreterData::kInterpreterTrampolineOffset)); + { + TNode trampoline = + LoadInterpreterDataInterpreterTrampoline(CAST(sfi_data)); + sfi_code = FromCodeT(trampoline); + } Goto(&done); #if V8_ENABLE_WEBASSEMBLY @@ -14288,6 +14291,7 @@ TNode CodeStubAssembler::GetSharedFunctionInfoCode( TNode CodeStubAssembler::AllocateFunctionWithMapAndContext( TNode map, TNode shared_info, TNode context) { + // TODO(v8:11880): avoid roundtrips between cdc and code. const TNode code = GetSharedFunctionInfoCode(shared_info); // TODO(ishell): All the callers of this function pass map loaded from diff --git a/src/objects/shared-function-info-inl.h b/src/objects/shared-function-info-inl.h index d86e4bc84f..847b4a36bd 100644 --- a/src/objects/shared-function-info-inl.h +++ b/src/objects/shared-function-info-inl.h @@ -98,9 +98,18 @@ OBJECT_CONSTRUCTORS_IMPL(InterpreterData, Struct) CAST_ACCESSOR(InterpreterData) ACCESSORS(InterpreterData, bytecode_array, BytecodeArray, kBytecodeArrayOffset) -ACCESSORS(InterpreterData, interpreter_trampoline, Code, +ACCESSORS(InterpreterData, raw_interpreter_trampoline, CodeT, kInterpreterTrampolineOffset) +DEF_GETTER(InterpreterData, interpreter_trampoline, Code) { + return FromCodeT(raw_interpreter_trampoline(cage_base)); +} + +void InterpreterData::set_interpreter_trampoline(Code code, + WriteBarrierMode mode) { + set_raw_interpreter_trampoline(ToCodeT(code), mode); +} + TQ_OBJECT_CONSTRUCTORS_IMPL(SharedFunctionInfo) NEVER_READ_ONLY_SPACE_IMPL(SharedFunctionInfo) DEFINE_DEOPT_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) @@ -504,6 +513,14 @@ BytecodeArray SharedFunctionInfo::GetBytecodeArray(IsolateT* isolate) const { return GetActiveBytecodeArray(); } +DEF_GETTER(BaselineData, baseline_code, Code) { + return FromCodeT(TorqueGeneratedClass::baseline_code(cage_base)); +} + +void BaselineData::set_baseline_code(Code code, WriteBarrierMode mode) { + return TorqueGeneratedClass::set_baseline_code(ToCodeT(code), mode); +} + BytecodeArray BaselineData::GetActiveBytecodeArray() const { Object data = this->data(); if (data.IsBytecodeArray()) { diff --git a/src/objects/shared-function-info.h b/src/objects/shared-function-info.h index 459acce0f5..4bbd580b95 100644 --- a/src/objects/shared-function-info.h +++ b/src/objects/shared-function-info.h @@ -153,6 +153,9 @@ class InterpreterData : public Struct { DECL_PRINTER(InterpreterData) DECL_VERIFIER(InterpreterData) + private: + DECL_ACCESSORS(raw_interpreter_trampoline, CodeT) + OBJECT_CONSTRUCTORS(InterpreterData, Struct); }; @@ -161,6 +164,8 @@ class BaselineData : public TorqueGeneratedBaselineData { inline BytecodeArray GetActiveBytecodeArray() const; inline void SetActiveBytecodeArray(BytecodeArray bytecode); + DECL_ACCESSORS(baseline_code, Code) + TQ_OBJECT_CONSTRUCTORS(BaselineData) }; diff --git a/src/objects/shared-function-info.tq b/src/objects/shared-function-info.tq index 7f7469f9c4..2a08c51088 100644 --- a/src/objects/shared-function-info.tq +++ b/src/objects/shared-function-info.tq @@ -11,13 +11,15 @@ extern class PreparseData extends HeapObject { extern class InterpreterData extends Struct { bytecode_array: BytecodeArray; - interpreter_trampoline: Code; + @if(V8_EXTERNAL_CODE_SPACE) interpreter_trampoline: CodeDataContainer; + @ifnot(V8_EXTERNAL_CODE_SPACE) interpreter_trampoline: Code; } @generateCppClass @generatePrint extern class BaselineData extends Struct { - baseline_code: Code; + @if(V8_EXTERNAL_CODE_SPACE) baseline_code: CodeDataContainer; + @ifnot(V8_EXTERNAL_CODE_SPACE) baseline_code: Code; data: BytecodeArray|InterpreterData; }