fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #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" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "execution.h" |
| 34 | #include "global-handles.h" |
| 35 | #include "ic-inl.h" |
| 36 | #include "natives.h" |
| 37 | #include "platform.h" |
| 38 | #include "runtime.h" |
| 39 | #include "serialize.h" |
| 40 | #include "stub-cache.h" |
| 41 | #include "v8threads.h" |
| 42 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 43 | namespace v8 { |
| 44 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | // ----------------------------------------------------------------------------- |
| 48 | // Coding of external references. |
| 49 | |
| 50 | // The encoding of an external reference. The type is in the high word. |
| 51 | // The id is in the low word. |
| 52 | static uint32_t EncodeExternal(TypeCode type, uint16_t id) { |
| 53 | return static_cast<uint32_t>(type) << 16 | id; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static int* GetInternalPointer(StatsCounter* counter) { |
| 58 | // All counters refer to dummy_counter, if deserializing happens without |
| 59 | // setting up counters. |
| 60 | static int dummy_counter = 0; |
| 61 | return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | // ExternalReferenceTable is a helper class that defines the relationship |
| 66 | // between external references and their encodings. It is used to build |
| 67 | // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder. |
| 68 | class ExternalReferenceTable { |
| 69 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 70 | static ExternalReferenceTable* instance(Isolate* isolate) { |
| 71 | ExternalReferenceTable* external_reference_table = |
| 72 | isolate->external_reference_table(); |
| 73 | if (external_reference_table == NULL) { |
| 74 | external_reference_table = new ExternalReferenceTable(isolate); |
| 75 | isolate->set_external_reference_table(external_reference_table); |
| 76 | } |
| 77 | return external_reference_table; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | int size() const { return refs_.length(); } |
| 81 | |
| 82 | Address address(int i) { return refs_[i].address; } |
| 83 | |
| 84 | uint32_t code(int i) { return refs_[i].code; } |
| 85 | |
| 86 | const char* name(int i) { return refs_[i].name; } |
| 87 | |
| 88 | int max_id(int code) { return max_id_[code]; } |
| 89 | |
| 90 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) { |
| 92 | PopulateTable(isolate); |
| 93 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 94 | ~ExternalReferenceTable() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | |
| 96 | struct ExternalReferenceEntry { |
| 97 | Address address; |
| 98 | uint32_t code; |
| 99 | const char* name; |
| 100 | }; |
| 101 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 102 | void PopulateTable(Isolate* isolate); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 103 | |
| 104 | // For a few types of references, we can get their address from their id. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 105 | void AddFromId(TypeCode type, |
| 106 | uint16_t id, |
| 107 | const char* name, |
| 108 | Isolate* isolate); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 109 | |
| 110 | // For other types of references, the caller will figure out the address. |
| 111 | void Add(Address address, TypeCode type, uint16_t id, const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | |
| 113 | List<ExternalReferenceEntry> refs_; |
| 114 | int max_id_[kTypeCodeCount]; |
| 115 | }; |
| 116 | |
| 117 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 118 | void ExternalReferenceTable::AddFromId(TypeCode type, |
| 119 | uint16_t id, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 120 | const char* name, |
| 121 | Isolate* isolate) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 122 | Address address; |
| 123 | switch (type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 124 | case C_BUILTIN: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 125 | ExternalReference ref(static_cast<Builtins::CFunctionId>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 126 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 127 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 128 | } |
| 129 | case BUILTIN: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 130 | ExternalReference ref(static_cast<Builtins::Name>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 131 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 132 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 133 | } |
| 134 | case RUNTIME_FUNCTION: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 135 | ExternalReference ref(static_cast<Runtime::FunctionId>(id), isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 136 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 137 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 138 | } |
| 139 | case IC_UTILITY: { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 140 | ExternalReference ref(IC_Utility(static_cast<IC::UtilityId>(id)), |
| 141 | isolate); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 142 | address = ref.address(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 143 | break; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 144 | } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 145 | default: |
| 146 | UNREACHABLE(); |
| 147 | return; |
| 148 | } |
| 149 | Add(address, type, id, name); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | void ExternalReferenceTable::Add(Address address, |
| 154 | TypeCode type, |
| 155 | uint16_t id, |
| 156 | const char* name) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 157 | ASSERT_NE(NULL, address); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 158 | ExternalReferenceEntry entry; |
| 159 | entry.address = address; |
| 160 | entry.code = EncodeExternal(type, id); |
| 161 | entry.name = name; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 162 | ASSERT_NE(0, entry.code); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 163 | refs_.Add(entry); |
| 164 | if (id > max_id_[type]) max_id_[type] = id; |
| 165 | } |
| 166 | |
| 167 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 168 | void ExternalReferenceTable::PopulateTable(Isolate* isolate) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | for (int type_code = 0; type_code < kTypeCodeCount; type_code++) { |
| 170 | max_id_[type_code] = 0; |
| 171 | } |
| 172 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 173 | // The following populates all of the different type of external references |
| 174 | // into the ExternalReferenceTable. |
| 175 | // |
| 176 | // NOTE: This function was originally 100k of code. It has since been |
| 177 | // rewritten to be mostly table driven, as the callback macro style tends to |
| 178 | // very easily cause code bloat. Please be careful in the future when adding |
| 179 | // new references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 180 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 181 | struct RefTableEntry { |
| 182 | TypeCode type; |
| 183 | uint16_t id; |
| 184 | const char* name; |
| 185 | }; |
| 186 | |
| 187 | static const RefTableEntry ref_table[] = { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | // Builtins |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 189 | #define DEF_ENTRY_C(name, ignored) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 190 | { C_BUILTIN, \ |
| 191 | Builtins::c_##name, \ |
| 192 | "Builtins::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | |
| 194 | BUILTIN_LIST_C(DEF_ENTRY_C) |
| 195 | #undef DEF_ENTRY_C |
| 196 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 197 | #define DEF_ENTRY_C(name, ignored) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 198 | { BUILTIN, \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 199 | Builtins::k##name, \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 200 | "Builtins::" #name }, |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 201 | #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] | 202 | |
| 203 | BUILTIN_LIST_C(DEF_ENTRY_C) |
| 204 | BUILTIN_LIST_A(DEF_ENTRY_A) |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 205 | BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | #undef DEF_ENTRY_C |
| 207 | #undef DEF_ENTRY_A |
| 208 | |
| 209 | // Runtime functions |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 210 | #define RUNTIME_ENTRY(name, nargs, ressize) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 211 | { RUNTIME_FUNCTION, \ |
| 212 | Runtime::k##name, \ |
| 213 | "Runtime::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | |
| 215 | RUNTIME_FUNCTION_LIST(RUNTIME_ENTRY) |
| 216 | #undef RUNTIME_ENTRY |
| 217 | |
| 218 | // IC utilities |
| 219 | #define IC_ENTRY(name) \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 220 | { IC_UTILITY, \ |
| 221 | IC::k##name, \ |
| 222 | "IC::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | |
| 224 | IC_UTIL_LIST(IC_ENTRY) |
| 225 | #undef IC_ENTRY |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 226 | }; // end of ref_table[]. |
| 227 | |
| 228 | for (size_t i = 0; i < ARRAY_SIZE(ref_table); ++i) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 229 | AddFromId(ref_table[i].type, |
| 230 | ref_table[i].id, |
| 231 | ref_table[i].name, |
| 232 | isolate); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 233 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 235 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | // Debug addresses |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 237 | Add(Debug_Address(Debug::k_after_break_target_address).address(isolate), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | DEBUG_ADDRESS, |
| 239 | Debug::k_after_break_target_address << kDebugIdShift, |
| 240 | "Debug::after_break_target_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 241 | Add(Debug_Address(Debug::k_debug_break_slot_address).address(isolate), |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 242 | DEBUG_ADDRESS, |
| 243 | Debug::k_debug_break_slot_address << kDebugIdShift, |
| 244 | "Debug::debug_break_slot_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 245 | Add(Debug_Address(Debug::k_debug_break_return_address).address(isolate), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 246 | DEBUG_ADDRESS, |
| 247 | Debug::k_debug_break_return_address << kDebugIdShift, |
| 248 | "Debug::debug_break_return_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 249 | Add(Debug_Address(Debug::k_restarter_frame_function_pointer).address(isolate), |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 250 | DEBUG_ADDRESS, |
| 251 | Debug::k_restarter_frame_function_pointer << kDebugIdShift, |
| 252 | "Debug::restarter_frame_function_pointer_address()"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 253 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | |
| 255 | // Stat counters |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 256 | struct StatsRefTableEntry { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 257 | StatsCounter* (Counters::*counter)(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 258 | uint16_t id; |
| 259 | const char* name; |
| 260 | }; |
| 261 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 262 | const StatsRefTableEntry stats_ref_table[] = { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | #define COUNTER_ENTRY(name, caption) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 264 | { &Counters::name, \ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 265 | Counters::k_##name, \ |
| 266 | "Counters::" #name }, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | |
| 268 | STATS_COUNTER_LIST_1(COUNTER_ENTRY) |
| 269 | STATS_COUNTER_LIST_2(COUNTER_ENTRY) |
| 270 | #undef COUNTER_ENTRY |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 271 | }; // end of stats_ref_table[]. |
| 272 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 273 | Counters* counters = isolate->counters(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 274 | 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] | 275 | Add(reinterpret_cast<Address>(GetInternalPointer( |
| 276 | (counters->*(stats_ref_table[i].counter))())), |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 277 | STATS_COUNTER, |
| 278 | stats_ref_table[i].id, |
| 279 | stats_ref_table[i].name); |
| 280 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | |
| 282 | // Top addresses |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 283 | |
| 284 | const char* AddressNames[] = { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 285 | #define C(name) "Isolate::" #name, |
| 286 | ISOLATE_ADDRESS_LIST(C) |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 287 | NULL |
| 288 | #undef C |
| 289 | }; |
| 290 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 291 | for (uint16_t i = 0; i < Isolate::k_isolate_address_count; ++i) { |
| 292 | Add(isolate->get_address_from_id((Isolate::AddressId)i), |
| 293 | TOP_ADDRESS, i, AddressNames[i]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | } |
| 295 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | // Accessors |
| 297 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 298 | Add((Address)&Accessors::name, \ |
| 299 | ACCESSOR, \ |
| 300 | Accessors::k##name, \ |
| 301 | "Accessors::" #name); |
| 302 | |
| 303 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 304 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 305 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | StubCache* stub_cache = isolate->stub_cache(); |
| 307 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | // Stub cache tables |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 309 | Add(stub_cache->key_reference(StubCache::kPrimary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 310 | STUB_CACHE_TABLE, |
| 311 | 1, |
| 312 | "StubCache::primary_->key"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 313 | Add(stub_cache->value_reference(StubCache::kPrimary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | STUB_CACHE_TABLE, |
| 315 | 2, |
| 316 | "StubCache::primary_->value"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 317 | Add(stub_cache->key_reference(StubCache::kSecondary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 318 | STUB_CACHE_TABLE, |
| 319 | 3, |
| 320 | "StubCache::secondary_->key"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 321 | Add(stub_cache->value_reference(StubCache::kSecondary).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | STUB_CACHE_TABLE, |
| 323 | 4, |
| 324 | "StubCache::secondary_->value"); |
| 325 | |
| 326 | // Runtime entries |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 327 | Add(ExternalReference::perform_gc_function(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | RUNTIME_ENTRY, |
| 329 | 1, |
| 330 | "Runtime::PerformGC"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 331 | Add(ExternalReference::fill_heap_number_with_random_function( |
| 332 | isolate).address(), |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 333 | RUNTIME_ENTRY, |
| 334 | 2, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 335 | "V8::FillHeapNumberWithRandom"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 336 | Add(ExternalReference::random_uint32_function(isolate).address(), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 337 | RUNTIME_ENTRY, |
| 338 | 3, |
| 339 | "V8::Random"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 340 | Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 341 | RUNTIME_ENTRY, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 342 | 4, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 343 | "HandleScope::DeleteExtensions"); |
| 344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | // Miscellaneous |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 346 | Add(ExternalReference::the_hole_value_location(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | UNCLASSIFIED, |
| 348 | 2, |
| 349 | "Factory::the_hole_value().location()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | Add(ExternalReference::roots_address(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | UNCLASSIFIED, |
| 352 | 3, |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 353 | "Heap::roots_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 354 | Add(ExternalReference::address_of_stack_limit(isolate).address(), |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 355 | UNCLASSIFIED, |
| 356 | 4, |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 357 | "StackGuard::address_of_jslimit()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 358 | Add(ExternalReference::address_of_real_stack_limit(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | UNCLASSIFIED, |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 360 | 5, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 361 | "StackGuard::address_of_real_jslimit()"); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 362 | #ifndef V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 363 | Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 364 | UNCLASSIFIED, |
| 365 | 6, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 366 | "RegExpStack::limit_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 367 | Add(ExternalReference::address_of_regexp_stack_memory_address( |
| 368 | isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | UNCLASSIFIED, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 370 | 7, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 371 | "RegExpStack::memory_address()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 372 | Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 373 | UNCLASSIFIED, |
| 374 | 8, |
| 375 | "RegExpStack::memory_size()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 376 | Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 377 | UNCLASSIFIED, |
| 378 | 9, |
| 379 | "OffsetsVector::static_offsets_vector"); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 380 | #endif // V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 381 | Add(ExternalReference::new_space_start(isolate).address(), |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 382 | UNCLASSIFIED, |
| 383 | 10, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 384 | "Heap::NewSpaceStart()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 385 | Add(ExternalReference::new_space_mask(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 386 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 387 | 11, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 388 | "Heap::NewSpaceMask()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 389 | Add(ExternalReference::heap_always_allocate_scope_depth(isolate).address(), |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 390 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 391 | 12, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 392 | "Heap::always_allocate_scope_depth()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 393 | Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 394 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 395 | 13, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | "Heap::NewSpaceAllocationLimitAddress()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 397 | Add(ExternalReference::new_space_allocation_top_address(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 398 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 399 | 14, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | "Heap::NewSpaceAllocationTopAddress()"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 401 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 402 | Add(ExternalReference::debug_break(isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 403 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 404 | 15, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 405 | "Debug::Break()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 406 | Add(ExternalReference::debug_step_in_fp_address(isolate).address(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 408 | 16, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | "Debug::step_in_fp_addr()"); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 410 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 411 | Add(ExternalReference::double_fp_operation(Token::ADD, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 412 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 413 | 17, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 414 | "add_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 415 | Add(ExternalReference::double_fp_operation(Token::SUB, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 416 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 417 | 18, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 418 | "sub_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 419 | Add(ExternalReference::double_fp_operation(Token::MUL, isolate).address(), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 420 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 421 | 19, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 422 | "mul_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 423 | Add(ExternalReference::double_fp_operation(Token::DIV, isolate).address(), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 424 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 425 | 20, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 426 | "div_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 427 | Add(ExternalReference::double_fp_operation(Token::MOD, isolate).address(), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 428 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 429 | 21, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 430 | "mod_two_doubles"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 431 | Add(ExternalReference::compare_doubles(isolate).address(), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 432 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 433 | 22, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 434 | "compare_doubles"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 435 | #ifndef V8_INTERPRETED_REGEXP |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 436 | Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 437 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 438 | 23, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 439 | "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 440 | Add(ExternalReference::re_check_stack_guard_state(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 441 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 442 | 24, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 443 | "RegExpMacroAssembler*::CheckStackGuardState()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 444 | Add(ExternalReference::re_grow_stack(isolate).address(), |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 445 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 446 | 25, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 447 | "NativeRegExpMacroAssembler::GrowStack()"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 448 | Add(ExternalReference::re_word_character_map().address(), |
| 449 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 450 | 26, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 451 | "NativeRegExpMacroAssembler::word_character_map"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 452 | #endif // V8_INTERPRETED_REGEXP |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 453 | // Keyed lookup cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 454 | Add(ExternalReference::keyed_lookup_cache_keys(isolate).address(), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 455 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 456 | 27, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 457 | "KeyedLookupCache::keys()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 458 | Add(ExternalReference::keyed_lookup_cache_field_offsets(isolate).address(), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 459 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 460 | 28, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 461 | "KeyedLookupCache::field_offsets()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 462 | Add(ExternalReference::transcendental_cache_array_address(isolate).address(), |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 463 | UNCLASSIFIED, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 464 | 29, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 465 | "TranscendentalCache::caches()"); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 466 | Add(ExternalReference::handle_scope_next_address().address(), |
| 467 | UNCLASSIFIED, |
| 468 | 30, |
| 469 | "HandleScope::next"); |
| 470 | Add(ExternalReference::handle_scope_limit_address().address(), |
| 471 | UNCLASSIFIED, |
| 472 | 31, |
| 473 | "HandleScope::limit"); |
| 474 | Add(ExternalReference::handle_scope_level_address().address(), |
| 475 | UNCLASSIFIED, |
| 476 | 32, |
| 477 | "HandleScope::level"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 478 | Add(ExternalReference::new_deoptimizer_function(isolate).address(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 479 | UNCLASSIFIED, |
| 480 | 33, |
| 481 | "Deoptimizer::New()"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 482 | Add(ExternalReference::compute_output_frames_function(isolate).address(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 483 | UNCLASSIFIED, |
| 484 | 34, |
| 485 | "Deoptimizer::ComputeOutputFrames()"); |
| 486 | Add(ExternalReference::address_of_min_int().address(), |
| 487 | UNCLASSIFIED, |
| 488 | 35, |
| 489 | "LDoubleConstant::min_int"); |
| 490 | Add(ExternalReference::address_of_one_half().address(), |
| 491 | UNCLASSIFIED, |
| 492 | 36, |
| 493 | "LDoubleConstant::one_half"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 494 | Add(ExternalReference::isolate_address().address(), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 495 | UNCLASSIFIED, |
| 496 | 37, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 497 | "isolate"); |
| 498 | Add(ExternalReference::address_of_minus_zero().address(), |
| 499 | UNCLASSIFIED, |
| 500 | 38, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 501 | "LDoubleConstant::minus_zero"); |
| 502 | Add(ExternalReference::address_of_negative_infinity().address(), |
| 503 | UNCLASSIFIED, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 504 | 39, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 505 | "LDoubleConstant::negative_infinity"); |
| 506 | Add(ExternalReference::power_double_double_function(isolate).address(), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 507 | UNCLASSIFIED, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 508 | 40, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 509 | "power_double_double_function"); |
| 510 | Add(ExternalReference::power_double_int_function(isolate).address(), |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 511 | UNCLASSIFIED, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 512 | 41, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 513 | "power_double_int_function"); |
| 514 | Add(ExternalReference::arguments_marker_location(isolate).address(), |
| 515 | UNCLASSIFIED, |
| 516 | 42, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 517 | "Factory::arguments_marker().location()"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
| 521 | ExternalReferenceEncoder::ExternalReferenceEncoder() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 522 | : encodings_(Match), |
| 523 | isolate_(Isolate::Current()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | ExternalReferenceTable* external_references = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 525 | ExternalReferenceTable::instance(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | for (int i = 0; i < external_references->size(); ++i) { |
| 527 | Put(external_references->address(i), i); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | |
| 532 | uint32_t ExternalReferenceEncoder::Encode(Address key) const { |
| 533 | int index = IndexOf(key); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 534 | ASSERT(key == NULL || index >= 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 535 | return index >=0 ? |
| 536 | ExternalReferenceTable::instance(isolate_)->code(index) : 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | const char* ExternalReferenceEncoder::NameOfAddress(Address key) const { |
| 541 | int index = IndexOf(key); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 542 | return index >= 0 ? |
| 543 | ExternalReferenceTable::instance(isolate_)->name(index) : NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | int ExternalReferenceEncoder::IndexOf(Address key) const { |
| 548 | if (key == NULL) return -1; |
| 549 | HashMap::Entry* entry = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 550 | const_cast<HashMap&>(encodings_).Lookup(key, Hash(key), false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 551 | return entry == NULL |
| 552 | ? -1 |
| 553 | : static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | |
| 557 | void ExternalReferenceEncoder::Put(Address key, int index) { |
| 558 | HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 559 | entry->value = reinterpret_cast<void*>(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | |
| 563 | ExternalReferenceDecoder::ExternalReferenceDecoder() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 564 | : encodings_(NewArray<Address*>(kTypeCodeCount)), |
| 565 | isolate_(Isolate::Current()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | ExternalReferenceTable* external_references = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 567 | ExternalReferenceTable::instance(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { |
| 569 | int max = external_references->max_id(type) + 1; |
| 570 | encodings_[type] = NewArray<Address>(max + 1); |
| 571 | } |
| 572 | for (int i = 0; i < external_references->size(); ++i) { |
| 573 | Put(external_references->code(i), external_references->address(i)); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | |
| 578 | ExternalReferenceDecoder::~ExternalReferenceDecoder() { |
| 579 | for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) { |
| 580 | DeleteArray(encodings_[type]); |
| 581 | } |
| 582 | DeleteArray(encodings_); |
| 583 | } |
| 584 | |
| 585 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 586 | bool Serializer::serialization_enabled_ = false; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 587 | bool Serializer::too_late_to_enable_now_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | |
| 589 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 590 | Deserializer::Deserializer(SnapshotByteSource* source) |
| 591 | : isolate_(NULL), |
| 592 | source_(source), |
| 593 | external_reference_decoder_(NULL) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
| 597 | // This routine both allocates a new object, and also keeps |
| 598 | // track of where objects have been allocated so that we can |
| 599 | // fix back references when deserializing. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 600 | Address Deserializer::Allocate(int space_index, Space* space, int size) { |
| 601 | Address address; |
| 602 | if (!SpaceIsLarge(space_index)) { |
| 603 | ASSERT(!SpaceIsPaged(space_index) || |
| 604 | size <= Page::kPageSize - Page::kObjectStartOffset); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 605 | MaybeObject* maybe_new_allocation; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 606 | if (space_index == NEW_SPACE) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 607 | maybe_new_allocation = |
| 608 | reinterpret_cast<NewSpace*>(space)->AllocateRaw(size); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 609 | } else { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 610 | maybe_new_allocation = |
| 611 | reinterpret_cast<PagedSpace*>(space)->AllocateRaw(size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 612 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 613 | Object* new_allocation = maybe_new_allocation->ToObjectUnchecked(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 614 | HeapObject* new_object = HeapObject::cast(new_allocation); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 615 | address = new_object->address(); |
| 616 | high_water_[space_index] = address + size; |
| 617 | } else { |
| 618 | ASSERT(SpaceIsLarge(space_index)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 619 | LargeObjectSpace* lo_space = reinterpret_cast<LargeObjectSpace*>(space); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 620 | Object* new_allocation; |
| 621 | if (space_index == kLargeData) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 622 | new_allocation = lo_space->AllocateRaw(size)->ToObjectUnchecked(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 623 | } else if (space_index == kLargeFixedArray) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 624 | new_allocation = |
| 625 | lo_space->AllocateRawFixedArray(size)->ToObjectUnchecked(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 626 | } else { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 627 | ASSERT_EQ(kLargeCode, space_index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 628 | new_allocation = lo_space->AllocateRawCode(size)->ToObjectUnchecked(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 629 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 630 | HeapObject* new_object = HeapObject::cast(new_allocation); |
| 631 | // Record all large objects in the same space. |
| 632 | address = new_object->address(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 633 | pages_[LO_SPACE].Add(address); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 634 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 635 | last_object_address_ = address; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 636 | return address; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | // This returns the address of an object that has been described in the |
| 641 | // snapshot as being offset bytes back in a particular space. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 642 | HeapObject* Deserializer::GetAddressFromEnd(int space) { |
| 643 | int offset = source_->GetInt(); |
| 644 | ASSERT(!SpaceIsLarge(space)); |
| 645 | offset <<= kObjectAlignmentBits; |
| 646 | return HeapObject::FromAddress(high_water_[space] - offset); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | // This returns the address of an object that has been described in the |
| 651 | // snapshot as being offset bytes into a particular space. |
| 652 | HeapObject* Deserializer::GetAddressFromStart(int space) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 653 | int offset = source_->GetInt(); |
| 654 | if (SpaceIsLarge(space)) { |
| 655 | // Large spaces have one object per 'page'. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 656 | return HeapObject::FromAddress(pages_[LO_SPACE][offset]); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 657 | } |
| 658 | offset <<= kObjectAlignmentBits; |
| 659 | if (space == NEW_SPACE) { |
| 660 | // New space has only one space - numbered 0. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 661 | return HeapObject::FromAddress(pages_[space][0] + offset); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 662 | } |
| 663 | ASSERT(SpaceIsPaged(space)); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 664 | int page_of_pointee = offset >> kPageSizeBits; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 665 | Address object_address = pages_[space][page_of_pointee] + |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 666 | (offset & Page::kPageAlignmentMask); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 667 | return HeapObject::FromAddress(object_address); |
| 668 | } |
| 669 | |
| 670 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 671 | void Deserializer::Deserialize() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 672 | isolate_ = Isolate::Current(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 673 | // Don't GC while deserializing - just expand the heap. |
| 674 | AlwaysAllocateScope always_allocate; |
| 675 | // Don't use the free lists while deserializing. |
| 676 | LinearAllocationScope allocate_linearly; |
| 677 | // No active threads. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 678 | ASSERT_EQ(NULL, isolate_->thread_manager()->FirstThreadStateInUse()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 679 | // No active handles. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 680 | ASSERT(isolate_->handle_scope_implementer()->blocks()->is_empty()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 681 | // Make sure the entire partial snapshot cache is traversed, filling it with |
| 682 | // valid object pointers. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 683 | isolate_->set_serialize_partial_snapshot_cache_length( |
| 684 | Isolate::kPartialSnapshotCacheCapacity); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 685 | ASSERT_EQ(NULL, external_reference_decoder_); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 686 | external_reference_decoder_ = new ExternalReferenceDecoder(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 687 | isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
| 688 | isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 689 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 690 | isolate_->heap()->set_global_contexts_list( |
| 691 | isolate_->heap()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | |
| 695 | void Deserializer::DeserializePartial(Object** root) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 696 | isolate_ = Isolate::Current(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 697 | // Don't GC while deserializing - just expand the heap. |
| 698 | AlwaysAllocateScope always_allocate; |
| 699 | // Don't use the free lists while deserializing. |
| 700 | LinearAllocationScope allocate_linearly; |
| 701 | if (external_reference_decoder_ == NULL) { |
| 702 | external_reference_decoder_ = new ExternalReferenceDecoder(); |
| 703 | } |
| 704 | VisitPointer(root); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | Deserializer::~Deserializer() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 709 | ASSERT(source_->AtEOF()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 710 | if (external_reference_decoder_) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 711 | delete external_reference_decoder_; |
| 712 | external_reference_decoder_ = NULL; |
| 713 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| 717 | // 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] | 718 | // process. It is also called on the body of each function. |
| 719 | void Deserializer::VisitPointers(Object** start, Object** end) { |
| 720 | // The space must be new space. Any other space would cause ReadChunk to try |
| 721 | // to update the remembered using NULL as the address. |
| 722 | ReadChunk(start, end, NEW_SPACE, NULL); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
| 726 | // This routine writes the new object into the pointer provided and then |
| 727 | // returns true if the new object was in young space and false otherwise. |
| 728 | // The reason for this strange interface is that otherwise the object is |
| 729 | // written very late, which means the ByteArray map is not set up by the |
| 730 | // time we need to use it to mark the space at the end of a page free (by |
| 731 | // making it into a byte array). |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 732 | void Deserializer::ReadObject(int space_number, |
| 733 | Space* space, |
| 734 | Object** write_back) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 735 | int size = source_->GetInt() << kObjectAlignmentBits; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 736 | Address address = Allocate(space_number, space, size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 737 | *write_back = HeapObject::FromAddress(address); |
| 738 | Object** current = reinterpret_cast<Object**>(address); |
| 739 | Object** limit = current + (size >> kPointerSizeLog2); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 740 | if (FLAG_log_snapshot_positions) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 741 | LOG(isolate_, SnapshotPositionEvent(address, source_->position())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 742 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 743 | ReadChunk(current, limit, space_number, address); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 744 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 745 | bool is_codespace = (space == HEAP->code_space()) || |
| 746 | ((space == HEAP->lo_space()) && (space_number == kLargeCode)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 747 | ASSERT(HeapObject::FromAddress(address)->IsCode() == is_codespace); |
| 748 | #endif |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 752 | // This macro is always used with a constant argument so it should all fold |
| 753 | // away to almost nothing in the generated code. It might be nicer to do this |
| 754 | // with the ternary operator but there are type issues with that. |
| 755 | #define ASSIGN_DEST_SPACE(space_number) \ |
| 756 | Space* dest_space; \ |
| 757 | if (space_number == NEW_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 758 | dest_space = isolate->heap()->new_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 759 | } else if (space_number == OLD_POINTER_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 760 | dest_space = isolate->heap()->old_pointer_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 761 | } else if (space_number == OLD_DATA_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 762 | dest_space = isolate->heap()->old_data_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 763 | } else if (space_number == CODE_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 764 | dest_space = isolate->heap()->code_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 765 | } else if (space_number == MAP_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 766 | dest_space = isolate->heap()->map_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 767 | } else if (space_number == CELL_SPACE) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 768 | dest_space = isolate->heap()->cell_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 769 | } else { \ |
| 770 | ASSERT(space_number >= LO_SPACE); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 771 | dest_space = isolate->heap()->lo_space(); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | |
| 775 | static const int kUnknownOffsetFromStart = -1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 776 | |
| 777 | |
| 778 | void Deserializer::ReadChunk(Object** current, |
| 779 | Object** limit, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 780 | int source_space, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 781 | Address address) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 782 | Isolate* const isolate = isolate_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 783 | while (current < limit) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 784 | int data = source_->Get(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 785 | switch (data) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 786 | #define CASE_STATEMENT(where, how, within, space_number) \ |
| 787 | case where + how + within + space_number: \ |
| 788 | ASSERT((where & ~kPointedToMask) == 0); \ |
| 789 | ASSERT((how & ~kHowToCodeMask) == 0); \ |
| 790 | ASSERT((within & ~kWhereToPointMask) == 0); \ |
| 791 | ASSERT((space_number & ~kSpaceMask) == 0); |
| 792 | |
| 793 | #define CASE_BODY(where, how, within, space_number_if_any, offset_from_start) \ |
| 794 | { \ |
| 795 | bool emit_write_barrier = false; \ |
| 796 | bool current_was_incremented = false; \ |
| 797 | int space_number = space_number_if_any == kAnyOldSpace ? \ |
| 798 | (data & kSpaceMask) : space_number_if_any; \ |
| 799 | if (where == kNewObject && how == kPlain && within == kStartOfObject) {\ |
| 800 | ASSIGN_DEST_SPACE(space_number) \ |
| 801 | ReadObject(space_number, dest_space, current); \ |
| 802 | emit_write_barrier = \ |
| 803 | (space_number == NEW_SPACE && source_space != NEW_SPACE); \ |
| 804 | } else { \ |
| 805 | Object* new_object = NULL; /* May not be a real Object pointer. */ \ |
| 806 | if (where == kNewObject) { \ |
| 807 | ASSIGN_DEST_SPACE(space_number) \ |
| 808 | ReadObject(space_number, dest_space, &new_object); \ |
| 809 | } else if (where == kRootArray) { \ |
| 810 | int root_id = source_->GetInt(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 811 | new_object = isolate->heap()->roots_address()[root_id]; \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 812 | } else if (where == kPartialSnapshotCache) { \ |
| 813 | int cache_index = source_->GetInt(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 814 | new_object = isolate->serialize_partial_snapshot_cache() \ |
| 815 | [cache_index]; \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 816 | } else if (where == kExternalReference) { \ |
| 817 | int reference_id = source_->GetInt(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 818 | Address address = external_reference_decoder_-> \ |
| 819 | Decode(reference_id); \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 820 | new_object = reinterpret_cast<Object*>(address); \ |
| 821 | } else if (where == kBackref) { \ |
| 822 | emit_write_barrier = \ |
| 823 | (space_number == NEW_SPACE && source_space != NEW_SPACE); \ |
| 824 | new_object = GetAddressFromEnd(data & kSpaceMask); \ |
| 825 | } else { \ |
| 826 | ASSERT(where == kFromStart); \ |
| 827 | if (offset_from_start == kUnknownOffsetFromStart) { \ |
| 828 | emit_write_barrier = \ |
| 829 | (space_number == NEW_SPACE && source_space != NEW_SPACE); \ |
| 830 | new_object = GetAddressFromStart(data & kSpaceMask); \ |
| 831 | } else { \ |
| 832 | Address object_address = pages_[space_number][0] + \ |
| 833 | (offset_from_start << kObjectAlignmentBits); \ |
| 834 | new_object = HeapObject::FromAddress(object_address); \ |
| 835 | } \ |
| 836 | } \ |
| 837 | if (within == kFirstInstruction) { \ |
| 838 | Code* new_code_object = reinterpret_cast<Code*>(new_object); \ |
| 839 | new_object = reinterpret_cast<Object*>( \ |
| 840 | new_code_object->instruction_start()); \ |
| 841 | } \ |
| 842 | if (how == kFromCode) { \ |
| 843 | Address location_of_branch_data = \ |
| 844 | reinterpret_cast<Address>(current); \ |
| 845 | Assembler::set_target_at(location_of_branch_data, \ |
| 846 | reinterpret_cast<Address>(new_object)); \ |
| 847 | if (within == kFirstInstruction) { \ |
| 848 | location_of_branch_data += Assembler::kCallTargetSize; \ |
| 849 | current = reinterpret_cast<Object**>(location_of_branch_data); \ |
| 850 | current_was_incremented = true; \ |
| 851 | } \ |
| 852 | } else { \ |
| 853 | *current = new_object; \ |
| 854 | } \ |
| 855 | } \ |
| 856 | if (emit_write_barrier) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 857 | isolate->heap()->RecordWrite(address, static_cast<int>( \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 858 | reinterpret_cast<Address>(current) - address)); \ |
| 859 | } \ |
| 860 | if (!current_was_incremented) { \ |
| 861 | current++; /* Increment current if it wasn't done above. */ \ |
| 862 | } \ |
| 863 | break; \ |
| 864 | } \ |
| 865 | |
| 866 | // This generates a case and a body for each space. The large object spaces are |
| 867 | // very rare in snapshots so they are grouped in one body. |
| 868 | #define ONE_PER_SPACE(where, how, within) \ |
| 869 | CASE_STATEMENT(where, how, within, NEW_SPACE) \ |
| 870 | CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \ |
| 871 | CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \ |
| 872 | CASE_BODY(where, how, within, OLD_DATA_SPACE, kUnknownOffsetFromStart) \ |
| 873 | CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \ |
| 874 | CASE_BODY(where, how, within, OLD_POINTER_SPACE, kUnknownOffsetFromStart) \ |
| 875 | CASE_STATEMENT(where, how, within, CODE_SPACE) \ |
| 876 | CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \ |
| 877 | CASE_STATEMENT(where, how, within, CELL_SPACE) \ |
| 878 | CASE_BODY(where, how, within, CELL_SPACE, kUnknownOffsetFromStart) \ |
| 879 | CASE_STATEMENT(where, how, within, MAP_SPACE) \ |
| 880 | CASE_BODY(where, how, within, MAP_SPACE, kUnknownOffsetFromStart) \ |
| 881 | CASE_STATEMENT(where, how, within, kLargeData) \ |
| 882 | CASE_STATEMENT(where, how, within, kLargeCode) \ |
| 883 | CASE_STATEMENT(where, how, within, kLargeFixedArray) \ |
| 884 | CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart) |
| 885 | |
| 886 | // This generates a case and a body for the new space (which has to do extra |
| 887 | // write barrier handling) and handles the other spaces with 8 fall-through |
| 888 | // cases and one body. |
| 889 | #define ALL_SPACES(where, how, within) \ |
| 890 | CASE_STATEMENT(where, how, within, NEW_SPACE) \ |
| 891 | CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \ |
| 892 | CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \ |
| 893 | CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \ |
| 894 | CASE_STATEMENT(where, how, within, CODE_SPACE) \ |
| 895 | CASE_STATEMENT(where, how, within, CELL_SPACE) \ |
| 896 | CASE_STATEMENT(where, how, within, MAP_SPACE) \ |
| 897 | CASE_STATEMENT(where, how, within, kLargeData) \ |
| 898 | CASE_STATEMENT(where, how, within, kLargeCode) \ |
| 899 | CASE_STATEMENT(where, how, within, kLargeFixedArray) \ |
| 900 | CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart) |
| 901 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 902 | #define ONE_PER_CODE_SPACE(where, how, within) \ |
| 903 | CASE_STATEMENT(where, how, within, CODE_SPACE) \ |
| 904 | CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \ |
| 905 | CASE_STATEMENT(where, how, within, kLargeCode) \ |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 906 | CASE_BODY(where, how, within, kLargeCode, kUnknownOffsetFromStart) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 907 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 908 | #define EMIT_COMMON_REFERENCE_PATTERNS(pseudo_space_number, \ |
| 909 | space_number, \ |
| 910 | offset_from_start) \ |
| 911 | CASE_STATEMENT(kFromStart, kPlain, kStartOfObject, pseudo_space_number) \ |
| 912 | CASE_BODY(kFromStart, kPlain, kStartOfObject, space_number, offset_from_start) |
| 913 | |
| 914 | // We generate 15 cases and bodies that process special tags that combine |
| 915 | // the raw data tag and the length into one byte. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 916 | #define RAW_CASE(index, size) \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 917 | case kRawData + index: { \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 918 | byte* raw_data_out = reinterpret_cast<byte*>(current); \ |
| 919 | source_->CopyRaw(raw_data_out, size); \ |
| 920 | current = reinterpret_cast<Object**>(raw_data_out + size); \ |
| 921 | break; \ |
| 922 | } |
| 923 | COMMON_RAW_LENGTHS(RAW_CASE) |
| 924 | #undef RAW_CASE |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 925 | |
| 926 | // Deserialize a chunk of raw data that doesn't have one of the popular |
| 927 | // lengths. |
| 928 | case kRawData: { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 929 | int size = source_->GetInt(); |
| 930 | byte* raw_data_out = reinterpret_cast<byte*>(current); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 931 | source_->CopyRaw(raw_data_out, size); |
| 932 | current = reinterpret_cast<Object**>(raw_data_out + size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 933 | break; |
| 934 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 935 | |
| 936 | // Deserialize a new object and write a pointer to it to the current |
| 937 | // object. |
| 938 | ONE_PER_SPACE(kNewObject, kPlain, kStartOfObject) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 939 | // Support for direct instruction pointers in functions |
| 940 | ONE_PER_CODE_SPACE(kNewObject, kPlain, kFirstInstruction) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 941 | // Deserialize a new code object and write a pointer to its first |
| 942 | // instruction to the current code object. |
| 943 | ONE_PER_SPACE(kNewObject, kFromCode, kFirstInstruction) |
| 944 | // Find a recently deserialized object using its offset from the current |
| 945 | // allocation point and write a pointer to it to the current object. |
| 946 | ALL_SPACES(kBackref, kPlain, kStartOfObject) |
| 947 | // Find a recently deserialized code object using its offset from the |
| 948 | // 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] | 949 | // to the current code object or the instruction pointer in a function |
| 950 | // object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 951 | ALL_SPACES(kBackref, kFromCode, kFirstInstruction) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 952 | ALL_SPACES(kBackref, kPlain, kFirstInstruction) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 953 | // Find an already deserialized object using its offset from the start |
| 954 | // and write a pointer to it to the current object. |
| 955 | ALL_SPACES(kFromStart, kPlain, kStartOfObject) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 956 | ALL_SPACES(kFromStart, kPlain, kFirstInstruction) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 957 | // Find an already deserialized code object using its offset from the |
| 958 | // start and write a pointer to its first instruction to the current code |
| 959 | // object. |
| 960 | ALL_SPACES(kFromStart, kFromCode, kFirstInstruction) |
| 961 | // Find an already deserialized object at one of the predetermined popular |
| 962 | // offsets from the start and write a pointer to it in the current object. |
| 963 | COMMON_REFERENCE_PATTERNS(EMIT_COMMON_REFERENCE_PATTERNS) |
| 964 | // Find an object in the roots array and write a pointer to it to the |
| 965 | // current object. |
| 966 | CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0) |
| 967 | CASE_BODY(kRootArray, kPlain, kStartOfObject, 0, kUnknownOffsetFromStart) |
| 968 | // Find an object in the partial snapshots cache and write a pointer to it |
| 969 | // to the current object. |
| 970 | CASE_STATEMENT(kPartialSnapshotCache, kPlain, kStartOfObject, 0) |
| 971 | CASE_BODY(kPartialSnapshotCache, |
| 972 | kPlain, |
| 973 | kStartOfObject, |
| 974 | 0, |
| 975 | kUnknownOffsetFromStart) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 976 | // Find an code entry in the partial snapshots cache and |
| 977 | // write a pointer to it to the current object. |
| 978 | CASE_STATEMENT(kPartialSnapshotCache, kPlain, kFirstInstruction, 0) |
| 979 | CASE_BODY(kPartialSnapshotCache, |
| 980 | kPlain, |
| 981 | kFirstInstruction, |
| 982 | 0, |
| 983 | kUnknownOffsetFromStart) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 984 | // Find an external reference and write a pointer to it to the current |
| 985 | // object. |
| 986 | CASE_STATEMENT(kExternalReference, kPlain, kStartOfObject, 0) |
| 987 | CASE_BODY(kExternalReference, |
| 988 | kPlain, |
| 989 | kStartOfObject, |
| 990 | 0, |
| 991 | kUnknownOffsetFromStart) |
| 992 | // Find an external reference and write a pointer to it in the current |
| 993 | // code object. |
| 994 | CASE_STATEMENT(kExternalReference, kFromCode, kStartOfObject, 0) |
| 995 | CASE_BODY(kExternalReference, |
| 996 | kFromCode, |
| 997 | kStartOfObject, |
| 998 | 0, |
| 999 | kUnknownOffsetFromStart) |
| 1000 | |
| 1001 | #undef CASE_STATEMENT |
| 1002 | #undef CASE_BODY |
| 1003 | #undef ONE_PER_SPACE |
| 1004 | #undef ALL_SPACES |
| 1005 | #undef EMIT_COMMON_REFERENCE_PATTERNS |
| 1006 | #undef ASSIGN_DEST_SPACE |
| 1007 | |
| 1008 | case kNewPage: { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1009 | int space = source_->Get(); |
| 1010 | pages_[space].Add(last_object_address_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1011 | if (space == CODE_SPACE) { |
| 1012 | CPU::FlushICache(last_object_address_, Page::kPageSize); |
| 1013 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1016 | |
| 1017 | case kNativesStringResource: { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1018 | int index = source_->Get(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1019 | Vector<const char> source_vector = Natives::GetRawScriptSource(index); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1020 | NativesExternalStringResource* resource = |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1021 | new NativesExternalStringResource(isolate->bootstrapper(), |
| 1022 | source_vector.start(), |
| 1023 | source_vector.length()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1024 | *current++ = reinterpret_cast<Object*>(resource); |
| 1025 | break; |
| 1026 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1027 | |
| 1028 | case kSynchronize: { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1029 | // If we get here then that indicates that you have a mismatch between |
| 1030 | // the number of GC roots when serializing and deserializing. |
| 1031 | UNREACHABLE(); |
| 1032 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1033 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1034 | default: |
| 1035 | UNREACHABLE(); |
| 1036 | } |
| 1037 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1038 | ASSERT_EQ(current, limit); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) { |
| 1043 | const int max_shift = ((kPointerSize * kBitsPerByte) / 7) * 7; |
| 1044 | for (int shift = max_shift; shift > 0; shift -= 7) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1045 | if (integer >= static_cast<uintptr_t>(1u) << shift) { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1046 | Put((static_cast<int>((integer >> shift)) & 0x7f) | 0x80, "IntPart"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1049 | PutSection(static_cast<int>(integer & 0x7f), "IntLastPart"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | #ifdef DEBUG |
| 1053 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1054 | void Deserializer::Synchronize(const char* tag) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1055 | int data = source_->Get(); |
| 1056 | // If this assert fails then that indicates that you have a mismatch between |
| 1057 | // the number of GC roots when serializing and deserializing. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1058 | ASSERT_EQ(kSynchronize, data); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1059 | do { |
| 1060 | int character = source_->Get(); |
| 1061 | if (character == 0) break; |
| 1062 | if (FLAG_debug_serialization) { |
| 1063 | PrintF("%c", character); |
| 1064 | } |
| 1065 | } while (true); |
| 1066 | if (FLAG_debug_serialization) { |
| 1067 | PrintF("\n"); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1072 | void Serializer::Synchronize(const char* tag) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1073 | sink_->Put(kSynchronize, tag); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1074 | int character; |
| 1075 | do { |
| 1076 | character = *tag++; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1077 | sink_->PutSection(character, "TagCharacter"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1078 | } while (character != 0); |
| 1079 | } |
| 1080 | |
| 1081 | #endif |
| 1082 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1083 | Serializer::Serializer(SnapshotByteSink* sink) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1084 | : sink_(sink), |
| 1085 | current_root_index_(0), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1086 | external_reference_encoder_(new ExternalReferenceEncoder), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1087 | large_object_total_(0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1088 | // The serializer is meant to be used only to generate initial heap images |
| 1089 | // from a context in which there is only one isolate. |
| 1090 | ASSERT(Isolate::Current()->IsDefaultIsolate()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1091 | for (int i = 0; i <= LAST_SPACE; i++) { |
| 1092 | fullness_[i] = 0; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1097 | Serializer::~Serializer() { |
| 1098 | delete external_reference_encoder_; |
| 1099 | } |
| 1100 | |
| 1101 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1102 | void StartupSerializer::SerializeStrongReferences() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1103 | Isolate* isolate = Isolate::Current(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1104 | // No active threads. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1105 | CHECK_EQ(NULL, Isolate::Current()->thread_manager()->FirstThreadStateInUse()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1106 | // No active or weak handles. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1107 | CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); |
| 1108 | CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1109 | // We don't support serializing installed extensions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1110 | for (RegisteredExtension* ext = v8::RegisteredExtension::first_extension(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1111 | ext != NULL; |
| 1112 | ext = ext->next()) { |
| 1113 | CHECK_NE(v8::INSTALLED, ext->state()); |
| 1114 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1115 | HEAP->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1119 | void PartialSerializer::Serialize(Object** object) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1120 | this->VisitPointer(object); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1121 | Isolate* isolate = Isolate::Current(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1122 | |
| 1123 | // After we have done the partial serialization the partial snapshot cache |
| 1124 | // will contain some references needed to decode the partial snapshot. We |
| 1125 | // fill it up with undefineds so it has a predictable length so the |
| 1126 | // deserialization code doesn't need to know the length. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1127 | for (int index = isolate->serialize_partial_snapshot_cache_length(); |
| 1128 | index < Isolate::kPartialSnapshotCacheCapacity; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1129 | index++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1130 | isolate->serialize_partial_snapshot_cache()[index] = |
| 1131 | isolate->heap()->undefined_value(); |
| 1132 | startup_serializer_->VisitPointer( |
| 1133 | &isolate->serialize_partial_snapshot_cache()[index]); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1134 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1135 | isolate->set_serialize_partial_snapshot_cache_length( |
| 1136 | Isolate::kPartialSnapshotCacheCapacity); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1140 | void Serializer::VisitPointers(Object** start, Object** end) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1141 | for (Object** current = start; current < end; current++) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1142 | if ((*current)->IsSmi()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1143 | sink_->Put(kRawData, "RawData"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1144 | sink_->PutInt(kPointerSize, "length"); |
| 1145 | for (int i = 0; i < kPointerSize; i++) { |
| 1146 | sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte"); |
| 1147 | } |
| 1148 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1149 | SerializeObject(*current, kPlain, kStartOfObject); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1150 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1155 | // This ensures that the partial snapshot cache keeps things alive during GC and |
| 1156 | // tracks their movement. When it is called during serialization of the startup |
| 1157 | // snapshot the partial snapshot is empty, so nothing happens. When the partial |
| 1158 | // (context) snapshot is created, this array is populated with the pointers that |
| 1159 | // the partial snapshot will need. As that happens we emit serialized objects to |
| 1160 | // the startup snapshot that correspond to the elements of this cache array. On |
| 1161 | // deserialization we therefore need to visit the cache array. This fills it up |
| 1162 | // with pointers to deserialized objects. |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1163 | void SerializerDeserializer::Iterate(ObjectVisitor* visitor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1164 | Isolate* isolate = Isolate::Current(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1165 | visitor->VisitPointers( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1166 | isolate->serialize_partial_snapshot_cache(), |
| 1167 | &isolate->serialize_partial_snapshot_cache()[ |
| 1168 | isolate->serialize_partial_snapshot_cache_length()]); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | // When deserializing we need to set the size of the snapshot cache. This means |
| 1173 | // the root iteration code (above) will iterate over array elements, writing the |
| 1174 | // references to deserialized objects in them. |
| 1175 | void SerializerDeserializer::SetSnapshotCacheSize(int size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1176 | Isolate::Current()->set_serialize_partial_snapshot_cache_length(size); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1181 | Isolate* isolate = Isolate::Current(); |
| 1182 | |
| 1183 | for (int i = 0; |
| 1184 | i < isolate->serialize_partial_snapshot_cache_length(); |
| 1185 | i++) { |
| 1186 | Object* entry = isolate->serialize_partial_snapshot_cache()[i]; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1187 | if (entry == heap_object) return i; |
| 1188 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1189 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1190 | // We didn't find the object in the cache. So we add it to the cache and |
| 1191 | // then visit the pointer so that it becomes part of the startup snapshot |
| 1192 | // and we can refer to it from the partial snapshot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1193 | int length = isolate->serialize_partial_snapshot_cache_length(); |
| 1194 | CHECK(length < Isolate::kPartialSnapshotCacheCapacity); |
| 1195 | isolate->serialize_partial_snapshot_cache()[length] = heap_object; |
| 1196 | startup_serializer_->VisitPointer( |
| 1197 | &isolate->serialize_partial_snapshot_cache()[length]); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1198 | // We don't recurse from the startup snapshot generator into the partial |
| 1199 | // snapshot generator. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1200 | ASSERT(length == isolate->serialize_partial_snapshot_cache_length()); |
| 1201 | isolate->set_serialize_partial_snapshot_cache_length(length + 1); |
| 1202 | return length; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | int PartialSerializer::RootIndex(HeapObject* heap_object) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1207 | for (int i = 0; i < Heap::kRootListLength; i++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1208 | Object* root = HEAP->roots_address()[i]; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1209 | if (root == heap_object) return i; |
| 1210 | } |
| 1211 | return kInvalidRootIndex; |
| 1212 | } |
| 1213 | |
| 1214 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1215 | // Encode the location of an already deserialized object in order to write its |
| 1216 | // location into a later object. We can encode the location as an offset from |
| 1217 | // the start of the deserialized objects or as an offset backwards from the |
| 1218 | // current allocation pointer. |
| 1219 | void Serializer::SerializeReferenceToPreviousObject( |
| 1220 | int space, |
| 1221 | int address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1222 | HowToCode how_to_code, |
| 1223 | WhereToPoint where_to_point) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1224 | int offset = CurrentAllocationAddress(space) - address; |
| 1225 | bool from_start = true; |
| 1226 | if (SpaceIsPaged(space)) { |
| 1227 | // For paged space it is simple to encode back from current allocation if |
| 1228 | // the object is on the same page as the current allocation pointer. |
| 1229 | if ((CurrentAllocationAddress(space) >> kPageSizeBits) == |
| 1230 | (address >> kPageSizeBits)) { |
| 1231 | from_start = false; |
| 1232 | address = offset; |
| 1233 | } |
| 1234 | } else if (space == NEW_SPACE) { |
| 1235 | // For new space it is always simple to encode back from current allocation. |
| 1236 | if (offset < address) { |
| 1237 | from_start = false; |
| 1238 | address = offset; |
| 1239 | } |
| 1240 | } |
| 1241 | // If we are actually dealing with real offsets (and not a numbering of |
| 1242 | // all objects) then we should shift out the bits that are always 0. |
| 1243 | if (!SpaceIsLarge(space)) address >>= kObjectAlignmentBits; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1244 | if (from_start) { |
| 1245 | #define COMMON_REFS_CASE(pseudo_space, actual_space, offset) \ |
| 1246 | if (space == actual_space && address == offset && \ |
| 1247 | how_to_code == kPlain && where_to_point == kStartOfObject) { \ |
| 1248 | sink_->Put(kFromStart + how_to_code + where_to_point + \ |
| 1249 | pseudo_space, "RefSer"); \ |
| 1250 | } else /* NOLINT */ |
| 1251 | COMMON_REFERENCE_PATTERNS(COMMON_REFS_CASE) |
| 1252 | #undef COMMON_REFS_CASE |
| 1253 | { /* NOLINT */ |
| 1254 | sink_->Put(kFromStart + how_to_code + where_to_point + space, "RefSer"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1255 | sink_->PutInt(address, "address"); |
| 1256 | } |
| 1257 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1258 | sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer"); |
| 1259 | sink_->PutInt(address, "address"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | void StartupSerializer::SerializeObject( |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1265 | Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1266 | HowToCode how_to_code, |
| 1267 | WhereToPoint where_to_point) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1268 | CHECK(o->IsHeapObject()); |
| 1269 | HeapObject* heap_object = HeapObject::cast(o); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1270 | |
| 1271 | if (address_mapper_.IsMapped(heap_object)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1272 | int space = SpaceOfAlreadySerializedObject(heap_object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1273 | int address = address_mapper_.MappedTo(heap_object); |
| 1274 | SerializeReferenceToPreviousObject(space, |
| 1275 | address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1276 | how_to_code, |
| 1277 | where_to_point); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1278 | } else { |
| 1279 | // Object has not yet been serialized. Serialize it here. |
| 1280 | ObjectSerializer object_serializer(this, |
| 1281 | heap_object, |
| 1282 | sink_, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1283 | how_to_code, |
| 1284 | where_to_point); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1285 | object_serializer.Serialize(); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | void StartupSerializer::SerializeWeakReferences() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1291 | for (int i = Isolate::Current()->serialize_partial_snapshot_cache_length(); |
| 1292 | i < Isolate::kPartialSnapshotCacheCapacity; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1293 | i++) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1294 | sink_->Put(kRootArray + kPlain + kStartOfObject, "RootSerialization"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1295 | sink_->PutInt(Heap::kUndefinedValueRootIndex, "root_index"); |
| 1296 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1297 | HEAP->IterateWeakRoots(this, VISIT_ALL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | void PartialSerializer::SerializeObject( |
| 1302 | Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1303 | HowToCode how_to_code, |
| 1304 | WhereToPoint where_to_point) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1305 | CHECK(o->IsHeapObject()); |
| 1306 | HeapObject* heap_object = HeapObject::cast(o); |
| 1307 | |
| 1308 | int root_index; |
| 1309 | if ((root_index = RootIndex(heap_object)) != kInvalidRootIndex) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1310 | sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1311 | sink_->PutInt(root_index, "root_index"); |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | if (ShouldBeInThePartialSnapshotCache(heap_object)) { |
| 1316 | int cache_index = PartialSnapshotCacheIndex(heap_object); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1317 | sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point, |
| 1318 | "PartialSnapshotCache"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1319 | sink_->PutInt(cache_index, "partial_snapshot_cache_index"); |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | // Pointers from the partial snapshot to the objects in the startup snapshot |
| 1324 | // should go through the root array or through the partial snapshot cache. |
| 1325 | // If this is not the case you may have to add something to the root array. |
| 1326 | ASSERT(!startup_serializer_->address_mapper()->IsMapped(heap_object)); |
| 1327 | // All the symbols that the partial snapshot needs should be either in the |
| 1328 | // root table or in the partial snapshot cache. |
| 1329 | ASSERT(!heap_object->IsSymbol()); |
| 1330 | |
| 1331 | if (address_mapper_.IsMapped(heap_object)) { |
| 1332 | int space = SpaceOfAlreadySerializedObject(heap_object); |
| 1333 | int address = address_mapper_.MappedTo(heap_object); |
| 1334 | SerializeReferenceToPreviousObject(space, |
| 1335 | address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1336 | how_to_code, |
| 1337 | where_to_point); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1338 | } else { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1339 | // Object has not yet been serialized. Serialize it here. |
| 1340 | ObjectSerializer serializer(this, |
| 1341 | heap_object, |
| 1342 | sink_, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1343 | how_to_code, |
| 1344 | where_to_point); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1345 | serializer.Serialize(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1350 | void Serializer::ObjectSerializer::Serialize() { |
| 1351 | int space = Serializer::SpaceOfObject(object_); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1352 | int size = object_->Size(); |
| 1353 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1354 | sink_->Put(kNewObject + reference_representation_ + space, |
| 1355 | "ObjectSerialization"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1356 | sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); |
| 1357 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1358 | LOG(i::Isolate::Current(), |
| 1359 | SnapshotPositionEvent(object_->address(), sink_->Position())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1360 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1361 | // Mark this object as already serialized. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1362 | bool start_new_page; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1363 | int offset = serializer_->Allocate(space, size, &start_new_page); |
| 1364 | serializer_->address_mapper()->AddMapping(object_, offset); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1365 | if (start_new_page) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1366 | sink_->Put(kNewPage, "NewPage"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1367 | sink_->PutSection(space, "NewPageSpace"); |
| 1368 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1369 | |
| 1370 | // Serialize the map (first word of the object). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1371 | serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1372 | |
| 1373 | // Serialize the rest of the object. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1374 | CHECK_EQ(0, bytes_processed_so_far_); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1375 | bytes_processed_so_far_ = kPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1376 | object_->IterateBody(object_->map()->instance_type(), size, this); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1377 | OutputRawData(object_->address() + size); |
| 1378 | } |
| 1379 | |
| 1380 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1381 | void Serializer::ObjectSerializer::VisitPointers(Object** start, |
| 1382 | Object** end) { |
| 1383 | Object** current = start; |
| 1384 | while (current < end) { |
| 1385 | while (current < end && (*current)->IsSmi()) current++; |
| 1386 | if (current < end) OutputRawData(reinterpret_cast<Address>(current)); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1387 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1388 | while (current < end && !(*current)->IsSmi()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1389 | serializer_->SerializeObject(*current, kPlain, kStartOfObject); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1390 | bytes_processed_so_far_ += kPointerSize; |
| 1391 | current++; |
| 1392 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1393 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1397 | void Serializer::ObjectSerializer::VisitExternalReferences(Address* start, |
| 1398 | Address* end) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1399 | Address references_start = reinterpret_cast<Address>(start); |
| 1400 | OutputRawData(references_start); |
| 1401 | |
| 1402 | for (Address* current = start; current < end; current++) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1403 | sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1404 | int reference_id = serializer_->EncodeExternalReference(*current); |
| 1405 | sink_->PutInt(reference_id, "reference id"); |
| 1406 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1407 | bytes_processed_so_far_ += static_cast<int>((end - start) * kPointerSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1411 | void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) { |
| 1412 | Address target_start = rinfo->target_address_address(); |
| 1413 | OutputRawData(target_start); |
| 1414 | Address target = rinfo->target_address(); |
| 1415 | uint32_t encoding = serializer_->EncodeExternalReference(target); |
| 1416 | CHECK(target == NULL ? encoding == 0 : encoding != 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1417 | int representation; |
| 1418 | // Can't use a ternary operator because of gcc. |
| 1419 | if (rinfo->IsCodedSpecially()) { |
| 1420 | representation = kStartOfObject + kFromCode; |
| 1421 | } else { |
| 1422 | representation = kStartOfObject + kPlain; |
| 1423 | } |
| 1424 | sink_->Put(kExternalReference + representation, "ExternalReference"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1425 | sink_->PutInt(encoding, "reference id"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1426 | bytes_processed_so_far_ += rinfo->target_address_size(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) { |
| 1431 | CHECK(RelocInfo::IsCodeTarget(rinfo->rmode())); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1432 | Address target_start = rinfo->target_address_address(); |
| 1433 | OutputRawData(target_start); |
| 1434 | Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1435 | serializer_->SerializeObject(target, kFromCode, kFirstInstruction); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1436 | bytes_processed_so_far_ += rinfo->target_address_size(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1440 | void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) { |
| 1441 | Code* target = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); |
| 1442 | OutputRawData(entry_address); |
| 1443 | serializer_->SerializeObject(target, kPlain, kFirstInstruction); |
| 1444 | bytes_processed_so_far_ += kPointerSize; |
| 1445 | } |
| 1446 | |
| 1447 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1448 | void Serializer::ObjectSerializer::VisitGlobalPropertyCell(RelocInfo* rinfo) { |
| 1449 | // We shouldn't have any global property cell references in code |
| 1450 | // objects in the snapshot. |
| 1451 | UNREACHABLE(); |
| 1452 | } |
| 1453 | |
| 1454 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1455 | void Serializer::ObjectSerializer::VisitExternalAsciiString( |
| 1456 | v8::String::ExternalAsciiStringResource** resource_pointer) { |
| 1457 | Address references_start = reinterpret_cast<Address>(resource_pointer); |
| 1458 | OutputRawData(references_start); |
| 1459 | for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1460 | Object* source = HEAP->natives_source_cache()->get(i); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1461 | if (!source->IsUndefined()) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1462 | ExternalAsciiString* string = ExternalAsciiString::cast(source); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1463 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 1464 | Resource* resource = string->resource(); |
| 1465 | if (resource == *resource_pointer) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1466 | sink_->Put(kNativesStringResource, "NativesStringResource"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1467 | sink_->PutSection(i, "NativesStringResourceEnd"); |
| 1468 | bytes_processed_so_far_ += sizeof(resource); |
| 1469 | return; |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | // One of the strings in the natives cache should match the resource. We |
| 1474 | // can't serialize any other kinds of external strings. |
| 1475 | UNREACHABLE(); |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | void Serializer::ObjectSerializer::OutputRawData(Address up_to) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1480 | Address object_start = object_->address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1481 | int up_to_offset = static_cast<int>(up_to - object_start); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1482 | int skipped = up_to_offset - bytes_processed_so_far_; |
| 1483 | // This assert will fail if the reloc info gives us the target_address_address |
| 1484 | // locations in a non-ascending order. Luckily that doesn't happen. |
| 1485 | ASSERT(skipped >= 0); |
| 1486 | if (skipped != 0) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1487 | Address base = object_start + bytes_processed_so_far_; |
| 1488 | #define RAW_CASE(index, length) \ |
| 1489 | if (skipped == length) { \ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1490 | sink_->PutSection(kRawData + index, "RawDataFixed"); \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1491 | } else /* NOLINT */ |
| 1492 | COMMON_RAW_LENGTHS(RAW_CASE) |
| 1493 | #undef RAW_CASE |
| 1494 | { /* NOLINT */ |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1495 | sink_->Put(kRawData, "RawData"); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1496 | sink_->PutInt(skipped, "length"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1497 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1498 | for (int i = 0; i < skipped; i++) { |
| 1499 | unsigned int data = base[i]; |
| 1500 | sink_->PutSection(data, "Byte"); |
| 1501 | } |
| 1502 | bytes_processed_so_far_ += skipped; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1503 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1507 | int Serializer::SpaceOfObject(HeapObject* object) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1508 | for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) { |
| 1509 | AllocationSpace s = static_cast<AllocationSpace>(i); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1510 | if (HEAP->InSpace(object, s)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1511 | if (i == LO_SPACE) { |
| 1512 | if (object->IsCode()) { |
| 1513 | return kLargeCode; |
| 1514 | } else if (object->IsFixedArray()) { |
| 1515 | return kLargeFixedArray; |
| 1516 | } else { |
| 1517 | return kLargeData; |
| 1518 | } |
| 1519 | } |
| 1520 | return i; |
| 1521 | } |
| 1522 | } |
| 1523 | UNREACHABLE(); |
| 1524 | return 0; |
| 1525 | } |
| 1526 | |
| 1527 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1528 | int Serializer::SpaceOfAlreadySerializedObject(HeapObject* object) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1529 | for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) { |
| 1530 | AllocationSpace s = static_cast<AllocationSpace>(i); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1531 | if (HEAP->InSpace(object, s)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1532 | return i; |
| 1533 | } |
| 1534 | } |
| 1535 | UNREACHABLE(); |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1540 | int Serializer::Allocate(int space, int size, bool* new_page) { |
| 1541 | CHECK(space >= 0 && space < kNumberOfSpaces); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1542 | if (SpaceIsLarge(space)) { |
| 1543 | // In large object space we merely number the objects instead of trying to |
| 1544 | // determine some sort of address. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1545 | *new_page = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1546 | large_object_total_ += size; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1547 | return fullness_[LO_SPACE]++; |
| 1548 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1549 | *new_page = false; |
| 1550 | if (fullness_[space] == 0) { |
| 1551 | *new_page = true; |
| 1552 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1553 | if (SpaceIsPaged(space)) { |
| 1554 | // Paged spaces are a little special. We encode their addresses as if the |
| 1555 | // pages were all contiguous and each page were filled up in the range |
| 1556 | // 0 - Page::kObjectAreaSize. In practice the pages may not be contiguous |
| 1557 | // and allocation does not start at offset 0 in the page, but this scheme |
| 1558 | // means the deserializer can get the page number quickly by shifting the |
| 1559 | // serialized address. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1560 | CHECK(IsPowerOf2(Page::kPageSize)); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1561 | int used_in_this_page = (fullness_[space] & (Page::kPageSize - 1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1562 | CHECK(size <= Page::kObjectAreaSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1563 | if (used_in_this_page + size > Page::kObjectAreaSize) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1564 | *new_page = true; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1565 | fullness_[space] = RoundUp(fullness_[space], Page::kPageSize); |
| 1566 | } |
| 1567 | } |
| 1568 | int allocation_address = fullness_[space]; |
| 1569 | fullness_[space] = allocation_address + size; |
| 1570 | return allocation_address; |
| 1571 | } |
| 1572 | |
| 1573 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1574 | } } // namespace v8::internal |