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