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

Side by Side Diff: src/heap.cc

Issue 2814050: Version 2.2.23... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
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 | « src/frames.cc ('k') | src/ia32/codegen-ia32.cc » ('j') | 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 + desc.reloc_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 // Initialize the object 2374 // Initialize the object
2370 HeapObject::cast(result)->set_map(code_map()); 2375 HeapObject::cast(result)->set_map(code_map());
2371 Code* code = Code::cast(result); 2376 Code* code = Code::cast(result);
2372 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2377 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2373 code->set_instruction_size(desc.instr_size); 2378 code->set_instruction_size(desc.instr_size);
2374 code->set_relocation_size(desc.reloc_size); 2379 code->set_relocation_info(ByteArray::cast(reloc_info));
2375 code->set_sinfo_size(sinfo_size); 2380 code->set_sinfo_size(sinfo_size);
2376 code->set_flags(flags); 2381 code->set_flags(flags);
2377 // 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
2378 // point to the newly allocated Code object. 2383 // point to the newly allocated Code object.
2379 if (!self_reference.is_null()) { 2384 if (!self_reference.is_null()) {
2380 *(self_reference.location()) = code; 2385 *(self_reference.location()) = code;
2381 } 2386 }
2382 // Migrate generated code. 2387 // Migrate generated code.
2383 // The generated code can contain Object** values (typically from handles) 2388 // The generated code can contain Object** values (typically from handles)
2384 // that are dereferenced during the copy to point directly to the actual heap 2389 // that are dereferenced during the copy to point directly to the actual heap
(...skipping 27 matching lines...) Expand all
2412 CopyBlock(new_addr, old_addr, obj_size); 2417 CopyBlock(new_addr, old_addr, obj_size);
2413 // Relocate the copy. 2418 // Relocate the copy.
2414 Code* new_code = Code::cast(result); 2419 Code* new_code = Code::cast(result);
2415 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2420 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2416 new_code->Relocate(new_addr - old_addr); 2421 new_code->Relocate(new_addr - old_addr);
2417 return new_code; 2422 return new_code;
2418 } 2423 }
2419 2424
2420 2425
2421 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { 2426 Object* Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
2422 int new_body_size = RoundUp(code->instruction_size() + reloc_info.length(), 2427 // Allocate ByteArray before the Code object, so that we do not risk
2423 kObjectAlignment); 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
2432 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
2424 2433
2425 int sinfo_size = code->sinfo_size(); 2434 int sinfo_size = code->sinfo_size();
2426 2435
2427 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size); 2436 int new_obj_size = Code::SizeFor(new_body_size, sinfo_size);
2428 2437
2429 Address old_addr = code->address(); 2438 Address old_addr = code->address();
2430 2439
2431 size_t relocation_offset = 2440 size_t relocation_offset =
2432 static_cast<size_t>(code->relocation_start() - old_addr); 2441 static_cast<size_t>(code->instruction_end() - old_addr);
2433 2442
2434 Object* result; 2443 Object* result;
2435 if (new_obj_size > MaxObjectSizeInPagedSpace()) { 2444 if (new_obj_size > MaxObjectSizeInPagedSpace()) {
2436 result = lo_space_->AllocateRawCode(new_obj_size); 2445 result = lo_space_->AllocateRawCode(new_obj_size);
2437 } else { 2446 } else {
2438 result = code_space_->AllocateRaw(new_obj_size); 2447 result = code_space_->AllocateRaw(new_obj_size);
2439 } 2448 }
2440 2449
2441 if (result->IsFailure()) return result; 2450 if (result->IsFailure()) return result;
2442 2451
2443 // Copy code object. 2452 // Copy code object.
2444 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 2453 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
2445 2454
2446 // Copy header and instructions. 2455 // Copy header and instructions.
2447 memcpy(new_addr, old_addr, relocation_offset); 2456 memcpy(new_addr, old_addr, relocation_offset);
2448 2457
2458 Code* new_code = Code::cast(result);
2459 new_code->set_relocation_info(ByteArray::cast(reloc_info_array));
2460
2449 // Copy patched rinfo. 2461 // Copy patched rinfo.
2450 memcpy(new_addr + relocation_offset, 2462 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. 2463 // Copy sinfo.
2458 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); 2464 memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size());
2459 2465
2460 // Relocate the copy. 2466 // Relocate the copy.
2461 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2467 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2462 new_code->Relocate(new_addr - old_addr); 2468 new_code->Relocate(new_addr - old_addr);
2463 2469
2464 #ifdef DEBUG 2470 #ifdef DEBUG
2465 code->Verify(); 2471 code->Verify();
2466 #endif 2472 #endif
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 SeqAsciiString* string_result = SeqAsciiString::cast(result); 2865 SeqAsciiString* string_result = SeqAsciiString::cast(result);
2860 for (int i = 0; i < string.length(); i++) { 2866 for (int i = 0; i < string.length(); i++) {
2861 string_result->SeqAsciiStringSet(i, string[i]); 2867 string_result->SeqAsciiStringSet(i, string[i]);
2862 } 2868 }
2863 return result; 2869 return result;
2864 } 2870 }
2865 2871
2866 2872
2867 Object* Heap::AllocateStringFromUtf8(Vector<const char> string, 2873 Object* Heap::AllocateStringFromUtf8(Vector<const char> string,
2868 PretenureFlag pretenure) { 2874 PretenureFlag pretenure) {
2875 // V8 only supports characters in the Basic Multilingual Plane.
2876 const uc32 kMaxSupportedChar = 0xFFFF;
2869 // Count the number of characters in the UTF-8 string and check if 2877 // Count the number of characters in the UTF-8 string and check if
2870 // it is an ASCII string. 2878 // it is an ASCII string.
2871 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder()); 2879 Access<Scanner::Utf8Decoder> decoder(Scanner::utf8_decoder());
2872 decoder->Reset(string.start(), string.length()); 2880 decoder->Reset(string.start(), string.length());
2873 int chars = 0; 2881 int chars = 0;
2874 bool is_ascii = true; 2882 bool is_ascii = true;
2875 while (decoder->has_more()) { 2883 while (decoder->has_more()) {
2876 uc32 r = decoder->GetNext(); 2884 uc32 r = decoder->GetNext();
2877 if (r > String::kMaxAsciiCharCode) is_ascii = false; 2885 if (r > String::kMaxAsciiCharCode) is_ascii = false;
2878 chars++; 2886 chars++;
2879 } 2887 }
2880 2888
2881 // If the string is ascii, we do not need to convert the characters 2889 // If the string is ascii, we do not need to convert the characters
2882 // since UTF8 is backwards compatible with ascii. 2890 // since UTF8 is backwards compatible with ascii.
2883 if (is_ascii) return AllocateStringFromAscii(string, pretenure); 2891 if (is_ascii) return AllocateStringFromAscii(string, pretenure);
2884 2892
2885 Object* result = AllocateRawTwoByteString(chars, pretenure); 2893 Object* result = AllocateRawTwoByteString(chars, pretenure);
2886 if (result->IsFailure()) return result; 2894 if (result->IsFailure()) return result;
2887 2895
2888 // Convert and copy the characters into the new object. 2896 // Convert and copy the characters into the new object.
2889 String* string_result = String::cast(result); 2897 String* string_result = String::cast(result);
2890 decoder->Reset(string.start(), string.length()); 2898 decoder->Reset(string.start(), string.length());
2891 for (int i = 0; i < chars; i++) { 2899 for (int i = 0; i < chars; i++) {
2892 uc32 r = decoder->GetNext(); 2900 uc32 r = decoder->GetNext();
2901 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; }
2893 string_result->Set(i, r); 2902 string_result->Set(i, r);
2894 } 2903 }
2895 return result; 2904 return result;
2896 } 2905 }
2897 2906
2898 2907
2899 Object* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, 2908 Object* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
2900 PretenureFlag pretenure) { 2909 PretenureFlag pretenure) {
2901 // Check if the string is an ASCII string. 2910 // Check if the string is an ASCII string.
2902 int i = 0; 2911 int i = 0;
(...skipping 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after
4822 void ExternalStringTable::TearDown() { 4831 void ExternalStringTable::TearDown() {
4823 new_space_strings_.Free(); 4832 new_space_strings_.Free();
4824 old_space_strings_.Free(); 4833 old_space_strings_.Free();
4825 } 4834 }
4826 4835
4827 4836
4828 List<Object*> ExternalStringTable::new_space_strings_; 4837 List<Object*> ExternalStringTable::new_space_strings_;
4829 List<Object*> ExternalStringTable::old_space_strings_; 4838 List<Object*> ExternalStringTable::old_space_strings_;
4830 4839
4831 } } // namespace v8::internal 4840 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/frames.cc ('k') | src/ia32/codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698