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