blob: feda2d11144a4c3b4d397eba640dc86a18632b5a [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
121 // Dispose of the C++ object.
122 if (external_string_dispose_callback_ != NULL) {
123 external_string_dispose_callback_(*resource_addr);
124 } else {
125 delete *resource_addr;
126 }
127
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000128 // Clear the resource pointer in the string.
129 *resource_addr = NULL;
130}
131
132
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000133Object* Heap::AllocateRawMap() {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000134#ifdef DEBUG
135 Counters::objs_since_last_full.Increment();
136 Counters::objs_since_last_young.Increment();
137#endif
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000138 Object* result = map_space_->AllocateRaw(Map::kSize);
139 if (result->IsFailure()) old_gen_exhausted_ = true;
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000140#ifdef DEBUG
141 if (!result->IsFailure()) {
142 // Maps have their own alignment.
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000143 CHECK((reinterpret_cast<intptr_t>(result) & kMapAlignmentMask) ==
144 static_cast<intptr_t>(kHeapObjectTag));
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000145 }
146#endif
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000147 return result;
148}
149
150
151Object* Heap::AllocateRawCell() {
152#ifdef DEBUG
153 Counters::objs_since_last_full.Increment();
154 Counters::objs_since_last_young.Increment();
155#endif
156 Object* result = cell_space_->AllocateRaw(JSGlobalPropertyCell::kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000157 if (result->IsFailure()) old_gen_exhausted_ = true;
158 return result;
159}
160
161
162bool Heap::InNewSpace(Object* object) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000163 bool result = new_space_.Contains(object);
164 ASSERT(!result || // Either not in new space
165 gc_state_ != NOT_IN_GC || // ... or in the middle of GC
166 InToSpace(object)); // ... or in to-space (where we allocate).
167 return result;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000168}
169
170
171bool Heap::InFromSpace(Object* object) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000172 return new_space_.FromSpaceContains(object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000173}
174
175
176bool Heap::InToSpace(Object* object) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000177 return new_space_.ToSpaceContains(object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000178}
179
180
181bool Heap::ShouldBePromoted(Address old_address, int object_size) {
182 // An object should be promoted if:
183 // - the object has survived a scavenge operation or
184 // - to space is already 25% full.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000185 return old_address < new_space_.age_mark()
186 || (new_space_.Size() + object_size) >= (new_space_.Capacity() >> 2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187}
188
189
190void Heap::RecordWrite(Address address, int offset) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000191 if (new_space_.Contains(address)) return;
192 ASSERT(!new_space_.FromSpaceContains(address));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193 SLOW_ASSERT(Contains(address + offset));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000194 Page::FromAddress(address)->MarkRegionDirty(address + offset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195}
196
197
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000198void Heap::RecordWrites(Address address, int start, int len) {
199 if (new_space_.Contains(address)) return;
200 ASSERT(!new_space_.FromSpaceContains(address));
201 for (int offset = start;
202 offset < start + len * kPointerSize;
203 offset += kPointerSize) {
204 SLOW_ASSERT(Contains(address + offset));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000205 Page::FromAddress(address)->MarkRegionDirty(address + offset);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000206 }
207}
208
209
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000210OldSpace* Heap::TargetSpace(HeapObject* object) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000211 InstanceType type = object->map()->instance_type();
212 AllocationSpace space = TargetSpaceId(type);
213 return (space == OLD_POINTER_SPACE)
214 ? old_pointer_space_
215 : old_data_space_;
216}
217
218
219AllocationSpace Heap::TargetSpaceId(InstanceType type) {
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000220 // Heap numbers and sequential strings are promoted to old data space, all
221 // other object types are promoted to old pointer space. We do not use
kasper.lund7276f142008-07-30 08:49:36 +0000222 // object->IsHeapNumber() and object->IsSeqString() because we already
223 // know that object has the heap object tag.
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000224
225 // These objects are never allocated in new space.
226 ASSERT(type != MAP_TYPE);
227 ASSERT(type != CODE_TYPE);
228 ASSERT(type != ODDBALL_TYPE);
229 ASSERT(type != JS_GLOBAL_PROPERTY_CELL_TYPE);
230
231 if (type < FIRST_NONSTRING_TYPE) {
232 // There are three string representations: sequential strings, cons
233 // strings, and external strings. Only cons strings contain
234 // non-map-word pointers to heap objects.
235 return ((type & kStringRepresentationMask) == kConsStringTag)
236 ? OLD_POINTER_SPACE
237 : OLD_DATA_SPACE;
238 } else {
239 return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE;
240 }
kasper.lund7276f142008-07-30 08:49:36 +0000241}
242
243
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000244void Heap::CopyBlock(Address dst, Address src, int byte_size) {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000245 ASSERT(IsAligned(byte_size, kPointerSize));
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000246 CopyWords(reinterpret_cast<Object**>(dst),
247 reinterpret_cast<Object**>(src),
248 byte_size / kPointerSize);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000249}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000250
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000251
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000252void Heap::CopyBlockToOldSpaceAndUpdateRegionMarks(Address dst,
253 Address src,
254 int byte_size) {
255 ASSERT(IsAligned(byte_size, kPointerSize));
256
257 Page* page = Page::FromAddress(dst);
258 uint32_t marks = page->GetRegionMarks();
259
260 for (int remaining = byte_size / kPointerSize;
261 remaining > 0;
262 remaining--) {
263 Memory::Object_at(dst) = Memory::Object_at(src);
264
265 if (Heap::InNewSpace(Memory::Object_at(dst))) {
266 marks |= page->GetRegionMaskForAddress(dst);
267 }
268
269 dst += kPointerSize;
270 src += kPointerSize;
271 }
272
273 page->SetRegionMarks(marks);
274}
275
276
277void Heap::MoveBlock(Address dst, Address src, int byte_size) {
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000278 ASSERT(IsAligned(byte_size, kPointerSize));
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000279
280 int size_in_words = byte_size / kPointerSize;
281
282 if ((dst < src) || (dst >= (src + size_in_words))) {
283 ASSERT((dst >= (src + size_in_words)) ||
284 ((OffsetFrom(reinterpret_cast<Address>(src)) -
285 OffsetFrom(reinterpret_cast<Address>(dst))) >= kPointerSize));
286
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000287 Object** src_slot = reinterpret_cast<Object**>(src);
288 Object** dst_slot = reinterpret_cast<Object**>(dst);
289 Object** end_slot = src_slot + size_in_words;
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000290
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000291 while (src_slot != end_slot) {
292 *dst_slot++ = *src_slot++;
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000293 }
294 } else {
295 memmove(dst, src, byte_size);
296 }
297}
298
299
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000300void Heap::MoveBlockToOldSpaceAndUpdateRegionMarks(Address dst,
301 Address src,
302 int byte_size) {
303 ASSERT(IsAligned(byte_size, kPointerSize));
304 ASSERT((dst >= (src + byte_size)) ||
305 ((OffsetFrom(src) - OffsetFrom(dst)) >= kPointerSize));
306
307 CopyBlockToOldSpaceAndUpdateRegionMarks(dst, src, byte_size);
308}
309
310
kasperl@chromium.orgb3284ad2009-05-18 06:12:45 +0000311void Heap::ScavengeObject(HeapObject** p, HeapObject* object) {
312 ASSERT(InFromSpace(object));
313
314 // We use the first word (where the map pointer usually is) of a heap
315 // object to record the forwarding pointer. A forwarding pointer can
316 // point to an old space, the code space, or the to space of the new
317 // generation.
318 MapWord first_word = object->map_word();
319
320 // If the first word is a forwarding address, the object has already been
321 // copied.
322 if (first_word.IsForwardingAddress()) {
323 *p = first_word.ToForwardingAddress();
324 return;
325 }
326
327 // Call the slow part of scavenge object.
328 return ScavengeObjectSlow(p, object);
329}
330
331
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000332Object* Heap::PrepareForCompare(String* str) {
333 // Always flatten small strings and force flattening of long strings
334 // after we have accumulated a certain amount we failed to flatten.
335 static const int kMaxAlwaysFlattenLength = 32;
336 static const int kFlattenLongThreshold = 16*KB;
337
338 const int length = str->length();
339 Object* obj = str->TryFlatten();
340 if (length <= kMaxAlwaysFlattenLength ||
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000341 unflattened_strings_length_ >= kFlattenLongThreshold) {
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000342 return obj;
343 }
344 if (obj->IsFailure()) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000345 unflattened_strings_length_ += length;
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000346 }
347 return str;
348}
349
350
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000351int Heap::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) {
352 ASSERT(HasBeenSetup());
353 int amount = amount_of_external_allocated_memory_ + change_in_bytes;
354 if (change_in_bytes >= 0) {
355 // Avoid overflow.
356 if (amount > amount_of_external_allocated_memory_) {
357 amount_of_external_allocated_memory_ = amount;
358 }
359 int amount_since_last_global_gc =
360 amount_of_external_allocated_memory_ -
361 amount_of_external_allocated_memory_at_last_global_gc_;
362 if (amount_since_last_global_gc > external_allocation_limit_) {
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000363 CollectAllGarbage(false);
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000364 }
365 } else {
366 // Avoid underflow.
367 if (amount >= 0) {
368 amount_of_external_allocated_memory_ = amount;
369 }
370 }
371 ASSERT(amount_of_external_allocated_memory_ >= 0);
372 return amount_of_external_allocated_memory_;
373}
374
375
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000376void Heap::SetLastScriptId(Object* last_script_id) {
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000377 roots_[kLastScriptIdRootIndex] = last_script_id;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000378}
379
380
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000381#define GC_GREEDY_CHECK() \
382 ASSERT(!FLAG_gc_greedy || v8::internal::Heap::GarbageCollectionGreedyCheck())
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000384
385// Calls the FUNCTION_CALL function and retries it up to three times
386// to guarantee that any allocations performed during the call will
387// succeed if there's enough memory.
388
389// Warning: Do not use the identifiers __object__ or __scope__ in a
390// call to this macro.
391
392#define CALL_AND_RETRY(FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \
393 do { \
394 GC_GREEDY_CHECK(); \
395 Object* __object__ = FUNCTION_CALL; \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000396 if (!__object__->IsFailure()) RETURN_VALUE; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000397 if (__object__->IsOutOfMemoryFailure()) { \
398 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0"); \
399 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000400 if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000401 Heap::CollectGarbage(Failure::cast(__object__)->requested(), \
402 Failure::cast(__object__)->allocation_space()); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000403 __object__ = FUNCTION_CALL; \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000404 if (!__object__->IsFailure()) RETURN_VALUE; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000405 if (__object__->IsOutOfMemoryFailure()) { \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000406 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_1"); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000407 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000408 if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000409 Counters::gc_last_resort_from_handles.Increment(); \
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000410 Heap::CollectAllGarbage(false); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000411 { \
412 AlwaysAllocateScope __scope__; \
413 __object__ = FUNCTION_CALL; \
414 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000415 if (!__object__->IsFailure()) RETURN_VALUE; \
ager@chromium.org9085a012009-05-11 19:22:57 +0000416 if (__object__->IsOutOfMemoryFailure() || \
417 __object__->IsRetryAfterGC()) { \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000418 /* TODO(1181417): Fix this. */ \
kasperl@chromium.org58870952008-10-30 14:34:19 +0000419 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_2"); \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000420 } \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000421 RETURN_EMPTY; \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000422 } while (false)
423
424
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000425#define CALL_HEAP_FUNCTION(FUNCTION_CALL, TYPE) \
426 CALL_AND_RETRY(FUNCTION_CALL, \
427 return Handle<TYPE>(TYPE::cast(__object__)), \
428 return Handle<TYPE>())
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000429
430
431#define CALL_HEAP_FUNCTION_VOID(FUNCTION_CALL) \
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000432 CALL_AND_RETRY(FUNCTION_CALL, return, return)
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000433
434
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000435#ifdef DEBUG
436
437inline bool Heap::allow_allocation(bool new_state) {
438 bool old = allocation_allowed_;
439 allocation_allowed_ = new_state;
440 return old;
441}
442
443#endif
444
445
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000446void ExternalStringTable::AddString(String* string) {
447 ASSERT(string->IsExternalString());
448 if (Heap::InNewSpace(string)) {
449 new_space_strings_.Add(string);
450 } else {
451 old_space_strings_.Add(string);
452 }
453}
454
455
456void ExternalStringTable::Iterate(ObjectVisitor* v) {
457 if (!new_space_strings_.is_empty()) {
458 Object** start = &new_space_strings_[0];
459 v->VisitPointers(start, start + new_space_strings_.length());
460 }
461 if (!old_space_strings_.is_empty()) {
462 Object** start = &old_space_strings_[0];
463 v->VisitPointers(start, start + old_space_strings_.length());
464 }
465}
466
467
468// Verify() is inline to avoid ifdef-s around its calls in release
469// mode.
470void ExternalStringTable::Verify() {
471#ifdef DEBUG
472 for (int i = 0; i < new_space_strings_.length(); ++i) {
473 ASSERT(Heap::InNewSpace(new_space_strings_[i]));
474 ASSERT(new_space_strings_[i] != Heap::raw_unchecked_null_value());
475 }
476 for (int i = 0; i < old_space_strings_.length(); ++i) {
477 ASSERT(!Heap::InNewSpace(old_space_strings_[i]));
478 ASSERT(old_space_strings_[i] != Heap::raw_unchecked_null_value());
479 }
480#endif
481}
482
483
484void ExternalStringTable::AddOldString(String* string) {
485 ASSERT(string->IsExternalString());
486 ASSERT(!Heap::InNewSpace(string));
487 old_space_strings_.Add(string);
488}
489
490
491void ExternalStringTable::ShrinkNewStrings(int position) {
492 new_space_strings_.Rewind(position);
493 Verify();
494}
495
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000496} } // namespace v8::internal
497
498#endif // V8_HEAP_INL_H_