Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
| 31 | #include <math.h> |
| 32 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 33 | #include "allocation.h" |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 34 | #include "globals.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 35 | #include "incremental-marking.h" |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 36 | #include "list.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 37 | #include "mark-compact.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 38 | #include "objects-visiting.h" |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 39 | #include "spaces.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 40 | #include "splay-tree-inl.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 41 | #include "store-buffer.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 42 | #include "v8-counters.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 43 | #include "v8globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | |
| 45 | namespace v8 { |
| 46 | namespace internal { |
| 47 | |
| 48 | // Defines all the roots in Heap. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 49 | #define STRONG_ROOT_LIST(V) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 50 | V(Map, byte_array_map, ByteArrayMap) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 51 | V(Map, free_space_map, FreeSpaceMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 52 | V(Map, one_pointer_filler_map, OnePointerFillerMap) \ |
| 53 | V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ |
| 54 | /* Cluster the most popular ones in a few cache lines here at the top. */ \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 55 | V(Smi, store_buffer_top, StoreBufferTop) \ |
| 56 | V(Oddball, undefined_value, UndefinedValue) \ |
| 57 | V(Oddball, the_hole_value, TheHoleValue) \ |
| 58 | V(Oddball, null_value, NullValue) \ |
| 59 | V(Oddball, true_value, TrueValue) \ |
| 60 | V(Oddball, false_value, FalseValue) \ |
| 61 | V(Map, global_property_cell_map, GlobalPropertyCellMap) \ |
| 62 | V(Map, shared_function_info_map, SharedFunctionInfoMap) \ |
| 63 | V(Map, meta_map, MetaMap) \ |
| 64 | V(Map, ascii_symbol_map, AsciiSymbolMap) \ |
| 65 | V(Map, ascii_string_map, AsciiStringMap) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 66 | V(Map, heap_number_map, HeapNumberMap) \ |
| 67 | V(Map, global_context_map, GlobalContextMap) \ |
| 68 | V(Map, fixed_array_map, FixedArrayMap) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 69 | V(Map, code_map, CodeMap) \ |
| 70 | V(Map, scope_info_map, ScopeInfoMap) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 71 | V(Map, fixed_cow_array_map, FixedCOWArrayMap) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 72 | V(Map, fixed_double_array_map, FixedDoubleArrayMap) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 73 | V(Object, no_interceptor_result_sentinel, NoInterceptorResultSentinel) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 74 | V(Map, hash_table_map, HashTableMap) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 75 | V(FixedArray, empty_fixed_array, EmptyFixedArray) \ |
| 76 | V(ByteArray, empty_byte_array, EmptyByteArray) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 77 | V(String, empty_string, EmptyString) \ |
| 78 | V(DescriptorArray, empty_descriptor_array, EmptyDescriptorArray) \ |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 79 | V(Smi, stack_limit, StackLimit) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 80 | V(Oddball, arguments_marker, ArgumentsMarker) \ |
| 81 | /* The first 32 roots above this line should be boring from a GC point of */ \ |
| 82 | /* view. This means they are never in new space and never on a page that */ \ |
| 83 | /* is being compacted. */ \ |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 84 | V(FixedArray, number_string_cache, NumberStringCache) \ |
| 85 | V(Object, instanceof_cache_function, InstanceofCacheFunction) \ |
| 86 | V(Object, instanceof_cache_map, InstanceofCacheMap) \ |
| 87 | V(Object, instanceof_cache_answer, InstanceofCacheAnswer) \ |
| 88 | V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \ |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 89 | V(FixedArray, string_split_cache, StringSplitCache) \ |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 90 | V(Object, termination_exception, TerminationException) \ |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 91 | V(Smi, hash_seed, HashSeed) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 92 | V(Map, string_map, StringMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 93 | V(Map, symbol_map, SymbolMap) \ |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 94 | V(Map, cons_string_map, ConsStringMap) \ |
| 95 | V(Map, cons_ascii_string_map, ConsAsciiStringMap) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 96 | V(Map, sliced_string_map, SlicedStringMap) \ |
| 97 | V(Map, sliced_ascii_string_map, SlicedAsciiStringMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 98 | V(Map, cons_symbol_map, ConsSymbolMap) \ |
| 99 | V(Map, cons_ascii_symbol_map, ConsAsciiSymbolMap) \ |
| 100 | V(Map, external_symbol_map, ExternalSymbolMap) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 101 | V(Map, external_symbol_with_ascii_data_map, ExternalSymbolWithAsciiDataMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 102 | V(Map, external_ascii_symbol_map, ExternalAsciiSymbolMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 103 | V(Map, external_string_map, ExternalStringMap) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 104 | V(Map, external_string_with_ascii_data_map, ExternalStringWithAsciiDataMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 105 | V(Map, external_ascii_string_map, ExternalAsciiStringMap) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 106 | V(Map, short_external_symbol_map, ShortExternalSymbolMap) \ |
| 107 | V(Map, \ |
| 108 | short_external_symbol_with_ascii_data_map, \ |
| 109 | ShortExternalSymbolWithAsciiDataMap) \ |
| 110 | V(Map, short_external_ascii_symbol_map, ShortExternalAsciiSymbolMap) \ |
| 111 | V(Map, short_external_string_map, ShortExternalStringMap) \ |
| 112 | V(Map, \ |
| 113 | short_external_string_with_ascii_data_map, \ |
| 114 | ShortExternalStringWithAsciiDataMap) \ |
| 115 | V(Map, short_external_ascii_string_map, ShortExternalAsciiStringMap) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 116 | V(Map, undetectable_string_map, UndetectableStringMap) \ |
| 117 | V(Map, undetectable_ascii_string_map, UndetectableAsciiStringMap) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 118 | V(Map, external_pixel_array_map, ExternalPixelArrayMap) \ |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 119 | V(Map, external_byte_array_map, ExternalByteArrayMap) \ |
| 120 | V(Map, external_unsigned_byte_array_map, ExternalUnsignedByteArrayMap) \ |
| 121 | V(Map, external_short_array_map, ExternalShortArrayMap) \ |
| 122 | V(Map, external_unsigned_short_array_map, ExternalUnsignedShortArrayMap) \ |
| 123 | V(Map, external_int_array_map, ExternalIntArrayMap) \ |
| 124 | V(Map, external_unsigned_int_array_map, ExternalUnsignedIntArrayMap) \ |
| 125 | V(Map, external_float_array_map, ExternalFloatArrayMap) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 126 | V(Map, external_double_array_map, ExternalDoubleArrayMap) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 127 | V(Map, non_strict_arguments_elements_map, NonStrictArgumentsElementsMap) \ |
| 128 | V(Map, function_context_map, FunctionContextMap) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | V(Map, catch_context_map, CatchContextMap) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 130 | V(Map, with_context_map, WithContextMap) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 131 | V(Map, block_context_map, BlockContextMap) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 132 | V(Map, module_context_map, ModuleContextMap) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 133 | V(Map, oddball_map, OddballMap) \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 134 | V(Map, message_object_map, JSMessageObjectMap) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 135 | V(Map, foreign_map, ForeignMap) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 136 | V(HeapNumber, nan_value, NanValue) \ |
| 137 | V(HeapNumber, infinity_value, InfinityValue) \ |
| 138 | V(HeapNumber, minus_zero_value, MinusZeroValue) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | V(Map, neander_map, NeanderMap) \ |
| 140 | V(JSObject, message_listeners, MessageListeners) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 141 | V(Foreign, prototype_accessors, PrototypeAccessors) \ |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 142 | V(UnseededNumberDictionary, code_stubs, CodeStubs) \ |
| 143 | V(UnseededNumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 144 | V(PolymorphicCodeCache, polymorphic_code_cache, PolymorphicCodeCache) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | V(Code, js_entry_code, JsEntryCode) \ |
| 146 | V(Code, js_construct_entry_code, JsConstructEntryCode) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | V(FixedArray, natives_source_cache, NativesSourceCache) \ |
| 148 | V(Object, last_script_id, LastScriptId) \ |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 149 | V(Script, empty_script, EmptyScript) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 150 | V(Smi, real_stack_limit, RealStackLimit) \ |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 151 | V(StringDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 152 | V(Smi, arguments_adaptor_deopt_pc_offset, ArgumentsAdaptorDeoptPCOffset) \ |
| 153 | V(Smi, construct_stub_deopt_pc_offset, ConstructStubDeoptPCOffset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 155 | #define ROOT_LIST(V) \ |
| 156 | STRONG_ROOT_LIST(V) \ |
| 157 | V(SymbolTable, symbol_table, SymbolTable) |
| 158 | |
| 159 | #define SYMBOL_LIST(V) \ |
| 160 | V(Array_symbol, "Array") \ |
| 161 | V(Object_symbol, "Object") \ |
| 162 | V(Proto_symbol, "__proto__") \ |
| 163 | V(StringImpl_symbol, "StringImpl") \ |
| 164 | V(arguments_symbol, "arguments") \ |
| 165 | V(Arguments_symbol, "Arguments") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 166 | V(call_symbol, "call") \ |
| 167 | V(apply_symbol, "apply") \ |
| 168 | V(caller_symbol, "caller") \ |
| 169 | V(boolean_symbol, "boolean") \ |
| 170 | V(Boolean_symbol, "Boolean") \ |
| 171 | V(callee_symbol, "callee") \ |
| 172 | V(constructor_symbol, "constructor") \ |
| 173 | V(code_symbol, ".code") \ |
| 174 | V(result_symbol, ".result") \ |
| 175 | V(catch_var_symbol, ".catch-var") \ |
| 176 | V(empty_symbol, "") \ |
| 177 | V(eval_symbol, "eval") \ |
| 178 | V(function_symbol, "function") \ |
| 179 | V(length_symbol, "length") \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 180 | V(module_symbol, "module") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 181 | V(name_symbol, "name") \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 182 | V(native_symbol, "native") \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 183 | V(null_symbol, "null") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | V(number_symbol, "number") \ |
| 185 | V(Number_symbol, "Number") \ |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 186 | V(nan_symbol, "NaN") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 187 | V(RegExp_symbol, "RegExp") \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 188 | V(source_symbol, "source") \ |
| 189 | V(global_symbol, "global") \ |
| 190 | V(ignore_case_symbol, "ignoreCase") \ |
| 191 | V(multiline_symbol, "multiline") \ |
| 192 | V(input_symbol, "input") \ |
| 193 | V(index_symbol, "index") \ |
| 194 | V(last_index_symbol, "lastIndex") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 195 | V(object_symbol, "object") \ |
| 196 | V(prototype_symbol, "prototype") \ |
| 197 | V(string_symbol, "string") \ |
| 198 | V(String_symbol, "String") \ |
| 199 | V(Date_symbol, "Date") \ |
| 200 | V(this_symbol, "this") \ |
| 201 | V(to_string_symbol, "toString") \ |
| 202 | V(char_at_symbol, "CharAt") \ |
| 203 | V(undefined_symbol, "undefined") \ |
| 204 | V(value_of_symbol, "valueOf") \ |
| 205 | V(InitializeVarGlobal_symbol, "InitializeVarGlobal") \ |
| 206 | V(InitializeConstGlobal_symbol, "InitializeConstGlobal") \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 207 | V(KeyedLoadElementMonomorphic_symbol, \ |
| 208 | "KeyedLoadElementMonomorphic") \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 209 | V(KeyedStoreElementMonomorphic_symbol, \ |
| 210 | "KeyedStoreElementMonomorphic") \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 211 | V(KeyedStoreAndGrowElementMonomorphic_symbol, \ |
| 212 | "KeyedStoreAndGrowElementMonomorphic") \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 213 | V(stack_overflow_symbol, "kStackOverflowBoilerplate") \ |
| 214 | V(illegal_access_symbol, "illegal access") \ |
| 215 | V(out_of_memory_symbol, "out-of-memory") \ |
| 216 | V(illegal_execution_state_symbol, "illegal execution state") \ |
| 217 | V(get_symbol, "get") \ |
| 218 | V(set_symbol, "set") \ |
| 219 | V(function_class_symbol, "Function") \ |
| 220 | V(illegal_argument_symbol, "illegal argument") \ |
| 221 | V(MakeReferenceError_symbol, "MakeReferenceError") \ |
| 222 | V(MakeSyntaxError_symbol, "MakeSyntaxError") \ |
| 223 | V(MakeTypeError_symbol, "MakeTypeError") \ |
| 224 | V(invalid_lhs_in_assignment_symbol, "invalid_lhs_in_assignment") \ |
| 225 | V(invalid_lhs_in_for_in_symbol, "invalid_lhs_in_for_in") \ |
| 226 | V(invalid_lhs_in_postfix_op_symbol, "invalid_lhs_in_postfix_op") \ |
| 227 | V(invalid_lhs_in_prefix_op_symbol, "invalid_lhs_in_prefix_op") \ |
| 228 | V(illegal_return_symbol, "illegal_return") \ |
| 229 | V(illegal_break_symbol, "illegal_break") \ |
| 230 | V(illegal_continue_symbol, "illegal_continue") \ |
| 231 | V(unknown_label_symbol, "unknown_label") \ |
| 232 | V(redeclaration_symbol, "redeclaration") \ |
| 233 | V(failure_symbol, "<failure>") \ |
| 234 | V(space_symbol, " ") \ |
| 235 | V(exec_symbol, "exec") \ |
| 236 | V(zero_symbol, "0") \ |
| 237 | V(global_eval_symbol, "GlobalEval") \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 238 | V(identity_hash_symbol, "v8::IdentityHash") \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 239 | V(closure_symbol, "(closure)") \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 240 | V(use_strict, "use strict") \ |
| 241 | V(dot_symbol, ".") \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 242 | V(anonymous_function_symbol, "(anonymous function)") \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 243 | V(compare_ic_symbol, ".compare_ic") \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 244 | V(infinity_symbol, "Infinity") \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 245 | V(minus_infinity_symbol, "-Infinity") \ |
| 246 | V(hidden_stack_trace_symbol, "v8::hidden_stack_trace") |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 247 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 248 | // Forward declarations. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 249 | class GCTracer; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 250 | class HeapStats; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 251 | class Isolate; |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 252 | class WeakObjectRetainer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 253 | |
| 254 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 255 | typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap, |
| 256 | Object** pointer); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 257 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 258 | class StoreBufferRebuilder { |
| 259 | public: |
| 260 | explicit StoreBufferRebuilder(StoreBuffer* store_buffer) |
| 261 | : store_buffer_(store_buffer) { |
| 262 | } |
| 263 | |
| 264 | void Callback(MemoryChunk* page, StoreBufferEvent event); |
| 265 | |
| 266 | private: |
| 267 | StoreBuffer* store_buffer_; |
| 268 | |
| 269 | // We record in this variable how full the store buffer was when we started |
| 270 | // iterating over the current page, finding pointers to new space. If the |
| 271 | // store buffer overflows again we can exempt the page from the store buffer |
| 272 | // by rewinding to this point instead of having to search the store buffer. |
| 273 | Object*** start_of_current_page_; |
| 274 | // The current page we are scanning in the store buffer iterator. |
| 275 | MemoryChunk* current_page_; |
| 276 | }; |
| 277 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 278 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 279 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 280 | // The all static Heap captures the interface to the global object heap. |
| 281 | // All JavaScript contexts by this process share the same object heap. |
| 282 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 283 | #ifdef DEBUG |
| 284 | class HeapDebugUtils; |
| 285 | #endif |
| 286 | |
| 287 | |
| 288 | // A queue of objects promoted during scavenge. Each object is accompanied |
| 289 | // by it's size to avoid dereferencing a map pointer for scanning. |
| 290 | class PromotionQueue { |
| 291 | public: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 292 | explicit PromotionQueue(Heap* heap) |
| 293 | : front_(NULL), |
| 294 | rear_(NULL), |
| 295 | limit_(NULL), |
| 296 | emergency_stack_(0), |
| 297 | heap_(heap) { } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 298 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 299 | void Initialize(); |
| 300 | |
| 301 | void Destroy() { |
| 302 | ASSERT(is_empty()); |
| 303 | delete emergency_stack_; |
| 304 | emergency_stack_ = NULL; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 307 | inline void ActivateGuardIfOnTheSamePage(); |
| 308 | |
| 309 | Page* GetHeadPage() { |
| 310 | return Page::FromAllocationTop(reinterpret_cast<Address>(rear_)); |
| 311 | } |
| 312 | |
| 313 | void SetNewLimit(Address limit) { |
| 314 | if (!guard_) { |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | ASSERT(GetHeadPage() == Page::FromAllocationTop(limit)); |
| 319 | limit_ = reinterpret_cast<intptr_t*>(limit); |
| 320 | |
| 321 | if (limit_ <= rear_) { |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | RelocateQueueHead(); |
| 326 | } |
| 327 | |
| 328 | bool is_empty() { |
| 329 | return (front_ == rear_) && |
| 330 | (emergency_stack_ == NULL || emergency_stack_->length() == 0); |
| 331 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 332 | |
| 333 | inline void insert(HeapObject* target, int size); |
| 334 | |
| 335 | void remove(HeapObject** target, int* size) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 336 | ASSERT(!is_empty()); |
| 337 | if (front_ == rear_) { |
| 338 | Entry e = emergency_stack_->RemoveLast(); |
| 339 | *target = e.obj_; |
| 340 | *size = e.size_; |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | if (NewSpacePage::IsAtStart(reinterpret_cast<Address>(front_))) { |
| 345 | NewSpacePage* front_page = |
| 346 | NewSpacePage::FromAddress(reinterpret_cast<Address>(front_)); |
| 347 | ASSERT(!front_page->prev_page()->is_anchor()); |
| 348 | front_ = |
| 349 | reinterpret_cast<intptr_t*>(front_page->prev_page()->area_end()); |
| 350 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 351 | *target = reinterpret_cast<HeapObject*>(*(--front_)); |
| 352 | *size = static_cast<int>(*(--front_)); |
| 353 | // Assert no underflow. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 354 | SemiSpace::AssertValidRange(reinterpret_cast<Address>(rear_), |
| 355 | reinterpret_cast<Address>(front_)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | private: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 359 | // The front of the queue is higher in the memory page chain than the rear. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 360 | intptr_t* front_; |
| 361 | intptr_t* rear_; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 362 | intptr_t* limit_; |
| 363 | |
| 364 | bool guard_; |
| 365 | |
| 366 | static const int kEntrySizeInWords = 2; |
| 367 | |
| 368 | struct Entry { |
| 369 | Entry(HeapObject* obj, int size) : obj_(obj), size_(size) { } |
| 370 | |
| 371 | HeapObject* obj_; |
| 372 | int size_; |
| 373 | }; |
| 374 | List<Entry>* emergency_stack_; |
| 375 | |
| 376 | Heap* heap_; |
| 377 | |
| 378 | void RelocateQueueHead(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 379 | |
| 380 | DISALLOW_COPY_AND_ASSIGN(PromotionQueue); |
| 381 | }; |
| 382 | |
| 383 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 384 | typedef void (*ScavengingCallback)(Map* map, |
| 385 | HeapObject** slot, |
| 386 | HeapObject* object); |
| 387 | |
| 388 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 389 | // External strings table is a place where all external strings are |
| 390 | // registered. We need to keep track of such strings to properly |
| 391 | // finalize them. |
| 392 | class ExternalStringTable { |
| 393 | public: |
| 394 | // Registers an external string. |
| 395 | inline void AddString(String* string); |
| 396 | |
| 397 | inline void Iterate(ObjectVisitor* v); |
| 398 | |
| 399 | // Restores internal invariant and gets rid of collected strings. |
| 400 | // Must be called after each Iterate() that modified the strings. |
| 401 | void CleanUp(); |
| 402 | |
| 403 | // Destroys all allocated memory. |
| 404 | void TearDown(); |
| 405 | |
| 406 | private: |
| 407 | ExternalStringTable() { } |
| 408 | |
| 409 | friend class Heap; |
| 410 | |
| 411 | inline void Verify(); |
| 412 | |
| 413 | inline void AddOldString(String* string); |
| 414 | |
| 415 | // Notifies the table that only a prefix of the new list is valid. |
| 416 | inline void ShrinkNewStrings(int position); |
| 417 | |
| 418 | // To speed up scavenge collections new space string are kept |
| 419 | // separate from old space strings. |
| 420 | List<Object*> new_space_strings_; |
| 421 | List<Object*> old_space_strings_; |
| 422 | |
| 423 | Heap* heap_; |
| 424 | |
| 425 | DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
| 426 | }; |
| 427 | |
| 428 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 429 | enum ArrayStorageAllocationMode { |
| 430 | DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 431 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
| 432 | }; |
| 433 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 434 | class Heap { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | public: |
| 436 | // Configure heap size before setup. Return false if the heap has been |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 437 | // set up already. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 438 | bool ConfigureHeap(int max_semispace_size, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 439 | intptr_t max_old_gen_size, |
| 440 | intptr_t max_executable_size); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 441 | bool ConfigureHeapDefault(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 442 | |
| 443 | // Initializes the global object heap. If create_heap_objects is true, |
| 444 | // also creates the basic non-mutable objects. |
| 445 | // Returns whether it succeeded. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 446 | bool SetUp(bool create_heap_objects); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | |
| 448 | // Destroys all memory allocated by the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 449 | void TearDown(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 451 | // Set the stack limit in the roots_ array. Some architectures generate |
| 452 | // code that looks here, because it is faster than loading from the static |
| 453 | // jslimit_/real_jslimit_ variable in the StackGuard. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 454 | void SetStackLimits(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 456 | // Returns whether SetUp has been called. |
| 457 | bool HasBeenSetUp(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 459 | // Returns the maximum amount of memory reserved for the heap. For |
| 460 | // the young generation, we reserve 4 times the amount needed for a |
| 461 | // semi space. The young generation consists of two semi spaces and |
| 462 | // we reserve twice the amount needed for those in order to ensure |
| 463 | // that new space can be aligned to its size. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 464 | intptr_t MaxReserved() { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 465 | return 4 * reserved_semispace_size_ + max_old_generation_size_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 467 | int MaxSemiSpaceSize() { return max_semispace_size_; } |
| 468 | int ReservedSemiSpaceSize() { return reserved_semispace_size_; } |
| 469 | int InitialSemiSpaceSize() { return initial_semispace_size_; } |
| 470 | intptr_t MaxOldGenerationSize() { return max_old_generation_size_; } |
| 471 | intptr_t MaxExecutableSize() { return max_executable_size_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 472 | |
| 473 | // Returns the capacity of the heap in bytes w/o growing. Heap grows when |
| 474 | // more spaces are needed until it reaches the limit. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 475 | intptr_t Capacity(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 477 | // Returns the amount of memory currently committed for the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 478 | intptr_t CommittedMemory(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 479 | |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 480 | // Returns the amount of executable memory currently committed for the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 481 | intptr_t CommittedMemoryExecutable(); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 482 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | // Returns the available bytes in space w/o growing. |
| 484 | // Heap doesn't guarantee that it can allocate an object that requires |
| 485 | // all available bytes. Check MaxHeapObjectSize() instead. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 486 | intptr_t Available(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 487 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | // Returns of size of all objects residing in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 489 | intptr_t SizeOfObjects(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | |
| 491 | // Return the starting address and a mask for the new space. And-masking an |
| 492 | // address with the mask will result in the start address of the new space |
| 493 | // for all addresses in either semispace. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 494 | Address NewSpaceStart() { return new_space_.start(); } |
| 495 | uintptr_t NewSpaceMask() { return new_space_.mask(); } |
| 496 | Address NewSpaceTop() { return new_space_.top(); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 498 | NewSpace* new_space() { return &new_space_; } |
| 499 | OldSpace* old_pointer_space() { return old_pointer_space_; } |
| 500 | OldSpace* old_data_space() { return old_data_space_; } |
| 501 | OldSpace* code_space() { return code_space_; } |
| 502 | MapSpace* map_space() { return map_space_; } |
| 503 | CellSpace* cell_space() { return cell_space_; } |
| 504 | LargeObjectSpace* lo_space() { return lo_space_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 505 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 506 | bool always_allocate() { return always_allocate_scope_depth_ != 0; } |
| 507 | Address always_allocate_scope_depth_address() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 508 | return reinterpret_cast<Address>(&always_allocate_scope_depth_); |
| 509 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 510 | bool linear_allocation() { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 511 | return linear_allocation_scope_depth_ != 0; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 512 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 514 | Address* NewSpaceAllocationTopAddress() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 515 | return new_space_.allocation_top_address(); |
| 516 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 517 | Address* NewSpaceAllocationLimitAddress() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | return new_space_.allocation_limit_address(); |
| 519 | } |
| 520 | |
| 521 | // Uncommit unused semi space. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 522 | bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | // Allocates and initializes a new JavaScript object based on a |
| 525 | // constructor. |
| 526 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 527 | // failed. |
| 528 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 529 | MUST_USE_RESULT MaybeObject* AllocateJSObject( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 530 | JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 531 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 532 | // Allocate a JSArray with no elements |
| 533 | MUST_USE_RESULT MaybeObject* AllocateEmptyJSArray( |
| 534 | ElementsKind elements_kind, |
| 535 | PretenureFlag pretenure = NOT_TENURED) { |
| 536 | return AllocateJSArrayAndStorage(elements_kind, 0, 0, |
| 537 | DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 538 | pretenure); |
| 539 | } |
| 540 | |
| 541 | // Allocate a JSArray with a specified length but elements that are left |
| 542 | // uninitialized. |
| 543 | MUST_USE_RESULT MaybeObject* AllocateJSArrayAndStorage( |
| 544 | ElementsKind elements_kind, |
| 545 | int length, |
| 546 | int capacity, |
| 547 | ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 548 | PretenureFlag pretenure = NOT_TENURED); |
| 549 | |
| 550 | // Allocate a JSArray with no elements |
| 551 | MUST_USE_RESULT MaybeObject* AllocateJSArrayWithElements( |
| 552 | FixedArrayBase* array_base, |
| 553 | ElementsKind elements_kind, |
| 554 | PretenureFlag pretenure = NOT_TENURED); |
| 555 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 556 | // Allocates and initializes a new global object based on a constructor. |
| 557 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 558 | // failed. |
| 559 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 560 | MUST_USE_RESULT MaybeObject* AllocateGlobalObject(JSFunction* constructor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 561 | |
| 562 | // Returns a deep copy of the JavaScript object. |
| 563 | // Properties and elements are copied too. |
| 564 | // Returns failure if allocation failed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 565 | MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | |
| 567 | // Allocates the function prototype. |
| 568 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 569 | // failed. |
| 570 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 571 | MUST_USE_RESULT MaybeObject* AllocateFunctionPrototype(JSFunction* function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 573 | // Allocates a Harmony proxy or function proxy. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 574 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 575 | // failed. |
| 576 | // Please note this does not perform a garbage collection. |
| 577 | MUST_USE_RESULT MaybeObject* AllocateJSProxy(Object* handler, |
| 578 | Object* prototype); |
| 579 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 580 | MUST_USE_RESULT MaybeObject* AllocateJSFunctionProxy(Object* handler, |
| 581 | Object* call_trap, |
| 582 | Object* construct_trap, |
| 583 | Object* prototype); |
| 584 | |
| 585 | // Reinitialize a JSReceiver into an (empty) JS object of respective type and |
| 586 | // size, but keeping the original prototype. The receiver must have at least |
| 587 | // the size of the new object. The object is reinitialized and behaves as an |
| 588 | // object that has been freshly allocated. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 589 | // Returns failure if an error occured, otherwise object. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 590 | MUST_USE_RESULT MaybeObject* ReinitializeJSReceiver(JSReceiver* object, |
| 591 | InstanceType type, |
| 592 | int size); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 593 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | // Reinitialize an JSGlobalProxy based on a constructor. The object |
| 595 | // must have the same size as objects allocated using the |
| 596 | // constructor. The object is reinitialized and behaves as an |
| 597 | // object that has been freshly allocated using the constructor. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 598 | MUST_USE_RESULT MaybeObject* ReinitializeJSGlobalProxy( |
| 599 | JSFunction* constructor, JSGlobalProxy* global); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 600 | |
| 601 | // Allocates and initializes a new JavaScript object based on a map. |
| 602 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 603 | // failed. |
| 604 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 605 | MUST_USE_RESULT MaybeObject* AllocateJSObjectFromMap( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 606 | Map* map, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 607 | |
| 608 | // Allocates a heap object based on the map. |
| 609 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 610 | // failed. |
| 611 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 612 | MUST_USE_RESULT MaybeObject* Allocate(Map* map, AllocationSpace space); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 613 | |
| 614 | // Allocates a JS Map in the heap. |
| 615 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 616 | // failed. |
| 617 | // Please note this function does not perform a garbage collection. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 618 | MUST_USE_RESULT MaybeObject* AllocateMap( |
| 619 | InstanceType instance_type, |
| 620 | int instance_size, |
| 621 | ElementsKind elements_kind = FAST_ELEMENTS); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 622 | |
| 623 | // Allocates a partial map for bootstrapping. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 624 | MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type, |
| 625 | int instance_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 626 | |
| 627 | // Allocate a map for the specified function |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 628 | MUST_USE_RESULT MaybeObject* AllocateInitialMap(JSFunction* fun); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 629 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 630 | // Allocates an empty code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 631 | MUST_USE_RESULT MaybeObject* AllocateCodeCache(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 632 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 633 | // Allocates a serialized scope info. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 634 | MUST_USE_RESULT MaybeObject* AllocateScopeInfo(int length); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 635 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 636 | // Allocates an empty PolymorphicCodeCache. |
| 637 | MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); |
| 638 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 639 | // Allocates a pre-tenured empty AccessorPair. |
| 640 | MUST_USE_RESULT MaybeObject* AllocateAccessorPair(); |
| 641 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 642 | // Allocates an empty TypeFeedbackInfo. |
| 643 | MUST_USE_RESULT MaybeObject* AllocateTypeFeedbackInfo(); |
| 644 | |
| 645 | // Allocates an AliasedArgumentsEntry. |
| 646 | MUST_USE_RESULT MaybeObject* AllocateAliasedArgumentsEntry(int slot); |
| 647 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 648 | // Clear the Instanceof cache (used when a prototype changes). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 649 | inline void ClearInstanceofCache(); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 650 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | // Allocates and fully initializes a String. There are two String |
| 652 | // encodings: ASCII and two byte. One should choose between the three string |
| 653 | // allocation functions based on the encoding of the string buffer used to |
| 654 | // initialized the string. |
| 655 | // - ...FromAscii initializes the string from a buffer that is ASCII |
| 656 | // encoded (it does not check that the buffer is ASCII encoded) and the |
| 657 | // result will be ASCII encoded. |
| 658 | // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 659 | // encoded. If the characters are all single-byte characters, the |
| 660 | // result will be ASCII encoded, otherwise it will converted to two |
| 661 | // byte. |
| 662 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 663 | // encoded. If the characters are all single-byte characters, the |
| 664 | // result will be converted to ASCII, otherwise it will be left as |
| 665 | // two-byte. |
| 666 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 667 | // failed. |
| 668 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 669 | MUST_USE_RESULT MaybeObject* AllocateStringFromAscii( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 670 | Vector<const char> str, |
| 671 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 672 | MUST_USE_RESULT inline MaybeObject* AllocateStringFromUtf8( |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 673 | Vector<const char> str, |
| 674 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 675 | MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 676 | Vector<const char> str, |
| 677 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 678 | MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 679 | Vector<const uc16> str, |
| 680 | PretenureFlag pretenure = NOT_TENURED); |
| 681 | |
| 682 | // Allocates a symbol in old space based on the character stream. |
| 683 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 684 | // failed. |
| 685 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 686 | MUST_USE_RESULT inline MaybeObject* AllocateSymbol(Vector<const char> str, |
| 687 | int chars, |
| 688 | uint32_t hash_field); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 689 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 690 | MUST_USE_RESULT inline MaybeObject* AllocateAsciiSymbol( |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 691 | Vector<const char> str, |
| 692 | uint32_t hash_field); |
| 693 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 694 | MUST_USE_RESULT inline MaybeObject* AllocateTwoByteSymbol( |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 695 | Vector<const uc16> str, |
| 696 | uint32_t hash_field); |
| 697 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 698 | MUST_USE_RESULT MaybeObject* AllocateInternalSymbol( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 699 | unibrow::CharacterStream* buffer, int chars, uint32_t hash_field); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 701 | MUST_USE_RESULT MaybeObject* AllocateExternalSymbol( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 702 | Vector<const char> str, |
| 703 | int chars); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 704 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 705 | // Allocates and partially initializes a String. There are two String |
| 706 | // encodings: ASCII and two byte. These functions allocate a string of the |
| 707 | // given length and set its map and length fields. The characters of the |
| 708 | // string are uninitialized. |
| 709 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 710 | // failed. |
| 711 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 712 | MUST_USE_RESULT MaybeObject* AllocateRawAsciiString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | int length, |
| 714 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 715 | MUST_USE_RESULT MaybeObject* AllocateRawTwoByteString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 716 | int length, |
| 717 | PretenureFlag pretenure = NOT_TENURED); |
| 718 | |
| 719 | // Computes a single character string where the character has code. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 720 | // A cache is used for ASCII codes. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 721 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 722 | // failed. Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 723 | MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 724 | uint16_t code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 725 | |
| 726 | // Allocate a byte array of the specified length |
| 727 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 728 | // failed. |
| 729 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 730 | MUST_USE_RESULT MaybeObject* AllocateByteArray(int length, |
| 731 | PretenureFlag pretenure); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | |
| 733 | // Allocate a non-tenured byte array of the specified length |
| 734 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 735 | // failed. |
| 736 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 737 | MUST_USE_RESULT MaybeObject* AllocateByteArray(int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 738 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 739 | // Allocates an external array of the specified length and type. |
| 740 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 741 | // failed. |
| 742 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 743 | MUST_USE_RESULT MaybeObject* AllocateExternalArray( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 744 | int length, |
| 745 | ExternalArrayType array_type, |
| 746 | void* external_pointer, |
| 747 | PretenureFlag pretenure); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 748 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 749 | // Allocate a tenured JS global property cell. |
| 750 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 751 | // failed. |
| 752 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 753 | MUST_USE_RESULT MaybeObject* AllocateJSGlobalPropertyCell(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 754 | |
| 755 | // Allocates a fixed array initialized with undefined values |
| 756 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 757 | // failed. |
| 758 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 759 | MUST_USE_RESULT MaybeObject* AllocateFixedArray(int length, |
| 760 | PretenureFlag pretenure); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 761 | // Allocates a fixed array initialized with undefined values |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 762 | MUST_USE_RESULT MaybeObject* AllocateFixedArray(int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 764 | // Allocates an uninitialized fixed array. It must be filled by the caller. |
| 765 | // |
| 766 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 767 | // failed. |
| 768 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 769 | MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 770 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | // Make a copy of src and return it. Returns |
| 772 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 773 | MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 774 | |
| 775 | // Make a copy of src, set the map, and return the copy. Returns |
| 776 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 777 | MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 778 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 779 | // Make a copy of src and return it. Returns |
| 780 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 781 | MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( |
| 782 | FixedDoubleArray* src); |
| 783 | |
| 784 | // Make a copy of src, set the map, and return the copy. Returns |
| 785 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 786 | MUST_USE_RESULT MaybeObject* CopyFixedDoubleArrayWithMap( |
| 787 | FixedDoubleArray* src, Map* map); |
| 788 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 789 | // Allocates a fixed array initialized with the hole values. |
| 790 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 791 | // failed. |
| 792 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 793 | MUST_USE_RESULT MaybeObject* AllocateFixedArrayWithHoles( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 794 | int length, |
| 795 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 796 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 797 | MUST_USE_RESULT MaybeObject* AllocateRawFixedDoubleArray( |
| 798 | int length, |
| 799 | PretenureFlag pretenure); |
| 800 | |
| 801 | // Allocates a fixed double array with uninitialized values. Returns |
| 802 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 803 | // Please note this does not perform a garbage collection. |
| 804 | MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedDoubleArray( |
| 805 | int length, |
| 806 | PretenureFlag pretenure = NOT_TENURED); |
| 807 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 808 | // Allocates a fixed double array with hole values. Returns |
| 809 | // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 810 | // Please note this does not perform a garbage collection. |
| 811 | MUST_USE_RESULT MaybeObject* AllocateFixedDoubleArrayWithHoles( |
| 812 | int length, |
| 813 | PretenureFlag pretenure = NOT_TENURED); |
| 814 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 815 | // AllocateHashTable is identical to AllocateFixedArray except |
| 816 | // that the resulting object has hash_table_map as map. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 817 | MUST_USE_RESULT MaybeObject* AllocateHashTable( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 818 | int length, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 819 | |
| 820 | // Allocate a global (but otherwise uninitialized) context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 821 | MUST_USE_RESULT MaybeObject* AllocateGlobalContext(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | |
| 823 | // Allocate a function context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 824 | MUST_USE_RESULT MaybeObject* AllocateFunctionContext(int length, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 825 | JSFunction* function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 827 | // Allocate a catch context. |
| 828 | MUST_USE_RESULT MaybeObject* AllocateCatchContext(JSFunction* function, |
| 829 | Context* previous, |
| 830 | String* name, |
| 831 | Object* thrown_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 832 | // Allocate a 'with' context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 833 | MUST_USE_RESULT MaybeObject* AllocateWithContext(JSFunction* function, |
| 834 | Context* previous, |
| 835 | JSObject* extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 837 | // Allocate a block context. |
| 838 | MUST_USE_RESULT MaybeObject* AllocateBlockContext(JSFunction* function, |
| 839 | Context* previous, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 840 | ScopeInfo* info); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 841 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | // Allocates a new utility object in the old generation. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 843 | MUST_USE_RESULT MaybeObject* AllocateStruct(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | |
| 845 | // Allocates a function initialized with a shared part. |
| 846 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 847 | // failed. |
| 848 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 849 | MUST_USE_RESULT MaybeObject* AllocateFunction( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 850 | Map* function_map, |
| 851 | SharedFunctionInfo* shared, |
| 852 | Object* prototype, |
| 853 | PretenureFlag pretenure = TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 855 | // Arguments object size. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 856 | static const int kArgumentsObjectSize = |
| 857 | JSObject::kHeaderSize + 2 * kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 858 | // Strict mode arguments has no callee so it is smaller. |
| 859 | static const int kArgumentsObjectSizeStrict = |
| 860 | JSObject::kHeaderSize + 1 * kPointerSize; |
| 861 | // Indicies for direct access into argument objects. |
| 862 | static const int kArgumentsLengthIndex = 0; |
| 863 | // callee is only valid in non-strict mode. |
| 864 | static const int kArgumentsCalleeIndex = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 865 | |
| 866 | // Allocates an arguments object - optionally with an elements array. |
| 867 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 868 | // failed. |
| 869 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 870 | MUST_USE_RESULT MaybeObject* AllocateArgumentsObject( |
| 871 | Object* callee, int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 872 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 873 | // Same as NewNumberFromDouble, but may return a preallocated/immutable |
| 874 | // number object (e.g., minus_zero_value_, nan_value_) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 875 | MUST_USE_RESULT MaybeObject* NumberFromDouble( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 876 | double value, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 877 | |
| 878 | // Allocated a HeapNumber from value. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 879 | MUST_USE_RESULT MaybeObject* AllocateHeapNumber( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 880 | double value, |
| 881 | PretenureFlag pretenure); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 882 | // pretenure = NOT_TENURED |
| 883 | MUST_USE_RESULT MaybeObject* AllocateHeapNumber(double value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 884 | |
| 885 | // Converts an int into either a Smi or a HeapNumber object. |
| 886 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 887 | // failed. |
| 888 | // Please note this does not perform a garbage collection. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 889 | MUST_USE_RESULT inline MaybeObject* NumberFromInt32( |
| 890 | int32_t value, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 891 | |
| 892 | // Converts an int into either a Smi or a HeapNumber object. |
| 893 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 894 | // failed. |
| 895 | // Please note this does not perform a garbage collection. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 896 | MUST_USE_RESULT inline MaybeObject* NumberFromUint32( |
| 897 | uint32_t value, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 898 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 899 | // Allocates a new foreign object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 900 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 901 | // failed. |
| 902 | // Please note this does not perform a garbage collection. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 903 | MUST_USE_RESULT MaybeObject* AllocateForeign( |
| 904 | Address address, PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 905 | |
| 906 | // Allocates a new SharedFunctionInfo object. |
| 907 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 908 | // failed. |
| 909 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 910 | MUST_USE_RESULT MaybeObject* AllocateSharedFunctionInfo(Object* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 912 | // Allocates a new JSMessageObject object. |
| 913 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 914 | // failed. |
| 915 | // Please note that this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 916 | MUST_USE_RESULT MaybeObject* AllocateJSMessageObject( |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 917 | String* type, |
| 918 | JSArray* arguments, |
| 919 | int start_position, |
| 920 | int end_position, |
| 921 | Object* script, |
| 922 | Object* stack_trace, |
| 923 | Object* stack_frames); |
| 924 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 925 | // Allocates a new cons string object. |
| 926 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 927 | // failed. |
| 928 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 929 | MUST_USE_RESULT MaybeObject* AllocateConsString(String* first, |
| 930 | String* second); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 931 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 932 | // Allocates a new sub string object which is a substring of an underlying |
| 933 | // string buffer stretching from the index start (inclusive) to the index |
| 934 | // end (exclusive). |
| 935 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 936 | // failed. |
| 937 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 938 | MUST_USE_RESULT MaybeObject* AllocateSubString( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 939 | String* buffer, |
| 940 | int start, |
| 941 | int end, |
| 942 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | |
| 944 | // Allocate a new external string object, which is backed by a string |
| 945 | // resource that resides outside the V8 heap. |
| 946 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 947 | // failed. |
| 948 | // Please note this does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 949 | MUST_USE_RESULT MaybeObject* AllocateExternalStringFromAscii( |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 950 | const ExternalAsciiString::Resource* resource); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 951 | MUST_USE_RESULT MaybeObject* AllocateExternalStringFromTwoByte( |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 952 | const ExternalTwoByteString::Resource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 953 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 954 | // Finalizes an external string by deleting the associated external |
| 955 | // data and clearing the resource pointer. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 956 | inline void FinalizeExternalString(String* string); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 957 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 958 | // Allocates an uninitialized object. The memory is non-executable if the |
| 959 | // hardware and OS allow. |
| 960 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 961 | // failed. |
| 962 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 963 | MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes, |
| 964 | AllocationSpace space, |
| 965 | AllocationSpace retry_space); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 966 | |
| 967 | // Initialize a filler object to keep the ability to iterate over the heap |
| 968 | // when shortening objects. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 969 | void CreateFillerObjectAt(Address addr, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 970 | |
| 971 | // Makes a new native code object |
| 972 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 973 | // failed. On success, the pointer to the Code object is stored in the |
| 974 | // self_reference. This allows generated code to reference its own Code |
| 975 | // object by containing this pointer. |
| 976 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 977 | MUST_USE_RESULT MaybeObject* CreateCode(const CodeDesc& desc, |
| 978 | Code::Flags flags, |
| 979 | Handle<Object> self_reference, |
| 980 | bool immovable = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 982 | MUST_USE_RESULT MaybeObject* CopyCode(Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 983 | |
| 984 | // Copy the code and scope info part of the code object, but insert |
| 985 | // the provided data as the relocation information. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 986 | MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 987 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 988 | // Finds the symbol for string in the symbol table. |
| 989 | // If not found, a new symbol is added to the table and returned. |
| 990 | // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation |
| 991 | // failed. |
| 992 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 993 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str); |
| 994 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 995 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 996 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(const char* str) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 997 | return LookupSymbol(CStrVector(str)); |
| 998 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 999 | MUST_USE_RESULT MaybeObject* LookupSymbol(String* str); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1000 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Handle<SeqAsciiString> string, |
| 1001 | int from, |
| 1002 | int length); |
| 1003 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1004 | bool LookupSymbolIfExists(String* str, String** symbol); |
| 1005 | bool LookupTwoCharsSymbolIfExists(String* str, String** symbol); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1006 | |
| 1007 | // Compute the matching symbol map for a string if possible. |
| 1008 | // NULL is returned if string is in new space or not flattened. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1009 | Map* SymbolMapForString(String* str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1010 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1011 | // Tries to flatten a string before compare operation. |
| 1012 | // |
| 1013 | // Returns a failure in case it was decided that flattening was |
| 1014 | // necessary and failed. Note, if flattening is not necessary the |
| 1015 | // string might stay non-flat even when not a failure is returned. |
| 1016 | // |
| 1017 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1018 | MUST_USE_RESULT inline MaybeObject* PrepareForCompare(String* str); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1019 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1020 | // Converts the given boolean condition to JavaScript boolean value. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1021 | inline Object* ToBoolean(bool condition); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1022 | |
| 1023 | // Code that should be run before and after each GC. Includes some |
| 1024 | // reporting/verification activities when compiled with DEBUG set. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1025 | void GarbageCollectionPrologue(); |
| 1026 | void GarbageCollectionEpilogue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1027 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1028 | // Performs garbage collection operation. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1029 | // Returns whether there is a chance that another major GC could |
| 1030 | // collect more garbage. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1031 | bool CollectGarbage(AllocationSpace space, |
| 1032 | GarbageCollector collector, |
| 1033 | const char* gc_reason, |
| 1034 | const char* collector_reason); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1035 | |
| 1036 | // Performs garbage collection operation. |
| 1037 | // Returns whether there is a chance that another major GC could |
| 1038 | // collect more garbage. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1039 | inline bool CollectGarbage(AllocationSpace space, |
| 1040 | const char* gc_reason = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1041 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1042 | static const int kNoGCFlags = 0; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1043 | static const int kSweepPreciselyMask = 1; |
| 1044 | static const int kReduceMemoryFootprintMask = 2; |
| 1045 | static const int kAbortIncrementalMarkingMask = 4; |
| 1046 | |
| 1047 | // Making the heap iterable requires us to sweep precisely and abort any |
| 1048 | // incremental marking as well. |
| 1049 | static const int kMakeHeapIterableMask = |
| 1050 | kSweepPreciselyMask | kAbortIncrementalMarkingMask; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1051 | |
| 1052 | // Performs a full garbage collection. If (flags & kMakeHeapIterableMask) is |
| 1053 | // non-zero, then the slower precise sweeper is used, which leaves the heap |
| 1054 | // in a state where we can iterate over the heap visiting all objects. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1055 | void CollectAllGarbage(int flags, const char* gc_reason = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1056 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1057 | // Last hope GC, should try to squeeze as much as possible. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1058 | void CollectAllAvailableGarbage(const char* gc_reason = NULL); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1059 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1060 | // Check whether the heap is currently iterable. |
| 1061 | bool IsHeapIterable(); |
| 1062 | |
| 1063 | // Ensure that we have swept all spaces in such a way that we can iterate |
| 1064 | // over all objects. May cause a GC. |
| 1065 | void EnsureHeapIsIterable(); |
| 1066 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1067 | // Notify the heap that a context has been disposed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1068 | int NotifyContextDisposed() { return ++contexts_disposed_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1069 | |
| 1070 | // Utility to invoke the scavenger. This is needed in test code to |
| 1071 | // ensure correct callback for weak global handles. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1072 | void PerformScavenge(); |
| 1073 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1074 | inline void increment_scan_on_scavenge_pages() { |
| 1075 | scan_on_scavenge_pages_++; |
| 1076 | if (FLAG_gc_verbose) { |
| 1077 | PrintF("Scan-on-scavenge pages: %d\n", scan_on_scavenge_pages_); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | inline void decrement_scan_on_scavenge_pages() { |
| 1082 | scan_on_scavenge_pages_--; |
| 1083 | if (FLAG_gc_verbose) { |
| 1084 | PrintF("Scan-on-scavenge pages: %d\n", scan_on_scavenge_pages_); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1088 | PromotionQueue* promotion_queue() { return &promotion_queue_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1089 | |
| 1090 | #ifdef DEBUG |
| 1091 | // Utility used with flag gc-greedy. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1092 | void GarbageCollectionGreedyCheck(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1093 | #endif |
| 1094 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1095 | void AddGCPrologueCallback( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1096 | GCEpilogueCallback callback, GCType gc_type_filter); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1097 | void RemoveGCPrologueCallback(GCEpilogueCallback callback); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1098 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1099 | void AddGCEpilogueCallback( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1100 | GCEpilogueCallback callback, GCType gc_type_filter); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1101 | void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1102 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1103 | void SetGlobalGCPrologueCallback(GCCallback callback) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1104 | ASSERT((callback == NULL) ^ (global_gc_prologue_callback_ == NULL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1105 | global_gc_prologue_callback_ = callback; |
| 1106 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1107 | void SetGlobalGCEpilogueCallback(GCCallback callback) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1108 | ASSERT((callback == NULL) ^ (global_gc_epilogue_callback_ == NULL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1109 | global_gc_epilogue_callback_ = callback; |
| 1110 | } |
| 1111 | |
| 1112 | // Heap root getters. We have versions with and without type::cast() here. |
| 1113 | // You can't use type::cast during GC because the assert fails. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1114 | // TODO(1490): Try removing the unchecked accessors, now that GC marking does |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1115 | // not corrupt the map. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1116 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1117 | type* name() { \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1118 | return type::cast(roots_[k##camel_name##RootIndex]); \ |
| 1119 | } \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1120 | type* raw_unchecked_##name() { \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1121 | return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \ |
| 1122 | } |
| 1123 | ROOT_LIST(ROOT_ACCESSOR) |
| 1124 | #undef ROOT_ACCESSOR |
| 1125 | |
| 1126 | // Utility type maps |
| 1127 | #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1128 | Map* name##_map() { \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1129 | return Map::cast(roots_[k##Name##MapRootIndex]); \ |
| 1130 | } |
| 1131 | STRUCT_LIST(STRUCT_MAP_ACCESSOR) |
| 1132 | #undef STRUCT_MAP_ACCESSOR |
| 1133 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1134 | #define SYMBOL_ACCESSOR(name, str) String* name() { \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1135 | return String::cast(roots_[k##name##RootIndex]); \ |
| 1136 | } |
| 1137 | SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 1138 | #undef SYMBOL_ACCESSOR |
| 1139 | |
| 1140 | // The hidden_symbol is special because it is the empty string, but does |
| 1141 | // not match the empty string. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1142 | String* hidden_symbol() { return hidden_symbol_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1143 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1144 | void set_global_contexts_list(Object* object) { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1145 | global_contexts_list_ = object; |
| 1146 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1147 | Object* global_contexts_list() { return global_contexts_list_; } |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1148 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1149 | // Number of mark-sweeps. |
| 1150 | int ms_count() { return ms_count_; } |
| 1151 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1152 | // Iterates over all roots in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1153 | void IterateRoots(ObjectVisitor* v, VisitMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1154 | // Iterates over all strong roots in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1155 | void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1156 | // Iterates over all the other roots in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1157 | void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1158 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 1159 | // Iterate pointers to from semispace of new space found in memory interval |
| 1160 | // from start to end. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1161 | void IterateAndMarkPointersToFromSpace(Address start, |
| 1162 | Address end, |
| 1163 | ObjectSlotCallback callback); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1164 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1165 | // Returns whether the object resides in new space. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1166 | inline bool InNewSpace(Object* object); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1167 | inline bool InNewSpace(Address addr); |
| 1168 | inline bool InNewSpacePage(Address addr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1169 | inline bool InFromSpace(Object* object); |
| 1170 | inline bool InToSpace(Object* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1171 | |
| 1172 | // Checks whether an address/object in the heap (including auxiliary |
| 1173 | // area and unused area). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1174 | bool Contains(Address addr); |
| 1175 | bool Contains(HeapObject* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1176 | |
| 1177 | // Checks whether an address/object in a space. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1178 | // Currently used by tests, serialization and heap verification only. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1179 | bool InSpace(Address addr, AllocationSpace space); |
| 1180 | bool InSpace(HeapObject* value, AllocationSpace space); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1181 | |
| 1182 | // Finds out which space an object should get promoted to based on its type. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1183 | inline OldSpace* TargetSpace(HeapObject* object); |
| 1184 | inline AllocationSpace TargetSpaceId(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1185 | |
| 1186 | // Sets the stub_cache_ (only used when expanding the dictionary). |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1187 | void public_set_code_stubs(UnseededNumberDictionary* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1188 | roots_[kCodeStubsRootIndex] = value; |
| 1189 | } |
| 1190 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1191 | // Support for computing object sizes for old objects during GCs. Returns |
| 1192 | // a function that is guaranteed to be safe for computing object sizes in |
| 1193 | // the current GC phase. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1194 | HeapObjectCallback GcSafeSizeOfOldObjectFunction() { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1195 | return gc_safe_size_of_old_object_; |
| 1196 | } |
| 1197 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1198 | // Sets the non_monomorphic_cache_ (only used when expanding the dictionary). |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1199 | void public_set_non_monomorphic_cache(UnseededNumberDictionary* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1200 | roots_[kNonMonomorphicCacheRootIndex] = value; |
| 1201 | } |
| 1202 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1203 | void public_set_empty_script(Script* script) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1204 | roots_[kEmptyScriptRootIndex] = script; |
| 1205 | } |
| 1206 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1207 | void public_set_store_buffer_top(Address* top) { |
| 1208 | roots_[kStoreBufferTopRootIndex] = reinterpret_cast<Smi*>(top); |
| 1209 | } |
| 1210 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1211 | // Update the next script id. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1212 | inline void SetLastScriptId(Object* last_script_id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1213 | |
| 1214 | // Generated code can embed this address to get access to the roots. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1215 | Object** roots_array_start() { return roots_; } |
| 1216 | |
| 1217 | Address* store_buffer_top_address() { |
| 1218 | return reinterpret_cast<Address*>(&roots_[kStoreBufferTopRootIndex]); |
| 1219 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1220 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1221 | // Get address of global contexts list for serialization support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1222 | Object** global_contexts_list_address() { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1223 | return &global_contexts_list_; |
| 1224 | } |
| 1225 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1226 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1227 | void Print(); |
| 1228 | void PrintHandles(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1229 | |
| 1230 | // Verify the heap is in its normal state before or after a GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1231 | void Verify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1232 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1233 | // Verify that AccessorPairs are not shared, i.e. make sure that they have |
| 1234 | // exactly one pointer to them. |
| 1235 | void VerifyNoAccessorPairSharing(); |
| 1236 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1237 | void OldPointerSpaceCheckStoreBuffer(); |
| 1238 | void MapSpaceCheckStoreBuffer(); |
| 1239 | void LargeObjectSpaceCheckStoreBuffer(); |
| 1240 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1241 | // Report heap statistics. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1242 | void ReportHeapStatistics(const char* title); |
| 1243 | void ReportCodeStatistics(const char* title); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1244 | |
| 1245 | // Fill in bogus values in from space |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1246 | void ZapFromSpace(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1247 | #endif |
| 1248 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1249 | // Print short heap statistics. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1250 | void PrintShortHeapStatistics(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Makes a new symbol object |
| 1253 | // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 1254 | // failed. |
| 1255 | // Please note this function does not perform a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1256 | MUST_USE_RESULT MaybeObject* CreateSymbol( |
| 1257 | const char* str, int length, int hash); |
| 1258 | MUST_USE_RESULT MaybeObject* CreateSymbol(String* str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1259 | |
| 1260 | // Write barrier support for address[offset] = o. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1261 | inline void RecordWrite(Address address, int offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1262 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1263 | // Write barrier support for address[start : start + len[ = o. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1264 | inline void RecordWrites(Address address, int start, int len); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1265 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1266 | // Given an address occupied by a live code object, return that object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1267 | Object* FindCodeObject(Address a); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1268 | |
| 1269 | // Invoke Shrink on shrinkable spaces. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1270 | void Shrink(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1271 | |
| 1272 | enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1273 | inline HeapState gc_state() { return gc_state_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1274 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1275 | inline bool IsInGCPostProcessing() { return gc_post_processing_depth_ > 0; } |
| 1276 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1277 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1278 | bool IsAllocationAllowed() { return allocation_allowed_; } |
| 1279 | inline bool allow_allocation(bool enable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1280 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1281 | bool disallow_allocation_failure() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1282 | return disallow_allocation_failure_; |
| 1283 | } |
| 1284 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1285 | void TracePathToObject(Object* target); |
| 1286 | void TracePathToGlobal(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1287 | #endif |
| 1288 | |
| 1289 | // Callback function passed to Heap::Iterate etc. Copies an object if |
| 1290 | // necessary, the object might be promoted to an old space. The caller must |
| 1291 | // ensure the precondition that the object is (a) a heap object and (b) in |
| 1292 | // the heap's from space. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1293 | static inline void ScavengePointer(HeapObject** p); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1294 | static inline void ScavengeObject(HeapObject** p, HeapObject* object); |
| 1295 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1296 | // Commits from space if it is uncommitted. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1297 | void EnsureFromSpaceIsCommitted(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1298 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1299 | // Support for partial snapshots. After calling this we can allocate a |
| 1300 | // certain number of bytes using only linear allocation (with a |
| 1301 | // LinearAllocationScope and an AlwaysAllocateScope) without using freelists |
| 1302 | // or causing a GC. It returns true of space was reserved or false if a GC is |
| 1303 | // needed. For paged spaces the space requested must include the space wasted |
| 1304 | // at the end of each page when allocating linearly. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1305 | void ReserveSpace( |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1306 | int new_space_size, |
| 1307 | int pointer_space_size, |
| 1308 | int data_space_size, |
| 1309 | int code_space_size, |
| 1310 | int map_space_size, |
| 1311 | int cell_space_size, |
| 1312 | int large_object_size); |
| 1313 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1314 | // |
| 1315 | // Support for the API. |
| 1316 | // |
| 1317 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1318 | bool CreateApiObjects(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Attempt to find the number in a small cache. If we finds it, return |
| 1321 | // the string representation of the number. Otherwise return undefined. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1322 | Object* GetNumberStringCache(Object* number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1323 | |
| 1324 | // Update the cache with a new number-string pair. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1325 | void SetNumberStringCache(Object* number, String* str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1326 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1327 | // Adjusts the amount of registered external memory. |
| 1328 | // Returns the adjusted value. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1329 | inline int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1330 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1331 | // Allocate uninitialized fixed array. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1332 | MUST_USE_RESULT MaybeObject* AllocateRawFixedArray(int length); |
| 1333 | MUST_USE_RESULT MaybeObject* AllocateRawFixedArray(int length, |
| 1334 | PretenureFlag pretenure); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1335 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1336 | inline intptr_t PromotedTotalSize() { |
| 1337 | return PromotedSpaceSize() + PromotedExternalMemorySize(); |
| 1338 | } |
| 1339 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1340 | // True if we have reached the allocation limit in the old generation that |
| 1341 | // should force the next GC (caused normally) to be a full one. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1342 | inline bool OldGenerationPromotionLimitReached() { |
| 1343 | return PromotedTotalSize() > old_gen_promotion_limit_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1346 | inline intptr_t OldGenerationSpaceAvailable() { |
| 1347 | return old_gen_allocation_limit_ - PromotedTotalSize(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1350 | inline intptr_t OldGenerationCapacityAvailable() { |
| 1351 | return max_old_generation_size_ - PromotedTotalSize(); |
| 1352 | } |
| 1353 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1354 | static const intptr_t kMinimumPromotionLimit = 5 * Page::kPageSize; |
| 1355 | static const intptr_t kMinimumAllocationLimit = |
| 1356 | 8 * (Page::kPageSize > MB ? Page::kPageSize : MB); |
| 1357 | |
| 1358 | // When we sweep lazily we initially guess that there is no garbage on the |
| 1359 | // heap and set the limits for the next GC accordingly. As we sweep we find |
| 1360 | // out that some of the pages contained garbage and we have to adjust |
| 1361 | // downwards the size of the heap. This means the limits that control the |
| 1362 | // timing of the next GC also need to be adjusted downwards. |
| 1363 | void LowerOldGenLimits(intptr_t adjustment) { |
| 1364 | size_of_old_gen_at_last_old_space_gc_ -= adjustment; |
| 1365 | old_gen_promotion_limit_ = |
| 1366 | OldGenPromotionLimit(size_of_old_gen_at_last_old_space_gc_); |
| 1367 | old_gen_allocation_limit_ = |
| 1368 | OldGenAllocationLimit(size_of_old_gen_at_last_old_space_gc_); |
| 1369 | } |
| 1370 | |
| 1371 | intptr_t OldGenPromotionLimit(intptr_t old_gen_size) { |
| 1372 | const int divisor = FLAG_stress_compaction ? 10 : 3; |
| 1373 | intptr_t limit = |
| 1374 | Max(old_gen_size + old_gen_size / divisor, kMinimumPromotionLimit); |
| 1375 | limit += new_space_.Capacity(); |
| 1376 | limit *= old_gen_limit_factor_; |
| 1377 | intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2; |
| 1378 | return Min(limit, halfway_to_the_max); |
| 1379 | } |
| 1380 | |
| 1381 | intptr_t OldGenAllocationLimit(intptr_t old_gen_size) { |
| 1382 | const int divisor = FLAG_stress_compaction ? 8 : 2; |
| 1383 | intptr_t limit = |
| 1384 | Max(old_gen_size + old_gen_size / divisor, kMinimumAllocationLimit); |
| 1385 | limit += new_space_.Capacity(); |
| 1386 | limit *= old_gen_limit_factor_; |
| 1387 | intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2; |
| 1388 | return Min(limit, halfway_to_the_max); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1391 | // Implements the corresponding V8 API function. |
| 1392 | bool IdleNotification(int hint); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1393 | |
| 1394 | // Declare all the root indices. |
| 1395 | enum RootListIndex { |
| 1396 | #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, |
| 1397 | STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) |
| 1398 | #undef ROOT_INDEX_DECLARATION |
| 1399 | |
| 1400 | // Utility type maps |
| 1401 | #define DECLARE_STRUCT_MAP(NAME, Name, name) k##Name##MapRootIndex, |
| 1402 | STRUCT_LIST(DECLARE_STRUCT_MAP) |
| 1403 | #undef DECLARE_STRUCT_MAP |
| 1404 | |
| 1405 | #define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex, |
| 1406 | SYMBOL_LIST(SYMBOL_INDEX_DECLARATION) |
| 1407 | #undef SYMBOL_DECLARATION |
| 1408 | |
| 1409 | kSymbolTableRootIndex, |
| 1410 | kStrongRootListLength = kSymbolTableRootIndex, |
| 1411 | kRootListLength |
| 1412 | }; |
| 1413 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1414 | MUST_USE_RESULT MaybeObject* NumberToString( |
| 1415 | Object* number, bool check_number_string_cache = true); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1416 | MUST_USE_RESULT MaybeObject* Uint32ToString( |
| 1417 | uint32_t value, bool check_number_string_cache = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1418 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1419 | Map* MapForExternalArrayType(ExternalArrayType array_type); |
| 1420 | RootListIndex RootIndexForExternalArrayType( |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1421 | ExternalArrayType array_type); |
| 1422 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1423 | void RecordStats(HeapStats* stats, bool take_snapshot = false); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1424 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1425 | // Copy block of memory from src to dst. Size of block should be aligned |
| 1426 | // by pointer size. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1427 | static inline void CopyBlock(Address dst, Address src, int byte_size); |
| 1428 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1429 | // Optimized version of memmove for blocks with pointer size aligned sizes and |
| 1430 | // pointer size aligned addresses. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1431 | static inline void MoveBlock(Address dst, Address src, int byte_size); |
| 1432 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1433 | // Check new space expansion criteria and expand semispaces if it was hit. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1434 | void CheckNewSpaceExpansionCriteria(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1435 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1436 | inline void IncrementYoungSurvivorsCounter(int survived) { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1437 | ASSERT(survived >= 0); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1438 | young_survivors_after_last_gc_ = survived; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1439 | survived_since_last_expansion_ += survived; |
| 1440 | } |
| 1441 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1442 | inline bool NextGCIsLikelyToBeFull() { |
| 1443 | if (FLAG_gc_global) return true; |
| 1444 | |
| 1445 | intptr_t total_promoted = PromotedTotalSize(); |
| 1446 | |
| 1447 | intptr_t adjusted_promotion_limit = |
| 1448 | old_gen_promotion_limit_ - new_space_.Capacity(); |
| 1449 | |
| 1450 | if (total_promoted >= adjusted_promotion_limit) return true; |
| 1451 | |
| 1452 | intptr_t adjusted_allocation_limit = |
| 1453 | old_gen_allocation_limit_ - new_space_.Capacity() / 5; |
| 1454 | |
| 1455 | if (PromotedSpaceSize() >= adjusted_allocation_limit) return true; |
| 1456 | |
| 1457 | return false; |
| 1458 | } |
| 1459 | |
| 1460 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1461 | void UpdateNewSpaceReferencesInExternalStringTable( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1462 | ExternalStringTableUpdaterCallback updater_func); |
| 1463 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1464 | void UpdateReferencesInExternalStringTable( |
| 1465 | ExternalStringTableUpdaterCallback updater_func); |
| 1466 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1467 | void ProcessWeakReferences(WeakObjectRetainer* retainer); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1468 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1469 | void VisitExternalResources(v8::ExternalResourceVisitor* visitor); |
| 1470 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1471 | // Helper function that governs the promotion policy from new space to |
| 1472 | // old. If the object's old address lies below the new space's age |
| 1473 | // mark or if we've already filled the bottom 1/16th of the to space, |
| 1474 | // we try to promote this object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1475 | inline bool ShouldBePromoted(Address old_address, int object_size); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1476 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1477 | int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1478 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1479 | void ClearJSFunctionResultCaches(); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1480 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1481 | void ClearNormalizedMapCaches(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1482 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1483 | // Clears the cache of ICs related to this map. |
| 1484 | void ClearCacheOnMap(Map* map) { |
| 1485 | if (FLAG_cleanup_code_caches_at_gc) { |
| 1486 | map->ClearCodeCache(this); |
| 1487 | } |
| 1488 | } |
| 1489 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1490 | GCTracer* tracer() { return tracer_; } |
| 1491 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1492 | // Returns the size of objects residing in non new spaces. |
| 1493 | intptr_t PromotedSpaceSize(); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1494 | intptr_t PromotedSpaceSizeOfObjects(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1495 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1496 | double total_regexp_code_generated() { return total_regexp_code_generated_; } |
| 1497 | void IncreaseTotalRegexpCodeGenerated(int size) { |
| 1498 | total_regexp_code_generated_ += size; |
| 1499 | } |
| 1500 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1501 | // Returns maximum GC pause. |
| 1502 | int get_max_gc_pause() { return max_gc_pause_; } |
| 1503 | |
| 1504 | // Returns maximum size of objects alive after GC. |
| 1505 | intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } |
| 1506 | |
| 1507 | // Returns minimal interval between two subsequent collections. |
| 1508 | int get_min_in_mutator() { return min_in_mutator_; } |
| 1509 | |
| 1510 | MarkCompactCollector* mark_compact_collector() { |
| 1511 | return &mark_compact_collector_; |
| 1512 | } |
| 1513 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1514 | StoreBuffer* store_buffer() { |
| 1515 | return &store_buffer_; |
| 1516 | } |
| 1517 | |
| 1518 | Marking* marking() { |
| 1519 | return &marking_; |
| 1520 | } |
| 1521 | |
| 1522 | IncrementalMarking* incremental_marking() { |
| 1523 | return &incremental_marking_; |
| 1524 | } |
| 1525 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1526 | bool IsSweepingComplete() { |
| 1527 | return old_data_space()->IsSweepingComplete() && |
| 1528 | old_pointer_space()->IsSweepingComplete(); |
| 1529 | } |
| 1530 | |
| 1531 | bool AdvanceSweepers(int step_size) { |
| 1532 | bool sweeping_complete = old_data_space()->AdvanceSweeper(step_size); |
| 1533 | sweeping_complete &= old_pointer_space()->AdvanceSweeper(step_size); |
| 1534 | return sweeping_complete; |
| 1535 | } |
| 1536 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1537 | ExternalStringTable* external_string_table() { |
| 1538 | return &external_string_table_; |
| 1539 | } |
| 1540 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1541 | // Returns the current sweep generation. |
| 1542 | int sweep_generation() { |
| 1543 | return sweep_generation_; |
| 1544 | } |
| 1545 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1546 | inline Isolate* isolate(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1547 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1548 | inline void CallGlobalGCPrologueCallback() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1549 | if (global_gc_prologue_callback_ != NULL) global_gc_prologue_callback_(); |
| 1550 | } |
| 1551 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1552 | inline void CallGlobalGCEpilogueCallback() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1553 | if (global_gc_epilogue_callback_ != NULL) global_gc_epilogue_callback_(); |
| 1554 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1555 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1556 | inline bool OldGenerationAllocationLimitReached(); |
| 1557 | |
| 1558 | inline void DoScavengeObject(Map* map, HeapObject** slot, HeapObject* obj) { |
| 1559 | scavenging_visitors_table_.GetVisitor(map)(map, slot, obj); |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1562 | void QueueMemoryChunkForFree(MemoryChunk* chunk); |
| 1563 | void FreeQueuedChunks(); |
| 1564 | |
| 1565 | // Completely clear the Instanceof cache (to stop it keeping objects alive |
| 1566 | // around a GC). |
| 1567 | inline void CompletelyClearInstanceofCache(); |
| 1568 | |
| 1569 | // The roots that have an index less than this are always in old space. |
| 1570 | static const int kOldSpaceRoots = 0x20; |
| 1571 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1572 | bool idle_notification_will_schedule_next_gc() { |
| 1573 | return idle_notification_will_schedule_next_gc_; |
| 1574 | } |
| 1575 | |
| 1576 | uint32_t HashSeed() { |
| 1577 | uint32_t seed = static_cast<uint32_t>(hash_seed()->value()); |
| 1578 | ASSERT(FLAG_randomize_hashes || seed == 0); |
| 1579 | return seed; |
| 1580 | } |
| 1581 | |
| 1582 | void SetArgumentsAdaptorDeoptPCOffset(int pc_offset) { |
| 1583 | ASSERT(arguments_adaptor_deopt_pc_offset() == Smi::FromInt(0)); |
| 1584 | set_arguments_adaptor_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 1585 | } |
| 1586 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1587 | void SetConstructStubDeoptPCOffset(int pc_offset) { |
| 1588 | ASSERT(construct_stub_deopt_pc_offset() == Smi::FromInt(0)); |
| 1589 | set_construct_stub_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 1590 | } |
| 1591 | |
| 1592 | // For post mortem debugging. |
| 1593 | void RememberUnmappedPage(Address page, bool compacted); |
| 1594 | |
| 1595 | // Global inline caching age: it is incremented on some GCs after context |
| 1596 | // disposal. We use it to flush inline caches. |
| 1597 | int global_ic_age() { |
| 1598 | return global_ic_age_; |
| 1599 | } |
| 1600 | |
| 1601 | void AgeInlineCaches() { |
| 1602 | ++global_ic_age_; |
| 1603 | } |
| 1604 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1605 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1606 | Heap(); |
| 1607 | |
| 1608 | // This can be calculated directly from a pointer to the heap; however, it is |
| 1609 | // more expedient to get at the isolate directly from within Heap methods. |
| 1610 | Isolate* isolate_; |
| 1611 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1612 | intptr_t code_range_size_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1613 | int reserved_semispace_size_; |
| 1614 | int max_semispace_size_; |
| 1615 | int initial_semispace_size_; |
| 1616 | intptr_t max_old_generation_size_; |
| 1617 | intptr_t max_executable_size_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1618 | |
| 1619 | // For keeping track of how much data has survived |
| 1620 | // scavenge since last new space expansion. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1621 | int survived_since_last_expansion_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1622 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1623 | // For keeping track on when to flush RegExp code. |
| 1624 | int sweep_generation_; |
| 1625 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1626 | int always_allocate_scope_depth_; |
| 1627 | int linear_allocation_scope_depth_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1628 | |
| 1629 | // For keeping track of context disposals. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1630 | int contexts_disposed_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1631 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1632 | int global_ic_age_; |
| 1633 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1634 | int scan_on_scavenge_pages_; |
| 1635 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1636 | #if defined(V8_TARGET_ARCH_X64) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1637 | static const int kMaxObjectSizeInNewSpace = 1024*KB; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1638 | #else |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1639 | static const int kMaxObjectSizeInNewSpace = 512*KB; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1640 | #endif |
| 1641 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1642 | NewSpace new_space_; |
| 1643 | OldSpace* old_pointer_space_; |
| 1644 | OldSpace* old_data_space_; |
| 1645 | OldSpace* code_space_; |
| 1646 | MapSpace* map_space_; |
| 1647 | CellSpace* cell_space_; |
| 1648 | LargeObjectSpace* lo_space_; |
| 1649 | HeapState gc_state_; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1650 | int gc_post_processing_depth_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1651 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1652 | // Returns the amount of external memory registered since last global gc. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1653 | int PromotedExternalMemorySize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1654 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1655 | int ms_count_; // how many mark-sweep collections happened |
| 1656 | unsigned int gc_count_; // how many gc happened |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1657 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1658 | // For post mortem debugging. |
| 1659 | static const int kRememberedUnmappedPages = 128; |
| 1660 | int remembered_unmapped_pages_index_; |
| 1661 | Address remembered_unmapped_pages_[kRememberedUnmappedPages]; |
| 1662 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1663 | // Total length of the strings we failed to flatten since the last GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1664 | int unflattened_strings_length_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1666 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1667 | inline void set_##name(type* value) { \ |
| 1668 | /* The deserializer makes use of the fact that these common roots are */ \ |
| 1669 | /* never in new space and never on a page that is being compacted. */ \ |
| 1670 | ASSERT(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1671 | roots_[k##camel_name##RootIndex] = value; \ |
| 1672 | } |
| 1673 | ROOT_LIST(ROOT_ACCESSOR) |
| 1674 | #undef ROOT_ACCESSOR |
| 1675 | |
| 1676 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1677 | bool allocation_allowed_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1678 | |
| 1679 | // If the --gc-interval flag is set to a positive value, this |
| 1680 | // variable holds the value indicating the number of allocations |
| 1681 | // remain until the next failure and garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1682 | int allocation_timeout_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1683 | |
| 1684 | // Do we expect to be able to handle allocation failure at this |
| 1685 | // time? |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1686 | bool disallow_allocation_failure_; |
| 1687 | |
| 1688 | HeapDebugUtils* debug_utils_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1689 | #endif // DEBUG |
| 1690 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1691 | // Indicates that the new space should be kept small due to high promotion |
| 1692 | // rates caused by the mutator allocating a lot of long-lived objects. |
| 1693 | bool new_space_high_promotion_mode_active_; |
| 1694 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1695 | // Limit that triggers a global GC on the next (normally caused) GC. This |
| 1696 | // is checked when we have already decided to do a GC to help determine |
| 1697 | // which collector to invoke. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1698 | intptr_t old_gen_promotion_limit_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Limit that triggers a global GC as soon as is reasonable. This is |
| 1701 | // checked before expanding a paged space in the old generation and on |
| 1702 | // every allocation in large object space. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1703 | intptr_t old_gen_allocation_limit_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1704 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1705 | // Sometimes the heuristics dictate that those limits are increased. This |
| 1706 | // variable records that fact. |
| 1707 | int old_gen_limit_factor_; |
| 1708 | |
| 1709 | // Used to adjust the limits that control the timing of the next GC. |
| 1710 | intptr_t size_of_old_gen_at_last_old_space_gc_; |
| 1711 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1712 | // Limit on the amount of externally allocated memory allowed |
| 1713 | // between global GCs. If reached a global GC is forced. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1714 | intptr_t external_allocation_limit_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1715 | |
| 1716 | // The amount of external memory registered through the API kept alive |
| 1717 | // by global handles |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1718 | int amount_of_external_allocated_memory_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1719 | |
| 1720 | // Caches the amount of external memory registered at the last global gc. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1721 | int amount_of_external_allocated_memory_at_last_global_gc_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1722 | |
| 1723 | // Indicates that an allocation has failed in the old generation since the |
| 1724 | // last GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1725 | int old_gen_exhausted_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1726 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1727 | Object* roots_[kRootListLength]; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1728 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1729 | Object* global_contexts_list_; |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1730 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1731 | StoreBufferRebuilder store_buffer_rebuilder_; |
| 1732 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1733 | struct StringTypeTable { |
| 1734 | InstanceType type; |
| 1735 | int size; |
| 1736 | RootListIndex index; |
| 1737 | }; |
| 1738 | |
| 1739 | struct ConstantSymbolTable { |
| 1740 | const char* contents; |
| 1741 | RootListIndex index; |
| 1742 | }; |
| 1743 | |
| 1744 | struct StructTable { |
| 1745 | InstanceType type; |
| 1746 | int size; |
| 1747 | RootListIndex index; |
| 1748 | }; |
| 1749 | |
| 1750 | static const StringTypeTable string_type_table[]; |
| 1751 | static const ConstantSymbolTable constant_symbol_table[]; |
| 1752 | static const StructTable struct_table[]; |
| 1753 | |
| 1754 | // The special hidden symbol which is an empty string, but does not match |
| 1755 | // any string when looked up in properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1756 | String* hidden_symbol_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1757 | |
| 1758 | // GC callback function, called before and after mark-compact GC. |
| 1759 | // Allocations in the callback function are disallowed. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1760 | struct GCPrologueCallbackPair { |
| 1761 | GCPrologueCallbackPair(GCPrologueCallback callback, GCType gc_type) |
| 1762 | : callback(callback), gc_type(gc_type) { |
| 1763 | } |
| 1764 | bool operator==(const GCPrologueCallbackPair& pair) const { |
| 1765 | return pair.callback == callback; |
| 1766 | } |
| 1767 | GCPrologueCallback callback; |
| 1768 | GCType gc_type; |
| 1769 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1770 | List<GCPrologueCallbackPair> gc_prologue_callbacks_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1771 | |
| 1772 | struct GCEpilogueCallbackPair { |
| 1773 | GCEpilogueCallbackPair(GCEpilogueCallback callback, GCType gc_type) |
| 1774 | : callback(callback), gc_type(gc_type) { |
| 1775 | } |
| 1776 | bool operator==(const GCEpilogueCallbackPair& pair) const { |
| 1777 | return pair.callback == callback; |
| 1778 | } |
| 1779 | GCEpilogueCallback callback; |
| 1780 | GCType gc_type; |
| 1781 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1782 | List<GCEpilogueCallbackPair> gc_epilogue_callbacks_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1783 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1784 | GCCallback global_gc_prologue_callback_; |
| 1785 | GCCallback global_gc_epilogue_callback_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1786 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1787 | // Support for computing object sizes during GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1788 | HeapObjectCallback gc_safe_size_of_old_object_; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1789 | static int GcSafeSizeOfOldObject(HeapObject* object); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1790 | |
| 1791 | // Update the GC state. Called from the mark-compact collector. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1792 | void MarkMapPointersAsEncoded(bool encoded) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1793 | ASSERT(!encoded); |
| 1794 | gc_safe_size_of_old_object_ = &GcSafeSizeOfOldObject; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1797 | // Checks whether a global GC is necessary |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1798 | GarbageCollector SelectGarbageCollector(AllocationSpace space, |
| 1799 | const char** reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1800 | |
| 1801 | // Performs garbage collection |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1802 | // Returns whether there is a chance another major GC could |
| 1803 | // collect more garbage. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1804 | bool PerformGarbageCollection(GarbageCollector collector, |
| 1805 | GCTracer* tracer); |
| 1806 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1807 | |
| 1808 | inline void UpdateOldSpaceLimits(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1809 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1810 | // Allocate an uninitialized object in map space. The behavior is identical |
| 1811 | // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't |
| 1812 | // have to test the allocation space argument and (b) can reduce code size |
| 1813 | // (since both AllocateRaw and AllocateRawMap are inlined). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1814 | MUST_USE_RESULT inline MaybeObject* AllocateRawMap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1815 | |
| 1816 | // Allocate an uninitialized object in the global property cell space. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1817 | MUST_USE_RESULT inline MaybeObject* AllocateRawCell(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1818 | |
| 1819 | // Initializes a JSObject based on its map. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1820 | void InitializeJSObjectFromMap(JSObject* obj, |
| 1821 | FixedArray* properties, |
| 1822 | Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1823 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1824 | bool CreateInitialMaps(); |
| 1825 | bool CreateInitialObjects(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1826 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1827 | // These five Create*EntryStub functions are here and forced to not be inlined |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1828 | // because of a gcc-4.4 bug that assigns wrong vtable entries. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1829 | NO_INLINE(void CreateJSEntryStub()); |
| 1830 | NO_INLINE(void CreateJSConstructEntryStub()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1831 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1832 | void CreateFixedStubs(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1833 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1834 | MaybeObject* CreateOddball(const char* to_string, |
| 1835 | Object* to_number, |
| 1836 | byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1837 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1838 | // Allocate a JSArray with no elements |
| 1839 | MUST_USE_RESULT MaybeObject* AllocateJSArray( |
| 1840 | ElementsKind elements_kind, |
| 1841 | PretenureFlag pretenure = NOT_TENURED); |
| 1842 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1843 | // Allocate empty fixed array. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1844 | MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1845 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1846 | // Allocate empty fixed double array. |
| 1847 | MUST_USE_RESULT MaybeObject* AllocateEmptyFixedDoubleArray(); |
| 1848 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1849 | // Performs a minor collection in new generation. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1850 | void Scavenge(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1851 | |
| 1852 | static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1853 | Heap* heap, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1854 | Object** pointer); |
| 1855 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1856 | Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1857 | static void ScavengeStoreBufferCallback(Heap* heap, |
| 1858 | MemoryChunk* page, |
| 1859 | StoreBufferEvent event); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1860 | |
| 1861 | // Performs a major collection in the whole heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1862 | void MarkCompact(GCTracer* tracer); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1863 | |
| 1864 | // Code to be run before and after mark-compact. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1865 | void MarkCompactPrologue(); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1866 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1867 | // Record statistics before and after garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1868 | void ReportStatisticsBeforeGC(); |
| 1869 | void ReportStatisticsAfterGC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1870 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1871 | // Slow part of scavenge object. |
| 1872 | static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
| 1873 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1874 | // Initializes a function with a shared part and prototype. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1875 | // Note: this code was factored out of AllocateFunction such that |
| 1876 | // other parts of the VM could use it. Specifically, a function that creates |
| 1877 | // instances of type JS_FUNCTION_TYPE benefit from the use of this function. |
| 1878 | // Please note this does not perform a garbage collection. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1879 | inline void InitializeFunction( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1880 | JSFunction* function, |
| 1881 | SharedFunctionInfo* shared, |
| 1882 | Object* prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1883 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1884 | // Total RegExp code ever generated |
| 1885 | double total_regexp_code_generated_; |
| 1886 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1887 | GCTracer* tracer_; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1888 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1889 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1890 | // Allocates a small number to string cache. |
| 1891 | MUST_USE_RESULT MaybeObject* AllocateInitialNumberStringCache(); |
| 1892 | // Creates and installs the full-sized number string cache. |
| 1893 | void AllocateFullSizeNumberStringCache(); |
| 1894 | // Get the length of the number to string cache based on the max semispace |
| 1895 | // size. |
| 1896 | int FullSizeNumberStringCacheLength(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1897 | // Flush the number to string cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1898 | void FlushNumberStringCache(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1899 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1900 | void UpdateSurvivalRateTrend(int start_new_space_size); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1901 | |
| 1902 | enum SurvivalRateTrend { INCREASING, STABLE, DECREASING, FLUCTUATING }; |
| 1903 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1904 | static const int kYoungSurvivalRateHighThreshold = 90; |
| 1905 | static const int kYoungSurvivalRateLowThreshold = 10; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1906 | static const int kYoungSurvivalRateAllowedDeviation = 15; |
| 1907 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1908 | int young_survivors_after_last_gc_; |
| 1909 | int high_survival_rate_period_length_; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1910 | int low_survival_rate_period_length_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1911 | double survival_rate_; |
| 1912 | SurvivalRateTrend previous_survival_rate_trend_; |
| 1913 | SurvivalRateTrend survival_rate_trend_; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1914 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1915 | void set_survival_rate_trend(SurvivalRateTrend survival_rate_trend) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1916 | ASSERT(survival_rate_trend != FLUCTUATING); |
| 1917 | previous_survival_rate_trend_ = survival_rate_trend_; |
| 1918 | survival_rate_trend_ = survival_rate_trend; |
| 1919 | } |
| 1920 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1921 | SurvivalRateTrend survival_rate_trend() { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1922 | if (survival_rate_trend_ == STABLE) { |
| 1923 | return STABLE; |
| 1924 | } else if (previous_survival_rate_trend_ == STABLE) { |
| 1925 | return survival_rate_trend_; |
| 1926 | } else if (survival_rate_trend_ != previous_survival_rate_trend_) { |
| 1927 | return FLUCTUATING; |
| 1928 | } else { |
| 1929 | return survival_rate_trend_; |
| 1930 | } |
| 1931 | } |
| 1932 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1933 | bool IsStableOrIncreasingSurvivalTrend() { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1934 | switch (survival_rate_trend()) { |
| 1935 | case STABLE: |
| 1936 | case INCREASING: |
| 1937 | return true; |
| 1938 | default: |
| 1939 | return false; |
| 1940 | } |
| 1941 | } |
| 1942 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1943 | bool IsStableOrDecreasingSurvivalTrend() { |
| 1944 | switch (survival_rate_trend()) { |
| 1945 | case STABLE: |
| 1946 | case DECREASING: |
| 1947 | return true; |
| 1948 | default: |
| 1949 | return false; |
| 1950 | } |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1951 | } |
| 1952 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1953 | bool IsIncreasingSurvivalTrend() { |
| 1954 | return survival_rate_trend() == INCREASING; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1957 | bool IsHighSurvivalRate() { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1958 | return high_survival_rate_period_length_ > 0; |
| 1959 | } |
| 1960 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1961 | bool IsLowSurvivalRate() { |
| 1962 | return low_survival_rate_period_length_ > 0; |
| 1963 | } |
| 1964 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1965 | void SelectScavengingVisitorsTable(); |
| 1966 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1967 | void StartIdleRound() { |
| 1968 | mark_sweeps_since_idle_round_started_ = 0; |
| 1969 | ms_count_at_last_idle_notification_ = ms_count_; |
| 1970 | } |
| 1971 | |
| 1972 | void FinishIdleRound() { |
| 1973 | mark_sweeps_since_idle_round_started_ = kMaxMarkSweepsInIdleRound; |
| 1974 | scavenges_since_last_idle_round_ = 0; |
| 1975 | } |
| 1976 | |
| 1977 | bool EnoughGarbageSinceLastIdleRound() { |
| 1978 | return (scavenges_since_last_idle_round_ >= kIdleScavengeThreshold); |
| 1979 | } |
| 1980 | |
| 1981 | bool WorthStartingGCWhenIdle() { |
| 1982 | if (contexts_disposed_ > 0) { |
| 1983 | return true; |
| 1984 | } |
| 1985 | return incremental_marking()->WorthActivating(); |
| 1986 | } |
| 1987 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1988 | // Estimates how many milliseconds a Mark-Sweep would take to complete. |
| 1989 | // In idle notification handler we assume that this function will return: |
| 1990 | // - a number less than 10 for small heaps, which are less than 8Mb. |
| 1991 | // - a number greater than 10 for large heaps, which are greater than 32Mb. |
| 1992 | int TimeMarkSweepWouldTakeInMs() { |
| 1993 | // Rough estimate of how many megabytes of heap can be processed in 1 ms. |
| 1994 | static const int kMbPerMs = 2; |
| 1995 | |
| 1996 | int heap_size_mb = static_cast<int>(SizeOfObjects() / MB); |
| 1997 | return heap_size_mb / kMbPerMs; |
| 1998 | } |
| 1999 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2000 | // Returns true if no more GC work is left. |
| 2001 | bool IdleGlobalGC(); |
| 2002 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2003 | void AdvanceIdleIncrementalMarking(intptr_t step_size); |
| 2004 | |
| 2005 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2006 | static const int kInitialSymbolTableSize = 2048; |
| 2007 | static const int kInitialEvalCacheSize = 64; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2008 | static const int kInitialNumberStringCacheSize = 256; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2009 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2010 | // Maximum GC pause. |
| 2011 | int max_gc_pause_; |
| 2012 | |
| 2013 | // Maximum size of objects alive after GC. |
| 2014 | intptr_t max_alive_after_gc_; |
| 2015 | |
| 2016 | // Minimal interval between two subsequent collections. |
| 2017 | int min_in_mutator_; |
| 2018 | |
| 2019 | // Size of objects alive after last GC. |
| 2020 | intptr_t alive_after_last_gc_; |
| 2021 | |
| 2022 | double last_gc_end_timestamp_; |
| 2023 | |
| 2024 | MarkCompactCollector mark_compact_collector_; |
| 2025 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2026 | StoreBuffer store_buffer_; |
| 2027 | |
| 2028 | Marking marking_; |
| 2029 | |
| 2030 | IncrementalMarking incremental_marking_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2031 | |
| 2032 | int number_idle_notifications_; |
| 2033 | unsigned int last_idle_notification_gc_count_; |
| 2034 | bool last_idle_notification_gc_count_init_; |
| 2035 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2036 | bool idle_notification_will_schedule_next_gc_; |
| 2037 | int mark_sweeps_since_idle_round_started_; |
| 2038 | int ms_count_at_last_idle_notification_; |
| 2039 | unsigned int gc_count_at_last_idle_gc_; |
| 2040 | int scavenges_since_last_idle_round_; |
| 2041 | |
| 2042 | static const int kMaxMarkSweepsInIdleRound = 7; |
| 2043 | static const int kIdleScavengeThreshold = 5; |
| 2044 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2045 | // Shared state read by the scavenge collector and set by ScavengeObject. |
| 2046 | PromotionQueue promotion_queue_; |
| 2047 | |
| 2048 | // Flag is set when the heap has been configured. The heap can be repeatedly |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2049 | // configured through the API until it is set up. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2050 | bool configured_; |
| 2051 | |
| 2052 | ExternalStringTable external_string_table_; |
| 2053 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2054 | VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
| 2055 | |
| 2056 | MemoryChunk* chunks_queued_for_free_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2057 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2058 | friend class Factory; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2059 | friend class GCTracer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2060 | friend class DisallowAllocationFailure; |
| 2061 | friend class AlwaysAllocateScope; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2062 | friend class LinearAllocationScope; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2063 | friend class Page; |
| 2064 | friend class Isolate; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2065 | friend class MarkCompactCollector; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2066 | friend class StaticMarkingVisitor; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2067 | friend class MapCompact; |
| 2068 | |
| 2069 | DISALLOW_COPY_AND_ASSIGN(Heap); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2070 | }; |
| 2071 | |
| 2072 | |
| 2073 | class HeapStats { |
| 2074 | public: |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2075 | static const int kStartMarker = 0xDECADE00; |
| 2076 | static const int kEndMarker = 0xDECADE01; |
| 2077 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2078 | int* start_marker; // 0 |
| 2079 | int* new_space_size; // 1 |
| 2080 | int* new_space_capacity; // 2 |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2081 | intptr_t* old_pointer_space_size; // 3 |
| 2082 | intptr_t* old_pointer_space_capacity; // 4 |
| 2083 | intptr_t* old_data_space_size; // 5 |
| 2084 | intptr_t* old_data_space_capacity; // 6 |
| 2085 | intptr_t* code_space_size; // 7 |
| 2086 | intptr_t* code_space_capacity; // 8 |
| 2087 | intptr_t* map_space_size; // 9 |
| 2088 | intptr_t* map_space_capacity; // 10 |
| 2089 | intptr_t* cell_space_size; // 11 |
| 2090 | intptr_t* cell_space_capacity; // 12 |
| 2091 | intptr_t* lo_space_size; // 13 |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2092 | int* global_handle_count; // 14 |
| 2093 | int* weak_global_handle_count; // 15 |
| 2094 | int* pending_global_handle_count; // 16 |
| 2095 | int* near_death_global_handle_count; // 17 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2096 | int* free_global_handle_count; // 18 |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2097 | intptr_t* memory_allocator_size; // 19 |
| 2098 | intptr_t* memory_allocator_capacity; // 20 |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2099 | int* objects_per_type; // 21 |
| 2100 | int* size_per_type; // 22 |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2101 | int* os_error; // 23 |
| 2102 | int* end_marker; // 24 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2103 | }; |
| 2104 | |
| 2105 | |
| 2106 | class AlwaysAllocateScope { |
| 2107 | public: |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2108 | inline AlwaysAllocateScope(); |
| 2109 | inline ~AlwaysAllocateScope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2110 | }; |
| 2111 | |
| 2112 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2113 | class LinearAllocationScope { |
| 2114 | public: |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2115 | inline LinearAllocationScope(); |
| 2116 | inline ~LinearAllocationScope(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2117 | }; |
| 2118 | |
| 2119 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2120 | #ifdef DEBUG |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2121 | // Visitor class to verify interior pointers in spaces that do not contain |
| 2122 | // or care about intergenerational references. All heap object pointers have to |
| 2123 | // point into the heap to a location that has a map pointer at its first word. |
| 2124 | // Caveat: Heap::Contains is an approximation because it can return true for |
| 2125 | // objects in a heap space but above the allocation pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2126 | class VerifyPointersVisitor: public ObjectVisitor { |
| 2127 | public: |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2128 | inline void VisitPointers(Object** start, Object** end); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2129 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2130 | #endif |
| 2131 | |
| 2132 | |
| 2133 | // Space iterator for iterating over all spaces of the heap. |
| 2134 | // Returns each space in turn, and null when it is done. |
| 2135 | class AllSpaces BASE_EMBEDDED { |
| 2136 | public: |
| 2137 | Space* next(); |
| 2138 | AllSpaces() { counter_ = FIRST_SPACE; } |
| 2139 | private: |
| 2140 | int counter_; |
| 2141 | }; |
| 2142 | |
| 2143 | |
| 2144 | // Space iterator for iterating over all old spaces of the heap: Old pointer |
| 2145 | // space, old data space and code space. |
| 2146 | // Returns each space in turn, and null when it is done. |
| 2147 | class OldSpaces BASE_EMBEDDED { |
| 2148 | public: |
| 2149 | OldSpace* next(); |
| 2150 | OldSpaces() { counter_ = OLD_POINTER_SPACE; } |
| 2151 | private: |
| 2152 | int counter_; |
| 2153 | }; |
| 2154 | |
| 2155 | |
| 2156 | // Space iterator for iterating over all the paged spaces of the heap: |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2157 | // Map space, old pointer space, old data space, code space and cell space. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2158 | // Returns each space in turn, and null when it is done. |
| 2159 | class PagedSpaces BASE_EMBEDDED { |
| 2160 | public: |
| 2161 | PagedSpace* next(); |
| 2162 | PagedSpaces() { counter_ = OLD_POINTER_SPACE; } |
| 2163 | private: |
| 2164 | int counter_; |
| 2165 | }; |
| 2166 | |
| 2167 | |
| 2168 | // Space iterator for iterating over all spaces of the heap. |
| 2169 | // For each space an object iterator is provided. The deallocation of the |
| 2170 | // returned object iterators is handled by the space iterator. |
| 2171 | class SpaceIterator : public Malloced { |
| 2172 | public: |
| 2173 | SpaceIterator(); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2174 | explicit SpaceIterator(HeapObjectCallback size_func); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2175 | virtual ~SpaceIterator(); |
| 2176 | |
| 2177 | bool has_next(); |
| 2178 | ObjectIterator* next(); |
| 2179 | |
| 2180 | private: |
| 2181 | ObjectIterator* CreateIterator(); |
| 2182 | |
| 2183 | int current_space_; // from enum AllocationSpace. |
| 2184 | ObjectIterator* iterator_; // object iterator for the current space. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2185 | HeapObjectCallback size_func_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2186 | }; |
| 2187 | |
| 2188 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2189 | // A HeapIterator provides iteration over the whole heap. It |
| 2190 | // aggregates the specific iterators for the different spaces as |
| 2191 | // these can only iterate over one space only. |
| 2192 | // |
| 2193 | // HeapIterator can skip free list nodes (that is, de-allocated heap |
| 2194 | // objects that still remain in the heap). As implementation of free |
| 2195 | // nodes filtering uses GC marks, it can't be used during MS/MC GC |
| 2196 | // phases. Also, it is forbidden to interrupt iteration in this mode, |
| 2197 | // as this will leave heap objects marked (and thus, unusable). |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2198 | class HeapObjectsFilter; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2199 | |
| 2200 | class HeapIterator BASE_EMBEDDED { |
| 2201 | public: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2202 | enum HeapObjectsFiltering { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2203 | kNoFiltering, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2204 | kFilterUnreachable |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2205 | }; |
| 2206 | |
| 2207 | HeapIterator(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2208 | explicit HeapIterator(HeapObjectsFiltering filtering); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2209 | ~HeapIterator(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2210 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2211 | HeapObject* next(); |
| 2212 | void reset(); |
| 2213 | |
| 2214 | private: |
| 2215 | // Perform the initialization. |
| 2216 | void Init(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2217 | // Perform all necessary shutdown (destruction) work. |
| 2218 | void Shutdown(); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2219 | HeapObject* NextObject(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2220 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2221 | HeapObjectsFiltering filtering_; |
| 2222 | HeapObjectsFilter* filter_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2223 | // Space iterator for iterating all the spaces. |
| 2224 | SpaceIterator* space_iterator_; |
| 2225 | // Object iterator for the space currently being iterated. |
| 2226 | ObjectIterator* object_iterator_; |
| 2227 | }; |
| 2228 | |
| 2229 | |
| 2230 | // Cache for mapping (map, property name) into field offset. |
| 2231 | // Cleared at startup and prior to mark sweep collection. |
| 2232 | class KeyedLookupCache { |
| 2233 | public: |
| 2234 | // Lookup field offset for (map, name). If absent, -1 is returned. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2235 | int Lookup(Map* map, String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2236 | |
| 2237 | // Update an element in the cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2238 | void Update(Map* map, String* name, int field_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2239 | |
| 2240 | // Clear the cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2241 | void Clear(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2242 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2243 | static const int kLength = 256; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2244 | static const int kCapacityMask = kLength - 1; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2245 | static const int kMapHashShift = 5; |
| 2246 | static const int kHashMask = -4; // Zero the last two bits. |
| 2247 | static const int kEntriesPerBucket = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2248 | static const int kNotFound = -1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2249 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2250 | // kEntriesPerBucket should be a power of 2. |
| 2251 | STATIC_ASSERT((kEntriesPerBucket & (kEntriesPerBucket - 1)) == 0); |
| 2252 | STATIC_ASSERT(kEntriesPerBucket == -kHashMask); |
| 2253 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2254 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2255 | KeyedLookupCache() { |
| 2256 | for (int i = 0; i < kLength; ++i) { |
| 2257 | keys_[i].map = NULL; |
| 2258 | keys_[i].name = NULL; |
| 2259 | field_offsets_[i] = kNotFound; |
| 2260 | } |
| 2261 | } |
| 2262 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2263 | static inline int Hash(Map* map, String* name); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2264 | |
| 2265 | // Get the address of the keys and field_offsets arrays. Used in |
| 2266 | // generated code to perform cache lookups. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2267 | Address keys_address() { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2268 | return reinterpret_cast<Address>(&keys_); |
| 2269 | } |
| 2270 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2271 | Address field_offsets_address() { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2272 | return reinterpret_cast<Address>(&field_offsets_); |
| 2273 | } |
| 2274 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2275 | struct Key { |
| 2276 | Map* map; |
| 2277 | String* name; |
| 2278 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2279 | |
| 2280 | Key keys_[kLength]; |
| 2281 | int field_offsets_[kLength]; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2282 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2283 | friend class ExternalReference; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2284 | friend class Isolate; |
| 2285 | DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2286 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2287 | |
| 2288 | |
| 2289 | // Cache for mapping (array, property name) into descriptor index. |
| 2290 | // The cache contains both positive and negative results. |
| 2291 | // Descriptor index equals kNotFound means the property is absent. |
| 2292 | // Cleared at startup and prior to any gc. |
| 2293 | class DescriptorLookupCache { |
| 2294 | public: |
| 2295 | // Lookup descriptor index for (map, name). |
| 2296 | // If absent, kAbsent is returned. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2297 | int Lookup(DescriptorArray* array, String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2298 | if (!StringShape(name).IsSymbol()) return kAbsent; |
| 2299 | int index = Hash(array, name); |
| 2300 | Key& key = keys_[index]; |
| 2301 | if ((key.array == array) && (key.name == name)) return results_[index]; |
| 2302 | return kAbsent; |
| 2303 | } |
| 2304 | |
| 2305 | // Update an element in the cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2306 | void Update(DescriptorArray* array, String* name, int result) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2307 | ASSERT(result != kAbsent); |
| 2308 | if (StringShape(name).IsSymbol()) { |
| 2309 | int index = Hash(array, name); |
| 2310 | Key& key = keys_[index]; |
| 2311 | key.array = array; |
| 2312 | key.name = name; |
| 2313 | results_[index] = result; |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | // Clear the cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2318 | void Clear(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2319 | |
| 2320 | static const int kAbsent = -2; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2321 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2322 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2323 | DescriptorLookupCache() { |
| 2324 | for (int i = 0; i < kLength; ++i) { |
| 2325 | keys_[i].array = NULL; |
| 2326 | keys_[i].name = NULL; |
| 2327 | results_[i] = kAbsent; |
| 2328 | } |
| 2329 | } |
| 2330 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2331 | static int Hash(DescriptorArray* array, String* name) { |
| 2332 | // Uses only lower 32 bits if pointers are larger. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2333 | uint32_t array_hash = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2334 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2335 | uint32_t name_hash = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2336 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2; |
| 2337 | return (array_hash ^ name_hash) % kLength; |
| 2338 | } |
| 2339 | |
| 2340 | static const int kLength = 64; |
| 2341 | struct Key { |
| 2342 | DescriptorArray* array; |
| 2343 | String* name; |
| 2344 | }; |
| 2345 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2346 | Key keys_[kLength]; |
| 2347 | int results_[kLength]; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2348 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2349 | friend class Isolate; |
| 2350 | DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2351 | }; |
| 2352 | |
| 2353 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2354 | #ifdef DEBUG |
| 2355 | class DisallowAllocationFailure { |
| 2356 | public: |
| 2357 | inline DisallowAllocationFailure(); |
| 2358 | inline ~DisallowAllocationFailure(); |
| 2359 | |
| 2360 | private: |
| 2361 | bool old_state_; |
| 2362 | }; |
| 2363 | #endif |
| 2364 | |
| 2365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2366 | // A helper class to document/test C++ scopes where we do not |
| 2367 | // expect a GC. Usage: |
| 2368 | // |
| 2369 | // /* Allocation not allowed: we cannot handle a GC in this scope. */ |
| 2370 | // { AssertNoAllocation nogc; |
| 2371 | // ... |
| 2372 | // } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2373 | class AssertNoAllocation { |
| 2374 | public: |
| 2375 | inline AssertNoAllocation(); |
| 2376 | inline ~AssertNoAllocation(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2377 | |
| 2378 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2379 | private: |
| 2380 | bool old_state_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2381 | #endif |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2382 | }; |
| 2383 | |
| 2384 | |
| 2385 | class DisableAssertNoAllocation { |
| 2386 | public: |
| 2387 | inline DisableAssertNoAllocation(); |
| 2388 | inline ~DisableAssertNoAllocation(); |
| 2389 | |
| 2390 | #ifdef DEBUG |
| 2391 | private: |
| 2392 | bool old_state_; |
| 2393 | #endif |
| 2394 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2395 | |
| 2396 | // GCTracer collects and prints ONE line after each garbage collector |
| 2397 | // invocation IFF --trace_gc is used. |
| 2398 | |
| 2399 | class GCTracer BASE_EMBEDDED { |
| 2400 | public: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2401 | class Scope BASE_EMBEDDED { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2402 | public: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2403 | enum ScopeId { |
| 2404 | EXTERNAL, |
| 2405 | MC_MARK, |
| 2406 | MC_SWEEP, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2407 | MC_SWEEP_NEWSPACE, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2408 | MC_EVACUATE_PAGES, |
| 2409 | MC_UPDATE_NEW_TO_NEW_POINTERS, |
| 2410 | MC_UPDATE_ROOT_TO_NEW_POINTERS, |
| 2411 | MC_UPDATE_OLD_TO_NEW_POINTERS, |
| 2412 | MC_UPDATE_POINTERS_TO_EVACUATED, |
| 2413 | MC_UPDATE_POINTERS_BETWEEN_EVACUATED, |
| 2414 | MC_UPDATE_MISC_POINTERS, |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2415 | MC_FLUSH_CODE, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2416 | kNumberOfScopes |
| 2417 | }; |
| 2418 | |
| 2419 | Scope(GCTracer* tracer, ScopeId scope) |
| 2420 | : tracer_(tracer), |
| 2421 | scope_(scope) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2422 | start_time_ = OS::TimeCurrentMillis(); |
| 2423 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2424 | |
| 2425 | ~Scope() { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2426 | ASSERT(scope_ < kNumberOfScopes); // scope_ is unsigned. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2427 | tracer_->scopes_[scope_] += OS::TimeCurrentMillis() - start_time_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2428 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2429 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2430 | private: |
| 2431 | GCTracer* tracer_; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2432 | ScopeId scope_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2433 | double start_time_; |
| 2434 | }; |
| 2435 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2436 | explicit GCTracer(Heap* heap, |
| 2437 | const char* gc_reason, |
| 2438 | const char* collector_reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2439 | ~GCTracer(); |
| 2440 | |
| 2441 | // Sets the collector. |
| 2442 | void set_collector(GarbageCollector collector) { collector_ = collector; } |
| 2443 | |
| 2444 | // Sets the GC count. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2445 | void set_gc_count(unsigned int count) { gc_count_ = count; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2446 | |
| 2447 | // Sets the full GC count. |
| 2448 | void set_full_gc_count(int count) { full_gc_count_ = count; } |
| 2449 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2450 | void increment_promoted_objects_size(int object_size) { |
| 2451 | promoted_objects_size_ += object_size; |
| 2452 | } |
| 2453 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2454 | private: |
| 2455 | // Returns a string matching the collector. |
| 2456 | const char* CollectorString(); |
| 2457 | |
| 2458 | // Returns size of object in heap (in MB). |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2459 | inline double SizeOfHeapObjects(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2460 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2461 | // Timestamp set in the constructor. |
| 2462 | double start_time_; |
| 2463 | |
| 2464 | // Size of objects in heap set in constructor. |
| 2465 | intptr_t start_object_size_; |
| 2466 | |
| 2467 | // Size of memory allocated from OS set in constructor. |
| 2468 | intptr_t start_memory_size_; |
| 2469 | |
| 2470 | // Type of collector. |
| 2471 | GarbageCollector collector_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2472 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2473 | // A count (including this one, e.g. the first collection is 1) of the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2474 | // number of garbage collections. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2475 | unsigned int gc_count_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2476 | |
| 2477 | // A count (including this one) of the number of full garbage collections. |
| 2478 | int full_gc_count_; |
| 2479 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2480 | // Amounts of time spent in different scopes during GC. |
| 2481 | double scopes_[Scope::kNumberOfScopes]; |
| 2482 | |
| 2483 | // Total amount of space either wasted or contained in one of free lists |
| 2484 | // before the current GC. |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2485 | intptr_t in_free_list_or_wasted_before_gc_; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2486 | |
| 2487 | // Difference between space used in the heap at the beginning of the current |
| 2488 | // collection and the end of the previous collection. |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2489 | intptr_t allocated_since_last_gc_; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2490 | |
| 2491 | // Amount of time spent in mutator that is time elapsed between end of the |
| 2492 | // previous collection and the beginning of the current one. |
| 2493 | double spent_in_mutator_; |
| 2494 | |
| 2495 | // Size of objects promoted during the current collection. |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2496 | intptr_t promoted_objects_size_; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2497 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2498 | // Incremental marking steps counters. |
| 2499 | int steps_count_; |
| 2500 | double steps_took_; |
| 2501 | double longest_step_; |
| 2502 | int steps_count_since_last_gc_; |
| 2503 | double steps_took_since_last_gc_; |
| 2504 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2505 | Heap* heap_; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2506 | |
| 2507 | const char* gc_reason_; |
| 2508 | const char* collector_reason_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2509 | }; |
| 2510 | |
| 2511 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2512 | class StringSplitCache { |
| 2513 | public: |
| 2514 | static Object* Lookup(FixedArray* cache, String* string, String* pattern); |
| 2515 | static void Enter(Heap* heap, |
| 2516 | FixedArray* cache, |
| 2517 | String* string, |
| 2518 | String* pattern, |
| 2519 | FixedArray* array); |
| 2520 | static void Clear(FixedArray* cache); |
| 2521 | static const int kStringSplitCacheSize = 0x100; |
| 2522 | |
| 2523 | private: |
| 2524 | static const int kArrayEntriesPerCacheEntry = 4; |
| 2525 | static const int kStringOffset = 0; |
| 2526 | static const int kPatternOffset = 1; |
| 2527 | static const int kArrayOffset = 2; |
| 2528 | |
| 2529 | static MaybeObject* WrapFixedArrayInJSArray(Object* fixed_array); |
| 2530 | }; |
| 2531 | |
| 2532 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2533 | class TranscendentalCache { |
| 2534 | public: |
| 2535 | enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches}; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2536 | static const int kTranscendentalTypeBits = 3; |
| 2537 | STATIC_ASSERT((1 << kTranscendentalTypeBits) >= kNumberOfCaches); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2538 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2539 | // Returns a heap number with f(input), where f is a math function specified |
| 2540 | // by the 'type' argument. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2541 | MUST_USE_RESULT inline MaybeObject* Get(Type type, double input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2542 | |
| 2543 | // The cache contains raw Object pointers. This method disposes of |
| 2544 | // them before a garbage collection. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2545 | void Clear(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2546 | |
| 2547 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2548 | class SubCache { |
| 2549 | static const int kCacheSize = 512; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2550 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2551 | explicit SubCache(Type t); |
| 2552 | |
| 2553 | MUST_USE_RESULT inline MaybeObject* Get(double input); |
| 2554 | |
| 2555 | inline double Calculate(double input); |
| 2556 | |
| 2557 | struct Element { |
| 2558 | uint32_t in[2]; |
| 2559 | Object* output; |
| 2560 | }; |
| 2561 | |
| 2562 | union Converter { |
| 2563 | double dbl; |
| 2564 | uint32_t integers[2]; |
| 2565 | }; |
| 2566 | |
| 2567 | inline static int Hash(const Converter& c) { |
| 2568 | uint32_t hash = (c.integers[0] ^ c.integers[1]); |
| 2569 | hash ^= static_cast<int32_t>(hash) >> 16; |
| 2570 | hash ^= static_cast<int32_t>(hash) >> 8; |
| 2571 | return (hash & (kCacheSize - 1)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2572 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2573 | |
| 2574 | Element elements_[kCacheSize]; |
| 2575 | Type type_; |
| 2576 | Isolate* isolate_; |
| 2577 | |
| 2578 | // Allow access to the caches_ array as an ExternalReference. |
| 2579 | friend class ExternalReference; |
| 2580 | // Inline implementation of the cache. |
| 2581 | friend class TranscendentalCacheStub; |
| 2582 | // For evaluating value. |
| 2583 | friend class TranscendentalCache; |
| 2584 | |
| 2585 | DISALLOW_COPY_AND_ASSIGN(SubCache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2586 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2587 | |
| 2588 | TranscendentalCache() { |
| 2589 | for (int i = 0; i < kNumberOfCaches; ++i) caches_[i] = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2590 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2591 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2592 | // Used to create an external reference. |
| 2593 | inline Address cache_array_address(); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2594 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2595 | // Instantiation |
| 2596 | friend class Isolate; |
| 2597 | // Inline implementation of the caching. |
| 2598 | friend class TranscendentalCacheStub; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2599 | // Allow access to the caches_ array as an ExternalReference. |
| 2600 | friend class ExternalReference; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2601 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2602 | SubCache* caches_[kNumberOfCaches]; |
| 2603 | DISALLOW_COPY_AND_ASSIGN(TranscendentalCache); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2604 | }; |
| 2605 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 2606 | |
| 2607 | // Abstract base class for checking whether a weak object should be retained. |
| 2608 | class WeakObjectRetainer { |
| 2609 | public: |
| 2610 | virtual ~WeakObjectRetainer() {} |
| 2611 | |
| 2612 | // Return whether this object should be retained. If NULL is returned the |
| 2613 | // object has no references. Otherwise the address of the retained object |
| 2614 | // should be returned as in some GC situations the object has been moved. |
| 2615 | virtual Object* RetainAs(Object* object) = 0; |
| 2616 | }; |
| 2617 | |
| 2618 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2619 | // Intrusive object marking uses least significant bit of |
| 2620 | // heap object's map word to mark objects. |
| 2621 | // Normally all map words have least significant bit set |
| 2622 | // because they contain tagged map pointer. |
| 2623 | // If the bit is not set object is marked. |
| 2624 | // All objects should be unmarked before resuming |
| 2625 | // JavaScript execution. |
| 2626 | class IntrusiveMarking { |
| 2627 | public: |
| 2628 | static bool IsMarked(HeapObject* object) { |
| 2629 | return (object->map_word().ToRawValue() & kNotMarkedBit) == 0; |
| 2630 | } |
| 2631 | |
| 2632 | static void ClearMark(HeapObject* object) { |
| 2633 | uintptr_t map_word = object->map_word().ToRawValue(); |
| 2634 | object->set_map_word(MapWord::FromRawValue(map_word | kNotMarkedBit)); |
| 2635 | ASSERT(!IsMarked(object)); |
| 2636 | } |
| 2637 | |
| 2638 | static void SetMark(HeapObject* object) { |
| 2639 | uintptr_t map_word = object->map_word().ToRawValue(); |
| 2640 | object->set_map_word(MapWord::FromRawValue(map_word & ~kNotMarkedBit)); |
| 2641 | ASSERT(IsMarked(object)); |
| 2642 | } |
| 2643 | |
| 2644 | static Map* MapOfMarkedObject(HeapObject* object) { |
| 2645 | uintptr_t map_word = object->map_word().ToRawValue(); |
| 2646 | return MapWord::FromRawValue(map_word | kNotMarkedBit).ToMap(); |
| 2647 | } |
| 2648 | |
| 2649 | static int SizeOfMarkedObject(HeapObject* object) { |
| 2650 | return object->SizeFromMap(MapOfMarkedObject(object)); |
| 2651 | } |
| 2652 | |
| 2653 | private: |
| 2654 | static const uintptr_t kNotMarkedBit = 0x1; |
| 2655 | STATIC_ASSERT((kHeapObjectTag & kNotMarkedBit) != 0); |
| 2656 | }; |
| 2657 | |
| 2658 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2659 | #if defined(DEBUG) || defined(LIVE_OBJECT_LIST) |
| 2660 | // Helper class for tracing paths to a search target Object from all roots. |
| 2661 | // The TracePathFrom() method can be used to trace paths from a specific |
| 2662 | // object to the search target object. |
| 2663 | class PathTracer : public ObjectVisitor { |
| 2664 | public: |
| 2665 | enum WhatToFind { |
| 2666 | FIND_ALL, // Will find all matches. |
| 2667 | FIND_FIRST // Will stop the search after first match. |
| 2668 | }; |
| 2669 | |
| 2670 | // For the WhatToFind arg, if FIND_FIRST is specified, tracing will stop |
| 2671 | // after the first match. If FIND_ALL is specified, then tracing will be |
| 2672 | // done for all matches. |
| 2673 | PathTracer(Object* search_target, |
| 2674 | WhatToFind what_to_find, |
| 2675 | VisitMode visit_mode) |
| 2676 | : search_target_(search_target), |
| 2677 | found_target_(false), |
| 2678 | found_target_in_trace_(false), |
| 2679 | what_to_find_(what_to_find), |
| 2680 | visit_mode_(visit_mode), |
| 2681 | object_stack_(20), |
| 2682 | no_alloc() {} |
| 2683 | |
| 2684 | virtual void VisitPointers(Object** start, Object** end); |
| 2685 | |
| 2686 | void Reset(); |
| 2687 | void TracePathFrom(Object** root); |
| 2688 | |
| 2689 | bool found() const { return found_target_; } |
| 2690 | |
| 2691 | static Object* const kAnyGlobalObject; |
| 2692 | |
| 2693 | protected: |
| 2694 | class MarkVisitor; |
| 2695 | class UnmarkVisitor; |
| 2696 | |
| 2697 | void MarkRecursively(Object** p, MarkVisitor* mark_visitor); |
| 2698 | void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor); |
| 2699 | virtual void ProcessResults(); |
| 2700 | |
| 2701 | // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. |
| 2702 | static const int kMarkTag = 2; |
| 2703 | |
| 2704 | Object* search_target_; |
| 2705 | bool found_target_; |
| 2706 | bool found_target_in_trace_; |
| 2707 | WhatToFind what_to_find_; |
| 2708 | VisitMode visit_mode_; |
| 2709 | List<Object*> object_stack_; |
| 2710 | |
| 2711 | AssertNoAllocation no_alloc; // i.e. no gc allowed. |
| 2712 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2713 | private: |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2714 | DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2715 | }; |
| 2716 | #endif // DEBUG || LIVE_OBJECT_LIST |
| 2717 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2718 | } } // namespace v8::internal |
| 2719 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2720 | #endif // V8_HEAP_H_ |