Commit a4c9cf49 authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space] Avoid Code <-> CodeT conversions in builtins, pt.2

Bug: v8:11880
Change-Id: Iffebca251d18d5637884b2181acdfb3e6c5496a0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3257715Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77682}
parent f5274dfe
......@@ -283,9 +283,8 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(
// which almost doubles the size of `await` builtins (unnecessarily).
TNode<Smi> builtin_id = LoadObjectField<Smi>(
shared_info, SharedFunctionInfo::kFunctionDataOffset);
TNode<Code> code = LoadBuiltin(builtin_id);
StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset,
ToCodeT(code));
TNode<CodeT> code = LoadBuiltin(builtin_id);
StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset, code);
}
TNode<JSFunction> AsyncBuiltinsAssembler::CreateUnwrapClosure(
......
......@@ -110,8 +110,9 @@ TF_BUILTIN(DebugBreakTrampoline, CodeStubAssembler) {
BIND(&tailcall_to_shared);
// Tail call into code object on the SharedFunctionInfo.
TNode<Code> code = GetSharedFunctionInfoCode(shared);
TailCallJSCode(code, context, function, new_target, arg_count);
TNode<CodeT> code = GetSharedFunctionInfoCode(shared);
// TODO(v8:11880): call CodeT directly.
TailCallJSCode(FromCodeT(code), context, function, new_target, arg_count);
}
class WriteBarrierCodeStubAssembler : public CodeStubAssembler {
......@@ -1325,7 +1326,7 @@ TF_BUILTIN(InstantiateAsmJs, CodeStubAssembler) {
// On failure, tail call back to regular JavaScript by re-calling the given
// function which has been reset to the compile lazy builtin.
// TODO(v8:11880): call CodeT instead.
// TODO(v8:11880): call CodeT directly.
TNode<Code> code = FromCodeT(LoadJSFunctionCode(function));
TailCallJSCode(code, context, function, new_target, arg_count);
}
......
......@@ -120,7 +120,7 @@ void LazyBuiltinsAssembler::CompileLazy(TNode<JSFunction> function) {
TNode<SharedFunctionInfo> shared =
CAST(LoadObjectField(function, JSFunction::kSharedFunctionInfoOffset));
TVARIABLE(Uint16T, sfi_data_type);
TNode<Code> sfi_code =
TNode<CodeT> sfi_code =
GetSharedFunctionInfoCode(shared, &sfi_data_type, &compile_function);
TNode<HeapObject> feedback_cell_value = LoadFeedbackCellValue(function);
......@@ -144,14 +144,14 @@ void LazyBuiltinsAssembler::CompileLazy(TNode<JSFunction> function) {
// optimized Code object (we'd have tail-called it above). A usual case would
// be the InterpreterEntryTrampoline to start executing existing bytecode.
BIND(&maybe_use_sfi_code);
CSA_DCHECK(this, TaggedNotEqual(sfi_code, HeapConstant(BUILTIN_CODE(
CSA_DCHECK(this, TaggedNotEqual(sfi_code, HeapConstant(BUILTIN_CODET(
isolate(), CompileLazy))));
StoreObjectField(function, JSFunction::kCodeOffset, ToCodeT(sfi_code));
StoreObjectField(function, JSFunction::kCodeOffset, sfi_code);
Label tailcall_code(this);
Label baseline(this);
TVARIABLE(Code, code);
TVARIABLE(CodeT, code);
// Check if we have baseline code.
GotoIf(InstanceTypeEqual(sfi_data_type.value(), CODET_TYPE), &baseline);
......@@ -161,17 +161,19 @@ void LazyBuiltinsAssembler::CompileLazy(TNode<JSFunction> function) {
BIND(&baseline);
// Ensure we have a feedback vector.
code = Select<Code>(
code = Select<CodeT>(
IsFeedbackVector(feedback_cell_value), [=]() { return sfi_code; },
[=]() {
return CAST(CallRuntime(Runtime::kInstallBaselineCode,
Parameter<Context>(Descriptor::kContext),
function));
// TODO(v8:11880): avoid roundtrips between cdc and code.
return ToCodeT(CAST(
CallRuntime(Runtime::kInstallBaselineCode,
Parameter<Context>(Descriptor::kContext), function)));
});
Goto(&tailcall_code);
BIND(&tailcall_code);
// Jump to the selected code entry.
GenerateTailCallToJSCode(code.value(), function);
// TODO(v8:11880): call CodeT directly.
GenerateTailCallToJSCode(FromCodeT(code.value()), function);
BIND(&compile_function);
GenerateTailCallToReturnedCode(Runtime::kCompileLazy, function);
......
......@@ -14332,24 +14332,30 @@ TNode<BoolT> CodeStubAssembler::NeedsAnyPromiseHooks(TNode<Uint32T> flags) {
return Word32NotEqual(flags, Int32Constant(0));
}
TNode<Code> CodeStubAssembler::LoadBuiltin(TNode<Smi> builtin_id) {
TNode<CodeT> CodeStubAssembler::LoadBuiltin(TNode<Smi> builtin_id) {
CSA_DCHECK(this, SmiBelow(builtin_id, SmiConstant(Builtins::kBuiltinCount)));
TNode<IntPtrT> offset =
ElementOffsetFromIndex(SmiToBInt(builtin_id), SYSTEM_POINTER_ELEMENTS);
return CAST(BitcastWordToTagged(Load<RawPtrT>(
ExternalConstant(ExternalReference::builtins_address(isolate())),
offset)));
TNode<ExternalReference> table = ExternalConstant(
#ifdef V8_EXTERNAL_CODE_SPACE
ExternalReference::builtins_code_data_container_table(isolate())
#else
ExternalReference::builtins_table(isolate())
#endif // V8_EXTERNAL_CODE_SPACE
); // NOLINT(whitespace/parens)
return CAST(BitcastWordToTagged(Load<RawPtrT>(table, offset)));
}
TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
TNode<CodeT> CodeStubAssembler::GetSharedFunctionInfoCode(
TNode<SharedFunctionInfo> shared_info, TVariable<Uint16T>* data_type_out,
Label* if_compile_lazy) {
TNode<Object> sfi_data =
LoadObjectField(shared_info, SharedFunctionInfo::kFunctionDataOffset);
TVARIABLE(Code, sfi_code);
TVARIABLE(CodeT, sfi_code);
Label done(this);
Label check_instance_type(this);
......@@ -14413,14 +14419,14 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
// IsBytecodeArray: Interpret bytecode
BIND(&check_is_bytecode_array);
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), InterpreterEntryTrampoline));
sfi_code = HeapConstant(BUILTIN_CODET(isolate(), InterpreterEntryTrampoline));
Goto(&done);
// IsBaselineData: Execute baseline code
BIND(&check_is_baseline_data);
{
TNode<CodeT> baseline_code = CAST(sfi_data);
sfi_code = FromCodeT(baseline_code);
sfi_code = baseline_code;
Goto(&done);
}
......@@ -14429,12 +14435,12 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
BIND(&check_is_uncompiled_data_with_preparse_data);
Goto(&check_is_uncompiled_data_without_preparse_data);
BIND(&check_is_uncompiled_data_without_preparse_data);
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), CompileLazy));
sfi_code = HeapConstant(BUILTIN_CODET(isolate(), CompileLazy));
Goto(if_compile_lazy ? if_compile_lazy : &done);
// IsFunctionTemplateInfo: API call
BIND(&check_is_function_template_info);
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), HandleApiCall));
sfi_code = HeapConstant(BUILTIN_CODET(isolate(), HandleApiCall));
Goto(&done);
// IsInterpreterData: Interpret bytecode
......@@ -14445,7 +14451,7 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
{
TNode<CodeT> trampoline =
LoadInterpreterDataInterpreterTrampoline(CAST(sfi_data));
sfi_code = FromCodeT(trampoline);
sfi_code = trampoline;
}
Goto(&done);
......@@ -14458,7 +14464,7 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
// IsAsmWasmData: Instantiate using AsmWasmData
BIND(&check_is_asm_wasm_data);
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), InstantiateAsmJs));
sfi_code = HeapConstant(BUILTIN_CODET(isolate(), InstantiateAsmJs));
Goto(&done);
#endif // V8_ENABLE_WEBASSEMBLY
......@@ -14482,8 +14488,7 @@ TNode<RawPtrT> CodeStubAssembler::GetCodeEntry(TNode<CodeT> code) {
TNode<JSFunction> CodeStubAssembler::AllocateFunctionWithMapAndContext(
TNode<Map> map, TNode<SharedFunctionInfo> shared_info,
TNode<Context> context) {
// TODO(v8:11880): avoid roundtrips between cdc and code.
const TNode<Code> code = GetSharedFunctionInfoCode(shared_info);
const TNode<CodeT> code = GetSharedFunctionInfoCode(shared_info);
// TODO(ishell): All the callers of this function pass map loaded from
// Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX. So we can remove
......@@ -14502,7 +14507,7 @@ TNode<JSFunction> CodeStubAssembler::AllocateFunctionWithMapAndContext(
StoreObjectFieldNoWriteBarrier(fun, JSFunction::kSharedFunctionInfoOffset,
shared_info);
StoreObjectFieldNoWriteBarrier(fun, JSFunction::kContextOffset, context);
StoreObjectField(fun, JSFunction::kCodeOffset, ToCodeT(code));
StoreObjectField(fun, JSFunction::kCodeOffset, code);
return CAST(fun);
}
......
......@@ -3629,7 +3629,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
ElementsKind kind = HOLEY_ELEMENTS);
// Load a builtin's code from the builtin array in the isolate.
TNode<Code> LoadBuiltin(TNode<Smi> builtin_id);
TNode<CodeT> LoadBuiltin(TNode<Smi> builtin_id);
// Figure out the SFI's code object using its data field.
// If |data_type_out| is provided, the instance type of the function data will
......@@ -3637,7 +3637,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// data_type_out will be set to 0.
// If |if_compile_lazy| is provided then the execution will go to the given
// label in case of an CompileLazy code object.
TNode<Code> GetSharedFunctionInfoCode(
TNode<CodeT> GetSharedFunctionInfoCode(
TNode<SharedFunctionInfo> shared_info,
TVariable<Uint16T>* data_type_out = nullptr,
Label* if_compile_lazy = nullptr);
......
......@@ -198,10 +198,17 @@ ExternalReference ExternalReference::isolate_address(Isolate* isolate) {
return ExternalReference(isolate);
}
ExternalReference ExternalReference::builtins_address(Isolate* isolate) {
ExternalReference ExternalReference::builtins_table(Isolate* isolate) {
return ExternalReference(isolate->builtin_table());
}
#ifdef V8_EXTERNAL_CODE_SPACE
ExternalReference ExternalReference::builtins_code_data_container_table(
Isolate* isolate) {
return ExternalReference(isolate->builtin_code_data_container_table());
}
#endif // V8_EXTERNAL_CODE_SPACE
ExternalReference ExternalReference::handle_scope_implementer_address(
Isolate* isolate) {
return ExternalReference(isolate->handle_scope_implementer_address());
......
......@@ -24,7 +24,7 @@ class StatsCounter;
#define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(V) \
V(isolate_address, "isolate") \
V(builtins_address, "builtins") \
V(builtins_table, "builtins_table") \
V(handle_scope_implementer_address, \
"Isolate::handle_scope_implementer_address") \
V(address_of_interpreter_entry_trampoline_instruction_start, \
......@@ -78,8 +78,16 @@ class StatsCounter;
V(thread_in_wasm_flag_address_address, \
"Isolate::thread_in_wasm_flag_address_address") \
V(javascript_execution_assert, "javascript_execution_assert") \
EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_EXTERNAL_CODE_SPACE(V) \
EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V)
#ifdef V8_EXTERNAL_CODE_SPACE
#define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_EXTERNAL_CODE_SPACE(V) \
V(builtins_code_data_container_table, "builtins_code_data_container_table")
#else
#define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_EXTERNAL_CODE_SPACE(V)
#endif // V8_EXTERNAL_CODE_SPACE
#ifdef V8_HEAP_SANDBOX
#define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V) \
V(external_pointer_table_address, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment