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