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

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

Powered by Google App Engine
This is Rietveld 408576698