OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-label.h" | 9 #include "src/interpreter/bytecode-label.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 .CompareOperation(Token::Value::LTE, reg, 6) | 183 .CompareOperation(Token::Value::LTE, reg, 6) |
184 .CompareOperation(Token::Value::GTE, reg, 7) | 184 .CompareOperation(Token::Value::GTE, reg, 7) |
185 .CompareOperation(Token::Value::INSTANCEOF, reg, 8) | 185 .CompareOperation(Token::Value::INSTANCEOF, reg, 8) |
186 .CompareOperation(Token::Value::IN, reg, 9); | 186 .CompareOperation(Token::Value::IN, reg, 9); |
187 | 187 |
188 // Emit conversion operator invocations. | 188 // Emit conversion operator invocations. |
189 builder.ConvertAccumulatorToNumber(reg) | 189 builder.ConvertAccumulatorToNumber(reg) |
190 .ConvertAccumulatorToObject(reg) | 190 .ConvertAccumulatorToObject(reg) |
191 .ConvertAccumulatorToName(reg); | 191 .ConvertAccumulatorToName(reg); |
192 | 192 |
193 // Emit control flow. Return must be the last instruction. | 193 // Short jumps with Imm8 operands |
194 BytecodeLabel start; | |
195 builder.Bind(&start); | |
196 { | 194 { |
197 // Short jumps with Imm8 operands | 195 BytecodeLabel start, after_jump1, after_jump2, after_jump3, after_jump4; |
198 BytecodeLabel after_jump; | 196 builder.Bind(&start) |
199 builder.Jump(&start) | 197 .Jump(&after_jump1) |
200 .Bind(&after_jump) | 198 .Bind(&after_jump1) |
201 .JumpIfNull(&start) | 199 .JumpIfNull(&after_jump2) |
202 .JumpIfUndefined(&start) | 200 .Bind(&after_jump2) |
203 .JumpIfNotHole(&start); | 201 .JumpIfUndefined(&after_jump3) |
| 202 .Bind(&after_jump3) |
| 203 .JumpIfNotHole(&after_jump4) |
| 204 .Bind(&after_jump4) |
| 205 .JumpLoop(&start, 0); |
204 } | 206 } |
205 | 207 |
206 // Longer jumps with constant operands | 208 // Longer jumps with constant operands |
207 BytecodeLabel end[8]; | 209 BytecodeLabel end[8]; |
208 { | 210 { |
209 BytecodeLabel after_jump; | 211 BytecodeLabel after_jump; |
210 builder.Jump(&end[0]) | 212 builder.Jump(&end[0]) |
211 .Bind(&after_jump) | 213 .Bind(&after_jump) |
212 .LoadTrue() | 214 .LoadTrue() |
213 .JumpIfTrue(&end[1]) | 215 .JumpIfTrue(&end[1]) |
214 .LoadTrue() | 216 .LoadTrue() |
215 .JumpIfFalse(&end[2]) | 217 .JumpIfFalse(&end[2]) |
216 .LoadLiteral(Smi::FromInt(0)) | 218 .LoadLiteral(Smi::FromInt(0)) |
217 .JumpIfTrue(&end[3]) | 219 .JumpIfTrue(&end[3]) |
218 .LoadLiteral(Smi::FromInt(0)) | 220 .LoadLiteral(Smi::FromInt(0)) |
219 .JumpIfFalse(&end[4]) | 221 .JumpIfFalse(&end[4]) |
220 .JumpIfNull(&end[5]) | 222 .JumpIfNull(&end[5]) |
221 .JumpIfUndefined(&end[6]) | 223 .JumpIfUndefined(&end[6]) |
222 .JumpIfNotHole(&end[7]); | 224 .JumpIfNotHole(&end[7]); |
223 } | 225 } |
224 | 226 |
225 // Perform an operation that returns boolean value to | 227 // Perform an operation that returns boolean value to |
226 // generate JumpIfTrue/False | 228 // generate JumpIfTrue/False |
227 builder.CompareOperation(Token::Value::EQ, reg, 1) | 229 { |
228 .JumpIfTrue(&start) | 230 BytecodeLabel after_jump1, after_jump2; |
229 .CompareOperation(Token::Value::EQ, reg, 2) | 231 builder.CompareOperation(Token::Value::EQ, reg, 1) |
230 .JumpIfFalse(&start); | 232 .JumpIfTrue(&after_jump1) |
| 233 .Bind(&after_jump1) |
| 234 .CompareOperation(Token::Value::EQ, reg, 2) |
| 235 .JumpIfFalse(&after_jump2) |
| 236 .Bind(&after_jump2); |
| 237 } |
| 238 |
231 // Perform an operation that returns a non-boolean operation to | 239 // Perform an operation that returns a non-boolean operation to |
232 // generate JumpIfToBooleanTrue/False. | 240 // generate JumpIfToBooleanTrue/False. |
233 builder.BinaryOperation(Token::Value::ADD, reg, 1) | |
234 .JumpIfTrue(&start) | |
235 .BinaryOperation(Token::Value::ADD, reg, 2) | |
236 .JumpIfFalse(&start); | |
237 // Insert dummy ops to force longer jumps | |
238 for (int i = 0; i < 128; i++) { | |
239 builder.LoadTrue(); | |
240 } | |
241 // Longer jumps requiring Constant operand | |
242 { | 241 { |
243 BytecodeLabel after_jump; | 242 BytecodeLabel after_jump1, after_jump2; |
244 builder.Jump(&start) | |
245 .Bind(&after_jump) | |
246 .JumpIfNull(&start) | |
247 .JumpIfUndefined(&start) | |
248 .JumpIfNotHole(&start); | |
249 // Perform an operation that returns boolean value to | |
250 // generate JumpIfTrue/False | |
251 builder.CompareOperation(Token::Value::EQ, reg, 1) | |
252 .JumpIfTrue(&start) | |
253 .CompareOperation(Token::Value::EQ, reg, 2) | |
254 .JumpIfFalse(&start); | |
255 // Perform an operation that returns a non-boolean operation to | |
256 // generate JumpIfToBooleanTrue/False. | |
257 builder.BinaryOperation(Token::Value::ADD, reg, 1) | 243 builder.BinaryOperation(Token::Value::ADD, reg, 1) |
258 .JumpIfTrue(&start) | 244 .JumpIfTrue(&after_jump1) |
| 245 .Bind(&after_jump1) |
259 .BinaryOperation(Token::Value::ADD, reg, 2) | 246 .BinaryOperation(Token::Value::ADD, reg, 2) |
260 .JumpIfFalse(&start); | 247 .JumpIfFalse(&after_jump2) |
| 248 .Bind(&after_jump2); |
261 } | 249 } |
262 | 250 |
263 // Emit stack check bytecode. | 251 // Emit stack check bytecode. |
264 builder.StackCheck(0); | 252 builder.StackCheck(0); |
265 | 253 |
266 // Emit an OSR poll bytecode. | |
267 builder.OsrPoll(1); | |
268 | |
269 // Emit throw and re-throw in it's own basic block so that the rest of the | 254 // Emit throw and re-throw in it's own basic block so that the rest of the |
270 // code isn't omitted due to being dead. | 255 // code isn't omitted due to being dead. |
271 BytecodeLabel after_throw; | 256 BytecodeLabel after_throw; |
272 builder.Throw().Bind(&after_throw); | 257 builder.Throw().Bind(&after_throw); |
273 BytecodeLabel after_rethrow; | 258 BytecodeLabel after_rethrow; |
274 builder.ReThrow().Bind(&after_rethrow); | 259 builder.ReThrow().Bind(&after_rethrow); |
275 | 260 |
276 builder.ForInPrepare(reg, reg) | 261 builder.ForInPrepare(reg, reg) |
277 .ForInContinue(reg, reg) | 262 .ForInContinue(reg, reg) |
278 .ForInNext(reg, reg, reg, 1) | 263 .ForInNext(reg, reg, reg, 1) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 317 |
333 // CreateClosureWide | 318 // CreateClosureWide |
334 builder.CreateClosure(1000, NOT_TENURED); | 319 builder.CreateClosure(1000, NOT_TENURED); |
335 | 320 |
336 // Emit wide variant of literal creation operations. | 321 // Emit wide variant of literal creation operations. |
337 builder.CreateRegExpLiteral(factory->NewStringFromStaticChars("wide_literal"), | 322 builder.CreateRegExpLiteral(factory->NewStringFromStaticChars("wide_literal"), |
338 0, 0) | 323 0, 0) |
339 .CreateArrayLiteral(factory->NewFixedArray(2), 0, 0) | 324 .CreateArrayLiteral(factory->NewFixedArray(2), 0, 0) |
340 .CreateObjectLiteral(factory->NewFixedArray(2), 0, 0, reg); | 325 .CreateObjectLiteral(factory->NewFixedArray(2), 0, 0, reg); |
341 | 326 |
342 // Longer jumps requiring ConstantWide operand | |
343 { | |
344 BytecodeLabel after_jump; | |
345 builder.Jump(&start) | |
346 .Bind(&after_jump) | |
347 .JumpIfNull(&start) | |
348 .JumpIfUndefined(&start) | |
349 .JumpIfNotHole(&start); | |
350 } | |
351 | |
352 // Perform an operation that returns boolean value to | |
353 // generate JumpIfTrue/False | |
354 builder.CompareOperation(Token::Value::EQ, reg, 1) | |
355 .JumpIfTrue(&start) | |
356 .CompareOperation(Token::Value::EQ, reg, 2) | |
357 .JumpIfFalse(&start); | |
358 | |
359 // Perform an operation that returns a non-boolean operation to | |
360 // generate JumpIfToBooleanTrue/False. | |
361 builder.BinaryOperation(Token::Value::ADD, reg, 1) | |
362 .JumpIfTrue(&start) | |
363 .BinaryOperation(Token::Value::ADD, reg, 2) | |
364 .JumpIfFalse(&start); | |
365 | |
366 // Emit generator operations | 327 // Emit generator operations |
367 builder.SuspendGenerator(reg) | 328 builder.SuspendGenerator(reg) |
368 .ResumeGenerator(reg); | 329 .ResumeGenerator(reg); |
369 | 330 |
370 // Intrinsics handled by the interpreter. | 331 // Intrinsics handled by the interpreter. |
371 builder.CallRuntime(Runtime::kInlineIsArray, reg, 1) | 332 builder.CallRuntime(Runtime::kInlineIsArray, reg, 1) |
372 .CallRuntime(Runtime::kInlineIsArray, wide, 1); | 333 .CallRuntime(Runtime::kInlineIsArray, wide, 1); |
373 | 334 |
| 335 // Emit debugger bytecode. |
374 builder.Debugger(); | 336 builder.Debugger(); |
| 337 |
| 338 // Insert dummy ops to force longer jumps. |
| 339 for (int i = 0; i < 128; i++) { |
| 340 builder.LoadTrue(); |
| 341 } |
| 342 |
| 343 // Bind labels for long jumps at the very end. |
375 for (size_t i = 0; i < arraysize(end); i++) { | 344 for (size_t i = 0; i < arraysize(end); i++) { |
376 builder.Bind(&end[i]); | 345 builder.Bind(&end[i]); |
377 } | 346 } |
| 347 |
| 348 // Return must be the last instruction. |
378 builder.Return(); | 349 builder.Return(); |
379 | 350 |
380 // Generate BytecodeArray. | 351 // Generate BytecodeArray. |
381 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate()); | 352 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate()); |
382 CHECK_EQ(the_array->frame_size(), | 353 CHECK_EQ(the_array->frame_size(), |
383 builder.fixed_and_temporary_register_count() * kPointerSize); | 354 builder.fixed_and_temporary_register_count() * kPointerSize); |
384 | 355 |
385 // Build scorecard of bytecodes encountered in the BytecodeArray. | 356 // Build scorecard of bytecodes encountered in the BytecodeArray. |
386 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); | 357 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); |
387 | 358 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 iterator.Advance(); | 643 iterator.Advance(); |
673 } | 644 } |
674 | 645 |
675 | 646 |
676 TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { | 647 TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
677 CanonicalHandleScope canonical(isolate()); | 648 CanonicalHandleScope canonical(isolate()); |
678 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 1); | 649 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 1); |
679 | 650 |
680 Register reg(0); | 651 Register reg(0); |
681 | 652 |
682 BytecodeLabel label0, label1, label2, label3, label4; | 653 BytecodeLabel label0; |
683 builder.Bind(&label0) | 654 builder.Bind(&label0).JumpLoop(&label0, 0); |
684 .Jump(&label0) | 655 for (int i = 0; i < 42; i++) { |
685 .Bind(&label1) | |
686 .CompareOperation(Token::Value::EQ, reg, 1) | |
687 .JumpIfTrue(&label1) | |
688 .Bind(&label2) | |
689 .CompareOperation(Token::Value::EQ, reg, 2) | |
690 .JumpIfFalse(&label2) | |
691 .Bind(&label3) | |
692 .BinaryOperation(Token::Value::ADD, reg, 1) | |
693 .JumpIfTrue(&label3) | |
694 .Bind(&label4) | |
695 .BinaryOperation(Token::Value::ADD, reg, 2) | |
696 .JumpIfFalse(&label4); | |
697 for (int i = 0; i < 62; i++) { | |
698 BytecodeLabel after_jump; | 656 BytecodeLabel after_jump; |
699 builder.Jump(&label4).Bind(&after_jump); | 657 builder.JumpLoop(&label0, 0).Bind(&after_jump); |
700 } | 658 } |
701 | 659 |
702 // Add padding to force wide backwards jumps. | 660 // Add padding to force wide backwards jumps. |
703 for (int i = 0; i < 256; i++) { | 661 for (int i = 0; i < 256; i++) { |
704 builder.Debugger(); | 662 builder.Debugger(); |
705 } | 663 } |
706 | 664 |
707 builder.BinaryOperation(Token::Value::ADD, reg, 1).JumpIfFalse(&label4); | 665 builder.JumpLoop(&label0, 0); |
708 builder.BinaryOperation(Token::Value::ADD, reg, 2).JumpIfTrue(&label3); | |
709 builder.CompareOperation(Token::Value::EQ, reg, 1).JumpIfFalse(&label2); | |
710 builder.CompareOperation(Token::Value::EQ, reg, 2).JumpIfTrue(&label1); | |
711 builder.Jump(&label0); | |
712 BytecodeLabel end; | 666 BytecodeLabel end; |
713 builder.Bind(&end); | 667 builder.Bind(&end); |
714 builder.Return(); | 668 builder.Return(); |
715 | 669 |
716 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); | 670 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); |
717 BytecodeArrayIterator iterator(array); | 671 BytecodeArrayIterator iterator(array); |
718 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 672 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
719 CHECK_EQ(iterator.GetImmediateOperand(0), 0); | 673 CHECK_EQ(iterator.GetImmediateOperand(0), 0); |
720 iterator.Advance(); | 674 iterator.Advance(); |
721 // Ignore compare operation. | 675 for (int i = 0; i < 42; i++) { |
722 iterator.Advance(); | 676 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
723 CHECK_EQ(iterator.current_bytecode(), | |
724 PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); | |
725 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | |
726 CHECK_EQ(iterator.GetImmediateOperand(0), -3); | |
727 iterator.Advance(); | |
728 // Ignore compare operation. | |
729 iterator.Advance(); | |
730 CHECK_EQ(iterator.current_bytecode(), | |
731 PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); | |
732 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | |
733 CHECK_EQ(iterator.GetImmediateOperand(0), -3); | |
734 iterator.Advance(); | |
735 // Ignore binary operation. | |
736 iterator.Advance(); | |
737 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); | |
738 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | |
739 CHECK_EQ(iterator.GetImmediateOperand(0), -3); | |
740 iterator.Advance(); | |
741 // Ignore binary operation. | |
742 iterator.Advance(); | |
743 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); | |
744 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | |
745 CHECK_EQ(iterator.GetImmediateOperand(0), -3); | |
746 iterator.Advance(); | |
747 for (int i = 0; i < 62; i++) { | |
748 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | |
749 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); | 677 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
750 // offset of 5 (3 for binary operation and 2 for jump) | 678 // offset of 3 (because kJumpLoop takes two immediate operands) |
751 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 5); | 679 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 3 - 3); |
752 iterator.Advance(); | 680 iterator.Advance(); |
753 } | 681 } |
754 // Check padding to force wide backwards jumps. | 682 // Check padding to force wide backwards jumps. |
755 for (int i = 0; i < 256; i++) { | 683 for (int i = 0; i < 256; i++) { |
756 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger); | 684 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger); |
757 iterator.Advance(); | 685 iterator.Advance(); |
758 } | 686 } |
759 // Ignore binary operation. | 687 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
760 iterator.Advance(); | |
761 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); | |
762 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); | 688 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
763 CHECK_EQ(iterator.GetImmediateOperand(0), -389); | 689 CHECK_EQ(iterator.GetImmediateOperand(0), -386); |
764 iterator.Advance(); | |
765 // Ignore binary operation. | |
766 iterator.Advance(); | |
767 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); | |
768 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); | |
769 CHECK_EQ(iterator.GetImmediateOperand(0), -401); | |
770 iterator.Advance(); | |
771 // Ignore compare operation. | |
772 iterator.Advance(); | |
773 CHECK_EQ(iterator.current_bytecode(), | |
774 PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); | |
775 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); | |
776 CHECK_EQ(iterator.GetImmediateOperand(0), -413); | |
777 iterator.Advance(); | |
778 // Ignore compare operation. | |
779 iterator.Advance(); | |
780 CHECK_EQ(iterator.current_bytecode(), | |
781 PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); | |
782 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); | |
783 CHECK_EQ(iterator.GetImmediateOperand(0), -425); | |
784 iterator.Advance(); | |
785 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | |
786 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); | |
787 CHECK_EQ(iterator.GetImmediateOperand(0), -431); | |
788 iterator.Advance(); | 690 iterator.Advance(); |
789 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 691 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
790 iterator.Advance(); | 692 iterator.Advance(); |
791 CHECK(iterator.done()); | 693 CHECK(iterator.done()); |
792 } | 694 } |
793 | 695 |
794 | 696 |
795 TEST_F(BytecodeArrayBuilderTest, LabelReuse) { | 697 TEST_F(BytecodeArrayBuilderTest, LabelReuse) { |
796 CanonicalHandleScope canonical(isolate()); | 698 CanonicalHandleScope canonical(isolate()); |
797 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); | 699 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); |
798 | 700 |
799 // Labels can only have 1 forward reference, but | 701 // Labels can only have 1 forward reference, but |
800 // can be referred to mulitple times once bound. | 702 // can be referred to mulitple times once bound. |
801 BytecodeLabel label, after_jump0, after_jump1; | 703 BytecodeLabel label, after_jump0, after_jump1; |
802 | 704 |
803 builder.Jump(&label) | 705 builder.Jump(&label) |
804 .Bind(&label) | 706 .Bind(&label) |
805 .Jump(&label) | 707 .JumpLoop(&label, 0) |
806 .Bind(&after_jump0) | 708 .Bind(&after_jump0) |
807 .Jump(&label) | 709 .JumpLoop(&label, 0) |
808 .Bind(&after_jump1) | 710 .Bind(&after_jump1) |
809 .Return(); | 711 .Return(); |
810 | 712 |
811 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); | 713 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); |
812 BytecodeArrayIterator iterator(array); | 714 BytecodeArrayIterator iterator(array); |
813 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 715 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
814 CHECK_EQ(iterator.GetImmediateOperand(0), 2); | 716 CHECK_EQ(iterator.GetImmediateOperand(0), 2); |
815 iterator.Advance(); | 717 iterator.Advance(); |
816 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 718 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
817 CHECK_EQ(iterator.GetImmediateOperand(0), 0); | 719 CHECK_EQ(iterator.GetImmediateOperand(0), 0); |
818 iterator.Advance(); | 720 iterator.Advance(); |
819 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 721 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
820 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 722 CHECK_EQ(iterator.GetImmediateOperand(0), -3); |
821 iterator.Advance(); | 723 iterator.Advance(); |
822 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 724 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
823 iterator.Advance(); | 725 iterator.Advance(); |
824 CHECK(iterator.done()); | 726 CHECK(iterator.done()); |
825 } | 727 } |
826 | 728 |
827 | 729 |
828 TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) { | 730 TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) { |
829 CanonicalHandleScope canonical(isolate()); | 731 CanonicalHandleScope canonical(isolate()); |
830 static const int kRepeats = 3; | 732 static const int kRepeats = 3; |
831 | 733 |
832 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); | 734 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); |
833 for (int i = 0; i < kRepeats; i++) { | 735 for (int i = 0; i < kRepeats; i++) { |
834 BytecodeLabel label, after_jump0, after_jump1; | 736 BytecodeLabel label, after_jump0, after_jump1; |
835 builder.Jump(&label) | 737 builder.Jump(&label) |
836 .Bind(&label) | 738 .Bind(&label) |
837 .Jump(&label) | 739 .JumpLoop(&label, 0) |
838 .Bind(&after_jump0) | 740 .Bind(&after_jump0) |
839 .Jump(&label) | 741 .JumpLoop(&label, 0) |
840 .Bind(&after_jump1); | 742 .Bind(&after_jump1); |
841 } | 743 } |
842 builder.Return(); | 744 builder.Return(); |
843 | 745 |
844 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); | 746 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); |
845 BytecodeArrayIterator iterator(array); | 747 BytecodeArrayIterator iterator(array); |
846 for (int i = 0; i < kRepeats; i++) { | 748 for (int i = 0; i < kRepeats; i++) { |
847 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 749 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
848 CHECK_EQ(iterator.GetImmediateOperand(0), 2); | 750 CHECK_EQ(iterator.GetImmediateOperand(0), 2); |
849 iterator.Advance(); | 751 iterator.Advance(); |
850 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 752 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
851 CHECK_EQ(iterator.GetImmediateOperand(0), 0); | 753 CHECK_EQ(iterator.GetImmediateOperand(0), 0); |
852 iterator.Advance(); | 754 iterator.Advance(); |
853 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 755 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); |
854 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 756 CHECK_EQ(iterator.GetImmediateOperand(0), -3); |
855 iterator.Advance(); | 757 iterator.Advance(); |
856 } | 758 } |
857 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 759 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
858 iterator.Advance(); | 760 iterator.Advance(); |
859 CHECK(iterator.done()); | 761 CHECK(iterator.done()); |
860 } | 762 } |
861 | 763 |
862 } // namespace interpreter | 764 } // namespace interpreter |
863 } // namespace internal | 765 } // namespace internal |
864 } // namespace v8 | 766 } // namespace v8 |
OLD | NEW |