2012-01-24 16:36:55 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "accessors.h"
|
|
|
|
#include "api.h"
|
2011-05-03 08:23:58 +00:00
|
|
|
#include "bootstrapper.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "execution.h"
|
|
|
|
#include "global-handles.h"
|
|
|
|
#include "ic-inl.h"
|
|
|
|
#include "natives.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "runtime.h"
|
|
|
|
#include "serialize.h"
|
|
|
|
#include "stub-cache.h"
|
|
|
|
#include "v8threads.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-11-25 12:55:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Coding of external references.
|
|
|
|
|
|
|
|
// The encoding of an external reference. The type is in the high word.
|
|
|
|
// The id is in the low word.
|
|
|
|
static uint32_t EncodeExternal(TypeCode type, uint16_t id) {
|
|
|
|
return static_cast<uint32_t>(type) << 16 | id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int* GetInternalPointer(StatsCounter* counter) {
|
|
|
|
// All counters refer to dummy_counter, if deserializing happens without
|
|
|
|
// setting up counters.
|
|
|
|
static int dummy_counter = 0;
|
|
|
|
return counter->Enabled() ? counter->GetInternalPointer() : &dummy_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 08:48:54 +00:00
|
|
|
ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) {
|
|
|
|
ExternalReferenceTable* external_reference_table =
|
|
|
|
isolate->external_reference_table();
|
|
|
|
if (external_reference_table == NULL) {
|
|
|
|
external_reference_table = new ExternalReferenceTable(isolate);
|
|
|
|
isolate->set_external_reference_table(external_reference_table);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
2011-08-17 08:48:54 +00:00
|
|
|
return external_reference_table;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-01-27 11:30:44 +00:00
|
|
|
void ExternalReferenceTable::AddFromId(TypeCode type,
|
|
|
|
uint16_t id,
|
2011-03-22 13:20:04 +00:00
|
|
|
const char* name,
|
|
|
|
Isolate* isolate) {
|
2009-01-27 11:30:44 +00:00
|
|
|
Address address;
|
|
|
|
switch (type) {
|
2009-06-09 09:26:53 +00:00
|
|
|
case C_BUILTIN: {
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference ref(static_cast<Builtins::CFunctionId>(id), isolate);
|
2009-06-09 09:26:53 +00:00
|
|
|
address = ref.address();
|
2009-01-27 11:30:44 +00:00
|
|
|
break;
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
|
|
|
case BUILTIN: {
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference ref(static_cast<Builtins::Name>(id), isolate);
|
2009-06-09 09:26:53 +00:00
|
|
|
address = ref.address();
|
2009-01-27 11:30:44 +00:00
|
|
|
break;
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
|
|
|
case RUNTIME_FUNCTION: {
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference ref(static_cast<Runtime::FunctionId>(id), isolate);
|
2009-06-09 09:26:53 +00:00
|
|
|
address = ref.address();
|
2009-01-27 11:30:44 +00:00
|
|
|
break;
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
|
|
|
case IC_UTILITY: {
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference ref(IC_Utility(static_cast<IC::UtilityId>(id)),
|
|
|
|
isolate);
|
2009-06-09 09:26:53 +00:00
|
|
|
address = ref.address();
|
2009-01-27 11:30:44 +00:00
|
|
|
break;
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
2009-01-27 11:30:44 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Add(address, type, id, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExternalReferenceTable::Add(Address address,
|
|
|
|
TypeCode type,
|
|
|
|
uint16_t id,
|
|
|
|
const char* name) {
|
2009-11-16 12:08:40 +00:00
|
|
|
ASSERT_NE(NULL, address);
|
2009-01-27 11:30:44 +00:00
|
|
|
ExternalReferenceEntry entry;
|
|
|
|
entry.address = address;
|
|
|
|
entry.code = EncodeExternal(type, id);
|
|
|
|
entry.name = name;
|
2009-11-16 12:08:40 +00:00
|
|
|
ASSERT_NE(0, entry.code);
|
2009-01-27 11:30:44 +00:00
|
|
|
refs_.Add(entry);
|
|
|
|
if (id > max_id_[type]) max_id_[type] = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void ExternalReferenceTable::PopulateTable(Isolate* isolate) {
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int type_code = 0; type_code < kTypeCodeCount; type_code++) {
|
|
|
|
max_id_[type_code] = 0;
|
|
|
|
}
|
|
|
|
|
2009-01-27 11:30:44 +00:00
|
|
|
// The following populates all of the different type of external references
|
|
|
|
// into the ExternalReferenceTable.
|
|
|
|
//
|
|
|
|
// NOTE: This function was originally 100k of code. It has since been
|
|
|
|
// rewritten to be mostly table driven, as the callback macro style tends to
|
|
|
|
// very easily cause code bloat. Please be careful in the future when adding
|
|
|
|
// new references.
|
|
|
|
|
|
|
|
struct RefTableEntry {
|
|
|
|
TypeCode type;
|
|
|
|
uint16_t id;
|
|
|
|
const char* name;
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-27 11:30:44 +00:00
|
|
|
static const RefTableEntry ref_table[] = {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Builtins
|
2010-01-15 12:25:24 +00:00
|
|
|
#define DEF_ENTRY_C(name, ignored) \
|
2009-01-27 11:30:44 +00:00
|
|
|
{ C_BUILTIN, \
|
|
|
|
Builtins::c_##name, \
|
|
|
|
"Builtins::" #name },
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
BUILTIN_LIST_C(DEF_ENTRY_C)
|
|
|
|
#undef DEF_ENTRY_C
|
|
|
|
|
2010-01-15 12:25:24 +00:00
|
|
|
#define DEF_ENTRY_C(name, ignored) \
|
2009-01-27 11:30:44 +00:00
|
|
|
{ BUILTIN, \
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::k##name, \
|
2009-01-27 11:30:44 +00:00
|
|
|
"Builtins::" #name },
|
2011-02-13 16:19:53 +00:00
|
|
|
#define DEF_ENTRY_A(name, kind, state, extra) DEF_ENTRY_C(name, ignored)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
BUILTIN_LIST_C(DEF_ENTRY_C)
|
|
|
|
BUILTIN_LIST_A(DEF_ENTRY_A)
|
2008-12-08 10:16:57 +00:00
|
|
|
BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A)
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef DEF_ENTRY_C
|
|
|
|
#undef DEF_ENTRY_A
|
|
|
|
|
|
|
|
// Runtime functions
|
2009-09-08 11:52:05 +00:00
|
|
|
#define RUNTIME_ENTRY(name, nargs, ressize) \
|
2009-01-27 11:30:44 +00:00
|
|
|
{ RUNTIME_FUNCTION, \
|
|
|
|
Runtime::k##name, \
|
|
|
|
"Runtime::" #name },
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
RUNTIME_FUNCTION_LIST(RUNTIME_ENTRY)
|
|
|
|
#undef RUNTIME_ENTRY
|
|
|
|
|
|
|
|
// IC utilities
|
|
|
|
#define IC_ENTRY(name) \
|
2009-01-27 11:30:44 +00:00
|
|
|
{ IC_UTILITY, \
|
|
|
|
IC::k##name, \
|
|
|
|
"IC::" #name },
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
IC_UTIL_LIST(IC_ENTRY)
|
|
|
|
#undef IC_ENTRY
|
2009-01-27 11:30:44 +00:00
|
|
|
}; // end of ref_table[].
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(ref_table); ++i) {
|
2011-03-22 13:20:04 +00:00
|
|
|
AddFromId(ref_table[i].type,
|
|
|
|
ref_table[i].id,
|
|
|
|
ref_table[i].name,
|
|
|
|
isolate);
|
2009-01-27 11:30:44 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-07-03 15:10:15 +00:00
|
|
|
// Debug addresses
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(Debug_Address(Debug::k_after_break_target_address).address(isolate),
|
2008-07-03 15:10:15 +00:00
|
|
|
DEBUG_ADDRESS,
|
|
|
|
Debug::k_after_break_target_address << kDebugIdShift,
|
|
|
|
"Debug::after_break_target_address()");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(Debug_Address(Debug::k_debug_break_slot_address).address(isolate),
|
2010-06-08 12:04:49 +00:00
|
|
|
DEBUG_ADDRESS,
|
|
|
|
Debug::k_debug_break_slot_address << kDebugIdShift,
|
|
|
|
"Debug::debug_break_slot_address()");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(Debug_Address(Debug::k_debug_break_return_address).address(isolate),
|
2008-07-03 15:10:15 +00:00
|
|
|
DEBUG_ADDRESS,
|
|
|
|
Debug::k_debug_break_return_address << kDebugIdShift,
|
|
|
|
"Debug::debug_break_return_address()");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(Debug_Address(Debug::k_restarter_frame_function_pointer).address(isolate),
|
2010-07-30 11:58:43 +00:00
|
|
|
DEBUG_ADDRESS,
|
|
|
|
Debug::k_restarter_frame_function_pointer << kDebugIdShift,
|
|
|
|
"Debug::restarter_frame_function_pointer_address()");
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Stat counters
|
2009-01-27 11:30:44 +00:00
|
|
|
struct StatsRefTableEntry {
|
2011-03-18 20:35:07 +00:00
|
|
|
StatsCounter* (Counters::*counter)();
|
2009-01-27 11:30:44 +00:00
|
|
|
uint16_t id;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
const StatsRefTableEntry stats_ref_table[] = {
|
2008-07-03 15:10:15 +00:00
|
|
|
#define COUNTER_ENTRY(name, caption) \
|
2011-03-18 20:35:07 +00:00
|
|
|
{ &Counters::name, \
|
2009-01-27 11:30:44 +00:00
|
|
|
Counters::k_##name, \
|
|
|
|
"Counters::" #name },
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
STATS_COUNTER_LIST_1(COUNTER_ENTRY)
|
|
|
|
STATS_COUNTER_LIST_2(COUNTER_ENTRY)
|
|
|
|
#undef COUNTER_ENTRY
|
2009-01-27 11:30:44 +00:00
|
|
|
}; // end of stats_ref_table[].
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Counters* counters = isolate->counters();
|
2009-01-27 11:30:44 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(stats_ref_table); ++i) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(reinterpret_cast<Address>(GetInternalPointer(
|
|
|
|
(counters->*(stats_ref_table[i].counter))())),
|
2009-01-27 11:30:44 +00:00
|
|
|
STATS_COUNTER,
|
|
|
|
stats_ref_table[i].id,
|
|
|
|
stats_ref_table[i].name);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Top addresses
|
2009-10-08 12:36:12 +00:00
|
|
|
|
|
|
|
const char* AddressNames[] = {
|
2011-09-08 16:29:57 +00:00
|
|
|
#define BUILD_NAME_LITERAL(CamelName, hacker_name) \
|
|
|
|
"Isolate::" #hacker_name "_address",
|
|
|
|
FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL)
|
2009-10-08 12:36:12 +00:00
|
|
|
NULL
|
|
|
|
#undef C
|
|
|
|
};
|
|
|
|
|
2011-09-08 16:29:57 +00:00
|
|
|
for (uint16_t i = 0; i < Isolate::kIsolateAddressCount; ++i) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(isolate->get_address_from_id((Isolate::AddressId)i),
|
|
|
|
TOP_ADDRESS, i, AddressNames[i]);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
#define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
|
|
|
|
Add((Address)&Accessors::name, \
|
|
|
|
ACCESSOR, \
|
|
|
|
Accessors::k##name, \
|
|
|
|
"Accessors::" #name);
|
|
|
|
|
|
|
|
ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
|
|
|
|
#undef ACCESSOR_DESCRIPTOR_DECLARATION
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
StubCache* stub_cache = isolate->stub_cache();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Stub cache tables
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(stub_cache->key_reference(StubCache::kPrimary).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
1,
|
|
|
|
"StubCache::primary_->key");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(stub_cache->value_reference(StubCache::kPrimary).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
2,
|
|
|
|
"StubCache::primary_->value");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(stub_cache->key_reference(StubCache::kSecondary).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
3,
|
|
|
|
"StubCache::secondary_->key");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(stub_cache->value_reference(StubCache::kSecondary).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
4,
|
|
|
|
"StubCache::secondary_->value");
|
|
|
|
|
|
|
|
// Runtime entries
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::perform_gc_function(isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
RUNTIME_ENTRY,
|
|
|
|
1,
|
|
|
|
"Runtime::PerformGC");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::fill_heap_number_with_random_function(
|
|
|
|
isolate).address(),
|
2009-06-15 08:04:47 +00:00
|
|
|
RUNTIME_ENTRY,
|
|
|
|
2,
|
2010-04-07 08:18:51 +00:00
|
|
|
"V8::FillHeapNumberWithRandom");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::random_uint32_function(isolate).address(),
|
2010-04-12 10:07:50 +00:00
|
|
|
RUNTIME_ENTRY,
|
|
|
|
3,
|
|
|
|
"V8::Random");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
|
2010-10-21 14:21:00 +00:00
|
|
|
RUNTIME_ENTRY,
|
2011-01-27 13:17:34 +00:00
|
|
|
4,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::DeleteExtensions");
|
2011-09-19 18:36:47 +00:00
|
|
|
Add(ExternalReference::
|
|
|
|
incremental_marking_record_write_function(isolate).address(),
|
|
|
|
RUNTIME_ENTRY,
|
|
|
|
5,
|
|
|
|
"IncrementalMarking::RecordWrite");
|
|
|
|
Add(ExternalReference::store_buffer_overflow_function(isolate).address(),
|
|
|
|
RUNTIME_ENTRY,
|
|
|
|
6,
|
|
|
|
"StoreBuffer::StoreBufferOverflow");
|
|
|
|
Add(ExternalReference::
|
|
|
|
incremental_evacuation_record_write_function(isolate).address(),
|
|
|
|
RUNTIME_ENTRY,
|
|
|
|
7,
|
|
|
|
"IncrementalMarking::RecordWrite");
|
|
|
|
|
|
|
|
|
2010-10-21 14:21:00 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Miscellaneous
|
2011-10-20 12:27:10 +00:00
|
|
|
Add(ExternalReference::roots_array_start(isolate).address(),
|
2009-08-17 14:31:49 +00:00
|
|
|
UNCLASSIFIED,
|
2009-08-18 00:12:26 +00:00
|
|
|
3,
|
2011-10-20 12:27:10 +00:00
|
|
|
"Heap::roots_array_start()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_stack_limit(isolate).address(),
|
2009-08-24 11:57:57 +00:00
|
|
|
UNCLASSIFIED,
|
|
|
|
4,
|
2009-02-12 09:29:02 +00:00
|
|
|
"StackGuard::address_of_jslimit()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_real_stack_limit(isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
UNCLASSIFIED,
|
2009-08-24 11:57:57 +00:00
|
|
|
5,
|
2009-11-05 13:59:40 +00:00
|
|
|
"StackGuard::address_of_real_jslimit()");
|
2010-07-15 10:31:30 +00:00
|
|
|
#ifndef V8_INTERPRETED_REGEXP
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(),
|
2009-11-05 13:59:40 +00:00
|
|
|
UNCLASSIFIED,
|
|
|
|
6,
|
2009-01-13 14:38:12 +00:00
|
|
|
"RegExpStack::limit_address()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_regexp_stack_memory_address(
|
|
|
|
isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
UNCLASSIFIED,
|
2009-11-05 13:59:40 +00:00
|
|
|
7,
|
2010-06-14 21:03:59 +00:00
|
|
|
"RegExpStack::memory_address()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(),
|
2010-06-14 21:03:59 +00:00
|
|
|
UNCLASSIFIED,
|
|
|
|
8,
|
|
|
|
"RegExpStack::memory_size()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::address_of_static_offsets_vector(isolate).address(),
|
2010-06-14 21:03:59 +00:00
|
|
|
UNCLASSIFIED,
|
|
|
|
9,
|
|
|
|
"OffsetsVector::static_offsets_vector");
|
2010-07-15 10:31:30 +00:00
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::new_space_start(isolate).address(),
|
2010-06-14 21:03:59 +00:00
|
|
|
UNCLASSIFIED,
|
|
|
|
10,
|
2008-07-03 15:10:15 +00:00
|
|
|
"Heap::NewSpaceStart()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::new_space_mask(isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
UNCLASSIFIED,
|
2010-06-14 21:03:59 +00:00
|
|
|
11,
|
2010-03-02 11:54:11 +00:00
|
|
|
"Heap::NewSpaceMask()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::heap_always_allocate_scope_depth(isolate).address(),
|
2010-03-02 11:54:11 +00:00
|
|
|
UNCLASSIFIED,
|
2010-06-14 21:03:59 +00:00
|
|
|
12,
|
2008-10-30 09:15:58 +00:00
|
|
|
"Heap::always_allocate_scope_depth()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::new_space_allocation_limit_address(isolate).address(),
|
2008-10-30 09:15:58 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
14,
|
2008-07-03 15:10:15 +00:00
|
|
|
"Heap::NewSpaceAllocationLimitAddress()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::new_space_allocation_top_address(isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
15,
|
2008-07-03 15:10:15 +00:00
|
|
|
"Heap::NewSpaceAllocationTopAddress()");
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::debug_break(isolate).address(),
|
2009-04-20 16:36:13 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
16,
|
2009-04-20 16:36:13 +00:00
|
|
|
"Debug::Break()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::debug_step_in_fp_address(isolate).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
17,
|
2008-07-03 15:10:15 +00:00
|
|
|
"Debug::step_in_fp_addr()");
|
2009-07-01 15:36:28 +00:00
|
|
|
#endif
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::double_fp_operation(Token::ADD, isolate).address(),
|
2009-04-16 09:30:23 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
18,
|
2009-04-16 09:30:23 +00:00
|
|
|
"add_two_doubles");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::double_fp_operation(Token::SUB, isolate).address(),
|
2009-04-16 09:30:23 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
19,
|
2009-04-16 09:30:23 +00:00
|
|
|
"sub_two_doubles");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::double_fp_operation(Token::MUL, isolate).address(),
|
2009-04-16 09:30:23 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
20,
|
2009-04-16 09:30:23 +00:00
|
|
|
"mul_two_doubles");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::double_fp_operation(Token::DIV, isolate).address(),
|
2009-06-29 13:52:13 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
21,
|
2009-07-03 12:44:31 +00:00
|
|
|
"div_two_doubles");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::double_fp_operation(Token::MOD, isolate).address(),
|
2009-07-03 12:44:31 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
22,
|
2009-07-03 12:44:31 +00:00
|
|
|
"mod_two_doubles");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::compare_doubles(isolate).address(),
|
2009-07-03 12:44:31 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
23,
|
2009-06-29 13:52:13 +00:00
|
|
|
"compare_doubles");
|
2010-04-19 19:30:11 +00:00
|
|
|
#ifndef V8_INTERPRETED_REGEXP
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(),
|
2009-08-31 12:40:37 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
24,
|
2009-08-31 12:40:37 +00:00
|
|
|
"NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::re_check_stack_guard_state(isolate).address(),
|
2009-08-31 12:40:37 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
25,
|
2009-08-31 12:40:37 +00:00
|
|
|
"RegExpMacroAssembler*::CheckStackGuardState()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::re_grow_stack(isolate).address(),
|
2009-08-31 12:40:37 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
26,
|
2009-08-31 12:40:37 +00:00
|
|
|
"NativeRegExpMacroAssembler::GrowStack()");
|
2010-01-18 09:49:50 +00:00
|
|
|
Add(ExternalReference::re_word_character_map().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
27,
|
2010-01-18 09:49:50 +00:00
|
|
|
"NativeRegExpMacroAssembler::word_character_map");
|
2010-04-19 19:30:11 +00:00
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
2009-12-10 15:10:50 +00:00
|
|
|
// Keyed lookup cache.
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::keyed_lookup_cache_keys(isolate).address(),
|
2009-12-10 15:10:50 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
28,
|
2009-12-10 15:10:50 +00:00
|
|
|
"KeyedLookupCache::keys()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::keyed_lookup_cache_field_offsets(isolate).address(),
|
2009-12-10 15:10:50 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
29,
|
2009-12-10 15:10:50 +00:00
|
|
|
"KeyedLookupCache::field_offsets()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::transcendental_cache_array_address(isolate).address(),
|
2010-02-23 10:29:02 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
30,
|
2010-02-23 10:29:02 +00:00
|
|
|
"TranscendentalCache::caches()");
|
2010-10-21 14:21:00 +00:00
|
|
|
Add(ExternalReference::handle_scope_next_address().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
31,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::next");
|
|
|
|
Add(ExternalReference::handle_scope_limit_address().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
32,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::limit");
|
|
|
|
Add(ExternalReference::handle_scope_level_address().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
33,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::level");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::new_deoptimizer_function(isolate).address(),
|
2010-12-07 11:31:57 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
34,
|
2010-12-07 11:31:57 +00:00
|
|
|
"Deoptimizer::New()");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::compute_output_frames_function(isolate).address(),
|
2010-12-07 11:31:57 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
35,
|
2010-12-07 11:31:57 +00:00
|
|
|
"Deoptimizer::ComputeOutputFrames()");
|
|
|
|
Add(ExternalReference::address_of_min_int().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
36,
|
2010-12-07 11:31:57 +00:00
|
|
|
"LDoubleConstant::min_int");
|
|
|
|
Add(ExternalReference::address_of_one_half().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
37,
|
2010-12-07 11:31:57 +00:00
|
|
|
"LDoubleConstant::one_half");
|
2011-03-18 20:35:07 +00:00
|
|
|
Add(ExternalReference::isolate_address().address(),
|
2011-03-18 18:49:56 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
38,
|
2011-03-18 20:35:07 +00:00
|
|
|
"isolate");
|
|
|
|
Add(ExternalReference::address_of_minus_zero().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
39,
|
2011-01-11 13:48:49 +00:00
|
|
|
"LDoubleConstant::minus_zero");
|
|
|
|
Add(ExternalReference::address_of_negative_infinity().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
40,
|
2010-12-08 14:32:40 +00:00
|
|
|
"LDoubleConstant::negative_infinity");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::power_double_double_function(isolate).address(),
|
2010-12-08 14:32:40 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
41,
|
2010-12-08 14:32:40 +00:00
|
|
|
"power_double_double_function");
|
2011-03-22 13:20:04 +00:00
|
|
|
Add(ExternalReference::power_double_int_function(isolate).address(),
|
2010-12-08 14:32:40 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
42,
|
2010-12-08 14:32:40 +00:00
|
|
|
"power_double_int_function");
|
2011-09-19 18:36:47 +00:00
|
|
|
Add(ExternalReference::store_buffer_top(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
43,
|
|
|
|
"store_buffer_top");
|
2011-09-27 16:15:29 +00:00
|
|
|
Add(ExternalReference::address_of_canonical_non_hole_nan().address(),
|
|
|
|
UNCLASSIFIED,
|
2011-10-04 09:07:50 +00:00
|
|
|
44,
|
2011-09-27 16:15:29 +00:00
|
|
|
"canonical_nan");
|
2011-10-20 12:36:45 +00:00
|
|
|
Add(ExternalReference::address_of_the_hole_nan().address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
45,
|
|
|
|
"the_hole_nan");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalReferenceEncoder::ExternalReferenceEncoder()
|
2011-03-18 20:35:07 +00:00
|
|
|
: encodings_(Match),
|
|
|
|
isolate_(Isolate::Current()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ExternalReferenceTable* external_references =
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReferenceTable::instance(isolate_);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < external_references->size(); ++i) {
|
|
|
|
Put(external_references->address(i), i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ExternalReferenceEncoder::Encode(Address key) const {
|
|
|
|
int index = IndexOf(key);
|
2010-07-30 11:58:43 +00:00
|
|
|
ASSERT(key == NULL || index >= 0);
|
2011-03-18 20:35:07 +00:00
|
|
|
return index >=0 ?
|
|
|
|
ExternalReferenceTable::instance(isolate_)->code(index) : 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* ExternalReferenceEncoder::NameOfAddress(Address key) const {
|
|
|
|
int index = IndexOf(key);
|
2011-03-18 20:35:07 +00:00
|
|
|
return index >= 0 ?
|
|
|
|
ExternalReferenceTable::instance(isolate_)->name(index) : NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ExternalReferenceEncoder::IndexOf(Address key) const {
|
|
|
|
if (key == NULL) return -1;
|
|
|
|
HashMap::Entry* entry =
|
2011-03-18 20:35:07 +00:00
|
|
|
const_cast<HashMap&>(encodings_).Lookup(key, Hash(key), false);
|
2009-05-07 11:50:09 +00:00
|
|
|
return entry == NULL
|
|
|
|
? -1
|
|
|
|
: static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExternalReferenceEncoder::Put(Address key, int index) {
|
|
|
|
HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true);
|
2010-03-17 14:53:16 +00:00
|
|
|
entry->value = reinterpret_cast<void*>(index);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalReferenceDecoder::ExternalReferenceDecoder()
|
2011-03-18 20:35:07 +00:00
|
|
|
: encodings_(NewArray<Address*>(kTypeCodeCount)),
|
|
|
|
isolate_(Isolate::Current()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ExternalReferenceTable* external_references =
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReferenceTable::instance(isolate_);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
|
|
|
|
int max = external_references->max_id(type) + 1;
|
|
|
|
encodings_[type] = NewArray<Address>(max + 1);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < external_references->size(); ++i) {
|
|
|
|
Put(external_references->code(i), external_references->address(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalReferenceDecoder::~ExternalReferenceDecoder() {
|
|
|
|
for (int type = kFirstTypeCode; type < kTypeCodeCount; ++type) {
|
|
|
|
DeleteArray(encodings_[type]);
|
|
|
|
}
|
|
|
|
DeleteArray(encodings_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 14:57:46 +00:00
|
|
|
bool Serializer::serialization_enabled_ = false;
|
2009-11-13 12:32:57 +00:00
|
|
|
bool Serializer::too_late_to_enable_now_ = false;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Deserializer::Deserializer(SnapshotByteSource* source)
|
|
|
|
: isolate_(NULL),
|
|
|
|
source_(source),
|
|
|
|
external_reference_decoder_(NULL) {
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This routine both allocates a new object, and also keeps
|
|
|
|
// track of where objects have been allocated so that we can
|
|
|
|
// fix back references when deserializing.
|
2009-11-16 12:08:40 +00:00
|
|
|
Address Deserializer::Allocate(int space_index, Space* space, int size) {
|
2009-11-03 21:00:43 +00:00
|
|
|
Address address;
|
|
|
|
if (!SpaceIsLarge(space_index)) {
|
|
|
|
ASSERT(!SpaceIsPaged(space_index) ||
|
|
|
|
size <= Page::kPageSize - Page::kObjectStartOffset);
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* maybe_new_allocation;
|
2009-11-03 21:00:43 +00:00
|
|
|
if (space_index == NEW_SPACE) {
|
2010-10-25 15:22:03 +00:00
|
|
|
maybe_new_allocation =
|
|
|
|
reinterpret_cast<NewSpace*>(space)->AllocateRaw(size);
|
2009-11-03 21:00:43 +00:00
|
|
|
} else {
|
2010-10-25 15:22:03 +00:00
|
|
|
maybe_new_allocation =
|
|
|
|
reinterpret_cast<PagedSpace*>(space)->AllocateRaw(size);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(!maybe_new_allocation->IsFailure());
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* new_allocation = maybe_new_allocation->ToObjectUnchecked();
|
2009-11-03 21:00:43 +00:00
|
|
|
HeapObject* new_object = HeapObject::cast(new_allocation);
|
|
|
|
address = new_object->address();
|
|
|
|
high_water_[space_index] = address + size;
|
|
|
|
} else {
|
|
|
|
ASSERT(SpaceIsLarge(space_index));
|
|
|
|
LargeObjectSpace* lo_space = reinterpret_cast<LargeObjectSpace*>(space);
|
2009-10-27 11:54:01 +00:00
|
|
|
Object* new_allocation;
|
2011-09-19 18:36:47 +00:00
|
|
|
if (space_index == kLargeData || space_index == kLargeFixedArray) {
|
2010-10-25 15:22:03 +00:00
|
|
|
new_allocation =
|
2011-09-19 18:36:47 +00:00
|
|
|
lo_space->AllocateRaw(size, NOT_EXECUTABLE)->ToObjectUnchecked();
|
2009-10-27 11:54:01 +00:00
|
|
|
} else {
|
2009-11-16 12:08:40 +00:00
|
|
|
ASSERT_EQ(kLargeCode, space_index);
|
2011-09-19 18:36:47 +00:00
|
|
|
new_allocation =
|
|
|
|
lo_space->AllocateRaw(size, EXECUTABLE)->ToObjectUnchecked();
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
HeapObject* new_object = HeapObject::cast(new_allocation);
|
|
|
|
// Record all large objects in the same space.
|
|
|
|
address = new_object->address();
|
2010-03-23 11:40:38 +00:00
|
|
|
pages_[LO_SPACE].Add(address);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
last_object_address_ = address;
|
2012-01-31 11:22:35 +00:00
|
|
|
ASSERT(address >= Page::FromAddress(address)->ObjectAreaStart());
|
2009-10-27 11:54:01 +00:00
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This returns the address of an object that has been described in the
|
|
|
|
// snapshot as being offset bytes back in a particular space.
|
2009-11-16 12:08:40 +00:00
|
|
|
HeapObject* Deserializer::GetAddressFromEnd(int space) {
|
2009-11-03 21:00:43 +00:00
|
|
|
int offset = source_->GetInt();
|
|
|
|
ASSERT(!SpaceIsLarge(space));
|
|
|
|
offset <<= kObjectAlignmentBits;
|
2012-01-31 11:22:35 +00:00
|
|
|
Address address = high_water_[space] - offset;
|
|
|
|
// This assert will fail if kMinimumSpaceSizes is too small for a space,
|
|
|
|
// because we rely on the fact that all allocation is linear when the VM
|
|
|
|
// is very young.
|
|
|
|
ASSERT(address >= Page::FromAddress(address)->ObjectAreaStart());
|
|
|
|
return HeapObject::FromAddress(address);
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This returns the address of an object that has been described in the
|
|
|
|
// snapshot as being offset bytes into a particular space.
|
2009-11-16 12:08:40 +00:00
|
|
|
HeapObject* Deserializer::GetAddressFromStart(int space) {
|
2009-10-27 11:54:01 +00:00
|
|
|
int offset = source_->GetInt();
|
|
|
|
if (SpaceIsLarge(space)) {
|
|
|
|
// Large spaces have one object per 'page'.
|
2009-11-03 21:00:43 +00:00
|
|
|
return HeapObject::FromAddress(pages_[LO_SPACE][offset]);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
offset <<= kObjectAlignmentBits;
|
|
|
|
if (space == NEW_SPACE) {
|
|
|
|
// New space has only one space - numbered 0.
|
2009-11-03 21:00:43 +00:00
|
|
|
return HeapObject::FromAddress(pages_[space][0] + offset);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
ASSERT(SpaceIsPaged(space));
|
2009-12-17 08:53:18 +00:00
|
|
|
int page_of_pointee = offset >> kPageSizeBits;
|
2009-10-27 11:54:01 +00:00
|
|
|
Address object_address = pages_[space][page_of_pointee] +
|
2009-11-03 21:00:43 +00:00
|
|
|
(offset & Page::kPageAlignmentMask);
|
2009-10-27 11:54:01 +00:00
|
|
|
return HeapObject::FromAddress(object_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Deserializer::Deserialize() {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_ = Isolate::Current();
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(isolate_ != NULL);
|
2009-10-27 11:54:01 +00:00
|
|
|
// Don't GC while deserializing - just expand the heap.
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
// Don't use the free lists while deserializing.
|
|
|
|
LinearAllocationScope allocate_linearly;
|
|
|
|
// No active threads.
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT_EQ(NULL, isolate_->thread_manager()->FirstThreadStateInUse());
|
2009-10-27 11:54:01 +00:00
|
|
|
// No active handles.
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(isolate_->handle_scope_implementer()->blocks()->is_empty());
|
2010-01-27 08:25:48 +00:00
|
|
|
// Make sure the entire partial snapshot cache is traversed, filling it with
|
|
|
|
// valid object pointers.
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_->set_serialize_partial_snapshot_cache_length(
|
|
|
|
Isolate::kPartialSnapshotCacheCapacity);
|
2009-11-16 12:08:40 +00:00
|
|
|
ASSERT_EQ(NULL, external_reference_decoder_);
|
2009-10-27 11:54:01 +00:00
|
|
|
external_reference_decoder_ = new ExternalReferenceDecoder();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
|
|
|
|
isolate_->heap()->IterateWeakRoots(this, VISIT_ALL);
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_->heap()->set_global_contexts_list(
|
|
|
|
isolate_->heap()->undefined_value());
|
2011-11-23 13:08:28 +00:00
|
|
|
|
|
|
|
// Update data pointers to the external strings containing natives sources.
|
|
|
|
for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
|
|
|
|
Object* source = isolate_->heap()->natives_source_cache()->get(i);
|
|
|
|
if (!source->IsUndefined()) {
|
|
|
|
ExternalAsciiString::cast(source)->update_data_cache();
|
|
|
|
}
|
|
|
|
}
|
2010-01-15 14:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deserializer::DeserializePartial(Object** root) {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_ = Isolate::Current();
|
2010-01-15 14:20:31 +00:00
|
|
|
// Don't GC while deserializing - just expand the heap.
|
|
|
|
AlwaysAllocateScope always_allocate;
|
|
|
|
// Don't use the free lists while deserializing.
|
|
|
|
LinearAllocationScope allocate_linearly;
|
|
|
|
if (external_reference_decoder_ == NULL) {
|
|
|
|
external_reference_decoder_ = new ExternalReferenceDecoder();
|
|
|
|
}
|
|
|
|
VisitPointer(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
Deserializer::~Deserializer() {
|
|
|
|
ASSERT(source_->AtEOF());
|
2011-03-18 20:35:07 +00:00
|
|
|
if (external_reference_decoder_) {
|
2010-01-15 14:20:31 +00:00
|
|
|
delete external_reference_decoder_;
|
|
|
|
external_reference_decoder_ = NULL;
|
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called on the roots. It is the driver of the deserialization
|
2009-11-03 21:00:43 +00:00
|
|
|
// process. It is also called on the body of each function.
|
2009-11-16 12:08:40 +00:00
|
|
|
void Deserializer::VisitPointers(Object** start, Object** end) {
|
2009-11-03 21:00:43 +00:00
|
|
|
// The space must be new space. Any other space would cause ReadChunk to try
|
|
|
|
// to update the remembered using NULL as the address.
|
|
|
|
ReadChunk(start, end, NEW_SPACE, NULL);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This routine writes the new object into the pointer provided and then
|
|
|
|
// returns true if the new object was in young space and false otherwise.
|
|
|
|
// The reason for this strange interface is that otherwise the object is
|
2011-09-19 18:36:47 +00:00
|
|
|
// written very late, which means the FreeSpace map is not set up by the
|
|
|
|
// time we need to use it to mark the space at the end of a page free.
|
2009-11-16 12:08:40 +00:00
|
|
|
void Deserializer::ReadObject(int space_number,
|
|
|
|
Space* space,
|
|
|
|
Object** write_back) {
|
2009-10-27 11:54:01 +00:00
|
|
|
int size = source_->GetInt() << kObjectAlignmentBits;
|
2009-11-03 21:00:43 +00:00
|
|
|
Address address = Allocate(space_number, space, size);
|
2009-10-27 11:54:01 +00:00
|
|
|
*write_back = HeapObject::FromAddress(address);
|
|
|
|
Object** current = reinterpret_cast<Object**>(address);
|
|
|
|
Object** limit = current + (size >> kPointerSizeLog2);
|
2010-01-18 16:04:25 +00:00
|
|
|
if (FLAG_log_snapshot_positions) {
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(isolate_, SnapshotPositionEvent(address, source_->position()));
|
2010-01-18 16:04:25 +00:00
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
ReadChunk(current, limit, space_number, address);
|
2011-03-17 08:16:27 +00:00
|
|
|
#ifdef DEBUG
|
2011-03-18 20:35:07 +00:00
|
|
|
bool is_codespace = (space == HEAP->code_space()) ||
|
|
|
|
((space == HEAP->lo_space()) && (space_number == kLargeCode));
|
2011-03-17 08:16:27 +00:00
|
|
|
ASSERT(HeapObject::FromAddress(address)->IsCode() == is_codespace);
|
|
|
|
#endif
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 13:54:31 +00:00
|
|
|
// This macro is always used with a constant argument so it should all fold
|
|
|
|
// away to almost nothing in the generated code. It might be nicer to do this
|
|
|
|
// with the ternary operator but there are type issues with that.
|
|
|
|
#define ASSIGN_DEST_SPACE(space_number) \
|
|
|
|
Space* dest_space; \
|
|
|
|
if (space_number == NEW_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->new_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (space_number == OLD_POINTER_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->old_pointer_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (space_number == OLD_DATA_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->old_data_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (space_number == CODE_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->code_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (space_number == MAP_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->map_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (space_number == CELL_SPACE) { \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->cell_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else { \
|
|
|
|
ASSERT(space_number >= LO_SPACE); \
|
2011-03-18 20:35:07 +00:00
|
|
|
dest_space = isolate->heap()->lo_space(); \
|
2010-05-20 13:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const int kUnknownOffsetFromStart = -1;
|
2009-11-03 21:00:43 +00:00
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Deserializer::ReadChunk(Object** current,
|
|
|
|
Object** limit,
|
2010-05-20 13:54:31 +00:00
|
|
|
int source_space,
|
2011-10-24 12:39:29 +00:00
|
|
|
Address current_object_address) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* const isolate = isolate_;
|
2011-10-25 08:24:06 +00:00
|
|
|
bool write_barrier_needed = (current_object_address != NULL &&
|
|
|
|
source_space != NEW_SPACE &&
|
|
|
|
source_space != CELL_SPACE &&
|
2011-10-25 08:59:03 +00:00
|
|
|
source_space != CODE_SPACE &&
|
2011-10-25 08:42:38 +00:00
|
|
|
source_space != OLD_DATA_SPACE);
|
2009-10-27 11:54:01 +00:00
|
|
|
while (current < limit) {
|
2009-11-03 21:00:43 +00:00
|
|
|
int data = source_->Get();
|
2009-10-27 11:54:01 +00:00
|
|
|
switch (data) {
|
2010-05-20 13:54:31 +00:00
|
|
|
#define CASE_STATEMENT(where, how, within, space_number) \
|
|
|
|
case where + how + within + space_number: \
|
|
|
|
ASSERT((where & ~kPointedToMask) == 0); \
|
|
|
|
ASSERT((how & ~kHowToCodeMask) == 0); \
|
2010-05-20 19:58:05 +00:00
|
|
|
ASSERT((within & ~kWhereToPointMask) == 0); \
|
2010-05-20 13:54:31 +00:00
|
|
|
ASSERT((space_number & ~kSpaceMask) == 0);
|
|
|
|
|
|
|
|
#define CASE_BODY(where, how, within, space_number_if_any, offset_from_start) \
|
|
|
|
{ \
|
|
|
|
bool emit_write_barrier = false; \
|
|
|
|
bool current_was_incremented = false; \
|
|
|
|
int space_number = space_number_if_any == kAnyOldSpace ? \
|
|
|
|
(data & kSpaceMask) : space_number_if_any; \
|
|
|
|
if (where == kNewObject && how == kPlain && within == kStartOfObject) {\
|
|
|
|
ASSIGN_DEST_SPACE(space_number) \
|
|
|
|
ReadObject(space_number, dest_space, current); \
|
2011-10-25 08:24:06 +00:00
|
|
|
emit_write_barrier = (space_number == NEW_SPACE); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else { \
|
|
|
|
Object* new_object = NULL; /* May not be a real Object pointer. */ \
|
|
|
|
if (where == kNewObject) { \
|
|
|
|
ASSIGN_DEST_SPACE(space_number) \
|
|
|
|
ReadObject(space_number, dest_space, &new_object); \
|
|
|
|
} else if (where == kRootArray) { \
|
|
|
|
int root_id = source_->GetInt(); \
|
2011-10-20 12:27:10 +00:00
|
|
|
new_object = isolate->heap()->roots_array_start()[root_id]; \
|
2011-10-25 11:02:29 +00:00
|
|
|
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (where == kPartialSnapshotCache) { \
|
|
|
|
int cache_index = source_->GetInt(); \
|
2011-03-18 20:35:07 +00:00
|
|
|
new_object = isolate->serialize_partial_snapshot_cache() \
|
|
|
|
[cache_index]; \
|
2011-10-25 11:02:29 +00:00
|
|
|
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} else if (where == kExternalReference) { \
|
|
|
|
int reference_id = source_->GetInt(); \
|
2011-03-18 20:35:07 +00:00
|
|
|
Address address = external_reference_decoder_-> \
|
|
|
|
Decode(reference_id); \
|
2010-05-20 13:54:31 +00:00
|
|
|
new_object = reinterpret_cast<Object*>(address); \
|
|
|
|
} else if (where == kBackref) { \
|
2011-10-25 08:24:06 +00:00
|
|
|
emit_write_barrier = (space_number == NEW_SPACE); \
|
2010-05-20 13:54:31 +00:00
|
|
|
new_object = GetAddressFromEnd(data & kSpaceMask); \
|
|
|
|
} else { \
|
|
|
|
ASSERT(where == kFromStart); \
|
|
|
|
if (offset_from_start == kUnknownOffsetFromStart) { \
|
2011-10-25 08:24:06 +00:00
|
|
|
emit_write_barrier = (space_number == NEW_SPACE); \
|
2010-05-20 13:54:31 +00:00
|
|
|
new_object = GetAddressFromStart(data & kSpaceMask); \
|
|
|
|
} else { \
|
|
|
|
Address object_address = pages_[space_number][0] + \
|
|
|
|
(offset_from_start << kObjectAlignmentBits); \
|
|
|
|
new_object = HeapObject::FromAddress(object_address); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
if (within == kFirstInstruction) { \
|
|
|
|
Code* new_code_object = reinterpret_cast<Code*>(new_object); \
|
|
|
|
new_object = reinterpret_cast<Object*>( \
|
|
|
|
new_code_object->instruction_start()); \
|
|
|
|
} \
|
|
|
|
if (how == kFromCode) { \
|
|
|
|
Address location_of_branch_data = \
|
|
|
|
reinterpret_cast<Address>(current); \
|
|
|
|
Assembler::set_target_at(location_of_branch_data, \
|
|
|
|
reinterpret_cast<Address>(new_object)); \
|
|
|
|
if (within == kFirstInstruction) { \
|
|
|
|
location_of_branch_data += Assembler::kCallTargetSize; \
|
|
|
|
current = reinterpret_cast<Object**>(location_of_branch_data); \
|
|
|
|
current_was_incremented = true; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
*current = new_object; \
|
|
|
|
} \
|
|
|
|
} \
|
2011-10-25 08:24:06 +00:00
|
|
|
if (emit_write_barrier && write_barrier_needed) { \
|
2011-10-24 12:39:29 +00:00
|
|
|
Address current_address = reinterpret_cast<Address>(current); \
|
|
|
|
isolate->heap()->RecordWrite( \
|
|
|
|
current_object_address, \
|
|
|
|
static_cast<int>(current_address - current_object_address)); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} \
|
|
|
|
if (!current_was_incremented) { \
|
2011-10-25 08:24:06 +00:00
|
|
|
current++; \
|
2010-05-20 13:54:31 +00:00
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
// This generates a case and a body for each space. The large object spaces are
|
|
|
|
// very rare in snapshots so they are grouped in one body.
|
|
|
|
#define ONE_PER_SPACE(where, how, within) \
|
|
|
|
CASE_STATEMENT(where, how, within, NEW_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, OLD_DATA_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, OLD_POINTER_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, CODE_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, CELL_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, CELL_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, MAP_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, MAP_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeData) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeCode) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeFixedArray) \
|
|
|
|
CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
|
|
|
|
|
|
|
|
// This generates a case and a body for the new space (which has to do extra
|
|
|
|
// write barrier handling) and handles the other spaces with 8 fall-through
|
|
|
|
// cases and one body.
|
|
|
|
#define ALL_SPACES(where, how, within) \
|
|
|
|
CASE_STATEMENT(where, how, within, NEW_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
|
|
|
|
CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
|
|
|
|
CASE_STATEMENT(where, how, within, CODE_SPACE) \
|
|
|
|
CASE_STATEMENT(where, how, within, CELL_SPACE) \
|
|
|
|
CASE_STATEMENT(where, how, within, MAP_SPACE) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeData) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeCode) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeFixedArray) \
|
|
|
|
CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
|
|
|
|
|
2010-08-20 07:10:18 +00:00
|
|
|
#define ONE_PER_CODE_SPACE(where, how, within) \
|
|
|
|
CASE_STATEMENT(where, how, within, CODE_SPACE) \
|
|
|
|
CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \
|
|
|
|
CASE_STATEMENT(where, how, within, kLargeCode) \
|
2011-03-17 08:16:27 +00:00
|
|
|
CASE_BODY(where, how, within, kLargeCode, kUnknownOffsetFromStart)
|
2010-08-20 07:10:18 +00:00
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
#define FOUR_CASES(byte_code) \
|
|
|
|
case byte_code: \
|
|
|
|
case byte_code + 1: \
|
|
|
|
case byte_code + 2: \
|
|
|
|
case byte_code + 3:
|
|
|
|
|
|
|
|
#define SIXTEEN_CASES(byte_code) \
|
|
|
|
FOUR_CASES(byte_code) \
|
|
|
|
FOUR_CASES(byte_code + 4) \
|
|
|
|
FOUR_CASES(byte_code + 8) \
|
|
|
|
FOUR_CASES(byte_code + 12)
|
2010-05-20 13:54:31 +00:00
|
|
|
|
|
|
|
// We generate 15 cases and bodies that process special tags that combine
|
|
|
|
// the raw data tag and the length into one byte.
|
2009-11-03 21:00:43 +00:00
|
|
|
#define RAW_CASE(index, size) \
|
2010-05-20 13:54:31 +00:00
|
|
|
case kRawData + index: { \
|
2009-11-03 21:00:43 +00:00
|
|
|
byte* raw_data_out = reinterpret_cast<byte*>(current); \
|
|
|
|
source_->CopyRaw(raw_data_out, size); \
|
|
|
|
current = reinterpret_cast<Object**>(raw_data_out + size); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
COMMON_RAW_LENGTHS(RAW_CASE)
|
|
|
|
#undef RAW_CASE
|
2010-05-20 13:54:31 +00:00
|
|
|
|
|
|
|
// Deserialize a chunk of raw data that doesn't have one of the popular
|
|
|
|
// lengths.
|
|
|
|
case kRawData: {
|
2009-10-27 11:54:01 +00:00
|
|
|
int size = source_->GetInt();
|
|
|
|
byte* raw_data_out = reinterpret_cast<byte*>(current);
|
2009-10-30 10:23:12 +00:00
|
|
|
source_->CopyRaw(raw_data_out, size);
|
|
|
|
current = reinterpret_cast<Object**>(raw_data_out + size);
|
2009-10-27 11:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-20 13:54:31 +00:00
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
SIXTEEN_CASES(kRootArrayLowConstants)
|
|
|
|
SIXTEEN_CASES(kRootArrayHighConstants) {
|
|
|
|
int root_id = RootArrayConstantFromByteCode(data);
|
2011-10-21 15:20:53 +00:00
|
|
|
Object* object = isolate->heap()->roots_array_start()[root_id];
|
|
|
|
ASSERT(!isolate->heap()->InNewSpace(object));
|
|
|
|
*current++ = object;
|
2011-10-20 12:27:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kRepeat: {
|
|
|
|
int repeats = source_->GetInt();
|
|
|
|
Object* object = current[-1];
|
2011-10-21 15:20:53 +00:00
|
|
|
ASSERT(!isolate->heap()->InNewSpace(object));
|
2011-10-20 12:27:10 +00:00
|
|
|
for (int i = 0; i < repeats; i++) current[i] = object;
|
|
|
|
current += repeats;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-21 15:20:53 +00:00
|
|
|
STATIC_ASSERT(kRootArrayNumberOfConstantEncodings ==
|
|
|
|
Heap::kOldSpaceRoots);
|
2011-10-20 12:27:10 +00:00
|
|
|
STATIC_ASSERT(kMaxRepeats == 12);
|
|
|
|
FOUR_CASES(kConstantRepeat)
|
|
|
|
FOUR_CASES(kConstantRepeat + 4)
|
|
|
|
FOUR_CASES(kConstantRepeat + 8) {
|
|
|
|
int repeats = RepeatsForCode(data);
|
|
|
|
Object* object = current[-1];
|
2011-10-21 15:20:53 +00:00
|
|
|
ASSERT(!isolate->heap()->InNewSpace(object));
|
2011-10-20 12:27:10 +00:00
|
|
|
for (int i = 0; i < repeats; i++) current[i] = object;
|
|
|
|
current += repeats;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-20 13:54:31 +00:00
|
|
|
// Deserialize a new object and write a pointer to it to the current
|
|
|
|
// object.
|
|
|
|
ONE_PER_SPACE(kNewObject, kPlain, kStartOfObject)
|
2010-08-20 07:10:18 +00:00
|
|
|
// Support for direct instruction pointers in functions
|
|
|
|
ONE_PER_CODE_SPACE(kNewObject, kPlain, kFirstInstruction)
|
2010-05-20 13:54:31 +00:00
|
|
|
// Deserialize a new code object and write a pointer to its first
|
|
|
|
// instruction to the current code object.
|
|
|
|
ONE_PER_SPACE(kNewObject, kFromCode, kFirstInstruction)
|
|
|
|
// Find a recently deserialized object using its offset from the current
|
|
|
|
// allocation point and write a pointer to it to the current object.
|
|
|
|
ALL_SPACES(kBackref, kPlain, kStartOfObject)
|
|
|
|
// Find a recently deserialized code object using its offset from the
|
|
|
|
// current allocation point and write a pointer to its first instruction
|
2010-08-20 07:10:18 +00:00
|
|
|
// to the current code object or the instruction pointer in a function
|
|
|
|
// object.
|
2010-05-20 13:54:31 +00:00
|
|
|
ALL_SPACES(kBackref, kFromCode, kFirstInstruction)
|
2010-08-20 07:10:18 +00:00
|
|
|
ALL_SPACES(kBackref, kPlain, kFirstInstruction)
|
2010-05-20 13:54:31 +00:00
|
|
|
// Find an already deserialized object using its offset from the start
|
|
|
|
// and write a pointer to it to the current object.
|
|
|
|
ALL_SPACES(kFromStart, kPlain, kStartOfObject)
|
2010-08-20 07:10:18 +00:00
|
|
|
ALL_SPACES(kFromStart, kPlain, kFirstInstruction)
|
2010-05-20 13:54:31 +00:00
|
|
|
// Find an already deserialized code object using its offset from the
|
|
|
|
// start and write a pointer to its first instruction to the current code
|
|
|
|
// object.
|
|
|
|
ALL_SPACES(kFromStart, kFromCode, kFirstInstruction)
|
|
|
|
// Find an object in the roots array and write a pointer to it to the
|
|
|
|
// current object.
|
|
|
|
CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0)
|
|
|
|
CASE_BODY(kRootArray, kPlain, kStartOfObject, 0, kUnknownOffsetFromStart)
|
|
|
|
// Find an object in the partial snapshots cache and write a pointer to it
|
|
|
|
// to the current object.
|
|
|
|
CASE_STATEMENT(kPartialSnapshotCache, kPlain, kStartOfObject, 0)
|
|
|
|
CASE_BODY(kPartialSnapshotCache,
|
|
|
|
kPlain,
|
|
|
|
kStartOfObject,
|
|
|
|
0,
|
|
|
|
kUnknownOffsetFromStart)
|
2010-08-20 07:10:18 +00:00
|
|
|
// Find an code entry in the partial snapshots cache and
|
|
|
|
// write a pointer to it to the current object.
|
|
|
|
CASE_STATEMENT(kPartialSnapshotCache, kPlain, kFirstInstruction, 0)
|
|
|
|
CASE_BODY(kPartialSnapshotCache,
|
|
|
|
kPlain,
|
|
|
|
kFirstInstruction,
|
|
|
|
0,
|
|
|
|
kUnknownOffsetFromStart)
|
2010-05-20 13:54:31 +00:00
|
|
|
// Find an external reference and write a pointer to it to the current
|
|
|
|
// object.
|
|
|
|
CASE_STATEMENT(kExternalReference, kPlain, kStartOfObject, 0)
|
|
|
|
CASE_BODY(kExternalReference,
|
|
|
|
kPlain,
|
|
|
|
kStartOfObject,
|
|
|
|
0,
|
|
|
|
kUnknownOffsetFromStart)
|
|
|
|
// Find an external reference and write a pointer to it in the current
|
|
|
|
// code object.
|
|
|
|
CASE_STATEMENT(kExternalReference, kFromCode, kStartOfObject, 0)
|
|
|
|
CASE_BODY(kExternalReference,
|
|
|
|
kFromCode,
|
|
|
|
kStartOfObject,
|
|
|
|
0,
|
|
|
|
kUnknownOffsetFromStart)
|
|
|
|
|
|
|
|
#undef CASE_STATEMENT
|
|
|
|
#undef CASE_BODY
|
|
|
|
#undef ONE_PER_SPACE
|
|
|
|
#undef ALL_SPACES
|
|
|
|
#undef ASSIGN_DEST_SPACE
|
|
|
|
|
|
|
|
case kNewPage: {
|
2009-11-03 21:00:43 +00:00
|
|
|
int space = source_->Get();
|
|
|
|
pages_[space].Add(last_object_address_);
|
2010-04-22 12:41:10 +00:00
|
|
|
if (space == CODE_SPACE) {
|
|
|
|
CPU::FlushICache(last_object_address_, Page::kPageSize);
|
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-20 13:54:31 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
case kSkip: {
|
|
|
|
current++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-20 13:54:31 +00:00
|
|
|
case kNativesStringResource: {
|
2009-11-06 13:48:33 +00:00
|
|
|
int index = source_->Get();
|
2011-06-06 20:47:30 +00:00
|
|
|
Vector<const char> source_vector = Natives::GetRawScriptSource(index);
|
2009-11-06 13:48:33 +00:00
|
|
|
NativesExternalStringResource* resource =
|
2011-06-06 20:47:30 +00:00
|
|
|
new NativesExternalStringResource(isolate->bootstrapper(),
|
|
|
|
source_vector.start(),
|
|
|
|
source_vector.length());
|
2009-11-06 13:48:33 +00:00
|
|
|
*current++ = reinterpret_cast<Object*>(resource);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-20 13:54:31 +00:00
|
|
|
|
|
|
|
case kSynchronize: {
|
2010-01-27 08:25:48 +00:00
|
|
|
// If we get here then that indicates that you have a mismatch between
|
|
|
|
// the number of GC roots when serializing and deserializing.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2010-05-20 13:54:31 +00:00
|
|
|
|
2009-10-27 11:54:01 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
2009-11-16 12:08:40 +00:00
|
|
|
ASSERT_EQ(current, limit);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
|
|
|
|
const int max_shift = ((kPointerSize * kBitsPerByte) / 7) * 7;
|
|
|
|
for (int shift = max_shift; shift > 0; shift -= 7) {
|
2009-11-11 09:50:06 +00:00
|
|
|
if (integer >= static_cast<uintptr_t>(1u) << shift) {
|
2010-02-22 11:42:46 +00:00
|
|
|
Put((static_cast<int>((integer >> shift)) & 0x7f) | 0x80, "IntPart");
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-22 11:42:46 +00:00
|
|
|
PutSection(static_cast<int>(integer & 0x7f), "IntLastPart");
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
Serializer::Serializer(SnapshotByteSink* sink)
|
2009-10-27 11:54:01 +00:00
|
|
|
: sink_(sink),
|
|
|
|
current_root_index_(0),
|
2010-03-23 11:40:38 +00:00
|
|
|
external_reference_encoder_(new ExternalReferenceEncoder),
|
2011-10-20 12:27:10 +00:00
|
|
|
large_object_total_(0),
|
|
|
|
root_index_wave_front_(0) {
|
2011-03-18 20:35:07 +00:00
|
|
|
// The serializer is meant to be used only to generate initial heap images
|
|
|
|
// from a context in which there is only one isolate.
|
|
|
|
ASSERT(Isolate::Current()->IsDefaultIsolate());
|
2009-10-27 11:54:01 +00:00
|
|
|
for (int i = 0; i <= LAST_SPACE; i++) {
|
|
|
|
fullness_[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
Serializer::~Serializer() {
|
|
|
|
delete external_reference_encoder_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
void StartupSerializer::SerializeStrongReferences() {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2009-10-27 11:54:01 +00:00
|
|
|
// No active threads.
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK_EQ(NULL, Isolate::Current()->thread_manager()->FirstThreadStateInUse());
|
2009-10-27 11:54:01 +00:00
|
|
|
// No active or weak handles.
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());
|
|
|
|
CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles());
|
2009-11-16 12:08:40 +00:00
|
|
|
// We don't support serializing installed extensions.
|
2011-11-15 22:48:55 +00:00
|
|
|
CHECK(!isolate->has_installed_extensions());
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
HEAP->IterateStrongRoots(this, VISIT_ONLY_STRONG);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
void PartialSerializer::Serialize(Object** object) {
|
2010-01-12 15:16:23 +00:00
|
|
|
this->VisitPointer(object);
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2010-01-27 08:25:48 +00:00
|
|
|
|
|
|
|
// After we have done the partial serialization the partial snapshot cache
|
|
|
|
// will contain some references needed to decode the partial snapshot. We
|
|
|
|
// fill it up with undefineds so it has a predictable length so the
|
|
|
|
// deserialization code doesn't need to know the length.
|
2011-03-18 20:35:07 +00:00
|
|
|
for (int index = isolate->serialize_partial_snapshot_cache_length();
|
|
|
|
index < Isolate::kPartialSnapshotCacheCapacity;
|
2010-01-27 08:25:48 +00:00
|
|
|
index++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->serialize_partial_snapshot_cache()[index] =
|
|
|
|
isolate->heap()->undefined_value();
|
|
|
|
startup_serializer_->VisitPointer(
|
|
|
|
&isolate->serialize_partial_snapshot_cache()[index]);
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->set_serialize_partial_snapshot_cache_length(
|
|
|
|
Isolate::kPartialSnapshotCacheCapacity);
|
2010-01-12 15:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::VisitPointers(Object** start, Object** end) {
|
2011-09-19 18:36:47 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
|
2009-10-27 11:54:01 +00:00
|
|
|
for (Object** current = start; current < end; current++) {
|
2011-10-20 12:27:10 +00:00
|
|
|
if (start == isolate->heap()->roots_array_start()) {
|
2011-10-20 13:47:14 +00:00
|
|
|
root_index_wave_front_ =
|
|
|
|
Max(root_index_wave_front_, static_cast<intptr_t>(current - start));
|
2011-10-20 12:27:10 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
if (reinterpret_cast<Address>(current) ==
|
|
|
|
isolate->heap()->store_buffer()->TopAddress()) {
|
|
|
|
sink_->Put(kSkip, "Skip");
|
|
|
|
} else if ((*current)->IsSmi()) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kRawData, "RawData");
|
2009-11-03 21:00:43 +00:00
|
|
|
sink_->PutInt(kPointerSize, "length");
|
|
|
|
for (int i = 0; i < kPointerSize; i++) {
|
|
|
|
sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-20 13:54:31 +00:00
|
|
|
SerializeObject(*current, kPlain, kStartOfObject);
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
// This ensures that the partial snapshot cache keeps things alive during GC and
|
|
|
|
// tracks their movement. When it is called during serialization of the startup
|
|
|
|
// snapshot the partial snapshot is empty, so nothing happens. When the partial
|
|
|
|
// (context) snapshot is created, this array is populated with the pointers that
|
|
|
|
// the partial snapshot will need. As that happens we emit serialized objects to
|
|
|
|
// the startup snapshot that correspond to the elements of this cache array. On
|
|
|
|
// deserialization we therefore need to visit the cache array. This fills it up
|
|
|
|
// with pointers to deserialized objects.
|
2010-03-17 14:53:16 +00:00
|
|
|
void SerializerDeserializer::Iterate(ObjectVisitor* visitor) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2010-01-27 08:25:48 +00:00
|
|
|
visitor->VisitPointers(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->serialize_partial_snapshot_cache(),
|
|
|
|
&isolate->serialize_partial_snapshot_cache()[
|
|
|
|
isolate->serialize_partial_snapshot_cache_length()]);
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// When deserializing we need to set the size of the snapshot cache. This means
|
|
|
|
// the root iteration code (above) will iterate over array elements, writing the
|
|
|
|
// references to deserialized objects in them.
|
|
|
|
void SerializerDeserializer::SetSnapshotCacheSize(int size) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->set_serialize_partial_snapshot_cache_length(size);
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
|
|
|
|
for (int i = 0;
|
|
|
|
i < isolate->serialize_partial_snapshot_cache_length();
|
|
|
|
i++) {
|
|
|
|
Object* entry = isolate->serialize_partial_snapshot_cache()[i];
|
2010-01-27 08:25:48 +00:00
|
|
|
if (entry == heap_object) return i;
|
|
|
|
}
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
// We didn't find the object in the cache. So we add it to the cache and
|
|
|
|
// then visit the pointer so that it becomes part of the startup snapshot
|
|
|
|
// and we can refer to it from the partial snapshot.
|
2011-03-18 20:35:07 +00:00
|
|
|
int length = isolate->serialize_partial_snapshot_cache_length();
|
|
|
|
CHECK(length < Isolate::kPartialSnapshotCacheCapacity);
|
|
|
|
isolate->serialize_partial_snapshot_cache()[length] = heap_object;
|
|
|
|
startup_serializer_->VisitPointer(
|
|
|
|
&isolate->serialize_partial_snapshot_cache()[length]);
|
2010-01-27 08:25:48 +00:00
|
|
|
// We don't recurse from the startup snapshot generator into the partial
|
|
|
|
// snapshot generator.
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(length == isolate->serialize_partial_snapshot_cache_length());
|
|
|
|
isolate->set_serialize_partial_snapshot_cache_length(length + 1);
|
|
|
|
return length;
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
int Serializer::RootIndex(HeapObject* heap_object) {
|
|
|
|
Heap* heap = HEAP;
|
|
|
|
if (heap->InNewSpace(heap_object)) return kInvalidRootIndex;
|
|
|
|
for (int i = 0; i < root_index_wave_front_; i++) {
|
|
|
|
Object* root = heap->roots_array_start()[i];
|
|
|
|
if (!root->IsSmi() && root == heap_object) return i;
|
2010-01-12 15:16:23 +00:00
|
|
|
}
|
|
|
|
return kInvalidRootIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
// Encode the location of an already deserialized object in order to write its
|
|
|
|
// location into a later object. We can encode the location as an offset from
|
|
|
|
// the start of the deserialized objects or as an offset backwards from the
|
|
|
|
// current allocation pointer.
|
|
|
|
void Serializer::SerializeReferenceToPreviousObject(
|
|
|
|
int space,
|
|
|
|
int address,
|
2010-05-20 13:54:31 +00:00
|
|
|
HowToCode how_to_code,
|
|
|
|
WhereToPoint where_to_point) {
|
2010-01-27 08:25:48 +00:00
|
|
|
int offset = CurrentAllocationAddress(space) - address;
|
|
|
|
bool from_start = true;
|
|
|
|
if (SpaceIsPaged(space)) {
|
|
|
|
// For paged space it is simple to encode back from current allocation if
|
|
|
|
// the object is on the same page as the current allocation pointer.
|
|
|
|
if ((CurrentAllocationAddress(space) >> kPageSizeBits) ==
|
|
|
|
(address >> kPageSizeBits)) {
|
|
|
|
from_start = false;
|
|
|
|
address = offset;
|
2010-01-12 15:16:23 +00:00
|
|
|
}
|
2010-01-27 08:25:48 +00:00
|
|
|
} else if (space == NEW_SPACE) {
|
|
|
|
// For new space it is always simple to encode back from current allocation.
|
|
|
|
if (offset < address) {
|
|
|
|
from_start = false;
|
|
|
|
address = offset;
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
// If we are actually dealing with real offsets (and not a numbering of
|
|
|
|
// all objects) then we should shift out the bits that are always 0.
|
|
|
|
if (!SpaceIsLarge(space)) address >>= kObjectAlignmentBits;
|
2010-05-20 13:54:31 +00:00
|
|
|
if (from_start) {
|
2011-10-20 12:27:10 +00:00
|
|
|
sink_->Put(kFromStart + how_to_code + where_to_point + space, "RefSer");
|
|
|
|
sink_->PutInt(address, "address");
|
2010-05-20 13:54:31 +00:00
|
|
|
} else {
|
|
|
|
sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer");
|
|
|
|
sink_->PutInt(address, "address");
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StartupSerializer::SerializeObject(
|
|
|
|
Object* o,
|
2010-05-20 13:54:31 +00:00
|
|
|
HowToCode how_to_code,
|
|
|
|
WhereToPoint where_to_point) {
|
2010-01-27 08:25:48 +00:00
|
|
|
CHECK(o->IsHeapObject());
|
|
|
|
HeapObject* heap_object = HeapObject::cast(o);
|
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
int root_index;
|
|
|
|
if ((root_index = RootIndex(heap_object)) != kInvalidRootIndex) {
|
|
|
|
PutRoot(root_index, heap_object, how_to_code, where_to_point);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
if (address_mapper_.IsMapped(heap_object)) {
|
|
|
|
int space = SpaceOfAlreadySerializedObject(heap_object);
|
|
|
|
int address = address_mapper_.MappedTo(heap_object);
|
|
|
|
SerializeReferenceToPreviousObject(space,
|
|
|
|
address,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
|
|
|
where_to_point);
|
2010-01-27 08:25:48 +00:00
|
|
|
} else {
|
|
|
|
// Object has not yet been serialized. Serialize it here.
|
|
|
|
ObjectSerializer object_serializer(this,
|
|
|
|
heap_object,
|
|
|
|
sink_,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
|
|
|
where_to_point);
|
2010-01-27 08:25:48 +00:00
|
|
|
object_serializer.Serialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StartupSerializer::SerializeWeakReferences() {
|
2011-03-18 20:35:07 +00:00
|
|
|
for (int i = Isolate::Current()->serialize_partial_snapshot_cache_length();
|
|
|
|
i < Isolate::kPartialSnapshotCacheCapacity;
|
2010-01-27 08:25:48 +00:00
|
|
|
i++) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kRootArray + kPlain + kStartOfObject, "RootSerialization");
|
2010-01-27 08:25:48 +00:00
|
|
|
sink_->PutInt(Heap::kUndefinedValueRootIndex, "root_index");
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
HEAP->IterateWeakRoots(this, VISIT_ALL);
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
void Serializer::PutRoot(int root_index,
|
|
|
|
HeapObject* object,
|
|
|
|
SerializerDeserializer::HowToCode how_to_code,
|
|
|
|
SerializerDeserializer::WhereToPoint where_to_point) {
|
|
|
|
if (how_to_code == kPlain &&
|
|
|
|
where_to_point == kStartOfObject &&
|
|
|
|
root_index < kRootArrayNumberOfConstantEncodings &&
|
|
|
|
!HEAP->InNewSpace(object)) {
|
|
|
|
if (root_index < kRootArrayNumberOfLowConstantEncodings) {
|
|
|
|
sink_->Put(kRootArrayLowConstants + root_index, "RootLoConstant");
|
|
|
|
} else {
|
|
|
|
sink_->Put(kRootArrayHighConstants + root_index -
|
|
|
|
kRootArrayNumberOfLowConstantEncodings,
|
|
|
|
"RootHiConstant");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
|
|
|
|
sink_->PutInt(root_index, "root_index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
void PartialSerializer::SerializeObject(
|
|
|
|
Object* o,
|
2010-05-20 13:54:31 +00:00
|
|
|
HowToCode how_to_code,
|
|
|
|
WhereToPoint where_to_point) {
|
2010-01-27 08:25:48 +00:00
|
|
|
CHECK(o->IsHeapObject());
|
|
|
|
HeapObject* heap_object = HeapObject::cast(o);
|
|
|
|
|
2012-01-19 13:51:45 +00:00
|
|
|
if (heap_object->IsMap()) {
|
|
|
|
// The code-caches link to context-specific code objects, which
|
|
|
|
// the startup and context serializes cannot currently handle.
|
|
|
|
ASSERT(Map::cast(heap_object)->code_cache() ==
|
|
|
|
heap_object->GetHeap()->raw_unchecked_empty_fixed_array());
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
int root_index;
|
|
|
|
if ((root_index = RootIndex(heap_object)) != kInvalidRootIndex) {
|
2011-10-20 12:27:10 +00:00
|
|
|
PutRoot(root_index, heap_object, how_to_code, where_to_point);
|
2010-01-27 08:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldBeInThePartialSnapshotCache(heap_object)) {
|
|
|
|
int cache_index = PartialSnapshotCacheIndex(heap_object);
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point,
|
|
|
|
"PartialSnapshotCache");
|
2010-01-27 08:25:48 +00:00
|
|
|
sink_->PutInt(cache_index, "partial_snapshot_cache_index");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pointers from the partial snapshot to the objects in the startup snapshot
|
|
|
|
// should go through the root array or through the partial snapshot cache.
|
|
|
|
// If this is not the case you may have to add something to the root array.
|
|
|
|
ASSERT(!startup_serializer_->address_mapper()->IsMapped(heap_object));
|
|
|
|
// All the symbols that the partial snapshot needs should be either in the
|
|
|
|
// root table or in the partial snapshot cache.
|
|
|
|
ASSERT(!heap_object->IsSymbol());
|
|
|
|
|
|
|
|
if (address_mapper_.IsMapped(heap_object)) {
|
|
|
|
int space = SpaceOfAlreadySerializedObject(heap_object);
|
|
|
|
int address = address_mapper_.MappedTo(heap_object);
|
|
|
|
SerializeReferenceToPreviousObject(space,
|
|
|
|
address,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
|
|
|
where_to_point);
|
2009-10-27 11:54:01 +00:00
|
|
|
} else {
|
2009-11-03 21:00:43 +00:00
|
|
|
// Object has not yet been serialized. Serialize it here.
|
|
|
|
ObjectSerializer serializer(this,
|
|
|
|
heap_object,
|
|
|
|
sink_,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
|
|
|
where_to_point);
|
2009-11-03 21:00:43 +00:00
|
|
|
serializer.Serialize();
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::Serialize() {
|
|
|
|
int space = Serializer::SpaceOfObject(object_);
|
2009-10-27 11:54:01 +00:00
|
|
|
int size = object_->Size();
|
|
|
|
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kNewObject + reference_representation_ + space,
|
|
|
|
"ObjectSerialization");
|
2009-10-27 11:54:01 +00:00
|
|
|
sink_->PutInt(size >> kObjectAlignmentBits, "Size in words");
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(i::Isolate::Current(),
|
|
|
|
SnapshotPositionEvent(object_->address(), sink_->Position()));
|
2010-01-18 16:04:25 +00:00
|
|
|
|
2009-10-27 11:54:01 +00:00
|
|
|
// Mark this object as already serialized.
|
2009-11-03 21:00:43 +00:00
|
|
|
bool start_new_page;
|
2010-01-27 08:25:48 +00:00
|
|
|
int offset = serializer_->Allocate(space, size, &start_new_page);
|
|
|
|
serializer_->address_mapper()->AddMapping(object_, offset);
|
2009-11-03 21:00:43 +00:00
|
|
|
if (start_new_page) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kNewPage, "NewPage");
|
2009-11-03 21:00:43 +00:00
|
|
|
sink_->PutSection(space, "NewPageSpace");
|
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
|
|
|
|
// Serialize the map (first word of the object).
|
2010-05-20 13:54:31 +00:00
|
|
|
serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject);
|
2009-10-27 11:54:01 +00:00
|
|
|
|
|
|
|
// Serialize the rest of the object.
|
2009-11-16 12:08:40 +00:00
|
|
|
CHECK_EQ(0, bytes_processed_so_far_);
|
2009-10-27 11:54:01 +00:00
|
|
|
bytes_processed_so_far_ = kPointerSize;
|
2009-11-25 12:55:33 +00:00
|
|
|
object_->IterateBody(object_->map()->instance_type(), size, this);
|
2009-10-27 11:54:01 +00:00
|
|
|
OutputRawData(object_->address() + size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitPointers(Object** start,
|
|
|
|
Object** end) {
|
2009-11-03 21:00:43 +00:00
|
|
|
Object** current = start;
|
|
|
|
while (current < end) {
|
|
|
|
while (current < end && (*current)->IsSmi()) current++;
|
2009-11-06 13:48:33 +00:00
|
|
|
if (current < end) OutputRawData(reinterpret_cast<Address>(current));
|
2009-11-03 21:00:43 +00:00
|
|
|
|
|
|
|
while (current < end && !(*current)->IsSmi()) {
|
2011-10-21 15:20:53 +00:00
|
|
|
HeapObject* current_contents = HeapObject::cast(*current);
|
|
|
|
int root_index = serializer_->RootIndex(current_contents);
|
|
|
|
// Repeats are not subject to the write barrier so there are only some
|
|
|
|
// objects that can be used in a repeat encoding. These are the early
|
|
|
|
// ones in the root array that are never in new space.
|
2011-10-20 12:27:10 +00:00
|
|
|
if (current != start &&
|
2011-10-21 15:20:53 +00:00
|
|
|
root_index != kInvalidRootIndex &&
|
|
|
|
root_index < kRootArrayNumberOfConstantEncodings &&
|
|
|
|
current_contents == current[-1]) {
|
|
|
|
ASSERT(!HEAP->InNewSpace(current_contents));
|
2011-10-20 12:27:10 +00:00
|
|
|
int repeat_count = 1;
|
2011-10-21 15:20:53 +00:00
|
|
|
while (current < end - 1 && current[repeat_count] == current_contents) {
|
2011-10-20 12:27:10 +00:00
|
|
|
repeat_count++;
|
|
|
|
}
|
|
|
|
current += repeat_count;
|
|
|
|
bytes_processed_so_far_ += repeat_count * kPointerSize;
|
|
|
|
if (repeat_count > kMaxRepeats) {
|
|
|
|
sink_->Put(kRepeat, "SerializeRepeats");
|
|
|
|
sink_->PutInt(repeat_count, "SerializeRepeats");
|
|
|
|
} else {
|
|
|
|
sink_->Put(CodeForRepeats(repeat_count), "SerializeRepeats");
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-21 15:20:53 +00:00
|
|
|
serializer_->SerializeObject(current_contents, kPlain, kStartOfObject);
|
2011-10-20 12:27:10 +00:00
|
|
|
bytes_processed_so_far_ += kPointerSize;
|
|
|
|
current++;
|
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-11 12:28:42 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) {
|
|
|
|
Object** current = rinfo->target_object_address();
|
|
|
|
|
|
|
|
OutputRawData(rinfo->target_address_address());
|
|
|
|
HowToCode representation = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
|
|
|
|
serializer_->SerializeObject(*current, representation, kStartOfObject);
|
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitExternalReferences(Address* start,
|
|
|
|
Address* end) {
|
2009-10-27 11:54:01 +00:00
|
|
|
Address references_start = reinterpret_cast<Address>(start);
|
|
|
|
OutputRawData(references_start);
|
|
|
|
|
|
|
|
for (Address* current = start; current < end; current++) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
|
2009-10-27 11:54:01 +00:00
|
|
|
int reference_id = serializer_->EncodeExternalReference(*current);
|
|
|
|
sink_->PutInt(reference_id, "reference id");
|
|
|
|
}
|
2009-11-11 09:50:06 +00:00
|
|
|
bytes_processed_so_far_ += static_cast<int>((end - start) * kPointerSize);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-11 12:28:42 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) {
|
|
|
|
Address references_start = rinfo->target_address_address();
|
|
|
|
OutputRawData(references_start);
|
|
|
|
|
|
|
|
Address* current = rinfo->target_reference_address();
|
|
|
|
int representation = rinfo->IsCodedSpecially() ?
|
|
|
|
kFromCode + kStartOfObject : kPlain + kStartOfObject;
|
|
|
|
sink_->Put(kExternalReference + representation, "ExternalRef");
|
|
|
|
int reference_id = serializer_->EncodeExternalReference(*current);
|
|
|
|
sink_->PutInt(reference_id, "reference id");
|
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
|
2009-10-30 10:23:12 +00:00
|
|
|
Address target_start = rinfo->target_address_address();
|
|
|
|
OutputRawData(target_start);
|
|
|
|
Address target = rinfo->target_address();
|
|
|
|
uint32_t encoding = serializer_->EncodeExternalReference(target);
|
|
|
|
CHECK(target == NULL ? encoding == 0 : encoding != 0);
|
2010-05-20 13:54:31 +00:00
|
|
|
int representation;
|
|
|
|
// Can't use a ternary operator because of gcc.
|
|
|
|
if (rinfo->IsCodedSpecially()) {
|
|
|
|
representation = kStartOfObject + kFromCode;
|
|
|
|
} else {
|
|
|
|
representation = kStartOfObject + kPlain;
|
|
|
|
}
|
|
|
|
sink_->Put(kExternalReference + representation, "ExternalReference");
|
2009-10-30 10:23:12 +00:00
|
|
|
sink_->PutInt(encoding, "reference id");
|
2010-05-26 08:34:07 +00:00
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
2009-10-30 10:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) {
|
|
|
|
CHECK(RelocInfo::IsCodeTarget(rinfo->rmode()));
|
2009-10-27 11:54:01 +00:00
|
|
|
Address target_start = rinfo->target_address_address();
|
|
|
|
OutputRawData(target_start);
|
|
|
|
Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
|
2010-05-20 13:54:31 +00:00
|
|
|
serializer_->SerializeObject(target, kFromCode, kFirstInstruction);
|
2010-05-26 08:34:07 +00:00
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 07:10:18 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) {
|
|
|
|
Code* target = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
|
|
|
|
OutputRawData(entry_address);
|
|
|
|
serializer_->SerializeObject(target, kPlain, kFirstInstruction);
|
|
|
|
bytes_processed_so_far_ += kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitGlobalPropertyCell(RelocInfo* rinfo) {
|
|
|
|
// We shouldn't have any global property cell references in code
|
|
|
|
// objects in the snapshot.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitExternalAsciiString(
|
2009-11-06 13:48:33 +00:00
|
|
|
v8::String::ExternalAsciiStringResource** resource_pointer) {
|
|
|
|
Address references_start = reinterpret_cast<Address>(resource_pointer);
|
|
|
|
OutputRawData(references_start);
|
|
|
|
for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Object* source = HEAP->natives_source_cache()->get(i);
|
2009-11-06 13:48:33 +00:00
|
|
|
if (!source->IsUndefined()) {
|
2009-11-25 12:55:33 +00:00
|
|
|
ExternalAsciiString* string = ExternalAsciiString::cast(source);
|
2009-11-06 13:48:33 +00:00
|
|
|
typedef v8::String::ExternalAsciiStringResource Resource;
|
2011-09-21 13:28:09 +00:00
|
|
|
const Resource* resource = string->resource();
|
2009-11-06 13:48:33 +00:00
|
|
|
if (resource == *resource_pointer) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kNativesStringResource, "NativesStringResource");
|
2009-11-06 13:48:33 +00:00
|
|
|
sink_->PutSection(i, "NativesStringResourceEnd");
|
|
|
|
bytes_processed_so_far_ += sizeof(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// One of the strings in the natives cache should match the resource. We
|
|
|
|
// can't serialize any other kinds of external strings.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::OutputRawData(Address up_to) {
|
2009-10-27 11:54:01 +00:00
|
|
|
Address object_start = object_->address();
|
2009-11-11 09:50:06 +00:00
|
|
|
int up_to_offset = static_cast<int>(up_to - object_start);
|
2009-10-27 11:54:01 +00:00
|
|
|
int skipped = up_to_offset - bytes_processed_so_far_;
|
2009-10-28 12:37:54 +00:00
|
|
|
// This assert will fail if the reloc info gives us the target_address_address
|
|
|
|
// locations in a non-ascending order. Luckily that doesn't happen.
|
2009-10-27 11:54:01 +00:00
|
|
|
ASSERT(skipped >= 0);
|
|
|
|
if (skipped != 0) {
|
2009-11-03 21:00:43 +00:00
|
|
|
Address base = object_start + bytes_processed_so_far_;
|
|
|
|
#define RAW_CASE(index, length) \
|
|
|
|
if (skipped == length) { \
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->PutSection(kRawData + index, "RawDataFixed"); \
|
2009-11-03 21:00:43 +00:00
|
|
|
} else /* NOLINT */
|
|
|
|
COMMON_RAW_LENGTHS(RAW_CASE)
|
|
|
|
#undef RAW_CASE
|
|
|
|
{ /* NOLINT */
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kRawData, "RawData");
|
2009-11-03 21:00:43 +00:00
|
|
|
sink_->PutInt(skipped, "length");
|
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
for (int i = 0; i < skipped; i++) {
|
2009-11-03 21:00:43 +00:00
|
|
|
unsigned int data = base[i];
|
|
|
|
sink_->PutSection(data, "Byte");
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2009-10-30 10:23:12 +00:00
|
|
|
bytes_processed_so_far_ += skipped;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
int Serializer::SpaceOfObject(HeapObject* object) {
|
2009-10-27 11:54:01 +00:00
|
|
|
for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
|
|
|
|
AllocationSpace s = static_cast<AllocationSpace>(i);
|
2011-03-18 20:35:07 +00:00
|
|
|
if (HEAP->InSpace(object, s)) {
|
2009-10-27 11:54:01 +00:00
|
|
|
if (i == LO_SPACE) {
|
|
|
|
if (object->IsCode()) {
|
|
|
|
return kLargeCode;
|
|
|
|
} else if (object->IsFixedArray()) {
|
|
|
|
return kLargeFixedArray;
|
|
|
|
} else {
|
|
|
|
return kLargeData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
int Serializer::SpaceOfAlreadySerializedObject(HeapObject* object) {
|
2009-10-27 11:54:01 +00:00
|
|
|
for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
|
|
|
|
AllocationSpace s = static_cast<AllocationSpace>(i);
|
2011-03-18 20:35:07 +00:00
|
|
|
if (HEAP->InSpace(object, s)) {
|
2009-10-27 11:54:01 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
int Serializer::Allocate(int space, int size, bool* new_page) {
|
|
|
|
CHECK(space >= 0 && space < kNumberOfSpaces);
|
2009-10-27 11:54:01 +00:00
|
|
|
if (SpaceIsLarge(space)) {
|
|
|
|
// In large object space we merely number the objects instead of trying to
|
|
|
|
// determine some sort of address.
|
2009-11-03 21:00:43 +00:00
|
|
|
*new_page = true;
|
2010-01-15 14:20:31 +00:00
|
|
|
large_object_total_ += size;
|
2009-10-27 11:54:01 +00:00
|
|
|
return fullness_[LO_SPACE]++;
|
|
|
|
}
|
2009-11-03 21:00:43 +00:00
|
|
|
*new_page = false;
|
|
|
|
if (fullness_[space] == 0) {
|
|
|
|
*new_page = true;
|
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
if (SpaceIsPaged(space)) {
|
|
|
|
// Paged spaces are a little special. We encode their addresses as if the
|
|
|
|
// pages were all contiguous and each page were filled up in the range
|
|
|
|
// 0 - Page::kObjectAreaSize. In practice the pages may not be contiguous
|
|
|
|
// and allocation does not start at offset 0 in the page, but this scheme
|
|
|
|
// means the deserializer can get the page number quickly by shifting the
|
|
|
|
// serialized address.
|
2009-11-16 12:08:40 +00:00
|
|
|
CHECK(IsPowerOf2(Page::kPageSize));
|
2009-10-27 11:54:01 +00:00
|
|
|
int used_in_this_page = (fullness_[space] & (Page::kPageSize - 1));
|
2009-11-16 12:08:40 +00:00
|
|
|
CHECK(size <= Page::kObjectAreaSize);
|
2009-10-27 11:54:01 +00:00
|
|
|
if (used_in_this_page + size > Page::kObjectAreaSize) {
|
2009-11-03 21:00:43 +00:00
|
|
|
*new_page = true;
|
2009-10-27 11:54:01 +00:00
|
|
|
fullness_[space] = RoundUp(fullness_[space], Page::kPageSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int allocation_address = fullness_[space];
|
|
|
|
fullness_[space] = allocation_address + size;
|
|
|
|
return allocation_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|