ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1 | // Copyright 2006-2010 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" |
| 32 | #include "objects.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 33 | #include "isolate.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "v8-counters.h" |
| 35 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | namespace v8 { |
| 37 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 39 | void PromotionQueue::insert(HeapObject* target, int size) { |
| 40 | *(--rear_) = reinterpret_cast<intptr_t>(target); |
| 41 | *(--rear_) = size; |
| 42 | // Assert no overflow into live objects. |
| 43 | ASSERT(reinterpret_cast<Address>(rear_) >= HEAP->new_space()->top()); |
| 44 | } |
| 45 | |
| 46 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 47 | int Heap::MaxObjectSizeInPagedSpace() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | return Page::kMaxHeapObjectSize; |
| 49 | } |
| 50 | |
| 51 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 52 | MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, |
| 53 | PretenureFlag pretenure) { |
| 54 | // Check for ASCII first since this is the common case. |
| 55 | if (String::IsAscii(str.start(), str.length())) { |
| 56 | // If the string is ASCII, we do not need to convert the characters |
| 57 | // since UTF8 is backwards compatible with ASCII. |
| 58 | return AllocateStringFromAscii(str, pretenure); |
| 59 | } |
| 60 | // Non-ASCII and we need to decode. |
| 61 | return AllocateStringFromUtf8Slow(str, pretenure); |
| 62 | } |
| 63 | |
| 64 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 65 | MaybeObject* Heap::AllocateSymbol(Vector<const char> str, |
| 66 | int chars, |
| 67 | uint32_t hash_field) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 68 | unibrow::Utf8InputBuffer<> buffer(str.start(), |
| 69 | static_cast<unsigned>(str.length())); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 70 | return AllocateInternalSymbol(&buffer, chars, hash_field); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 74 | MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, |
| 75 | uint32_t hash_field) { |
| 76 | if (str.length() > SeqAsciiString::kMaxLength) { |
| 77 | return Failure::OutOfMemoryException(); |
| 78 | } |
| 79 | // Compute map and object size. |
| 80 | Map* map = ascii_symbol_map(); |
| 81 | int size = SeqAsciiString::SizeFor(str.length()); |
| 82 | |
| 83 | // Allocate string. |
| 84 | Object* result; |
| 85 | { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 86 | ? lo_space_->AllocateRaw(size) |
| 87 | : old_data_space_->AllocateRaw(size); |
| 88 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 89 | } |
| 90 | |
| 91 | reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 92 | // Set length and hash fields of the allocated string. |
| 93 | String* answer = String::cast(result); |
| 94 | answer->set_length(str.length()); |
| 95 | answer->set_hash_field(hash_field); |
| 96 | |
| 97 | ASSERT_EQ(size, answer->Size()); |
| 98 | |
| 99 | // Fill in the characters. |
| 100 | memcpy(answer->address() + SeqAsciiString::kHeaderSize, |
| 101 | str.start(), str.length()); |
| 102 | |
| 103 | return answer; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str, |
| 108 | uint32_t hash_field) { |
| 109 | if (str.length() > SeqTwoByteString::kMaxLength) { |
| 110 | return Failure::OutOfMemoryException(); |
| 111 | } |
| 112 | // Compute map and object size. |
| 113 | Map* map = symbol_map(); |
| 114 | int size = SeqTwoByteString::SizeFor(str.length()); |
| 115 | |
| 116 | // Allocate string. |
| 117 | Object* result; |
| 118 | { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 119 | ? lo_space_->AllocateRaw(size) |
| 120 | : old_data_space_->AllocateRaw(size); |
| 121 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 122 | } |
| 123 | |
| 124 | reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 125 | // Set length and hash fields of the allocated string. |
| 126 | String* answer = String::cast(result); |
| 127 | answer->set_length(str.length()); |
| 128 | answer->set_hash_field(hash_field); |
| 129 | |
| 130 | ASSERT_EQ(size, answer->Size()); |
| 131 | |
| 132 | // Fill in the characters. |
| 133 | memcpy(answer->address() + SeqTwoByteString::kHeaderSize, |
| 134 | str.start(), str.length() * kUC16Size); |
| 135 | |
| 136 | return answer; |
| 137 | } |
| 138 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 139 | MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 140 | return CopyFixedArrayWithMap(src, src->map()); |
| 141 | } |
| 142 | |
| 143 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 144 | MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
| 145 | AllocationSpace space, |
| 146 | AllocationSpace retry_space) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 148 | ASSERT(space != NEW_SPACE || |
| 149 | retry_space == OLD_POINTER_SPACE || |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 150 | retry_space == OLD_DATA_SPACE || |
| 151 | retry_space == LO_SPACE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 152 | #ifdef DEBUG |
| 153 | if (FLAG_gc_interval >= 0 && |
| 154 | !disallow_allocation_failure_ && |
| 155 | Heap::allocation_timeout_-- <= 0) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 156 | return Failure::RetryAfterGC(space); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 158 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 159 | isolate_->counters()->objs_since_last_young()->Increment(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | #endif |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 161 | MaybeObject* result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | if (NEW_SPACE == space) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 163 | result = new_space_.AllocateRaw(size_in_bytes); |
| 164 | if (always_allocate() && result->IsFailure()) { |
| 165 | space = retry_space; |
| 166 | } else { |
| 167 | return result; |
| 168 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | } |
| 170 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 171 | if (OLD_POINTER_SPACE == space) { |
| 172 | result = old_pointer_space_->AllocateRaw(size_in_bytes); |
| 173 | } else if (OLD_DATA_SPACE == space) { |
| 174 | result = old_data_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | } else if (CODE_SPACE == space) { |
| 176 | result = code_space_->AllocateRaw(size_in_bytes); |
| 177 | } else if (LO_SPACE == space) { |
| 178 | result = lo_space_->AllocateRaw(size_in_bytes); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 179 | } else if (CELL_SPACE == space) { |
| 180 | result = cell_space_->AllocateRaw(size_in_bytes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 181 | } else { |
| 182 | ASSERT(MAP_SPACE == space); |
| 183 | result = map_space_->AllocateRaw(size_in_bytes); |
| 184 | } |
| 185 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 186 | return result; |
| 187 | } |
| 188 | |
| 189 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 190 | MaybeObject* Heap::NumberFromInt32(int32_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | if (Smi::IsValid(value)) return Smi::FromInt(value); |
| 192 | // Bypass NumberFromDouble to avoid various redundant checks. |
| 193 | return AllocateHeapNumber(FastI2D(value)); |
| 194 | } |
| 195 | |
| 196 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 197 | MaybeObject* Heap::NumberFromUint32(uint32_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | if ((int32_t)value >= 0 && Smi::IsValid((int32_t)value)) { |
| 199 | return Smi::FromInt((int32_t)value); |
| 200 | } |
| 201 | // Bypass NumberFromDouble to avoid various redundant checks. |
| 202 | return AllocateHeapNumber(FastUI2D(value)); |
| 203 | } |
| 204 | |
| 205 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 206 | void Heap::FinalizeExternalString(String* string) { |
| 207 | ASSERT(string->IsExternalString()); |
| 208 | v8::String::ExternalStringResourceBase** resource_addr = |
| 209 | reinterpret_cast<v8::String::ExternalStringResourceBase**>( |
| 210 | reinterpret_cast<byte*>(string) + |
| 211 | ExternalString::kResourceOffset - |
| 212 | kHeapObjectTag); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 213 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 214 | // Dispose of the C++ object if it has not already been disposed. |
| 215 | if (*resource_addr != NULL) { |
| 216 | (*resource_addr)->Dispose(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 217 | } |
| 218 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 219 | // Clear the resource pointer in the string. |
| 220 | *resource_addr = NULL; |
| 221 | } |
| 222 | |
| 223 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 224 | MaybeObject* Heap::AllocateRawMap() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 226 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 227 | isolate_->counters()->objs_since_last_young()->Increment(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 228 | #endif |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 229 | MaybeObject* result = map_space_->AllocateRaw(Map::kSize); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 230 | if (result->IsFailure()) old_gen_exhausted_ = true; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 231 | #ifdef DEBUG |
| 232 | if (!result->IsFailure()) { |
| 233 | // Maps have their own alignment. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 234 | CHECK((reinterpret_cast<intptr_t>(result) & kMapAlignmentMask) == |
| 235 | static_cast<intptr_t>(kHeapObjectTag)); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 236 | } |
| 237 | #endif |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 238 | return result; |
| 239 | } |
| 240 | |
| 241 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 242 | MaybeObject* Heap::AllocateRawCell() { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 243 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 244 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 245 | isolate_->counters()->objs_since_last_young()->Increment(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 246 | #endif |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 247 | MaybeObject* result = cell_space_->AllocateRaw(JSGlobalPropertyCell::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | if (result->IsFailure()) old_gen_exhausted_ = true; |
| 249 | return result; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | bool Heap::InNewSpace(Object* object) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 254 | bool result = new_space_.Contains(object); |
| 255 | ASSERT(!result || // Either not in new space |
| 256 | gc_state_ != NOT_IN_GC || // ... or in the middle of GC |
| 257 | InToSpace(object)); // ... or in to-space (where we allocate). |
| 258 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | |
| 262 | bool Heap::InFromSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 263 | return new_space_.FromSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | |
| 267 | bool Heap::InToSpace(Object* object) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 268 | return new_space_.ToSpaceContains(object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
| 272 | bool Heap::ShouldBePromoted(Address old_address, int object_size) { |
| 273 | // An object should be promoted if: |
| 274 | // - the object has survived a scavenge operation or |
| 275 | // - to space is already 25% full. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 276 | return old_address < new_space_.age_mark() |
| 277 | || (new_space_.Size() + object_size) >= (new_space_.Capacity() >> 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
| 281 | void Heap::RecordWrite(Address address, int offset) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 282 | if (new_space_.Contains(address)) return; |
| 283 | ASSERT(!new_space_.FromSpaceContains(address)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 284 | SLOW_ASSERT(Contains(address + offset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 285 | Page::FromAddress(address)->MarkRegionDirty(address + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 289 | void Heap::RecordWrites(Address address, int start, int len) { |
| 290 | if (new_space_.Contains(address)) return; |
| 291 | ASSERT(!new_space_.FromSpaceContains(address)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 292 | Page* page = Page::FromAddress(address); |
| 293 | page->SetRegionMarks(page->GetRegionMarks() | |
| 294 | page->GetRegionMaskForSpan(address + start, len * kPointerSize)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 298 | OldSpace* Heap::TargetSpace(HeapObject* object) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 299 | InstanceType type = object->map()->instance_type(); |
| 300 | AllocationSpace space = TargetSpaceId(type); |
| 301 | return (space == OLD_POINTER_SPACE) |
| 302 | ? old_pointer_space_ |
| 303 | : old_data_space_; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | AllocationSpace Heap::TargetSpaceId(InstanceType type) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 308 | // Heap numbers and sequential strings are promoted to old data space, all |
| 309 | // 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] | 310 | // object->IsHeapNumber() and object->IsSeqString() because we already |
| 311 | // know that object has the heap object tag. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 312 | |
| 313 | // These objects are never allocated in new space. |
| 314 | ASSERT(type != MAP_TYPE); |
| 315 | ASSERT(type != CODE_TYPE); |
| 316 | ASSERT(type != ODDBALL_TYPE); |
| 317 | ASSERT(type != JS_GLOBAL_PROPERTY_CELL_TYPE); |
| 318 | |
| 319 | if (type < FIRST_NONSTRING_TYPE) { |
| 320 | // There are three string representations: sequential strings, cons |
| 321 | // strings, and external strings. Only cons strings contain |
| 322 | // non-map-word pointers to heap objects. |
| 323 | return ((type & kStringRepresentationMask) == kConsStringTag) |
| 324 | ? OLD_POINTER_SPACE |
| 325 | : OLD_DATA_SPACE; |
| 326 | } else { |
| 327 | return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; |
| 328 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 332 | void Heap::CopyBlock(Address dst, Address src, int byte_size) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 333 | ASSERT(IsAligned(byte_size, kPointerSize)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 334 | CopyWords(reinterpret_cast<Object**>(dst), |
| 335 | reinterpret_cast<Object**>(src), |
| 336 | byte_size / kPointerSize); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 337 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 339 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 340 | void Heap::CopyBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 341 | Address src, |
| 342 | int byte_size) { |
| 343 | ASSERT(IsAligned(byte_size, kPointerSize)); |
| 344 | |
| 345 | Page* page = Page::FromAddress(dst); |
| 346 | uint32_t marks = page->GetRegionMarks(); |
| 347 | |
| 348 | for (int remaining = byte_size / kPointerSize; |
| 349 | remaining > 0; |
| 350 | remaining--) { |
| 351 | Memory::Object_at(dst) = Memory::Object_at(src); |
| 352 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 353 | if (InNewSpace(Memory::Object_at(dst))) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 354 | marks |= page->GetRegionMaskForAddress(dst); |
| 355 | } |
| 356 | |
| 357 | dst += kPointerSize; |
| 358 | src += kPointerSize; |
| 359 | } |
| 360 | |
| 361 | page->SetRegionMarks(marks); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | void Heap::MoveBlock(Address dst, Address src, int byte_size) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 366 | ASSERT(IsAligned(byte_size, kPointerSize)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 367 | |
| 368 | int size_in_words = byte_size / kPointerSize; |
| 369 | |
| 370 | if ((dst < src) || (dst >= (src + size_in_words))) { |
| 371 | ASSERT((dst >= (src + size_in_words)) || |
| 372 | ((OffsetFrom(reinterpret_cast<Address>(src)) - |
| 373 | OffsetFrom(reinterpret_cast<Address>(dst))) >= kPointerSize)); |
| 374 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 375 | Object** src_slot = reinterpret_cast<Object**>(src); |
| 376 | Object** dst_slot = reinterpret_cast<Object**>(dst); |
| 377 | Object** end_slot = src_slot + size_in_words; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 378 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 379 | while (src_slot != end_slot) { |
| 380 | *dst_slot++ = *src_slot++; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 381 | } |
| 382 | } else { |
| 383 | memmove(dst, src, byte_size); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 388 | void Heap::MoveBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 389 | Address src, |
| 390 | int byte_size) { |
| 391 | ASSERT(IsAligned(byte_size, kPointerSize)); |
| 392 | ASSERT((dst >= (src + byte_size)) || |
| 393 | ((OffsetFrom(src) - OffsetFrom(dst)) >= kPointerSize)); |
| 394 | |
| 395 | CopyBlockToOldSpaceAndUpdateRegionMarks(dst, src, byte_size); |
| 396 | } |
| 397 | |
| 398 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 399 | void Heap::ScavengePointer(HeapObject** p) { |
| 400 | ScavengeObject(p, *p); |
| 401 | } |
| 402 | |
| 403 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 404 | void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 405 | ASSERT(HEAP->InFromSpace(object)); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 406 | |
| 407 | // We use the first word (where the map pointer usually is) of a heap |
| 408 | // object to record the forwarding pointer. A forwarding pointer can |
| 409 | // point to an old space, the code space, or the to space of the new |
| 410 | // generation. |
| 411 | MapWord first_word = object->map_word(); |
| 412 | |
| 413 | // If the first word is a forwarding address, the object has already been |
| 414 | // copied. |
| 415 | if (first_word.IsForwardingAddress()) { |
| 416 | *p = first_word.ToForwardingAddress(); |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | // Call the slow part of scavenge object. |
| 421 | return ScavengeObjectSlow(p, object); |
| 422 | } |
| 423 | |
| 424 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 425 | bool Heap::CollectGarbage(AllocationSpace space) { |
| 426 | return CollectGarbage(space, SelectGarbageCollector(space)); |
| 427 | } |
| 428 | |
| 429 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 430 | MaybeObject* Heap::PrepareForCompare(String* str) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 431 | // Always flatten small strings and force flattening of long strings |
| 432 | // after we have accumulated a certain amount we failed to flatten. |
| 433 | static const int kMaxAlwaysFlattenLength = 32; |
| 434 | static const int kFlattenLongThreshold = 16*KB; |
| 435 | |
| 436 | const int length = str->length(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 437 | MaybeObject* obj = str->TryFlatten(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 438 | if (length <= kMaxAlwaysFlattenLength || |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 439 | unflattened_strings_length_ >= kFlattenLongThreshold) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 440 | return obj; |
| 441 | } |
| 442 | if (obj->IsFailure()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 443 | unflattened_strings_length_ += length; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 444 | } |
| 445 | return str; |
| 446 | } |
| 447 | |
| 448 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 449 | int Heap::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) { |
| 450 | ASSERT(HasBeenSetup()); |
| 451 | int amount = amount_of_external_allocated_memory_ + change_in_bytes; |
| 452 | if (change_in_bytes >= 0) { |
| 453 | // Avoid overflow. |
| 454 | if (amount > amount_of_external_allocated_memory_) { |
| 455 | amount_of_external_allocated_memory_ = amount; |
| 456 | } |
| 457 | int amount_since_last_global_gc = |
| 458 | amount_of_external_allocated_memory_ - |
| 459 | amount_of_external_allocated_memory_at_last_global_gc_; |
| 460 | if (amount_since_last_global_gc > external_allocation_limit_) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 461 | CollectAllGarbage(false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 462 | } |
| 463 | } else { |
| 464 | // Avoid underflow. |
| 465 | if (amount >= 0) { |
| 466 | amount_of_external_allocated_memory_ = amount; |
| 467 | } |
| 468 | } |
| 469 | ASSERT(amount_of_external_allocated_memory_ >= 0); |
| 470 | return amount_of_external_allocated_memory_; |
| 471 | } |
| 472 | |
| 473 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 474 | void Heap::SetLastScriptId(Object* last_script_id) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 475 | roots_[kLastScriptIdRootIndex] = last_script_id; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 476 | } |
| 477 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 478 | Isolate* Heap::isolate() { |
| 479 | return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) - |
| 480 | reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4); |
| 481 | } |
| 482 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 483 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 484 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 485 | #define GC_GREEDY_CHECK() \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 486 | if (FLAG_gc_greedy) HEAP->GarbageCollectionGreedyCheck() |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 487 | #else |
| 488 | #define GC_GREEDY_CHECK() { } |
| 489 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 491 | |
| 492 | // Calls the FUNCTION_CALL function and retries it up to three times |
| 493 | // to guarantee that any allocations performed during the call will |
| 494 | // succeed if there's enough memory. |
| 495 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 496 | // Warning: Do not use the identifiers __object__, __maybe_object__ or |
| 497 | // __scope__ in a call to this macro. |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 498 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 499 | #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY)\ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 500 | do { \ |
| 501 | GC_GREEDY_CHECK(); \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 502 | MaybeObject* __maybe_object__ = FUNCTION_CALL; \ |
| 503 | Object* __object__ = NULL; \ |
| 504 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 505 | if (__maybe_object__->IsOutOfMemory()) { \ |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 506 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0", true);\ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 507 | } \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 508 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 509 | ISOLATE->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
| 510 | allocation_space()); \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 511 | __maybe_object__ = FUNCTION_CALL; \ |
| 512 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 513 | if (__maybe_object__->IsOutOfMemory()) { \ |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 514 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_1", true);\ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 515 | } \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 516 | if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 517 | ISOLATE->counters()->gc_last_resort_from_handles()->Increment(); \ |
| 518 | ISOLATE->heap()->CollectAllAvailableGarbage(); \ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 519 | { \ |
| 520 | AlwaysAllocateScope __scope__; \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 521 | __maybe_object__ = FUNCTION_CALL; \ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 522 | } \ |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 523 | if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 524 | if (__maybe_object__->IsOutOfMemory() || \ |
| 525 | __maybe_object__->IsRetryAfterGC()) { \ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 526 | /* TODO(1181417): Fix this. */ \ |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 527 | v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_2", true);\ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 528 | } \ |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 529 | RETURN_EMPTY; \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | } while (false) |
| 531 | |
| 532 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 533 | // TODO(isolates): cache isolate: either accept as a parameter or |
| 534 | // set to some known symbol (__CUR_ISOLATE__?) |
| 535 | #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
| 536 | CALL_AND_RETRY(ISOLATE, \ |
| 537 | FUNCTION_CALL, \ |
| 538 | return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 539 | return Handle<TYPE>()) |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 540 | |
| 541 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 542 | #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
| 543 | CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, return, return) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 544 | |
| 545 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | #ifdef DEBUG |
| 547 | |
| 548 | inline bool Heap::allow_allocation(bool new_state) { |
| 549 | bool old = allocation_allowed_; |
| 550 | allocation_allowed_ = new_state; |
| 551 | return old; |
| 552 | } |
| 553 | |
| 554 | #endif |
| 555 | |
| 556 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 557 | void ExternalStringTable::AddString(String* string) { |
| 558 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 559 | if (heap_->InNewSpace(string)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 560 | new_space_strings_.Add(string); |
| 561 | } else { |
| 562 | old_space_strings_.Add(string); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | |
| 567 | void ExternalStringTable::Iterate(ObjectVisitor* v) { |
| 568 | if (!new_space_strings_.is_empty()) { |
| 569 | Object** start = &new_space_strings_[0]; |
| 570 | v->VisitPointers(start, start + new_space_strings_.length()); |
| 571 | } |
| 572 | if (!old_space_strings_.is_empty()) { |
| 573 | Object** start = &old_space_strings_[0]; |
| 574 | v->VisitPointers(start, start + old_space_strings_.length()); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | |
| 579 | // Verify() is inline to avoid ifdef-s around its calls in release |
| 580 | // mode. |
| 581 | void ExternalStringTable::Verify() { |
| 582 | #ifdef DEBUG |
| 583 | for (int i = 0; i < new_space_strings_.length(); ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 584 | ASSERT(heap_->InNewSpace(new_space_strings_[i])); |
| 585 | ASSERT(new_space_strings_[i] != HEAP->raw_unchecked_null_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 586 | } |
| 587 | for (int i = 0; i < old_space_strings_.length(); ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 588 | ASSERT(!heap_->InNewSpace(old_space_strings_[i])); |
| 589 | ASSERT(old_space_strings_[i] != HEAP->raw_unchecked_null_value()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 590 | } |
| 591 | #endif |
| 592 | } |
| 593 | |
| 594 | |
| 595 | void ExternalStringTable::AddOldString(String* string) { |
| 596 | ASSERT(string->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 597 | ASSERT(!heap_->InNewSpace(string)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 598 | old_space_strings_.Add(string); |
| 599 | } |
| 600 | |
| 601 | |
| 602 | void ExternalStringTable::ShrinkNewStrings(int position) { |
| 603 | new_space_strings_.Rewind(position); |
| 604 | Verify(); |
| 605 | } |
| 606 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 607 | |
| 608 | void Heap::ClearInstanceofCache() { |
| 609 | set_instanceof_cache_function(the_hole_value()); |
| 610 | } |
| 611 | |
| 612 | |
| 613 | Object* Heap::ToBoolean(bool condition) { |
| 614 | return condition ? true_value() : false_value(); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | void Heap::CompletelyClearInstanceofCache() { |
| 619 | set_instanceof_cache_map(the_hole_value()); |
| 620 | set_instanceof_cache_function(the_hole_value()); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | MaybeObject* TranscendentalCache::Get(Type type, double input) { |
| 625 | SubCache* cache = caches_[type]; |
| 626 | if (cache == NULL) { |
| 627 | caches_[type] = cache = new SubCache(type); |
| 628 | } |
| 629 | return cache->Get(input); |
| 630 | } |
| 631 | |
| 632 | |
| 633 | Address TranscendentalCache::cache_array_address() { |
| 634 | return reinterpret_cast<Address>(caches_); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | double TranscendentalCache::SubCache::Calculate(double input) { |
| 639 | switch (type_) { |
| 640 | case ACOS: |
| 641 | return acos(input); |
| 642 | case ASIN: |
| 643 | return asin(input); |
| 644 | case ATAN: |
| 645 | return atan(input); |
| 646 | case COS: |
| 647 | return cos(input); |
| 648 | case EXP: |
| 649 | return exp(input); |
| 650 | case LOG: |
| 651 | return log(input); |
| 652 | case SIN: |
| 653 | return sin(input); |
| 654 | case TAN: |
| 655 | return tan(input); |
| 656 | default: |
| 657 | return 0.0; // Never happens. |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | |
| 662 | MaybeObject* TranscendentalCache::SubCache::Get(double input) { |
| 663 | Converter c; |
| 664 | c.dbl = input; |
| 665 | int hash = Hash(c); |
| 666 | Element e = elements_[hash]; |
| 667 | if (e.in[0] == c.integers[0] && |
| 668 | e.in[1] == c.integers[1]) { |
| 669 | ASSERT(e.output != NULL); |
| 670 | isolate_->counters()->transcendental_cache_hit()->Increment(); |
| 671 | return e.output; |
| 672 | } |
| 673 | double answer = Calculate(input); |
| 674 | isolate_->counters()->transcendental_cache_miss()->Increment(); |
| 675 | Object* heap_number; |
| 676 | { MaybeObject* maybe_heap_number = |
| 677 | isolate_->heap()->AllocateHeapNumber(answer); |
| 678 | if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; |
| 679 | } |
| 680 | elements_[hash].in[0] = c.integers[0]; |
| 681 | elements_[hash].in[1] = c.integers[1]; |
| 682 | elements_[hash].output = heap_number; |
| 683 | return heap_number; |
| 684 | } |
| 685 | |
| 686 | |
| 687 | Heap* _inline_get_heap_() { |
| 688 | return HEAP; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | void MarkCompactCollector::SetMark(HeapObject* obj) { |
| 693 | tracer_->increment_marked_count(); |
| 694 | #ifdef DEBUG |
| 695 | UpdateLiveObjectCount(obj); |
| 696 | #endif |
| 697 | obj->SetMark(); |
| 698 | } |
| 699 | |
| 700 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | } } // namespace v8::internal |
| 702 | |
| 703 | #endif // V8_HEAP_INL_H_ |