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