Commit 188ea8c5 authored by klaasb's avatar klaasb Committed by Commit bot

[interpreter] Add CreateCatchContext bytecode

One more bytecode to pass info through to TurboFan.

BUG=v8:4280
LOG=n

Review-Url: https://codereview.chromium.org/2260473003
Cr-Commit-Position: refs/heads/master@{#38726}
parent d7c6195c
......@@ -942,6 +942,18 @@ void BytecodeGraphBuilder::VisitCreateFunctionContext() {
environment()->BindAccumulator(context);
}
void BytecodeGraphBuilder::VisitCreateCatchContext() {
interpreter::Register reg = bytecode_iterator().GetRegisterOperand(0);
Node* exception = environment()->LookupRegister(reg);
Handle<String> name =
Handle<String>::cast(bytecode_iterator().GetConstantForIndexOperand(1));
Node* closure = environment()->LookupAccumulator();
const Operator* op = javascript()->CreateCatchContext(name);
Node* context = NewNode(op, exception, closure);
environment()->BindAccumulator(context);
}
void BytecodeGraphBuilder::VisitCreateWithContext() {
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
......
......@@ -345,13 +345,21 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::CreateBlockContext(
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CreateCatchContext(
Register exception, Handle<String> name) {
size_t name_index = GetConstantPoolEntry(name);
Output(Bytecode::kCreateCatchContext, RegisterOperand(exception),
UnsignedOperand(name_index));
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CreateFunctionContext(int slots) {
Output(Bytecode::kCreateFunctionContext, UnsignedOperand(slots));
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CreateWithContext(Register object) {
Output(Bytecode::kCreateWithContext, RegisterOperand(object));
Output(Bytecode::kCreateWithContext, RegisterOperand(object));
return *this;
}
......
......@@ -139,6 +139,11 @@ class BytecodeArrayBuilder final : public ZoneObject {
// in the accumulator.
BytecodeArrayBuilder& CreateBlockContext(Handle<ScopeInfo> scope_info);
// Create a new context for a catch block with |exception| and |name| and the
// closure in the accumulator.
BytecodeArrayBuilder& CreateCatchContext(Register exception,
Handle<String> name);
// Create a new context with size |slots|.
BytecodeArrayBuilder& CreateFunctionContext(int slots);
......
......@@ -3227,19 +3227,10 @@ void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) {
AccumulatorResultScope accumulator_execution_result(this);
DCHECK(variable->IsContextSlot());
// Allocate a new local block context.
register_allocator()->PrepareForConsecutiveAllocations(3);
Register name = register_allocator()->NextConsecutiveRegister();
Register exception = register_allocator()->NextConsecutiveRegister();
Register closure = register_allocator()->NextConsecutiveRegister();
builder()
->StoreAccumulatorInRegister(exception)
.LoadLiteral(variable->name())
.StoreAccumulatorInRegister(name);
Register exception = register_allocator()->NewRegister();
builder()->StoreAccumulatorInRegister(exception);
VisitFunctionClosureForContext();
builder()->StoreAccumulatorInRegister(closure).CallRuntime(
Runtime::kPushCatchContext, name, 3);
builder()->CreateCatchContext(exception, variable->name());
execution_result()->SetResultInAccumulator();
}
......
......@@ -235,6 +235,8 @@ namespace interpreter {
\
/* Context allocation */ \
V(CreateBlockContext, AccumulatorUse::kReadWrite, OperandType::kIdx) \
V(CreateCatchContext, AccumulatorUse::kReadWrite, OperandType::kReg, \
OperandType::kIdx) \
/* TODO(klaasb) rename Idx or add unsigned Imm OperandType? */ \
V(CreateFunctionContext, AccumulatorUse::kWrite, OperandType::kIdx) \
V(CreateWithContext, AccumulatorUse::kReadWrite, OperandType::kReg) \
......
......@@ -1849,6 +1849,22 @@ void Interpreter::DoCreateBlockContext(InterpreterAssembler* assembler) {
__ Dispatch();
}
// CreateCatchContext <exception> <index>
//
// Creates a new context for a catch block with the |exception| in a register,
// the variable name at |index| and the closure in the accumulator.
void Interpreter::DoCreateCatchContext(InterpreterAssembler* assembler) {
Node* exception_reg = __ BytecodeOperandReg(0);
Node* exception = __ LoadRegister(exception_reg);
Node* index = __ BytecodeOperandIdx(1);
Node* name = __ LoadConstantPoolEntry(index);
Node* closure = __ GetAccumulator();
Node* context = __ GetContext();
__ SetAccumulator(__ CallRuntime(Runtime::kPushCatchContext, context, name,
exception, closure));
__ Dispatch();
}
// CreateFunctionContext <slots>
//
// Creates a new context with number of |slots| for the function closure.
......
......@@ -268,7 +268,7 @@ snippet: "
"
frame size: 18
parameter count: 1
bytecode array length: 756
bytecode array length: 742
bytecodes: [
B(Ldar), R(new_target),
B(JumpIfUndefined), U8(26),
......@@ -418,7 +418,7 @@ bytecodes: [
B(Star), R(9),
B(LdaZero),
B(Star), R(8),
B(Jump), U8(75),
B(Jump), U8(68),
B(Ldar), R(13),
/* 36 E> */ B(Throw),
B(Ldar), R(13),
......@@ -426,12 +426,10 @@ bytecodes: [
B(LdaZero),
B(StaContextSlot), R(1), U8(9),
B(Wide), B(Jump), U16(-215),
B(Jump), U8(46),
B(Star), R(13),
B(LdaConstant), U8(11),
B(Jump), U8(39),
B(Star), R(12),
B(Mov), R(closure), R(14),
B(CallRuntime), U16(Runtime::kPushCatchContext), R(12), U8(3),
B(Ldar), R(closure),
B(CreateCatchContext), R(12), U8(11),
B(Star), R(11),
B(PushContext), R(2),
B(LdrContextSlot), R(0), U8(9), R(12),
......@@ -466,11 +464,11 @@ bytecodes: [
B(LdaNull),
B(TestEqual), R(11),
B(JumpIfFalse), U8(4),
B(Jump), U8(124),
B(Jump), U8(117),
B(LdrContextSlot), R(1), U8(9), R(11),
B(LdaSmi), U8(1),
B(TestEqualStrict), R(11),
B(JumpIfFalse), U8(78),
B(JumpIfFalse), U8(71),
B(LdaContextSlot), R(1), U8(11),
B(TypeOf),
B(Star), R(11),
......@@ -488,12 +486,10 @@ bytecodes: [
B(LdrContextSlot), R(1), U8(11), R(12),
B(LdrContextSlot), R(1), U8(7), R(13),
B(InvokeIntrinsic), U8(Runtime::k_Call), R(12), U8(2),
B(Jump), U8(29),
B(Star), R(13),
B(LdaConstant), U8(11),
B(Jump), U8(22),
B(Star), R(12),
B(Mov), R(closure), R(14),
B(CallRuntime), U16(Runtime::kPushCatchContext), R(12), U8(3),
B(Ldar), R(closure),
B(CreateCatchContext), R(12), U8(11),
B(Star), R(11),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(11),
......@@ -600,9 +596,9 @@ constant pool: [
kInstanceTypeDontCare,
]
handlers: [
[45, 675, 681],
[143, 430, 436],
[45, 661, 667],
[143, 423, 429],
[146, 384, 386],
[532, 544, 546],
[525, 537, 539],
]
......@@ -11,20 +11,18 @@ wrap: yes
snippet: "
try { return 1; } catch(e) { return 2; }
"
frame size: 5
frame size: 3
parameter count: 1
bytecode array length: 41
bytecode array length: 34
bytecodes: [
/* 30 E> */ B(StackCheck),
B(Mov), R(context), R(1),
/* 40 S> */ B(LdaSmi), U8(1),
/* 75 S> */ B(Return),
B(Jump), U8(32),
B(Star), R(3),
B(LdaConstant), U8(0),
B(Jump), U8(25),
B(Star), R(2),
B(Mov), R(closure), R(4),
B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3),
B(Ldar), R(closure),
B(CreateCatchContext), R(2), U8(0),
B(Star), R(1),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(1),
......@@ -48,20 +46,18 @@ snippet: "
try { a = 1 } catch(e1) {};
try { a = 2 } catch(e2) { a = 3 }
"
frame size: 6
frame size: 4
parameter count: 1
bytecode array length: 79
bytecode array length: 65
bytecodes: [
/* 30 E> */ B(StackCheck),
B(Mov), R(context), R(2),
/* 47 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
B(Jump), U8(29),
B(Star), R(4),
B(LdaConstant), U8(0),
B(Jump), U8(22),
B(Star), R(3),
B(Mov), R(closure), R(5),
/* 49 E> */ B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3),
B(Ldar), R(closure),
/* 49 E> */ B(CreateCatchContext), R(3), U8(0),
B(Star), R(2),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(2),
......@@ -70,12 +66,10 @@ bytecodes: [
B(Mov), R(context), R(2),
/* 75 S> */ B(LdaSmi), U8(2),
B(Star), R(0),
B(Jump), U8(33),
B(Star), R(4),
B(LdaConstant), U8(1),
B(Jump), U8(26),
B(Star), R(3),
B(Mov), R(closure), R(5),
/* 77 E> */ B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3),
B(Ldar), R(closure),
/* 77 E> */ B(CreateCatchContext), R(3), U8(1),
B(Star), R(2),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(2),
......@@ -92,6 +86,6 @@ constant pool: [
]
handlers: [
[4, 8, 10],
[40, 44, 46],
[33, 37, 39],
]
......@@ -53,9 +53,9 @@ snippet: "
var a = 1;
try { a = 2; } catch(e) { a = 20 } finally { a = 3; }
"
frame size: 9
frame size: 7
parameter count: 1
bytecode array length: 87
bytecode array length: 80
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
......@@ -64,12 +64,10 @@ bytecodes: [
B(Mov), R(context), R(5),
/* 51 S> */ B(LdaSmi), U8(2),
B(Star), R(0),
B(Jump), U8(33),
B(Star), R(7),
B(LdaConstant), U8(0),
B(Jump), U8(26),
B(Star), R(6),
B(Mov), R(closure), R(8),
/* 53 E> */ B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3),
B(Ldar), R(closure),
/* 53 E> */ B(CreateCatchContext), R(6), U8(0),
B(Star), R(5),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(5),
......@@ -101,7 +99,7 @@ constant pool: [
"e",
]
handlers: [
[8, 48, 54],
[8, 41, 47],
[11, 15, 17],
]
......@@ -111,9 +109,9 @@ snippet: "
try { a = 1 } catch(e) { a = 2 }
} catch(e) { a = 20 } finally { a = 3; }
"
frame size: 10
frame size: 8
parameter count: 1
bytecode array length: 119
bytecode array length: 105
bytecodes: [
/* 30 E> */ B(StackCheck),
B(Mov), R(context), R(4),
......@@ -121,12 +119,10 @@ bytecodes: [
B(Mov), R(context), R(6),
/* 55 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
B(Jump), U8(33),
B(Star), R(8),
B(LdaConstant), U8(0),
B(Jump), U8(26),
B(Star), R(7),
B(Mov), R(closure), R(9),
/* 57 E> */ B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3),
B(Ldar), R(closure),
/* 57 E> */ B(CreateCatchContext), R(7), U8(0),
B(Star), R(6),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(6),
......@@ -134,12 +130,10 @@ bytecodes: [
/* 74 S> */ B(LdaSmi), U8(2),
B(Star), R(0),
B(PopContext), R(1),
B(Jump), U8(33),
B(Star), R(7),
B(LdaConstant), U8(0),
B(Jump), U8(26),
B(Star), R(6),
B(Mov), R(closure), R(8),
/* 76 E> */ B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3),
B(Ldar), R(closure),
/* 76 E> */ B(CreateCatchContext), R(6), U8(0),
B(Star), R(5),
B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), R(0), U8(0),
B(Ldar), R(5),
......@@ -171,8 +165,8 @@ constant pool: [
"e",
]
handlers: [
[4, 80, 86],
[7, 47, 49],
[4, 66, 72],
[7, 40, 42],
[10, 14, 16],
]
......@@ -102,11 +102,10 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Emit closure operations.
builder.CreateClosure(0, NOT_TENURED);
builder.CreateBlockContext(factory->NewScopeInfo(1));
// Emit create context operation.
builder.CreateBlockContext(factory->NewScopeInfo(1));
builder.CreateCatchContext(reg, name);
builder.CreateFunctionContext(1);
builder.CreateWithContext(reg);
// Emit literal creation operations.
......
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