Commit d4696c48 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Simplify pending message object handling.

This moves the decision whether to report a message or not to when
the pending exception is propagated instead of trying to preserve the
decision in a ThreadLocalTop field.

R=titzer@chromium.org

Review URL: https://codereview.chromium.org/998943003

Cr-Commit-Position: refs/heads/master@{#27150}
parent 4ededa86
......@@ -5324,28 +5324,12 @@ void FullCodeGenerator::EnterFinallyBlock() {
__ mov(ip, Operand(pending_message_obj));
__ ldr(r1, MemOperand(ip));
__ push(r1);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ mov(ip, Operand(has_pending_message));
STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
__ ldrb(r1, MemOperand(ip));
__ SmiTag(r1);
__ push(r1);
}
void FullCodeGenerator::ExitFinallyBlock() {
DCHECK(!result_register().is(r1));
// Restore pending message from stack.
__ pop(r1);
__ SmiUntag(r1);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ mov(ip, Operand(has_pending_message));
STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
__ strb(r1, MemOperand(ip));
__ pop(r1);
ExternalReference pending_message_obj =
ExternalReference::address_of_pending_message_obj(isolate());
......
......@@ -5345,15 +5345,7 @@ void FullCodeGenerator::EnterFinallyBlock() {
ExternalReference::address_of_pending_message_obj(isolate());
__ Mov(x10, pending_message_obj);
__ Ldr(x10, MemOperand(x10));
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
__ Mov(x11, has_pending_message);
__ Ldrb(x11, MemOperand(x11));
__ SmiTag(x11);
__ Push(x10, x11);
__ Push(x10);
}
......@@ -5362,18 +5354,11 @@ void FullCodeGenerator::ExitFinallyBlock() {
DCHECK(!result_register().is(x10));
// Restore pending message from stack.
__ Pop(x10, x11);
__ SmiUntag(x10);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ Mov(x13, has_pending_message);
STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
__ Strb(x10, MemOperand(x13));
__ Pop(x10);
ExternalReference pending_message_obj =
ExternalReference::address_of_pending_message_obj(isolate());
__ Mov(x13, pending_message_obj);
__ Str(x11, MemOperand(x13));
__ Str(x10, MemOperand(x13));
// Restore result register and cooked return address from the stack.
__ Pop(x10, result_register());
......
......@@ -1267,12 +1267,6 @@ ExternalReference ExternalReference::address_of_pending_message_obj(
}
ExternalReference ExternalReference::address_of_has_pending_message(
Isolate* isolate) {
return ExternalReference(isolate->has_pending_message_address());
}
ExternalReference ExternalReference::address_of_min_int() {
return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int));
}
......
......@@ -956,7 +956,6 @@ class ExternalReference BASE_EMBEDDED {
static ExternalReference scheduled_exception_address(Isolate* isolate);
static ExternalReference address_of_pending_message_obj(Isolate* isolate);
static ExternalReference address_of_has_pending_message(Isolate* isolate);
// Static variables containing common double constants.
static ExternalReference address_of_min_int();
......
......@@ -1264,8 +1264,6 @@ void AstGraphBuilder::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
ExternalReference message_object =
ExternalReference::address_of_pending_message_obj(isolate());
ExternalReference message_present =
ExternalReference::address_of_has_pending_message(isolate());
// We keep a record of all paths that enter the finally-block to be able to
// dispatch to the correct continuation point after the statements in the
......@@ -1302,7 +1300,6 @@ void AstGraphBuilder::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
environment()->Push(token); // TODO(mstarzinger): Cook token!
environment()->Push(result);
environment()->Push(BuildLoadExternal(message_object, kMachAnyTagged));
environment()->Push(BuildLoadExternal(message_present, kMachBool));
// Evaluate the finally-block.
Visit(stmt->finally_block());
......@@ -1310,7 +1307,6 @@ void AstGraphBuilder::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// The result value, dispatch token and message is restored from the operand
// stack (this is in sync with FullCodeGenerator::ExitFinallyBlock).
BuildStoreExternal(message_present, kMachBool, environment()->Pop());
BuildStoreExternal(message_object, kMachAnyTagged, environment()->Pop());
result = environment()->Pop();
token = environment()->Pop(); // TODO(mstarzinger): Uncook token!
......
......@@ -249,7 +249,7 @@ class FullCodeGenerator: public AstVisitor {
// The finally block of a try/finally statement.
class Finally : public NestedStatement {
public:
static const int kElementCount = 4;
static const int kElementCount = 3;
explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
virtual ~Finally() {}
......
......@@ -5252,24 +5252,12 @@ void FullCodeGenerator::EnterFinallyBlock() {
ExternalReference::address_of_pending_message_obj(isolate());
__ mov(edx, Operand::StaticVariable(pending_message_obj));
__ push(edx);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ mov(edx, Operand::StaticVariable(has_pending_message));
__ SmiTag(edx);
__ push(edx);
}
void FullCodeGenerator::ExitFinallyBlock() {
DCHECK(!result_register().is(edx));
// Restore pending message from stack.
__ pop(edx);
__ SmiUntag(edx);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ mov(Operand::StaticVariable(has_pending_message), edx);
__ pop(edx);
ExternalReference pending_message_obj =
ExternalReference::address_of_pending_message_obj(isolate());
......
......@@ -87,7 +87,6 @@ void ThreadLocalTop::InitializeInternal() {
// These members are re-initialized later after deserialization
// is complete.
pending_exception_ = NULL;
has_pending_message_ = false;
rethrowing_message_ = false;
pending_message_obj_ = NULL;
scheduled_exception_ = NULL;
......@@ -1000,9 +999,6 @@ Object* Isolate::Throw(Object* exception, MessageLocation* location) {
}
}
// Save the message for reporting if the the exception remains uncaught.
thread_local_top()->has_pending_message_ = report_exception;
// Set the exception being thrown.
set_pending_exception(*exception_handle);
return heap()->exception();
......@@ -1405,30 +1401,38 @@ bool Isolate::IsFinallyOnTop() {
void Isolate::ReportPendingMessages() {
DCHECK(has_pending_exception());
bool can_clear_message = PropagatePendingExceptionToExternalTryCatch();
Object* exception = pending_exception();
HandleScope scope(this);
if (thread_local_top_.pending_exception_ == heap()->termination_exception()) {
// Try to propagate the exception to an external v8::TryCatch handler. If
// propagation was unsuccessful, then we will get another chance at reporting
// the pending message if the exception is re-thrown.
bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch();
if (!has_been_propagated) return;
// Clear the pending message object early to avoid endless recursion.
Object* message_obj = thread_local_top_.pending_message_obj_;
clear_pending_message();
bool can_be_caught_externally = false;
bool catchable_by_javascript = is_catchable_by_javascript(exception);
bool should_report_exception =
ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
if (!catchable_by_javascript) {
// Do nothing: if needed, the exception has been already propagated to
// v8::TryCatch.
} else {
if (thread_local_top_.has_pending_message_) {
thread_local_top_.has_pending_message_ = false;
if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
HandleScope scope(this);
Handle<JSMessageObject> message_obj(
JSMessageObject::cast(thread_local_top_.pending_message_obj_));
Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script()));
Handle<Script> script(Script::cast(script_wrapper->value()));
int start_pos = message_obj->start_position();
int end_pos = message_obj->end_position();
MessageLocation location(script, start_pos, end_pos);
MessageHandler::ReportMessage(this, &location, message_obj);
}
if (!message_obj->IsTheHole() && should_report_exception) {
HandleScope scope(this);
Handle<JSMessageObject> message(JSMessageObject::cast(message_obj));
Handle<JSValue> script_wrapper(JSValue::cast(message->script()));
Handle<Script> script(Script::cast(script_wrapper->value()));
int start_pos = message->start_position();
int end_pos = message->end_position();
MessageLocation location(script, start_pos, end_pos);
MessageHandler::ReportMessage(this, &location, message);
}
}
if (can_clear_message) clear_pending_message();
}
......@@ -1436,7 +1440,6 @@ MessageLocation Isolate::GetMessageLocation() {
DCHECK(has_pending_exception());
if (thread_local_top_.pending_exception_ != heap()->termination_exception() &&
thread_local_top_.has_pending_message_ &&
!thread_local_top_.pending_message_obj_->IsTheHole()) {
Handle<JSMessageObject> message_obj(
JSMessageObject::cast(thread_local_top_.pending_message_obj_));
......
......@@ -282,7 +282,6 @@ class ThreadLocalTop BASE_EMBEDDED {
Address pending_handler_sp_;
// Communication channel between Isolate::Throw and message consumers.
bool has_pending_message_;
bool rethrowing_message_;
Object* pending_message_obj_;
......@@ -604,7 +603,6 @@ class Isolate {
THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception)
void clear_pending_message() {
thread_local_top_.has_pending_message_ = false;
thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
}
v8::TryCatch* try_catch_handler() {
......@@ -623,10 +621,6 @@ class Isolate {
return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_);
}
Address has_pending_message_address() {
return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_);
}
Object* scheduled_exception() {
DCHECK(has_scheduled_exception());
DCHECK(!thread_local_top_.scheduled_exception_->IsException());
......
......@@ -102,8 +102,6 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"date_cache_stamp");
Add(ExternalReference::address_of_pending_message_obj(isolate).address(),
"address_of_pending_message_obj");
Add(ExternalReference::address_of_has_pending_message(isolate).address(),
"address_of_has_pending_message");
Add(ExternalReference::get_make_code_young_function(isolate).address(),
"Code::MakeCodeYoung");
Add(ExternalReference::cpu_features().address(), "cpu_features");
......
......@@ -5272,12 +5272,6 @@ void FullCodeGenerator::EnterFinallyBlock() {
ExternalReference::address_of_pending_message_obj(isolate());
__ Load(rdx, pending_message_obj);
__ Push(rdx);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ Load(rdx, has_pending_message);
__ Integer32ToSmi(rdx, rdx);
__ Push(rdx);
}
......@@ -5285,12 +5279,6 @@ void FullCodeGenerator::ExitFinallyBlock() {
DCHECK(!result_register().is(rdx));
DCHECK(!result_register().is(rcx));
// Restore pending message from stack.
__ Pop(rdx);
__ SmiToInteger32(rdx, rdx);
ExternalReference has_pending_message =
ExternalReference::address_of_has_pending_message(isolate());
__ Store(has_pending_message, rdx);
__ Pop(rdx);
ExternalReference pending_message_obj =
ExternalReference::address_of_pending_message_obj(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