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

Side by Side Diff: src/heap/heap.cc

Issue 1030353003: Enable constant pool support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 3690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3701 isolate_->code_range()->contains(code->address())); 3701 isolate_->code_range()->contains(code->address()));
3702 code->set_gc_metadata(Smi::FromInt(0)); 3702 code->set_gc_metadata(Smi::FromInt(0));
3703 code->set_ic_age(global_ic_age_); 3703 code->set_ic_age(global_ic_age_);
3704 return code; 3704 return code;
3705 } 3705 }
3706 3706
3707 3707
3708 AllocationResult Heap::CopyCode(Code* code) { 3708 AllocationResult Heap::CopyCode(Code* code) {
3709 AllocationResult allocation; 3709 AllocationResult allocation;
3710 HeapObject* new_constant_pool; 3710 HeapObject* new_constant_pool;
3711 if (FLAG_enable_ool_constant_pool && 3711 if (FLAG_enable_ool_constant_pool) {
3712 code->constant_pool() != empty_constant_pool_array()) { 3712 ConstantPoolArray* constant_pool =
3713 // Copy the constant pool, since edits to the copied code may modify 3713 reinterpret_cast<ConstantPoolArray*>(code->constant_pool());
3714 // the constant pool. 3714 if (constant_pool != empty_constant_pool_array()) {
3715 allocation = CopyConstantPoolArray(code->constant_pool()); 3715 // Copy the constant pool, since edits to the copied code may modify
3716 if (!allocation.To(&new_constant_pool)) return allocation; 3716 // the constant pool.
3717 } else { 3717 allocation = CopyConstantPoolArray(constant_pool);
3718 new_constant_pool = empty_constant_pool_array(); 3718 if (!allocation.To(&new_constant_pool)) return allocation;
3719 } else {
3720 new_constant_pool = empty_constant_pool_array();
3721 }
3719 } 3722 }
3720 3723
3721 HeapObject* result; 3724 HeapObject* result;
3722 // Allocate an object the same size as the code object. 3725 // Allocate an object the same size as the code object.
3723 int obj_size = code->Size(); 3726 int obj_size = code->Size();
3724 allocation = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); 3727 allocation = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE);
3725 if (!allocation.To(&result)) return allocation; 3728 if (!allocation.To(&result)) return allocation;
3726 3729
3727 // Copy code object. 3730 // Copy code object.
3728 Address old_addr = code->address(); 3731 Address old_addr = code->address();
3729 Address new_addr = result->address(); 3732 Address new_addr = result->address();
3730 CopyBlock(new_addr, old_addr, obj_size); 3733 CopyBlock(new_addr, old_addr, obj_size);
3731 Code* new_code = Code::cast(result); 3734 Code* new_code = Code::cast(result);
3732 3735
3733 // Update the constant pool. 3736 if (FLAG_enable_ool_constant_pool) {
3734 new_code->set_constant_pool(new_constant_pool); 3737 // Update the constant pool.
3738 new_code->set_constant_pool(new_constant_pool);
3739 }
3735 3740
3736 // Relocate the copy. 3741 // Relocate the copy.
3737 DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() || 3742 DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() ||
3738 isolate_->code_range()->contains(code->address())); 3743 isolate_->code_range()->contains(code->address()));
3739 new_code->Relocate(new_addr - old_addr); 3744 new_code->Relocate(new_addr - old_addr);
3740 return new_code; 3745 return new_code;
3741 } 3746 }
3742 3747
3743 3748
3744 AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) { 3749 AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
3745 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we 3750 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we
3746 // do not risk leaving uninitialized Code object (and breaking the heap). 3751 // do not risk leaving uninitialized Code object (and breaking the heap).
3747 ByteArray* reloc_info_array; 3752 ByteArray* reloc_info_array;
3748 { 3753 {
3749 AllocationResult allocation = 3754 AllocationResult allocation =
3750 AllocateByteArray(reloc_info.length(), TENURED); 3755 AllocateByteArray(reloc_info.length(), TENURED);
3751 if (!allocation.To(&reloc_info_array)) return allocation; 3756 if (!allocation.To(&reloc_info_array)) return allocation;
3752 } 3757 }
3753 HeapObject* new_constant_pool; 3758 HeapObject* new_constant_pool;
3754 if (FLAG_enable_ool_constant_pool && 3759 if (FLAG_enable_ool_constant_pool) {
3755 code->constant_pool() != empty_constant_pool_array()) { 3760 ConstantPoolArray* constant_pool =
3756 // Copy the constant pool, since edits to the copied code may modify 3761 reinterpret_cast<ConstantPoolArray*>(code->constant_pool());
3757 // the constant pool. 3762 if (constant_pool != empty_constant_pool_array()) {
3758 AllocationResult allocation = CopyConstantPoolArray(code->constant_pool()); 3763 // Copy the constant pool, since edits to the copied code may modify
3759 if (!allocation.To(&new_constant_pool)) return allocation; 3764 // the constant pool.
3760 } else { 3765 AllocationResult allocation = CopyConstantPoolArray(constant_pool);
3761 new_constant_pool = empty_constant_pool_array(); 3766 if (!allocation.To(&new_constant_pool)) return allocation;
3767 } else {
3768 new_constant_pool = empty_constant_pool_array();
3769 }
3762 } 3770 }
3763 3771
3764 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); 3772 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
3765 3773
3766 int new_obj_size = Code::SizeFor(new_body_size); 3774 int new_obj_size = Code::SizeFor(new_body_size);
3767 3775
3768 Address old_addr = code->address(); 3776 Address old_addr = code->address();
3769 3777
3770 size_t relocation_offset = 3778 size_t relocation_offset =
3771 static_cast<size_t>(code->instruction_end() - old_addr); 3779 static_cast<size_t>(code->instruction_end() - old_addr);
3772 3780
3773 HeapObject* result; 3781 HeapObject* result;
3774 AllocationResult allocation = 3782 AllocationResult allocation =
3775 AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE); 3783 AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE);
3776 if (!allocation.To(&result)) return allocation; 3784 if (!allocation.To(&result)) return allocation;
3777 3785
3778 // Copy code object. 3786 // Copy code object.
3779 Address new_addr = result->address(); 3787 Address new_addr = result->address();
3780 3788
3781 // Copy header and instructions. 3789 // Copy header and instructions.
3782 CopyBytes(new_addr, old_addr, relocation_offset); 3790 CopyBytes(new_addr, old_addr, relocation_offset);
3783 3791
3784 Code* new_code = Code::cast(result); 3792 Code* new_code = Code::cast(result);
3785 new_code->set_relocation_info(reloc_info_array); 3793 new_code->set_relocation_info(reloc_info_array);
3786 3794
3787 // Update constant pool. 3795 if (FLAG_enable_ool_constant_pool) {
3788 new_code->set_constant_pool(new_constant_pool); 3796 // Update constant pool.
3797 new_code->set_constant_pool(new_constant_pool);
3798 }
3789 3799
3790 // Copy patched rinfo. 3800 // Copy patched rinfo.
3791 CopyBytes(new_code->relocation_start(), reloc_info.start(), 3801 CopyBytes(new_code->relocation_start(), reloc_info.start(),
3792 static_cast<size_t>(reloc_info.length())); 3802 static_cast<size_t>(reloc_info.length()));
3793 3803
3794 // Relocate the copy. 3804 // Relocate the copy.
3795 DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() || 3805 DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() ||
3796 isolate_->code_range()->contains(code->address())); 3806 isolate_->code_range()->contains(code->address()));
3797 new_code->Relocate(new_addr - old_addr); 3807 new_code->Relocate(new_addr - old_addr);
3798 3808
(...skipping 2591 matching lines...) Expand 10 before | Expand all | Expand 10 after
6390 static_cast<int>(object_sizes_last_time_[index])); 6400 static_cast<int>(object_sizes_last_time_[index]));
6391 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6401 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6392 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6402 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6393 6403
6394 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6404 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6395 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6405 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6396 ClearObjectStats(); 6406 ClearObjectStats();
6397 } 6407 }
6398 } 6408 }
6399 } // namespace v8::internal 6409 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698