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