OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 | 134 |
135 MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, | 135 MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, |
136 uint32_t hash_field) { | 136 uint32_t hash_field) { |
137 if (str.length() > SeqOneByteString::kMaxLength) { | 137 if (str.length() > SeqOneByteString::kMaxLength) { |
138 return Failure::OutOfMemoryException(0x2); | 138 return Failure::OutOfMemoryException(0x2); |
139 } | 139 } |
140 // Compute map and object size. | 140 // Compute map and object size. |
141 Map* map = ascii_internalized_string_map(); | 141 Map* map = ascii_internalized_string_map(); |
142 int size = SeqOneByteString::SizeFor(str.length()); | 142 int size = SeqOneByteString::SizeFor(str.length()); |
| 143 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
143 | 144 |
144 // Allocate string. | 145 // Allocate string. |
145 Object* result; | 146 Object* result; |
146 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) | 147 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
147 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) | |
148 : old_data_space_->AllocateRaw(size); | |
149 if (!maybe_result->ToObject(&result)) return maybe_result; | 148 if (!maybe_result->ToObject(&result)) return maybe_result; |
150 } | 149 } |
151 | 150 |
152 // String maps are all immortal immovable objects. | 151 // String maps are all immortal immovable objects. |
153 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); | 152 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); |
154 // Set length and hash fields of the allocated string. | 153 // Set length and hash fields of the allocated string. |
155 String* answer = String::cast(result); | 154 String* answer = String::cast(result); |
156 answer->set_length(str.length()); | 155 answer->set_length(str.length()); |
157 answer->set_hash_field(hash_field); | 156 answer->set_hash_field(hash_field); |
158 | 157 |
159 ASSERT_EQ(size, answer->Size()); | 158 ASSERT_EQ(size, answer->Size()); |
160 | 159 |
161 // Fill in the characters. | 160 // Fill in the characters. |
162 OS::MemCopy(answer->address() + SeqOneByteString::kHeaderSize, | 161 OS::MemCopy(answer->address() + SeqOneByteString::kHeaderSize, |
163 str.start(), str.length()); | 162 str.start(), str.length()); |
164 | 163 |
165 return answer; | 164 return answer; |
166 } | 165 } |
167 | 166 |
168 | 167 |
169 MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 168 MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
170 uint32_t hash_field) { | 169 uint32_t hash_field) { |
171 if (str.length() > SeqTwoByteString::kMaxLength) { | 170 if (str.length() > SeqTwoByteString::kMaxLength) { |
172 return Failure::OutOfMemoryException(0x3); | 171 return Failure::OutOfMemoryException(0x3); |
173 } | 172 } |
174 // Compute map and object size. | 173 // Compute map and object size. |
175 Map* map = internalized_string_map(); | 174 Map* map = internalized_string_map(); |
176 int size = SeqTwoByteString::SizeFor(str.length()); | 175 int size = SeqTwoByteString::SizeFor(str.length()); |
| 176 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
177 | 177 |
178 // Allocate string. | 178 // Allocate string. |
179 Object* result; | 179 Object* result; |
180 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) | 180 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
181 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) | |
182 : old_data_space_->AllocateRaw(size); | |
183 if (!maybe_result->ToObject(&result)) return maybe_result; | 181 if (!maybe_result->ToObject(&result)) return maybe_result; |
184 } | 182 } |
185 | 183 |
186 reinterpret_cast<HeapObject*>(result)->set_map(map); | 184 reinterpret_cast<HeapObject*>(result)->set_map(map); |
187 // Set length and hash fields of the allocated string. | 185 // Set length and hash fields of the allocated string. |
188 String* answer = String::cast(result); | 186 String* answer = String::cast(result); |
189 answer->set_length(str.length()); | 187 answer->set_length(str.length()); |
190 answer->set_hash_field(hash_field); | 188 answer->set_hash_field(hash_field); |
191 | 189 |
192 ASSERT_EQ(size, answer->Size()); | 190 ASSERT_EQ(size, answer->Size()); |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 DisallowAllocationFailure::~DisallowAllocationFailure() { | 844 DisallowAllocationFailure::~DisallowAllocationFailure() { |
847 #ifdef DEBUG | 845 #ifdef DEBUG |
848 HEAP->disallow_allocation_failure_ = old_state_; | 846 HEAP->disallow_allocation_failure_ = old_state_; |
849 #endif | 847 #endif |
850 } | 848 } |
851 | 849 |
852 | 850 |
853 } } // namespace v8::internal | 851 } } // namespace v8::internal |
854 | 852 |
855 #endif // V8_HEAP_INL_H_ | 853 #endif // V8_HEAP_INL_H_ |
OLD | NEW |