danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_HEAP_INL_H_ |
| 29 | #define V8_HEAP_INL_H_ |
| 30 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 31 | #include "heap.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 32 | #include "isolate.h" |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 33 | #include "list-inl.h" |
| 34 | #include "objects.h" |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 35 | #include "platform.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "v8-counters.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 37 | #include "store-buffer.h" |
| 38 | #include "store-buffer-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 43 | void PromotionQueue::insert(HeapObject* target, int size) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 44 | if (emergency_stack_ != NULL) { |
| 45 | emergency_stack_->Add(Entry(target, size)); |
| 46 | return; |
| 47 | } |
| 48 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 49 | if (NewSpacePage::IsAtStart(reinterpret_cast<Address>(rear_))) { |
| 50 | NewSpacePage* rear_page = |
| 51 | NewSpacePage::FromAddress(reinterpret_cast<Address>(rear_)); |
| 52 | ASSERT(!rear_page->prev_page()->is_anchor()); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 53 | rear_ = reinterpret_cast<intptr_t*>(rear_page->prev_page()->area_end()); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 54 | ActivateGuardIfOnTheSamePage(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 55 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 56 | |
| 57 | if (guard_) { |
| 58 | ASSERT(GetHeadPage() == |
| 59 | Page::FromAllocationTop(reinterpret_cast<Address>(limit_))); |
| 60 | |
| 61 | if ((rear_ - 2) < limit_) { |
| 62 | RelocateQueueHead(); |
| 63 | emergency_stack_->Add(Entry(target, size)); |
| 64 | return; |
| 65 | } |
| 66 | } |
| 67 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | *(--rear_) = reinterpret_cast<intptr_t>(target); |
| 69 | *(--rear_) = size; |
| 70 | // Assert no overflow into live objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 71 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 72 | SemiSpace::AssertValidRange(target->GetIsolate()->heap()->new_space()->top(), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 73 | reinterpret_cast<Address>(rear_)); |
| 74 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 78 | void PromotionQueue::ActivateGuardIfOnTheSamePage() { |
| 79 | guard_ = guard_ || |
| 80 | heap_->new_space()->active_space()->current_page()->address() == |
| 81 | GetHeadPage()->address(); |
| 82 | } |
| 83 | |
| 84 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 85 | MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, |
| 86 | PretenureFlag pretenure) { |
| 87 | // Check for ASCII first since this is the common case. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 88 | const char* start = str.start(); |
| 89 | int length = str.length(); |
| 90 | int non_ascii_start = String::NonAsciiStart(start, length); |
| 91 | if (non_ascii_start >= length) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 92 | // If the string is ASCII, we do not need to convert the characters |
| 93 | // since UTF8 is backwards compatible with ASCII. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 94 | return AllocateStringFromOneByte(str, pretenure); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 95 | } |
| 96 | // Non-ASCII and we need to decode. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 97 | return AllocateStringFromUtf8Slow(str, non_ascii_start, pretenure); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 101 | template<> |
| 102 | bool inline Heap::IsOneByte(Vector<const char> str, int chars) { |
| 103 | // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported? |
| 104 | // ASCII only check. |
| 105 | return chars == str.length(); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | template<> |
| 110 | bool inline Heap::IsOneByte(String* str, int chars) { |
| 111 | return str->IsOneByteRepresentation(); |
| 112 | } |
| 113 | |
| 114 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 115 | MaybeObject* Heap::AllocateInternalizedStringFromUtf8( |
| 116 | Vector<const char> str, int chars, uint32_t hash_field) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 117 | if (IsOneByte(str, chars)) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 118 | return AllocateOneByteInternalizedString( |
| 119 | Vector<const uint8_t>::cast(str), hash_field); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 120 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 121 | return AllocateInternalizedStringImpl<false>(str, chars, hash_field); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | |
| 125 | template<typename T> |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 126 | MaybeObject* Heap::AllocateInternalizedStringImpl( |
| 127 | T t, int chars, uint32_t hash_field) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 128 | if (IsOneByte(t, chars)) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 129 | return AllocateInternalizedStringImpl<true>(t, chars, hash_field); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 130 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 131 | return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 135 | MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, |
| 136 | uint32_t hash_field) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 137 | if (str.length() > SeqOneByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 138 | return Failure::OutOfMemoryException(0x2); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 139 | } |
| 140 | // Compute map and object size. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 141 | Map* map = ascii_internalized_string_map(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 142 | int size = SeqOneByteString::SizeFor(str.length()); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 143 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 144 | |
| 145 | // Allocate string. |
| 146 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 147 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 148 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 149 | } |
| 150 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 151 | // String maps are all immortal immovable objects. |
| 152 | reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 153 | // Set length and hash fields of the allocated string. |
| 154 | String* answer = String::cast(result); |
| 155 | answer->set_length(str.length()); |
| 156 | answer->set_hash_field(hash_field); |
| 157 | |
| 158 | ASSERT_EQ(size, answer->Size()); |
| 159 | |
| 160 | // Fill in the characters. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 161 | OS::MemCopy(answer->address() + SeqOneByteString::kHeaderSize, |
| 162 | str.start(), str.length()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 163 | |
| 164 | return answer; |
| 165 | } |
| 166 | |
| 167 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 168 | MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
| 169 | uint32_t hash_field) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 170 | if (str.length() > SeqTwoByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 171 | return Failure::OutOfMemoryException(0x3); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 172 | } |
| 173 | // Compute map and object size. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 174 | Map* map = internalized_string_map(); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 175 | int size = SeqTwoByteString::SizeFor(str.length()); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 176 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 177 | |
| 178 | // Allocate string. |
| 179 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 180 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 181 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 182 | } |
| 183 | |
| 184 | reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 185 | // Set length and hash fields of the allocated string. |
| 186 | String* answer = String::cast(result); |
| 187 | answer->set_length(str.length()); |
| 188 | answer->set_hash_field(hash_field); |
| 189 | |
| 190 | ASSERT_EQ(size, answer->Size()); |
| 191 | |
| 192 | // Fill in the characters. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 193 | OS::MemCopy(answer->address() + SeqTwoByteString::kHeaderSize, |
| 194 | str.start(), str.length() * kUC16Size); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 195 | |
| 196 | return answer; |
| 197 | } |
| 198 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 199 | MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 200 | return CopyFixedArrayWithMap(src, src->map()); |
| 201 | } |
| 202 | |
| 203 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 204 | MaybeObject* Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { |
| 205 | return CopyFixedDoubleArrayWithMap(src, src->map()); |
| 206 | } |
| 207 | |
| 208 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 209 | MaybeObject* Heap::CopyConstantPoolArray(ConstantPoolArray* src) { |
| 210 | return CopyConstantPoolArrayWithMap(src, src->map()); |
| 211 | } |
| 212 | |
| 213 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 214 | MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
| 215 | AllocationSpace space, |
| 216 | AllocationSpace retry_space) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 217 | ASSERT(AllowHandleAllocation::IsAllowed()); |
| 218 | ASSERT(AllowHeapAllocation::IsAllowed()); |
| 219 | ASSERT(gc_state_ == NOT_IN_GC); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 220 | HeapProfiler* profiler = isolate_->heap_profiler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | #ifdef DEBUG |
| 222 | if (FLAG_gc_interval >= 0 && |
| 223 | !disallow_allocation_failure_ && |
| 224 | Heap::allocation_timeout_-- <= 0) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 225 | return Failure::RetryAfterGC(space); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 226 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 227 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 228 | isolate_->counters()->objs_since_last_young()->Increment(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | #endif |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 230 | |
| 231 | HeapObject* object; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 232 | MaybeObject* result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | if (NEW_SPACE == space) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 234 | result = new_space_.AllocateRaw(size_in_bytes); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 235 | if (always_allocate() && result->IsFailure() && retry_space != NEW_SPACE) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 236 | space = retry_space; |
| 237 | } else { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 238 | if (profiler->is_tracking_allocations() && result->To(&object)) { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 239 | profiler->AllocationEvent(object->address(), size_in_bytes); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 240 | } |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 241 | return result; |
| 242 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | } |
| 244 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 245 | if (OLD_POINTER_SPACE == space) { |
| 246 | result = old_pointer_space_->AllocateRaw(size_in_bytes); |
| 247 | } else if (OLD_DATA_SPACE == space) { |
| 248 | result = old_data_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | } else if (CODE_SPACE == space) { |
| 250 | result = code_space_->AllocateRaw(size_in_bytes); |
| 251 | } else if (LO_SPACE == space) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 252 | result = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 253 | } else if (CELL_SPACE == space) { |
| 254 | result = cell_space_->AllocateRaw(size_in_bytes); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 255 | } else if (PROPERTY_CELL_SPACE == space) { |
| 256 | result = property_cell_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | } else { |
| 258 | ASSERT(MAP_SPACE == space); |
| 259 | result = map_space_->AllocateRaw(size_in_bytes); |
| 260 | } |
| 261 | if (result->IsFailure()) old_gen_exhausted_ = true; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 262 | if (profiler->is_tracking_allocations() && result->To(&object)) { |
yangguo@chromium.org | cc53605 | 2013-11-29 11:43:20 +0000 | [diff] [blame] | 263 | profiler->AllocationEvent(object->address(), size_in_bytes); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 264 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | return result; |
| 266 | } |
| 267 | |
| 268 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 269 | MaybeObject* Heap::NumberFromInt32( |
| 270 | int32_t value, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 271 | if (Smi::IsValid(value)) return Smi::FromInt(value); |
| 272 | // Bypass NumberFromDouble to avoid various redundant checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 273 | return AllocateHeapNumber(FastI2D(value), pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 277 | MaybeObject* Heap::NumberFromUint32( |
| 278 | uint32_t value, PretenureFlag pretenure) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 279 | if (static_cast<int32_t>(value) >= 0 && |
| 280 | Smi::IsValid(static_cast<int32_t>(value))) { |
| 281 | return Smi::FromInt(static_cast<int32_t>(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | } |
| 283 | // Bypass NumberFromDouble to avoid various redundant checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 284 | return AllocateHeapNumber(FastUI2D(value), pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 288 | void Heap::FinalizeExternalString(String* string) { |
| 289 | ASSERT(string->IsExternalString()); |
| 290 | v8::String::ExternalStringResourceBase** resource_addr = |
| 291 | reinterpret_cast<v8::String::ExternalStringResourceBase**>( |
| 292 | reinterpret_cast<byte*>(string) + |
| 293 | ExternalString::kResourceOffset - |
| 294 | kHeapObjectTag); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 295 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 296 | // Dispose of the C++ object if it has not already been disposed. |
| 297 | if (*resource_addr != NULL) { |
| 298 | (*resource_addr)->Dispose(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 299 | *resource_addr = NULL; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 300 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | bool Heap::InNewSpace(Object* object) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 305 | bool result = new_space_.Contains(object); |
| 306 | ASSERT(!result || // Either not in new space |
| 307 | gc_state_ != NOT_IN_GC || // ... or in the middle of GC |
| 308 | InToSpace(object)); // ... or in to-space (where we allocate). |
| 309 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 313 | bool Heap::InNewSpace(Address address) { |
| 314 | return new_space_.Contains(address); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 318 | bool Heap::InFromSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 319 | return new_space_.FromSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
| 323 | bool Heap::InToSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 324 | return new_space_.ToSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 328 | bool Heap::InOldPointerSpace(Address address) { |
| 329 | return old_pointer_space_->Contains(address); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | bool Heap::InOldPointerSpace(Object* object) { |
| 334 | return InOldPointerSpace(reinterpret_cast<Address>(object)); |
| 335 | } |
| 336 | |
| 337 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 338 | bool Heap::InOldDataSpace(Address address) { |
| 339 | return old_data_space_->Contains(address); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | bool Heap::InOldDataSpace(Object* object) { |
| 344 | return InOldDataSpace(reinterpret_cast<Address>(object)); |
| 345 | } |
| 346 | |
| 347 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 348 | bool Heap::OldGenerationAllocationLimitReached() { |
| 349 | if (!incremental_marking()->IsStopped()) return false; |
| 350 | return OldGenerationSpaceAvailable() < 0; |
| 351 | } |
| 352 | |
| 353 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | bool Heap::ShouldBePromoted(Address old_address, int object_size) { |
| 355 | // An object should be promoted if: |
| 356 | // - the object has survived a scavenge operation or |
| 357 | // - to space is already 25% full. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 358 | NewSpacePage* page = NewSpacePage::FromAddress(old_address); |
| 359 | Address age_mark = new_space_.age_mark(); |
| 360 | bool below_mark = page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && |
| 361 | (!page->ContainsLimit(age_mark) || old_address < age_mark); |
| 362 | return below_mark || (new_space_.Size() + object_size) >= |
| 363 | (new_space_.EffectiveCapacity() >> 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
| 367 | void Heap::RecordWrite(Address address, int offset) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 368 | if (!InNewSpace(address)) store_buffer_.Mark(address + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 372 | void Heap::RecordWrites(Address address, int start, int len) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 373 | if (!InNewSpace(address)) { |
| 374 | for (int i = 0; i < len; i++) { |
| 375 | store_buffer_.Mark(address + start + i * kPointerSize); |
| 376 | } |
| 377 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 381 | OldSpace* Heap::TargetSpace(HeapObject* object) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 382 | InstanceType type = object->map()->instance_type(); |
| 383 | AllocationSpace space = TargetSpaceId(type); |
| 384 | return (space == OLD_POINTER_SPACE) |
| 385 | ? old_pointer_space_ |
| 386 | : old_data_space_; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | AllocationSpace Heap::TargetSpaceId(InstanceType type) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 391 | // Heap numbers and sequential strings are promoted to old data space, all |
| 392 | // other object types are promoted to old pointer space. We do not use |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 393 | // object->IsHeapNumber() and object->IsSeqString() because we already |
| 394 | // know that object has the heap object tag. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 395 | |
| 396 | // These objects are never allocated in new space. |
| 397 | ASSERT(type != MAP_TYPE); |
| 398 | ASSERT(type != CODE_TYPE); |
| 399 | ASSERT(type != ODDBALL_TYPE); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 400 | ASSERT(type != CELL_TYPE); |
| 401 | ASSERT(type != PROPERTY_CELL_TYPE); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 402 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 403 | if (type <= LAST_NAME_TYPE) { |
| 404 | if (type == SYMBOL_TYPE) return OLD_POINTER_SPACE; |
| 405 | ASSERT(type < FIRST_NONSTRING_TYPE); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 406 | // There are four string representations: sequential strings, external |
| 407 | // strings, cons strings, and sliced strings. |
| 408 | // Only the latter two contain non-map-word pointers to heap objects. |
| 409 | return ((type & kIsIndirectStringMask) == kIsIndirectStringTag) |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 410 | ? OLD_POINTER_SPACE |
| 411 | : OLD_DATA_SPACE; |
| 412 | } else { |
| 413 | return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; |
| 414 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
verwaest@chromium.org | ec6855e | 2013-08-22 12:26:58 +0000 | [diff] [blame] | 418 | bool Heap::AllowedToBeMigrated(HeapObject* object, AllocationSpace dst) { |
| 419 | // Object migration is governed by the following rules: |
| 420 | // |
| 421 | // 1) Objects in new-space can be migrated to one of the old spaces |
| 422 | // that matches their target space or they stay in new-space. |
| 423 | // 2) Objects in old-space stay in the same space when migrating. |
| 424 | // 3) Fillers (two or more words) can migrate due to left-trimming of |
| 425 | // fixed arrays in new-space, old-data-space and old-pointer-space. |
| 426 | // 4) Fillers (one word) can never migrate, they are skipped by |
| 427 | // incremental marking explicitly to prevent invalid pattern. |
| 428 | // |
| 429 | // Since this function is used for debugging only, we do not place |
| 430 | // asserts here, but check everything explicitly. |
| 431 | if (object->map() == one_pointer_filler_map()) return false; |
| 432 | InstanceType type = object->map()->instance_type(); |
| 433 | MemoryChunk* chunk = MemoryChunk::FromAddress(object->address()); |
| 434 | AllocationSpace src = chunk->owner()->identity(); |
| 435 | switch (src) { |
| 436 | case NEW_SPACE: |
| 437 | return dst == src || dst == TargetSpaceId(type); |
| 438 | case OLD_POINTER_SPACE: |
| 439 | return dst == src && (dst == TargetSpaceId(type) || object->IsFiller()); |
| 440 | case OLD_DATA_SPACE: |
| 441 | return dst == src && dst == TargetSpaceId(type); |
| 442 | case CODE_SPACE: |
| 443 | return dst == src && type == CODE_TYPE; |
| 444 | case MAP_SPACE: |
| 445 | case CELL_SPACE: |
| 446 | case PROPERTY_CELL_SPACE: |
| 447 | case LO_SPACE: |
| 448 | return false; |
| 449 | } |
| 450 | UNREACHABLE(); |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 455 | void Heap::CopyBlock(Address dst, Address src, int byte_size) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 456 | CopyWords(reinterpret_cast<Object**>(dst), |
| 457 | reinterpret_cast<Object**>(src), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 458 | static_cast<size_t>(byte_size / kPointerSize)); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 459 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 461 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 462 | void Heap::MoveBlock(Address dst, Address src, int byte_size) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 463 | ASSERT(IsAligned(byte_size, kPointerSize)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 464 | |
| 465 | int size_in_words = byte_size / kPointerSize; |
| 466 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 467 | if ((dst < src) || (dst >= (src + byte_size))) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 468 | Object** src_slot = reinterpret_cast<Object**>(src); |
| 469 | Object** dst_slot = reinterpret_cast<Object**>(dst); |
| 470 | Object** end_slot = src_slot + size_in_words; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 471 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 472 | while (src_slot != end_slot) { |
| 473 | *dst_slot++ = *src_slot++; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 474 | } |
| 475 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 476 | OS::MemMove(dst, src, static_cast<size_t>(byte_size)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
| 480 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 481 | void Heap::ScavengePointer(HeapObject** p) { |
| 482 | ScavengeObject(p, *p); |
| 483 | } |
| 484 | |
| 485 | |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 486 | void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 487 | Heap* heap = object->GetHeap(); |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame^] | 488 | ASSERT(heap->InNewSpace(object)); |
| 489 | |
| 490 | if (!FLAG_allocation_site_pretenuring || |
| 491 | !heap->new_space_high_promotion_mode_active_ || |
| 492 | !AllocationSite::CanTrack(object->map()->instance_type())) return; |
| 493 | |
| 494 | // Either object is the last object in the from space, or there is another |
| 495 | // object of at least word size (the header map word) following it, so |
| 496 | // suffices to compare ptr and top here. |
| 497 | Address ptr = object->address() + object->Size(); |
| 498 | Address top = heap->new_space()->FromSpacePageHigh(); |
| 499 | ASSERT(ptr == top || ptr + HeapObject::kHeaderSize <= top); |
| 500 | if (ptr == top) return; |
| 501 | |
| 502 | HeapObject* candidate = HeapObject::FromAddress(ptr); |
| 503 | if (candidate->map() != heap->allocation_memento_map()) return; |
| 504 | |
| 505 | AllocationMemento* memento = AllocationMemento::cast(candidate); |
| 506 | if (!memento->IsValid()) return; |
| 507 | |
| 508 | if (memento->GetAllocationSite()->IncrementMementoFoundCount() && |
| 509 | heap->allocation_sites_scratchpad_length < |
| 510 | kAllocationSiteScratchpadSize) { |
| 511 | heap->allocation_sites_scratchpad[ |
| 512 | heap->allocation_sites_scratchpad_length++] = |
| 513 | memento->GetAllocationSite(); |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 518 | void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 519 | ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 520 | |
| 521 | // We use the first word (where the map pointer usually is) of a heap |
| 522 | // object to record the forwarding pointer. A forwarding pointer can |
| 523 | // point to an old space, the code space, or the to space of the new |
| 524 | // generation. |
| 525 | MapWord first_word = object->map_word(); |
| 526 | |
| 527 | // If the first word is a forwarding address, the object has already been |
| 528 | // copied. |
| 529 | if (first_word.IsForwardingAddress()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 530 | HeapObject* dest = first_word.ToForwardingAddress(); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 531 | ASSERT(object->GetIsolate()->heap()->InFromSpace(*p)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 532 | *p = dest; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 533 | return; |
| 534 | } |
| 535 | |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 536 | UpdateAllocationSiteFeedback(object); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 537 | |
hpayer@chromium.org | 27ce874 | 2013-09-19 09:59:01 +0000 | [diff] [blame] | 538 | // AllocationMementos are unrooted and shouldn't survive a scavenge |
| 539 | ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 540 | // Call the slow part of scavenge object. |
| 541 | return ScavengeObjectSlow(p, object); |
| 542 | } |
| 543 | |
| 544 | |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame^] | 545 | bool Heap::CollectGarbage(AllocationSpace space, |
| 546 | const char* gc_reason, |
| 547 | const v8::GCCallbackFlags callbackFlags) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 548 | const char* collector_reason = NULL; |
| 549 | GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame^] | 550 | return CollectGarbage( |
| 551 | space, collector, gc_reason, collector_reason, callbackFlags); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 555 | MaybeObject* Heap::PrepareForCompare(String* str) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 556 | // Always flatten small strings and force flattening of long strings |
| 557 | // after we have accumulated a certain amount we failed to flatten. |
| 558 | static const int kMaxAlwaysFlattenLength = 32; |
| 559 | static const int kFlattenLongThreshold = 16*KB; |
| 560 | |
| 561 | const int length = str->length(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 562 | MaybeObject* obj = str->TryFlatten(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 563 | if (length <= kMaxAlwaysFlattenLength || |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 564 | unflattened_strings_length_ >= kFlattenLongThreshold) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 565 | return obj; |
| 566 | } |
| 567 | if (obj->IsFailure()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 568 | unflattened_strings_length_ += length; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 569 | } |
| 570 | return str; |
| 571 | } |
| 572 | |
| 573 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 574 | int64_t Heap::AdjustAmountOfExternalAllocatedMemory( |
| 575 | int64_t change_in_bytes) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 576 | ASSERT(HasBeenSetUp()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 577 | int64_t amount = amount_of_external_allocated_memory_ + change_in_bytes; |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 578 | if (change_in_bytes > 0) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 579 | // Avoid overflow. |
| 580 | if (amount > amount_of_external_allocated_memory_) { |
| 581 | amount_of_external_allocated_memory_ = amount; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 582 | } else { |
| 583 | // Give up and reset the counters in case of an overflow. |
| 584 | amount_of_external_allocated_memory_ = 0; |
| 585 | amount_of_external_allocated_memory_at_last_global_gc_ = 0; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 586 | } |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 587 | int64_t amount_since_last_global_gc = PromotedExternalMemorySize(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 588 | if (amount_since_last_global_gc > external_allocation_limit_) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 589 | CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached"); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 590 | } |
| 591 | } else { |
| 592 | // Avoid underflow. |
| 593 | if (amount >= 0) { |
| 594 | amount_of_external_allocated_memory_ = amount; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 595 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 596 | // Give up and reset the counters in case of an underflow. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 597 | amount_of_external_allocated_memory_ = 0; |
| 598 | amount_of_external_allocated_memory_at_last_global_gc_ = 0; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 601 | if (FLAG_trace_external_memory) { |
| 602 | PrintPID("%8.0f ms: ", isolate()->time_millis_since_init()); |
| 603 | PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d KB, " |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 604 | "amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d KB, " |
| 605 | "isolate=0x%08" V8PRIxPTR ".\n", |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 606 | static_cast<intptr_t>(change_in_bytes / KB), |
| 607 | static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB), |
| 608 | static_cast<intptr_t>(PromotedExternalMemorySize() / KB), |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 609 | reinterpret_cast<intptr_t>(isolate())); |
| 610 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 611 | ASSERT(amount_of_external_allocated_memory_ >= 0); |
| 612 | return amount_of_external_allocated_memory_; |
| 613 | } |
| 614 | |
| 615 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 616 | Isolate* Heap::isolate() { |
| 617 | return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) - |
| 618 | reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4); |
| 619 | } |
| 620 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 621 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 622 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 623 | #define GC_GREEDY_CHECK(ISOLATE) \ |
| 624 | if (FLAG_gc_greedy) (ISOLATE)->heap()->GarbageCollectionGreedyCheck() |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 625 | #else |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 626 | #define GC_GREEDY_CHECK(ISOLATE) { } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 627 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 629 | // Calls the FUNCTION_CALL function and retries it up to three times |
| 630 | // to guarantee that any allocations performed during the call will |
| 631 | // succeed if there's enough memory. |
| 632 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 633 | // Warning: Do not use the identifiers __object__, __maybe_object__ or |
| 634 | // __scope__ in a call to this macro. |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 635 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 636 | #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY, OOM)\ |
| 637 | do { \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 638 | GC_GREEDY_CHECK(ISOLATE); \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 639 | MaybeObject* __maybe_object__ = FUNCTION_CALL; \ |
| 640 | Object* __object__ = NULL; \ |
| 641 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 642 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 643 | OOM; \ |
| 644 | } \ |
| 645 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 646 | (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 647 | allocation_space(), \ |
| 648 | "allocation failure"); \ |
| 649 | __maybe_object__ = FUNCTION_CALL; \ |
| 650 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 651 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 652 | OOM; \ |
| 653 | } \ |
| 654 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 655 | (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
| 656 | (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 657 | { \ |
| 658 | AlwaysAllocateScope __scope__; \ |
| 659 | __maybe_object__ = FUNCTION_CALL; \ |
| 660 | } \ |
| 661 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 662 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 663 | OOM; \ |
| 664 | } \ |
| 665 | if (__maybe_object__->IsRetryAfterGC()) { \ |
| 666 | /* TODO(1181417): Fix this. */ \ |
| 667 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ |
| 668 | } \ |
| 669 | RETURN_EMPTY; \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | } while (false) |
| 671 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 672 | #define CALL_AND_RETRY_OR_DIE( \ |
| 673 | ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
| 674 | CALL_AND_RETRY( \ |
| 675 | ISOLATE, \ |
| 676 | FUNCTION_CALL, \ |
| 677 | RETURN_VALUE, \ |
| 678 | RETURN_EMPTY, \ |
| 679 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY", true)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 681 | #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
| 682 | CALL_AND_RETRY_OR_DIE(ISOLATE, \ |
| 683 | FUNCTION_CALL, \ |
| 684 | return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
| 685 | return Handle<TYPE>()) \ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 686 | |
| 687 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 688 | #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
| 689 | CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 690 | |
| 691 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 692 | #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ |
| 693 | CALL_AND_RETRY(ISOLATE, \ |
| 694 | FUNCTION_CALL, \ |
| 695 | return __object__, \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 696 | return __maybe_object__, \ |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 697 | return __maybe_object__) |
| 698 | |
| 699 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 700 | void ExternalStringTable::AddString(String* string) { |
| 701 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 702 | if (heap_->InNewSpace(string)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 703 | new_space_strings_.Add(string); |
| 704 | } else { |
| 705 | old_space_strings_.Add(string); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | void ExternalStringTable::Iterate(ObjectVisitor* v) { |
| 711 | if (!new_space_strings_.is_empty()) { |
| 712 | Object** start = &new_space_strings_[0]; |
| 713 | v->VisitPointers(start, start + new_space_strings_.length()); |
| 714 | } |
| 715 | if (!old_space_strings_.is_empty()) { |
| 716 | Object** start = &old_space_strings_[0]; |
| 717 | v->VisitPointers(start, start + old_space_strings_.length()); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | |
| 722 | // Verify() is inline to avoid ifdef-s around its calls in release |
| 723 | // mode. |
| 724 | void ExternalStringTable::Verify() { |
| 725 | #ifdef DEBUG |
| 726 | for (int i = 0; i < new_space_strings_.length(); ++i) { |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 727 | Object* obj = Object::cast(new_space_strings_[i]); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 728 | ASSERT(heap_->InNewSpace(obj)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 729 | ASSERT(obj != heap_->the_hole_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 730 | } |
| 731 | for (int i = 0; i < old_space_strings_.length(); ++i) { |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 732 | Object* obj = Object::cast(old_space_strings_[i]); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 733 | ASSERT(!heap_->InNewSpace(obj)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 734 | ASSERT(obj != heap_->the_hole_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 735 | } |
| 736 | #endif |
| 737 | } |
| 738 | |
| 739 | |
| 740 | void ExternalStringTable::AddOldString(String* string) { |
| 741 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 742 | ASSERT(!heap_->InNewSpace(string)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 743 | old_space_strings_.Add(string); |
| 744 | } |
| 745 | |
| 746 | |
| 747 | void ExternalStringTable::ShrinkNewStrings(int position) { |
| 748 | new_space_strings_.Rewind(position); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 749 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 750 | if (FLAG_verify_heap) { |
| 751 | Verify(); |
| 752 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 753 | #endif |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 754 | } |
| 755 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 756 | |
| 757 | void Heap::ClearInstanceofCache() { |
| 758 | set_instanceof_cache_function(the_hole_value()); |
| 759 | } |
| 760 | |
| 761 | |
| 762 | Object* Heap::ToBoolean(bool condition) { |
| 763 | return condition ? true_value() : false_value(); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | void Heap::CompletelyClearInstanceofCache() { |
| 768 | set_instanceof_cache_map(the_hole_value()); |
| 769 | set_instanceof_cache_function(the_hole_value()); |
| 770 | } |
| 771 | |
| 772 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 773 | AlwaysAllocateScope::AlwaysAllocateScope() { |
| 774 | // We shouldn't hit any nested scopes, because that requires |
| 775 | // non-handle code to call handle code. The code still works but |
| 776 | // performance will degrade, so we want to catch this situation |
| 777 | // in debug mode. |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 778 | Isolate* isolate = Isolate::Current(); |
| 779 | ASSERT(isolate->heap()->always_allocate_scope_depth_ == 0); |
| 780 | isolate->heap()->always_allocate_scope_depth_++; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 784 | AlwaysAllocateScope::~AlwaysAllocateScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 785 | Isolate* isolate = Isolate::Current(); |
| 786 | isolate->heap()->always_allocate_scope_depth_--; |
| 787 | ASSERT(isolate->heap()->always_allocate_scope_depth_ == 0); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 791 | #ifdef VERIFY_HEAP |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 792 | NoWeakObjectVerificationScope::NoWeakObjectVerificationScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 793 | Isolate* isolate = Isolate::Current(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 794 | isolate->heap()->no_weak_object_verification_scope_depth_++; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 798 | NoWeakObjectVerificationScope::~NoWeakObjectVerificationScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 799 | Isolate* isolate = Isolate::Current(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 800 | isolate->heap()->no_weak_object_verification_scope_depth_--; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 801 | } |
| 802 | #endif |
| 803 | |
| 804 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 805 | void VerifyPointersVisitor::VisitPointers(Object** start, Object** end) { |
| 806 | for (Object** current = start; current < end; current++) { |
| 807 | if ((*current)->IsHeapObject()) { |
| 808 | HeapObject* object = HeapObject::cast(*current); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 809 | CHECK(object->GetIsolate()->heap()->Contains(object)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 810 | CHECK(object->map()->IsMap()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 814 | |
| 815 | |
| 816 | double GCTracer::SizeOfHeapObjects() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 817 | return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 821 | DisallowAllocationFailure::DisallowAllocationFailure() { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 822 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 823 | Isolate* isolate = Isolate::Current(); |
| 824 | old_state_ = isolate->heap()->disallow_allocation_failure_; |
| 825 | isolate->heap()->disallow_allocation_failure_ = true; |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 826 | #endif |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
| 830 | DisallowAllocationFailure::~DisallowAllocationFailure() { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 831 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 832 | Isolate* isolate = Isolate::Current(); |
| 833 | isolate->heap()->disallow_allocation_failure_ = old_state_; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 834 | #endif |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 835 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 836 | |
| 837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 838 | } } // namespace v8::internal |
| 839 | |
| 840 | #endif // V8_HEAP_INL_H_ |