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