Commit 918ec32d authored by michael_dawson's avatar michael_dawson Committed by Commit bot

PPC: Switch full-codegen from StackHandlers to handler table.

Port 38a719f9

Original commit message:
This switches full-codegen to no longer push and pop StackHandler
markers onto the operand stack, but relies on a range-based handler
table instead. We only use StackHandlers in JSEntryStubs to mark the
transition from C to JS code.

Note that this makes deoptimization and OSR from within any try-block
work out of the box, makes the non-exception paths faster and should
overall be neutral on the memory footprint (pros).

On the other hand it makes the exception paths slower and actually
throwing and exception more expensive (cons).

TEST=cctest/test-run-jsexceptions/DeoptTry

R=yangguo@chromium.org, R=mbrandy@us.ibm.com

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27453}
parent 25552871
......@@ -1158,9 +1158,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ mov(fp, Operand(pending_handler_fp_address));
__ LoadP(fp, MemOperand(fp));
// If the handler is a JS frame, restore the context to the frame.
// (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp
// or cp.
// If the handler is a JS frame, restore the context to the frame. Note that
// the context will be set to (cp == 0) for non-JS frames.
Label skip;
__ cmpi(cp, Operand::Zero());
__ beq(&skip);
......@@ -1250,7 +1249,7 @@ void JSEntryStub::Generate(MacroAssembler* masm) {
handler_offset_ = handler_entry.pos();
// Caught exception: Store result (exception) in the pending exception
// field in the JSEnv and return a failure sentinel. Coming in here the
// fp will be invalid because the PushTryHandler below sets it to 0 to
// fp will be invalid because the PushStackHandler below sets it to 0 to
// signal the existence of the JSEntry frame.
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
isolate())));
......@@ -1259,11 +1258,10 @@ void JSEntryStub::Generate(MacroAssembler* masm) {
__ LoadRoot(r3, Heap::kExceptionRootIndex);
__ b(&exit);
// Invoke: Link this frame into the handler chain. There's only one
// handler block in this code object, so its index is 0.
// Invoke: Link this frame into the handler chain.
__ bind(&invoke);
// Must preserve r0-r4, r5-r7 are available. (needs update for PPC)
__ PushTryHandler(StackHandler::JS_ENTRY, 0);
// Must preserve r3-r7.
__ PushStackHandler();
// If an exception not caught by another handler occurs, this handler
// returns control to the code after the b(&invoke) above, which
// restores all kCalleeSaved registers (including cp and fp) to their
......@@ -1302,7 +1300,7 @@ void JSEntryStub::Generate(MacroAssembler* masm) {
__ bctrl(); // make the call
// Unlink this frame from the handler chain.
__ PopTryHandler();
__ PopStackHandler();
__ bind(&exit); // r3 holds result
// Check if the current stack frame is marked as the outermost JS frame.
......
......@@ -104,7 +104,8 @@ class JumpPatchSite BASE_EMBEDDED {
void FullCodeGenerator::Generate() {
CompilationInfo* info = info_;
handler_table_ =
isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED);
Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray(
HandlerTable::LengthForRange(function()->handler_count()), TENURED));
profiling_counter_ = isolate()->factory()->NewCell(
Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate()));
......@@ -2143,7 +2144,6 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
// catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
__ bind(&l_catch);
handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
__ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw"
__ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter
__ Push(load_name, r6, r3); // "throw", iter, except
......@@ -2154,16 +2154,17 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
// re-boxing.
__ bind(&l_try);
__ pop(r3); // result
__ PushTryHandler(StackHandler::CATCH, expr->index());
const int handler_size = StackHandlerConstants::kSize;
EnterTryBlock(expr->index(), &l_catch);
const int try_block_size = TryCatch::kElementCount * kPointerSize;
__ push(r3); // result
__ b(&l_suspend);
__ bind(&l_continuation);
__ b(&l_resume);
__ bind(&l_suspend);
const int generator_object_depth = kPointerSize + handler_size;
const int generator_object_depth = kPointerSize + try_block_size;
__ LoadP(r3, MemOperand(sp, generator_object_depth));
__ push(r3); // g
__ Push(Smi::FromInt(expr->index())); // handler-index
DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
__ LoadSmiLiteral(r4, Smi::FromInt(l_continuation.pos()));
__ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kContinuationOffset),
......@@ -2172,12 +2173,12 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ mr(r4, cp);
__ RecordWriteField(r3, JSGeneratorObject::kContextOffset, r4, r5,
kLRHasBeenSaved, kDontSaveFPRegs);
__ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
__ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2);
__ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
__ pop(r3); // result
EmitReturnSequence();
__ bind(&l_resume); // received in r3
__ PopTryHandler();
ExitTryBlock(expr->index());
// receiver = iter; f = 'next'; arg = received;
__ bind(&l_next);
......@@ -5361,32 +5362,6 @@ void FullCodeGenerator::ExitFinallyBlock() {
}
#undef __
#define __ ACCESS_MASM(masm())
FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit(
int* stack_depth, int* context_length) {
// The macros used here must preserve the result register.
// Because the handler block contains the context of the finally
// code, we can restore it directly from there for the finally code
// rather than iteratively unwinding contexts via their previous
// links.
__ Drop(*stack_depth); // Down to the handler block.
if (*context_length > 0) {
// Restore the context to its dedicated register and the stack.
__ LoadP(cp, MemOperand(sp, StackHandlerConstants::kContextOffset));
__ StoreP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
}
__ PopTryHandler();
__ b(finally_entry_, SetLK);
*stack_depth = 0;
*context_length = 0;
return previous_;
}
#undef __
......
......@@ -1086,41 +1086,28 @@ void MacroAssembler::DebugBreak() {
}
void MacroAssembler::PushTryHandler(StackHandler::Kind kind,
int handler_index) {
void MacroAssembler::PushStackHandler() {
// Adjust this code if not the case.
STATIC_ASSERT(StackHandlerConstants::kSize == 3 * kPointerSize);
STATIC_ASSERT(StackHandlerConstants::kSize == 1 * kPointerSize);
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
STATIC_ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize);
STATIC_ASSERT(StackHandlerConstants::kContextOffset == 2 * kPointerSize);
// For the JSEntry handler, we must preserve r1-r7, r0,r8-r12 are available.
// We want the stack to look like
// sp -> NextOffset
// index
// context
// Link the current handler as the next handler.
// Preserve r3-r7.
mov(r8, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
LoadP(r0, MemOperand(r8));
StorePU(r0, MemOperand(sp, -StackHandlerConstants::kSize));
push(r0);
// Set this new handler as the current one.
StoreP(sp, MemOperand(r8));
mov(r8, Operand(handler_index));
if (kind == StackHandler::JS_ENTRY) {
LoadSmiLiteral(cp, Smi::FromInt(0)); // Indicates no context.
}
StoreP(r8, MemOperand(sp, StackHandlerConstants::kStateOffset));
StoreP(cp, MemOperand(sp, StackHandlerConstants::kContextOffset));
}
void MacroAssembler::PopTryHandler() {
void MacroAssembler::PopStackHandler() {
STATIC_ASSERT(StackHandlerConstants::kSize == 1 * kPointerSize);
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
pop(r4);
mov(ip, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
addi(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
StoreP(r4, MemOperand(ip));
}
......
......@@ -544,12 +544,12 @@ class MacroAssembler : public Assembler {
// ---------------------------------------------------------------------------
// Exception handling
// Push a new try handler and link into try handler chain.
void PushTryHandler(StackHandler::Kind kind, int handler_index);
// Push a new stack handler and link into stack handler chain.
void PushStackHandler();
// Unlink the stack handler on top of the stack from the try handler chain.
// Unlink the stack handler on top of the stack from the stack handler chain.
// Must preserve the result register.
void PopTryHandler();
void PopStackHandler();
// ---------------------------------------------------------------------------
// Inline caching support
......
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