| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 | 46 |
| 47 int Heap::MaxObjectSizeInPagedSpace() { | 47 int Heap::MaxObjectSizeInPagedSpace() { |
| 48 return Page::kMaxHeapObjectSize; | 48 return Page::kMaxHeapObjectSize; |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, | 52 MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, |
| 53 PretenureFlag pretenure) { | 53 PretenureFlag pretenure) { |
| 54 // Check for ASCII first since this is the common case. | 54 // Check for ASCII first since this is the common case. |
| 55 for (int i = 0; i < str.length(); ++i) { | 55 if (String::IsAscii(str.start(), str.length())) { |
| 56 if (static_cast<uint8_t>(str[i]) > String::kMaxAsciiCharCodeU) { | 56 // If the string is ASCII, we do not need to convert the characters |
| 57 // Non-ASCII and we need to decode. | 57 // since UTF8 is backwards compatible with ASCII. |
| 58 return AllocateStringFromUtf8Slow(str, pretenure); | 58 return AllocateStringFromAscii(str, pretenure); |
| 59 } | |
| 60 } | 59 } |
| 61 // If the string is ASCII, we do not need to convert the characters | 60 // Non-ASCII and we need to decode. |
| 62 // since UTF8 is backwards compatible with ASCII. | 61 return AllocateStringFromUtf8Slow(str, pretenure); |
| 63 return AllocateStringFromAscii(str, pretenure); | |
| 64 } | 62 } |
| 65 | 63 |
| 66 | 64 |
| 67 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, | 65 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, |
| 68 int chars, | 66 int chars, |
| 69 uint32_t hash_field) { | 67 uint32_t hash_field) { |
| 70 unibrow::Utf8InputBuffer<> buffer(str.start(), | 68 unibrow::Utf8InputBuffer<> buffer(str.start(), |
| 71 static_cast<unsigned>(str.length())); | 69 static_cast<unsigned>(str.length())); |
| 72 return AllocateInternalSymbol(&buffer, chars, hash_field); | 70 return AllocateInternalSymbol(&buffer, chars, hash_field); |
| 73 } | 71 } |
| 74 | 72 |
| 75 | 73 |
| 74 MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, |
| 75 uint32_t hash_field) { |
| 76 if (str.length() > SeqAsciiString::kMaxLength) { |
| 77 return Failure::OutOfMemoryException(); |
| 78 } |
| 79 // Compute map and object size. |
| 80 Map* map = ascii_symbol_map(); |
| 81 int size = SeqAsciiString::SizeFor(str.length()); |
| 82 |
| 83 // Allocate string. |
| 84 Object* result; |
| 85 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 86 ? lo_space_->AllocateRaw(size) |
| 87 : old_data_space_->AllocateRaw(size); |
| 88 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 89 } |
| 90 |
| 91 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 92 // Set length and hash fields of the allocated string. |
| 93 String* answer = String::cast(result); |
| 94 answer->set_length(str.length()); |
| 95 answer->set_hash_field(hash_field); |
| 96 |
| 97 ASSERT_EQ(size, answer->Size()); |
| 98 |
| 99 // Fill in the characters. |
| 100 memcpy(answer->address() + SeqAsciiString::kHeaderSize, |
| 101 str.start(), str.length()); |
| 102 |
| 103 return answer; |
| 104 } |
| 105 |
| 106 |
| 107 MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str, |
| 108 uint32_t hash_field) { |
| 109 if (str.length() > SeqTwoByteString::kMaxLength) { |
| 110 return Failure::OutOfMemoryException(); |
| 111 } |
| 112 // Compute map and object size. |
| 113 Map* map = symbol_map(); |
| 114 int size = SeqTwoByteString::SizeFor(str.length()); |
| 115 |
| 116 // Allocate string. |
| 117 Object* result; |
| 118 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 119 ? lo_space_->AllocateRaw(size) |
| 120 : old_data_space_->AllocateRaw(size); |
| 121 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 122 } |
| 123 |
| 124 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 125 // Set length and hash fields of the allocated string. |
| 126 String* answer = String::cast(result); |
| 127 answer->set_length(str.length()); |
| 128 answer->set_hash_field(hash_field); |
| 129 |
| 130 ASSERT_EQ(size, answer->Size()); |
| 131 |
| 132 // Fill in the characters. |
| 133 memcpy(answer->address() + SeqTwoByteString::kHeaderSize, |
| 134 str.start(), str.length() * kUC16Size); |
| 135 |
| 136 return answer; |
| 137 } |
| 138 |
| 76 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { | 139 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
| 77 return CopyFixedArrayWithMap(src, src->map()); | 140 return CopyFixedArrayWithMap(src, src->map()); |
| 78 } | 141 } |
| 79 | 142 |
| 80 | 143 |
| 81 MaybeObject* Heap::AllocateRaw(int size_in_bytes, | 144 MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
| 82 AllocationSpace space, | 145 AllocationSpace space, |
| 83 AllocationSpace retry_space) { | 146 AllocationSpace retry_space) { |
| 84 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); | 147 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); |
| 85 ASSERT(space != NEW_SPACE || | 148 ASSERT(space != NEW_SPACE || |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 #ifdef DEBUG | 694 #ifdef DEBUG |
| 632 UpdateLiveObjectCount(obj); | 695 UpdateLiveObjectCount(obj); |
| 633 #endif | 696 #endif |
| 634 obj->SetMark(); | 697 obj->SetMark(); |
| 635 } | 698 } |
| 636 | 699 |
| 637 | 700 |
| 638 } } // namespace v8::internal | 701 } } // namespace v8::internal |
| 639 | 702 |
| 640 #endif // V8_HEAP_INL_H_ | 703 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |