[fastcall] Set no JS execution flag from TurboFan

This CL implements setting the javascript_execution_assert
on the isolate from generated code, so we don't need to create
an expensive class in the embedder callback.

Bug: chromium:1218898
Change-Id: Ia05b49281ab4c1cc3ac34caf2dfadb79feb86e84
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2982998
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75414}
This commit is contained in:
Maya Lekova 2021-06-28 14:54:09 +02:00 committed by V8 LUCI CQ
parent edab873071
commit c8e544fda8
4 changed files with 80 additions and 20 deletions

View File

@ -738,6 +738,11 @@ ExternalReference ExternalReference::address_of_regexp_stack_memory_top_address(
isolate->regexp_stack()->memory_top_address_address());
}
ExternalReference ExternalReference::javascript_execution_assert(
Isolate* isolate) {
return ExternalReference(isolate->javascript_execution_assert_address());
}
FUNCTION_REFERENCE_WITH_TYPE(ieee754_acos_function, base::ieee754::acos,
BUILTIN_FP_CALL)
FUNCTION_REFERENCE_WITH_TYPE(ieee754_acosh_function, base::ieee754::acosh,

View File

@ -83,6 +83,7 @@ class StatsCounter;
"RegExpMacroAssembler*::CheckStackGuardState()") \
V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()") \
V(re_word_character_map, "NativeRegExpMacroAssembler::word_character_map") \
V(javascript_execution_assert, "javascript_execution_assert") \
EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V)
#ifdef V8_HEAP_SANDBOX

View File

@ -198,6 +198,12 @@ class EffectControlLinearizer {
Node* LowerLoadMessage(Node* node);
Node* AdaptFastCallArgument(Node* node, CTypeInfo arg_type,
GraphAssemblerLabel<0>* if_error);
Node* PrepareFastCall(Node* target);
Node* GenerateFastCallAndCleanup(const CallDescriptor* call_descriptor,
int inputs_size, Node** inputs,
Node* target_address,
const CFunctionInfo* c_signature,
int c_arg_count, Node* stack_slot);
Node* LowerFastApiCall(Node* node);
Node* LowerLoadTypedElement(Node* node);
Node* LowerLoadDataViewElement(Node* node);
@ -5039,6 +5045,66 @@ Node* EffectControlLinearizer::AdaptFastCallArgument(
}
}
Node* EffectControlLinearizer::PrepareFastCall(Node* target) {
Node* target_address = __ ExternalConstant(
ExternalReference::fast_api_call_target_address(isolate()));
// CPU profiler support
__ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier),
target_address, 0, target);
return target_address;
}
Node* EffectControlLinearizer::GenerateFastCallAndCleanup(
const CallDescriptor* call_descriptor, int inputs_size, Node** inputs,
Node* target_address, const CFunctionInfo* c_signature, int c_arg_count,
Node* stack_slot) {
// Disable JS execution
Node* javascript_execution_assert = __ ExternalConstant(
ExternalReference::javascript_execution_assert(isolate()));
static_assert(sizeof(bool) == 1, "Wrong assumption about boolean size.");
if (FLAG_debug_code) {
auto do_store = __ MakeLabel();
Node* old_scope_value =
__ Load(MachineType::Int8(), javascript_execution_assert, 0);
__ GotoIf(__ Word32Equal(old_scope_value, __ Int32Constant(1)), &do_store);
// We expect that JS execution is enabled, otherwise assert.
__ Unreachable(&do_store);
__ Bind(&do_store);
}
__ Store(StoreRepresentation(MachineRepresentation::kWord8, kNoWriteBarrier),
javascript_execution_assert, 0, __ Int32Constant(0));
// Update effect and control
if (c_signature->HasOptions()) {
inputs[c_arg_count + 1] = stack_slot;
inputs[c_arg_count + 2] = __ effect();
inputs[c_arg_count + 3] = __ control();
} else {
inputs[c_arg_count + 1] = __ effect();
inputs[c_arg_count + 2] = __ control();
}
// Create the fast call
Node* call = __ Call(call_descriptor, inputs_size, inputs);
// Reenable JS execution
__ Store(StoreRepresentation(MachineRepresentation::kWord8, kNoWriteBarrier),
javascript_execution_assert, 0, __ Int32Constant(1));
// Reset the CPU profiler target address.
__ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier),
target_address, 0, __ IntPtrConstant(0));
return call;
}
Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
FastApiCallNode n(node);
FastApiCallParameters const& params = n.Parameters();
@ -5090,12 +5156,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
call_descriptor->SetCFunctionInfo(c_signature);
// CPU profiler support
Node* target_address = __ ExternalConstant(
ExternalReference::fast_api_call_target_address(isolate()));
__ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier),
target_address, 0, n.target());
Node* target_address = PrepareFastCall(n.target());
Node** const inputs = graph()->zone()->NewArray<Node*>(
c_arg_count + n.FastCallExtraInputCount());
@ -5111,21 +5172,10 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
CTypeInfo type = c_signature->ArgumentInfo(i - 1);
inputs[i] = AdaptFastCallArgument(value, type, &if_error);
}
if (c_signature->HasOptions()) {
inputs[c_arg_count + 1] = stack_slot;
inputs[c_arg_count + 2] = __ effect();
inputs[c_arg_count + 3] = __ control();
} else {
inputs[c_arg_count + 1] = __ effect();
inputs[c_arg_count + 2] = __ control();
}
Node* c_call_result = __ Call(
call_descriptor, c_arg_count + n.FastCallExtraInputCount(), inputs);
__ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier),
target_address, 0, __ IntPtrConstant(0));
Node* c_call_result = GenerateFastCallAndCleanup(
call_descriptor, c_arg_count + n.FastCallExtraInputCount(), inputs,
target_address, c_signature, c_arg_count, stack_slot);
Node* fast_call_result;
switch (c_signature->ReturnInfo().GetType()) {

View File

@ -1516,6 +1516,10 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
return reinterpret_cast<Address>(&async_event_delegate_);
}
Address javascript_execution_assert_address() {
return reinterpret_cast<Address>(&javascript_execution_assert_);
}
Address handle_scope_implementer_address() {
return reinterpret_cast<Address>(&handle_scope_implementer_);
}