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

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

Issue 2242193002: [Interpreter] Avoid accessing Isolate from during bytecode generation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_sourceposition
Patch Set: Rebase Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 builder.CallRuntime(Runtime::kInlineIsArray, reg, 1) 369 builder.CallRuntime(Runtime::kInlineIsArray, reg, 1)
370 .CallRuntime(Runtime::kInlineIsArray, wide, 1); 370 .CallRuntime(Runtime::kInlineIsArray, wide, 1);
371 371
372 builder.Debugger(); 372 builder.Debugger();
373 for (size_t i = 0; i < arraysize(end); i++) { 373 for (size_t i = 0; i < arraysize(end); i++) {
374 builder.Bind(&end[i]); 374 builder.Bind(&end[i]);
375 } 375 }
376 builder.Return(); 376 builder.Return();
377 377
378 // Generate BytecodeArray. 378 // Generate BytecodeArray.
379 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); 379 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate());
380 CHECK_EQ(the_array->frame_size(), 380 CHECK_EQ(the_array->frame_size(),
381 builder.fixed_and_temporary_register_count() * kPointerSize); 381 builder.fixed_and_temporary_register_count() * kPointerSize);
382 382
383 // Build scorecard of bytecodes encountered in the BytecodeArray. 383 // Build scorecard of bytecodes encountered in the BytecodeArray.
384 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); 384 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1);
385 385
386 Bytecode final_bytecode = Bytecode::kLdaZero; 386 Bytecode final_bytecode = Bytecode::kLdaZero;
387 int i = 0; 387 int i = 0;
388 while (i < the_array->length()) { 388 while (i < the_array->length()) {
389 uint8_t code = the_array->get(i); 389 uint8_t code = the_array->get(i);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 builder.StoreAccumulatorInRegister(temporaries.NewRegister()); 458 builder.StoreAccumulatorInRegister(temporaries.NewRegister());
459 } 459 }
460 if (temps > 0) { 460 if (temps > 0) {
461 // Ensure temporaries are used so not optimized away by the 461 // Ensure temporaries are used so not optimized away by the
462 // register optimizer. 462 // register optimizer.
463 builder.New(Register(locals + contexts), Register(locals + contexts), 463 builder.New(Register(locals + contexts), Register(locals + contexts),
464 static_cast<size_t>(temps)); 464 static_cast<size_t>(temps));
465 } 465 }
466 builder.Return(); 466 builder.Return();
467 467
468 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); 468 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate());
469 int total_registers = locals + contexts + temps; 469 int total_registers = locals + contexts + temps;
470 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); 470 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize);
471 } 471 }
472 } 472 }
473 } 473 }
474 } 474 }
475 475
476 476
477 TEST_F(BytecodeArrayBuilderTest, RegisterValues) { 477 TEST_F(BytecodeArrayBuilderTest, RegisterValues) {
478 CanonicalHandleScope canonical(isolate()); 478 CanonicalHandleScope canonical(isolate());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Handle<Object> large_smi(Smi::FromInt(0x12345678), isolate()); 531 Handle<Object> large_smi(Smi::FromInt(0x12345678), isolate());
532 Handle<HeapObject> heap_num_2_copy(*heap_num_2); 532 Handle<HeapObject> heap_num_2_copy(*heap_num_2);
533 builder.LoadLiteral(heap_num_1) 533 builder.LoadLiteral(heap_num_1)
534 .LoadLiteral(heap_num_2) 534 .LoadLiteral(heap_num_2)
535 .LoadLiteral(large_smi) 535 .LoadLiteral(large_smi)
536 .LoadLiteral(heap_num_1) 536 .LoadLiteral(heap_num_1)
537 .LoadLiteral(heap_num_1) 537 .LoadLiteral(heap_num_1)
538 .LoadLiteral(heap_num_2_copy) 538 .LoadLiteral(heap_num_2_copy)
539 .Return(); 539 .Return();
540 540
541 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 541 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
542 // Should only have one entry for each identical constant. 542 // Should only have one entry for each identical constant.
543 CHECK_EQ(array->constant_pool()->length(), 3); 543 CHECK_EQ(array->constant_pool()->length(), 3);
544 } 544 }
545 545
546 static Bytecode PeepholeToBoolean(Bytecode jump_bytecode) { 546 static Bytecode PeepholeToBoolean(Bytecode jump_bytecode) {
547 return FLAG_ignition_peephole 547 return FLAG_ignition_peephole
548 ? Bytecodes::GetJumpWithoutToBoolean(jump_bytecode) 548 ? Bytecodes::GetJumpWithoutToBoolean(jump_bytecode)
549 : jump_bytecode; 549 : jump_bytecode;
550 } 550 }
551 551
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 .BinaryOperation(Token::Value::ADD, reg, 3) 584 .BinaryOperation(Token::Value::ADD, reg, 3)
585 .JumpIfTrue(&far3) 585 .JumpIfTrue(&far3)
586 .BinaryOperation(Token::Value::ADD, reg, 4) 586 .BinaryOperation(Token::Value::ADD, reg, 4)
587 .JumpIfFalse(&far4); 587 .JumpIfFalse(&far4);
588 for (int i = 0; i < kFarJumpDistance - 20; i++) { 588 for (int i = 0; i < kFarJumpDistance - 20; i++) {
589 builder.Debugger(); 589 builder.Debugger();
590 } 590 }
591 builder.Bind(&far0).Bind(&far1).Bind(&far2).Bind(&far3).Bind(&far4); 591 builder.Bind(&far0).Bind(&far1).Bind(&far2).Bind(&far3).Bind(&far4);
592 builder.Return(); 592 builder.Return();
593 593
594 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 594 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
595 DCHECK_EQ(array->length(), 40 + kFarJumpDistance - 20 + 1); 595 DCHECK_EQ(array->length(), 40 + kFarJumpDistance - 20 + 1);
596 596
597 BytecodeArrayIterator iterator(array); 597 BytecodeArrayIterator iterator(array);
598 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 598 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
599 CHECK_EQ(iterator.GetImmediateOperand(0), 20); 599 CHECK_EQ(iterator.GetImmediateOperand(0), 20);
600 iterator.Advance(); 600 iterator.Advance();
601 601
602 // Ignore compare operation. 602 // Ignore compare operation.
603 iterator.Advance(); 603 iterator.Advance();
604 604
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 builder.BinaryOperation(Token::Value::ADD, reg, 1).JumpIfFalse(&label4); 705 builder.BinaryOperation(Token::Value::ADD, reg, 1).JumpIfFalse(&label4);
706 builder.BinaryOperation(Token::Value::ADD, reg, 2).JumpIfTrue(&label3); 706 builder.BinaryOperation(Token::Value::ADD, reg, 2).JumpIfTrue(&label3);
707 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2); 707 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2);
708 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1); 708 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1);
709 builder.Jump(&label0); 709 builder.Jump(&label0);
710 BytecodeLabel end; 710 BytecodeLabel end;
711 builder.Bind(&end); 711 builder.Bind(&end);
712 builder.Return(); 712 builder.Return();
713 713
714 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 714 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
715 BytecodeArrayIterator iterator(array); 715 BytecodeArrayIterator iterator(array);
716 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 716 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
717 CHECK_EQ(iterator.GetImmediateOperand(0), 0); 717 CHECK_EQ(iterator.GetImmediateOperand(0), 0);
718 iterator.Advance(); 718 iterator.Advance();
719 // Ignore compare operation. 719 // Ignore compare operation.
720 iterator.Advance(); 720 iterator.Advance();
721 CHECK_EQ(iterator.current_bytecode(), 721 CHECK_EQ(iterator.current_bytecode(),
722 PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); 722 PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue));
723 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 723 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
724 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 724 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 BytecodeLabel label, after_jump0, after_jump1; 799 BytecodeLabel label, after_jump0, after_jump1;
800 800
801 builder.Jump(&label) 801 builder.Jump(&label)
802 .Bind(&label) 802 .Bind(&label)
803 .Jump(&label) 803 .Jump(&label)
804 .Bind(&after_jump0) 804 .Bind(&after_jump0)
805 .Jump(&label) 805 .Jump(&label)
806 .Bind(&after_jump1) 806 .Bind(&after_jump1)
807 .Return(); 807 .Return();
808 808
809 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 809 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
810 BytecodeArrayIterator iterator(array); 810 BytecodeArrayIterator iterator(array);
811 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 811 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
812 CHECK_EQ(iterator.GetImmediateOperand(0), 2); 812 CHECK_EQ(iterator.GetImmediateOperand(0), 2);
813 iterator.Advance(); 813 iterator.Advance();
814 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 814 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
815 CHECK_EQ(iterator.GetImmediateOperand(0), 0); 815 CHECK_EQ(iterator.GetImmediateOperand(0), 0);
816 iterator.Advance(); 816 iterator.Advance();
817 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 817 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
818 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 818 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
819 iterator.Advance(); 819 iterator.Advance();
(...skipping 12 matching lines...) Expand all
832 BytecodeLabel label, after_jump0, after_jump1; 832 BytecodeLabel label, after_jump0, after_jump1;
833 builder.Jump(&label) 833 builder.Jump(&label)
834 .Bind(&label) 834 .Bind(&label)
835 .Jump(&label) 835 .Jump(&label)
836 .Bind(&after_jump0) 836 .Bind(&after_jump0)
837 .Jump(&label) 837 .Jump(&label)
838 .Bind(&after_jump1); 838 .Bind(&after_jump1);
839 } 839 }
840 builder.Return(); 840 builder.Return();
841 841
842 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 842 Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
843 BytecodeArrayIterator iterator(array); 843 BytecodeArrayIterator iterator(array);
844 for (int i = 0; i < kRepeats; i++) { 844 for (int i = 0; i < kRepeats; i++) {
845 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 845 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
846 CHECK_EQ(iterator.GetImmediateOperand(0), 2); 846 CHECK_EQ(iterator.GetImmediateOperand(0), 2);
847 iterator.Advance(); 847 iterator.Advance();
848 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 848 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
849 CHECK_EQ(iterator.GetImmediateOperand(0), 0); 849 CHECK_EQ(iterator.GetImmediateOperand(0), 0);
850 iterator.Advance(); 850 iterator.Advance();
851 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 851 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
852 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 852 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
853 iterator.Advance(); 853 iterator.Advance();
854 } 854 }
855 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); 855 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
856 iterator.Advance(); 856 iterator.Advance();
857 CHECK(iterator.done()); 857 CHECK(iterator.done());
858 } 858 }
859 859
860 } // namespace interpreter 860 } // namespace interpreter
861 } // namespace internal 861 } // namespace internal
862 } // namespace v8 862 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-interpreter-intrinsics.cc ('k') | test/unittests/interpreter/bytecode-array-iterator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698