| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2416 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 2416 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 2417 CopyBlock(new_addr, old_addr, obj_size); | 2417 CopyBlock(new_addr, old_addr, obj_size); |
| 2418 // Relocate the copy. | 2418 // Relocate the copy. |
| 2419 Code* new_code = Code::cast(result); | 2419 Code* new_code = Code::cast(result); |
| 2420 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); | 2420 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); |
| 2421 new_code->Relocate(new_addr - old_addr); | 2421 new_code->Relocate(new_addr - old_addr); |
| 2422 return new_code; | 2422 return new_code; |
| 2423 } | 2423 } |
| 2424 | 2424 |
| 2425 | 2425 |
| 2426 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { | 2426 Object* Heap::AddPatchToCode(Code* code, Code* patch) { |
| 2427 // Allocate ByteArray before the Code object, so that we do not risk | 2427 int space_size = patch->instruction_size(); |
| 2428 // leaving uninitialized Code object (and breaking the heap). | 2428 int new_body_size = RoundUp(code->instruction_size() + space_size, |
| 2429 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED); | 2429 kObjectAlignment); |
| 2430 if (reloc_info_array->IsFailure()) return reloc_info_array; | |
| 2431 | |
| 2432 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); | |
| 2433 | 2430 |
| 2434 int sinfo_size = code->sinfo_size(); | 2431 int sinfo_size = code->sinfo_size(); |
| 2435 | 2432 |
| 2436 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); | 2433 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); |
| 2437 | 2434 |
| 2438 Address old_addr = code->address(); | 2435 Address old_addr = code->address(); |
| 2439 | 2436 |
| 2440 size_t relocation_offset = | |
| 2441 static_cast<size_t>(code->instruction_end() - old_addr); | |
| 2442 | |
| 2443 Object* result; | 2437 Object* result; |
| 2444 if (new_obj_size > MaxObjectSizeInPagedSpace()) { | 2438 if (new_obj_size > MaxObjectSizeInPagedSpace()) { |
| 2445 result = lo_space_->AllocateRawCode(new_obj_size); | 2439 result = lo_space_->AllocateRawCode(new_obj_size); |
| 2446 } else { | 2440 } else { |
| 2447 result = code_space_->AllocateRaw(new_obj_size); | 2441 result = code_space_->AllocateRaw(new_obj_size); |
| 2448 } | 2442 } |
| 2449 | 2443 |
| 2450 if (result->IsFailure()) return result; | 2444 if (result->IsFailure()) return result; |
| 2451 | 2445 |
| 2452 // Copy code object. | 2446 // Copy code object. |
| 2453 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 2447 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 2454 | 2448 |
| 2449 int first_part_size = |
| 2450 code->instruction_start() + code->instruction_size() - old_addr; |
| 2451 |
| 2455 // Copy header and instructions. | 2452 // Copy header and instructions. |
| 2456 memcpy(new_addr, old_addr, relocation_offset); | 2453 memcpy(new_addr, old_addr, first_part_size); |
| 2457 | 2454 |
| 2458 Code* new_code = Code::cast(result); | 2455 Code* new_code = Code::cast(result); |
| 2459 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); | 2456 new_code->set_instruction_size(code->instruction_size() + space_size); |
| 2460 | 2457 |
| 2461 // Copy patched rinfo. | 2458 // Copy patch instructions ignoring its rinfo/sinfo. |
| 2462 memcpy(new_code->relocation_start(), reloc_info.start(), reloc_info.length()); | 2459 memcpy(new_addr + first_part_size, patch->instruction_start(), space_size); |
| 2460 |
| 2463 // Copy sinfo. | 2461 // Copy sinfo. |
| 2464 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); | 2462 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); |
| 2465 | 2463 |
| 2466 // Relocate the copy. | 2464 // Relocate the copy. |
| 2467 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); | 2465 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); |
| 2468 new_code->Relocate(new_addr - old_addr); | 2466 new_code->Relocate(new_addr - old_addr); |
| 2469 | 2467 |
| 2470 #ifdef DEBUG | 2468 #ifdef DEBUG |
| 2471 code->Verify(); | 2469 new_code->Verify(); |
| 2472 #endif | 2470 #endif |
| 2473 return new_code; | 2471 return new_code; |
| 2474 } | 2472 } |
| 2475 | 2473 |
| 2476 | 2474 |
| 2477 Object* Heap::Allocate(Map* map, AllocationSpace space) { | 2475 Object* Heap::Allocate(Map* map, AllocationSpace space) { |
| 2478 ASSERT(gc_state_ == NOT_IN_GC); | 2476 ASSERT(gc_state_ == NOT_IN_GC); |
| 2479 ASSERT(map->instance_type() != MAP_TYPE); | 2477 ASSERT(map->instance_type() != MAP_TYPE); |
| 2480 // If allocation failures are disallowed, we may allocate in a different | 2478 // If allocation failures are disallowed, we may allocate in a different |
| 2481 // space when new space is full and the object is not a large object. | 2479 // space when new space is full and the object is not a large object. |
| (...skipping 2349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4831 void ExternalStringTable::TearDown() { | 4829 void ExternalStringTable::TearDown() { |
| 4832 new_space_strings_.Free(); | 4830 new_space_strings_.Free(); |
| 4833 old_space_strings_.Free(); | 4831 old_space_strings_.Free(); |
| 4834 } | 4832 } |
| 4835 | 4833 |
| 4836 | 4834 |
| 4837 List<Object*> ExternalStringTable::new_space_strings_; | 4835 List<Object*> ExternalStringTable::new_space_strings_; |
| 4838 List<Object*> ExternalStringTable::old_space_strings_; | 4836 List<Object*> ExternalStringTable::old_space_strings_; |
| 4839 | 4837 |
| 4840 } } // namespace v8::internal | 4838 } } // namespace v8::internal |
| OLD | NEW |