blob: cc558b8248bb767b47ecb0a09081ec0050861b49 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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
31#include "log.h"
32#include "v8-counters.h"
33
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
ager@chromium.org5aa501c2009-06-23 07:57:28 +000037int Heap::MaxObjectSizeInPagedSpace() {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038 return Page::kMaxHeapObjectSize;
39}
40
41
ager@chromium.orga74f0da2008-12-03 16:05:52 +000042Object* Heap::AllocateSymbol(Vector<const char> str,
43 int chars,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +000044 uint32_t hash_field) {
ager@chromium.orga74f0da2008-12-03 16:05:52 +000045 unibrow::Utf8InputBuffer<> buffer(str.start(),
46 static_cast<unsigned>(str.length()));
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +000047 return AllocateInternalSymbol(&buffer, chars, hash_field);
ager@chromium.orga74f0da2008-12-03 16:05:52 +000048}
49
50
ager@chromium.org9258b6b2008-09-11 09:11:10 +000051Object* Heap::AllocateRaw(int size_in_bytes,
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000052 AllocationSpace space,
53 AllocationSpace retry_space) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000054 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000055 ASSERT(space != NEW_SPACE ||
56 retry_space == OLD_POINTER_SPACE ||
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000057 retry_space == OLD_DATA_SPACE ||
58 retry_space == LO_SPACE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000059#ifdef DEBUG
60 if (FLAG_gc_interval >= 0 &&
61 !disallow_allocation_failure_ &&
62 Heap::allocation_timeout_-- <= 0) {
63 return Failure::RetryAfterGC(size_in_bytes, space);
64 }
65 Counters::objs_since_last_full.Increment();
66 Counters::objs_since_last_young.Increment();
67#endif
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000068 Object* result;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069 if (NEW_SPACE == space) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000070 result = new_space_.AllocateRaw(size_in_bytes);
71 if (always_allocate() && result->IsFailure()) {
72 space = retry_space;
73 } else {
74 return result;
75 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000076 }
77
ager@chromium.org9258b6b2008-09-11 09:11:10 +000078 if (OLD_POINTER_SPACE == space) {
79 result = old_pointer_space_->AllocateRaw(size_in_bytes);
80 } else if (OLD_DATA_SPACE == space) {
81 result = old_data_space_->AllocateRaw(size_in_bytes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000082 } else if (CODE_SPACE == space) {
83 result = code_space_->AllocateRaw(size_in_bytes);
84 } else if (LO_SPACE == space) {
85 result = lo_space_->AllocateRaw(size_in_bytes);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +000086 } else if (CELL_SPACE == space) {
87 result = cell_space_->AllocateRaw(size_in_bytes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000088 } else {
89 ASSERT(MAP_SPACE == space);
90 result = map_space_->AllocateRaw(size_in_bytes);
91 }
92 if (result->IsFailure()) old_gen_exhausted_ = true;
93 return result;
94}
95
96
97Object* Heap::NumberFromInt32(int32_t value) {
98 if (Smi::IsValid(value)) return Smi::FromInt(value);
99 // Bypass NumberFromDouble to avoid various redundant checks.
100 return AllocateHeapNumber(FastI2D(value));
101}
102
103
104Object* Heap::NumberFromUint32(uint32_t value) {
105 if ((int32_t)value >= 0 && Smi::IsValid((int32_t)value)) {
106 return Smi::FromInt((int32_t)value);
107 }
108 // Bypass NumberFromDouble to avoid various redundant checks.
109 return AllocateHeapNumber(FastUI2D(value));
110}
111
112
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000113void Heap::FinalizeExternalString(String* string) {
114 ASSERT(string->IsExternalString());
115 v8::String::ExternalStringResourceBase** resource_addr =
116 reinterpret_cast<v8::String::ExternalStringResourceBase**>(
117 reinterpret_cast<byte*>(string) +
118 ExternalString::kResourceOffset -
119 kHeapObjectTag);
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000120
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000121 // Dispose of the C++ object if it has not already been disposed.
122 if (*resource_addr != NULL) {
123 (*resource_addr)->Dispose();
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000124 }
125
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000126 // Clear the resource pointer in the string.
127 *resource_addr = NULL;
128}
129
130
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000131Object* Heap::AllocateRawMap() {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000132#ifdef DEBUG
133 Counters::objs_since_last_full.Increment();
134 Counters::objs_since_last_young.Increment();
135#endif
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000136 Object* result = map_space_->AllocateRaw(Map::kSize);
137 if (result->IsFailure()) old_gen_exhausted_ = true;
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000138#ifdef DEBUG
139 if (!result->IsFailure()) {
140 // Maps have their own alignment.
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000141 CHECK((reinterpret_cast<intptr_t>(result) & kMapAlignmentMask) ==
142 static_cast<intptr_t>(kHeapObjectTag));
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000143 }
144#endif
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000145 return result;
146}
147
148
149Object* Heap::AllocateRawCell() {
150#ifdef DEBUG
151 Counters::objs_since_last_full.Increment();
152 Counters::objs_since_last_young.Increment();
153#endif
154 Object* result = cell_space_->AllocateRaw(JSGlobalPropertyCell::kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155 if (result->IsFailure()) old_gen_exhausted_ = true;
156 return result;
157}
158
159
160bool Heap::InNewSpace(Object* object) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000161 bool result = new_space_.Contains(object);
162 ASSERT(!result || // Either not in new space
163 gc_state_ != NOT_IN_GC || // ... or in the middle of GC
164 InToSpace(object)); // ... or in to-space (where we allocate).
165 return result;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000166}
167
168
169bool Heap::InFromSpace(Object* object) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000170 return new_space_.FromSpaceContains(object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171}
172
173
174bool Heap::InToSpace(Object* object) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000175 return new_space_.ToSpaceContains(object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000176}
177
178
179bool Heap::ShouldBePromoted(Address old_address, int object_size) {
180 // An object should be promoted if:
181 // - the object has survived a scavenge operation or
182 // - to space is already 25% full.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000183 return old_address < new_space_.age_mark()
184 || (new_space_.Size() + object_size) >= (new_space_.Capacity() >> 2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185}
186
187
188void Heap::RecordWrite(Address address, int offset) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000189 if (new_space_.Contains(address)) return;
190 ASSERT(!new_space_.FromSpaceContains(address));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191 SLOW_ASSERT(Contains(address + offset));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000192 Page::FromAddress(address)->MarkRegionDirty(address + offset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193}
194
195
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000196void Heap::RecordWrites(Address address, int start, int len) {
197 if (new_space_.Contains(address)) return;
198 ASSERT(!new_space_.FromSpaceContains(address));
199 for (int offset = start;
200 offset < start + len * kPointerSize;
201 offset += kPointerSize) {
202 SLOW_ASSERT(Contains(address + offset));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000203 Page::FromAddress(address)->MarkRegionDirty(address + offset);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000204 }
205}
206
207
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000208OldSpace* Heap::TargetSpace(HeapObject* object) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000209 InstanceType type = object->map()->instance_type();
210 AllocationSpace space = TargetSpaceId(type);
211 return (space == OLD_POINTER_SPACE)
212 ? old_pointer_space_
213 : old_data_space_;
214}
215
216
217AllocationSpace Heap::TargetSpaceId(InstanceType type) {
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000218 // Heap numbers and sequential strings are promoted to old data space, all
219 // other object types are promoted to old pointer space. We do not use
kasper.lund7276f142008-07-30 08:49:36 +0000220 // object->IsHeapNumber() and object->IsSeqString() because we already
221 // know that object has the heap object tag.
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000222
223 // These objects are never allocated in new space.
224 ASSERT(type != MAP_TYPE);
225 ASSERT(type != CODE_TYPE);
226 ASSERT(type != ODDBALL_TYPE);
227 ASSERT(type != JS_GLOBAL_PROPERTY_CELL_TYPE);
228
229 if (type < FIRST_NONSTRING_TYPE) {
230 // There are three string representations: sequential strings, cons
231 // strings, and external strings. Only cons strings contain
232 // non-map-word pointers to heap objects.
233 return ((type & kStringRepresentationMask) == kConsStringTag)
234 ? OLD_POINTER_SPACE
235 : OLD_DATA_SPACE;
236 } else {
237 return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE;
238 }
kasper.lund7276f142008-07-30 08:49:36 +0000239}
240
241
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000242void Heap::CopyBlock(Address dst, Address src, int byte_size) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000243 ASSERT(IsAligned(byte_size, kPointerSize));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000244 CopyWords(reinterpret_cast<Object**>(dst),
245 reinterpret_cast<Object**>(src),
246 byte_size / kPointerSize);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000247}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000248
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000249
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000250void Heap::CopyBlockToOldSpaceAndUpdateRegionMarks(Address dst,
251 Address src,
252 int byte_size) {
253 ASSERT(IsAligned(byte_size, kPointerSize));
254
255 Page* page = Page::FromAddress(dst);
256 uint32_t marks = page->GetRegionMarks();
257
258 for (int remaining = byte_size / kPointerSize;
259 remaining > 0;
260 remaining--) {
261 Memory::Object_at(dst) = Memory::Object_at(src);
262
263 if (Heap::InNewSpace(Memory::Object_at(dst))) {
264 marks |= page->GetRegionMaskForAddress(dst);
265 }
266
267 dst += kPointerSize;
268 src += kPointerSize;
269 }
270
271 page->SetRegionMarks(marks);
272}
273
274
275void Heap::MoveBlock(Address dst, Address src, int byte_size) {
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000276 ASSERT(IsAligned(byte_size, kPointerSize));
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000277
278 int size_in_words = byte_size / kPointerSize;
279
280 if ((dst < src) || (dst >= (src + size_in_words))) {
281 ASSERT((dst >= (src + size_in_words)) ||
282 ((OffsetFrom(reinterpret_cast<Address>(src)) -
283 OffsetFrom(reinterpret_cast<Address>(dst))) >= kPointerSize));
284
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000285 Object** src_slot = reinterpret_cast<Object**>(src);
286 Object** dst_slot = reinterpret_cast<Object**>(dst);
287 Object** end_slot = src_slot + size_in_words;
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000288
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000289 while (src_slot != end_slot) {
290 *dst_slot++ = *src_slot++;
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000291 }
292 } else {
293 memmove(dst, src, byte_size);
294 }
295}
296
297
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000298void Heap::MoveBlockToOldSpaceAndUpdateRegionMarks(Address dst,
299 Address src,
300 int byte_size) {
301 ASSERT(IsAligned(byte_size, kPointerSize));
302 ASSERT((dst >= (src + byte_size)) ||
303 ((OffsetFrom(src) - OffsetFrom(dst)) >= kPointerSize));
304
305 CopyBlockToOldSpaceAndUpdateRegionMarks(dst, src, byte_size);
306}
307
308
kasperl@chromium.orgb3284ad2009-05-18 06:12:45 +0000309void Heap::ScavengeObject(HeapObject** p, HeapObject* object) {
310 ASSERT(InFromSpace(object));
311
312 // We use the first word (where the map pointer usually is) of a heap
313 // object to record the forwarding pointer. A forwarding pointer can
314 // point to an old space, the code space, or the to space of the new
315 // generation.
316 MapWord first_word = object->map_word();
317
318 // If the first word is a forwarding address, the object has already been
319 // copied.
320 if (first_word.IsForwardingAddress()) {
321 *p = first_word.ToForwardingAddress();
322 return;
323 }
324
325 // Call the slow part of scavenge object.
326 return ScavengeObjectSlow(p, object);
327}
328
329
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000330Object* Heap::PrepareForCompare(String* str) {
331 // Always flatten small strings and force flattening of long strings
332 // after we have accumulated a certain amount we failed to flatten.
333 static const int kMaxAlwaysFlattenLength = 32;
334 static const int kFlattenLongThreshold = 16*KB;
335
336 const int length = str->length();
337 Object* obj = str->TryFlatten();
338 if (length <= kMaxAlwaysFlattenLength ||
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000339 unflattened_strings_length_ >= kFlattenLongThreshold) {
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000340 return obj;
341 }
342 if (obj->IsFailure()) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000343 unflattened_strings_length_ += length;
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000344 }
345 return str;
346}
347
348
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000349int Heap::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) {
350 ASSERT(HasBeenSetup());
351 int amount = amount_of_external_allocated_memory_ + change_in_bytes;
352 if (change_in_bytes >= 0) {
353 // Avoid overflow.
354 if (amount > amount_of_external_allocated_memory_) {
355 amount_of_external_allocated_memory_ = amount;
356 }
357 int amount_since_last_global_gc =
358 amount_of_external_allocated_memory_ -
359 amount_of_external_allocated_memory_at_last_global_gc_;
360 if (amount_since_last_global_gc > external_allocation_limit_) {
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000361 CollectAllGarbage(false);
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000362 }
363 } else {
364 // Avoid underflow.
365 if (amount >= 0) {
366 amount_of_external_allocated_memory_ = amount;
367 }
368 }
369 ASSERT(amount_of_external_allocated_memory_ >= 0);
370 return amount_of_external_allocated_memory_;
371}
372
373
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000374void Heap::SetLastScriptId(Object* last_script_id) {
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000375 roots_[kLastScriptIdRootIndex] = last_script_id;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000376}
377
378
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000379#define GC_GREEDY_CHECK() \
380 ASSERT(!FLAG_gc_greedy || v8::internal::Heap::GarbageCollectionGreedyCheck())
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000381
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000382
383// Calls the FUNCTION_CALL function and retries it up to three times
384// to guarantee that any allocations performed during the call will
385// succeed if there's enough memory.
386
387// Warning: Do not use the identifiers __object__ or __scope__ in a
388// call to this macro.
389
390#define CALL_AND_RETRY(FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \
391 do { \
392 GC_GREEDY_CHECK(); \
393 Object* __object__ = FUNCTION_CALL; \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000394 if (!__object__->IsFailure()) RETURN_VALUE; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000395 if (__object__->IsOutOfMemoryFailure()) { \
396 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0"); \
397 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000398 if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000399 Heap::CollectGarbage(Failure::cast(__object__)->requested(), \
400 Failure::cast(__object__)->allocation_space()); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000401 __object__ = FUNCTION_CALL; \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000402 if (!__object__->IsFailure()) RETURN_VALUE; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000403 if (__object__->IsOutOfMemoryFailure()) { \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000404 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_1"); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000405 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000406 if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000407 Counters::gc_last_resort_from_handles.Increment(); \
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000408 Heap::CollectAllGarbage(false); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000409 { \
410 AlwaysAllocateScope __scope__; \
411 __object__ = FUNCTION_CALL; \
412 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000413 if (!__object__->IsFailure()) RETURN_VALUE; \
ager@chromium.org9085a012009-05-11 19:22:57 +0000414 if (__object__->IsOutOfMemoryFailure() || \
415 __object__->IsRetryAfterGC()) { \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000416 /* TODO(1181417): Fix this. */ \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000417 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_2"); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000418 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000419 RETURN_EMPTY; \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000420 } while (false)
421
422
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000423#define CALL_HEAP_FUNCTION(FUNCTION_CALL, TYPE) \
424 CALL_AND_RETRY(FUNCTION_CALL, \
425 return Handle<TYPE>(TYPE::cast(__object__)), \
426 return Handle<TYPE>())
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000427
428
429#define CALL_HEAP_FUNCTION_VOID(FUNCTION_CALL) \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000430 CALL_AND_RETRY(FUNCTION_CALL, return, return)
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000431
432
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000433#ifdef DEBUG
434
435inline bool Heap::allow_allocation(bool new_state) {
436 bool old = allocation_allowed_;
437 allocation_allowed_ = new_state;
438 return old;
439}
440
441#endif
442
443
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000444void ExternalStringTable::AddString(String* string) {
445 ASSERT(string->IsExternalString());
446 if (Heap::InNewSpace(string)) {
447 new_space_strings_.Add(string);
448 } else {
449 old_space_strings_.Add(string);
450 }
451}
452
453
454void ExternalStringTable::Iterate(ObjectVisitor* v) {
455 if (!new_space_strings_.is_empty()) {
456 Object** start = &new_space_strings_[0];
457 v->VisitPointers(start, start + new_space_strings_.length());
458 }
459 if (!old_space_strings_.is_empty()) {
460 Object** start = &old_space_strings_[0];
461 v->VisitPointers(start, start + old_space_strings_.length());
462 }
463}
464
465
466// Verify() is inline to avoid ifdef-s around its calls in release
467// mode.
468void ExternalStringTable::Verify() {
469#ifdef DEBUG
470 for (int i = 0; i < new_space_strings_.length(); ++i) {
471 ASSERT(Heap::InNewSpace(new_space_strings_[i]));
472 ASSERT(new_space_strings_[i] != Heap::raw_unchecked_null_value());
473 }
474 for (int i = 0; i < old_space_strings_.length(); ++i) {
475 ASSERT(!Heap::InNewSpace(old_space_strings_[i]));
476 ASSERT(old_space_strings_[i] != Heap::raw_unchecked_null_value());
477 }
478#endif
479}
480
481
482void ExternalStringTable::AddOldString(String* string) {
483 ASSERT(string->IsExternalString());
484 ASSERT(!Heap::InNewSpace(string));
485 old_space_strings_.Add(string);
486}
487
488
489void ExternalStringTable::ShrinkNewStrings(int position) {
490 new_space_strings_.Rewind(position);
491 Verify();
492}
493
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000494} } // namespace v8::internal
495
496#endif // V8_HEAP_INL_H_