OLD | NEW |
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/heap/heap.h" | 5 #include "src/heap/heap.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/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3420 copy->set_frame_size(bytecode_array->frame_size()); | 3420 copy->set_frame_size(bytecode_array->frame_size()); |
3421 copy->set_parameter_count(bytecode_array->parameter_count()); | 3421 copy->set_parameter_count(bytecode_array->parameter_count()); |
3422 copy->set_constant_pool(bytecode_array->constant_pool()); | 3422 copy->set_constant_pool(bytecode_array->constant_pool()); |
3423 copy->set_handler_table(bytecode_array->handler_table()); | 3423 copy->set_handler_table(bytecode_array->handler_table()); |
3424 copy->set_source_position_table(bytecode_array->source_position_table()); | 3424 copy->set_source_position_table(bytecode_array->source_position_table()); |
3425 copy->set_interrupt_budget(bytecode_array->interrupt_budget()); | 3425 copy->set_interrupt_budget(bytecode_array->interrupt_budget()); |
3426 bytecode_array->CopyBytecodesTo(copy); | 3426 bytecode_array->CopyBytecodesTo(copy); |
3427 return copy; | 3427 return copy; |
3428 } | 3428 } |
3429 | 3429 |
3430 AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) { | |
3431 // Allocate ByteArray before the Code object, so that we do not risk | |
3432 // leaving uninitialized Code object (and breaking the heap). | |
3433 ByteArray* reloc_info_array = nullptr; | |
3434 { | |
3435 AllocationResult allocation = | |
3436 AllocateByteArray(reloc_info.length(), TENURED); | |
3437 if (!allocation.To(&reloc_info_array)) return allocation; | |
3438 } | |
3439 | |
3440 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); | |
3441 | |
3442 int new_obj_size = Code::SizeFor(new_body_size); | |
3443 | |
3444 Address old_addr = code->address(); | |
3445 | |
3446 size_t relocation_offset = | |
3447 static_cast<size_t>(code->instruction_end() - old_addr); | |
3448 | |
3449 HeapObject* result = nullptr; | |
3450 AllocationResult allocation = AllocateRaw(new_obj_size, CODE_SPACE); | |
3451 if (!allocation.To(&result)) return allocation; | |
3452 | |
3453 // Copy code object. | |
3454 Address new_addr = result->address(); | |
3455 | |
3456 // Copy header and instructions. | |
3457 CopyBytes(new_addr, old_addr, relocation_offset); | |
3458 | |
3459 Code* new_code = Code::cast(result); | |
3460 new_code->set_relocation_info(reloc_info_array); | |
3461 | |
3462 // Copy patched rinfo. | |
3463 CopyBytes(new_code->relocation_start(), reloc_info.start(), | |
3464 static_cast<size_t>(reloc_info.length())); | |
3465 | |
3466 // Relocate the copy. | |
3467 DCHECK(IsAligned(bit_cast<intptr_t>(new_code->address()), kCodeAlignment)); | |
3468 DCHECK(!memory_allocator()->code_range()->valid() || | |
3469 memory_allocator()->code_range()->contains(code->address()) || | |
3470 new_obj_size <= code_space()->AreaSize()); | |
3471 | |
3472 new_code->Relocate(new_addr - old_addr); | |
3473 // We have to iterate over over the object and process its pointers when | |
3474 // black allocation is on. | |
3475 incremental_marking()->IterateBlackObject(new_code); | |
3476 #ifdef VERIFY_HEAP | |
3477 if (FLAG_verify_heap) code->ObjectVerify(); | |
3478 #endif | |
3479 return new_code; | |
3480 } | |
3481 | |
3482 | |
3483 void Heap::InitializeAllocationMemento(AllocationMemento* memento, | 3430 void Heap::InitializeAllocationMemento(AllocationMemento* memento, |
3484 AllocationSite* allocation_site) { | 3431 AllocationSite* allocation_site) { |
3485 memento->set_map_no_write_barrier(allocation_memento_map()); | 3432 memento->set_map_no_write_barrier(allocation_memento_map()); |
3486 DCHECK(allocation_site->map() == allocation_site_map()); | 3433 DCHECK(allocation_site->map() == allocation_site_map()); |
3487 memento->set_allocation_site(allocation_site, SKIP_WRITE_BARRIER); | 3434 memento->set_allocation_site(allocation_site, SKIP_WRITE_BARRIER); |
3488 if (FLAG_allocation_site_pretenuring) { | 3435 if (FLAG_allocation_site_pretenuring) { |
3489 allocation_site->IncrementMementoCreateCount(); | 3436 allocation_site->IncrementMementoCreateCount(); |
3490 } | 3437 } |
3491 } | 3438 } |
3492 | 3439 |
(...skipping 2959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6452 } | 6399 } |
6453 | 6400 |
6454 | 6401 |
6455 // static | 6402 // static |
6456 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6403 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6457 return StaticVisitorBase::GetVisitorId(map); | 6404 return StaticVisitorBase::GetVisitorId(map); |
6458 } | 6405 } |
6459 | 6406 |
6460 } // namespace internal | 6407 } // namespace internal |
6461 } // namespace v8 | 6408 } // namespace v8 |
OLD | NEW |