| 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 11 matching lines...) Expand all Loading... |
| 204 | 202 |
| 205 | 203 |
| 206 MaybeObject* Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { | 204 MaybeObject* Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { |
| 207 return CopyFixedDoubleArrayWithMap(src, src->map()); | 205 return CopyFixedDoubleArrayWithMap(src, src->map()); |
| 208 } | 206 } |
| 209 | 207 |
| 210 | 208 |
| 211 MaybeObject* Heap::AllocateRaw(int size_in_bytes, | 209 MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
| 212 AllocationSpace space, | 210 AllocationSpace space, |
| 213 AllocationSpace retry_space) { | 211 AllocationSpace retry_space) { |
| 214 ASSERT(AllowHandleAllocation::IsAllowed() && gc_state_ == NOT_IN_GC); | 212 ASSERT(AllowHandleAllocation::IsAllowed()); |
| 213 ASSERT(AllowHeapAllocation::IsAllowed()); |
| 214 ASSERT(gc_state_ == NOT_IN_GC); |
| 215 ASSERT(space != NEW_SPACE || | 215 ASSERT(space != NEW_SPACE || |
| 216 retry_space == OLD_POINTER_SPACE || | 216 retry_space == OLD_POINTER_SPACE || |
| 217 retry_space == OLD_DATA_SPACE || | 217 retry_space == OLD_DATA_SPACE || |
| 218 retry_space == LO_SPACE); | 218 retry_space == LO_SPACE); |
| 219 #ifdef DEBUG | 219 #ifdef DEBUG |
| 220 if (FLAG_gc_interval >= 0 && | 220 if (FLAG_gc_interval >= 0 && |
| 221 !disallow_allocation_failure_ && | 221 !disallow_allocation_failure_ && |
| 222 Heap::allocation_timeout_-- <= 0) { | 222 Heap::allocation_timeout_-- <= 0) { |
| 223 return Failure::RetryAfterGC(space); | 223 return Failure::RetryAfterGC(space); |
| 224 } | 224 } |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 #ifdef DEBUG | 881 #ifdef DEBUG |
| 882 Isolate* isolate = Isolate::Current(); | 882 Isolate* isolate = Isolate::Current(); |
| 883 isolate->heap()->disallow_allocation_failure_ = old_state_; | 883 isolate->heap()->disallow_allocation_failure_ = old_state_; |
| 884 #endif | 884 #endif |
| 885 } | 885 } |
| 886 | 886 |
| 887 | 887 |
| 888 } } // namespace v8::internal | 888 } } // namespace v8::internal |
| 889 | 889 |
| 890 #endif // V8_HEAP_INL_H_ | 890 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |