Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3167)

Unified Diff: test/unittests/interpreter/bytecode-array-builder-unittest.cc

Issue 2331033002: [interpreter] Merge {OsrPoll} with {Jump} bytecode. (Closed)
Patch Set: One more test. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/unittests/interpreter/bytecode-array-builder-unittest.cc
diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
index ce55ab99a3aabb48680b3f5b8e842aa234d0cc5e..d32a75245ebfeacac236073799e0027766d34e4f 100644
--- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc
+++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
@@ -190,17 +190,19 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
.ConvertAccumulatorToObject(reg)
.ConvertAccumulatorToName(reg);
- // Emit control flow. Return must be the last instruction.
- BytecodeLabel start;
- builder.Bind(&start);
+ // Short jumps with Imm8 operands
{
- // Short jumps with Imm8 operands
- BytecodeLabel after_jump;
- builder.Jump(&start)
- .Bind(&after_jump)
- .JumpIfNull(&start)
- .JumpIfUndefined(&start)
- .JumpIfNotHole(&start);
+ BytecodeLabel start, after_jump1, after_jump2, after_jump3, after_jump4;
+ builder.Bind(&start)
+ .Jump(&after_jump1)
+ .Bind(&after_jump1)
+ .JumpIfNull(&after_jump2)
+ .Bind(&after_jump2)
+ .JumpIfUndefined(&after_jump3)
+ .Bind(&after_jump3)
+ .JumpIfNotHole(&after_jump4)
+ .Bind(&after_jump4)
+ .JumpLoop(&start, 0);
}
// Longer jumps with constant operands
@@ -224,48 +226,31 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Perform an operation that returns boolean value to
// generate JumpIfTrue/False
- builder.CompareOperation(Token::Value::EQ, reg, 1)
- .JumpIfTrue(&start)
- .CompareOperation(Token::Value::EQ, reg, 2)
- .JumpIfFalse(&start);
- // Perform an operation that returns a non-boolean operation to
- // generate JumpIfToBooleanTrue/False.
- builder.BinaryOperation(Token::Value::ADD, reg, 1)
- .JumpIfTrue(&start)
- .BinaryOperation(Token::Value::ADD, reg, 2)
- .JumpIfFalse(&start);
- // Insert dummy ops to force longer jumps
- for (int i = 0; i < 128; i++) {
- builder.LoadTrue();
- }
- // Longer jumps requiring Constant operand
{
- BytecodeLabel after_jump;
- builder.Jump(&start)
- .Bind(&after_jump)
- .JumpIfNull(&start)
- .JumpIfUndefined(&start)
- .JumpIfNotHole(&start);
- // Perform an operation that returns boolean value to
- // generate JumpIfTrue/False
+ BytecodeLabel after_jump1, after_jump2;
builder.CompareOperation(Token::Value::EQ, reg, 1)
- .JumpIfTrue(&start)
+ .JumpIfTrue(&after_jump1)
+ .Bind(&after_jump1)
.CompareOperation(Token::Value::EQ, reg, 2)
- .JumpIfFalse(&start);
- // Perform an operation that returns a non-boolean operation to
- // generate JumpIfToBooleanTrue/False.
+ .JumpIfFalse(&after_jump2)
+ .Bind(&after_jump2);
+ }
+
+ // Perform an operation that returns a non-boolean operation to
+ // generate JumpIfToBooleanTrue/False.
+ {
+ BytecodeLabel after_jump1, after_jump2;
builder.BinaryOperation(Token::Value::ADD, reg, 1)
- .JumpIfTrue(&start)
+ .JumpIfTrue(&after_jump1)
+ .Bind(&after_jump1)
.BinaryOperation(Token::Value::ADD, reg, 2)
- .JumpIfFalse(&start);
+ .JumpIfFalse(&after_jump2)
+ .Bind(&after_jump2);
}
// Emit stack check bytecode.
builder.StackCheck(0);
- // Emit an OSR poll bytecode.
- builder.OsrPoll(1);
-
// Emit throw and re-throw in it's own basic block so that the rest of the
// code isn't omitted due to being dead.
BytecodeLabel after_throw;
@@ -339,30 +324,6 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
.CreateArrayLiteral(factory->NewFixedArray(2), 0, 0)
.CreateObjectLiteral(factory->NewFixedArray(2), 0, 0, reg);
- // Longer jumps requiring ConstantWide operand
- {
- BytecodeLabel after_jump;
- builder.Jump(&start)
- .Bind(&after_jump)
- .JumpIfNull(&start)
- .JumpIfUndefined(&start)
- .JumpIfNotHole(&start);
- }
-
- // Perform an operation that returns boolean value to
- // generate JumpIfTrue/False
- builder.CompareOperation(Token::Value::EQ, reg, 1)
- .JumpIfTrue(&start)
- .CompareOperation(Token::Value::EQ, reg, 2)
- .JumpIfFalse(&start);
-
- // Perform an operation that returns a non-boolean operation to
- // generate JumpIfToBooleanTrue/False.
- builder.BinaryOperation(Token::Value::ADD, reg, 1)
- .JumpIfTrue(&start)
- .BinaryOperation(Token::Value::ADD, reg, 2)
- .JumpIfFalse(&start);
-
// Emit generator operations
builder.SuspendGenerator(reg)
.ResumeGenerator(reg);
@@ -371,10 +332,20 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
builder.CallRuntime(Runtime::kInlineIsArray, reg, 1)
.CallRuntime(Runtime::kInlineIsArray, wide, 1);
+ // Emit debugger bytecode.
builder.Debugger();
+
+ // Insert dummy ops to force longer jumps.
+ for (int i = 0; i < 128; i++) {
+ builder.LoadTrue();
+ }
+
+ // Bind labels for long jumps at the very end.
for (size_t i = 0; i < arraysize(end); i++) {
builder.Bind(&end[i]);
}
+
+ // Return must be the last instruction.
builder.Return();
// Generate BytecodeArray.
@@ -679,24 +650,11 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) {
Register reg(0);
- BytecodeLabel label0, label1, label2, label3, label4;
- builder.Bind(&label0)
- .Jump(&label0)
- .Bind(&label1)
- .CompareOperation(Token::Value::EQ, reg, 1)
- .JumpIfTrue(&label1)
- .Bind(&label2)
- .CompareOperation(Token::Value::EQ, reg, 2)
- .JumpIfFalse(&label2)
- .Bind(&label3)
- .BinaryOperation(Token::Value::ADD, reg, 1)
- .JumpIfTrue(&label3)
- .Bind(&label4)
- .BinaryOperation(Token::Value::ADD, reg, 2)
- .JumpIfFalse(&label4);
- for (int i = 0; i < 62; i++) {
+ BytecodeLabel label0;
+ builder.Bind(&label0).JumpLoop(&label0, 0);
+ for (int i = 0; i < 42; i++) {
BytecodeLabel after_jump;
- builder.Jump(&label4).Bind(&after_jump);
+ builder.JumpLoop(&label0, 0).Bind(&after_jump);
}
// Add padding to force wide backwards jumps.
@@ -704,51 +662,21 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) {
builder.Debugger();
}
- builder.BinaryOperation(Token::Value::ADD, reg, 1).JumpIfFalse(&label4);
- builder.BinaryOperation(Token::Value::ADD, reg, 2).JumpIfTrue(&label3);
- builder.CompareOperation(Token::Value::EQ, reg, 1).JumpIfFalse(&label2);
- builder.CompareOperation(Token::Value::EQ, reg, 2).JumpIfTrue(&label1);
- builder.Jump(&label0);
+ builder.JumpLoop(&label0, 0);
BytecodeLabel end;
builder.Bind(&end);
builder.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
BytecodeArrayIterator iterator(array);
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
- // Ignore compare operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(),
- PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue));
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
- CHECK_EQ(iterator.GetImmediateOperand(0), -3);
- iterator.Advance();
- // Ignore compare operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(),
- PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse));
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
- CHECK_EQ(iterator.GetImmediateOperand(0), -3);
- iterator.Advance();
- // Ignore binary operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
- CHECK_EQ(iterator.GetImmediateOperand(0), -3);
- iterator.Advance();
- // Ignore binary operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
- CHECK_EQ(iterator.GetImmediateOperand(0), -3);
- iterator.Advance();
- for (int i = 0; i < 62; i++) {
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ for (int i = 0; i < 42; i++) {
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
- // offset of 5 (3 for binary operation and 2 for jump)
- CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 5);
+ // offset of 3 (because kJumpLoop takes two immediate operands)
+ CHECK_EQ(iterator.GetImmediateOperand(0), -i * 3 - 3);
iterator.Advance();
}
// Check padding to force wide backwards jumps.
@@ -756,35 +684,9 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
iterator.Advance();
}
- // Ignore binary operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
- CHECK_EQ(iterator.GetImmediateOperand(0), -389);
- iterator.Advance();
- // Ignore binary operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
- CHECK_EQ(iterator.GetImmediateOperand(0), -401);
- iterator.Advance();
- // Ignore compare operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(),
- PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse));
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
- CHECK_EQ(iterator.GetImmediateOperand(0), -413);
- iterator.Advance();
- // Ignore compare operation.
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(),
- PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue));
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
- CHECK_EQ(iterator.GetImmediateOperand(0), -425);
- iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
- CHECK_EQ(iterator.GetImmediateOperand(0), -431);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -386);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
iterator.Advance();
@@ -802,9 +704,9 @@ TEST_F(BytecodeArrayBuilderTest, LabelReuse) {
builder.Jump(&label)
.Bind(&label)
- .Jump(&label)
+ .JumpLoop(&label, 0)
.Bind(&after_jump0)
- .Jump(&label)
+ .JumpLoop(&label, 0)
.Bind(&after_jump1)
.Return();
@@ -813,11 +715,11 @@ TEST_F(BytecodeArrayBuilderTest, LabelReuse) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
CHECK_EQ(iterator.GetImmediateOperand(0), 2);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetImmediateOperand(0), -2);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -3);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
iterator.Advance();
@@ -834,9 +736,9 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
BytecodeLabel label, after_jump0, after_jump1;
builder.Jump(&label)
.Bind(&label)
- .Jump(&label)
+ .JumpLoop(&label, 0)
.Bind(&after_jump0)
- .Jump(&label)
+ .JumpLoop(&label, 0)
.Bind(&after_jump1);
}
builder.Return();
@@ -847,11 +749,11 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
CHECK_EQ(iterator.GetImmediateOperand(0), 2);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetImmediateOperand(0), -2);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -3);
iterator.Advance();
}
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/unittests/interpreter/bytecode-array-writer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698