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

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

Bug: v8:11880
Change-Id: Ib0997ca8cedaf1065fc6803d5297c30621b49949
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3257714Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77680}
parent 9fcb9693
......@@ -254,11 +254,9 @@ TF_BUILTIN(FastNewClosure, ConstructorBuiltinsAssembler) {
StoreObjectFieldNoWriteBarrier(result, JSFunction::kSharedFunctionInfoOffset,
shared_function_info);
StoreObjectFieldNoWriteBarrier(result, JSFunction::kContextOffset, context);
Handle<Code> lazy_builtin_handle = BUILTIN_CODE(isolate(), CompileLazy);
// TODO(v8:11880): support embedding of CodeDataContainers.
TNode<Code> lazy_builtin = HeapConstant(lazy_builtin_handle);
StoreObjectFieldNoWriteBarrier(result, JSFunction::kCodeOffset,
ToCodeT(lazy_builtin));
TNode<CodeT> lazy_builtin =
HeapConstant(BUILTIN_CODET(isolate(), CompileLazy));
StoreObjectFieldNoWriteBarrier(result, JSFunction::kCodeOffset, lazy_builtin);
Return(result);
}
......
......@@ -78,14 +78,13 @@ void LazyBuiltinsAssembler::MaybeTailCallOptimizedCodeSlot(
feedback_vector, FeedbackVector::kMaybeOptimizedCodeOffset);
// Optimized code slot is a weak reference to CodeT object.
TNode<CodeT> code_t = CAST(GetHeapObjectAssumeWeak(
TNode<CodeT> optimized_code = CAST(GetHeapObjectAssumeWeak(
maybe_optimized_code_entry, &heal_optimized_code_slot));
TNode<Code> optimized_code = FromCodeT(code_t);
// Check if the optimized code is marked for deopt. If it is, call the
// runtime to clear it.
TNode<CodeDataContainer> code_data_container =
CodeDataContainerFromCodeT(code_t);
CodeDataContainerFromCodeT(optimized_code);
TNode<Int32T> code_kind_specific_flags = LoadObjectField<Int32T>(
code_data_container, CodeDataContainer::kKindSpecificFlagsOffset);
GotoIf(IsSetWord32<Code::MarkedForDeoptimizationField>(
......@@ -94,11 +93,10 @@ void LazyBuiltinsAssembler::MaybeTailCallOptimizedCodeSlot(
// Optimized code is good, get it into the closure and link the closure into
// the optimized functions list, then tail call the optimized code.
StoreObjectField(function, JSFunction::kCodeOffset,
ToCodeT(optimized_code, code_data_container));
StoreObjectField(function, JSFunction::kCodeOffset, optimized_code);
Comment("MaybeTailCallOptimizedCodeSlot:: GenerateTailCallToJSCode");
// TODO(v8:11880): call CodeT directly.
GenerateTailCallToJSCode(optimized_code, function);
GenerateTailCallToJSCode(FromCodeT(optimized_code), function);
// Optimized code slot contains deoptimized code or code is cleared and
// optimized code marker isn't updated. Evict the code, update the marker
......@@ -188,13 +186,11 @@ TF_BUILTIN(CompileLazy, LazyBuiltinsAssembler) {
TF_BUILTIN(CompileLazyDeoptimizedCode, LazyBuiltinsAssembler) {
auto function = Parameter<JSFunction>(Descriptor::kTarget);
Handle<Code> compile_lazy = BUILTIN_CODE(isolate(), CompileLazy);
TNode<Code> code = HeapConstant(compile_lazy);
TNode<CodeT> code = HeapConstant(BUILTIN_CODET(isolate(), CompileLazy));
// Set the code slot inside the JSFunction to CompileLazy.
// TODO(v8:11880): support embedding of CodeDataContainer constants.
StoreObjectField(function, JSFunction::kCodeOffset, ToCodeT(code));
StoreObjectField(function, JSFunction::kCodeOffset, code);
// TODO(v8:11880): call CodeT directly.
GenerateTailCallToJSCode(code, function);
GenerateTailCallToJSCode(FromCodeT(code), function);
}
} // namespace internal
......
......@@ -47,7 +47,13 @@ TNode<IntPtrT> RegExpBuiltinsAssembler::IntPtrZero() {
// If code is a builtin, return the address to the (possibly embedded) builtin
// code entry, otherwise return the entry of the code object itself.
TNode<RawPtrT> RegExpBuiltinsAssembler::LoadCodeObjectEntry(TNode<Code> code) {
TNode<RawPtrT> RegExpBuiltinsAssembler::LoadCodeObjectEntry(TNode<CodeT> code) {
if (V8_EXTERNAL_CODE_SPACE_BOOL) {
// When external code space is enabled we can load the entry point directly
// from the CodeT object.
return GetCodeEntry(code);
}
TVARIABLE(RawPtrT, var_result);
Label if_code_is_off_heap(this), out(this);
......@@ -553,8 +559,7 @@ TNode<HeapObject> RegExpBuiltinsAssembler::RegExpExecInternal(
#endif
GotoIf(TaggedIsSmi(var_code.value()), &runtime);
// TODO(v8:11880): avoid roundtrips between cdc and code.
TNode<Code> code = FromCodeT(CAST(var_code.value()));
TNode<CodeT> code = CAST(var_code.value());
Label if_success(this), if_exception(this, Label::kDeferred);
{
......@@ -618,7 +623,6 @@ TNode<HeapObject> RegExpBuiltinsAssembler::RegExpExecInternal(
MachineType arg8_type = type_tagged;
TNode<JSRegExp> arg8 = regexp;
// TODO(v8:11880): avoid roundtrips between cdc and code.
TNode<RawPtrT> code_entry = LoadCodeObjectEntry(code);
// AIX uses function descriptors on CFunction calls. code_entry in this case
......
......@@ -21,7 +21,7 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
TNode<Smi> SmiZero();
TNode<IntPtrT> IntPtrZero();
TNode<RawPtrT> LoadCodeObjectEntry(TNode<Code> code);
TNode<RawPtrT> LoadCodeObjectEntry(TNode<CodeT> code);
// Allocate either a JSRegExpResult or a JSRegExpResultWithIndices (depending
// on has_indices) with the given length (the number of captures, including
......
......@@ -225,7 +225,7 @@ void AccessorAssembler::HandleLoadICHandlerCase(
BIND(&call_handler);
{
// TODO(v8:11880): avoid roundtrips between cdc and code.
// TODO(v8:11880): call CodeT directly.
TNode<Code> code_handler = FromCodeT(CAST(handler));
exit_point->ReturnCallStub(LoadWithVectorDescriptor{}, code_handler,
p->context(), p->lookup_start_object(),
......@@ -988,8 +988,7 @@ TNode<Object> AccessorAssembler::HandleProtoHandler(
if (on_code_handler) {
Label if_smi_handler(this);
GotoIf(TaggedIsSmi(smi_or_code_handler), &if_smi_handler);
// TODO(v8:11880): avoid roundtrips between cdc and code.
TNode<Code> code = FromCodeT(CAST(smi_or_code_handler));
TNode<CodeT> code = CAST(smi_or_code_handler);
on_code_handler(code);
BIND(&if_smi_handler);
......@@ -1323,7 +1322,7 @@ void AccessorAssembler::HandleStoreICHandlerCase(
// |handler| is a heap object. Must be code, call it.
BIND(&call_handler);
{
// TODO(v8:11880): avoid roundtrips between cdc and code.
// TODO(v8:11880): call CodeT directly.
TNode<Code> code_handler = FromCodeT(CAST(strong_handler));
TailCallStub(StoreWithVectorDescriptor{}, code_handler, p->context(),
p->receiver(), p->name(), p->value(), p->slot(),
......@@ -1693,16 +1692,17 @@ void AccessorAssembler::HandleStoreICProtoHandler(
OnCodeHandler on_code_handler;
if (support_elements == kSupportElements) {
// Code sub-handlers are expected only in KeyedStoreICs.
on_code_handler = [=](TNode<Code> code_handler) {
on_code_handler = [=](TNode<CodeT> code_handler) {
// This is either element store or transitioning element store.
Label if_element_store(this), if_transitioning_element_store(this);
Branch(IsStoreHandler0Map(LoadMap(handler)), &if_element_store,
&if_transitioning_element_store);
BIND(&if_element_store);
{
TailCallStub(StoreWithVectorDescriptor{}, code_handler, p->context(),
p->receiver(), p->name(), p->value(), p->slot(),
p->vector());
// TODO(v8:11880): call CodeT directly.
TailCallStub(StoreWithVectorDescriptor{}, FromCodeT(code_handler),
p->context(), p->receiver(), p->name(), p->value(),
p->slot(), p->vector());
}
BIND(&if_transitioning_element_store);
......@@ -1714,9 +1714,10 @@ void AccessorAssembler::HandleStoreICProtoHandler(
GotoIf(IsDeprecatedMap(transition_map), miss);
TailCallStub(StoreTransitionDescriptor{}, code_handler, p->context(),
p->receiver(), p->name(), transition_map, p->value(),
p->slot(), p->vector());
// TODO(v8:11880): call CodeT directly.
TailCallStub(StoreTransitionDescriptor{}, FromCodeT(code_handler),
p->context(), p->receiver(), p->name(), transition_map,
p->value(), p->slot(), p->vector());
}
};
}
......@@ -3963,7 +3964,7 @@ void AccessorAssembler::StoreInArrayLiteralIC(const StoreICParameters* p) {
{
// Call the handler.
// TODO(v8:11880): avoid roundtrips between cdc and code.
// TODO(v8:11880): call CodeT directly.
TNode<Code> code_handler = FromCodeT(CAST(handler));
TailCallStub(StoreWithVectorDescriptor{}, code_handler, p->context(),
p->receiver(), p->name(), p->value(), p->slot(),
......@@ -3977,7 +3978,7 @@ void AccessorAssembler::StoreInArrayLiteralIC(const StoreICParameters* p) {
TNode<Map> transition_map =
CAST(GetHeapObjectAssumeWeak(maybe_transition_map, &miss));
GotoIf(IsDeprecatedMap(transition_map), &miss);
// TODO(v8:11880): avoid roundtrips between cdc and code.
// TODO(v8:11880): call CodeT directly.
TNode<Code> code = FromCodeT(
CAST(LoadObjectField(handler, StoreHandler::kSmiHandlerOffset)));
TailCallStub(StoreTransitionDescriptor{}, code, p->context(),
......
......@@ -468,7 +468,7 @@ class V8_EXPORT_PRIVATE AccessorAssembler : public CodeStubAssembler {
// Low-level helpers.
using OnCodeHandler = std::function<void(TNode<Code> code_handler)>;
using OnCodeHandler = std::function<void(TNode<CodeT> code_handler)>;
using OnFoundOnLookupStartObject = std::function<void(
TNode<PropertyDictionary> properties, TNode<IntPtrT> name_index)>;
......
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