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

Side by Side Diff: src/heap.cc

Issue 2800044: Fix crash introduced in r5019.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 } 2344 }
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 // Allocate ByteArray before the Code object, so that we do not risk
2355 // leaving uninitialized Code object (and breaking the heap).
2356 Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
2357 if (reloc_info->IsFailure()) return reloc_info;
2358
2354 // Compute size 2359 // Compute size
2355 int body_size = RoundUp(desc.instr_size, kObjectAlignment); 2360 int body_size = RoundUp(desc.instr_size, kObjectAlignment);
2356 int sinfo_size = 0; 2361 int sinfo_size = 0;
2357 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); 2362 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL);
2358 int obj_size = Code::SizeFor(body_size, sinfo_size); 2363 int obj_size = Code::SizeFor(body_size, sinfo_size);
2359 ASSERT(IsAligned(obj_size, Code::kCodeAlignment)); 2364 ASSERT(IsAligned(obj_size, Code::kCodeAlignment));
2360 Object* result; 2365 Object* result;
2361 if (obj_size > MaxObjectSizeInPagedSpace()) { 2366 if (obj_size > MaxObjectSizeInPagedSpace()) {
2362 result = lo_space_->AllocateRawCode(obj_size); 2367 result = lo_space_->AllocateRawCode(obj_size);
2363 } else { 2368 } else {
2364 result = code_space_->AllocateRaw(obj_size); 2369 result = code_space_->AllocateRaw(obj_size);
2365 } 2370 }
2366 2371
2367 if (result->IsFailure()) return result; 2372 if (result->IsFailure()) return result;
2368 2373
2369 Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED);
2370 if (reloc_info->IsFailure()) return reloc_info;
2371
2372 // Initialize the object 2374 // Initialize the object
2373 HeapObject::cast(result)->set_map(code_map()); 2375 HeapObject::cast(result)->set_map(code_map());
2374 Code* code = Code::cast(result); 2376 Code* code = Code::cast(result);
2375 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2377 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2376 code->set_instruction_size(desc.instr_size); 2378 code->set_instruction_size(desc.instr_size);
2377 code->set_relocation_info(ByteArray::cast(reloc_info)); 2379 code->set_relocation_info(ByteArray::cast(reloc_info));
2378 code->set_sinfo_size(sinfo_size); 2380 code->set_sinfo_size(sinfo_size);
2379 code->set_flags(flags); 2381 code->set_flags(flags);
2380 // Allow self references to created code object by patching the handle to 2382 // Allow self references to created code object by patching the handle to
2381 // point to the newly allocated Code object. 2383 // point to the newly allocated Code object.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 CopyBlock(new_addr, old_addr, obj_size); 2417 CopyBlock(new_addr, old_addr, obj_size);
2416 // Relocate the copy. 2418 // Relocate the copy.
2417 Code* new_code = Code::cast(result); 2419 Code* new_code = Code::cast(result);
2418 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2420 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2419 new_code->Relocate(new_addr - old_addr); 2421 new_code->Relocate(new_addr - old_addr);
2420 return new_code; 2422 return new_code;
2421 } 2423 }
2422 2424
2423 2425
2424 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { 2426 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
2427 // Allocate ByteArray before the Code object, so that we do not risk
2428 // leaving uninitialized Code object (and breaking the heap).
2429 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED);
2430 if (reloc_info_array->IsFailure()) return reloc_info_array;
2431
2425 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); 2432 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
2426 2433
2427 int sinfo_size = code->sinfo_size(); 2434 int sinfo_size = code->sinfo_size();
2428 2435
2429 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); 2436 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size);
2430 2437
2431 Address old_addr = code->address(); 2438 Address old_addr = code->address();
2432 2439
2433 size_t relocation_offset = 2440 size_t relocation_offset =
2434 static_cast<size_t>(code->instruction_end() - old_addr); 2441 static_cast<size_t>(code->instruction_end() - old_addr);
2435 2442
2436 Object* result; 2443 Object* result;
2437 if (new_obj_size > MaxObjectSizeInPagedSpace()) { 2444 if (new_obj_size > MaxObjectSizeInPagedSpace()) {
2438 result = lo_space_->AllocateRawCode(new_obj_size); 2445 result = lo_space_->AllocateRawCode(new_obj_size);
2439 } else { 2446 } else {
2440 result = code_space_->AllocateRaw(new_obj_size); 2447 result = code_space_->AllocateRaw(new_obj_size);
2441 } 2448 }
2442 2449
2443 if (result->IsFailure()) return result; 2450 if (result->IsFailure()) return result;
2444 2451
2445 Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED);
2446 if (reloc_info_array->IsFailure()) return reloc_info_array;
2447
2448 // Copy code object. 2452 // Copy code object.
2449 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 2453 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
2450 2454
2451 // Copy header and instructions. 2455 // Copy header and instructions.
2452 memcpy(new_addr, old_addr, relocation_offset); 2456 memcpy(new_addr, old_addr, relocation_offset);
2453 2457
2454 Code* new_code = Code::cast(result); 2458 Code* new_code = Code::cast(result);
2455 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); 2459 new_code->set_relocation_info(ByteArray::cast(reloc_info_array));
2456 2460
2457 // Copy patched rinfo. 2461 // Copy patched rinfo.
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
4827 void ExternalStringTable::TearDown() { 4831 void ExternalStringTable::TearDown() {
4828 new_space_strings_.Free(); 4832 new_space_strings_.Free();
4829 old_space_strings_.Free(); 4833 old_space_strings_.Free();
4830 } 4834 }
4831 4835
4832 4836
4833 List<Object*> ExternalStringTable::new_space_strings_; 4837 List<Object*> ExternalStringTable::new_space_strings_;
4834 List<Object*> ExternalStringTable::old_space_strings_; 4838 List<Object*> ExternalStringTable::old_space_strings_;
4835 4839
4836 } } // namespace v8::internal 4840 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698