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 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 } | 2345 } |
2346 } | 2346 } |
2347 } | 2347 } |
2348 | 2348 |
2349 | 2349 |
2350 Object* Heap::CreateCode(const CodeDesc& desc, | 2350 Object* Heap::CreateCode(const CodeDesc& desc, |
2351 ZoneScopeInfo* sinfo, | 2351 ZoneScopeInfo* sinfo, |
2352 Code::Flags flags, | 2352 Code::Flags flags, |
2353 Handle<Object> self_reference) { | 2353 Handle<Object> self_reference) { |
2354 // Compute size | 2354 // Compute size |
2355 int body_size = RoundUp(desc.instr_size + desc.reloc_size, kObjectAlignment); | 2355 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
2356 int sinfo_size = 0; | 2356 int sinfo_size = 0; |
2357 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); | 2357 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); |
2358 int obj_size = Code::SizeFor(body_size, sinfo_size); | 2358 int obj_size = Code::SizeFor(body_size, sinfo_size); |
2359 ASSERT(IsAligned(obj_size, Code::kCodeAlignment)); | 2359 ASSERT(IsAligned(obj_size, Code::kCodeAlignment)); |
2360 Object* result; | 2360 Object* result; |
2361 if (obj_size > MaxObjectSizeInPagedSpace()) { | 2361 if (obj_size > MaxObjectSizeInPagedSpace()) { |
2362 result = lo_space_->AllocateRawCode(obj_size); | 2362 result = lo_space_->AllocateRawCode(obj_size); |
2363 } else { | 2363 } else { |
2364 result = code_space_->AllocateRaw(obj_size); | 2364 result = code_space_->AllocateRaw(obj_size); |
2365 } | 2365 } |
2366 | 2366 |
2367 if (result->IsFailure()) return result; | 2367 if (result->IsFailure()) return result; |
2368 | 2368 |
| 2369 Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED); |
| 2370 if (reloc_info->IsFailure()) return reloc_info; |
| 2371 |
2369 // Initialize the object | 2372 // Initialize the object |
2370 HeapObject::cast(result)->set_map(code_map()); | 2373 HeapObject::cast(result)->set_map(code_map()); |
2371 Code* code = Code::cast(result); | 2374 Code* code = Code::cast(result); |
2372 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); | 2375 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); |
2373 code->set_instruction_size(desc.instr_size); | 2376 code->set_instruction_size(desc.instr_size); |
2374 code->set_relocation_size(desc.reloc_size); | 2377 code->set_relocation_info(ByteArray::cast(reloc_info)); |
2375 code->set_sinfo_size(sinfo_size); | 2378 code->set_sinfo_size(sinfo_size); |
2376 code->set_flags(flags); | 2379 code->set_flags(flags); |
2377 // Allow self references to created code object by patching the handle to | 2380 // Allow self references to created code object by patching the handle to |
2378 // point to the newly allocated Code object. | 2381 // point to the newly allocated Code object. |
2379 if (!self_reference.is_null()) { | 2382 if (!self_reference.is_null()) { |
2380 *(self_reference.location()) = code; | 2383 *(self_reference.location()) = code; |
2381 } | 2384 } |
2382 // Migrate generated code. | 2385 // Migrate generated code. |
2383 // The generated code can contain Object** values (typically from handles) | 2386 // The generated code can contain Object** values (typically from handles) |
2384 // that are dereferenced during the copy to point directly to the actual heap | 2387 // that are dereferenced during the copy to point directly to the actual heap |
(...skipping 27 matching lines...) Expand all Loading... |
2412 CopyBlock(new_addr, old_addr, obj_size); | 2415 CopyBlock(new_addr, old_addr, obj_size); |
2413 // Relocate the copy. | 2416 // Relocate the copy. |
2414 Code* new_code = Code::cast(result); | 2417 Code* new_code = Code::cast(result); |
2415 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); | 2418 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); |
2416 new_code->Relocate(new_addr - old_addr); | 2419 new_code->Relocate(new_addr - old_addr); |
2417 return new_code; | 2420 return new_code; |
2418 } | 2421 } |
2419 | 2422 |
2420 | 2423 |
2421 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { | 2424 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { |
2422 int new_body_size = RoundUp(code->instruction_size() + reloc_info.length(), | 2425 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); |
2423 kObjectAlignment); | |
2424 | 2426 |
2425 int sinfo_size = code->sinfo_size(); | 2427 int sinfo_size = code->sinfo_size(); |
2426 | 2428 |
2427 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); | 2429 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); |
2428 | 2430 |
2429 Address old_addr = code->address(); | 2431 Address old_addr = code->address(); |
2430 | 2432 |
2431 size_t relocation_offset = | 2433 size_t relocation_offset = |
2432 static_cast<size_t>(code->relocation_start() - old_addr); | 2434 static_cast<size_t>(code->instruction_end() - old_addr); |
2433 | 2435 |
2434 Object* result; | 2436 Object* result; |
2435 if (new_obj_size > MaxObjectSizeInPagedSpace()) { | 2437 if (new_obj_size > MaxObjectSizeInPagedSpace()) { |
2436 result = lo_space_->AllocateRawCode(new_obj_size); | 2438 result = lo_space_->AllocateRawCode(new_obj_size); |
2437 } else { | 2439 } else { |
2438 result = code_space_->AllocateRaw(new_obj_size); | 2440 result = code_space_->AllocateRaw(new_obj_size); |
2439 } | 2441 } |
2440 | 2442 |
2441 if (result->IsFailure()) return result; | 2443 if (result->IsFailure()) return result; |
2442 | 2444 |
| 2445 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED); |
| 2446 if (reloc_info_array->IsFailure()) return reloc_info_array; |
| 2447 |
2443 // Copy code object. | 2448 // Copy code object. |
2444 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 2449 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
2445 | 2450 |
2446 // Copy header and instructions. | 2451 // Copy header and instructions. |
2447 memcpy(new_addr, old_addr, relocation_offset); | 2452 memcpy(new_addr, old_addr, relocation_offset); |
2448 | 2453 |
| 2454 Code* new_code = Code::cast(result); |
| 2455 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); |
| 2456 |
2449 // Copy patched rinfo. | 2457 // Copy patched rinfo. |
2450 memcpy(new_addr + relocation_offset, | 2458 memcpy(new_code->relocation_start(), reloc_info.start(), reloc_info.length()); |
2451 reloc_info.start(), | |
2452 reloc_info.length()); | |
2453 | |
2454 Code* new_code = Code::cast(result); | |
2455 new_code->set_relocation_size(reloc_info.length()); | |
2456 | |
2457 // Copy sinfo. | 2459 // Copy sinfo. |
2458 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); | 2460 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); |
2459 | 2461 |
2460 // Relocate the copy. | 2462 // Relocate the copy. |
2461 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); | 2463 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); |
2462 new_code->Relocate(new_addr - old_addr); | 2464 new_code->Relocate(new_addr - old_addr); |
2463 | 2465 |
2464 #ifdef DEBUG | 2466 #ifdef DEBUG |
2465 code->Verify(); | 2467 code->Verify(); |
2466 #endif | 2468 #endif |
(...skipping 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4822 void ExternalStringTable::TearDown() { | 4824 void ExternalStringTable::TearDown() { |
4823 new_space_strings_.Free(); | 4825 new_space_strings_.Free(); |
4824 old_space_strings_.Free(); | 4826 old_space_strings_.Free(); |
4825 } | 4827 } |
4826 | 4828 |
4827 | 4829 |
4828 List<Object*> ExternalStringTable::new_space_strings_; | 4830 List<Object*> ExternalStringTable::new_space_strings_; |
4829 List<Object*> ExternalStringTable::old_space_strings_; | 4831 List<Object*> ExternalStringTable::old_space_strings_; |
4830 | 4832 |
4831 } } // namespace v8::internal | 4833 } } // namespace v8::internal |
OLD | NEW |