blob: 179f9af10c9d1b606cb3d746fb650d847da8475e [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_H_
29#define V8_HEAP_H_
30
kasperl@chromium.org71affb52009-05-26 05:44:31 +000031#include "zone-inl.h"
32
33namespace v8 {
34namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000035
36// Defines all the roots in Heap.
kasperl@chromium.org68ac0092009-07-09 06:00:35 +000037#define STRONG_ROOT_LIST(V) \
38 V(Map, meta_map, MetaMap) \
39 V(Map, heap_number_map, HeapNumberMap) \
40 V(Map, short_string_map, ShortStringMap) \
41 V(Map, medium_string_map, MediumStringMap) \
42 V(Map, long_string_map, LongStringMap) \
43 V(Map, short_ascii_string_map, ShortAsciiStringMap) \
44 V(Map, medium_ascii_string_map, MediumAsciiStringMap) \
45 V(Map, long_ascii_string_map, LongAsciiStringMap) \
46 V(Map, short_symbol_map, ShortSymbolMap) \
47 V(Map, medium_symbol_map, MediumSymbolMap) \
48 V(Map, long_symbol_map, LongSymbolMap) \
49 V(Map, short_ascii_symbol_map, ShortAsciiSymbolMap) \
50 V(Map, medium_ascii_symbol_map, MediumAsciiSymbolMap) \
51 V(Map, long_ascii_symbol_map, LongAsciiSymbolMap) \
52 V(Map, short_cons_symbol_map, ShortConsSymbolMap) \
53 V(Map, medium_cons_symbol_map, MediumConsSymbolMap) \
54 V(Map, long_cons_symbol_map, LongConsSymbolMap) \
55 V(Map, short_cons_ascii_symbol_map, ShortConsAsciiSymbolMap) \
56 V(Map, medium_cons_ascii_symbol_map, MediumConsAsciiSymbolMap) \
57 V(Map, long_cons_ascii_symbol_map, LongConsAsciiSymbolMap) \
58 V(Map, short_sliced_symbol_map, ShortSlicedSymbolMap) \
59 V(Map, medium_sliced_symbol_map, MediumSlicedSymbolMap) \
60 V(Map, long_sliced_symbol_map, LongSlicedSymbolMap) \
61 V(Map, short_sliced_ascii_symbol_map, ShortSlicedAsciiSymbolMap) \
62 V(Map, medium_sliced_ascii_symbol_map, MediumSlicedAsciiSymbolMap) \
63 V(Map, long_sliced_ascii_symbol_map, LongSlicedAsciiSymbolMap) \
64 V(Map, short_external_symbol_map, ShortExternalSymbolMap) \
65 V(Map, medium_external_symbol_map, MediumExternalSymbolMap) \
66 V(Map, long_external_symbol_map, LongExternalSymbolMap) \
67 V(Map, short_external_ascii_symbol_map, ShortExternalAsciiSymbolMap) \
68 V(Map, medium_external_ascii_symbol_map, MediumExternalAsciiSymbolMap) \
69 V(Map, long_external_ascii_symbol_map, LongExternalAsciiSymbolMap) \
70 V(Map, short_cons_string_map, ShortConsStringMap) \
71 V(Map, medium_cons_string_map, MediumConsStringMap) \
72 V(Map, long_cons_string_map, LongConsStringMap) \
73 V(Map, short_cons_ascii_string_map, ShortConsAsciiStringMap) \
74 V(Map, medium_cons_ascii_string_map, MediumConsAsciiStringMap) \
75 V(Map, long_cons_ascii_string_map, LongConsAsciiStringMap) \
76 V(Map, short_sliced_string_map, ShortSlicedStringMap) \
77 V(Map, medium_sliced_string_map, MediumSlicedStringMap) \
78 V(Map, long_sliced_string_map, LongSlicedStringMap) \
79 V(Map, short_sliced_ascii_string_map, ShortSlicedAsciiStringMap) \
80 V(Map, medium_sliced_ascii_string_map, MediumSlicedAsciiStringMap) \
81 V(Map, long_sliced_ascii_string_map, LongSlicedAsciiStringMap) \
82 V(Map, short_external_string_map, ShortExternalStringMap) \
83 V(Map, medium_external_string_map, MediumExternalStringMap) \
84 V(Map, long_external_string_map, LongExternalStringMap) \
85 V(Map, short_external_ascii_string_map, ShortExternalAsciiStringMap) \
86 V(Map, medium_external_ascii_string_map, MediumExternalAsciiStringMap) \
87 V(Map, long_external_ascii_string_map, LongExternalAsciiStringMap) \
88 V(Map, undetectable_short_string_map, UndetectableShortStringMap) \
89 V(Map, undetectable_medium_string_map, UndetectableMediumStringMap) \
90 V(Map, undetectable_long_string_map, UndetectableLongStringMap) \
91 V(Map, undetectable_short_ascii_string_map, UndetectableShortAsciiStringMap) \
92 V(Map, \
93 undetectable_medium_ascii_string_map, \
94 UndetectableMediumAsciiStringMap) \
95 V(Map, undetectable_long_ascii_string_map, UndetectableLongAsciiStringMap) \
96 V(Map, byte_array_map, ByteArrayMap) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000097 V(Map, pixel_array_map, PixelArrayMap) \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +000098 V(Map, fixed_array_map, FixedArrayMap) \
99 V(Map, hash_table_map, HashTableMap) \
100 V(Map, context_map, ContextMap) \
101 V(Map, catch_context_map, CatchContextMap) \
102 V(Map, global_context_map, GlobalContextMap) \
103 V(Map, code_map, CodeMap) \
104 V(Map, oddball_map, OddballMap) \
105 V(Map, global_property_cell_map, GlobalPropertyCellMap) \
106 V(Map, boilerplate_function_map, BoilerplateFunctionMap) \
107 V(Map, shared_function_info_map, SharedFunctionInfoMap) \
108 V(Map, proxy_map, ProxyMap) \
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000109 V(Map, one_pointer_filler_map, OnePointerFillerMap) \
110 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000111 V(Object, nan_value, NanValue) \
112 V(Object, undefined_value, UndefinedValue) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000113 V(Object, no_interceptor_result_sentinel, NoInterceptorResultSentinel) \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000114 V(Object, minus_zero_value, MinusZeroValue) \
115 V(Object, null_value, NullValue) \
116 V(Object, true_value, TrueValue) \
117 V(Object, false_value, FalseValue) \
118 V(String, empty_string, EmptyString) \
119 V(FixedArray, empty_fixed_array, EmptyFixedArray) \
120 V(DescriptorArray, empty_descriptor_array, EmptyDescriptorArray) \
121 V(Object, the_hole_value, TheHoleValue) \
122 V(Map, neander_map, NeanderMap) \
123 V(JSObject, message_listeners, MessageListeners) \
124 V(Proxy, prototype_accessors, PrototypeAccessors) \
125 V(NumberDictionary, code_stubs, CodeStubs) \
126 V(NumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \
127 V(Code, js_entry_code, JsEntryCode) \
128 V(Code, js_construct_entry_code, JsConstructEntryCode) \
129 V(Code, c_entry_code, CEntryCode) \
130 V(Code, c_entry_debug_break_code, CEntryDebugBreakCode) \
131 V(FixedArray, number_string_cache, NumberStringCache) \
132 V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \
133 V(FixedArray, natives_source_cache, NativesSourceCache) \
134 V(Object, last_script_id, LastScriptId)
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000135
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000136
137#define ROOT_LIST(V) \
138 STRONG_ROOT_LIST(V) \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000139 V(SymbolTable, symbol_table, SymbolTable)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000140
141#define SYMBOL_LIST(V) \
142 V(Array_symbol, "Array") \
143 V(Object_symbol, "Object") \
144 V(Proto_symbol, "__proto__") \
145 V(StringImpl_symbol, "StringImpl") \
146 V(arguments_symbol, "arguments") \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000147 V(Arguments_symbol, "Arguments") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000148 V(arguments_shadow_symbol, ".arguments") \
149 V(call_symbol, "call") \
150 V(apply_symbol, "apply") \
151 V(caller_symbol, "caller") \
152 V(boolean_symbol, "boolean") \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000153 V(Boolean_symbol, "Boolean") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154 V(callee_symbol, "callee") \
155 V(constructor_symbol, "constructor") \
156 V(code_symbol, ".code") \
157 V(result_symbol, ".result") \
158 V(catch_var_symbol, ".catch-var") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000159 V(empty_symbol, "") \
160 V(eval_symbol, "eval") \
161 V(function_symbol, "function") \
162 V(length_symbol, "length") \
163 V(name_symbol, "name") \
164 V(number_symbol, "number") \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000165 V(Number_symbol, "Number") \
166 V(RegExp_symbol, "RegExp") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000167 V(object_symbol, "object") \
168 V(prototype_symbol, "prototype") \
169 V(string_symbol, "string") \
ager@chromium.org7c537e22008-10-16 08:43:32 +0000170 V(String_symbol, "String") \
171 V(Date_symbol, "Date") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000172 V(this_symbol, "this") \
173 V(to_string_symbol, "toString") \
174 V(char_at_symbol, "CharAt") \
175 V(undefined_symbol, "undefined") \
176 V(value_of_symbol, "valueOf") \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000177 V(InitializeVarGlobal_symbol, "InitializeVarGlobal") \
178 V(InitializeConstGlobal_symbol, "InitializeConstGlobal") \
179 V(stack_overflow_symbol, "kStackOverflowBoilerplate") \
180 V(illegal_access_symbol, "illegal access") \
181 V(out_of_memory_symbol, "out-of-memory") \
182 V(illegal_execution_state_symbol, "illegal execution state") \
183 V(get_symbol, "get") \
184 V(set_symbol, "set") \
185 V(function_class_symbol, "Function") \
186 V(illegal_argument_symbol, "illegal argument") \
187 V(MakeReferenceError_symbol, "MakeReferenceError") \
188 V(MakeSyntaxError_symbol, "MakeSyntaxError") \
189 V(MakeTypeError_symbol, "MakeTypeError") \
190 V(invalid_lhs_in_assignment_symbol, "invalid_lhs_in_assignment") \
191 V(invalid_lhs_in_for_in_symbol, "invalid_lhs_in_for_in") \
192 V(invalid_lhs_in_postfix_op_symbol, "invalid_lhs_in_postfix_op") \
193 V(invalid_lhs_in_prefix_op_symbol, "invalid_lhs_in_prefix_op") \
194 V(illegal_return_symbol, "illegal_return") \
195 V(illegal_break_symbol, "illegal_break") \
196 V(illegal_continue_symbol, "illegal_continue") \
197 V(unknown_label_symbol, "unknown_label") \
198 V(redeclaration_symbol, "redeclaration") \
199 V(failure_symbol, "<failure>") \
200 V(space_symbol, " ") \
201 V(exec_symbol, "exec") \
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000202 V(zero_symbol, "0") \
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000203 V(global_eval_symbol, "GlobalEval") \
204 V(identity_hash_symbol, "v8::IdentityHash")
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000205
206
kasper.lund7276f142008-07-30 08:49:36 +0000207// Forward declaration of the GCTracer class.
208class GCTracer;
209
210
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000211// The all static Heap captures the interface to the global object heap.
212// All JavaScript contexts by this process share the same object heap.
213
214class Heap : public AllStatic {
215 public:
216 // Configure heap size before setup. Return false if the heap has been
217 // setup already.
218 static bool ConfigureHeap(int semispace_size, int old_gen_size);
kasper.lund7276f142008-07-30 08:49:36 +0000219 static bool ConfigureHeapDefault();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000220
221 // Initializes the global object heap. If create_heap_objects is true,
222 // also creates the basic non-mutable objects.
223 // Returns whether it succeeded.
224 static bool Setup(bool create_heap_objects);
225
226 // Destroys all memory allocated by the heap.
227 static void TearDown();
228
229 // Returns whether Setup has been called.
230 static bool HasBeenSetup();
231
232 // Returns the maximum heap capacity.
233 static int MaxCapacity() {
234 return young_generation_size_ + old_generation_size_;
235 }
236 static int SemiSpaceSize() { return semispace_size_; }
237 static int InitialSemiSpaceSize() { return initial_semispace_size_; }
238 static int YoungGenerationSize() { return young_generation_size_; }
239 static int OldGenerationSize() { return old_generation_size_; }
240
241 // Returns the capacity of the heap in bytes w/o growing. Heap grows when
242 // more spaces are needed until it reaches the limit.
243 static int Capacity();
244
245 // Returns the available bytes in space w/o growing.
246 // Heap doesn't guarantee that it can allocate an object that requires
247 // all available bytes. Check MaxHeapObjectSize() instead.
248 static int Available();
249
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000250 // Returns the maximum object size in paged space.
251 static inline int MaxObjectSizeInPagedSpace();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252
253 // Returns of size of all objects residing in the heap.
254 static int SizeOfObjects();
255
256 // Return the starting address and a mask for the new space. And-masking an
257 // address with the mask will result in the start address of the new space
258 // for all addresses in either semispace.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000259 static Address NewSpaceStart() { return new_space_.start(); }
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000260 static uintptr_t NewSpaceMask() { return new_space_.mask(); }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000261 static Address NewSpaceTop() { return new_space_.top(); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000262
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000263 static NewSpace* new_space() { return &new_space_; }
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000264 static OldSpace* old_pointer_space() { return old_pointer_space_; }
265 static OldSpace* old_data_space() { return old_data_space_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000266 static OldSpace* code_space() { return code_space_; }
267 static MapSpace* map_space() { return map_space_; }
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000268 static CellSpace* cell_space() { return cell_space_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000269 static LargeObjectSpace* lo_space() { return lo_space_; }
270
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000271 static bool always_allocate() { return always_allocate_scope_depth_ != 0; }
272 static Address always_allocate_scope_depth_address() {
273 return reinterpret_cast<Address>(&always_allocate_scope_depth_);
274 }
275
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276 static Address* NewSpaceAllocationTopAddress() {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000277 return new_space_.allocation_top_address();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000278 }
279 static Address* NewSpaceAllocationLimitAddress() {
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000280 return new_space_.allocation_limit_address();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000281 }
282
ager@chromium.orgadd848f2009-08-13 12:44:13 +0000283 // Uncommit unused semi space.
284 static bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); }
285
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000286#ifdef ENABLE_HEAP_PROTECTION
287 // Protect/unprotect the heap by marking all spaces read-only/writable.
288 static void Protect();
289 static void Unprotect();
290#endif
291
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000292 // Allocates and initializes a new JavaScript object based on a
293 // constructor.
294 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
295 // failed.
296 // Please note this does not perform a garbage collection.
297 static Object* AllocateJSObject(JSFunction* constructor,
298 PretenureFlag pretenure = NOT_TENURED);
299
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000300 // Allocates and initializes a new global object based on a constructor.
301 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
302 // failed.
303 // Please note this does not perform a garbage collection.
304 static Object* AllocateGlobalObject(JSFunction* constructor);
305
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000306 // Returns a deep copy of the JavaScript object.
307 // Properties and elements are copied too.
308 // Returns failure if allocation failed.
309 static Object* CopyJSObject(JSObject* source);
310
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000311 // Allocates the function prototype.
312 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
313 // failed.
314 // Please note this does not perform a garbage collection.
315 static Object* AllocateFunctionPrototype(JSFunction* function);
316
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000317 // Reinitialize an JSGlobalProxy based on a constructor. The object
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000318 // must have the same size as objects allocated using the
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000319 // constructor. The object is reinitialized and behaves as an
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000320 // object that has been freshly allocated using the constructor.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000321 static Object* ReinitializeJSGlobalProxy(JSFunction* constructor,
322 JSGlobalProxy* global);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000323
324 // Allocates and initializes a new JavaScript object based on a map.
325 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
326 // failed.
327 // Please note this does not perform a garbage collection.
328 static Object* AllocateJSObjectFromMap(Map* map,
329 PretenureFlag pretenure = NOT_TENURED);
330
331 // Allocates a heap object based on the map.
332 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
333 // failed.
334 // Please note this function does not perform a garbage collection.
335 static Object* Allocate(Map* map, AllocationSpace space);
336
337 // Allocates a JS Map in the heap.
338 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
339 // failed.
340 // Please note this function does not perform a garbage collection.
341 static Object* AllocateMap(InstanceType instance_type, int instance_size);
342
343 // Allocates a partial map for bootstrapping.
344 static Object* AllocatePartialMap(InstanceType instance_type,
345 int instance_size);
346
347 // Allocate a map for the specified function
348 static Object* AllocateInitialMap(JSFunction* fun);
349
350 // Allocates and fully initializes a String. There are two String
351 // encodings: ASCII and two byte. One should choose between the three string
352 // allocation functions based on the encoding of the string buffer used to
353 // initialized the string.
354 // - ...FromAscii initializes the string from a buffer that is ASCII
355 // encoded (it does not check that the buffer is ASCII encoded) and the
356 // result will be ASCII encoded.
357 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
358 // encoded. If the characters are all single-byte characters, the
359 // result will be ASCII encoded, otherwise it will converted to two
360 // byte.
361 // - ...FromTwoByte initializes the string from a buffer that is two-byte
362 // encoded. If the characters are all single-byte characters, the
363 // result will be converted to ASCII, otherwise it will be left as
364 // two-byte.
365 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
366 // failed.
367 // Please note this does not perform a garbage collection.
368 static Object* AllocateStringFromAscii(
369 Vector<const char> str,
370 PretenureFlag pretenure = NOT_TENURED);
371 static Object* AllocateStringFromUtf8(
372 Vector<const char> str,
373 PretenureFlag pretenure = NOT_TENURED);
374 static Object* AllocateStringFromTwoByte(
375 Vector<const uc16> str,
376 PretenureFlag pretenure = NOT_TENURED);
377
378 // Allocates a symbol in old space based on the character stream.
379 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
380 // failed.
381 // Please note this function does not perform a garbage collection.
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000382 static inline Object* AllocateSymbol(Vector<const char> str,
383 int chars,
384 uint32_t length_field);
385
386 static Object* AllocateInternalSymbol(unibrow::CharacterStream* buffer,
387 int chars,
388 uint32_t length_field);
389
390 static Object* AllocateExternalSymbol(Vector<const char> str,
391 int chars);
392
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000393
394 // Allocates and partially initializes a String. There are two String
395 // encodings: ASCII and two byte. These functions allocate a string of the
396 // given length and set its map and length fields. The characters of the
397 // string are uninitialized.
398 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
399 // failed.
400 // Please note this does not perform a garbage collection.
401 static Object* AllocateRawAsciiString(
402 int length,
403 PretenureFlag pretenure = NOT_TENURED);
404 static Object* AllocateRawTwoByteString(
405 int length,
406 PretenureFlag pretenure = NOT_TENURED);
407
408 // Computes a single character string where the character has code.
409 // A cache is used for ascii codes.
410 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
411 // failed. Please note this does not perform a garbage collection.
412 static Object* LookupSingleCharacterStringFromCode(uint16_t code);
413
414 // Allocate a byte array of the specified length
415 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
416 // failed.
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000417 // Please note this does not perform a garbage collection.
418 static Object* AllocateByteArray(int length, PretenureFlag pretenure);
419
420 // Allocate a non-tenured byte array of the specified length
421 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
422 // failed.
423 // Please note this does not perform a garbage collection.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000424 static Object* AllocateByteArray(int length);
425
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000426 // Allocate a pixel array of the specified length
427 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
428 // failed.
429 // Please note this does not perform a garbage collection.
430 static Object* AllocatePixelArray(int length,
431 uint8_t* external_pointer,
432 PretenureFlag pretenure);
433
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000434 // Allocate a tenured JS global property cell.
435 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
436 // failed.
437 // Please note this does not perform a garbage collection.
438 static Object* AllocateJSGlobalPropertyCell(Object* value);
439
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000440 // Allocates a fixed array initialized with undefined values
441 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
442 // failed.
443 // Please note this does not perform a garbage collection.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000444 static Object* AllocateFixedArray(int length, PretenureFlag pretenure);
445 // Allocate uninitialized, non-tenured fixed array with length elements.
446 static Object* AllocateFixedArray(int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000447
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000448 // Make a copy of src and return it. Returns
449 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
450 static Object* CopyFixedArray(FixedArray* src);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000451
452 // Allocates a fixed array initialized with the hole values.
453 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
454 // failed.
455 // Please note this does not perform a garbage collection.
456 static Object* AllocateFixedArrayWithHoles(int length);
457
458 // AllocateHashTable is identical to AllocateFixedArray except
459 // that the resulting object has hash_table_map as map.
460 static Object* AllocateHashTable(int length);
461
462 // Allocate a global (but otherwise uninitialized) context.
463 static Object* AllocateGlobalContext();
464
465 // Allocate a function context.
466 static Object* AllocateFunctionContext(int length, JSFunction* closure);
467
468 // Allocate a 'with' context.
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000469 static Object* AllocateWithContext(Context* previous,
470 JSObject* extension,
471 bool is_catch_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000472
473 // Allocates a new utility object in the old generation.
474 static Object* AllocateStruct(InstanceType type);
475
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000476 // Allocates a function initialized with a shared part.
477 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
478 // failed.
479 // Please note this does not perform a garbage collection.
480 static Object* AllocateFunction(Map* function_map,
481 SharedFunctionInfo* shared,
482 Object* prototype);
483
484 // Indicies for direct access into argument objects.
485 static const int arguments_callee_index = 0;
486 static const int arguments_length_index = 1;
487
488 // Allocates an arguments object - optionally with an elements array.
489 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
490 // failed.
491 // Please note this does not perform a garbage collection.
492 static Object* AllocateArgumentsObject(Object* callee, int length);
493
494 // Converts a double into either a Smi or a HeapNumber object.
495 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
496 // failed.
497 // Please note this does not perform a garbage collection.
498 static Object* NewNumberFromDouble(double value,
499 PretenureFlag pretenure = NOT_TENURED);
500
501 // Same as NewNumberFromDouble, but may return a preallocated/immutable
502 // number object (e.g., minus_zero_value_, nan_value_)
503 static Object* NumberFromDouble(double value,
504 PretenureFlag pretenure = NOT_TENURED);
505
506 // Allocated a HeapNumber from value.
507 static Object* AllocateHeapNumber(double value, PretenureFlag pretenure);
508 static Object* AllocateHeapNumber(double value); // pretenure = NOT_TENURED
509
510 // Converts an int into either a Smi or a HeapNumber object.
511 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
512 // failed.
513 // Please note this does not perform a garbage collection.
514 static inline Object* NumberFromInt32(int32_t value);
515
516 // Converts an int into either a Smi or a HeapNumber object.
517 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
518 // failed.
519 // Please note this does not perform a garbage collection.
520 static inline Object* NumberFromUint32(uint32_t value);
521
522 // Allocates a new proxy object.
523 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
524 // failed.
525 // Please note this does not perform a garbage collection.
526 static Object* AllocateProxy(Address proxy,
527 PretenureFlag pretenure = NOT_TENURED);
528
529 // Allocates a new SharedFunctionInfo object.
530 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
531 // failed.
532 // Please note this does not perform a garbage collection.
533 static Object* AllocateSharedFunctionInfo(Object* name);
534
535 // Allocates a new cons string object.
536 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
537 // failed.
538 // Please note this does not perform a garbage collection.
ager@chromium.org3e875802009-06-29 08:26:34 +0000539 static Object* AllocateConsString(String* first, String* second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000540
541 // Allocates a new sliced string object which is a slice of an underlying
542 // string buffer stretching from the index start (inclusive) to the index
543 // end (exclusive).
544 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
545 // failed.
546 // Please note this does not perform a garbage collection.
ager@chromium.org870a0b62008-11-04 11:43:05 +0000547 static Object* AllocateSlicedString(String* buffer,
ager@chromium.org870a0b62008-11-04 11:43:05 +0000548 int start,
549 int end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000550
551 // Allocates a new sub string object which is a substring of an underlying
552 // string buffer stretching from the index start (inclusive) to the index
553 // end (exclusive).
554 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
555 // failed.
556 // Please note this does not perform a garbage collection.
ager@chromium.org870a0b62008-11-04 11:43:05 +0000557 static Object* AllocateSubString(String* buffer,
ager@chromium.org870a0b62008-11-04 11:43:05 +0000558 int start,
559 int end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000560
561 // Allocate a new external string object, which is backed by a string
562 // resource that resides outside the V8 heap.
563 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
564 // failed.
565 // Please note this does not perform a garbage collection.
566 static Object* AllocateExternalStringFromAscii(
567 ExternalAsciiString::Resource* resource);
568 static Object* AllocateExternalStringFromTwoByte(
569 ExternalTwoByteString::Resource* resource);
570
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000571 // Allocates an uninitialized object. The memory is non-executable if the
572 // hardware and OS allow.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000573 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
574 // failed.
575 // Please note this function does not perform a garbage collection.
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000576 static inline Object* AllocateRaw(int size_in_bytes,
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000577 AllocationSpace space,
578 AllocationSpace retry_space);
kasper.lund7276f142008-07-30 08:49:36 +0000579
ager@chromium.org6f10e412009-02-13 10:11:16 +0000580 // Initialize a filler object to keep the ability to iterate over the heap
581 // when shortening objects.
582 static void CreateFillerObjectAt(Address addr, int size);
583
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000584 // Makes a new native code object
585 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000586 // failed. On success, the pointer to the Code object is stored in the
587 // self_reference. This allows generated code to reference its own Code
588 // object by containing this pointer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000589 // Please note this function does not perform a garbage collection.
590 static Object* CreateCode(const CodeDesc& desc,
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000591 ZoneScopeInfo* sinfo,
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000592 Code::Flags flags,
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000593 Handle<Object> self_reference);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000594
595 static Object* CopyCode(Code* code);
596 // Finds the symbol for string in the symbol table.
597 // If not found, a new symbol is added to the table and returned.
598 // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation
599 // failed.
600 // Please note this function does not perform a garbage collection.
601 static Object* LookupSymbol(Vector<const char> str);
602 static Object* LookupAsciiSymbol(const char* str) {
603 return LookupSymbol(CStrVector(str));
604 }
605 static Object* LookupSymbol(String* str);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000606 static bool LookupSymbolIfExists(String* str, String** symbol);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000607
608 // Compute the matching symbol map for a string if possible.
609 // NULL is returned if string is in new space or not flattened.
610 static Map* SymbolMapForString(String* str);
611
612 // Converts the given boolean condition to JavaScript boolean value.
613 static Object* ToBoolean(bool condition) {
614 return condition ? true_value() : false_value();
615 }
616
617 // Code that should be run before and after each GC. Includes some
618 // reporting/verification activities when compiled with DEBUG set.
619 static void GarbageCollectionPrologue();
620 static void GarbageCollectionEpilogue();
621
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000622 // Code that should be executed after the garbage collection proper.
623 static void PostGarbageCollectionProcessing();
624
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000625 // Performs garbage collection operation.
626 // Returns whether required_space bytes are available after the collection.
627 static bool CollectGarbage(int required_space, AllocationSpace space);
628
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000629 // Performs a full garbage collection.
630 static void CollectAllGarbage();
631
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000632 // Performs a full garbage collection if a context has been disposed
633 // since the last time the check was performed.
634 static void CollectAllGarbageIfContextDisposed();
635
636 // Notify the heap that a context has been disposed.
637 static void NotifyContextDisposed();
638
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000639 // Utility to invoke the scavenger. This is needed in test code to
640 // ensure correct callback for weak global handles.
kasper.lund7276f142008-07-30 08:49:36 +0000641 static void PerformScavenge();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000642
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000643#ifdef DEBUG
644 // Utility used with flag gc-greedy.
645 static bool GarbageCollectionGreedyCheck();
646#endif
647
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000648 static void SetGlobalGCPrologueCallback(GCCallback callback) {
649 global_gc_prologue_callback_ = callback;
650 }
651 static void SetGlobalGCEpilogueCallback(GCCallback callback) {
652 global_gc_epilogue_callback_ = callback;
653 }
654
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000655 // Heap root getters. We have versions with and without type::cast() here.
656 // You can't use type::cast during GC because the assert fails.
657#define ROOT_ACCESSOR(type, name, camel_name) \
658 static inline type* name() { \
659 return type::cast(roots_[k##camel_name##RootIndex]); \
660 } \
661 static inline type* raw_unchecked_##name() { \
662 return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \
663 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000664 ROOT_LIST(ROOT_ACCESSOR)
665#undef ROOT_ACCESSOR
666
667// Utility type maps
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000668#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
669 static inline Map* name##_map() { \
670 return Map::cast(roots_[k##Name##MapRootIndex]); \
671 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000672 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
673#undef STRUCT_MAP_ACCESSOR
674
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000675#define SYMBOL_ACCESSOR(name, str) static inline String* name() { \
676 return String::cast(roots_[k##name##RootIndex]); \
677 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000678 SYMBOL_LIST(SYMBOL_ACCESSOR)
679#undef SYMBOL_ACCESSOR
680
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000681 // The hidden_symbol is special because it is the empty string, but does
682 // not match the empty string.
683 static String* hidden_symbol() { return hidden_symbol_; }
684
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000685 // Iterates over all roots in the heap.
686 static void IterateRoots(ObjectVisitor* v);
687 // Iterates over all strong roots in the heap.
688 static void IterateStrongRoots(ObjectVisitor* v);
689
690 // Iterates remembered set of an old space.
691 static void IterateRSet(PagedSpace* space, ObjectSlotCallback callback);
692
693 // Iterates a range of remembered set addresses starting with rset_start
694 // corresponding to the range of allocated pointers
695 // [object_start, object_end).
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000696 // Returns the number of bits that were set.
697 static int IterateRSetRange(Address object_start,
698 Address object_end,
699 Address rset_start,
700 ObjectSlotCallback copy_object_func);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000701
702 // Returns whether the object resides in new space.
703 static inline bool InNewSpace(Object* object);
704 static inline bool InFromSpace(Object* object);
705 static inline bool InToSpace(Object* object);
706
707 // Checks whether an address/object in the heap (including auxiliary
708 // area and unused area).
709 static bool Contains(Address addr);
710 static bool Contains(HeapObject* value);
711
712 // Checks whether an address/object in a space.
713 // Currently used by tests and heap verification only.
714 static bool InSpace(Address addr, AllocationSpace space);
715 static bool InSpace(HeapObject* value, AllocationSpace space);
716
kasper.lund7276f142008-07-30 08:49:36 +0000717 // Finds out which space an object should get promoted to based on its type.
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000718 static inline OldSpace* TargetSpace(HeapObject* object);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000719 static inline AllocationSpace TargetSpaceId(InstanceType type);
kasper.lund7276f142008-07-30 08:49:36 +0000720
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000721 // Sets the stub_cache_ (only used when expanding the dictionary).
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000722 static void public_set_code_stubs(NumberDictionary* value) {
723 roots_[kCodeStubsRootIndex] = value;
724 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000725
726 // Sets the non_monomorphic_cache_ (only used when expanding the dictionary).
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000727 static void public_set_non_monomorphic_cache(NumberDictionary* value) {
728 roots_[kNonMonomorphicCacheRootIndex] = value;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000729 }
730
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000731 // Update the next script id.
732 static inline void SetLastScriptId(Object* last_script_id);
733
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000734#ifdef DEBUG
735 static void Print();
736 static void PrintHandles();
737
738 // Verify the heap is in its normal state before or after a GC.
739 static void Verify();
740
741 // Report heap statistics.
742 static void ReportHeapStatistics(const char* title);
743 static void ReportCodeStatistics(const char* title);
744
745 // Fill in bogus values in from space
746 static void ZapFromSpace();
747#endif
748
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000749#if defined(ENABLE_LOGGING_AND_PROFILING)
750 // Print short heap statistics.
751 static void PrintShortHeapStatistics();
752#endif
753
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000754 // Makes a new symbol object
755 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
756 // failed.
757 // Please note this function does not perform a garbage collection.
758 static Object* CreateSymbol(const char* str, int length, int hash);
759 static Object* CreateSymbol(String* str);
760
761 // Write barrier support for address[offset] = o.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000762 static inline void RecordWrite(Address address, int offset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000763
kasper.lund7276f142008-07-30 08:49:36 +0000764 // Given an address occupied by a live code object, return that object.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000765 static Object* FindCodeObject(Address a);
766
767 // Invoke Shrink on shrinkable spaces.
768 static void Shrink();
769
770 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT };
771 static inline HeapState gc_state() { return gc_state_; }
772
773#ifdef DEBUG
774 static bool IsAllocationAllowed() { return allocation_allowed_; }
775 static inline bool allow_allocation(bool enable);
776
777 static bool disallow_allocation_failure() {
778 return disallow_allocation_failure_;
779 }
780
781 static void TracePathToObject();
782 static void TracePathToGlobal();
783#endif
784
ager@chromium.org32912102009-01-16 10:38:43 +0000785 // Callback function passed to Heap::Iterate etc. Copies an object if
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000786 // necessary, the object might be promoted to an old space. The caller must
787 // ensure the precondition that the object is (a) a heap object and (b) in
788 // the heap's from space.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000789 static void ScavengePointer(HeapObject** p);
790 static inline void ScavengeObject(HeapObject** p, HeapObject* object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000791
792 // Clear a range of remembered set addresses corresponding to the object
793 // area address 'start' with size 'size_in_bytes', eg, when adding blocks
794 // to the free list.
795 static void ClearRSetRange(Address start, int size_in_bytes);
796
797 // Rebuild remembered set in old and map spaces.
798 static void RebuildRSets();
799
ager@chromium.orgadd848f2009-08-13 12:44:13 +0000800 // Commits from space if it is uncommitted.
801 static void EnsureFromSpaceIsCommitted();
802
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000803 //
804 // Support for the API.
805 //
806
807 static bool CreateApiObjects();
808
809 // Attempt to find the number in a small cache. If we finds it, return
810 // the string representation of the number. Otherwise return undefined.
811 static Object* GetNumberStringCache(Object* number);
812
813 // Update the cache with a new number-string pair.
814 static void SetNumberStringCache(Object* number, String* str);
815
816 // Entries in the cache. Must be a power of 2.
817 static const int kNumberStringCacheSize = 64;
818
kasper.lund7276f142008-07-30 08:49:36 +0000819 // Adjusts the amount of registered external memory.
820 // Returns the adjusted value.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000821 static inline int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
kasper.lund7276f142008-07-30 08:49:36 +0000822
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000823 // Allocate unitialized fixed array (pretenure == NON_TENURE).
824 static Object* AllocateRawFixedArray(int length);
825
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000826 // True if we have reached the allocation limit in the old generation that
827 // should force the next GC (caused normally) to be a full one.
828 static bool OldGenerationPromotionLimitReached() {
829 return (PromotedSpaceSize() + PromotedExternalMemorySize())
830 > old_gen_promotion_limit_;
831 }
832
833 // True if we have reached the allocation limit in the old generation that
834 // should artificially cause a GC right now.
835 static bool OldGenerationAllocationLimitReached() {
836 return (PromotedSpaceSize() + PromotedExternalMemorySize())
837 > old_gen_allocation_limit_;
838 }
839
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000840 private:
841 static int semispace_size_;
842 static int initial_semispace_size_;
843 static int young_generation_size_;
844 static int old_generation_size_;
845
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000846 // For keeping track of how much data has survived
847 // scavenge since last new space expansion.
848 static int survived_since_last_expansion_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000849
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000850 static int always_allocate_scope_depth_;
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000851 static bool context_disposed_pending_;
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000852
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000853 static const int kMaxMapSpaceSize = 8*MB;
854
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000855 static const int kMaxObjectSizeInNewSpace = 256*KB;
856
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000857 static NewSpace new_space_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000858 static OldSpace* old_pointer_space_;
859 static OldSpace* old_data_space_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000860 static OldSpace* code_space_;
861 static MapSpace* map_space_;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000862 static CellSpace* cell_space_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000863 static LargeObjectSpace* lo_space_;
864 static HeapState gc_state_;
865
866 // Returns the size of object residing in non new spaces.
867 static int PromotedSpaceSize();
868
kasper.lund7276f142008-07-30 08:49:36 +0000869 // Returns the amount of external memory registered since last global gc.
870 static int PromotedExternalMemorySize();
871
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000872 static int mc_count_; // how many mark-compact collections happened
873 static int gc_count_; // how many gc happened
874
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000875#define ROOT_ACCESSOR(type, name, camel_name) \
876 static inline void set_##name(type* value) { \
877 roots_[k##camel_name##RootIndex] = value; \
878 }
879 ROOT_LIST(ROOT_ACCESSOR)
880#undef ROOT_ACCESSOR
881
kasper.lund7276f142008-07-30 08:49:36 +0000882#ifdef DEBUG
883 static bool allocation_allowed_;
884
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000885 // If the --gc-interval flag is set to a positive value, this
886 // variable holds the value indicating the number of allocations
887 // remain until the next failure and garbage collection.
888 static int allocation_timeout_;
889
890 // Do we expect to be able to handle allocation failure at this
891 // time?
892 static bool disallow_allocation_failure_;
893#endif // DEBUG
894
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000895 // Limit that triggers a global GC on the next (normally caused) GC. This
896 // is checked when we have already decided to do a GC to help determine
897 // which collector to invoke.
898 static int old_gen_promotion_limit_;
899
900 // Limit that triggers a global GC as soon as is reasonable. This is
901 // checked before expanding a paged space in the old generation and on
902 // every allocation in large object space.
903 static int old_gen_allocation_limit_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000904
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000905 // Limit on the amount of externally allocated memory allowed
906 // between global GCs. If reached a global GC is forced.
907 static int external_allocation_limit_;
908
kasper.lund7276f142008-07-30 08:49:36 +0000909 // The amount of external memory registered through the API kept alive
910 // by global handles
911 static int amount_of_external_allocated_memory_;
912
913 // Caches the amount of external memory registered at the last global gc.
914 static int amount_of_external_allocated_memory_at_last_global_gc_;
915
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000916 // Indicates that an allocation has failed in the old generation since the
917 // last GC.
918 static int old_gen_exhausted_;
919
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000920 // Declare all the root indices.
921 enum RootListIndex {
922#define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex,
923 STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION)
924#undef ROOT_INDEX_DECLARATION
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000925
926// Utility type maps
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000927#define DECLARE_STRUCT_MAP(NAME, Name, name) k##Name##MapRootIndex,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000928 STRUCT_LIST(DECLARE_STRUCT_MAP)
929#undef DECLARE_STRUCT_MAP
930
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000931#define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex,
932 SYMBOL_LIST(SYMBOL_INDEX_DECLARATION)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000933#undef SYMBOL_DECLARATION
934
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000935 kSymbolTableRootIndex,
936 kStrongRootListLength = kSymbolTableRootIndex,
937 kRootListLength
938 };
939
940 static Object* roots_[kRootListLength];
941
942 struct StringTypeTable {
943 InstanceType type;
944 int size;
945 RootListIndex index;
946 };
947
948 struct ConstantSymbolTable {
949 const char* contents;
950 RootListIndex index;
951 };
952
953 struct StructTable {
954 InstanceType type;
955 int size;
956 RootListIndex index;
957 };
958
959 static const StringTypeTable string_type_table[];
960 static const ConstantSymbolTable constant_symbol_table[];
961 static const StructTable struct_table[];
962
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000963 // The special hidden symbol which is an empty string, but does not match
964 // any string when looked up in properties.
965 static String* hidden_symbol_;
966
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000967 // GC callback function, called before and after mark-compact GC.
968 // Allocations in the callback function are disallowed.
969 static GCCallback global_gc_prologue_callback_;
970 static GCCallback global_gc_epilogue_callback_;
971
972 // Checks whether a global GC is necessary
973 static GarbageCollector SelectGarbageCollector(AllocationSpace space);
974
975 // Performs garbage collection
976 static void PerformGarbageCollection(AllocationSpace space,
kasper.lund7276f142008-07-30 08:49:36 +0000977 GarbageCollector collector,
978 GCTracer* tracer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000979
980 // Returns either a Smi or a Number object from 'value'. If 'new_object'
981 // is false, it may return a preallocated immutable object.
982 static Object* SmiOrNumberFromDouble(double value,
983 bool new_object,
984 PretenureFlag pretenure = NOT_TENURED);
985
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000986 // Allocate an uninitialized object in map space. The behavior is identical
987 // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't
988 // have to test the allocation space argument and (b) can reduce code size
989 // (since both AllocateRaw and AllocateRawMap are inlined).
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000990 static inline Object* AllocateRawMap();
991
992 // Allocate an uninitialized object in the global property cell space.
993 static inline Object* AllocateRawCell();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000994
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000995 // Initializes a JSObject based on its map.
996 static void InitializeJSObjectFromMap(JSObject* obj,
997 FixedArray* properties,
998 Map* map);
999
1000 static bool CreateInitialMaps();
1001 static bool CreateInitialObjects();
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001002
1003 // These four Create*EntryStub functions are here because of a gcc-4.4 bug
1004 // that assigns wrong vtable entries.
1005 static void CreateCEntryStub();
1006 static void CreateCEntryDebugBreakStub();
1007 static void CreateJSEntryStub();
1008 static void CreateJSConstructEntryStub();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001009 static void CreateFixedStubs();
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001010
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001011 static Object* CreateOddball(Map* map,
1012 const char* to_string,
1013 Object* to_number);
1014
1015 // Allocate empty fixed array.
1016 static Object* AllocateEmptyFixedArray();
1017
1018 // Performs a minor collection in new generation.
1019 static void Scavenge();
1020
1021 // Performs a major collection in the whole heap.
kasper.lund7276f142008-07-30 08:49:36 +00001022 static void MarkCompact(GCTracer* tracer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001023
1024 // Code to be run before and after mark-compact.
kasperl@chromium.org061ef742009-02-27 12:16:20 +00001025 static void MarkCompactPrologue(bool is_compacting);
1026 static void MarkCompactEpilogue(bool is_compacting);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001027
1028 // Helper function used by CopyObject to copy a source object to an
1029 // allocated target object and update the forwarding pointer in the source
1030 // object. Returns the target object.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001031 static HeapObject* MigrateObject(HeapObject* source,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001032 HeapObject* target,
1033 int size);
1034
1035 // Helper function that governs the promotion policy from new space to
1036 // old. If the object's old address lies below the new space's age
1037 // mark or if we've already filled the bottom 1/16th of the to space,
1038 // we try to promote this object.
1039 static inline bool ShouldBePromoted(Address old_address, int object_size);
1040#if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1041 // Record the copy of an object in the NewSpace's statistics.
1042 static void RecordCopiedObject(HeapObject* obj);
1043
1044 // Record statistics before and after garbage collection.
1045 static void ReportStatisticsBeforeGC();
1046 static void ReportStatisticsAfterGC();
1047#endif
1048
1049 // Update an old object's remembered set
1050 static int UpdateRSet(HeapObject* obj);
1051
1052 // Rebuild remembered set in an old space.
1053 static void RebuildRSets(PagedSpace* space);
1054
1055 // Rebuild remembered set in the large object space.
1056 static void RebuildRSets(LargeObjectSpace* space);
1057
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001058 // Slow part of scavenge object.
1059 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
1060
1061 // Copy memory from src to dst.
ager@chromium.org5aa501c2009-06-23 07:57:28 +00001062 static inline void CopyBlock(Object** dst, Object** src, int byte_size);
1063
1064 // Initializes a function with a shared part and prototype.
1065 // Returns the function.
1066 // Note: this code was factored out of AllocateFunction such that
1067 // other parts of the VM could use it. Specifically, a function that creates
1068 // instances of type JS_FUNCTION_TYPE benefit from the use of this function.
1069 // Please note this does not perform a garbage collection.
1070 static inline Object* InitializeFunction(JSFunction* function,
1071 SharedFunctionInfo* shared,
1072 Object* prototype);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001073
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001074 static const int kInitialSymbolTableSize = 2048;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001075 static const int kInitialEvalCacheSize = 64;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001076
1077 friend class Factory;
1078 friend class DisallowAllocationFailure;
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001079 friend class AlwaysAllocateScope;
1080};
1081
1082
1083class AlwaysAllocateScope {
1084 public:
1085 AlwaysAllocateScope() {
1086 // We shouldn't hit any nested scopes, because that requires
1087 // non-handle code to call handle code. The code still works but
1088 // performance will degrade, so we want to catch this situation
1089 // in debug mode.
1090 ASSERT(Heap::always_allocate_scope_depth_ == 0);
1091 Heap::always_allocate_scope_depth_++;
1092 }
1093
1094 ~AlwaysAllocateScope() {
1095 Heap::always_allocate_scope_depth_--;
1096 ASSERT(Heap::always_allocate_scope_depth_ == 0);
1097 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001098};
1099
1100
1101#ifdef DEBUG
1102// Visitor class to verify interior pointers that do not have remembered set
1103// bits. All heap object pointers have to point into the heap to a location
1104// that has a map pointer at its first word. Caveat: Heap::Contains is an
1105// approximation because it can return true for objects in a heap space but
1106// above the allocation pointer.
1107class VerifyPointersVisitor: public ObjectVisitor {
1108 public:
1109 void VisitPointers(Object** start, Object** end) {
1110 for (Object** current = start; current < end; current++) {
1111 if ((*current)->IsHeapObject()) {
1112 HeapObject* object = HeapObject::cast(*current);
1113 ASSERT(Heap::Contains(object));
1114 ASSERT(object->map()->IsMap());
1115 }
1116 }
1117 }
1118};
1119
1120
1121// Visitor class to verify interior pointers that have remembered set bits.
1122// As VerifyPointersVisitor but also checks that remembered set bits are
1123// always set for pointers into new space.
1124class VerifyPointersAndRSetVisitor: public ObjectVisitor {
1125 public:
1126 void VisitPointers(Object** start, Object** end) {
1127 for (Object** current = start; current < end; current++) {
1128 if ((*current)->IsHeapObject()) {
1129 HeapObject* object = HeapObject::cast(*current);
1130 ASSERT(Heap::Contains(object));
1131 ASSERT(object->map()->IsMap());
1132 if (Heap::InNewSpace(object)) {
1133 ASSERT(Page::IsRSetSet(reinterpret_cast<Address>(current), 0));
1134 }
1135 }
1136 }
1137 }
1138};
1139#endif
1140
1141
kasper.lund7276f142008-07-30 08:49:36 +00001142// Space iterator for iterating over all spaces of the heap.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001143// Returns each space in turn, and null when it is done.
1144class AllSpaces BASE_EMBEDDED {
1145 public:
1146 Space* next();
1147 AllSpaces() { counter_ = FIRST_SPACE; }
1148 private:
1149 int counter_;
1150};
1151
1152
1153// Space iterator for iterating over all old spaces of the heap: Old pointer
1154// space, old data space and code space.
1155// Returns each space in turn, and null when it is done.
1156class OldSpaces BASE_EMBEDDED {
1157 public:
1158 OldSpace* next();
1159 OldSpaces() { counter_ = OLD_POINTER_SPACE; }
1160 private:
1161 int counter_;
1162};
1163
1164
1165// Space iterator for iterating over all the paged spaces of the heap:
1166// Map space, old pointer space, old data space and code space.
1167// Returns each space in turn, and null when it is done.
1168class PagedSpaces BASE_EMBEDDED {
1169 public:
1170 PagedSpace* next();
1171 PagedSpaces() { counter_ = OLD_POINTER_SPACE; }
1172 private:
1173 int counter_;
1174};
1175
1176
1177// Space iterator for iterating over all spaces of the heap.
kasper.lund7276f142008-07-30 08:49:36 +00001178// For each space an object iterator is provided. The deallocation of the
1179// returned object iterators is handled by the space iterator.
kasper.lund7276f142008-07-30 08:49:36 +00001180class SpaceIterator : public Malloced {
1181 public:
1182 SpaceIterator();
1183 virtual ~SpaceIterator();
1184
1185 bool has_next();
1186 ObjectIterator* next();
1187
1188 private:
1189 ObjectIterator* CreateIterator();
1190
1191 int current_space_; // from enum AllocationSpace.
1192 ObjectIterator* iterator_; // object iterator for the current space.
1193};
1194
1195
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001196// A HeapIterator provides iteration over the whole heap It aggregates a the
1197// specific iterators for the different spaces as these can only iterate over
1198// one space only.
1199
1200class HeapIterator BASE_EMBEDDED {
1201 public:
1202 explicit HeapIterator();
1203 virtual ~HeapIterator();
1204
1205 bool has_next();
1206 HeapObject* next();
1207 void reset();
1208
1209 private:
1210 // Perform the initialization.
1211 void Init();
1212
1213 // Perform all necessary shutdown (destruction) work.
1214 void Shutdown();
1215
1216 // Space iterator for iterating all the spaces.
1217 SpaceIterator* space_iterator_;
1218 // Object iterator for the space currently being iterated.
1219 ObjectIterator* object_iterator_;
1220};
1221
1222
ager@chromium.org5aa501c2009-06-23 07:57:28 +00001223// Cache for mapping (map, property name) into field offset.
1224// Cleared at startup and prior to mark sweep collection.
1225class KeyedLookupCache {
1226 public:
1227 // Lookup field offset for (map, name). If absent, -1 is returned.
1228 static int Lookup(Map* map, String* name);
1229
1230 // Update an element in the cache.
1231 static void Update(Map* map, String* name, int field_offset);
1232
1233 // Clear the cache.
1234 static void Clear();
1235 private:
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001236 static inline int Hash(Map* map, String* name);
ager@chromium.org5aa501c2009-06-23 07:57:28 +00001237 static const int kLength = 64;
1238 struct Key {
1239 Map* map;
1240 String* name;
1241 };
1242 static Key keys_[kLength];
1243 static int field_offsets_[kLength];
1244};
1245
1246
1247
1248// Cache for mapping (array, property name) into descriptor index.
1249// The cache contains both positive and negative results.
1250// Descriptor index equals kNotFound means the property is absent.
1251// Cleared at startup and prior to any gc.
1252class DescriptorLookupCache {
1253 public:
1254 // Lookup descriptor index for (map, name).
1255 // If absent, kAbsent is returned.
1256 static int Lookup(DescriptorArray* array, String* name) {
1257 if (!StringShape(name).IsSymbol()) return kAbsent;
1258 int index = Hash(array, name);
1259 Key& key = keys_[index];
1260 if ((key.array == array) && (key.name == name)) return results_[index];
1261 return kAbsent;
1262 }
1263
1264 // Update an element in the cache.
1265 static void Update(DescriptorArray* array, String* name, int result) {
1266 ASSERT(result != kAbsent);
1267 if (StringShape(name).IsSymbol()) {
1268 int index = Hash(array, name);
1269 Key& key = keys_[index];
1270 key.array = array;
1271 key.name = name;
1272 results_[index] = result;
1273 }
1274 }
1275
1276 // Clear the cache.
1277 static void Clear();
1278
1279 static const int kAbsent = -2;
1280 private:
1281 static int Hash(DescriptorArray* array, String* name) {
1282 // Uses only lower 32 bits if pointers are larger.
1283 uintptr_t array_hash =
1284 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2;
1285 uintptr_t name_hash =
1286 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2;
1287 return (array_hash ^ name_hash) % kLength;
1288 }
1289
1290 static const int kLength = 64;
1291 struct Key {
1292 DescriptorArray* array;
1293 String* name;
1294 };
1295
1296 static Key keys_[kLength];
1297 static int results_[kLength];
1298};
1299
1300
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001301// ----------------------------------------------------------------------------
1302// Marking stack for tracing live objects.
1303
1304class MarkingStack {
1305 public:
1306 void Initialize(Address low, Address high) {
1307 top_ = low_ = reinterpret_cast<HeapObject**>(low);
1308 high_ = reinterpret_cast<HeapObject**>(high);
1309 overflowed_ = false;
1310 }
1311
1312 bool is_full() { return top_ >= high_; }
1313
1314 bool is_empty() { return top_ <= low_; }
1315
1316 bool overflowed() { return overflowed_; }
1317
1318 void clear_overflowed() { overflowed_ = false; }
1319
mads.s.ager31e71382008-08-13 09:32:07 +00001320 // Push the (marked) object on the marking stack if there is room,
1321 // otherwise mark the object as overflowed and wait for a rescan of the
1322 // heap.
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001323 void Push(HeapObject* object) {
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001324 CHECK(object->IsHeapObject());
mads.s.ager31e71382008-08-13 09:32:07 +00001325 if (is_full()) {
1326 object->SetOverflow();
1327 overflowed_ = true;
1328 } else {
1329 *(top_++) = object;
1330 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001331 }
1332
1333 HeapObject* Pop() {
1334 ASSERT(!is_empty());
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001335 HeapObject* object = *(--top_);
1336 CHECK(object->IsHeapObject());
1337 return object;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001338 }
1339
1340 private:
1341 HeapObject** low_;
1342 HeapObject** top_;
1343 HeapObject** high_;
1344 bool overflowed_;
1345};
1346
1347
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001348// A helper class to document/test C++ scopes where we do not
1349// expect a GC. Usage:
1350//
1351// /* Allocation not allowed: we cannot handle a GC in this scope. */
1352// { AssertNoAllocation nogc;
1353// ...
1354// }
1355
1356#ifdef DEBUG
1357
1358class DisallowAllocationFailure {
1359 public:
1360 DisallowAllocationFailure() {
1361 old_state_ = Heap::disallow_allocation_failure_;
1362 Heap::disallow_allocation_failure_ = true;
1363 }
1364 ~DisallowAllocationFailure() {
1365 Heap::disallow_allocation_failure_ = old_state_;
1366 }
1367 private:
1368 bool old_state_;
1369};
1370
1371class AssertNoAllocation {
1372 public:
1373 AssertNoAllocation() {
1374 old_state_ = Heap::allow_allocation(false);
1375 }
1376
1377 ~AssertNoAllocation() {
1378 Heap::allow_allocation(old_state_);
1379 }
1380
1381 private:
1382 bool old_state_;
1383};
1384
1385#else // ndef DEBUG
1386
1387class AssertNoAllocation {
1388 public:
1389 AssertNoAllocation() { }
1390 ~AssertNoAllocation() { }
1391};
1392
1393#endif
1394
1395#ifdef ENABLE_LOGGING_AND_PROFILING
1396// The HeapProfiler writes data to the log files, which can be postprocessed
1397// to generate .hp files for use by the GHC/Valgrind tool hp2ps.
1398class HeapProfiler {
1399 public:
1400 // Write a single heap sample to the log file.
1401 static void WriteSample();
1402
1403 private:
1404 // Update the array info with stats from obj.
1405 static void CollectStats(HeapObject* obj, HistogramInfo* info);
1406};
1407#endif
1408
kasper.lund7276f142008-07-30 08:49:36 +00001409// GCTracer collects and prints ONE line after each garbage collector
1410// invocation IFF --trace_gc is used.
1411
1412class GCTracer BASE_EMBEDDED {
1413 public:
1414 GCTracer();
1415
1416 ~GCTracer();
1417
1418 // Sets the collector.
1419 void set_collector(GarbageCollector collector) { collector_ = collector; }
1420
1421 // Sets the GC count.
1422 void set_gc_count(int count) { gc_count_ = count; }
1423
1424 // Sets the full GC count.
1425 void set_full_gc_count(int count) { full_gc_count_ = count; }
1426
1427 // Sets the flag that this is a compacting full GC.
1428 void set_is_compacting() { is_compacting_ = true; }
1429
1430 // Increment and decrement the count of marked objects.
1431 void increment_marked_count() { ++marked_count_; }
1432 void decrement_marked_count() { --marked_count_; }
1433
1434 int marked_count() { return marked_count_; }
1435
1436 private:
1437 // Returns a string matching the collector.
1438 const char* CollectorString();
1439
1440 // Returns size of object in heap (in MB).
1441 double SizeOfHeapObjects() {
1442 return (static_cast<double>(Heap::SizeOfObjects())) / MB;
1443 }
1444
1445 double start_time_; // Timestamp set in the constructor.
1446 double start_size_; // Size of objects in heap set in constructor.
1447 GarbageCollector collector_; // Type of collector.
1448
1449 // A count (including this one, eg, the first collection is 1) of the
1450 // number of garbage collections.
1451 int gc_count_;
1452
1453 // A count (including this one) of the number of full garbage collections.
1454 int full_gc_count_;
1455
1456 // True if the current GC is a compacting full collection, false
1457 // otherwise.
1458 bool is_compacting_;
1459
1460 // True if the *previous* full GC cwas a compacting collection (will be
1461 // false if there has not been a previous full GC).
1462 bool previous_has_compacted_;
1463
1464 // On a full GC, a count of the number of marked objects. Incremented
1465 // when an object is marked and decremented when an object's mark bit is
1466 // cleared. Will be zero on a scavenge collection.
1467 int marked_count_;
1468
1469 // The count from the end of the previous full GC. Will be zero if there
1470 // was no previous full GC.
1471 int previous_marked_count_;
1472};
1473
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001474} } // namespace v8::internal
1475
1476#endif // V8_HEAP_H_