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