Commit c573dcc8 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[isolate] Minor cleanup for exceptions

* Avoid accessing thread_local_top directly and use getters:
  - scheduled_exception
  - pending_exception
  - pending_message

* Rename pending_message_obj to pending_message

Bug: chromium:1014421
Change-Id: I080b7d5919e180a943776c79ee9321235d58d3c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3010278Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75864}
parent 4fafd076
...@@ -2053,7 +2053,7 @@ void BaselineCompiler::VisitSetPendingMessage() { ...@@ -2053,7 +2053,7 @@ void BaselineCompiler::VisitSetPendingMessage() {
BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_);
Register pending_message = scratch_scope.AcquireScratch(); Register pending_message = scratch_scope.AcquireScratch();
__ Move(pending_message, __ Move(pending_message,
ExternalReference::address_of_pending_message_obj(isolate_)); ExternalReference::address_of_pending_message(isolate_));
Register tmp = scratch_scope.AcquireScratch(); Register tmp = scratch_scope.AcquireScratch();
__ Move(tmp, kInterpreterAccumulatorRegister); __ Move(tmp, kInterpreterAccumulatorRegister);
__ Move(kInterpreterAccumulatorRegister, MemOperand(pending_message, 0)); __ Move(kInterpreterAccumulatorRegister, MemOperand(pending_message, 0));
......
...@@ -492,9 +492,9 @@ ExternalReference ExternalReference::scheduled_exception_address( ...@@ -492,9 +492,9 @@ ExternalReference ExternalReference::scheduled_exception_address(
return ExternalReference(isolate->scheduled_exception_address()); return ExternalReference(isolate->scheduled_exception_address());
} }
ExternalReference ExternalReference::address_of_pending_message_obj( ExternalReference ExternalReference::address_of_pending_message(
Isolate* isolate) { Isolate* isolate) {
return ExternalReference(isolate->pending_message_obj_address()); return ExternalReference(isolate->pending_message_address());
} }
FUNCTION_REFERENCE(abort_with_reason, i::abort_with_reason) FUNCTION_REFERENCE(abort_with_reason, i::abort_with_reason)
......
...@@ -49,7 +49,7 @@ class StatsCounter; ...@@ -49,7 +49,7 @@ class StatsCounter;
V(handle_scope_next_address, "HandleScope::next") \ V(handle_scope_next_address, "HandleScope::next") \
V(handle_scope_limit_address, "HandleScope::limit") \ V(handle_scope_limit_address, "HandleScope::limit") \
V(scheduled_exception_address, "Isolate::scheduled_exception") \ V(scheduled_exception_address, "Isolate::scheduled_exception") \
V(address_of_pending_message_obj, "address_of_pending_message_obj") \ V(address_of_pending_message, "address_of_pending_message") \
V(promise_hook_flags_address, "Isolate::promise_hook_flags_address()") \ V(promise_hook_flags_address, "Isolate::promise_hook_flags_address()") \
V(promise_hook_address, "Isolate::promise_hook_address()") \ V(promise_hook_address, "Isolate::promise_hook_address()") \
V(async_event_delegate_address, "Isolate::async_event_delegate_address()") \ V(async_event_delegate_address, "Isolate::async_event_delegate_address()") \
......
...@@ -2079,7 +2079,7 @@ Reduction JSTypedLowering::ReduceJSForInPrepare(Node* node) { ...@@ -2079,7 +2079,7 @@ Reduction JSTypedLowering::ReduceJSForInPrepare(Node* node) {
Reduction JSTypedLowering::ReduceJSLoadMessage(Node* node) { Reduction JSTypedLowering::ReduceJSLoadMessage(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadMessage, node->opcode()); DCHECK_EQ(IrOpcode::kJSLoadMessage, node->opcode());
ExternalReference const ref = ExternalReference const ref =
ExternalReference::address_of_pending_message_obj(isolate()); ExternalReference::address_of_pending_message(isolate());
node->ReplaceInput(0, jsgraph()->ExternalConstant(ref)); node->ReplaceInput(0, jsgraph()->ExternalConstant(ref));
NodeProperties::ChangeOp(node, simplified()->LoadMessage()); NodeProperties::ChangeOp(node, simplified()->LoadMessage());
return Changed(node); return Changed(node);
...@@ -2088,7 +2088,7 @@ Reduction JSTypedLowering::ReduceJSLoadMessage(Node* node) { ...@@ -2088,7 +2088,7 @@ Reduction JSTypedLowering::ReduceJSLoadMessage(Node* node) {
Reduction JSTypedLowering::ReduceJSStoreMessage(Node* node) { Reduction JSTypedLowering::ReduceJSStoreMessage(Node* node) {
DCHECK_EQ(IrOpcode::kJSStoreMessage, node->opcode()); DCHECK_EQ(IrOpcode::kJSStoreMessage, node->opcode());
ExternalReference const ref = ExternalReference const ref =
ExternalReference::address_of_pending_message_obj(isolate()); ExternalReference::address_of_pending_message(isolate());
Node* value = NodeProperties::GetValueInput(node, 0); Node* value = NodeProperties::GetValueInput(node, 0);
node->ReplaceInput(0, jsgraph()->ExternalConstant(ref)); node->ReplaceInput(0, jsgraph()->ExternalConstant(ref));
node->ReplaceInput(1, value); node->ReplaceInput(1, value);
......
...@@ -1974,7 +1974,7 @@ base::Optional<Object> Debug::OnThrow(Handle<Object> exception) { ...@@ -1974,7 +1974,7 @@ base::Optional<Object> Debug::OnThrow(Handle<Object> exception) {
maybe_promise->IsJSPromise() ? v8::debug::kPromiseRejection maybe_promise->IsJSPromise() ? v8::debug::kPromiseRejection
: v8::debug::kException); : v8::debug::kException);
if (!scheduled_exception.is_null()) { if (!scheduled_exception.is_null()) {
isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; isolate_->set_scheduled_exception(*scheduled_exception);
} }
PrepareStepOnThrow(); PrepareStepOnThrow();
// If the OnException handler requested termination, then indicated this to // If the OnException handler requested termination, then indicated this to
......
...@@ -33,6 +33,22 @@ NativeContext Isolate::raw_native_context() { ...@@ -33,6 +33,22 @@ NativeContext Isolate::raw_native_context() {
return context().native_context(); return context().native_context();
} }
void Isolate::set_pending_message(Object message_obj) {
thread_local_top()->pending_message_ = message_obj;
}
Object Isolate::pending_message() {
return thread_local_top()->pending_message_;
}
void Isolate::clear_pending_message() {
set_pending_message(ReadOnlyRoots(this).the_hole_value());
}
bool Isolate::has_pending_message() {
return !pending_message().IsTheHole(this);
}
Object Isolate::pending_exception() { Object Isolate::pending_exception() {
DCHECK(has_pending_exception()); DCHECK(has_pending_exception());
DCHECK(!thread_local_top()->pending_exception_.IsException(this)); DCHECK(!thread_local_top()->pending_exception_.IsException(this));
...@@ -54,11 +70,6 @@ bool Isolate::has_pending_exception() { ...@@ -54,11 +70,6 @@ bool Isolate::has_pending_exception() {
return !thread_local_top()->pending_exception_.IsTheHole(this); return !thread_local_top()->pending_exception_.IsTheHole(this);
} }
void Isolate::clear_pending_message() {
thread_local_top()->pending_message_obj_ =
ReadOnlyRoots(this).the_hole_value();
}
Object Isolate::scheduled_exception() { Object Isolate::scheduled_exception() {
DCHECK(has_scheduled_exception()); DCHECK(has_scheduled_exception());
DCHECK(!thread_local_top()->scheduled_exception_.IsException(this)); DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
...@@ -73,8 +84,11 @@ bool Isolate::has_scheduled_exception() { ...@@ -73,8 +84,11 @@ bool Isolate::has_scheduled_exception() {
void Isolate::clear_scheduled_exception() { void Isolate::clear_scheduled_exception() {
DCHECK(!thread_local_top()->scheduled_exception_.IsException(this)); DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
thread_local_top()->scheduled_exception_ = set_scheduled_exception(ReadOnlyRoots(this).the_hole_value());
ReadOnlyRoots(this).the_hole_value(); }
void Isolate::set_scheduled_exception(Object exception) {
thread_local_top()->scheduled_exception_ = exception;
} }
bool Isolate::is_catchable_by_javascript(Object exception) { bool Isolate::is_catchable_by_javascript(Object exception) {
......
...@@ -511,7 +511,7 @@ void Isolate::Iterate(RootVisitor* v, ThreadLocalTop* thread) { ...@@ -511,7 +511,7 @@ void Isolate::Iterate(RootVisitor* v, ThreadLocalTop* thread) {
v->VisitRootPointer(Root::kStackRoots, nullptr, v->VisitRootPointer(Root::kStackRoots, nullptr,
FullObjectSlot(&thread->pending_exception_)); FullObjectSlot(&thread->pending_exception_));
v->VisitRootPointer(Root::kStackRoots, nullptr, v->VisitRootPointer(Root::kStackRoots, nullptr,
FullObjectSlot(&thread->pending_message_obj_)); FullObjectSlot(&thread->pending_message_));
v->VisitRootPointer(Root::kStackRoots, nullptr, v->VisitRootPointer(Root::kStackRoots, nullptr,
FullObjectSlot(&thread->context_)); FullObjectSlot(&thread->context_));
v->VisitRootPointer(Root::kStackRoots, nullptr, v->VisitRootPointer(Root::kStackRoots, nullptr,
...@@ -1658,7 +1658,7 @@ Object Isolate::ThrowInternal(Object raw_exception, MessageLocation* location) { ...@@ -1658,7 +1658,7 @@ Object Isolate::ThrowInternal(Object raw_exception, MessageLocation* location) {
ReportBootstrappingException(exception, location); ReportBootstrappingException(exception, location);
} else { } else {
Handle<Object> message_obj = CreateMessageOrAbort(exception, location); Handle<Object> message_obj = CreateMessageOrAbort(exception, location);
thread_local_top()->pending_message_obj_ = *message_obj; set_pending_message(*message_obj);
} }
} }
...@@ -2086,7 +2086,7 @@ void Isolate::ScheduleThrow(Object exception) { ...@@ -2086,7 +2086,7 @@ void Isolate::ScheduleThrow(Object exception) {
Throw(exception); Throw(exception);
PropagatePendingExceptionToExternalTryCatch(); PropagatePendingExceptionToExternalTryCatch();
if (has_pending_exception()) { if (has_pending_exception()) {
thread_local_top()->scheduled_exception_ = pending_exception(); set_scheduled_exception(pending_exception());
thread_local_top()->external_caught_exception_ = false; thread_local_top()->external_caught_exception_ = false;
clear_pending_exception(); clear_pending_exception();
} }
...@@ -2099,7 +2099,7 @@ void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) { ...@@ -2099,7 +2099,7 @@ void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) {
DCHECK(handler->capture_message_); DCHECK(handler->capture_message_);
Object message(reinterpret_cast<Address>(handler->message_obj_)); Object message(reinterpret_cast<Address>(handler->message_obj_));
DCHECK(message.IsJSMessageObject() || message.IsTheHole(this)); DCHECK(message.IsJSMessageObject() || message.IsTheHole(this));
thread_local_top()->pending_message_obj_ = message; set_pending_message(message);
} }
void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) { void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) {
...@@ -2118,7 +2118,7 @@ void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) { ...@@ -2118,7 +2118,7 @@ void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) {
clear_scheduled_exception(); clear_scheduled_exception();
} }
} }
if (reinterpret_cast<void*>(thread_local_top()->pending_message_obj_.ptr()) == if (reinterpret_cast<void*>(thread_local_top()->pending_message_.ptr()) ==
handler->message_obj_) { handler->message_obj_) {
clear_pending_message(); clear_pending_message();
} }
...@@ -2331,7 +2331,7 @@ void Isolate::ReportPendingMessages() { ...@@ -2331,7 +2331,7 @@ void Isolate::ReportPendingMessages() {
if (!has_been_propagated) return; if (!has_been_propagated) return;
// Clear the pending message object early to avoid endless recursion. // Clear the pending message object early to avoid endless recursion.
Object message_obj = thread_local_top()->pending_message_obj_; Object message_obj = pending_message();
clear_pending_message(); clear_pending_message();
// For uncatchable exceptions we do nothing. If needed, the exception and the // For uncatchable exceptions we do nothing. If needed, the exception and the
...@@ -2402,7 +2402,7 @@ bool Isolate::OptionalRescheduleException(bool clear_exception) { ...@@ -2402,7 +2402,7 @@ bool Isolate::OptionalRescheduleException(bool clear_exception) {
} }
// Reschedule the exception. // Reschedule the exception.
thread_local_top()->scheduled_exception_ = pending_exception(); set_scheduled_exception(pending_exception());
clear_pending_exception(); clear_pending_exception();
return true; return true;
} }
...@@ -3336,16 +3336,14 @@ bool Isolate::PropagatePendingExceptionToExternalTryCatch() { ...@@ -3336,16 +3336,14 @@ bool Isolate::PropagatePendingExceptionToExternalTryCatch() {
SetTerminationOnExternalTryCatch(); SetTerminationOnExternalTryCatch();
} else { } else {
v8::TryCatch* handler = try_catch_handler(); v8::TryCatch* handler = try_catch_handler();
DCHECK(thread_local_top()->pending_message_obj_.IsJSMessageObject() || DCHECK(pending_message().IsJSMessageObject() ||
thread_local_top()->pending_message_obj_.IsTheHole(this)); pending_message().IsTheHole(this));
handler->can_continue_ = true; handler->can_continue_ = true;
handler->has_terminated_ = false; handler->has_terminated_ = false;
handler->exception_ = reinterpret_cast<void*>(pending_exception().ptr()); handler->exception_ = reinterpret_cast<void*>(pending_exception().ptr());
// Propagate to the external try-catch only if we got an actual message. // Propagate to the external try-catch only if we got an actual message.
if (thread_local_top()->pending_message_obj_.IsTheHole(this)) return true; if (!has_pending_message()) return true;
handler->message_obj_ = reinterpret_cast<void*>(pending_message().ptr());
handler->message_obj_ =
reinterpret_cast<void*>(thread_local_top()->pending_message_obj_.ptr());
} }
return true; return true;
} }
......
...@@ -706,11 +706,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -706,11 +706,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
return thread_local_top()->thread_id_.load(std::memory_order_relaxed); return thread_local_top()->thread_id_.load(std::memory_order_relaxed);
} }
// Interface to pending exception.
inline Object pending_exception();
inline void set_pending_exception(Object exception_obj);
inline void clear_pending_exception();
void InstallConditionalFeatures(Handle<Context> context); void InstallConditionalFeatures(Handle<Context> context);
bool IsSharedArrayBufferConstructorEnabled(Handle<Context> context); bool IsSharedArrayBufferConstructorEnabled(Handle<Context> context);
...@@ -718,10 +713,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -718,10 +713,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool IsWasmSimdEnabled(Handle<Context> context); bool IsWasmSimdEnabled(Handle<Context> context);
bool AreWasmExceptionsEnabled(Handle<Context> context); bool AreWasmExceptionsEnabled(Handle<Context> context);
THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception)
inline bool has_pending_exception();
THREAD_LOCAL_TOP_ADDRESS(Context, pending_handler_context) THREAD_LOCAL_TOP_ADDRESS(Context, pending_handler_context)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_entrypoint) THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_entrypoint)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_constant_pool) THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_constant_pool)
...@@ -733,20 +724,27 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -733,20 +724,27 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
v8::TryCatch* try_catch_handler() { v8::TryCatch* try_catch_handler() {
return thread_local_top()->try_catch_handler_; return thread_local_top()->try_catch_handler_;
} }
bool* external_caught_exception_address() {
return &thread_local_top()->external_caught_exception_;
}
THREAD_LOCAL_TOP_ADDRESS(Object, scheduled_exception) THREAD_LOCAL_TOP_ADDRESS(bool, external_caught_exception)
// Interface to pending exception.
THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception)
inline Object pending_exception();
inline void set_pending_exception(Object exception_obj);
inline void clear_pending_exception();
inline bool has_pending_exception();
THREAD_LOCAL_TOP_ADDRESS(Object, pending_message)
inline void clear_pending_message(); inline void clear_pending_message();
Address pending_message_obj_address() { inline Object pending_message();
return reinterpret_cast<Address>(&thread_local_top()->pending_message_obj_); inline bool has_pending_message();
} inline void set_pending_message(Object message_obj);
THREAD_LOCAL_TOP_ADDRESS(Object, scheduled_exception)
inline Object scheduled_exception(); inline Object scheduled_exception();
inline bool has_scheduled_exception(); inline bool has_scheduled_exception();
inline void clear_scheduled_exception(); inline void clear_scheduled_exception();
inline void set_scheduled_exception(Object exception);
bool IsJavaScriptHandlerOnTop(Object exception); bool IsJavaScriptHandlerOnTop(Object exception);
bool IsExternalHandlerOnTop(Object exception); bool IsExternalHandlerOnTop(Object exception);
......
...@@ -20,7 +20,7 @@ void ThreadLocalTop::Clear() { ...@@ -20,7 +20,7 @@ void ThreadLocalTop::Clear() {
pending_handler_fp_ = kNullAddress; pending_handler_fp_ = kNullAddress;
pending_handler_sp_ = kNullAddress; pending_handler_sp_ = kNullAddress;
last_api_entry_ = kNullAddress; last_api_entry_ = kNullAddress;
pending_message_obj_ = Object(); pending_message_ = Object();
rethrowing_message_ = false; rethrowing_message_ = false;
external_caught_exception_ = false; external_caught_exception_ = false;
c_entry_fp_ = kNullAddress; c_entry_fp_ = kNullAddress;
......
...@@ -116,7 +116,7 @@ class ThreadLocalTop { ...@@ -116,7 +116,7 @@ class ThreadLocalTop {
Address last_api_entry_; Address last_api_entry_;
// Communication channel between Isolate::Throw and message consumers. // Communication channel between Isolate::Throw and message consumers.
Object pending_message_obj_; Object pending_message_;
bool rethrowing_message_; bool rethrowing_message_;
// Use a separate value for scheduled exceptions to preserve the // Use a separate value for scheduled exceptions to preserve the
......
...@@ -2608,7 +2608,7 @@ IGNITION_HANDLER(CreateRestParameter, InterpreterAssembler) { ...@@ -2608,7 +2608,7 @@ IGNITION_HANDLER(CreateRestParameter, InterpreterAssembler) {
// previous pending message in the accumulator. // previous pending message in the accumulator.
IGNITION_HANDLER(SetPendingMessage, InterpreterAssembler) { IGNITION_HANDLER(SetPendingMessage, InterpreterAssembler) {
TNode<ExternalReference> pending_message = ExternalConstant( TNode<ExternalReference> pending_message = ExternalConstant(
ExternalReference::address_of_pending_message_obj(isolate())); ExternalReference::address_of_pending_message(isolate()));
TNode<HeapObject> previous_message = TNode<HeapObject> previous_message =
UncheckedCast<HeapObject>(LoadFullTagged(pending_message)); UncheckedCast<HeapObject>(LoadFullTagged(pending_message));
TNode<Object> new_message = GetAccumulator(); TNode<Object> new_message = GetAccumulator();
......
...@@ -5354,12 +5354,9 @@ Handle<Object> JSPromise::Fulfill(Handle<JSPromise> promise, ...@@ -5354,12 +5354,9 @@ Handle<Object> JSPromise::Fulfill(Handle<JSPromise> promise,
} }
static void MoveMessageToPromise(Isolate* isolate, Handle<JSPromise> promise) { static void MoveMessageToPromise(Isolate* isolate, Handle<JSPromise> promise) {
if (isolate->thread_local_top()->pending_message_obj_.IsTheHole(isolate)) { if (!isolate->has_pending_message()) return;
return;
}
Handle<Object> message = Handle<Object> message = handle(isolate->pending_message(), isolate);
handle(isolate->thread_local_top()->pending_message_obj_, isolate);
Handle<Symbol> key = isolate->factory()->promise_debug_message_symbol(); Handle<Symbol> key = isolate->factory()->promise_debug_message_symbol();
Object::SetProperty(isolate, promise, key, message, StoreOrigin::kMaybeKeyed, Object::SetProperty(isolate, promise, key, message, StoreOrigin::kMaybeKeyed,
Just(ShouldThrow::kThrowOnError)) Just(ShouldThrow::kThrowOnError))
......
...@@ -5317,7 +5317,7 @@ TEST(OldSpaceAllocationCounter) { ...@@ -5317,7 +5317,7 @@ TEST(OldSpaceAllocationCounter) {
static void CheckLeak(const v8::FunctionCallbackInfo<v8::Value>& args) { static void CheckLeak(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Object message( Object message(
*reinterpret_cast<Address*>(isolate->pending_message_obj_address())); *reinterpret_cast<Address*>(isolate->pending_message_address()));
CHECK(message.IsTheHole(isolate)); CHECK(message.IsTheHole(isolate));
} }
......
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