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); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 220 | ASSERT(space != NEW_SPACE || |
| 221 | retry_space == OLD_POINTER_SPACE || |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 222 | retry_space == OLD_DATA_SPACE || |
| 223 | retry_space == LO_SPACE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | #ifdef DEBUG |
| 225 | if (FLAG_gc_interval >= 0 && |
| 226 | !disallow_allocation_failure_ && |
| 227 | Heap::allocation_timeout_-- <= 0) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 228 | return Failure::RetryAfterGC(space); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 230 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 231 | isolate_->counters()->objs_since_last_young()->Increment(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | #endif |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 233 | MaybeObject* result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | if (NEW_SPACE == space) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 235 | result = new_space_.AllocateRaw(size_in_bytes); |
| 236 | if (always_allocate() && result->IsFailure()) { |
| 237 | space = retry_space; |
| 238 | } else { |
| 239 | return result; |
| 240 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | } |
| 242 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 243 | if (OLD_POINTER_SPACE == space) { |
| 244 | result = old_pointer_space_->AllocateRaw(size_in_bytes); |
| 245 | } else if (OLD_DATA_SPACE == space) { |
| 246 | result = old_data_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | } else if (CODE_SPACE == space) { |
| 248 | result = code_space_->AllocateRaw(size_in_bytes); |
| 249 | } else if (LO_SPACE == space) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 250 | result = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 251 | } else if (CELL_SPACE == space) { |
| 252 | result = cell_space_->AllocateRaw(size_in_bytes); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 253 | } else if (PROPERTY_CELL_SPACE == space) { |
| 254 | result = property_cell_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } else { |
| 256 | ASSERT(MAP_SPACE == space); |
| 257 | result = map_space_->AllocateRaw(size_in_bytes); |
| 258 | } |
| 259 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 260 | return result; |
| 261 | } |
| 262 | |
| 263 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 264 | MaybeObject* Heap::NumberFromInt32( |
| 265 | int32_t value, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | if (Smi::IsValid(value)) return Smi::FromInt(value); |
| 267 | // Bypass NumberFromDouble to avoid various redundant checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 268 | return AllocateHeapNumber(FastI2D(value), pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 272 | MaybeObject* Heap::NumberFromUint32( |
| 273 | uint32_t value, PretenureFlag pretenure) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 274 | if (static_cast<int32_t>(value) >= 0 && |
| 275 | Smi::IsValid(static_cast<int32_t>(value))) { |
| 276 | return Smi::FromInt(static_cast<int32_t>(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | } |
| 278 | // Bypass NumberFromDouble to avoid various redundant checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 279 | return AllocateHeapNumber(FastUI2D(value), pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 283 | void Heap::FinalizeExternalString(String* string) { |
| 284 | ASSERT(string->IsExternalString()); |
| 285 | v8::String::ExternalStringResourceBase** resource_addr = |
| 286 | reinterpret_cast<v8::String::ExternalStringResourceBase**>( |
| 287 | reinterpret_cast<byte*>(string) + |
| 288 | ExternalString::kResourceOffset - |
| 289 | kHeapObjectTag); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 290 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 291 | // Dispose of the C++ object if it has not already been disposed. |
| 292 | if (*resource_addr != NULL) { |
| 293 | (*resource_addr)->Dispose(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 294 | *resource_addr = NULL; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 295 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 299 | MaybeObject* Heap::AllocateRawMap() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 300 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 301 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 302 | isolate_->counters()->objs_since_last_young()->Increment(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 303 | #endif |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 304 | MaybeObject* result = map_space_->AllocateRaw(Map::kSize); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 305 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 306 | return result; |
| 307 | } |
| 308 | |
| 309 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 310 | MaybeObject* Heap::AllocateRawCell() { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 311 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 312 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 313 | isolate_->counters()->objs_since_last_young()->Increment(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 314 | #endif |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 315 | MaybeObject* result = cell_space_->AllocateRaw(Cell::kSize); |
| 316 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 317 | return result; |
| 318 | } |
| 319 | |
| 320 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 321 | MaybeObject* Heap::AllocateRawPropertyCell() { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 322 | #ifdef DEBUG |
| 323 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 324 | isolate_->counters()->objs_since_last_young()->Increment(); |
| 325 | #endif |
| 326 | MaybeObject* result = |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 327 | property_cell_space_->AllocateRaw(PropertyCell::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 329 | return result; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | bool Heap::InNewSpace(Object* object) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 334 | bool result = new_space_.Contains(object); |
| 335 | ASSERT(!result || // Either not in new space |
| 336 | gc_state_ != NOT_IN_GC || // ... or in the middle of GC |
| 337 | InToSpace(object)); // ... or in to-space (where we allocate). |
| 338 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 342 | bool Heap::InNewSpace(Address address) { |
| 343 | return new_space_.Contains(address); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | bool Heap::InFromSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 348 | return new_space_.FromSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
| 352 | bool Heap::InToSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 353 | return new_space_.ToSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 357 | bool Heap::InOldPointerSpace(Address address) { |
| 358 | return old_pointer_space_->Contains(address); |
| 359 | } |
| 360 | |
| 361 | |
| 362 | bool Heap::InOldPointerSpace(Object* object) { |
| 363 | return InOldPointerSpace(reinterpret_cast<Address>(object)); |
| 364 | } |
| 365 | |
| 366 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 367 | bool Heap::InOldDataSpace(Address address) { |
| 368 | return old_data_space_->Contains(address); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | bool Heap::InOldDataSpace(Object* object) { |
| 373 | return InOldDataSpace(reinterpret_cast<Address>(object)); |
| 374 | } |
| 375 | |
| 376 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 377 | bool Heap::OldGenerationAllocationLimitReached() { |
| 378 | if (!incremental_marking()->IsStopped()) return false; |
| 379 | return OldGenerationSpaceAvailable() < 0; |
| 380 | } |
| 381 | |
| 382 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | bool Heap::ShouldBePromoted(Address old_address, int object_size) { |
| 384 | // An object should be promoted if: |
| 385 | // - the object has survived a scavenge operation or |
| 386 | // - to space is already 25% full. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 387 | NewSpacePage* page = NewSpacePage::FromAddress(old_address); |
| 388 | Address age_mark = new_space_.age_mark(); |
| 389 | bool below_mark = page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && |
| 390 | (!page->ContainsLimit(age_mark) || old_address < age_mark); |
| 391 | return below_mark || (new_space_.Size() + object_size) >= |
| 392 | (new_space_.EffectiveCapacity() >> 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | void Heap::RecordWrite(Address address, int offset) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 397 | if (!InNewSpace(address)) store_buffer_.Mark(address + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 401 | void Heap::RecordWrites(Address address, int start, int len) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 402 | if (!InNewSpace(address)) { |
| 403 | for (int i = 0; i < len; i++) { |
| 404 | store_buffer_.Mark(address + start + i * kPointerSize); |
| 405 | } |
| 406 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 410 | OldSpace* Heap::TargetSpace(HeapObject* object) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 411 | InstanceType type = object->map()->instance_type(); |
| 412 | AllocationSpace space = TargetSpaceId(type); |
| 413 | return (space == OLD_POINTER_SPACE) |
| 414 | ? old_pointer_space_ |
| 415 | : old_data_space_; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | AllocationSpace Heap::TargetSpaceId(InstanceType type) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 420 | // Heap numbers and sequential strings are promoted to old data space, all |
| 421 | // 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] | 422 | // object->IsHeapNumber() and object->IsSeqString() because we already |
| 423 | // know that object has the heap object tag. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 424 | |
| 425 | // These objects are never allocated in new space. |
| 426 | ASSERT(type != MAP_TYPE); |
| 427 | ASSERT(type != CODE_TYPE); |
| 428 | ASSERT(type != ODDBALL_TYPE); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 429 | ASSERT(type != CELL_TYPE); |
| 430 | ASSERT(type != PROPERTY_CELL_TYPE); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 431 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 432 | if (type <= LAST_NAME_TYPE) { |
| 433 | if (type == SYMBOL_TYPE) return OLD_POINTER_SPACE; |
| 434 | ASSERT(type < FIRST_NONSTRING_TYPE); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 435 | // There are four string representations: sequential strings, external |
| 436 | // strings, cons strings, and sliced strings. |
| 437 | // Only the latter two contain non-map-word pointers to heap objects. |
| 438 | return ((type & kIsIndirectStringMask) == kIsIndirectStringTag) |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 439 | ? OLD_POINTER_SPACE |
| 440 | : OLD_DATA_SPACE; |
| 441 | } else { |
| 442 | return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; |
| 443 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | |
verwaest@chromium.org | ec6855e | 2013-08-22 12:26:58 +0000 | [diff] [blame] | 447 | bool Heap::AllowedToBeMigrated(HeapObject* object, AllocationSpace dst) { |
| 448 | // Object migration is governed by the following rules: |
| 449 | // |
| 450 | // 1) Objects in new-space can be migrated to one of the old spaces |
| 451 | // that matches their target space or they stay in new-space. |
| 452 | // 2) Objects in old-space stay in the same space when migrating. |
| 453 | // 3) Fillers (two or more words) can migrate due to left-trimming of |
| 454 | // fixed arrays in new-space, old-data-space and old-pointer-space. |
| 455 | // 4) Fillers (one word) can never migrate, they are skipped by |
| 456 | // incremental marking explicitly to prevent invalid pattern. |
| 457 | // |
| 458 | // Since this function is used for debugging only, we do not place |
| 459 | // asserts here, but check everything explicitly. |
| 460 | if (object->map() == one_pointer_filler_map()) return false; |
| 461 | InstanceType type = object->map()->instance_type(); |
| 462 | MemoryChunk* chunk = MemoryChunk::FromAddress(object->address()); |
| 463 | AllocationSpace src = chunk->owner()->identity(); |
| 464 | switch (src) { |
| 465 | case NEW_SPACE: |
| 466 | return dst == src || dst == TargetSpaceId(type); |
| 467 | case OLD_POINTER_SPACE: |
| 468 | return dst == src && (dst == TargetSpaceId(type) || object->IsFiller()); |
| 469 | case OLD_DATA_SPACE: |
| 470 | return dst == src && dst == TargetSpaceId(type); |
| 471 | case CODE_SPACE: |
| 472 | return dst == src && type == CODE_TYPE; |
| 473 | case MAP_SPACE: |
| 474 | case CELL_SPACE: |
| 475 | case PROPERTY_CELL_SPACE: |
| 476 | case LO_SPACE: |
| 477 | return false; |
| 478 | } |
| 479 | UNREACHABLE(); |
| 480 | return false; |
| 481 | } |
| 482 | |
| 483 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 484 | void Heap::CopyBlock(Address dst, Address src, int byte_size) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 485 | CopyWords(reinterpret_cast<Object**>(dst), |
| 486 | reinterpret_cast<Object**>(src), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 487 | static_cast<size_t>(byte_size / kPointerSize)); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 488 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 490 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 491 | void Heap::MoveBlock(Address dst, Address src, int byte_size) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 492 | ASSERT(IsAligned(byte_size, kPointerSize)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 493 | |
| 494 | int size_in_words = byte_size / kPointerSize; |
| 495 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 496 | if ((dst < src) || (dst >= (src + byte_size))) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 497 | Object** src_slot = reinterpret_cast<Object**>(src); |
| 498 | Object** dst_slot = reinterpret_cast<Object**>(dst); |
| 499 | Object** end_slot = src_slot + size_in_words; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 500 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 501 | while (src_slot != end_slot) { |
| 502 | *dst_slot++ = *src_slot++; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 503 | } |
| 504 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 505 | OS::MemMove(dst, src, static_cast<size_t>(byte_size)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 510 | void Heap::ScavengePointer(HeapObject** p) { |
| 511 | ScavengeObject(p, *p); |
| 512 | } |
| 513 | |
| 514 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 515 | void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 516 | ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 517 | |
| 518 | // We use the first word (where the map pointer usually is) of a heap |
| 519 | // object to record the forwarding pointer. A forwarding pointer can |
| 520 | // point to an old space, the code space, or the to space of the new |
| 521 | // generation. |
| 522 | MapWord first_word = object->map_word(); |
| 523 | |
| 524 | // If the first word is a forwarding address, the object has already been |
| 525 | // copied. |
| 526 | if (first_word.IsForwardingAddress()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 527 | HeapObject* dest = first_word.ToForwardingAddress(); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 528 | ASSERT(object->GetIsolate()->heap()->InFromSpace(*p)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 529 | *p = dest; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 530 | return; |
| 531 | } |
| 532 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 533 | if (FLAG_trace_track_allocation_sites && object->IsJSObject()) { |
| 534 | if (AllocationMemento::FindForJSObject(JSObject::cast(object), true) != |
| 535 | NULL) { |
| 536 | object->GetIsolate()->heap()->allocation_mementos_found_++; |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
hpayer@chromium.org | 27ce874 | 2013-09-19 09:59:01 +0000 | [diff] [blame] | 540 | // AllocationMementos are unrooted and shouldn't survive a scavenge |
| 541 | ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 542 | // Call the slow part of scavenge object. |
| 543 | return ScavengeObjectSlow(p, object); |
| 544 | } |
| 545 | |
| 546 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 547 | bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason) { |
| 548 | const char* collector_reason = NULL; |
| 549 | GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); |
| 550 | return CollectGarbage(space, collector, gc_reason, collector_reason); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 554 | MaybeObject* Heap::PrepareForCompare(String* str) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 555 | // Always flatten small strings and force flattening of long strings |
| 556 | // after we have accumulated a certain amount we failed to flatten. |
| 557 | static const int kMaxAlwaysFlattenLength = 32; |
| 558 | static const int kFlattenLongThreshold = 16*KB; |
| 559 | |
| 560 | const int length = str->length(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 561 | MaybeObject* obj = str->TryFlatten(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 562 | if (length <= kMaxAlwaysFlattenLength || |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 563 | unflattened_strings_length_ >= kFlattenLongThreshold) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 564 | return obj; |
| 565 | } |
| 566 | if (obj->IsFailure()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 567 | unflattened_strings_length_ += length; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 568 | } |
| 569 | return str; |
| 570 | } |
| 571 | |
| 572 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 573 | intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( |
| 574 | intptr_t change_in_bytes) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 575 | ASSERT(HasBeenSetUp()); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 576 | intptr_t amount = amount_of_external_allocated_memory_ + change_in_bytes; |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 577 | if (change_in_bytes > 0) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 578 | // Avoid overflow. |
| 579 | if (amount > amount_of_external_allocated_memory_) { |
| 580 | amount_of_external_allocated_memory_ = amount; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 581 | } else { |
| 582 | // Give up and reset the counters in case of an overflow. |
| 583 | amount_of_external_allocated_memory_ = 0; |
| 584 | amount_of_external_allocated_memory_at_last_global_gc_ = 0; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 585 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 586 | intptr_t amount_since_last_global_gc = PromotedExternalMemorySize(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 587 | if (amount_since_last_global_gc > external_allocation_limit_) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 588 | CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached"); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 589 | } |
| 590 | } else { |
| 591 | // Avoid underflow. |
| 592 | if (amount >= 0) { |
| 593 | amount_of_external_allocated_memory_ = amount; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 594 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 595 | // Give up and reset the counters in case of an underflow. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 596 | amount_of_external_allocated_memory_ = 0; |
| 597 | amount_of_external_allocated_memory_at_last_global_gc_ = 0; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 600 | if (FLAG_trace_external_memory) { |
| 601 | PrintPID("%8.0f ms: ", isolate()->time_millis_since_init()); |
| 602 | 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] | 603 | "amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d KB, " |
| 604 | "isolate=0x%08" V8PRIxPTR ".\n", |
| 605 | change_in_bytes / KB, |
| 606 | amount_of_external_allocated_memory_ / KB, |
| 607 | PromotedExternalMemorySize() / KB, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 608 | reinterpret_cast<intptr_t>(isolate())); |
| 609 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 610 | ASSERT(amount_of_external_allocated_memory_ >= 0); |
| 611 | return amount_of_external_allocated_memory_; |
| 612 | } |
| 613 | |
| 614 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 615 | Isolate* Heap::isolate() { |
| 616 | return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) - |
| 617 | reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4); |
| 618 | } |
| 619 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 620 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 621 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 622 | #define GC_GREEDY_CHECK(ISOLATE) \ |
| 623 | if (FLAG_gc_greedy) (ISOLATE)->heap()->GarbageCollectionGreedyCheck() |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 624 | #else |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 625 | #define GC_GREEDY_CHECK(ISOLATE) { } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 626 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 627 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 628 | // Calls the FUNCTION_CALL function and retries it up to three times |
| 629 | // to guarantee that any allocations performed during the call will |
| 630 | // succeed if there's enough memory. |
| 631 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 632 | // Warning: Do not use the identifiers __object__, __maybe_object__ or |
| 633 | // __scope__ in a call to this macro. |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 634 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 635 | #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY, OOM)\ |
| 636 | do { \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 637 | GC_GREEDY_CHECK(ISOLATE); \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 638 | MaybeObject* __maybe_object__ = FUNCTION_CALL; \ |
| 639 | Object* __object__ = NULL; \ |
| 640 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 641 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 642 | OOM; \ |
| 643 | } \ |
| 644 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 645 | (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 646 | allocation_space(), \ |
| 647 | "allocation failure"); \ |
| 648 | __maybe_object__ = FUNCTION_CALL; \ |
| 649 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 650 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 651 | OOM; \ |
| 652 | } \ |
| 653 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 654 | (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
| 655 | (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 656 | { \ |
| 657 | AlwaysAllocateScope __scope__; \ |
| 658 | __maybe_object__ = FUNCTION_CALL; \ |
| 659 | } \ |
| 660 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 661 | if (__maybe_object__->IsOutOfMemory()) { \ |
| 662 | OOM; \ |
| 663 | } \ |
| 664 | if (__maybe_object__->IsRetryAfterGC()) { \ |
| 665 | /* TODO(1181417): Fix this. */ \ |
| 666 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ |
| 667 | } \ |
| 668 | RETURN_EMPTY; \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 669 | } while (false) |
| 670 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 671 | #define CALL_AND_RETRY_OR_DIE( \ |
| 672 | ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
| 673 | CALL_AND_RETRY( \ |
| 674 | ISOLATE, \ |
| 675 | FUNCTION_CALL, \ |
| 676 | RETURN_VALUE, \ |
| 677 | RETURN_EMPTY, \ |
| 678 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY", true)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 679 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 680 | #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
| 681 | CALL_AND_RETRY_OR_DIE(ISOLATE, \ |
| 682 | FUNCTION_CALL, \ |
| 683 | return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
| 684 | return Handle<TYPE>()) \ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 685 | |
| 686 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 687 | #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
| 688 | CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 689 | |
| 690 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 691 | #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ |
| 692 | CALL_AND_RETRY(ISOLATE, \ |
| 693 | FUNCTION_CALL, \ |
| 694 | return __object__, \ |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 695 | return __maybe_object__, \ |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 696 | return __maybe_object__) |
| 697 | |
| 698 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 699 | void ExternalStringTable::AddString(String* string) { |
| 700 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 701 | if (heap_->InNewSpace(string)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 702 | new_space_strings_.Add(string); |
| 703 | } else { |
| 704 | old_space_strings_.Add(string); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | |
| 709 | void ExternalStringTable::Iterate(ObjectVisitor* v) { |
| 710 | if (!new_space_strings_.is_empty()) { |
| 711 | Object** start = &new_space_strings_[0]; |
| 712 | v->VisitPointers(start, start + new_space_strings_.length()); |
| 713 | } |
| 714 | if (!old_space_strings_.is_empty()) { |
| 715 | Object** start = &old_space_strings_[0]; |
| 716 | v->VisitPointers(start, start + old_space_strings_.length()); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | |
| 721 | // Verify() is inline to avoid ifdef-s around its calls in release |
| 722 | // mode. |
| 723 | void ExternalStringTable::Verify() { |
| 724 | #ifdef DEBUG |
| 725 | for (int i = 0; i < new_space_strings_.length(); ++i) { |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 726 | Object* obj = Object::cast(new_space_strings_[i]); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 727 | ASSERT(heap_->InNewSpace(obj)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 728 | ASSERT(obj != heap_->the_hole_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 729 | } |
| 730 | for (int i = 0; i < old_space_strings_.length(); ++i) { |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 731 | Object* obj = Object::cast(old_space_strings_[i]); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 732 | ASSERT(!heap_->InNewSpace(obj)); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 733 | ASSERT(obj != heap_->the_hole_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 734 | } |
| 735 | #endif |
| 736 | } |
| 737 | |
| 738 | |
| 739 | void ExternalStringTable::AddOldString(String* string) { |
| 740 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 741 | ASSERT(!heap_->InNewSpace(string)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 742 | old_space_strings_.Add(string); |
| 743 | } |
| 744 | |
| 745 | |
| 746 | void ExternalStringTable::ShrinkNewStrings(int position) { |
| 747 | new_space_strings_.Rewind(position); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 748 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 749 | if (FLAG_verify_heap) { |
| 750 | Verify(); |
| 751 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 752 | #endif |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 753 | } |
| 754 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 755 | |
| 756 | void Heap::ClearInstanceofCache() { |
| 757 | set_instanceof_cache_function(the_hole_value()); |
| 758 | } |
| 759 | |
| 760 | |
| 761 | Object* Heap::ToBoolean(bool condition) { |
| 762 | return condition ? true_value() : false_value(); |
| 763 | } |
| 764 | |
| 765 | |
| 766 | void Heap::CompletelyClearInstanceofCache() { |
| 767 | set_instanceof_cache_map(the_hole_value()); |
| 768 | set_instanceof_cache_function(the_hole_value()); |
| 769 | } |
| 770 | |
| 771 | |
| 772 | MaybeObject* TranscendentalCache::Get(Type type, double input) { |
| 773 | SubCache* cache = caches_[type]; |
| 774 | if (cache == NULL) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 775 | caches_[type] = cache = new SubCache(isolate_, type); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 776 | } |
| 777 | return cache->Get(input); |
| 778 | } |
| 779 | |
| 780 | |
| 781 | Address TranscendentalCache::cache_array_address() { |
| 782 | return reinterpret_cast<Address>(caches_); |
| 783 | } |
| 784 | |
| 785 | |
| 786 | double TranscendentalCache::SubCache::Calculate(double input) { |
| 787 | switch (type_) { |
| 788 | case ACOS: |
| 789 | return acos(input); |
| 790 | case ASIN: |
| 791 | return asin(input); |
| 792 | case ATAN: |
| 793 | return atan(input); |
| 794 | case COS: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 795 | return fast_cos(input); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 796 | case EXP: |
| 797 | return exp(input); |
| 798 | case LOG: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 799 | return fast_log(input); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 800 | case SIN: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 801 | return fast_sin(input); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 802 | case TAN: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 803 | return fast_tan(input); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 804 | default: |
| 805 | return 0.0; // Never happens. |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | |
| 810 | MaybeObject* TranscendentalCache::SubCache::Get(double input) { |
| 811 | Converter c; |
| 812 | c.dbl = input; |
| 813 | int hash = Hash(c); |
| 814 | Element e = elements_[hash]; |
| 815 | if (e.in[0] == c.integers[0] && |
| 816 | e.in[1] == c.integers[1]) { |
| 817 | ASSERT(e.output != NULL); |
| 818 | isolate_->counters()->transcendental_cache_hit()->Increment(); |
| 819 | return e.output; |
| 820 | } |
| 821 | double answer = Calculate(input); |
| 822 | isolate_->counters()->transcendental_cache_miss()->Increment(); |
| 823 | Object* heap_number; |
| 824 | { MaybeObject* maybe_heap_number = |
| 825 | isolate_->heap()->AllocateHeapNumber(answer); |
| 826 | if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; |
| 827 | } |
| 828 | elements_[hash].in[0] = c.integers[0]; |
| 829 | elements_[hash].in[1] = c.integers[1]; |
| 830 | elements_[hash].output = heap_number; |
| 831 | return heap_number; |
| 832 | } |
| 833 | |
| 834 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 835 | AlwaysAllocateScope::AlwaysAllocateScope() { |
| 836 | // We shouldn't hit any nested scopes, because that requires |
| 837 | // non-handle code to call handle code. The code still works but |
| 838 | // performance will degrade, so we want to catch this situation |
| 839 | // in debug mode. |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 840 | Isolate* isolate = Isolate::Current(); |
| 841 | ASSERT(isolate->heap()->always_allocate_scope_depth_ == 0); |
| 842 | isolate->heap()->always_allocate_scope_depth_++; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 846 | AlwaysAllocateScope::~AlwaysAllocateScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 847 | Isolate* isolate = Isolate::Current(); |
| 848 | isolate->heap()->always_allocate_scope_depth_--; |
| 849 | ASSERT(isolate->heap()->always_allocate_scope_depth_ == 0); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 853 | #ifdef VERIFY_HEAP |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 854 | NoWeakObjectVerificationScope::NoWeakObjectVerificationScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 855 | Isolate* isolate = Isolate::Current(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 856 | isolate->heap()->no_weak_object_verification_scope_depth_++; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 860 | NoWeakObjectVerificationScope::~NoWeakObjectVerificationScope() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 861 | Isolate* isolate = Isolate::Current(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 862 | isolate->heap()->no_weak_object_verification_scope_depth_--; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 863 | } |
| 864 | #endif |
| 865 | |
| 866 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 867 | void VerifyPointersVisitor::VisitPointers(Object** start, Object** end) { |
| 868 | for (Object** current = start; current < end; current++) { |
| 869 | if ((*current)->IsHeapObject()) { |
| 870 | HeapObject* object = HeapObject::cast(*current); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 871 | CHECK(object->GetIsolate()->heap()->Contains(object)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 872 | CHECK(object->map()->IsMap()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 876 | |
| 877 | |
| 878 | double GCTracer::SizeOfHeapObjects() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 879 | return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 883 | DisallowAllocationFailure::DisallowAllocationFailure() { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 884 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 885 | Isolate* isolate = Isolate::Current(); |
| 886 | old_state_ = isolate->heap()->disallow_allocation_failure_; |
| 887 | isolate->heap()->disallow_allocation_failure_ = true; |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 888 | #endif |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | |
| 892 | DisallowAllocationFailure::~DisallowAllocationFailure() { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 893 | #ifdef DEBUG |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 894 | Isolate* isolate = Isolate::Current(); |
| 895 | isolate->heap()->disallow_allocation_failure_ = old_state_; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 896 | #endif |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 897 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 898 | |
| 899 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 900 | } } // namespace v8::internal |
| 901 | |
| 902 | #endif // V8_HEAP_INL_H_ |