yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +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 | #include "v8.h" |
| 29 | |
| 30 | #include "accessors.h" |
| 31 | #include "api.h" |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 33 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "execution.h" |
| 35 | #include "global-handles.h" |
| 36 | #include "ic-inl.h" |
| 37 | #include "natives.h" |
| 38 | #include "platform.h" |
| 39 | #include "runtime.h" |
| 40 | #include "serialize.h" |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 41 | #include "snapshot.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | #include "stub-cache.h" |
| 43 | #include "v8threads.h" |
| 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 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 48 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | // ----------------------------------------------------------------------------- |
| 50 | // Coding of external references. |
| 51 | |
| 52 | // The encoding of an external reference. The type is in the high word. |
| 53 | // The id is in the low word. |
| 54 | static uint32_t EncodeExternal(TypeCode type, uint16_t id) { |
| 55 | return static_cast<uint32_t>(type) << 16 | id; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | static int* GetInternalPointer(StatsCounter* counter) { |
| 60 | // All counters refer to dummy_counter, if deserializing happens without |
| 61 | // setting up counters. |
| 62 | static int dummy_counter = 0; |
| 63 | return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter; |
| 64 | } |
| 65 | |
| 66 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 67 | ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) { |
| 68 | ExternalReferenceTable* external_reference_table = |
| 69 | isolate->external_reference_table(); |
| 70 | if (external_reference_table == NULL) { |
| 71 | external_reference_table = new ExternalReferenceTable(isolate); |
| 72 | isolate->set_external_reference_table(external_reference_table); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 73 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 74 | return external_reference_table; |
| 75 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | |
| 77 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 78 | void ExternalReferenceTable::AddFromId(TypeCode type, |
| 79 | uint16_t id, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 80 | const char* name, |
| 81 | Isolate* isolate) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 82 | Address address; |
| 83 | switch (type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 84 | case C_BUILTIN: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 85 | ExternalReference ref(static_cast<Builtins::CFunctionId>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 86 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 87 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 88 | } |
| 89 | case BUILTIN: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 90 | ExternalReference ref(static_cast<Builtins::Name>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 91 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 92 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 93 | } |
| 94 | case RUNTIME_FUNCTION: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 95 | ExternalReference ref(static_cast<Runtime::FunctionId>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 96 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 97 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 98 | } |
| 99 | case IC_UTILITY: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 100 | ExternalReference ref(IC_Utility(static_cast<IC::UtilityId>(id)), |
| 101 | isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 102 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 103 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 104 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 105 | default: |
| 106 | UNREACHABLE(); |
| 107 | return; |
| 108 | } |
| 109 | Add(address, type, id, name); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | void ExternalReferenceTable::Add(Address address, |
| 114 | TypeCode type, |
| 115 | uint16_t id, |
| 116 | const char* name) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 117 | ASSERT_NE(NULL, address); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 118 | ExternalReferenceEntry entry; |
| 119 | entry.address = address; |
| 120 | entry.code = EncodeExternal(type, id); |
| 121 | entry.name = name; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 122 | ASSERT_NE(0, entry.code); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 123 | refs_.Add(entry); |
| 124 | if (id > max_id_[type]) max_id_[type] = id; |
| 125 | } |
| 126 | |
| 127 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | void ExternalReferenceTable::PopulateTable(Isolate* isolate) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | for (int type_code = 0; type_code < kTypeCodeCount; type_code++) { |
| 130 | max_id_[type_code] = 0; |
| 131 | } |
| 132 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 133 | // The following populates all of the different type of external references |
| 134 | // into the ExternalReferenceTable. |
| 135 | // |
| 136 | // NOTE: This function was originally 100k of code. It has since been |
| 137 | // rewritten to be mostly table driven, as the callback macro style tends to |
| 138 | // very easily cause code bloat. Please be careful in the future when adding |
| 139 | // new references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 141 | struct RefTableEntry { |
| 142 | TypeCode type; |
| 143 | uint16_t id; |
| 144 | const char* name; |
| 145 | }; |
| 146 | |
| 147 | static const RefTableEntry ref_table[] = { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | // Builtins |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 149 | #define DEF_ENTRY_C(name, ignored) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 150 | { C_BUILTIN, \ |
| 151 | Builtins::c_##name, \ |
| 152 | "Builtins::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | |
| 154 | BUILTIN_LIST_C(DEF_ENTRY_C) |
| 155 | #undef DEF_ENTRY_C |
| 156 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 157 | #define DEF_ENTRY_C(name, ignored) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 158 | { BUILTIN, \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 159 | Builtins::k##name, \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 160 | "Builtins::" #name }, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 161 | #define DEF_ENTRY_A(name, kind, state, extra) DEF_ENTRY_C(name, ignored) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | |
| 163 | BUILTIN_LIST_C(DEF_ENTRY_C) |
| 164 | BUILTIN_LIST_A(DEF_ENTRY_A) |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 165 | BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | #undef DEF_ENTRY_C |
| 167 | #undef DEF_ENTRY_A |
| 168 | |
| 169 | // Runtime functions |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 170 | #define RUNTIME_ENTRY(name, nargs, ressize) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 171 | { RUNTIME_FUNCTION, \ |
| 172 | Runtime::k##name, \ |
| 173 | "Runtime::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 174 | |
| 175 | RUNTIME_FUNCTION_LIST(RUNTIME_ENTRY) |
| 176 | #undef RUNTIME_ENTRY |
| 177 | |
| 178 | // IC utilities |
| 179 | #define IC_ENTRY(name) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 180 | { IC_UTILITY, \ |
| 181 | IC::k##name, \ |
| 182 | "IC::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | |
| 184 | IC_UTIL_LIST(IC_ENTRY) |
| 185 | #undef IC_ENTRY |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 186 | }; // end of ref_table[]. |
| 187 | |
| 188 | for (size_t i = 0; i < ARRAY_SIZE(ref_table); ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 189 | AddFromId(ref_table[i].type, |
| 190 | ref_table[i].id, |
| 191 | ref_table[i].name, |
| 192 | isolate); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 193 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 195 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | // Debug addresses |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 197 | Add(Debug_Address(Debug::k_after_break_target_address).address(isolate), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | DEBUG_ADDRESS, |
| 199 | Debug::k_after_break_target_address << kDebugIdShift, |
| 200 | "Debug::after_break_target_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 201 | Add(Debug_Address(Debug::k_debug_break_slot_address).address(isolate), |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 202 | DEBUG_ADDRESS, |
| 203 | Debug::k_debug_break_slot_address << kDebugIdShift, |
| 204 | "Debug::debug_break_slot_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 205 | Add(Debug_Address(Debug::k_debug_break_return_address).address(isolate), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | DEBUG_ADDRESS, |
| 207 | Debug::k_debug_break_return_address << kDebugIdShift, |
| 208 | "Debug::debug_break_return_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 209 | Add(Debug_Address(Debug::k_restarter_frame_function_pointer).address(isolate), |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 210 | DEBUG_ADDRESS, |
| 211 | Debug::k_restarter_frame_function_pointer << kDebugIdShift, |
| 212 | "Debug::restarter_frame_function_pointer_address()"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 213 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | |
| 215 | // Stat counters |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 216 | struct StatsRefTableEntry { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 217 | StatsCounter* (Counters::*counter)(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 218 | uint16_t id; |
| 219 | const char* name; |
| 220 | }; |
| 221 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 222 | const StatsRefTableEntry stats_ref_table[] = { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | #define COUNTER_ENTRY(name, caption) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 224 | { &Counters::name, \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 225 | Counters::k_##name, \ |
| 226 | "Counters::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | |
| 228 | STATS_COUNTER_LIST_1(COUNTER_ENTRY) |
| 229 | STATS_COUNTER_LIST_2(COUNTER_ENTRY) |
| 230 | #undef COUNTER_ENTRY |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 231 | }; // end of stats_ref_table[]. |
| 232 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 233 | Counters* counters = isolate->counters(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 234 | for (size_t i = 0; i < ARRAY_SIZE(stats_ref_table); ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 235 | Add(reinterpret_cast<Address>(GetInternalPointer( |
| 236 | (counters->*(stats_ref_table[i].counter))())), |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 237 | STATS_COUNTER, |
| 238 | stats_ref_table[i].id, |
| 239 | stats_ref_table[i].name); |
| 240 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | |
| 242 | // Top addresses |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 243 | |
| 244 | const char* AddressNames[] = { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 245 | #define BUILD_NAME_LITERAL(CamelName, hacker_name) \ |
| 246 | "Isolate::" #hacker_name "_address", |
| 247 | FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 248 | NULL |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 249 | #undef BUILD_NAME_LITERAL |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 250 | }; |
| 251 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 252 | for (uint16_t i = 0; i < Isolate::kIsolateAddressCount; ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 253 | Add(isolate->get_address_from_id((Isolate::AddressId)i), |
| 254 | TOP_ADDRESS, i, AddressNames[i]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | // Accessors |
| 258 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 259 | Add((Address)&Accessors::name, \ |
| 260 | ACCESSOR, \ |
| 261 | Accessors::k##name, \ |
| 262 | "Accessors::" #name); |
| 263 | |
| 264 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 265 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 266 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 267 | StubCache* stub_cache = isolate->stub_cache(); |
| 268 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | // Stub cache tables |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 270 | Add(stub_cache->key_reference(StubCache::kPrimary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 271 | STUB_CACHE_TABLE, |
| 272 | 1, |
| 273 | "StubCache::primary_->key"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 274 | Add(stub_cache->value_reference(StubCache::kPrimary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | STUB_CACHE_TABLE, |
| 276 | 2, |
| 277 | "StubCache::primary_->value"); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 278 | Add(stub_cache->map_reference(StubCache::kPrimary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | STUB_CACHE_TABLE, |
| 280 | 3, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 281 | "StubCache::primary_->map"); |
| 282 | Add(stub_cache->key_reference(StubCache::kSecondary).address(), |
| 283 | STUB_CACHE_TABLE, |
| 284 | 4, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | "StubCache::secondary_->key"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 286 | Add(stub_cache->value_reference(StubCache::kSecondary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | STUB_CACHE_TABLE, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 288 | 5, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | "StubCache::secondary_->value"); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 290 | Add(stub_cache->map_reference(StubCache::kSecondary).address(), |
| 291 | STUB_CACHE_TABLE, |
| 292 | 6, |
| 293 | "StubCache::secondary_->map"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | |
| 295 | // Runtime entries |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | Add(ExternalReference::perform_gc_function(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | RUNTIME_ENTRY, |
| 298 | 1, |
| 299 | "Runtime::PerformGC"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 300 | Add(ExternalReference::fill_heap_number_with_random_function( |
| 301 | isolate).address(), |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 302 | RUNTIME_ENTRY, |
| 303 | 2, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 304 | "V8::FillHeapNumberWithRandom"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 305 | Add(ExternalReference::random_uint32_function(isolate).address(), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 306 | RUNTIME_ENTRY, |
| 307 | 3, |
| 308 | "V8::Random"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 309 | Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 310 | RUNTIME_ENTRY, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 311 | 4, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 312 | "HandleScope::DeleteExtensions"); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 313 | Add(ExternalReference:: |
| 314 | incremental_marking_record_write_function(isolate).address(), |
| 315 | RUNTIME_ENTRY, |
| 316 | 5, |
| 317 | "IncrementalMarking::RecordWrite"); |
| 318 | Add(ExternalReference::store_buffer_overflow_function(isolate).address(), |
| 319 | RUNTIME_ENTRY, |
| 320 | 6, |
| 321 | "StoreBuffer::StoreBufferOverflow"); |
| 322 | Add(ExternalReference:: |
| 323 | incremental_evacuation_record_write_function(isolate).address(), |
| 324 | RUNTIME_ENTRY, |
| 325 | 7, |
| 326 | "IncrementalMarking::RecordWrite"); |
| 327 | |
| 328 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 329 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | // Miscellaneous |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 331 | Add(ExternalReference::roots_array_start(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | UNCLASSIFIED, |
| 333 | 3, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 334 | "Heap::roots_array_start()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 335 | Add(ExternalReference::address_of_stack_limit(isolate).address(), |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 336 | UNCLASSIFIED, |
| 337 | 4, |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 338 | "StackGuard::address_of_jslimit()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 339 | Add(ExternalReference::address_of_real_stack_limit(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | UNCLASSIFIED, |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 341 | 5, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 342 | "StackGuard::address_of_real_jslimit()"); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 343 | #ifndef V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 344 | Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 345 | UNCLASSIFIED, |
| 346 | 6, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 347 | "RegExpStack::limit_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 348 | Add(ExternalReference::address_of_regexp_stack_memory_address( |
| 349 | isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | UNCLASSIFIED, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 351 | 7, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 352 | "RegExpStack::memory_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 353 | Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 354 | UNCLASSIFIED, |
| 355 | 8, |
| 356 | "RegExpStack::memory_size()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 357 | Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 358 | UNCLASSIFIED, |
| 359 | 9, |
| 360 | "OffsetsVector::static_offsets_vector"); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 361 | #endif // V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 362 | Add(ExternalReference::new_space_start(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 363 | UNCLASSIFIED, |
| 364 | 10, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | "Heap::NewSpaceStart()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 366 | Add(ExternalReference::new_space_mask(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 368 | 11, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 369 | "Heap::NewSpaceMask()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 370 | Add(ExternalReference::heap_always_allocate_scope_depth(isolate).address(), |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 371 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 372 | 12, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 373 | "Heap::always_allocate_scope_depth()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 374 | Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 375 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 376 | 14, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 377 | "Heap::NewSpaceAllocationLimitAddress()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 378 | Add(ExternalReference::new_space_allocation_top_address(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 380 | 15, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 381 | "Heap::NewSpaceAllocationTopAddress()"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 382 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 383 | Add(ExternalReference::debug_break(isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 384 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 385 | 16, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 386 | "Debug::Break()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 387 | Add(ExternalReference::debug_step_in_fp_address(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 389 | 17, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 390 | "Debug::step_in_fp_addr()"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 391 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 392 | Add(ExternalReference::double_fp_operation(Token::ADD, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 393 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 394 | 18, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 395 | "add_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 396 | Add(ExternalReference::double_fp_operation(Token::SUB, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 397 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 398 | 19, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 399 | "sub_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 400 | Add(ExternalReference::double_fp_operation(Token::MUL, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 401 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 402 | 20, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 403 | "mul_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 404 | Add(ExternalReference::double_fp_operation(Token::DIV, isolate).address(), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 405 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 406 | 21, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 407 | "div_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 408 | Add(ExternalReference::double_fp_operation(Token::MOD, isolate).address(), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 409 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 410 | 22, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 411 | "mod_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 412 | Add(ExternalReference::compare_doubles(isolate).address(), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 413 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 414 | 23, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 415 | "compare_doubles"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 416 | #ifndef V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 417 | Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 418 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 419 | 24, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 420 | "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 421 | Add(ExternalReference::re_check_stack_guard_state(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 422 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 423 | 25, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 424 | "RegExpMacroAssembler*::CheckStackGuardState()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 425 | Add(ExternalReference::re_grow_stack(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 426 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 427 | 26, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 428 | "NativeRegExpMacroAssembler::GrowStack()"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 429 | Add(ExternalReference::re_word_character_map().address(), |
| 430 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 431 | 27, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 432 | "NativeRegExpMacroAssembler::word_character_map"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 433 | #endif // V8_INTERPRETED_REGEXP |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 434 | // Keyed lookup cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 435 | Add(ExternalReference::keyed_lookup_cache_keys(isolate).address(), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 436 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 437 | 28, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 438 | "KeyedLookupCache::keys()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 439 | Add(ExternalReference::keyed_lookup_cache_field_offsets(isolate).address(), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 440 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 441 | 29, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 442 | "KeyedLookupCache::field_offsets()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 443 | Add(ExternalReference::transcendental_cache_array_address(isolate).address(), |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 444 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 445 | 30, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 446 | "TranscendentalCache::caches()"); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 447 | Add(ExternalReference::handle_scope_next_address(isolate).address(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 448 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 449 | 31, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 450 | "HandleScope::next"); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 451 | Add(ExternalReference::handle_scope_limit_address(isolate).address(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 452 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 453 | 32, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 454 | "HandleScope::limit"); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 455 | Add(ExternalReference::handle_scope_level_address(isolate).address(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 456 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 457 | 33, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 458 | "HandleScope::level"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 459 | Add(ExternalReference::new_deoptimizer_function(isolate).address(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 460 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 461 | 34, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 462 | "Deoptimizer::New()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 463 | Add(ExternalReference::compute_output_frames_function(isolate).address(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 464 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 465 | 35, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | "Deoptimizer::ComputeOutputFrames()"); |
| 467 | Add(ExternalReference::address_of_min_int().address(), |
| 468 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 469 | 36, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 470 | "LDoubleConstant::min_int"); |
| 471 | Add(ExternalReference::address_of_one_half().address(), |
| 472 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 473 | 37, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 474 | "LDoubleConstant::one_half"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 475 | Add(ExternalReference::isolate_address().address(), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 476 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 477 | 38, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 478 | "isolate"); |
| 479 | Add(ExternalReference::address_of_minus_zero().address(), |
| 480 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 481 | 39, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 482 | "LDoubleConstant::minus_zero"); |
| 483 | Add(ExternalReference::address_of_negative_infinity().address(), |
| 484 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 485 | 40, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 486 | "LDoubleConstant::negative_infinity"); |
| 487 | Add(ExternalReference::power_double_double_function(isolate).address(), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 488 | UNCLASSIFIED, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 489 | 41, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 490 | "power_double_double_function"); |
| 491 | Add(ExternalReference::power_double_int_function(isolate).address(), |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 492 | UNCLASSIFIED, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 493 | 42, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 494 | "power_double_int_function"); |
| 495 | Add(ExternalReference::store_buffer_top(isolate).address(), |
| 496 | UNCLASSIFIED, |
| 497 | 43, |
| 498 | "store_buffer_top"); |
| 499 | Add(ExternalReference::address_of_canonical_non_hole_nan().address(), |
| 500 | UNCLASSIFIED, |
| 501 | 44, |
| 502 | "canonical_nan"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 503 | Add(ExternalReference::address_of_the_hole_nan().address(), |
| 504 | UNCLASSIFIED, |
| 505 | 45, |
| 506 | "the_hole_nan"); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 507 | Add(ExternalReference::get_date_field_function(isolate).address(), |
| 508 | UNCLASSIFIED, |
| 509 | 46, |
| 510 | "JSDate::GetField"); |
| 511 | Add(ExternalReference::date_cache_stamp(isolate).address(), |
| 512 | UNCLASSIFIED, |
| 513 | 47, |
| 514 | "date_cache_stamp"); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 515 | Add(ExternalReference::address_of_pending_message_obj(isolate).address(), |
| 516 | UNCLASSIFIED, |
| 517 | 48, |
| 518 | "address_of_pending_message_obj"); |
| 519 | Add(ExternalReference::address_of_has_pending_message(isolate).address(), |
| 520 | UNCLASSIFIED, |
| 521 | 49, |
| 522 | "address_of_has_pending_message"); |
| 523 | Add(ExternalReference::address_of_pending_message_script(isolate).address(), |
| 524 | UNCLASSIFIED, |
| 525 | 50, |
| 526 | "pending_message_script"); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 527 | Add(ExternalReference::get_make_code_young_function(isolate).address(), |
| 528 | UNCLASSIFIED, |
| 529 | 51, |
| 530 | "Code::MakeCodeYoung"); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 531 | Add(ExternalReference::cpu_features().address(), |
| 532 | UNCLASSIFIED, |
| 533 | 52, |
| 534 | "cpu_features"); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 535 | Add(ExternalReference::new_space_allocation_top_address(isolate).address(), |
| 536 | UNCLASSIFIED, |
| 537 | 53, |
| 538 | "Heap::NewSpaceAllocationTopAddress"); |
| 539 | Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), |
| 540 | UNCLASSIFIED, |
| 541 | 54, |
| 542 | "Heap::NewSpaceAllocationLimitAddress"); |
| 543 | Add(ExternalReference(Runtime::kAllocateInNewSpace, isolate).address(), |
| 544 | UNCLASSIFIED, |
| 545 | 55, |
| 546 | "Runtime::AllocateInNewSpace"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 547 | |
| 548 | // Add a small set of deopt entry addresses to encoder without generating the |
| 549 | // deopt table code, which isn't possible at deserialization time. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 550 | HandleScope scope(isolate); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 551 | for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { |
| 552 | Address address = Deoptimizer::GetDeoptimizationEntry( |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 553 | isolate, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 554 | entry, |
| 555 | Deoptimizer::LAZY, |
| 556 | Deoptimizer::CALCULATE_ENTRY_ADDRESS); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 557 | Add(address, LAZY_DEOPTIMIZATION, 56 + entry, "lazy_deopt"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 558 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | ExternalReferenceEncoder::ExternalReferenceEncoder() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 563 | : encodings_(Match), |
| 564 | isolate_(Isolate::Current()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | ExternalReferenceTable* external_references = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 566 | ExternalReferenceTable::instance(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | for (int i = 0; i < external_references->size(); ++i) { |
| 568 | Put(external_references->address(i), i); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | |
| 573 | uint32_t ExternalReferenceEncoder::Encode(Address key) const { |
| 574 | int index = IndexOf(key); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 575 | ASSERT(key == NULL || index >= 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 576 | return index >=0 ? |
| 577 | ExternalReferenceTable::instance(isolate_)->code(index) : 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | |
| 581 | const char* ExternalReferenceEncoder::NameOfAddress(Address key) const { |
| 582 | int index = IndexOf(key); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 583 | return index >= 0 ? |
| 584 | ExternalReferenceTable::instance(isolate_)->name(index) : NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
| 588 | int ExternalReferenceEncoder::IndexOf(Address key) const { |
| 589 | if (key == NULL) return -1; |
| 590 | HashMap::Entry* entry = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 591 | const_cast<HashMap&>(encodings_).Lookup(key, Hash(key), false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 592 | return entry == NULL |
| 593 | ? -1 |
| 594 | : static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
| 598 | void ExternalReferenceEncoder::Put(Address key, int index) { |
| 599 | HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 600 | entry->value = reinterpret_cast<void*>(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | |
| 604 | ExternalReferenceDecoder::ExternalReferenceDecoder() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 605 | : encodings_(NewArray<Address*>(kTypeCodeCount)), |
| 606 | isolate_(Isolate::Current()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | ExternalReferenceTable* external_references = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 608 | ExternalReferenceTable::instance(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { |
| 610 | int max = external_references->max_id(type) + 1; |
| 611 | encodings_[type] = NewArray<Address>(max + 1); |
| 612 | } |
| 613 | for (int i = 0; i < external_references->size(); ++i) { |
| 614 | Put(external_references->code(i), external_references->address(i)); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | |
| 619 | ExternalReferenceDecoder::~ExternalReferenceDecoder() { |
| 620 | for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { |
| 621 | DeleteArray(encodings_[type]); |
| 622 | } |
| 623 | DeleteArray(encodings_); |
| 624 | } |
| 625 | |
| 626 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 627 | bool Serializer::serialization_enabled_ = false; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 628 | bool Serializer::too_late_to_enable_now_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 629 | |
| 630 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | Deserializer::Deserializer(SnapshotByteSource* source) |
| 632 | : isolate_(NULL), |
| 633 | source_(source), |
| 634 | external_reference_decoder_(NULL) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 635 | for (int i = 0; i < LAST_SPACE + 1; i++) { |
| 636 | reservations_[i] = kUninitializedReservation; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 637 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 641 | void Deserializer::Deserialize() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 642 | isolate_ = Isolate::Current(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 643 | ASSERT(isolate_ != NULL); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 644 | isolate_->heap()->ReserveSpace(reservations_, &high_water_[0]); |
| 645 | // No active threads. |
| 646 | ASSERT_EQ(NULL, isolate_->thread_manager()->FirstThreadStateInUse()); |
| 647 | // No active handles. |
| 648 | ASSERT(isolate_->handle_scope_implementer()->blocks()->is_empty()); |
| 649 | ASSERT_EQ(NULL, external_reference_decoder_); |
| 650 | external_reference_decoder_ = new ExternalReferenceDecoder(); |
| 651 | isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
| 652 | isolate_->heap()->RepairFreeListsAfterBoot(); |
| 653 | isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 654 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 655 | isolate_->heap()->set_native_contexts_list( |
| 656 | isolate_->heap()->undefined_value()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 657 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 658 | // Update data pointers to the external strings containing natives sources. |
| 659 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 660 | Object* source = isolate_->heap()->natives_source_cache()->get(i); |
| 661 | if (!source->IsUndefined()) { |
| 662 | ExternalAsciiString::cast(source)->update_data_cache(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 665 | |
| 666 | // Issue code events for newly deserialized code objects. |
| 667 | LOG_CODE_EVENT(isolate_, LogCodeObjects()); |
| 668 | LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | |
| 672 | void Deserializer::DeserializePartial(Object** root) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 673 | isolate_ = Isolate::Current(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 674 | for (int i = NEW_SPACE; i < kNumberOfSpaces; i++) { |
| 675 | ASSERT(reservations_[i] != kUninitializedReservation); |
| 676 | } |
| 677 | isolate_->heap()->ReserveSpace(reservations_, &high_water_[0]); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 678 | if (external_reference_decoder_ == NULL) { |
| 679 | external_reference_decoder_ = new ExternalReferenceDecoder(); |
| 680 | } |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 681 | |
| 682 | // Keep track of the code space start and end pointers in case new |
| 683 | // code objects were unserialized |
| 684 | OldSpace* code_space = isolate_->heap()->code_space(); |
| 685 | Address start_address = code_space->top(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 686 | VisitPointer(root); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 687 | |
| 688 | // There's no code deserialized here. If this assert fires |
| 689 | // then that's changed and logging should be added to notify |
| 690 | // the profiler et al of the new code. |
| 691 | CHECK_EQ(start_address, code_space->top()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | |
| 695 | Deserializer::~Deserializer() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 696 | ASSERT(source_->AtEOF()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 697 | if (external_reference_decoder_) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | delete external_reference_decoder_; |
| 699 | external_reference_decoder_ = NULL; |
| 700 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
| 704 | // This is called on the roots. It is the driver of the deserialization |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 705 | // process. It is also called on the body of each function. |
| 706 | void Deserializer::VisitPointers(Object** start, Object** end) { |
| 707 | // The space must be new space. Any other space would cause ReadChunk to try |
| 708 | // to update the remembered using NULL as the address. |
| 709 | ReadChunk(start, end, NEW_SPACE, NULL); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
| 713 | // This routine writes the new object into the pointer provided and then |
| 714 | // returns true if the new object was in young space and false otherwise. |
| 715 | // The reason for this strange interface is that otherwise the object is |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 716 | // written very late, which means the FreeSpace map is not set up by the |
| 717 | // time we need to use it to mark the space at the end of a page free. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 718 | void Deserializer::ReadObject(int space_number, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 719 | Object** write_back) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 720 | int size = source_->GetInt() << kObjectAlignmentBits; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 721 | Address address = Allocate(space_number, size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 722 | *write_back = HeapObject::FromAddress(address); |
| 723 | Object** current = reinterpret_cast<Object**>(address); |
| 724 | Object** limit = current + (size >> kPointerSizeLog2); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 725 | if (FLAG_log_snapshot_positions) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 726 | LOG(isolate_, SnapshotPositionEvent(address, source_->position())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 727 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 728 | ReadChunk(current, limit, space_number, address); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 729 | #ifdef DEBUG |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 730 | bool is_codespace = (space_number == CODE_SPACE); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 731 | ASSERT(HeapObject::FromAddress(address)->IsCode() == is_codespace); |
| 732 | #endif |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 733 | } |
| 734 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 735 | void Deserializer::ReadChunk(Object** current, |
| 736 | Object** limit, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 737 | int source_space, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 738 | Address current_object_address) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 739 | Isolate* const isolate = isolate_; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 740 | // Write barrier support costs around 1% in startup time. In fact there |
| 741 | // are no new space objects in current boot snapshots, so it's not needed, |
| 742 | // but that may change. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 743 | bool write_barrier_needed = (current_object_address != NULL && |
| 744 | source_space != NEW_SPACE && |
| 745 | source_space != CELL_SPACE && |
| 746 | source_space != CODE_SPACE && |
| 747 | source_space != OLD_DATA_SPACE); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 748 | while (current < limit) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 749 | int data = source_->Get(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 750 | switch (data) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 751 | #define CASE_STATEMENT(where, how, within, space_number) \ |
| 752 | case where + how + within + space_number: \ |
| 753 | ASSERT((where & ~kPointedToMask) == 0); \ |
| 754 | ASSERT((how & ~kHowToCodeMask) == 0); \ |
| 755 | ASSERT((within & ~kWhereToPointMask) == 0); \ |
| 756 | ASSERT((space_number & ~kSpaceMask) == 0); |
| 757 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 758 | #define CASE_BODY(where, how, within, space_number_if_any) \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 759 | { \ |
| 760 | bool emit_write_barrier = false; \ |
| 761 | bool current_was_incremented = false; \ |
| 762 | int space_number = space_number_if_any == kAnyOldSpace ? \ |
| 763 | (data & kSpaceMask) : space_number_if_any; \ |
| 764 | if (where == kNewObject && how == kPlain && within == kStartOfObject) {\ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 765 | ReadObject(space_number, current); \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 766 | emit_write_barrier = (space_number == NEW_SPACE); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 767 | } else { \ |
| 768 | Object* new_object = NULL; /* May not be a real Object pointer. */ \ |
| 769 | if (where == kNewObject) { \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 770 | ReadObject(space_number, &new_object); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 771 | } else if (where == kRootArray) { \ |
| 772 | int root_id = source_->GetInt(); \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 773 | new_object = isolate->heap()->roots_array_start()[root_id]; \ |
| 774 | emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 775 | } else if (where == kPartialSnapshotCache) { \ |
| 776 | int cache_index = source_->GetInt(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 777 | new_object = isolate->serialize_partial_snapshot_cache() \ |
| 778 | [cache_index]; \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 779 | emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 780 | } else if (where == kExternalReference) { \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 781 | int skip = source_->GetInt(); \ |
| 782 | current = reinterpret_cast<Object**>(reinterpret_cast<Address>( \ |
| 783 | current) + skip); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 784 | int reference_id = source_->GetInt(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 785 | Address address = external_reference_decoder_-> \ |
| 786 | Decode(reference_id); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 787 | new_object = reinterpret_cast<Object*>(address); \ |
| 788 | } else if (where == kBackref) { \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 789 | emit_write_barrier = (space_number == NEW_SPACE); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 790 | new_object = GetAddressFromEnd(data & kSpaceMask); \ |
| 791 | } else { \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 792 | ASSERT(where == kBackrefWithSkip); \ |
| 793 | int skip = source_->GetInt(); \ |
| 794 | current = reinterpret_cast<Object**>( \ |
| 795 | reinterpret_cast<Address>(current) + skip); \ |
| 796 | emit_write_barrier = (space_number == NEW_SPACE); \ |
| 797 | new_object = GetAddressFromEnd(data & kSpaceMask); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 798 | } \ |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 799 | if (within == kInnerPointer) { \ |
| 800 | if (space_number != CODE_SPACE || new_object->IsCode()) { \ |
| 801 | Code* new_code_object = reinterpret_cast<Code*>(new_object); \ |
| 802 | new_object = reinterpret_cast<Object*>( \ |
| 803 | new_code_object->instruction_start()); \ |
| 804 | } else { \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 805 | ASSERT(space_number == CODE_SPACE); \ |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 806 | JSGlobalPropertyCell* cell = \ |
| 807 | JSGlobalPropertyCell::cast(new_object); \ |
| 808 | new_object = reinterpret_cast<Object*>( \ |
| 809 | cell->ValueAddress()); \ |
| 810 | } \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 811 | } \ |
| 812 | if (how == kFromCode) { \ |
| 813 | Address location_of_branch_data = \ |
| 814 | reinterpret_cast<Address>(current); \ |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 815 | Assembler::deserialization_set_special_target_at( \ |
| 816 | location_of_branch_data, \ |
| 817 | reinterpret_cast<Address>(new_object)); \ |
| 818 | location_of_branch_data += Assembler::kSpecialTargetSize; \ |
| 819 | current = reinterpret_cast<Object**>(location_of_branch_data); \ |
| 820 | current_was_incremented = true; \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 821 | } else { \ |
| 822 | *current = new_object; \ |
| 823 | } \ |
| 824 | } \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 825 | if (emit_write_barrier && write_barrier_needed) { \ |
| 826 | Address current_address = reinterpret_cast<Address>(current); \ |
| 827 | isolate->heap()->RecordWrite( \ |
| 828 | current_object_address, \ |
| 829 | static_cast<int>(current_address - current_object_address)); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 830 | } \ |
| 831 | if (!current_was_incremented) { \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 832 | current++; \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 833 | } \ |
| 834 | break; \ |
| 835 | } \ |
| 836 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 837 | // This generates a case and a body for the new space (which has to do extra |
| 838 | // write barrier handling) and handles the other spaces with 8 fall-through |
| 839 | // cases and one body. |
| 840 | #define ALL_SPACES(where, how, within) \ |
| 841 | CASE_STATEMENT(where, how, within, NEW_SPACE) \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 842 | CASE_BODY(where, how, within, NEW_SPACE) \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 843 | CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \ |
| 844 | CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \ |
| 845 | CASE_STATEMENT(where, how, within, CODE_SPACE) \ |
| 846 | CASE_STATEMENT(where, how, within, CELL_SPACE) \ |
| 847 | CASE_STATEMENT(where, how, within, MAP_SPACE) \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 848 | CASE_BODY(where, how, within, kAnyOldSpace) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 849 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 850 | #define FOUR_CASES(byte_code) \ |
| 851 | case byte_code: \ |
| 852 | case byte_code + 1: \ |
| 853 | case byte_code + 2: \ |
| 854 | case byte_code + 3: |
| 855 | |
| 856 | #define SIXTEEN_CASES(byte_code) \ |
| 857 | FOUR_CASES(byte_code) \ |
| 858 | FOUR_CASES(byte_code + 4) \ |
| 859 | FOUR_CASES(byte_code + 8) \ |
| 860 | FOUR_CASES(byte_code + 12) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 861 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 862 | #define COMMON_RAW_LENGTHS(f) \ |
| 863 | f(1) \ |
| 864 | f(2) \ |
| 865 | f(3) \ |
| 866 | f(4) \ |
| 867 | f(5) \ |
| 868 | f(6) \ |
| 869 | f(7) \ |
| 870 | f(8) \ |
| 871 | f(9) \ |
| 872 | f(10) \ |
| 873 | f(11) \ |
| 874 | f(12) \ |
| 875 | f(13) \ |
| 876 | f(14) \ |
| 877 | f(15) \ |
| 878 | f(16) \ |
| 879 | f(17) \ |
| 880 | f(18) \ |
| 881 | f(19) \ |
| 882 | f(20) \ |
| 883 | f(21) \ |
| 884 | f(22) \ |
| 885 | f(23) \ |
| 886 | f(24) \ |
| 887 | f(25) \ |
| 888 | f(26) \ |
| 889 | f(27) \ |
| 890 | f(28) \ |
| 891 | f(29) \ |
| 892 | f(30) \ |
| 893 | f(31) |
| 894 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 895 | // We generate 15 cases and bodies that process special tags that combine |
| 896 | // the raw data tag and the length into one byte. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 897 | #define RAW_CASE(index) \ |
| 898 | case kRawData + index: { \ |
| 899 | byte* raw_data_out = reinterpret_cast<byte*>(current); \ |
| 900 | source_->CopyRaw(raw_data_out, index * kPointerSize); \ |
| 901 | current = \ |
| 902 | reinterpret_cast<Object**>(raw_data_out + index * kPointerSize); \ |
| 903 | break; \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 904 | } |
| 905 | COMMON_RAW_LENGTHS(RAW_CASE) |
| 906 | #undef RAW_CASE |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 907 | |
| 908 | // Deserialize a chunk of raw data that doesn't have one of the popular |
| 909 | // lengths. |
| 910 | case kRawData: { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 911 | int size = source_->GetInt(); |
| 912 | byte* raw_data_out = reinterpret_cast<byte*>(current); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 913 | source_->CopyRaw(raw_data_out, size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 914 | break; |
| 915 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 916 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 917 | SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance) |
| 918 | SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance + 16) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 919 | int root_id = RootArrayConstantFromByteCode(data); |
| 920 | Object* object = isolate->heap()->roots_array_start()[root_id]; |
| 921 | ASSERT(!isolate->heap()->InNewSpace(object)); |
| 922 | *current++ = object; |
| 923 | break; |
| 924 | } |
| 925 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 926 | SIXTEEN_CASES(kRootArrayConstants + kHasSkipDistance) |
| 927 | SIXTEEN_CASES(kRootArrayConstants + kHasSkipDistance + 16) { |
| 928 | int root_id = RootArrayConstantFromByteCode(data); |
| 929 | int skip = source_->GetInt(); |
| 930 | current = reinterpret_cast<Object**>( |
| 931 | reinterpret_cast<intptr_t>(current) + skip); |
| 932 | Object* object = isolate->heap()->roots_array_start()[root_id]; |
| 933 | ASSERT(!isolate->heap()->InNewSpace(object)); |
| 934 | *current++ = object; |
| 935 | break; |
| 936 | } |
| 937 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 938 | case kRepeat: { |
| 939 | int repeats = source_->GetInt(); |
| 940 | Object* object = current[-1]; |
| 941 | ASSERT(!isolate->heap()->InNewSpace(object)); |
| 942 | for (int i = 0; i < repeats; i++) current[i] = object; |
| 943 | current += repeats; |
| 944 | break; |
| 945 | } |
| 946 | |
| 947 | STATIC_ASSERT(kRootArrayNumberOfConstantEncodings == |
| 948 | Heap::kOldSpaceRoots); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 949 | STATIC_ASSERT(kMaxRepeats == 13); |
| 950 | case kConstantRepeat: |
| 951 | FOUR_CASES(kConstantRepeat + 1) |
| 952 | FOUR_CASES(kConstantRepeat + 5) |
| 953 | FOUR_CASES(kConstantRepeat + 9) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 954 | int repeats = RepeatsForCode(data); |
| 955 | Object* object = current[-1]; |
| 956 | ASSERT(!isolate->heap()->InNewSpace(object)); |
| 957 | for (int i = 0; i < repeats; i++) current[i] = object; |
| 958 | current += repeats; |
| 959 | break; |
| 960 | } |
| 961 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 962 | // Deserialize a new object and write a pointer to it to the current |
| 963 | // object. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 964 | ALL_SPACES(kNewObject, kPlain, kStartOfObject) |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 965 | // Support for direct instruction pointers in functions. It's an inner |
| 966 | // pointer because it points at the entry point, not at the start of the |
| 967 | // code object. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 968 | CASE_STATEMENT(kNewObject, kPlain, kInnerPointer, CODE_SPACE) |
| 969 | CASE_BODY(kNewObject, kPlain, kInnerPointer, CODE_SPACE) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 970 | // Deserialize a new code object and write a pointer to its first |
| 971 | // instruction to the current code object. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 972 | ALL_SPACES(kNewObject, kFromCode, kInnerPointer) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 973 | // Find a recently deserialized object using its offset from the current |
| 974 | // allocation point and write a pointer to it to the current object. |
| 975 | ALL_SPACES(kBackref, kPlain, kStartOfObject) |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 976 | ALL_SPACES(kBackrefWithSkip, kPlain, kStartOfObject) |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 977 | #if V8_TARGET_ARCH_MIPS |
| 978 | // Deserialize a new object from pointer found in code and write |
| 979 | // a pointer to it to the current object. Required only for MIPS, and |
| 980 | // omitted on the other architectures because it is fully unrolled and |
| 981 | // would cause bloat. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 982 | ALL_SPACES(kNewObject, kFromCode, kStartOfObject) |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 983 | // Find a recently deserialized code object using its offset from the |
| 984 | // current allocation point and write a pointer to it to the current |
| 985 | // object. Required only for MIPS. |
| 986 | ALL_SPACES(kBackref, kFromCode, kStartOfObject) |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 987 | ALL_SPACES(kBackrefWithSkip, kFromCode, kStartOfObject) |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 988 | #endif |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 989 | // Find a recently deserialized code object using its offset from the |
| 990 | // current allocation point and write a pointer to its first instruction |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 991 | // to the current code object or the instruction pointer in a function |
| 992 | // object. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 993 | ALL_SPACES(kBackref, kFromCode, kInnerPointer) |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 994 | ALL_SPACES(kBackrefWithSkip, kFromCode, kInnerPointer) |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 995 | ALL_SPACES(kBackref, kPlain, kInnerPointer) |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 996 | ALL_SPACES(kBackrefWithSkip, kPlain, kInnerPointer) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 997 | // Find an object in the roots array and write a pointer to it to the |
| 998 | // current object. |
| 999 | CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0) |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1000 | CASE_BODY(kRootArray, kPlain, kStartOfObject, 0) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1001 | // Find an object in the partial snapshots cache and write a pointer to it |
| 1002 | // to the current object. |
| 1003 | CASE_STATEMENT(kPartialSnapshotCache, kPlain, kStartOfObject, 0) |
| 1004 | CASE_BODY(kPartialSnapshotCache, |
| 1005 | kPlain, |
| 1006 | kStartOfObject, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1007 | 0) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1008 | // Find an code entry in the partial snapshots cache and |
| 1009 | // write a pointer to it to the current object. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1010 | CASE_STATEMENT(kPartialSnapshotCache, kPlain, kInnerPointer, 0) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1011 | CASE_BODY(kPartialSnapshotCache, |
| 1012 | kPlain, |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1013 | kInnerPointer, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1014 | 0) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1015 | // Find an external reference and write a pointer to it to the current |
| 1016 | // object. |
| 1017 | CASE_STATEMENT(kExternalReference, kPlain, kStartOfObject, 0) |
| 1018 | CASE_BODY(kExternalReference, |
| 1019 | kPlain, |
| 1020 | kStartOfObject, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1021 | 0) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1022 | // Find an external reference and write a pointer to it in the current |
| 1023 | // code object. |
| 1024 | CASE_STATEMENT(kExternalReference, kFromCode, kStartOfObject, 0) |
| 1025 | CASE_BODY(kExternalReference, |
| 1026 | kFromCode, |
| 1027 | kStartOfObject, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1028 | 0) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1029 | |
| 1030 | #undef CASE_STATEMENT |
| 1031 | #undef CASE_BODY |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1032 | #undef ALL_SPACES |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1033 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1034 | case kSkip: { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1035 | int size = source_->GetInt(); |
| 1036 | current = reinterpret_cast<Object**>( |
| 1037 | reinterpret_cast<intptr_t>(current) + size); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1041 | case kNativesStringResource: { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1042 | int index = source_->Get(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1043 | Vector<const char> source_vector = Natives::GetRawScriptSource(index); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1044 | NativesExternalStringResource* resource = |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1045 | new NativesExternalStringResource(isolate->bootstrapper(), |
| 1046 | source_vector.start(), |
| 1047 | source_vector.length()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1048 | *current++ = reinterpret_cast<Object*>(resource); |
| 1049 | break; |
| 1050 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1051 | |
| 1052 | case kSynchronize: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1053 | // If we get here then that indicates that you have a mismatch between |
| 1054 | // the number of GC roots when serializing and deserializing. |
| 1055 | UNREACHABLE(); |
| 1056 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1057 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1058 | default: |
| 1059 | UNREACHABLE(); |
| 1060 | } |
| 1061 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1062 | ASSERT_EQ(limit, current); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1067 | ASSERT(integer < 1 << 22); |
| 1068 | integer <<= 2; |
| 1069 | int bytes = 1; |
| 1070 | if (integer > 0xff) bytes = 2; |
| 1071 | if (integer > 0xffff) bytes = 3; |
| 1072 | integer |= bytes; |
| 1073 | Put(static_cast<int>(integer & 0xff), "IntPart1"); |
| 1074 | if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2"); |
| 1075 | if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1078 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1079 | Serializer::Serializer(SnapshotByteSink* sink) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1080 | : sink_(sink), |
| 1081 | current_root_index_(0), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1082 | external_reference_encoder_(new ExternalReferenceEncoder), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1083 | root_index_wave_front_(0) { |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1084 | isolate_ = Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1085 | // The serializer is meant to be used only to generate initial heap images |
| 1086 | // from a context in which there is only one isolate. |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1087 | ASSERT(isolate_->IsDefaultIsolate()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1088 | for (int i = 0; i <= LAST_SPACE; i++) { |
| 1089 | fullness_[i] = 0; |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1094 | Serializer::~Serializer() { |
| 1095 | delete external_reference_encoder_; |
| 1096 | } |
| 1097 | |
| 1098 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1099 | void StartupSerializer::SerializeStrongReferences() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1100 | Isolate* isolate = Isolate::Current(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1101 | // No active threads. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1102 | CHECK_EQ(NULL, Isolate::Current()->thread_manager()->FirstThreadStateInUse()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1103 | // No active or weak handles. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1104 | CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); |
| 1105 | CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1106 | // We don't support serializing installed extensions. |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1107 | CHECK(!isolate->has_installed_extensions()); |
| 1108 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1109 | HEAP->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1113 | void PartialSerializer::Serialize(Object** object) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1114 | this->VisitPointer(object); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1115 | Pad(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1119 | void Serializer::VisitPointers(Object** start, Object** end) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1120 | Isolate* isolate = Isolate::Current(); |
| 1121 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1122 | for (Object** current = start; current < end; current++) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1123 | if (start == isolate->heap()->roots_array_start()) { |
| 1124 | root_index_wave_front_ = |
| 1125 | Max(root_index_wave_front_, static_cast<intptr_t>(current - start)); |
| 1126 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1127 | if (reinterpret_cast<Address>(current) == |
| 1128 | isolate->heap()->store_buffer()->TopAddress()) { |
| 1129 | sink_->Put(kSkip, "Skip"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1130 | sink_->PutInt(kPointerSize, "SkipOneWord"); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1131 | } else if ((*current)->IsSmi()) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1132 | sink_->Put(kRawData + 1, "Smi"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1133 | for (int i = 0; i < kPointerSize; i++) { |
| 1134 | sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte"); |
| 1135 | } |
| 1136 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1137 | SerializeObject(*current, kPlain, kStartOfObject, 0); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1138 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1143 | // This ensures that the partial snapshot cache keeps things alive during GC and |
| 1144 | // tracks their movement. When it is called during serialization of the startup |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1145 | // snapshot nothing happens. When the partial (context) snapshot is created, |
| 1146 | // this array is populated with the pointers that the partial snapshot will |
| 1147 | // need. As that happens we emit serialized objects to the startup snapshot |
| 1148 | // that correspond to the elements of this cache array. On deserialization we |
| 1149 | // therefore need to visit the cache array. This fills it up with pointers to |
| 1150 | // deserialized objects. |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1151 | void SerializerDeserializer::Iterate(ObjectVisitor* visitor) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1152 | if (Serializer::enabled()) return; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1153 | Isolate* isolate = Isolate::Current(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1154 | for (int i = 0; ; i++) { |
| 1155 | if (isolate->serialize_partial_snapshot_cache_length() <= i) { |
| 1156 | // Extend the array ready to get a value from the visitor when |
| 1157 | // deserializing. |
| 1158 | isolate->PushToPartialSnapshotCache(Smi::FromInt(0)); |
| 1159 | } |
| 1160 | Object** cache = isolate->serialize_partial_snapshot_cache(); |
| 1161 | visitor->VisitPointers(&cache[i], &cache[i + 1]); |
| 1162 | // Sentinel is the undefined object, which is a root so it will not normally |
| 1163 | // be found in the cache. |
| 1164 | if (cache[i] == isolate->heap()->undefined_value()) { |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | |
| 1171 | int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1172 | Isolate* isolate = Isolate::Current(); |
| 1173 | |
| 1174 | for (int i = 0; |
| 1175 | i < isolate->serialize_partial_snapshot_cache_length(); |
| 1176 | i++) { |
| 1177 | Object* entry = isolate->serialize_partial_snapshot_cache()[i]; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1178 | if (entry == heap_object) return i; |
| 1179 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1180 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1181 | // We didn't find the object in the cache. So we add it to the cache and |
| 1182 | // then visit the pointer so that it becomes part of the startup snapshot |
| 1183 | // and we can refer to it from the partial snapshot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1184 | int length = isolate->serialize_partial_snapshot_cache_length(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1185 | isolate->PushToPartialSnapshotCache(heap_object); |
| 1186 | startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1187 | // We don't recurse from the startup snapshot generator into the partial |
| 1188 | // snapshot generator. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1189 | ASSERT(length == isolate->serialize_partial_snapshot_cache_length() - 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1190 | return length; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1194 | int Serializer::RootIndex(HeapObject* heap_object, HowToCode from) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1195 | Heap* heap = HEAP; |
| 1196 | if (heap->InNewSpace(heap_object)) return kInvalidRootIndex; |
| 1197 | for (int i = 0; i < root_index_wave_front_; i++) { |
| 1198 | Object* root = heap->roots_array_start()[i]; |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1199 | if (!root->IsSmi() && root == heap_object) { |
| 1200 | #if V8_TARGET_ARCH_MIPS |
| 1201 | if (from == kFromCode) { |
| 1202 | // In order to avoid code bloat in the deserializer we don't have |
| 1203 | // support for the encoding that specifies a particular root should |
| 1204 | // be written into the lui/ori instructions on MIPS. Therefore we |
| 1205 | // should not generate such serialization data for MIPS. |
| 1206 | return kInvalidRootIndex; |
| 1207 | } |
| 1208 | #endif |
| 1209 | return i; |
| 1210 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1211 | } |
| 1212 | return kInvalidRootIndex; |
| 1213 | } |
| 1214 | |
| 1215 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1216 | // Encode the location of an already deserialized object in order to write its |
| 1217 | // location into a later object. We can encode the location as an offset from |
| 1218 | // the start of the deserialized objects or as an offset backwards from the |
| 1219 | // current allocation pointer. |
| 1220 | void Serializer::SerializeReferenceToPreviousObject( |
| 1221 | int space, |
| 1222 | int address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1223 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1224 | WhereToPoint where_to_point, |
| 1225 | int skip) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1226 | int offset = CurrentAllocationAddress(space) - address; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1227 | // Shift out the bits that are always 0. |
| 1228 | offset >>= kObjectAlignmentBits; |
| 1229 | if (skip == 0) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1230 | sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1231 | } else { |
| 1232 | sink_->Put(kBackrefWithSkip + how_to_code + where_to_point + space, |
| 1233 | "BackRefSerWithSkip"); |
| 1234 | sink_->PutInt(skip, "BackRefSkipDistance"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1235 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1236 | sink_->PutInt(offset, "offset"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | void StartupSerializer::SerializeObject( |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1241 | Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1242 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1243 | WhereToPoint where_to_point, |
| 1244 | int skip) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1245 | CHECK(o->IsHeapObject()); |
| 1246 | HeapObject* heap_object = HeapObject::cast(o); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1247 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1248 | int root_index; |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1249 | if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1250 | PutRoot(root_index, heap_object, how_to_code, where_to_point, skip); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1251 | return; |
| 1252 | } |
| 1253 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1254 | if (address_mapper_.IsMapped(heap_object)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1255 | int space = SpaceOfObject(heap_object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1256 | int address = address_mapper_.MappedTo(heap_object); |
| 1257 | SerializeReferenceToPreviousObject(space, |
| 1258 | address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1259 | how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1260 | where_to_point, |
| 1261 | skip); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1262 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1263 | if (skip != 0) { |
| 1264 | sink_->Put(kSkip, "FlushPendingSkip"); |
| 1265 | sink_->PutInt(skip, "SkipDistance"); |
| 1266 | } |
| 1267 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1268 | // Object has not yet been serialized. Serialize it here. |
| 1269 | ObjectSerializer object_serializer(this, |
| 1270 | heap_object, |
| 1271 | sink_, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1272 | how_to_code, |
| 1273 | where_to_point); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1274 | object_serializer.Serialize(); |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | |
| 1279 | void StartupSerializer::SerializeWeakReferences() { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1280 | // This phase comes right after the partial serialization (of the snapshot). |
| 1281 | // After we have done the partial serialization the partial snapshot cache |
| 1282 | // will contain some references needed to decode the partial snapshot. We |
| 1283 | // add one entry with 'undefined' which is the sentinel that the deserializer |
| 1284 | // uses to know it is done deserializing the array. |
| 1285 | Isolate* isolate = Isolate::Current(); |
| 1286 | Object* undefined = isolate->heap()->undefined_value(); |
| 1287 | VisitPointer(&undefined); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1288 | HEAP->IterateWeakRoots(this, VISIT_ALL); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1289 | Pad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1293 | void Serializer::PutRoot(int root_index, |
| 1294 | HeapObject* object, |
| 1295 | SerializerDeserializer::HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1296 | SerializerDeserializer::WhereToPoint where_to_point, |
| 1297 | int skip) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1298 | if (how_to_code == kPlain && |
| 1299 | where_to_point == kStartOfObject && |
| 1300 | root_index < kRootArrayNumberOfConstantEncodings && |
| 1301 | !HEAP->InNewSpace(object)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1302 | if (skip == 0) { |
| 1303 | sink_->Put(kRootArrayConstants + kNoSkipDistance + root_index, |
| 1304 | "RootConstant"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1305 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1306 | sink_->Put(kRootArrayConstants + kHasSkipDistance + root_index, |
| 1307 | "RootConstant"); |
| 1308 | sink_->PutInt(skip, "SkipInPutRoot"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1309 | } |
| 1310 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1311 | if (skip != 0) { |
| 1312 | sink_->Put(kSkip, "SkipFromPutRoot"); |
| 1313 | sink_->PutInt(skip, "SkipFromPutRootDistance"); |
| 1314 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1315 | sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization"); |
| 1316 | sink_->PutInt(root_index, "root_index"); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1321 | void PartialSerializer::SerializeObject( |
| 1322 | Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1323 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1324 | WhereToPoint where_to_point, |
| 1325 | int skip) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1326 | CHECK(o->IsHeapObject()); |
| 1327 | HeapObject* heap_object = HeapObject::cast(o); |
| 1328 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1329 | if (heap_object->IsMap()) { |
| 1330 | // The code-caches link to context-specific code objects, which |
| 1331 | // the startup and context serializes cannot currently handle. |
| 1332 | ASSERT(Map::cast(heap_object)->code_cache() == |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 1333 | heap_object->GetHeap()->empty_fixed_array()); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1336 | int root_index; |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1337 | if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1338 | PutRoot(root_index, heap_object, how_to_code, where_to_point, skip); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1339 | return; |
| 1340 | } |
| 1341 | |
| 1342 | if (ShouldBeInThePartialSnapshotCache(heap_object)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1343 | if (skip != 0) { |
| 1344 | sink_->Put(kSkip, "SkipFromSerializeObject"); |
| 1345 | sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
| 1346 | } |
| 1347 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1348 | int cache_index = PartialSnapshotCacheIndex(heap_object); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1349 | sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point, |
| 1350 | "PartialSnapshotCache"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1351 | sink_->PutInt(cache_index, "partial_snapshot_cache_index"); |
| 1352 | return; |
| 1353 | } |
| 1354 | |
| 1355 | // Pointers from the partial snapshot to the objects in the startup snapshot |
| 1356 | // should go through the root array or through the partial snapshot cache. |
| 1357 | // If this is not the case you may have to add something to the root array. |
| 1358 | ASSERT(!startup_serializer_->address_mapper()->IsMapped(heap_object)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1359 | // All the internalized strings that the partial snapshot needs should be |
| 1360 | // either in the root table or in the partial snapshot cache. |
| 1361 | ASSERT(!heap_object->IsInternalizedString()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1362 | |
| 1363 | if (address_mapper_.IsMapped(heap_object)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1364 | int space = SpaceOfObject(heap_object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1365 | int address = address_mapper_.MappedTo(heap_object); |
| 1366 | SerializeReferenceToPreviousObject(space, |
| 1367 | address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1368 | how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1369 | where_to_point, |
| 1370 | skip); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1371 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1372 | if (skip != 0) { |
| 1373 | sink_->Put(kSkip, "SkipFromSerializeObject"); |
| 1374 | sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
| 1375 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1376 | // Object has not yet been serialized. Serialize it here. |
| 1377 | ObjectSerializer serializer(this, |
| 1378 | heap_object, |
| 1379 | sink_, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1380 | how_to_code, |
| 1381 | where_to_point); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1382 | serializer.Serialize(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1387 | void Serializer::ObjectSerializer::Serialize() { |
| 1388 | int space = Serializer::SpaceOfObject(object_); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1389 | int size = object_->Size(); |
| 1390 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1391 | sink_->Put(kNewObject + reference_representation_ + space, |
| 1392 | "ObjectSerialization"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1393 | sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); |
| 1394 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1395 | LOG(i::Isolate::Current(), |
| 1396 | SnapshotPositionEvent(object_->address(), sink_->Position())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1397 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1398 | // Mark this object as already serialized. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1399 | int offset = serializer_->Allocate(space, size); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1400 | serializer_->address_mapper()->AddMapping(object_, offset); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1401 | |
| 1402 | // Serialize the map (first word of the object). |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1403 | serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1404 | |
| 1405 | // Serialize the rest of the object. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1406 | CHECK_EQ(0, bytes_processed_so_far_); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1407 | bytes_processed_so_far_ = kPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1408 | object_->IterateBody(object_->map()->instance_type(), size, this); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1409 | OutputRawData(object_->address() + size); |
| 1410 | } |
| 1411 | |
| 1412 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1413 | void Serializer::ObjectSerializer::VisitPointers(Object** start, |
| 1414 | Object** end) { |
| 1415 | Object** current = start; |
| 1416 | while (current < end) { |
| 1417 | while (current < end && (*current)->IsSmi()) current++; |
| 1418 | if (current < end) OutputRawData(reinterpret_cast<Address>(current)); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1419 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1420 | while (current < end && !(*current)->IsSmi()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1421 | HeapObject* current_contents = HeapObject::cast(*current); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1422 | int root_index = serializer_->RootIndex(current_contents, kPlain); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1423 | // Repeats are not subject to the write barrier so there are only some |
| 1424 | // objects that can be used in a repeat encoding. These are the early |
| 1425 | // ones in the root array that are never in new space. |
| 1426 | if (current != start && |
| 1427 | root_index != kInvalidRootIndex && |
| 1428 | root_index < kRootArrayNumberOfConstantEncodings && |
| 1429 | current_contents == current[-1]) { |
| 1430 | ASSERT(!HEAP->InNewSpace(current_contents)); |
| 1431 | int repeat_count = 1; |
| 1432 | while (current < end - 1 && current[repeat_count] == current_contents) { |
| 1433 | repeat_count++; |
| 1434 | } |
| 1435 | current += repeat_count; |
| 1436 | bytes_processed_so_far_ += repeat_count * kPointerSize; |
| 1437 | if (repeat_count > kMaxRepeats) { |
| 1438 | sink_->Put(kRepeat, "SerializeRepeats"); |
| 1439 | sink_->PutInt(repeat_count, "SerializeRepeats"); |
| 1440 | } else { |
| 1441 | sink_->Put(CodeForRepeats(repeat_count), "SerializeRepeats"); |
| 1442 | } |
| 1443 | } else { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1444 | serializer_->SerializeObject( |
| 1445 | current_contents, kPlain, kStartOfObject, 0); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1446 | bytes_processed_so_far_ += kPointerSize; |
| 1447 | current++; |
| 1448 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1449 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1450 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1454 | void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) { |
| 1455 | Object** current = rinfo->target_object_address(); |
| 1456 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1457 | int skip = OutputRawData(rinfo->target_address_address(), |
| 1458 | kCanReturnSkipInsteadOfSkipping); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1459 | HowToCode representation = rinfo->IsCodedSpecially() ? kFromCode : kPlain; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1460 | serializer_->SerializeObject(*current, representation, kStartOfObject, skip); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1461 | bytes_processed_so_far_ += rinfo->target_address_size(); |
| 1462 | } |
| 1463 | |
| 1464 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1465 | void Serializer::ObjectSerializer::VisitExternalReferences(Address* start, |
| 1466 | Address* end) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1467 | Address references_start = reinterpret_cast<Address>(start); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1468 | int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1469 | |
| 1470 | for (Address* current = start; current < end; current++) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1471 | sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1472 | sink_->PutInt(skip, "SkipB4ExternalRef"); |
| 1473 | skip = 0; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1474 | int reference_id = serializer_->EncodeExternalReference(*current); |
| 1475 | sink_->PutInt(reference_id, "reference id"); |
| 1476 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1477 | bytes_processed_so_far_ += static_cast<int>((end - start) * kPointerSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1481 | void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) { |
| 1482 | Address references_start = rinfo->target_address_address(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1483 | int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1484 | |
| 1485 | Address* current = rinfo->target_reference_address(); |
| 1486 | int representation = rinfo->IsCodedSpecially() ? |
| 1487 | kFromCode + kStartOfObject : kPlain + kStartOfObject; |
| 1488 | sink_->Put(kExternalReference + representation, "ExternalRef"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1489 | sink_->PutInt(skip, "SkipB4ExternalRef"); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1490 | int reference_id = serializer_->EncodeExternalReference(*current); |
| 1491 | sink_->PutInt(reference_id, "reference id"); |
| 1492 | bytes_processed_so_far_ += rinfo->target_address_size(); |
| 1493 | } |
| 1494 | |
| 1495 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1496 | void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) { |
| 1497 | Address target_start = rinfo->target_address_address(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1498 | int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1499 | Address target = rinfo->target_address(); |
| 1500 | uint32_t encoding = serializer_->EncodeExternalReference(target); |
| 1501 | CHECK(target == NULL ? encoding == 0 : encoding != 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1502 | int representation; |
| 1503 | // Can't use a ternary operator because of gcc. |
| 1504 | if (rinfo->IsCodedSpecially()) { |
| 1505 | representation = kStartOfObject + kFromCode; |
| 1506 | } else { |
| 1507 | representation = kStartOfObject + kPlain; |
| 1508 | } |
| 1509 | sink_->Put(kExternalReference + representation, "ExternalReference"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1510 | sink_->PutInt(skip, "SkipB4ExternalRef"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1511 | sink_->PutInt(encoding, "reference id"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1512 | bytes_processed_so_far_ += rinfo->target_address_size(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
| 1516 | void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) { |
| 1517 | CHECK(RelocInfo::IsCodeTarget(rinfo->rmode())); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1518 | Address target_start = rinfo->target_address_address(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1519 | int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1520 | Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1521 | serializer_->SerializeObject(target, kFromCode, kInnerPointer, skip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1522 | bytes_processed_so_far_ += rinfo->target_address_size(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1526 | void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) { |
| 1527 | Code* target = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1528 | int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping); |
| 1529 | serializer_->SerializeObject(target, kPlain, kInnerPointer, skip); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1530 | bytes_processed_so_far_ += kPointerSize; |
| 1531 | } |
| 1532 | |
| 1533 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1534 | void Serializer::ObjectSerializer::VisitGlobalPropertyCell(RelocInfo* rinfo) { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1535 | ASSERT(rinfo->rmode() == RelocInfo::GLOBAL_PROPERTY_CELL); |
| 1536 | JSGlobalPropertyCell* cell = |
| 1537 | JSGlobalPropertyCell::cast(rinfo->target_cell()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1538 | int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping); |
| 1539 | serializer_->SerializeObject(cell, kPlain, kInnerPointer, skip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1543 | void Serializer::ObjectSerializer::VisitExternalAsciiString( |
| 1544 | v8::String::ExternalAsciiStringResource** resource_pointer) { |
| 1545 | Address references_start = reinterpret_cast<Address>(resource_pointer); |
| 1546 | OutputRawData(references_start); |
| 1547 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1548 | Object* source = HEAP->natives_source_cache()->get(i); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1549 | if (!source->IsUndefined()) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1550 | ExternalAsciiString* string = ExternalAsciiString::cast(source); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1551 | typedef v8::String::ExternalAsciiStringResource Resource; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1552 | const Resource* resource = string->resource(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1553 | if (resource == *resource_pointer) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1554 | sink_->Put(kNativesStringResource, "NativesStringResource"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1555 | sink_->PutSection(i, "NativesStringResourceEnd"); |
| 1556 | bytes_processed_so_far_ += sizeof(resource); |
| 1557 | return; |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | // One of the strings in the natives cache should match the resource. We |
| 1562 | // can't serialize any other kinds of external strings. |
| 1563 | UNREACHABLE(); |
| 1564 | } |
| 1565 | |
| 1566 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1567 | int Serializer::ObjectSerializer::OutputRawData( |
| 1568 | Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1569 | Address object_start = object_->address(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1570 | Address base = object_start + bytes_processed_so_far_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1571 | int up_to_offset = static_cast<int>(up_to - object_start); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1572 | int to_skip = up_to_offset - bytes_processed_so_far_; |
| 1573 | int bytes_to_output = to_skip; |
| 1574 | bytes_processed_so_far_ += to_skip; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1575 | // This assert will fail if the reloc info gives us the target_address_address |
| 1576 | // locations in a non-ascending order. Luckily that doesn't happen. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1577 | ASSERT(to_skip >= 0); |
| 1578 | bool outputting_code = false; |
| 1579 | if (to_skip != 0 && code_object_ && !code_has_been_output_) { |
| 1580 | // Output the code all at once and fix later. |
| 1581 | bytes_to_output = object_->Size() + to_skip - bytes_processed_so_far_; |
| 1582 | outputting_code = true; |
| 1583 | code_has_been_output_ = true; |
| 1584 | } |
| 1585 | if (bytes_to_output != 0 && |
| 1586 | (!code_object_ || outputting_code)) { |
| 1587 | #define RAW_CASE(index) \ |
| 1588 | if (!outputting_code && bytes_to_output == index * kPointerSize && \ |
| 1589 | index * kPointerSize == to_skip) { \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1590 | sink_->PutSection(kRawData + index, "RawDataFixed"); \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1591 | to_skip = 0; /* This insn already skips. */ \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1592 | } else /* NOLINT */ |
| 1593 | COMMON_RAW_LENGTHS(RAW_CASE) |
| 1594 | #undef RAW_CASE |
| 1595 | { /* NOLINT */ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1596 | // We always end up here if we are outputting the code of a code object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1597 | sink_->Put(kRawData, "RawData"); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1598 | sink_->PutInt(bytes_to_output, "length"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1599 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1600 | for (int i = 0; i < bytes_to_output; i++) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1601 | unsigned int data = base[i]; |
| 1602 | sink_->PutSection(data, "Byte"); |
| 1603 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1604 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1605 | if (to_skip != 0 && return_skip == kIgnoringReturn) { |
| 1606 | sink_->Put(kSkip, "Skip"); |
| 1607 | sink_->PutInt(to_skip, "SkipDistance"); |
| 1608 | to_skip = 0; |
| 1609 | } |
| 1610 | return to_skip; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1614 | int Serializer::SpaceOfObject(HeapObject* object) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1615 | for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) { |
| 1616 | AllocationSpace s = static_cast<AllocationSpace>(i); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1617 | if (HEAP->InSpace(object, s)) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1618 | ASSERT(i < kNumberOfSpaces); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1619 | return i; |
| 1620 | } |
| 1621 | } |
| 1622 | UNREACHABLE(); |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1627 | int Serializer::Allocate(int space, int size) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1628 | CHECK(space >= 0 && space < kNumberOfSpaces); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1629 | int allocation_address = fullness_[space]; |
| 1630 | fullness_[space] = allocation_address + size; |
| 1631 | return allocation_address; |
| 1632 | } |
| 1633 | |
| 1634 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1635 | int Serializer::SpaceAreaSize(int space) { |
| 1636 | if (space == CODE_SPACE) { |
| 1637 | return isolate_->memory_allocator()->CodePageAreaSize(); |
| 1638 | } else { |
| 1639 | return Page::kPageSize - Page::kObjectStartOffset; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1644 | void Serializer::Pad() { |
| 1645 | // The non-branching GetInt will read up to 3 bytes too far, so we need |
| 1646 | // to pad the snapshot to make sure we don't read over the end. |
| 1647 | for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) { |
| 1648 | sink_->Put(kNop, "Padding"); |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | |
| 1653 | bool SnapshotByteSource::AtEOF() { |
| 1654 | if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; |
| 1655 | for (int x = position_; x < length_; x++) { |
| 1656 | if (data_[x] != SerializerDeserializer::nop()) return false; |
| 1657 | } |
| 1658 | return true; |
| 1659 | } |
| 1660 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | } } // namespace v8::internal |