erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_HEAP_H_ |
| 29 | #define V8_HEAP_H_ |
| 30 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 31 | #include <math.h> |
| 32 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 33 | #include "spaces.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 34 | #include "splay-tree-inl.h" |
| 35 | #include "v8-counters.h" |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 36 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 37 | namespace v8 { |
| 38 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 40 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | // Defines all the roots in Heap. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 42 | #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 43 | /* Put the byte array map early. We need it to be in place by the time */ \ |
| 44 | /* the deserializer hits the next page, since it wants to put a byte */ \ |
| 45 | /* array in the unused space at the end of the page. */ \ |
| 46 | V(Map, byte_array_map, ByteArrayMap) \ |
| 47 | V(Map, one_pointer_filler_map, OnePointerFillerMap) \ |
| 48 | V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ |
| 49 | /* Cluster the most popular ones in a few cache lines here at the top. */ \ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 50 | V(Smi, stack_limit, StackLimit) \ |
| 51 | V(Object, undefined_value, UndefinedValue) \ |
| 52 | V(Object, the_hole_value, TheHoleValue) \ |
| 53 | V(Object, null_value, NullValue) \ |
| 54 | V(Object, true_value, TrueValue) \ |
| 55 | V(Object, false_value, FalseValue) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 56 | V(Map, heap_number_map, HeapNumberMap) \ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 57 | V(Map, global_context_map, GlobalContextMap) \ |
| 58 | V(Map, fixed_array_map, FixedArrayMap) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 59 | V(Map, fixed_cow_array_map, FixedCOWArrayMap) \ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 60 | V(Object, no_interceptor_result_sentinel, NoInterceptorResultSentinel) \ |
| 61 | V(Map, meta_map, MetaMap) \ |
| 62 | V(Object, termination_exception, TerminationException) \ |
| 63 | V(Map, hash_table_map, HashTableMap) \ |
| 64 | V(FixedArray, empty_fixed_array, EmptyFixedArray) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 65 | V(ByteArray, empty_byte_array, EmptyByteArray) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 66 | V(Map, string_map, StringMap) \ |
| 67 | V(Map, ascii_string_map, AsciiStringMap) \ |
| 68 | V(Map, symbol_map, SymbolMap) \ |
| 69 | V(Map, ascii_symbol_map, AsciiSymbolMap) \ |
| 70 | V(Map, cons_symbol_map, ConsSymbolMap) \ |
| 71 | V(Map, cons_ascii_symbol_map, ConsAsciiSymbolMap) \ |
| 72 | V(Map, external_symbol_map, ExternalSymbolMap) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 73 | V(Map, external_symbol_with_ascii_data_map, ExternalSymbolWithAsciiDataMap) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 74 | V(Map, external_ascii_symbol_map, ExternalAsciiSymbolMap) \ |
| 75 | V(Map, cons_string_map, ConsStringMap) \ |
| 76 | V(Map, cons_ascii_string_map, ConsAsciiStringMap) \ |
| 77 | V(Map, external_string_map, ExternalStringMap) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 78 | V(Map, external_string_with_ascii_data_map, ExternalStringWithAsciiDataMap) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 79 | V(Map, external_ascii_string_map, ExternalAsciiStringMap) \ |
| 80 | V(Map, undetectable_string_map, UndetectableStringMap) \ |
| 81 | V(Map, undetectable_ascii_string_map, UndetectableAsciiStringMap) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 82 | V(Map, pixel_array_map, PixelArrayMap) \ |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 83 | V(Map, external_byte_array_map, ExternalByteArrayMap) \ |
| 84 | V(Map, external_unsigned_byte_array_map, ExternalUnsignedByteArrayMap) \ |
| 85 | V(Map, external_short_array_map, ExternalShortArrayMap) \ |
| 86 | V(Map, external_unsigned_short_array_map, ExternalUnsignedShortArrayMap) \ |
| 87 | V(Map, external_int_array_map, ExternalIntArrayMap) \ |
| 88 | V(Map, external_unsigned_int_array_map, ExternalUnsignedIntArrayMap) \ |
| 89 | V(Map, external_float_array_map, ExternalFloatArrayMap) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 90 | V(Map, context_map, ContextMap) \ |
| 91 | V(Map, catch_context_map, CatchContextMap) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 92 | V(Map, code_map, CodeMap) \ |
| 93 | V(Map, oddball_map, OddballMap) \ |
| 94 | V(Map, global_property_cell_map, GlobalPropertyCellMap) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 95 | V(Map, shared_function_info_map, SharedFunctionInfoMap) \ |
| 96 | V(Map, proxy_map, ProxyMap) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 97 | V(Object, nan_value, NanValue) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 98 | V(Object, minus_zero_value, MinusZeroValue) \ |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 99 | V(Object, instanceof_cache_function, InstanceofCacheFunction) \ |
| 100 | V(Object, instanceof_cache_map, InstanceofCacheMap) \ |
| 101 | V(Object, instanceof_cache_answer, InstanceofCacheAnswer) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 102 | V(String, empty_string, EmptyString) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 103 | V(DescriptorArray, empty_descriptor_array, EmptyDescriptorArray) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 104 | V(Map, neander_map, NeanderMap) \ |
| 105 | V(JSObject, message_listeners, MessageListeners) \ |
| 106 | V(Proxy, prototype_accessors, PrototypeAccessors) \ |
| 107 | V(NumberDictionary, code_stubs, CodeStubs) \ |
| 108 | V(NumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \ |
| 109 | V(Code, js_entry_code, JsEntryCode) \ |
| 110 | V(Code, js_construct_entry_code, JsConstructEntryCode) \ |
| 111 | V(Code, c_entry_code, CEntryCode) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 112 | V(FixedArray, number_string_cache, NumberStringCache) \ |
| 113 | V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \ |
| 114 | V(FixedArray, natives_source_cache, NativesSourceCache) \ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 115 | V(Object, last_script_id, LastScriptId) \ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 116 | V(Script, empty_script, EmptyScript) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 117 | V(Smi, real_stack_limit, RealStackLimit) \ |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 118 | V(StringDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 119 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 120 | #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 121 | #define STRONG_ROOT_LIST(V) \ |
| 122 | UNCONDITIONAL_STRONG_ROOT_LIST(V) \ |
| 123 | V(Code, re_c_entry_code, RegExpCEntryCode) |
| 124 | #else |
| 125 | #define STRONG_ROOT_LIST(V) UNCONDITIONAL_STRONG_ROOT_LIST(V) |
| 126 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | |
| 128 | #define ROOT_LIST(V) \ |
| 129 | STRONG_ROOT_LIST(V) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 130 | V(SymbolTable, symbol_table, SymbolTable) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | |
| 132 | #define SYMBOL_LIST(V) \ |
| 133 | V(Array_symbol, "Array") \ |
| 134 | V(Object_symbol, "Object") \ |
| 135 | V(Proto_symbol, "__proto__") \ |
| 136 | V(StringImpl_symbol, "StringImpl") \ |
| 137 | V(arguments_symbol, "arguments") \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 138 | V(Arguments_symbol, "Arguments") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | V(arguments_shadow_symbol, ".arguments") \ |
| 140 | V(call_symbol, "call") \ |
| 141 | V(apply_symbol, "apply") \ |
| 142 | V(caller_symbol, "caller") \ |
| 143 | V(boolean_symbol, "boolean") \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 144 | V(Boolean_symbol, "Boolean") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | V(callee_symbol, "callee") \ |
| 146 | V(constructor_symbol, "constructor") \ |
| 147 | V(code_symbol, ".code") \ |
| 148 | V(result_symbol, ".result") \ |
| 149 | V(catch_var_symbol, ".catch-var") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | V(empty_symbol, "") \ |
| 151 | V(eval_symbol, "eval") \ |
| 152 | V(function_symbol, "function") \ |
| 153 | V(length_symbol, "length") \ |
| 154 | V(name_symbol, "name") \ |
| 155 | V(number_symbol, "number") \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 156 | V(Number_symbol, "Number") \ |
| 157 | V(RegExp_symbol, "RegExp") \ |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 158 | V(source_symbol, "source") \ |
| 159 | V(global_symbol, "global") \ |
| 160 | V(ignore_case_symbol, "ignoreCase") \ |
| 161 | V(multiline_symbol, "multiline") \ |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 162 | V(input_symbol, "input") \ |
| 163 | V(index_symbol, "index") \ |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 164 | V(last_index_symbol, "lastIndex") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | V(object_symbol, "object") \ |
| 166 | V(prototype_symbol, "prototype") \ |
| 167 | V(string_symbol, "string") \ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 168 | V(String_symbol, "String") \ |
| 169 | V(Date_symbol, "Date") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | V(this_symbol, "this") \ |
| 171 | V(to_string_symbol, "toString") \ |
| 172 | V(char_at_symbol, "CharAt") \ |
| 173 | V(undefined_symbol, "undefined") \ |
| 174 | V(value_of_symbol, "valueOf") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | V(InitializeVarGlobal_symbol, "InitializeVarGlobal") \ |
| 176 | V(InitializeConstGlobal_symbol, "InitializeConstGlobal") \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 177 | V(KeyedLoadSpecialized_symbol, "KeyedLoadSpecialized") \ |
| 178 | V(KeyedStoreSpecialized_symbol, "KeyedStoreSpecialized") \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 202 | V(zero_symbol, "0") \ |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 203 | V(global_eval_symbol, "GlobalEval") \ |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 204 | V(identity_hash_symbol, "v8::IdentityHash") \ |
| 205 | V(closure_symbol, "(closure)") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | |
| 207 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 208 | // Forward declarations. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 209 | class GCTracer; |
ager@chromium.org | 6012123 | 2009-12-03 11:25:37 +0000 | [diff] [blame] | 210 | class HeapStats; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 211 | class WeakObjectRetainer; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 212 | |
| 213 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 214 | typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); |
| 215 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 216 | typedef bool (*DirtyRegionCallback)(Address start, |
| 217 | Address end, |
| 218 | ObjectSlotCallback copy_object_func); |
| 219 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 220 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | // The all static Heap captures the interface to the global object heap. |
| 222 | // All JavaScript contexts by this process share the same object heap. |
| 223 | |
| 224 | class Heap : public AllStatic { |
| 225 | public: |
| 226 | // Configure heap size before setup. Return false if the heap has been |
| 227 | // setup already. |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 228 | static bool ConfigureHeap(int max_semispace_size, |
| 229 | int max_old_gen_size, |
| 230 | int max_executable_size); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 231 | static bool ConfigureHeapDefault(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | |
| 233 | // Initializes the global object heap. If create_heap_objects is true, |
| 234 | // also creates the basic non-mutable objects. |
| 235 | // Returns whether it succeeded. |
| 236 | static bool Setup(bool create_heap_objects); |
| 237 | |
| 238 | // Destroys all memory allocated by the heap. |
| 239 | static void TearDown(); |
| 240 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 241 | // Set the stack limit in the roots_ array. Some architectures generate |
| 242 | // code that looks here, because it is faster than loading from the static |
| 243 | // jslimit_/real_jslimit_ variable in the StackGuard. |
| 244 | static void SetStackLimits(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 245 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 246 | // Returns whether Setup has been called. |
| 247 | static bool HasBeenSetup(); |
| 248 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 249 | // Returns the maximum amount of memory reserved for the heap. For |
| 250 | // the young generation, we reserve 4 times the amount needed for a |
| 251 | // semi space. The young generation consists of two semi spaces and |
| 252 | // we reserve twice the amount needed for those in order to ensure |
| 253 | // that new space can be aligned to its size. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 254 | static intptr_t MaxReserved() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 255 | return 4 * reserved_semispace_size_ + max_old_generation_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 257 | static int MaxSemiSpaceSize() { return max_semispace_size_; } |
| 258 | static int ReservedSemiSpaceSize() { return reserved_semispace_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | static int InitialSemiSpaceSize() { return initial_semispace_size_; } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 260 | static intptr_t MaxOldGenerationSize() { return max_old_generation_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 261 | static intptr_t MaxExecutableSize() { return max_executable_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | |
| 263 | // Returns the capacity of the heap in bytes w/o growing. Heap grows when |
| 264 | // more spaces are needed until it reaches the limit. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 265 | static intptr_t Capacity(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 267 | // Returns the amount of memory currently committed for the heap. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 268 | static intptr_t CommittedMemory(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 269 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 270 | // Returns the amount of executable memory currently committed for the heap. |
| 271 | static intptr_t CommittedMemoryExecutable(); |
| 272 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 273 | // Returns the available bytes in space w/o growing. |
| 274 | // Heap doesn't guarantee that it can allocate an object that requires |
| 275 | // all available bytes. Check MaxHeapObjectSize() instead. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 276 | static intptr_t Available(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 278 | // Returns the maximum object size in paged space. |
| 279 | static inline int MaxObjectSizeInPagedSpace(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | |
| 281 | // Returns of size of all objects residing in the heap. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 282 | static intptr_t SizeOfObjects(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | |
| 284 | // Return the starting address and a mask for the new space. And-masking an |
| 285 | // address with the mask will result in the start address of the new space |
| 286 | // for all addresses in either semispace. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 287 | static Address NewSpaceStart() { return new_space_.start(); } |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 288 | static uintptr_t NewSpaceMask() { return new_space_.mask(); } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 289 | static Address NewSpaceTop() { return new_space_.top(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 290 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 291 | static NewSpace* new_space() { return &new_space_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 292 | static OldSpace* old_pointer_space() { return old_pointer_space_; } |
| 293 | static OldSpace* old_data_space() { return old_data_space_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | static OldSpace* code_space() { return code_space_; } |
| 295 | static MapSpace* map_space() { return map_space_; } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 296 | static CellSpace* cell_space() { return cell_space_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | static LargeObjectSpace* lo_space() { return lo_space_; } |
| 298 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 299 | static bool always_allocate() { return always_allocate_scope_depth_ != 0; } |
| 300 | static Address always_allocate_scope_depth_address() { |
| 301 | return reinterpret_cast<Address>(&always_allocate_scope_depth_); |
| 302 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 303 | static bool linear_allocation() { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 304 | return linear_allocation_scope_depth_ != 0; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 305 | } |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 306 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 307 | static Address* NewSpaceAllocationTopAddress() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 308 | return new_space_.allocation_top_address(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | } |
| 310 | static Address* NewSpaceAllocationLimitAddress() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 311 | return new_space_.allocation_limit_address(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 312 | } |
| 313 | |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 314 | // Uncommit unused semi space. |
| 315 | static bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); } |
| 316 | |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 317 | #ifdef ENABLE_HEAP_PROTECTION |
| 318 | // Protect/unprotect the heap by marking all spaces read-only/writable. |
| 319 | static void Protect(); |
| 320 | static void Unprotect(); |
| 321 | #endif |
| 322 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 323 | // Allocates and initializes a new JavaScript object based on a |
| 324 | // constructor. |
| 325 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 326 | // failed. |
| 327 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 328 | MUST_USE_RESULT static MaybeObject* AllocateJSObject( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 329 | JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 331 | // Allocates and initializes a new global object based on a constructor. |
| 332 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 333 | // failed. |
| 334 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 335 | MUST_USE_RESULT static MaybeObject* AllocateGlobalObject( |
| 336 | JSFunction* constructor); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 337 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 338 | // Returns a deep copy of the JavaScript object. |
| 339 | // Properties and elements are copied too. |
| 340 | // Returns failure if allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 341 | MUST_USE_RESULT static MaybeObject* CopyJSObject(JSObject* source); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 343 | // Allocates the function prototype. |
| 344 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 345 | // failed. |
| 346 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 347 | MUST_USE_RESULT static MaybeObject* AllocateFunctionPrototype( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 348 | JSFunction* function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 350 | // Reinitialize an JSGlobalProxy based on a constructor. The object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | // must have the same size as objects allocated using the |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 352 | // constructor. The object is reinitialized and behaves as an |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 353 | // object that has been freshly allocated using the constructor. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 354 | MUST_USE_RESULT static MaybeObject* ReinitializeJSGlobalProxy( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 355 | JSFunction* constructor, |
| 356 | JSGlobalProxy* global); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | |
| 358 | // Allocates and initializes a new JavaScript object based on a map. |
| 359 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 360 | // failed. |
| 361 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 362 | MUST_USE_RESULT static MaybeObject* AllocateJSObjectFromMap( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 363 | Map* map, PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | |
| 365 | // Allocates a heap object based on the map. |
| 366 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 367 | // failed. |
| 368 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 369 | MUST_USE_RESULT static MaybeObject* Allocate(Map* map, AllocationSpace space); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | |
| 371 | // Allocates a JS Map in the heap. |
| 372 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 373 | // failed. |
| 374 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 375 | MUST_USE_RESULT static MaybeObject* AllocateMap(InstanceType instance_type, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 376 | int instance_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 377 | |
| 378 | // Allocates a partial map for bootstrapping. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 379 | MUST_USE_RESULT static MaybeObject* AllocatePartialMap( |
| 380 | InstanceType instance_type, |
| 381 | int instance_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | |
| 383 | // Allocate a map for the specified function |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 384 | MUST_USE_RESULT static MaybeObject* AllocateInitialMap(JSFunction* fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 385 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 386 | // Allocates an empty code cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 387 | MUST_USE_RESULT static MaybeObject* AllocateCodeCache(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 388 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 389 | // Clear the Instanceof cache (used when a prototype changes). |
| 390 | static void ClearInstanceofCache() { |
| 391 | set_instanceof_cache_function(the_hole_value()); |
| 392 | } |
| 393 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | // Allocates and fully initializes a String. There are two String |
| 395 | // encodings: ASCII and two byte. One should choose between the three string |
| 396 | // allocation functions based on the encoding of the string buffer used to |
| 397 | // initialized the string. |
| 398 | // - ...FromAscii initializes the string from a buffer that is ASCII |
| 399 | // encoded (it does not check that the buffer is ASCII encoded) and the |
| 400 | // result will be ASCII encoded. |
| 401 | // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 402 | // encoded. If the characters are all single-byte characters, the |
| 403 | // result will be ASCII encoded, otherwise it will converted to two |
| 404 | // byte. |
| 405 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 406 | // encoded. If the characters are all single-byte characters, the |
| 407 | // result will be converted to ASCII, otherwise it will be left as |
| 408 | // two-byte. |
| 409 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 410 | // failed. |
| 411 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 412 | MUST_USE_RESULT static MaybeObject* AllocateStringFromAscii( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 413 | Vector<const char> str, |
| 414 | PretenureFlag pretenure = NOT_TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 415 | MUST_USE_RESULT static MaybeObject* AllocateStringFromUtf8( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 416 | Vector<const char> str, |
| 417 | PretenureFlag pretenure = NOT_TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 418 | MUST_USE_RESULT static MaybeObject* AllocateStringFromTwoByte( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | Vector<const uc16> str, |
| 420 | PretenureFlag pretenure = NOT_TENURED); |
| 421 | |
| 422 | // Allocates a symbol in old space based on the character stream. |
| 423 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 424 | // failed. |
| 425 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 426 | MUST_USE_RESULT static inline MaybeObject* AllocateSymbol( |
| 427 | Vector<const char> str, |
| 428 | int chars, |
| 429 | uint32_t hash_field); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 430 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 431 | MUST_USE_RESULT static MaybeObject* AllocateInternalSymbol( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 432 | unibrow::CharacterStream* buffer, int chars, uint32_t hash_field); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 433 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 434 | MUST_USE_RESULT static MaybeObject* AllocateExternalSymbol( |
| 435 | Vector<const char> str, |
| 436 | int chars); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 437 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | |
| 439 | // Allocates and partially initializes a String. There are two String |
| 440 | // encodings: ASCII and two byte. These functions allocate a string of the |
| 441 | // given length and set its map and length fields. The characters of the |
| 442 | // string are uninitialized. |
| 443 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 444 | // failed. |
| 445 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 446 | MUST_USE_RESULT static MaybeObject* AllocateRawAsciiString( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 447 | int length, |
| 448 | PretenureFlag pretenure = NOT_TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 449 | MUST_USE_RESULT static MaybeObject* AllocateRawTwoByteString( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | int length, |
| 451 | PretenureFlag pretenure = NOT_TENURED); |
| 452 | |
| 453 | // Computes a single character string where the character has code. |
| 454 | // A cache is used for ascii codes. |
| 455 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 456 | // failed. Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 457 | MUST_USE_RESULT static MaybeObject* LookupSingleCharacterStringFromCode( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 458 | uint16_t code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | |
| 460 | // Allocate a byte array of the specified length |
| 461 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 462 | // failed. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 463 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 464 | MUST_USE_RESULT static MaybeObject* AllocateByteArray(int length, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 465 | PretenureFlag pretenure); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 466 | |
| 467 | // Allocate a non-tenured byte array of the specified length |
| 468 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 469 | // failed. |
| 470 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 471 | MUST_USE_RESULT static MaybeObject* AllocateByteArray(int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 473 | // Allocate a pixel array of the specified length |
| 474 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 475 | // failed. |
| 476 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 477 | MUST_USE_RESULT static MaybeObject* AllocatePixelArray(int length, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 478 | uint8_t* external_pointer, |
| 479 | PretenureFlag pretenure); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 480 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 481 | // Allocates an external array of the specified length and type. |
| 482 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 483 | // failed. |
| 484 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 485 | MUST_USE_RESULT static MaybeObject* AllocateExternalArray( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 486 | int length, |
| 487 | ExternalArrayType array_type, |
| 488 | void* external_pointer, |
| 489 | PretenureFlag pretenure); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 490 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 491 | // Allocate a tenured JS global property cell. |
| 492 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 493 | // failed. |
| 494 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 495 | MUST_USE_RESULT static MaybeObject* AllocateJSGlobalPropertyCell( |
| 496 | Object* value); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | // Allocates a fixed array initialized with undefined values |
| 499 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 500 | // failed. |
| 501 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 502 | MUST_USE_RESULT static MaybeObject* AllocateFixedArray( |
| 503 | int length, |
| 504 | PretenureFlag pretenure); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 505 | // Allocates a fixed array initialized with undefined values |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 506 | MUST_USE_RESULT static MaybeObject* AllocateFixedArray(int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 507 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 508 | // Allocates an uninitialized fixed array. It must be filled by the caller. |
| 509 | // |
| 510 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 511 | // failed. |
| 512 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 513 | MUST_USE_RESULT static MaybeObject* AllocateUninitializedFixedArray( |
| 514 | int length); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 515 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 516 | // Make a copy of src and return it. Returns |
| 517 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 518 | MUST_USE_RESULT static inline MaybeObject* CopyFixedArray(FixedArray* src); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 519 | |
| 520 | // Make a copy of src, set the map, and return the copy. Returns |
| 521 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 522 | MUST_USE_RESULT static MaybeObject* CopyFixedArrayWithMap(FixedArray* src, |
| 523 | Map* map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | |
| 525 | // Allocates a fixed array initialized with the hole values. |
| 526 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 527 | // failed. |
| 528 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 529 | MUST_USE_RESULT static MaybeObject* AllocateFixedArrayWithHoles( |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 530 | int length, |
| 531 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | |
| 533 | // AllocateHashTable is identical to AllocateFixedArray except |
| 534 | // that the resulting object has hash_table_map as map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 535 | MUST_USE_RESULT static MaybeObject* AllocateHashTable( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 536 | int length, PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | |
| 538 | // Allocate a global (but otherwise uninitialized) context. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 539 | MUST_USE_RESULT static MaybeObject* AllocateGlobalContext(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | |
| 541 | // Allocate a function context. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 542 | MUST_USE_RESULT static MaybeObject* AllocateFunctionContext( |
| 543 | int length, |
| 544 | JSFunction* closure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
| 546 | // Allocate a 'with' context. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 547 | MUST_USE_RESULT static MaybeObject* AllocateWithContext( |
| 548 | Context* previous, |
| 549 | JSObject* extension, |
| 550 | bool is_catch_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 551 | |
| 552 | // Allocates a new utility object in the old generation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 553 | MUST_USE_RESULT static MaybeObject* AllocateStruct(InstanceType type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | // Allocates a function initialized with a shared part. |
| 556 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 557 | // failed. |
| 558 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 559 | MUST_USE_RESULT static MaybeObject* AllocateFunction( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 560 | Map* function_map, |
| 561 | SharedFunctionInfo* shared, |
| 562 | Object* prototype, |
| 563 | PretenureFlag pretenure = TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 564 | |
| 565 | // Indicies for direct access into argument objects. |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 566 | static const int kArgumentsObjectSize = |
| 567 | JSObject::kHeaderSize + 2 * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | static const int arguments_callee_index = 0; |
| 569 | static const int arguments_length_index = 1; |
| 570 | |
| 571 | // Allocates an arguments object - optionally with an elements array. |
| 572 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 573 | // failed. |
| 574 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 575 | MUST_USE_RESULT static MaybeObject* AllocateArgumentsObject(Object* callee, |
| 576 | int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | // Same as NewNumberFromDouble, but may return a preallocated/immutable |
| 579 | // number object (e.g., minus_zero_value_, nan_value_) |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 580 | MUST_USE_RESULT static MaybeObject* NumberFromDouble( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 581 | double value, PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | |
| 583 | // Allocated a HeapNumber from value. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 584 | MUST_USE_RESULT static MaybeObject* AllocateHeapNumber( |
| 585 | double value, |
| 586 | PretenureFlag pretenure); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 587 | // pretenure = NOT_TENURED. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 588 | MUST_USE_RESULT static MaybeObject* AllocateHeapNumber(double value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 589 | |
| 590 | // Converts an int into either a Smi or a HeapNumber object. |
| 591 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 592 | // failed. |
| 593 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 594 | MUST_USE_RESULT static inline MaybeObject* NumberFromInt32(int32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | |
| 596 | // Converts an int into either a Smi or a HeapNumber object. |
| 597 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 598 | // failed. |
| 599 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 600 | MUST_USE_RESULT static inline MaybeObject* NumberFromUint32(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | |
| 602 | // Allocates a new proxy object. |
| 603 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 604 | // failed. |
| 605 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 606 | MUST_USE_RESULT static MaybeObject* AllocateProxy( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 607 | Address proxy, |
| 608 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | |
| 610 | // Allocates a new SharedFunctionInfo object. |
| 611 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 612 | // failed. |
| 613 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 614 | MUST_USE_RESULT static MaybeObject* AllocateSharedFunctionInfo(Object* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | |
| 616 | // Allocates a new cons string object. |
| 617 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 618 | // failed. |
| 619 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 620 | MUST_USE_RESULT static MaybeObject* AllocateConsString(String* first, |
| 621 | String* second); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 623 | // Allocates a new sub string object which is a substring of an underlying |
| 624 | // string buffer stretching from the index start (inclusive) to the index |
| 625 | // end (exclusive). |
| 626 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 627 | // failed. |
| 628 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 629 | MUST_USE_RESULT static MaybeObject* AllocateSubString( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 630 | String* buffer, |
| 631 | int start, |
| 632 | int end, |
| 633 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | |
| 635 | // Allocate a new external string object, which is backed by a string |
| 636 | // resource that resides outside the V8 heap. |
| 637 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 638 | // failed. |
| 639 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 640 | MUST_USE_RESULT static MaybeObject* AllocateExternalStringFromAscii( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | ExternalAsciiString::Resource* resource); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 642 | MUST_USE_RESULT static MaybeObject* AllocateExternalStringFromTwoByte( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | ExternalTwoByteString::Resource* resource); |
| 644 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 645 | // Finalizes an external string by deleting the associated external |
| 646 | // data and clearing the resource pointer. |
| 647 | static inline void FinalizeExternalString(String* string); |
| 648 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 649 | // Allocates an uninitialized object. The memory is non-executable if the |
| 650 | // hardware and OS allow. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 651 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 652 | // failed. |
| 653 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 654 | MUST_USE_RESULT static inline MaybeObject* AllocateRaw( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 655 | int size_in_bytes, |
| 656 | AllocationSpace space, |
| 657 | AllocationSpace retry_space); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 658 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 659 | // Initialize a filler object to keep the ability to iterate over the heap |
| 660 | // when shortening objects. |
| 661 | static void CreateFillerObjectAt(Address addr, int size); |
| 662 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 663 | // Makes a new native code object |
| 664 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 665 | // failed. On success, the pointer to the Code object is stored in the |
| 666 | // self_reference. This allows generated code to reference its own Code |
| 667 | // object by containing this pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 669 | MUST_USE_RESULT static MaybeObject* CreateCode(const CodeDesc& desc, |
| 670 | Code::Flags flags, |
| 671 | Handle<Object> self_reference); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 673 | MUST_USE_RESULT static MaybeObject* CopyCode(Code* code); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 674 | |
| 675 | // Copy the code and scope info part of the code object, but insert |
| 676 | // the provided data as the relocation information. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 677 | MUST_USE_RESULT static MaybeObject* CopyCode(Code* code, |
| 678 | Vector<byte> reloc_info); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 679 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | // Finds the symbol for string in the symbol table. |
| 681 | // If not found, a new symbol is added to the table and returned. |
| 682 | // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation |
| 683 | // failed. |
| 684 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 685 | MUST_USE_RESULT static MaybeObject* LookupSymbol(Vector<const char> str); |
| 686 | MUST_USE_RESULT static MaybeObject* LookupAsciiSymbol(const char* str) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 687 | return LookupSymbol(CStrVector(str)); |
| 688 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 689 | MUST_USE_RESULT static MaybeObject* LookupSymbol(String* str); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 690 | static bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 691 | static bool LookupTwoCharsSymbolIfExists(String* str, String** symbol); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | |
| 693 | // Compute the matching symbol map for a string if possible. |
| 694 | // NULL is returned if string is in new space or not flattened. |
| 695 | static Map* SymbolMapForString(String* str); |
| 696 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 697 | // Tries to flatten a string before compare operation. |
| 698 | // |
| 699 | // Returns a failure in case it was decided that flattening was |
| 700 | // necessary and failed. Note, if flattening is not necessary the |
| 701 | // string might stay non-flat even when not a failure is returned. |
| 702 | // |
| 703 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 704 | MUST_USE_RESULT static inline MaybeObject* PrepareForCompare(String* str); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 705 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | // Converts the given boolean condition to JavaScript boolean value. |
| 707 | static Object* ToBoolean(bool condition) { |
| 708 | return condition ? true_value() : false_value(); |
| 709 | } |
| 710 | |
| 711 | // Code that should be run before and after each GC. Includes some |
| 712 | // reporting/verification activities when compiled with DEBUG set. |
| 713 | static void GarbageCollectionPrologue(); |
| 714 | static void GarbageCollectionEpilogue(); |
| 715 | |
| 716 | // Performs garbage collection operation. |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 717 | // Returns whether there is a chance that another major GC could |
| 718 | // collect more garbage. |
| 719 | static bool CollectGarbage(AllocationSpace space, GarbageCollector collector); |
| 720 | |
| 721 | // Performs garbage collection operation. |
| 722 | // Returns whether there is a chance that another major GC could |
| 723 | // collect more garbage. |
| 724 | inline static bool CollectGarbage(AllocationSpace space); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 726 | // Performs a full garbage collection. Force compaction if the |
| 727 | // parameter is true. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 728 | static void CollectAllGarbage(bool force_compaction); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 729 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 730 | // Last hope GC, should try to squeeze as much as possible. |
| 731 | static void CollectAllAvailableGarbage(); |
| 732 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 733 | // Notify the heap that a context has been disposed. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 734 | static int NotifyContextDisposed() { return ++contexts_disposed_; } |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 735 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | // Utility to invoke the scavenger. This is needed in test code to |
| 737 | // ensure correct callback for weak global handles. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 738 | static void PerformScavenge(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 740 | #ifdef DEBUG |
| 741 | // Utility used with flag gc-greedy. |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 742 | static void GarbageCollectionGreedyCheck(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 743 | #endif |
| 744 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 745 | static void AddGCPrologueCallback( |
| 746 | GCEpilogueCallback callback, GCType gc_type_filter); |
| 747 | static void RemoveGCPrologueCallback(GCEpilogueCallback callback); |
| 748 | |
| 749 | static void AddGCEpilogueCallback( |
| 750 | GCEpilogueCallback callback, GCType gc_type_filter); |
| 751 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 752 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 753 | static void SetGlobalGCPrologueCallback(GCCallback callback) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 754 | ASSERT((callback == NULL) ^ (global_gc_prologue_callback_ == NULL)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | global_gc_prologue_callback_ = callback; |
| 756 | } |
| 757 | static void SetGlobalGCEpilogueCallback(GCCallback callback) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 758 | ASSERT((callback == NULL) ^ (global_gc_epilogue_callback_ == NULL)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | global_gc_epilogue_callback_ = callback; |
| 760 | } |
| 761 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 762 | // Heap root getters. We have versions with and without type::cast() here. |
| 763 | // You can't use type::cast during GC because the assert fails. |
| 764 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 765 | static inline type* name() { \ |
| 766 | return type::cast(roots_[k##camel_name##RootIndex]); \ |
| 767 | } \ |
| 768 | static inline type* raw_unchecked_##name() { \ |
| 769 | return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \ |
| 770 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 771 | ROOT_LIST(ROOT_ACCESSOR) |
| 772 | #undef ROOT_ACCESSOR |
| 773 | |
| 774 | // Utility type maps |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 775 | #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ |
| 776 | static inline Map* name##_map() { \ |
| 777 | return Map::cast(roots_[k##Name##MapRootIndex]); \ |
| 778 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 779 | STRUCT_LIST(STRUCT_MAP_ACCESSOR) |
| 780 | #undef STRUCT_MAP_ACCESSOR |
| 781 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 782 | #define SYMBOL_ACCESSOR(name, str) static inline String* name() { \ |
| 783 | return String::cast(roots_[k##name##RootIndex]); \ |
| 784 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 785 | SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 786 | #undef SYMBOL_ACCESSOR |
| 787 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 788 | // The hidden_symbol is special because it is the empty string, but does |
| 789 | // not match the empty string. |
| 790 | static String* hidden_symbol() { return hidden_symbol_; } |
| 791 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 792 | static void set_global_contexts_list(Object* object) { |
| 793 | global_contexts_list_ = object; |
| 794 | } |
| 795 | static Object* global_contexts_list() { return global_contexts_list_; } |
| 796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | // Iterates over all roots in the heap. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 798 | static void IterateRoots(ObjectVisitor* v, VisitMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 799 | // Iterates over all strong roots in the heap. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 800 | static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 801 | // Iterates over all the other roots in the heap. |
| 802 | static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 804 | enum ExpectedPageWatermarkState { |
| 805 | WATERMARK_SHOULD_BE_VALID, |
| 806 | WATERMARK_CAN_BE_INVALID |
| 807 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 809 | // For each dirty region on a page in use from an old space call |
| 810 | // visit_dirty_region callback. |
| 811 | // If either visit_dirty_region or callback can cause an allocation |
| 812 | // in old space and changes in allocation watermark then |
| 813 | // can_preallocate_during_iteration should be set to true. |
| 814 | // All pages will be marked as having invalid watermark upon |
| 815 | // iteration completion. |
| 816 | static void IterateDirtyRegions( |
| 817 | PagedSpace* space, |
| 818 | DirtyRegionCallback visit_dirty_region, |
| 819 | ObjectSlotCallback callback, |
| 820 | ExpectedPageWatermarkState expected_page_watermark_state); |
| 821 | |
| 822 | // Interpret marks as a bitvector of dirty marks for regions of size |
| 823 | // Page::kRegionSize aligned by Page::kRegionAlignmentMask and covering |
| 824 | // memory interval from start to top. For each dirty region call a |
| 825 | // visit_dirty_region callback. Return updated bitvector of dirty marks. |
| 826 | static uint32_t IterateDirtyRegions(uint32_t marks, |
| 827 | Address start, |
| 828 | Address end, |
| 829 | DirtyRegionCallback visit_dirty_region, |
| 830 | ObjectSlotCallback callback); |
| 831 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 832 | // Iterate pointers to from semispace of new space found in memory interval |
| 833 | // from start to end. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 834 | // Update dirty marks for page containing start address. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 835 | static void IterateAndMarkPointersToFromSpace(Address start, |
| 836 | Address end, |
| 837 | ObjectSlotCallback callback); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 838 | |
| 839 | // Iterate pointers to new space found in memory interval from start to end. |
| 840 | // Return true if pointers to new space was found. |
| 841 | static bool IteratePointersInDirtyRegion(Address start, |
| 842 | Address end, |
| 843 | ObjectSlotCallback callback); |
| 844 | |
| 845 | |
| 846 | // Iterate pointers to new space found in memory interval from start to end. |
| 847 | // This interval is considered to belong to the map space. |
| 848 | // Return true if pointers to new space was found. |
| 849 | static bool IteratePointersInDirtyMapsRegion(Address start, |
| 850 | Address end, |
| 851 | ObjectSlotCallback callback); |
| 852 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | |
| 854 | // Returns whether the object resides in new space. |
| 855 | static inline bool InNewSpace(Object* object); |
| 856 | static inline bool InFromSpace(Object* object); |
| 857 | static inline bool InToSpace(Object* object); |
| 858 | |
| 859 | // Checks whether an address/object in the heap (including auxiliary |
| 860 | // area and unused area). |
| 861 | static bool Contains(Address addr); |
| 862 | static bool Contains(HeapObject* value); |
| 863 | |
| 864 | // Checks whether an address/object in a space. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 865 | // Currently used by tests, serialization and heap verification only. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 866 | static bool InSpace(Address addr, AllocationSpace space); |
| 867 | static bool InSpace(HeapObject* value, AllocationSpace space); |
| 868 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 869 | // Finds out which space an object should get promoted to based on its type. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 870 | static inline OldSpace* TargetSpace(HeapObject* object); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 871 | static inline AllocationSpace TargetSpaceId(InstanceType type); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 872 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | // Sets the stub_cache_ (only used when expanding the dictionary). |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 874 | static void public_set_code_stubs(NumberDictionary* value) { |
| 875 | roots_[kCodeStubsRootIndex] = value; |
| 876 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 877 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 878 | // Support for computing object sizes for old objects during GCs. Returns |
| 879 | // a function that is guaranteed to be safe for computing object sizes in |
| 880 | // the current GC phase. |
| 881 | static HeapObjectCallback GcSafeSizeOfOldObjectFunction() { |
| 882 | return gc_safe_size_of_old_object_; |
| 883 | } |
| 884 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | // Sets the non_monomorphic_cache_ (only used when expanding the dictionary). |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 886 | static void public_set_non_monomorphic_cache(NumberDictionary* value) { |
| 887 | roots_[kNonMonomorphicCacheRootIndex] = value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | } |
| 889 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 890 | static void public_set_empty_script(Script* script) { |
| 891 | roots_[kEmptyScriptRootIndex] = script; |
| 892 | } |
| 893 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 894 | // Update the next script id. |
| 895 | static inline void SetLastScriptId(Object* last_script_id); |
| 896 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 897 | // Generated code can embed this address to get access to the roots. |
| 898 | static Object** roots_address() { return roots_; } |
| 899 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 900 | // Get address of global contexts list for serialization support. |
| 901 | static Object** global_contexts_list_address() { |
| 902 | return &global_contexts_list_; |
| 903 | } |
| 904 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 905 | #ifdef DEBUG |
| 906 | static void Print(); |
| 907 | static void PrintHandles(); |
| 908 | |
| 909 | // Verify the heap is in its normal state before or after a GC. |
| 910 | static void Verify(); |
| 911 | |
| 912 | // Report heap statistics. |
| 913 | static void ReportHeapStatistics(const char* title); |
| 914 | static void ReportCodeStatistics(const char* title); |
| 915 | |
| 916 | // Fill in bogus values in from space |
| 917 | static void ZapFromSpace(); |
| 918 | #endif |
| 919 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 920 | #if defined(ENABLE_LOGGING_AND_PROFILING) |
| 921 | // Print short heap statistics. |
| 922 | static void PrintShortHeapStatistics(); |
| 923 | #endif |
| 924 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 925 | // Makes a new symbol object |
| 926 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 927 | // failed. |
| 928 | // Please note this function does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 929 | MUST_USE_RESULT static MaybeObject* CreateSymbol(const char* str, |
| 930 | int length, |
| 931 | int hash); |
| 932 | MUST_USE_RESULT static MaybeObject* CreateSymbol(String* str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 933 | |
| 934 | // Write barrier support for address[offset] = o. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 935 | static inline void RecordWrite(Address address, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 937 | // Write barrier support for address[start : start + len[ = o. |
| 938 | static inline void RecordWrites(Address address, int start, int len); |
| 939 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 940 | // Given an address occupied by a live code object, return that object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 941 | static Object* FindCodeObject(Address a); |
| 942 | |
| 943 | // Invoke Shrink on shrinkable spaces. |
| 944 | static void Shrink(); |
| 945 | |
| 946 | enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; |
| 947 | static inline HeapState gc_state() { return gc_state_; } |
| 948 | |
| 949 | #ifdef DEBUG |
| 950 | static bool IsAllocationAllowed() { return allocation_allowed_; } |
| 951 | static inline bool allow_allocation(bool enable); |
| 952 | |
| 953 | static bool disallow_allocation_failure() { |
| 954 | return disallow_allocation_failure_; |
| 955 | } |
| 956 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 957 | static void TracePathToObject(Object* target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 958 | static void TracePathToGlobal(); |
| 959 | #endif |
| 960 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 961 | // Callback function passed to Heap::Iterate etc. Copies an object if |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 962 | // necessary, the object might be promoted to an old space. The caller must |
| 963 | // ensure the precondition that the object is (a) a heap object and (b) in |
| 964 | // the heap's from space. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 965 | static void ScavengePointer(HeapObject** p); |
| 966 | static inline void ScavengeObject(HeapObject** p, HeapObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 967 | |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 968 | // Commits from space if it is uncommitted. |
| 969 | static void EnsureFromSpaceIsCommitted(); |
| 970 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 971 | // Support for partial snapshots. After calling this we can allocate a |
| 972 | // certain number of bytes using only linear allocation (with a |
| 973 | // LinearAllocationScope and an AlwaysAllocateScope) without using freelists |
| 974 | // or causing a GC. It returns true of space was reserved or false if a GC is |
| 975 | // needed. For paged spaces the space requested must include the space wasted |
| 976 | // at the end of each page when allocating linearly. |
| 977 | static void ReserveSpace( |
| 978 | int new_space_size, |
| 979 | int pointer_space_size, |
| 980 | int data_space_size, |
| 981 | int code_space_size, |
| 982 | int map_space_size, |
| 983 | int cell_space_size, |
| 984 | int large_object_size); |
| 985 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 986 | // |
| 987 | // Support for the API. |
| 988 | // |
| 989 | |
| 990 | static bool CreateApiObjects(); |
| 991 | |
| 992 | // Attempt to find the number in a small cache. If we finds it, return |
| 993 | // the string representation of the number. Otherwise return undefined. |
| 994 | static Object* GetNumberStringCache(Object* number); |
| 995 | |
| 996 | // Update the cache with a new number-string pair. |
| 997 | static void SetNumberStringCache(Object* number, String* str); |
| 998 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 999 | // Adjusts the amount of registered external memory. |
| 1000 | // Returns the adjusted value. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1001 | static inline int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1002 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1003 | // Allocate uninitialized fixed array. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1004 | MUST_USE_RESULT static MaybeObject* AllocateRawFixedArray(int length); |
| 1005 | MUST_USE_RESULT static MaybeObject* AllocateRawFixedArray( |
| 1006 | int length, |
| 1007 | PretenureFlag pretenure); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1008 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1009 | // True if we have reached the allocation limit in the old generation that |
| 1010 | // should force the next GC (caused normally) to be a full one. |
| 1011 | static bool OldGenerationPromotionLimitReached() { |
| 1012 | return (PromotedSpaceSize() + PromotedExternalMemorySize()) |
| 1013 | > old_gen_promotion_limit_; |
| 1014 | } |
| 1015 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1016 | static intptr_t OldGenerationSpaceAvailable() { |
| 1017 | return old_gen_allocation_limit_ - |
| 1018 | (PromotedSpaceSize() + PromotedExternalMemorySize()); |
| 1019 | } |
| 1020 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1021 | // True if we have reached the allocation limit in the old generation that |
| 1022 | // should artificially cause a GC right now. |
| 1023 | static bool OldGenerationAllocationLimitReached() { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1024 | return OldGenerationSpaceAvailable() < 0; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1027 | // Can be called when the embedding application is idle. |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 1028 | static bool IdleNotification(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Declare all the root indices. |
| 1031 | enum RootListIndex { |
| 1032 | #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, |
| 1033 | STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) |
| 1034 | #undef ROOT_INDEX_DECLARATION |
| 1035 | |
| 1036 | // Utility type maps |
| 1037 | #define DECLARE_STRUCT_MAP(NAME, Name, name) k##Name##MapRootIndex, |
| 1038 | STRUCT_LIST(DECLARE_STRUCT_MAP) |
| 1039 | #undef DECLARE_STRUCT_MAP |
| 1040 | |
| 1041 | #define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex, |
| 1042 | SYMBOL_LIST(SYMBOL_INDEX_DECLARATION) |
| 1043 | #undef SYMBOL_DECLARATION |
| 1044 | |
| 1045 | kSymbolTableRootIndex, |
| 1046 | kStrongRootListLength = kSymbolTableRootIndex, |
| 1047 | kRootListLength |
| 1048 | }; |
| 1049 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1050 | MUST_USE_RESULT static MaybeObject* NumberToString( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1051 | Object* number, |
| 1052 | bool check_number_string_cache = true); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1053 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1054 | static Map* MapForExternalArrayType(ExternalArrayType array_type); |
| 1055 | static RootListIndex RootIndexForExternalArrayType( |
| 1056 | ExternalArrayType array_type); |
| 1057 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1058 | static void RecordStats(HeapStats* stats, bool take_snapshot = false); |
ager@chromium.org | 6012123 | 2009-12-03 11:25:37 +0000 | [diff] [blame] | 1059 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1060 | // Copy block of memory from src to dst. Size of block should be aligned |
| 1061 | // by pointer size. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1062 | static inline void CopyBlock(Address dst, Address src, int byte_size); |
| 1063 | |
| 1064 | static inline void CopyBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 1065 | Address src, |
| 1066 | int byte_size); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1067 | |
| 1068 | // Optimized version of memmove for blocks with pointer size aligned sizes and |
| 1069 | // pointer size aligned addresses. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1070 | static inline void MoveBlock(Address dst, Address src, int byte_size); |
| 1071 | |
| 1072 | static inline void MoveBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 1073 | Address src, |
| 1074 | int byte_size); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Check new space expansion criteria and expand semispaces if it was hit. |
| 1077 | static void CheckNewSpaceExpansionCriteria(); |
| 1078 | |
| 1079 | static inline void IncrementYoungSurvivorsCounter(int survived) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1080 | young_survivors_after_last_gc_ = survived; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1081 | survived_since_last_expansion_ += survived; |
| 1082 | } |
| 1083 | |
| 1084 | static void UpdateNewSpaceReferencesInExternalStringTable( |
| 1085 | ExternalStringTableUpdaterCallback updater_func); |
| 1086 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1087 | static void ProcessWeakReferences(WeakObjectRetainer* retainer); |
| 1088 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1089 | // Helper function that governs the promotion policy from new space to |
| 1090 | // old. If the object's old address lies below the new space's age |
| 1091 | // mark or if we've already filled the bottom 1/16th of the to space, |
| 1092 | // we try to promote this object. |
| 1093 | static inline bool ShouldBePromoted(Address old_address, int object_size); |
| 1094 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1095 | static int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
| 1096 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1097 | static void ClearJSFunctionResultCaches(); |
| 1098 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1099 | static void ClearNormalizedMapCaches(); |
| 1100 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1101 | static GCTracer* tracer() { return tracer_; } |
| 1102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1103 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1104 | static int reserved_semispace_size_; |
| 1105 | static int max_semispace_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1106 | static int initial_semispace_size_; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1107 | static intptr_t max_old_generation_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 1108 | static intptr_t max_executable_size_; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1109 | static intptr_t code_range_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1110 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1111 | // For keeping track of how much data has survived |
| 1112 | // scavenge since last new space expansion. |
| 1113 | static int survived_since_last_expansion_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1114 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1115 | static int always_allocate_scope_depth_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1116 | static int linear_allocation_scope_depth_; |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 1117 | |
| 1118 | // For keeping track of context disposals. |
| 1119 | static int contexts_disposed_; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1120 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1121 | #if defined(V8_TARGET_ARCH_X64) |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame^] | 1122 | static const int kMaxObjectSizeInNewSpace = 1024*KB; |
lrn@chromium.org | 8541d77 | 2010-12-15 12:05:09 +0000 | [diff] [blame] | 1123 | #else |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame^] | 1124 | static const int kMaxObjectSizeInNewSpace = 512*KB; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1125 | #endif |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1126 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1127 | static NewSpace new_space_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1128 | static OldSpace* old_pointer_space_; |
| 1129 | static OldSpace* old_data_space_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1130 | static OldSpace* code_space_; |
| 1131 | static MapSpace* map_space_; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1132 | static CellSpace* cell_space_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1133 | static LargeObjectSpace* lo_space_; |
| 1134 | static HeapState gc_state_; |
| 1135 | |
| 1136 | // Returns the size of object residing in non new spaces. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1137 | static intptr_t PromotedSpaceSize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1138 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1139 | // Returns the amount of external memory registered since last global gc. |
| 1140 | static int PromotedExternalMemorySize(); |
| 1141 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | static int mc_count_; // how many mark-compact collections happened |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1143 | static int ms_count_; // how many mark-sweep collections happened |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1144 | static int gc_count_; // how many gc happened |
| 1145 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1146 | // Total length of the strings we failed to flatten since the last GC. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1147 | static int unflattened_strings_length_; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1148 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1149 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 1150 | static inline void set_##name(type* value) { \ |
| 1151 | roots_[k##camel_name##RootIndex] = value; \ |
| 1152 | } |
| 1153 | ROOT_LIST(ROOT_ACCESSOR) |
| 1154 | #undef ROOT_ACCESSOR |
| 1155 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1156 | #ifdef DEBUG |
| 1157 | static bool allocation_allowed_; |
| 1158 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1159 | // If the --gc-interval flag is set to a positive value, this |
| 1160 | // variable holds the value indicating the number of allocations |
| 1161 | // remain until the next failure and garbage collection. |
| 1162 | static int allocation_timeout_; |
| 1163 | |
| 1164 | // Do we expect to be able to handle allocation failure at this |
| 1165 | // time? |
| 1166 | static bool disallow_allocation_failure_; |
| 1167 | #endif // DEBUG |
| 1168 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1169 | // Limit that triggers a global GC on the next (normally caused) GC. This |
| 1170 | // is checked when we have already decided to do a GC to help determine |
| 1171 | // which collector to invoke. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1172 | static intptr_t old_gen_promotion_limit_; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1173 | |
| 1174 | // Limit that triggers a global GC as soon as is reasonable. This is |
| 1175 | // checked before expanding a paged space in the old generation and on |
| 1176 | // every allocation in large object space. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1177 | static intptr_t old_gen_allocation_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1178 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1179 | // Limit on the amount of externally allocated memory allowed |
| 1180 | // between global GCs. If reached a global GC is forced. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1181 | static intptr_t external_allocation_limit_; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1182 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1183 | // The amount of external memory registered through the API kept alive |
| 1184 | // by global handles |
| 1185 | static int amount_of_external_allocated_memory_; |
| 1186 | |
| 1187 | // Caches the amount of external memory registered at the last global gc. |
| 1188 | static int amount_of_external_allocated_memory_at_last_global_gc_; |
| 1189 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1190 | // Indicates that an allocation has failed in the old generation since the |
| 1191 | // last GC. |
| 1192 | static int old_gen_exhausted_; |
| 1193 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1194 | static Object* roots_[kRootListLength]; |
| 1195 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1196 | static Object* global_contexts_list_; |
| 1197 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1198 | struct StringTypeTable { |
| 1199 | InstanceType type; |
| 1200 | int size; |
| 1201 | RootListIndex index; |
| 1202 | }; |
| 1203 | |
| 1204 | struct ConstantSymbolTable { |
| 1205 | const char* contents; |
| 1206 | RootListIndex index; |
| 1207 | }; |
| 1208 | |
| 1209 | struct StructTable { |
| 1210 | InstanceType type; |
| 1211 | int size; |
| 1212 | RootListIndex index; |
| 1213 | }; |
| 1214 | |
| 1215 | static const StringTypeTable string_type_table[]; |
| 1216 | static const ConstantSymbolTable constant_symbol_table[]; |
| 1217 | static const StructTable struct_table[]; |
| 1218 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1219 | // The special hidden symbol which is an empty string, but does not match |
| 1220 | // any string when looked up in properties. |
| 1221 | static String* hidden_symbol_; |
| 1222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | // GC callback function, called before and after mark-compact GC. |
| 1224 | // Allocations in the callback function are disallowed. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1225 | struct GCPrologueCallbackPair { |
| 1226 | GCPrologueCallbackPair(GCPrologueCallback callback, GCType gc_type) |
| 1227 | : callback(callback), gc_type(gc_type) { |
| 1228 | } |
| 1229 | bool operator==(const GCPrologueCallbackPair& pair) const { |
| 1230 | return pair.callback == callback; |
| 1231 | } |
| 1232 | GCPrologueCallback callback; |
| 1233 | GCType gc_type; |
| 1234 | }; |
| 1235 | static List<GCPrologueCallbackPair> gc_prologue_callbacks_; |
| 1236 | |
| 1237 | struct GCEpilogueCallbackPair { |
| 1238 | GCEpilogueCallbackPair(GCEpilogueCallback callback, GCType gc_type) |
| 1239 | : callback(callback), gc_type(gc_type) { |
| 1240 | } |
| 1241 | bool operator==(const GCEpilogueCallbackPair& pair) const { |
| 1242 | return pair.callback == callback; |
| 1243 | } |
| 1244 | GCEpilogueCallback callback; |
| 1245 | GCType gc_type; |
| 1246 | }; |
| 1247 | static List<GCEpilogueCallbackPair> gc_epilogue_callbacks_; |
| 1248 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | static GCCallback global_gc_prologue_callback_; |
| 1250 | static GCCallback global_gc_epilogue_callback_; |
| 1251 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1252 | // Support for computing object sizes during GC. |
| 1253 | static HeapObjectCallback gc_safe_size_of_old_object_; |
| 1254 | static int GcSafeSizeOfOldObject(HeapObject* object); |
| 1255 | static int GcSafeSizeOfOldObjectWithEncodedMap(HeapObject* object); |
| 1256 | |
| 1257 | // Update the GC state. Called from the mark-compact collector. |
| 1258 | static void MarkMapPointersAsEncoded(bool encoded) { |
| 1259 | gc_safe_size_of_old_object_ = encoded |
| 1260 | ? &GcSafeSizeOfOldObjectWithEncodedMap |
| 1261 | : &GcSafeSizeOfOldObject; |
| 1262 | } |
| 1263 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | // Checks whether a global GC is necessary |
| 1265 | static GarbageCollector SelectGarbageCollector(AllocationSpace space); |
| 1266 | |
| 1267 | // Performs garbage collection |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1268 | // Returns whether there is a chance another major GC could |
| 1269 | // collect more garbage. |
| 1270 | static bool PerformGarbageCollection(GarbageCollector collector, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1271 | GCTracer* tracer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1272 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1273 | // Allocate an uninitialized object in map space. The behavior is identical |
| 1274 | // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't |
| 1275 | // have to test the allocation space argument and (b) can reduce code size |
| 1276 | // (since both AllocateRaw and AllocateRawMap are inlined). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1277 | MUST_USE_RESULT static inline MaybeObject* AllocateRawMap(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1278 | |
| 1279 | // Allocate an uninitialized object in the global property cell space. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1280 | MUST_USE_RESULT static inline MaybeObject* AllocateRawCell(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | // Initializes a JSObject based on its map. |
| 1283 | static void InitializeJSObjectFromMap(JSObject* obj, |
| 1284 | FixedArray* properties, |
| 1285 | Map* map); |
| 1286 | |
| 1287 | static bool CreateInitialMaps(); |
| 1288 | static bool CreateInitialObjects(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1289 | |
sgjesse@chromium.org | 76ae699 | 2010-08-05 15:54:25 +0000 | [diff] [blame] | 1290 | // These four Create*EntryStub functions are here and forced to not be inlined |
| 1291 | // because of a gcc-4.4 bug that assigns wrong vtable entries. |
| 1292 | NO_INLINE(static void CreateCEntryStub()); |
| 1293 | NO_INLINE(static void CreateJSEntryStub()); |
| 1294 | NO_INLINE(static void CreateJSConstructEntryStub()); |
| 1295 | NO_INLINE(static void CreateRegExpCEntryStub()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1296 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | static void CreateFixedStubs(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1298 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1299 | MUST_USE_RESULT static MaybeObject* CreateOddball(const char* to_string, |
| 1300 | Object* to_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | |
| 1302 | // Allocate empty fixed array. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1303 | MUST_USE_RESULT static MaybeObject* AllocateEmptyFixedArray(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | |
| 1305 | // Performs a minor collection in new generation. |
| 1306 | static void Scavenge(); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1307 | |
| 1308 | static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
| 1309 | Object** pointer); |
| 1310 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1311 | static Address DoScavenge(ObjectVisitor* scavenge_visitor, |
| 1312 | Address new_space_front); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | |
| 1314 | // Performs a major collection in the whole heap. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1315 | static void MarkCompact(GCTracer* tracer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | |
| 1317 | // Code to be run before and after mark-compact. |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1318 | static void MarkCompactPrologue(bool is_compacting); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1320 | // Completely clear the Instanceof cache (to stop it keeping objects alive |
| 1321 | // around a GC). |
| 1322 | static void CompletelyClearInstanceofCache() { |
| 1323 | set_instanceof_cache_map(the_hole_value()); |
| 1324 | set_instanceof_cache_function(the_hole_value()); |
| 1325 | } |
| 1326 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1327 | #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1328 | // Record statistics before and after garbage collection. |
| 1329 | static void ReportStatisticsBeforeGC(); |
| 1330 | static void ReportStatisticsAfterGC(); |
| 1331 | #endif |
| 1332 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1333 | // Slow part of scavenge object. |
| 1334 | static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
| 1335 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1336 | // Initializes a function with a shared part and prototype. |
| 1337 | // Returns the function. |
| 1338 | // Note: this code was factored out of AllocateFunction such that |
| 1339 | // other parts of the VM could use it. Specifically, a function that creates |
| 1340 | // instances of type JS_FUNCTION_TYPE benefit from the use of this function. |
| 1341 | // Please note this does not perform a garbage collection. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1342 | MUST_USE_RESULT static inline MaybeObject* InitializeFunction( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1343 | JSFunction* function, |
| 1344 | SharedFunctionInfo* shared, |
| 1345 | Object* prototype); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1346 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1347 | static GCTracer* tracer_; |
| 1348 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1349 | |
| 1350 | // Initializes the number to string cache based on the max semispace size. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1351 | MUST_USE_RESULT static MaybeObject* InitializeNumberStringCache(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1352 | // Flush the number to string cache. |
| 1353 | static void FlushNumberStringCache(); |
| 1354 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1355 | static void UpdateSurvivalRateTrend(int start_new_space_size); |
| 1356 | |
| 1357 | enum SurvivalRateTrend { INCREASING, STABLE, DECREASING, FLUCTUATING }; |
| 1358 | |
| 1359 | static const int kYoungSurvivalRateThreshold = 90; |
| 1360 | static const int kYoungSurvivalRateAllowedDeviation = 15; |
| 1361 | |
| 1362 | static int young_survivors_after_last_gc_; |
| 1363 | static int high_survival_rate_period_length_; |
| 1364 | static double survival_rate_; |
| 1365 | static SurvivalRateTrend previous_survival_rate_trend_; |
| 1366 | static SurvivalRateTrend survival_rate_trend_; |
| 1367 | |
| 1368 | static void set_survival_rate_trend(SurvivalRateTrend survival_rate_trend) { |
| 1369 | ASSERT(survival_rate_trend != FLUCTUATING); |
| 1370 | previous_survival_rate_trend_ = survival_rate_trend_; |
| 1371 | survival_rate_trend_ = survival_rate_trend; |
| 1372 | } |
| 1373 | |
| 1374 | static SurvivalRateTrend survival_rate_trend() { |
| 1375 | if (survival_rate_trend_ == STABLE) { |
| 1376 | return STABLE; |
| 1377 | } else if (previous_survival_rate_trend_ == STABLE) { |
| 1378 | return survival_rate_trend_; |
| 1379 | } else if (survival_rate_trend_ != previous_survival_rate_trend_) { |
| 1380 | return FLUCTUATING; |
| 1381 | } else { |
| 1382 | return survival_rate_trend_; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | static bool IsStableOrIncreasingSurvivalTrend() { |
| 1387 | switch (survival_rate_trend()) { |
| 1388 | case STABLE: |
| 1389 | case INCREASING: |
| 1390 | return true; |
| 1391 | default: |
| 1392 | return false; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | static bool IsIncreasingSurvivalTrend() { |
| 1397 | return survival_rate_trend() == INCREASING; |
| 1398 | } |
| 1399 | |
| 1400 | static bool IsHighSurvivalRate() { |
| 1401 | return high_survival_rate_period_length_ > 0; |
| 1402 | } |
| 1403 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1404 | static const int kInitialSymbolTableSize = 2048; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1405 | static const int kInitialEvalCacheSize = 64; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1406 | |
| 1407 | friend class Factory; |
| 1408 | friend class DisallowAllocationFailure; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1409 | friend class AlwaysAllocateScope; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1410 | friend class LinearAllocationScope; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1411 | friend class MarkCompactCollector; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1412 | }; |
| 1413 | |
| 1414 | |
ager@chromium.org | 6736865 | 2009-12-03 11:40:49 +0000 | [diff] [blame] | 1415 | class HeapStats { |
| 1416 | public: |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1417 | static const int kStartMarker = 0xDECADE00; |
| 1418 | static const int kEndMarker = 0xDECADE01; |
| 1419 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1420 | int* start_marker; // 0 |
| 1421 | int* new_space_size; // 1 |
| 1422 | int* new_space_capacity; // 2 |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1423 | intptr_t* old_pointer_space_size; // 3 |
| 1424 | intptr_t* old_pointer_space_capacity; // 4 |
| 1425 | intptr_t* old_data_space_size; // 5 |
| 1426 | intptr_t* old_data_space_capacity; // 6 |
| 1427 | intptr_t* code_space_size; // 7 |
| 1428 | intptr_t* code_space_capacity; // 8 |
| 1429 | intptr_t* map_space_size; // 9 |
| 1430 | intptr_t* map_space_capacity; // 10 |
| 1431 | intptr_t* cell_space_size; // 11 |
| 1432 | intptr_t* cell_space_capacity; // 12 |
| 1433 | intptr_t* lo_space_size; // 13 |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1434 | int* global_handle_count; // 14 |
| 1435 | int* weak_global_handle_count; // 15 |
| 1436 | int* pending_global_handle_count; // 16 |
| 1437 | int* near_death_global_handle_count; // 17 |
| 1438 | int* destroyed_global_handle_count; // 18 |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1439 | intptr_t* memory_allocator_size; // 19 |
| 1440 | intptr_t* memory_allocator_capacity; // 20 |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1441 | int* objects_per_type; // 21 |
| 1442 | int* size_per_type; // 22 |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1443 | int* os_error; // 23 |
| 1444 | int* end_marker; // 24 |
ager@chromium.org | 6012123 | 2009-12-03 11:25:37 +0000 | [diff] [blame] | 1445 | }; |
| 1446 | |
| 1447 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1448 | class AlwaysAllocateScope { |
| 1449 | public: |
| 1450 | AlwaysAllocateScope() { |
| 1451 | // We shouldn't hit any nested scopes, because that requires |
| 1452 | // non-handle code to call handle code. The code still works but |
| 1453 | // performance will degrade, so we want to catch this situation |
| 1454 | // in debug mode. |
| 1455 | ASSERT(Heap::always_allocate_scope_depth_ == 0); |
| 1456 | Heap::always_allocate_scope_depth_++; |
| 1457 | } |
| 1458 | |
| 1459 | ~AlwaysAllocateScope() { |
| 1460 | Heap::always_allocate_scope_depth_--; |
| 1461 | ASSERT(Heap::always_allocate_scope_depth_ == 0); |
| 1462 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1463 | }; |
| 1464 | |
| 1465 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1466 | class LinearAllocationScope { |
| 1467 | public: |
| 1468 | LinearAllocationScope() { |
| 1469 | Heap::linear_allocation_scope_depth_++; |
| 1470 | } |
| 1471 | |
| 1472 | ~LinearAllocationScope() { |
| 1473 | Heap::linear_allocation_scope_depth_--; |
| 1474 | ASSERT(Heap::linear_allocation_scope_depth_ >= 0); |
| 1475 | } |
| 1476 | }; |
| 1477 | |
| 1478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | #ifdef DEBUG |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1480 | // Visitor class to verify interior pointers in spaces that do not contain |
| 1481 | // or care about intergenerational references. All heap object pointers have to |
| 1482 | // point into the heap to a location that has a map pointer at its first word. |
| 1483 | // Caveat: Heap::Contains is an approximation because it can return true for |
| 1484 | // objects in a heap space but above the allocation pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | class VerifyPointersVisitor: public ObjectVisitor { |
| 1486 | public: |
| 1487 | void VisitPointers(Object** start, Object** end) { |
| 1488 | for (Object** current = start; current < end; current++) { |
| 1489 | if ((*current)->IsHeapObject()) { |
| 1490 | HeapObject* object = HeapObject::cast(*current); |
| 1491 | ASSERT(Heap::Contains(object)); |
| 1492 | ASSERT(object->map()->IsMap()); |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | }; |
| 1497 | |
| 1498 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1499 | // Visitor class to verify interior pointers in spaces that use region marks |
| 1500 | // to keep track of intergenerational references. |
| 1501 | // As VerifyPointersVisitor but also checks that dirty marks are set |
| 1502 | // for regions covering intergenerational references. |
| 1503 | class VerifyPointersAndDirtyRegionsVisitor: public ObjectVisitor { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1504 | public: |
| 1505 | void VisitPointers(Object** start, Object** end) { |
| 1506 | for (Object** current = start; current < end; current++) { |
| 1507 | if ((*current)->IsHeapObject()) { |
| 1508 | HeapObject* object = HeapObject::cast(*current); |
| 1509 | ASSERT(Heap::Contains(object)); |
| 1510 | ASSERT(object->map()->IsMap()); |
| 1511 | if (Heap::InNewSpace(object)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1512 | ASSERT(Heap::InToSpace(object)); |
| 1513 | Address addr = reinterpret_cast<Address>(current); |
| 1514 | ASSERT(Page::FromAddress(addr)->IsRegionDirty(addr)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | } |
| 1519 | }; |
| 1520 | #endif |
| 1521 | |
| 1522 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1523 | // Space iterator for iterating over all spaces of the heap. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1524 | // Returns each space in turn, and null when it is done. |
| 1525 | class AllSpaces BASE_EMBEDDED { |
| 1526 | public: |
| 1527 | Space* next(); |
| 1528 | AllSpaces() { counter_ = FIRST_SPACE; } |
| 1529 | private: |
| 1530 | int counter_; |
| 1531 | }; |
| 1532 | |
| 1533 | |
| 1534 | // Space iterator for iterating over all old spaces of the heap: Old pointer |
| 1535 | // space, old data space and code space. |
| 1536 | // Returns each space in turn, and null when it is done. |
| 1537 | class OldSpaces BASE_EMBEDDED { |
| 1538 | public: |
| 1539 | OldSpace* next(); |
| 1540 | OldSpaces() { counter_ = OLD_POINTER_SPACE; } |
| 1541 | private: |
| 1542 | int counter_; |
| 1543 | }; |
| 1544 | |
| 1545 | |
| 1546 | // Space iterator for iterating over all the paged spaces of the heap: |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1547 | // Map space, old pointer space, old data space, code space and cell space. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1548 | // Returns each space in turn, and null when it is done. |
| 1549 | class PagedSpaces BASE_EMBEDDED { |
| 1550 | public: |
| 1551 | PagedSpace* next(); |
| 1552 | PagedSpaces() { counter_ = OLD_POINTER_SPACE; } |
| 1553 | private: |
| 1554 | int counter_; |
| 1555 | }; |
| 1556 | |
| 1557 | |
| 1558 | // Space iterator for iterating over all spaces of the heap. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1559 | // For each space an object iterator is provided. The deallocation of the |
| 1560 | // returned object iterators is handled by the space iterator. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1561 | class SpaceIterator : public Malloced { |
| 1562 | public: |
| 1563 | SpaceIterator(); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1564 | explicit SpaceIterator(HeapObjectCallback size_func); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1565 | virtual ~SpaceIterator(); |
| 1566 | |
| 1567 | bool has_next(); |
| 1568 | ObjectIterator* next(); |
| 1569 | |
| 1570 | private: |
| 1571 | ObjectIterator* CreateIterator(); |
| 1572 | |
| 1573 | int current_space_; // from enum AllocationSpace. |
| 1574 | ObjectIterator* iterator_; // object iterator for the current space. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1575 | HeapObjectCallback size_func_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1576 | }; |
| 1577 | |
| 1578 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1579 | // A HeapIterator provides iteration over the whole heap. It |
| 1580 | // aggregates the specific iterators for the different spaces as |
| 1581 | // these can only iterate over one space only. |
| 1582 | // |
| 1583 | // HeapIterator can skip free list nodes (that is, de-allocated heap |
| 1584 | // objects that still remain in the heap). As implementation of free |
| 1585 | // nodes filtering uses GC marks, it can't be used during MS/MC GC |
| 1586 | // phases. Also, it is forbidden to interrupt iteration in this mode, |
| 1587 | // as this will leave heap objects marked (and thus, unusable). |
| 1588 | class FreeListNodesFilter; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1589 | |
| 1590 | class HeapIterator BASE_EMBEDDED { |
| 1591 | public: |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1592 | enum FreeListNodesFiltering { |
| 1593 | kNoFiltering, |
| 1594 | kPreciseFiltering |
| 1595 | }; |
| 1596 | |
| 1597 | HeapIterator(); |
| 1598 | explicit HeapIterator(FreeListNodesFiltering filtering); |
| 1599 | ~HeapIterator(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1600 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1601 | HeapObject* next(); |
| 1602 | void reset(); |
| 1603 | |
| 1604 | private: |
| 1605 | // Perform the initialization. |
| 1606 | void Init(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1607 | // Perform all necessary shutdown (destruction) work. |
| 1608 | void Shutdown(); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1609 | HeapObject* NextObject(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1610 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1611 | FreeListNodesFiltering filtering_; |
| 1612 | FreeListNodesFilter* filter_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1613 | // Space iterator for iterating all the spaces. |
| 1614 | SpaceIterator* space_iterator_; |
| 1615 | // Object iterator for the space currently being iterated. |
| 1616 | ObjectIterator* object_iterator_; |
| 1617 | }; |
| 1618 | |
| 1619 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1620 | // Cache for mapping (map, property name) into field offset. |
| 1621 | // Cleared at startup and prior to mark sweep collection. |
| 1622 | class KeyedLookupCache { |
| 1623 | public: |
| 1624 | // Lookup field offset for (map, name). If absent, -1 is returned. |
| 1625 | static int Lookup(Map* map, String* name); |
| 1626 | |
| 1627 | // Update an element in the cache. |
| 1628 | static void Update(Map* map, String* name, int field_offset); |
| 1629 | |
| 1630 | // Clear the cache. |
| 1631 | static void Clear(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1632 | |
| 1633 | static const int kLength = 64; |
| 1634 | static const int kCapacityMask = kLength - 1; |
| 1635 | static const int kMapHashShift = 2; |
| 1636 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1637 | private: |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1638 | static inline int Hash(Map* map, String* name); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1639 | |
| 1640 | // Get the address of the keys and field_offsets arrays. Used in |
| 1641 | // generated code to perform cache lookups. |
| 1642 | static Address keys_address() { |
| 1643 | return reinterpret_cast<Address>(&keys_); |
| 1644 | } |
| 1645 | |
| 1646 | static Address field_offsets_address() { |
| 1647 | return reinterpret_cast<Address>(&field_offsets_); |
| 1648 | } |
| 1649 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1650 | struct Key { |
| 1651 | Map* map; |
| 1652 | String* name; |
| 1653 | }; |
| 1654 | static Key keys_[kLength]; |
| 1655 | static int field_offsets_[kLength]; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1656 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1657 | friend class ExternalReference; |
| 1658 | }; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1659 | |
| 1660 | |
| 1661 | // Cache for mapping (array, property name) into descriptor index. |
| 1662 | // The cache contains both positive and negative results. |
| 1663 | // Descriptor index equals kNotFound means the property is absent. |
| 1664 | // Cleared at startup and prior to any gc. |
| 1665 | class DescriptorLookupCache { |
| 1666 | public: |
| 1667 | // Lookup descriptor index for (map, name). |
| 1668 | // If absent, kAbsent is returned. |
| 1669 | static int Lookup(DescriptorArray* array, String* name) { |
| 1670 | if (!StringShape(name).IsSymbol()) return kAbsent; |
| 1671 | int index = Hash(array, name); |
| 1672 | Key& key = keys_[index]; |
| 1673 | if ((key.array == array) && (key.name == name)) return results_[index]; |
| 1674 | return kAbsent; |
| 1675 | } |
| 1676 | |
| 1677 | // Update an element in the cache. |
| 1678 | static void Update(DescriptorArray* array, String* name, int result) { |
| 1679 | ASSERT(result != kAbsent); |
| 1680 | if (StringShape(name).IsSymbol()) { |
| 1681 | int index = Hash(array, name); |
| 1682 | Key& key = keys_[index]; |
| 1683 | key.array = array; |
| 1684 | key.name = name; |
| 1685 | results_[index] = result; |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | // Clear the cache. |
| 1690 | static void Clear(); |
| 1691 | |
| 1692 | static const int kAbsent = -2; |
| 1693 | private: |
| 1694 | static int Hash(DescriptorArray* array, String* name) { |
| 1695 | // Uses only lower 32 bits if pointers are larger. |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1696 | uint32_t array_hash = |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1697 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2; |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1698 | uint32_t name_hash = |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1699 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2; |
| 1700 | return (array_hash ^ name_hash) % kLength; |
| 1701 | } |
| 1702 | |
| 1703 | static const int kLength = 64; |
| 1704 | struct Key { |
| 1705 | DescriptorArray* array; |
| 1706 | String* name; |
| 1707 | }; |
| 1708 | |
| 1709 | static Key keys_[kLength]; |
| 1710 | static int results_[kLength]; |
| 1711 | }; |
| 1712 | |
| 1713 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1714 | // ---------------------------------------------------------------------------- |
| 1715 | // Marking stack for tracing live objects. |
| 1716 | |
| 1717 | class MarkingStack { |
| 1718 | public: |
| 1719 | void Initialize(Address low, Address high) { |
| 1720 | top_ = low_ = reinterpret_cast<HeapObject**>(low); |
| 1721 | high_ = reinterpret_cast<HeapObject**>(high); |
| 1722 | overflowed_ = false; |
| 1723 | } |
| 1724 | |
| 1725 | bool is_full() { return top_ >= high_; } |
| 1726 | |
| 1727 | bool is_empty() { return top_ <= low_; } |
| 1728 | |
| 1729 | bool overflowed() { return overflowed_; } |
| 1730 | |
| 1731 | void clear_overflowed() { overflowed_ = false; } |
| 1732 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1733 | // Push the (marked) object on the marking stack if there is room, |
| 1734 | // otherwise mark the object as overflowed and wait for a rescan of the |
| 1735 | // heap. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1736 | void Push(HeapObject* object) { |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1737 | CHECK(object->IsHeapObject()); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1738 | if (is_full()) { |
| 1739 | object->SetOverflow(); |
| 1740 | overflowed_ = true; |
| 1741 | } else { |
| 1742 | *(top_++) = object; |
| 1743 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | HeapObject* Pop() { |
| 1747 | ASSERT(!is_empty()); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1748 | HeapObject* object = *(--top_); |
| 1749 | CHECK(object->IsHeapObject()); |
| 1750 | return object; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | private: |
| 1754 | HeapObject** low_; |
| 1755 | HeapObject** top_; |
| 1756 | HeapObject** high_; |
| 1757 | bool overflowed_; |
| 1758 | }; |
| 1759 | |
| 1760 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1761 | // A helper class to document/test C++ scopes where we do not |
| 1762 | // expect a GC. Usage: |
| 1763 | // |
| 1764 | // /* Allocation not allowed: we cannot handle a GC in this scope. */ |
| 1765 | // { AssertNoAllocation nogc; |
| 1766 | // ... |
| 1767 | // } |
| 1768 | |
| 1769 | #ifdef DEBUG |
| 1770 | |
| 1771 | class DisallowAllocationFailure { |
| 1772 | public: |
| 1773 | DisallowAllocationFailure() { |
| 1774 | old_state_ = Heap::disallow_allocation_failure_; |
| 1775 | Heap::disallow_allocation_failure_ = true; |
| 1776 | } |
| 1777 | ~DisallowAllocationFailure() { |
| 1778 | Heap::disallow_allocation_failure_ = old_state_; |
| 1779 | } |
| 1780 | private: |
| 1781 | bool old_state_; |
| 1782 | }; |
| 1783 | |
| 1784 | class AssertNoAllocation { |
| 1785 | public: |
| 1786 | AssertNoAllocation() { |
| 1787 | old_state_ = Heap::allow_allocation(false); |
| 1788 | } |
| 1789 | |
| 1790 | ~AssertNoAllocation() { |
| 1791 | Heap::allow_allocation(old_state_); |
| 1792 | } |
| 1793 | |
| 1794 | private: |
| 1795 | bool old_state_; |
| 1796 | }; |
| 1797 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1798 | class DisableAssertNoAllocation { |
| 1799 | public: |
| 1800 | DisableAssertNoAllocation() { |
| 1801 | old_state_ = Heap::allow_allocation(true); |
| 1802 | } |
| 1803 | |
| 1804 | ~DisableAssertNoAllocation() { |
| 1805 | Heap::allow_allocation(old_state_); |
| 1806 | } |
| 1807 | |
| 1808 | private: |
| 1809 | bool old_state_; |
| 1810 | }; |
| 1811 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1812 | #else // ndef DEBUG |
| 1813 | |
| 1814 | class AssertNoAllocation { |
| 1815 | public: |
| 1816 | AssertNoAllocation() { } |
| 1817 | ~AssertNoAllocation() { } |
| 1818 | }; |
| 1819 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1820 | class DisableAssertNoAllocation { |
| 1821 | public: |
| 1822 | DisableAssertNoAllocation() { } |
| 1823 | ~DisableAssertNoAllocation() { } |
| 1824 | }; |
| 1825 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1826 | #endif |
| 1827 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1828 | // GCTracer collects and prints ONE line after each garbage collector |
| 1829 | // invocation IFF --trace_gc is used. |
| 1830 | |
| 1831 | class GCTracer BASE_EMBEDDED { |
| 1832 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1833 | class Scope BASE_EMBEDDED { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1834 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1835 | enum ScopeId { |
| 1836 | EXTERNAL, |
| 1837 | MC_MARK, |
| 1838 | MC_SWEEP, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1839 | MC_SWEEP_NEWSPACE, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1840 | MC_COMPACT, |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 1841 | MC_FLUSH_CODE, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1842 | kNumberOfScopes |
| 1843 | }; |
| 1844 | |
| 1845 | Scope(GCTracer* tracer, ScopeId scope) |
| 1846 | : tracer_(tracer), |
| 1847 | scope_(scope) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1848 | start_time_ = OS::TimeCurrentMillis(); |
| 1849 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1850 | |
| 1851 | ~Scope() { |
| 1852 | ASSERT((0 <= scope_) && (scope_ < kNumberOfScopes)); |
| 1853 | tracer_->scopes_[scope_] += OS::TimeCurrentMillis() - start_time_; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1854 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1855 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1856 | private: |
| 1857 | GCTracer* tracer_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1858 | ScopeId scope_; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1859 | double start_time_; |
| 1860 | }; |
| 1861 | |
| 1862 | GCTracer(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1863 | ~GCTracer(); |
| 1864 | |
| 1865 | // Sets the collector. |
| 1866 | void set_collector(GarbageCollector collector) { collector_ = collector; } |
| 1867 | |
| 1868 | // Sets the GC count. |
| 1869 | void set_gc_count(int count) { gc_count_ = count; } |
| 1870 | |
| 1871 | // Sets the full GC count. |
| 1872 | void set_full_gc_count(int count) { full_gc_count_ = count; } |
| 1873 | |
| 1874 | // Sets the flag that this is a compacting full GC. |
| 1875 | void set_is_compacting() { is_compacting_ = true; } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1876 | bool is_compacting() const { return is_compacting_; } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1877 | |
| 1878 | // Increment and decrement the count of marked objects. |
| 1879 | void increment_marked_count() { ++marked_count_; } |
| 1880 | void decrement_marked_count() { --marked_count_; } |
| 1881 | |
| 1882 | int marked_count() { return marked_count_; } |
| 1883 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1884 | void increment_promoted_objects_size(int object_size) { |
| 1885 | promoted_objects_size_ += object_size; |
| 1886 | } |
| 1887 | |
| 1888 | // Returns maximum GC pause. |
| 1889 | static int get_max_gc_pause() { return max_gc_pause_; } |
| 1890 | |
| 1891 | // Returns maximum size of objects alive after GC. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1892 | static intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1893 | |
| 1894 | // Returns minimal interval between two subsequent collections. |
| 1895 | static int get_min_in_mutator() { return min_in_mutator_; } |
| 1896 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1897 | private: |
| 1898 | // Returns a string matching the collector. |
| 1899 | const char* CollectorString(); |
| 1900 | |
| 1901 | // Returns size of object in heap (in MB). |
| 1902 | double SizeOfHeapObjects() { |
| 1903 | return (static_cast<double>(Heap::SizeOfObjects())) / MB; |
| 1904 | } |
| 1905 | |
| 1906 | double start_time_; // Timestamp set in the constructor. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1907 | intptr_t start_size_; // Size of objects in heap set in constructor. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1908 | GarbageCollector collector_; // Type of collector. |
| 1909 | |
| 1910 | // A count (including this one, eg, the first collection is 1) of the |
| 1911 | // number of garbage collections. |
| 1912 | int gc_count_; |
| 1913 | |
| 1914 | // A count (including this one) of the number of full garbage collections. |
| 1915 | int full_gc_count_; |
| 1916 | |
| 1917 | // True if the current GC is a compacting full collection, false |
| 1918 | // otherwise. |
| 1919 | bool is_compacting_; |
| 1920 | |
| 1921 | // True if the *previous* full GC cwas a compacting collection (will be |
| 1922 | // false if there has not been a previous full GC). |
| 1923 | bool previous_has_compacted_; |
| 1924 | |
| 1925 | // On a full GC, a count of the number of marked objects. Incremented |
| 1926 | // when an object is marked and decremented when an object's mark bit is |
| 1927 | // cleared. Will be zero on a scavenge collection. |
| 1928 | int marked_count_; |
| 1929 | |
| 1930 | // The count from the end of the previous full GC. Will be zero if there |
| 1931 | // was no previous full GC. |
| 1932 | int previous_marked_count_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1933 | |
| 1934 | // Amounts of time spent in different scopes during GC. |
| 1935 | double scopes_[Scope::kNumberOfScopes]; |
| 1936 | |
| 1937 | // Total amount of space either wasted or contained in one of free lists |
| 1938 | // before the current GC. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1939 | intptr_t in_free_list_or_wasted_before_gc_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1940 | |
| 1941 | // Difference between space used in the heap at the beginning of the current |
| 1942 | // collection and the end of the previous collection. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1943 | intptr_t allocated_since_last_gc_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Amount of time spent in mutator that is time elapsed between end of the |
| 1946 | // previous collection and the beginning of the current one. |
| 1947 | double spent_in_mutator_; |
| 1948 | |
| 1949 | // Size of objects promoted during the current collection. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1950 | intptr_t promoted_objects_size_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1951 | |
| 1952 | // Maximum GC pause. |
| 1953 | static int max_gc_pause_; |
| 1954 | |
| 1955 | // Maximum size of objects alive after GC. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1956 | static intptr_t max_alive_after_gc_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1957 | |
| 1958 | // Minimal interval between two subsequent collections. |
| 1959 | static int min_in_mutator_; |
| 1960 | |
| 1961 | // Size of objects alive after last GC. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1962 | static intptr_t alive_after_last_gc_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1963 | |
| 1964 | static double last_gc_end_timestamp_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1965 | }; |
| 1966 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1967 | |
| 1968 | class TranscendentalCache { |
| 1969 | public: |
| 1970 | enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches}; |
| 1971 | |
| 1972 | explicit TranscendentalCache(Type t); |
| 1973 | |
| 1974 | // Returns a heap number with f(input), where f is a math function specified |
| 1975 | // by the 'type' argument. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1976 | MUST_USE_RESULT static inline MaybeObject* Get(Type type, double input) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1977 | TranscendentalCache* cache = caches_[type]; |
| 1978 | if (cache == NULL) { |
| 1979 | caches_[type] = cache = new TranscendentalCache(type); |
| 1980 | } |
| 1981 | return cache->Get(input); |
| 1982 | } |
| 1983 | |
| 1984 | // The cache contains raw Object pointers. This method disposes of |
| 1985 | // them before a garbage collection. |
| 1986 | static void Clear(); |
| 1987 | |
| 1988 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1989 | MUST_USE_RESULT inline MaybeObject* Get(double input) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1990 | Converter c; |
| 1991 | c.dbl = input; |
| 1992 | int hash = Hash(c); |
| 1993 | Element e = elements_[hash]; |
| 1994 | if (e.in[0] == c.integers[0] && |
| 1995 | e.in[1] == c.integers[1]) { |
| 1996 | ASSERT(e.output != NULL); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1997 | Counters::transcendental_cache_hit.Increment(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1998 | return e.output; |
| 1999 | } |
| 2000 | double answer = Calculate(input); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2001 | Counters::transcendental_cache_miss.Increment(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2002 | Object* heap_number; |
| 2003 | { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer); |
| 2004 | if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; |
| 2005 | } |
| 2006 | elements_[hash].in[0] = c.integers[0]; |
| 2007 | elements_[hash].in[1] = c.integers[1]; |
| 2008 | elements_[hash].output = heap_number; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2009 | return heap_number; |
| 2010 | } |
| 2011 | |
| 2012 | inline double Calculate(double input) { |
| 2013 | switch (type_) { |
| 2014 | case ACOS: |
| 2015 | return acos(input); |
| 2016 | case ASIN: |
| 2017 | return asin(input); |
| 2018 | case ATAN: |
| 2019 | return atan(input); |
| 2020 | case COS: |
| 2021 | return cos(input); |
| 2022 | case EXP: |
| 2023 | return exp(input); |
| 2024 | case LOG: |
| 2025 | return log(input); |
| 2026 | case SIN: |
| 2027 | return sin(input); |
| 2028 | case TAN: |
| 2029 | return tan(input); |
| 2030 | default: |
| 2031 | return 0.0; // Never happens. |
| 2032 | } |
| 2033 | } |
| 2034 | static const int kCacheSize = 512; |
| 2035 | struct Element { |
| 2036 | uint32_t in[2]; |
| 2037 | Object* output; |
| 2038 | }; |
| 2039 | union Converter { |
| 2040 | double dbl; |
| 2041 | uint32_t integers[2]; |
| 2042 | }; |
| 2043 | inline static int Hash(const Converter& c) { |
| 2044 | uint32_t hash = (c.integers[0] ^ c.integers[1]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2045 | hash ^= static_cast<int32_t>(hash) >> 16; |
| 2046 | hash ^= static_cast<int32_t>(hash) >> 8; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2047 | return (hash & (kCacheSize - 1)); |
| 2048 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2049 | |
| 2050 | static Address cache_array_address() { |
| 2051 | // Used to create an external reference. |
| 2052 | return reinterpret_cast<Address>(caches_); |
| 2053 | } |
| 2054 | |
| 2055 | // Allow access to the caches_ array as an ExternalReference. |
| 2056 | friend class ExternalReference; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame^] | 2057 | // Inline implementation of the cache. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2058 | friend class TranscendentalCacheStub; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame^] | 2059 | friend class TranscendentalCacheSSE2Stub; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2060 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2061 | static TranscendentalCache* caches_[kNumberOfCaches]; |
| 2062 | Element elements_[kCacheSize]; |
| 2063 | Type type_; |
| 2064 | }; |
| 2065 | |
| 2066 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2067 | // External strings table is a place where all external strings are |
| 2068 | // registered. We need to keep track of such strings to properly |
| 2069 | // finalize them. |
| 2070 | class ExternalStringTable : public AllStatic { |
| 2071 | public: |
| 2072 | // Registers an external string. |
| 2073 | inline static void AddString(String* string); |
| 2074 | |
| 2075 | inline static void Iterate(ObjectVisitor* v); |
| 2076 | |
| 2077 | // Restores internal invariant and gets rid of collected strings. |
| 2078 | // Must be called after each Iterate() that modified the strings. |
| 2079 | static void CleanUp(); |
| 2080 | |
| 2081 | // Destroys all allocated memory. |
| 2082 | static void TearDown(); |
| 2083 | |
| 2084 | private: |
| 2085 | friend class Heap; |
| 2086 | |
| 2087 | inline static void Verify(); |
| 2088 | |
| 2089 | inline static void AddOldString(String* string); |
| 2090 | |
| 2091 | // Notifies the table that only a prefix of the new list is valid. |
| 2092 | inline static void ShrinkNewStrings(int position); |
| 2093 | |
| 2094 | // To speed up scavenge collections new space string are kept |
| 2095 | // separate from old space strings. |
| 2096 | static List<Object*> new_space_strings_; |
| 2097 | static List<Object*> old_space_strings_; |
| 2098 | }; |
| 2099 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 2100 | |
| 2101 | // Abstract base class for checking whether a weak object should be retained. |
| 2102 | class WeakObjectRetainer { |
| 2103 | public: |
| 2104 | virtual ~WeakObjectRetainer() {} |
| 2105 | |
| 2106 | // Return whether this object should be retained. If NULL is returned the |
| 2107 | // object has no references. Otherwise the address of the retained object |
| 2108 | // should be returned as in some GC situations the object has been moved. |
| 2109 | virtual Object* RetainAs(Object* object) = 0; |
| 2110 | }; |
| 2111 | |
| 2112 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2113 | } } // namespace v8::internal |
| 2114 | |
| 2115 | #endif // V8_HEAP_H_ |