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"
|
2012-12-18 16:25:45 +00:00
|
|
|
#include "deoptimizer.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"
|
2012-06-19 18:38:03 +00:00
|
|
|
#include "snapshot.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#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
|
2012-04-23 15:09:59 +00:00
|
|
|
#undef BUILD_NAME_LITERAL
|
2009-10-08 12:36:12 +00:00
|
|
|
};
|
|
|
|
|
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");
|
2012-02-29 10:45:59 +00:00
|
|
|
Add(stub_cache->map_reference(StubCache::kPrimary).address(),
|
2008-07-03 15:10:15 +00:00
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
3,
|
2012-02-29 10:45:59 +00:00
|
|
|
"StubCache::primary_->map");
|
|
|
|
Add(stub_cache->key_reference(StubCache::kSecondary).address(),
|
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
4,
|
2008-07-03 15:10:15 +00:00
|
|
|
"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,
|
2012-02-29 10:45:59 +00:00
|
|
|
5,
|
2008-07-03 15:10:15 +00:00
|
|
|
"StubCache::secondary_->value");
|
2012-02-29 10:45:59 +00:00
|
|
|
Add(stub_cache->map_reference(StubCache::kSecondary).address(),
|
|
|
|
STUB_CACHE_TABLE,
|
|
|
|
6,
|
|
|
|
"StubCache::secondary_->map");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// 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::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");
|
|
|
|
|
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
|
2013-12-18 10:40:26 +00:00
|
|
|
Add(ExternalReference::mod_two_doubles_operation(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");
|
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()");
|
2013-02-25 14:46:09 +00:00
|
|
|
Add(ExternalReference::handle_scope_next_address(isolate).address(),
|
2010-10-21 14:21:00 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
31,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::next");
|
2013-02-25 14:46:09 +00:00
|
|
|
Add(ExternalReference::handle_scope_limit_address(isolate).address(),
|
2010-10-21 14:21:00 +00:00
|
|
|
UNCLASSIFIED,
|
2011-09-19 18:36:47 +00:00
|
|
|
32,
|
2010-10-21 14:21:00 +00:00
|
|
|
"HandleScope::limit");
|
2013-02-25 14:46:09 +00:00
|
|
|
Add(ExternalReference::handle_scope_level_address(isolate).address(),
|
2010-10-21 14:21:00 +00:00
|
|
|
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");
|
2013-04-24 07:39:35 +00:00
|
|
|
Add(ExternalReference::isolate_address(isolate).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");
|
2012-03-09 12:07:29 +00:00
|
|
|
Add(ExternalReference::get_date_field_function(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
46,
|
|
|
|
"JSDate::GetField");
|
|
|
|
Add(ExternalReference::date_cache_stamp(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
47,
|
|
|
|
"date_cache_stamp");
|
2012-07-31 14:59:32 +00:00
|
|
|
Add(ExternalReference::address_of_pending_message_obj(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
48,
|
|
|
|
"address_of_pending_message_obj");
|
|
|
|
Add(ExternalReference::address_of_has_pending_message(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
49,
|
|
|
|
"address_of_has_pending_message");
|
|
|
|
Add(ExternalReference::address_of_pending_message_script(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
50,
|
|
|
|
"pending_message_script");
|
2012-11-08 12:18:11 +00:00
|
|
|
Add(ExternalReference::get_make_code_young_function(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
51,
|
|
|
|
"Code::MakeCodeYoung");
|
2013-01-23 16:29:48 +00:00
|
|
|
Add(ExternalReference::cpu_features().address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
52,
|
|
|
|
"cpu_features");
|
2013-02-04 12:01:59 +00:00
|
|
|
Add(ExternalReference(Runtime::kAllocateInNewSpace, isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-10-23 18:05:27 +00:00
|
|
|
53,
|
2013-02-04 12:01:59 +00:00
|
|
|
"Runtime::AllocateInNewSpace");
|
2013-11-15 13:49:41 +00:00
|
|
|
Add(ExternalReference(Runtime::kAllocateInTargetSpace, isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
|
|
|
54,
|
|
|
|
"Runtime::AllocateInTargetSpace");
|
2013-03-14 08:32:52 +00:00
|
|
|
Add(ExternalReference::old_pointer_space_allocation_top_address(
|
|
|
|
isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-11-15 13:49:41 +00:00
|
|
|
55,
|
2013-03-14 08:32:52 +00:00
|
|
|
"Heap::OldPointerSpaceAllocationTopAddress");
|
|
|
|
Add(ExternalReference::old_pointer_space_allocation_limit_address(
|
|
|
|
isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-10-23 18:05:27 +00:00
|
|
|
56,
|
2013-11-15 13:49:41 +00:00
|
|
|
"Heap::OldPointerSpaceAllocationLimitAddress");
|
2013-05-28 09:38:28 +00:00
|
|
|
Add(ExternalReference::old_data_space_allocation_top_address(
|
|
|
|
isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-10-23 18:05:27 +00:00
|
|
|
57,
|
2013-05-28 09:38:28 +00:00
|
|
|
"Heap::OldDataSpaceAllocationTopAddress");
|
|
|
|
Add(ExternalReference::old_data_space_allocation_limit_address(
|
|
|
|
isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-10-23 18:05:27 +00:00
|
|
|
58,
|
2013-05-28 09:38:28 +00:00
|
|
|
"Heap::OldDataSpaceAllocationLimitAddress");
|
2013-05-03 10:36:16 +00:00
|
|
|
Add(ExternalReference::new_space_high_promotion_mode_active_address(isolate).
|
|
|
|
address(),
|
|
|
|
UNCLASSIFIED,
|
2013-11-15 13:49:41 +00:00
|
|
|
59,
|
2013-05-03 10:36:16 +00:00
|
|
|
"Heap::NewSpaceAllocationLimitAddress");
|
2013-07-17 11:50:24 +00:00
|
|
|
Add(ExternalReference::allocation_sites_list_address(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-11-15 13:49:41 +00:00
|
|
|
60,
|
2013-07-17 11:50:24 +00:00
|
|
|
"Heap::allocation_sites_list_address()");
|
2013-10-15 16:12:25 +00:00
|
|
|
Add(ExternalReference::address_of_uint32_bias().address(),
|
|
|
|
UNCLASSIFIED,
|
2013-11-15 13:49:41 +00:00
|
|
|
61,
|
2013-10-15 16:12:25 +00:00
|
|
|
"uint32_bias");
|
2013-10-23 13:48:04 +00:00
|
|
|
Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(),
|
|
|
|
UNCLASSIFIED,
|
2013-11-15 13:49:41 +00:00
|
|
|
62,
|
2013-10-23 13:48:04 +00:00
|
|
|
"Code::MarkCodeAsExecuted");
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
// Add a small set of deopt entry addresses to encoder without generating the
|
|
|
|
// deopt table code, which isn't possible at deserialization time.
|
2013-02-27 14:45:59 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-12-18 16:25:45 +00:00
|
|
|
for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) {
|
|
|
|
Address address = Deoptimizer::GetDeoptimizationEntry(
|
2013-02-27 14:45:59 +00:00
|
|
|
isolate,
|
2012-12-18 16:25:45 +00:00
|
|
|
entry,
|
|
|
|
Deoptimizer::LAZY,
|
|
|
|
Deoptimizer::CALCULATE_ENTRY_ADDRESS);
|
2013-11-15 13:49:41 +00:00
|
|
|
Add(address, LAZY_DEOPTIMIZATION, entry, "lazy_deopt");
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate)
|
2011-03-18 20:35:07 +00:00
|
|
|
: encodings_(Match),
|
2013-09-03 11:54:08 +00:00
|
|
|
isolate_(isolate) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
ExternalReferenceDecoder::ExternalReferenceDecoder(Isolate* isolate)
|
2011-03-18 20:35:07 +00:00
|
|
|
: encodings_(NewArray<Address*>(kTypeCodeCount)),
|
2013-09-03 11:54:08 +00:00
|
|
|
isolate_(isolate) {
|
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
|
|
|
|
|
|
|
|
2013-07-26 13:50:23 +00:00
|
|
|
class CodeAddressMap: public CodeEventLogger {
|
|
|
|
public:
|
|
|
|
explicit CodeAddressMap(Isolate* isolate)
|
|
|
|
: isolate_(isolate) {
|
|
|
|
isolate->logger()->addCodeEventListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CodeAddressMap() {
|
|
|
|
isolate_->logger()->removeCodeEventListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void CodeMoveEvent(Address from, Address to) {
|
|
|
|
address_to_name_map_.Move(from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void CodeDeleteEvent(Address from) {
|
|
|
|
address_to_name_map_.Remove(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Lookup(Address address) {
|
|
|
|
return address_to_name_map_.Lookup(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
class NameMap {
|
|
|
|
public:
|
|
|
|
NameMap() : impl_(&PointerEquals) {}
|
|
|
|
|
|
|
|
~NameMap() {
|
|
|
|
for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) {
|
|
|
|
DeleteArray(static_cast<const char*>(p->value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Insert(Address code_address, const char* name, int name_size) {
|
|
|
|
HashMap::Entry* entry = FindOrCreateEntry(code_address);
|
|
|
|
if (entry->value == NULL) {
|
|
|
|
entry->value = CopyName(name, name_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Lookup(Address code_address) {
|
|
|
|
HashMap::Entry* entry = FindEntry(code_address);
|
|
|
|
return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remove(Address code_address) {
|
|
|
|
HashMap::Entry* entry = FindEntry(code_address);
|
|
|
|
if (entry != NULL) {
|
|
|
|
DeleteArray(static_cast<char*>(entry->value));
|
|
|
|
RemoveEntry(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Move(Address from, Address to) {
|
|
|
|
if (from == to) return;
|
|
|
|
HashMap::Entry* from_entry = FindEntry(from);
|
|
|
|
ASSERT(from_entry != NULL);
|
|
|
|
void* value = from_entry->value;
|
|
|
|
RemoveEntry(from_entry);
|
|
|
|
HashMap::Entry* to_entry = FindOrCreateEntry(to);
|
|
|
|
ASSERT(to_entry->value == NULL);
|
|
|
|
to_entry->value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool PointerEquals(void* lhs, void* rhs) {
|
|
|
|
return lhs == rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* CopyName(const char* name, int name_size) {
|
|
|
|
char* result = NewArray<char>(name_size + 1);
|
|
|
|
for (int i = 0; i < name_size; ++i) {
|
|
|
|
char c = name[i];
|
|
|
|
if (c == '\0') c = ' ';
|
|
|
|
result[i] = c;
|
|
|
|
}
|
|
|
|
result[name_size] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap::Entry* FindOrCreateEntry(Address code_address) {
|
|
|
|
return impl_.Lookup(code_address, ComputePointerHash(code_address), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap::Entry* FindEntry(Address code_address) {
|
|
|
|
return impl_.Lookup(code_address,
|
|
|
|
ComputePointerHash(code_address),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveEntry(HashMap::Entry* entry) {
|
|
|
|
impl_.Remove(entry->key, entry->hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap impl_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NameMap);
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void LogRecordedBuffer(Code* code,
|
|
|
|
SharedFunctionInfo*,
|
|
|
|
const char* name,
|
|
|
|
int length) {
|
|
|
|
address_to_name_map_.Insert(code->address(), name, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
NameMap address_to_name_map_;
|
|
|
|
Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CodeAddressMap* Serializer::code_address_map_ = NULL;
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
void Serializer::Enable(Isolate* isolate) {
|
2013-07-26 13:50:23 +00:00
|
|
|
if (!serialization_enabled_) {
|
|
|
|
ASSERT(!too_late_to_enable_now_);
|
|
|
|
}
|
|
|
|
if (serialization_enabled_) return;
|
|
|
|
serialization_enabled_ = true;
|
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
code_address_map_ = new CodeAddressMap(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Serializer::Disable() {
|
|
|
|
if (!serialization_enabled_) return;
|
|
|
|
serialization_enabled_ = false;
|
|
|
|
delete code_address_map_;
|
|
|
|
code_address_map_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Deserializer::Deserializer(SnapshotByteSource* source)
|
|
|
|
: isolate_(NULL),
|
|
|
|
source_(source),
|
|
|
|
external_reference_decoder_(NULL) {
|
2012-09-14 11:16:56 +00:00
|
|
|
for (int i = 0; i < LAST_SPACE + 1; i++) {
|
|
|
|
reservations_[i] = kUninitializedReservation;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-16 13:08:24 +00:00
|
|
|
void Deserializer::FlushICacheForNewCodeObjects() {
|
|
|
|
PageIterator it(isolate_->heap()->code_space());
|
|
|
|
while (it.has_next()) {
|
|
|
|
Page* p = it.next();
|
|
|
|
CPU::FlushICache(p->area_start(), p->area_end() - p->area_start());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
void Deserializer::Deserialize(Isolate* isolate) {
|
|
|
|
isolate_ = isolate;
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(isolate_ != NULL);
|
2012-09-14 11:16:56 +00:00
|
|
|
isolate_->heap()->ReserveSpace(reservations_, &high_water_[0]);
|
|
|
|
// No active threads.
|
|
|
|
ASSERT_EQ(NULL, isolate_->thread_manager()->FirstThreadStateInUse());
|
|
|
|
// No active handles.
|
|
|
|
ASSERT(isolate_->handle_scope_implementer()->blocks()->is_empty());
|
|
|
|
ASSERT_EQ(NULL, external_reference_decoder_);
|
2013-09-03 11:54:08 +00:00
|
|
|
external_reference_decoder_ = new ExternalReferenceDecoder(isolate);
|
2014-02-17 10:41:25 +00:00
|
|
|
isolate_->heap()->IterateSmiRoots(this);
|
2012-09-14 11:16:56 +00:00
|
|
|
isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
|
|
|
|
isolate_->heap()->RepairFreeListsAfterBoot();
|
|
|
|
isolate_->heap()->IterateWeakRoots(this, VISIT_ALL);
|
|
|
|
|
|
|
|
isolate_->heap()->set_native_contexts_list(
|
|
|
|
isolate_->heap()->undefined_value());
|
2013-06-12 09:31:39 +00:00
|
|
|
isolate_->heap()->set_array_buffers_list(
|
|
|
|
isolate_->heap()->undefined_value());
|
2012-09-14 11:16:56 +00:00
|
|
|
|
2013-07-17 11:50:24 +00:00
|
|
|
// The allocation site list is build during root iteration, but if no sites
|
|
|
|
// were encountered then it needs to be initialized to undefined.
|
|
|
|
if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) {
|
|
|
|
isolate_->heap()->set_allocation_sites_list(
|
|
|
|
isolate_->heap()->undefined_value());
|
|
|
|
}
|
|
|
|
|
2013-10-04 07:25:24 +00:00
|
|
|
isolate_->heap()->InitializeWeakObjectToCodeTable();
|
|
|
|
|
2012-09-14 11:16:56 +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();
|
2011-11-23 13:08:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-28 14:43:28 +00:00
|
|
|
|
2013-12-16 13:08:24 +00:00
|
|
|
FlushICacheForNewCodeObjects();
|
|
|
|
|
2012-08-28 14:43:28 +00:00
|
|
|
// Issue code events for newly deserialized code objects.
|
|
|
|
LOG_CODE_EVENT(isolate_, LogCodeObjects());
|
|
|
|
LOG_CODE_EVENT(isolate_, LogCompiledFunctions());
|
2010-01-15 14:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
void Deserializer::DeserializePartial(Isolate* isolate, Object** root) {
|
|
|
|
isolate_ = isolate;
|
2012-09-14 11:16:56 +00:00
|
|
|
for (int i = NEW_SPACE; i < kNumberOfSpaces; i++) {
|
|
|
|
ASSERT(reservations_[i] != kUninitializedReservation);
|
|
|
|
}
|
|
|
|
isolate_->heap()->ReserveSpace(reservations_, &high_water_[0]);
|
2010-01-15 14:20:31 +00:00
|
|
|
if (external_reference_decoder_ == NULL) {
|
2013-09-03 11:54:08 +00:00
|
|
|
external_reference_decoder_ = new ExternalReferenceDecoder(isolate);
|
2010-01-15 14:20:31 +00:00
|
|
|
}
|
2012-08-28 14:43:28 +00:00
|
|
|
|
|
|
|
// Keep track of the code space start and end pointers in case new
|
|
|
|
// code objects were unserialized
|
|
|
|
OldSpace* code_space = isolate_->heap()->code_space();
|
|
|
|
Address start_address = code_space->top();
|
2010-01-15 14:20:31 +00:00
|
|
|
VisitPointer(root);
|
2012-08-28 14:43:28 +00:00
|
|
|
|
|
|
|
// There's no code deserialized here. If this assert fires
|
|
|
|
// then that's changed and logging should be added to notify
|
|
|
|
// the profiler et al of the new code.
|
|
|
|
CHECK_EQ(start_address, code_space->top());
|
2010-01-15 14:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 11:50:24 +00:00
|
|
|
void Deserializer::RelinkAllocationSite(AllocationSite* site) {
|
|
|
|
if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) {
|
|
|
|
site->set_weak_next(isolate_->heap()->undefined_value());
|
|
|
|
} else {
|
|
|
|
site->set_weak_next(isolate_->heap()->allocation_sites_list());
|
|
|
|
}
|
|
|
|
isolate_->heap()->set_allocation_sites_list(site);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
Object** write_back) {
|
2009-10-27 11:54:01 +00:00
|
|
|
int size = source_->GetInt() << kObjectAlignmentBits;
|
2012-09-14 11:16:56 +00:00
|
|
|
Address address = Allocate(space_number, size);
|
2013-07-17 11:50:24 +00:00
|
|
|
HeapObject* obj = HeapObject::FromAddress(address);
|
|
|
|
*write_back = obj;
|
2009-10-27 11:54:01 +00:00
|
|
|
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);
|
2013-07-17 11:50:24 +00:00
|
|
|
|
|
|
|
// TODO(mvstanton): consider treating the heap()->allocation_sites_list()
|
|
|
|
// as a (weak) root. If this root is relocated correctly,
|
|
|
|
// RelinkAllocationSite() isn't necessary.
|
|
|
|
if (obj->IsAllocationSite()) {
|
|
|
|
RelinkAllocationSite(AllocationSite::cast(obj));
|
|
|
|
}
|
|
|
|
|
2011-03-17 08:16:27 +00:00
|
|
|
#ifdef DEBUG
|
2012-09-14 11:16:56 +00:00
|
|
|
bool is_codespace = (space_number == CODE_SPACE);
|
2013-07-17 11:50:24 +00:00
|
|
|
ASSERT(obj->IsCode() == is_codespace);
|
2011-03-17 08:16:27 +00:00
|
|
|
#endif
|
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_;
|
2012-09-14 11:16:56 +00:00
|
|
|
// Write barrier support costs around 1% in startup time. In fact there
|
|
|
|
// are no new space objects in current boot snapshots, so it's not needed,
|
|
|
|
// but that may change.
|
2011-10-25 08:24:06 +00:00
|
|
|
bool write_barrier_needed = (current_object_address != NULL &&
|
|
|
|
source_space != NEW_SPACE &&
|
|
|
|
source_space != CELL_SPACE &&
|
2013-06-12 15:03:44 +00:00
|
|
|
source_space != PROPERTY_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);
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
#define CASE_BODY(where, how, within, space_number_if_any) \
|
2010-05-20 13:54:31 +00:00
|
|
|
{ \
|
|
|
|
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) {\
|
2012-09-14 11:16:56 +00:00
|
|
|
ReadObject(space_number, 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) { \
|
2012-09-14 11:16:56 +00:00
|
|
|
ReadObject(space_number, &new_object); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} 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) { \
|
2012-09-14 11:16:56 +00:00
|
|
|
int skip = source_->GetInt(); \
|
|
|
|
current = reinterpret_cast<Object**>(reinterpret_cast<Address>( \
|
|
|
|
current) + skip); \
|
2010-05-20 13:54:31 +00:00
|
|
|
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 { \
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(where == kBackrefWithSkip); \
|
|
|
|
int skip = source_->GetInt(); \
|
|
|
|
current = reinterpret_cast<Object**>( \
|
|
|
|
reinterpret_cast<Address>(current) + skip); \
|
|
|
|
emit_write_barrier = (space_number == NEW_SPACE); \
|
|
|
|
new_object = GetAddressFromEnd(data & kSpaceMask); \
|
2010-05-20 13:54:31 +00:00
|
|
|
} \
|
2012-07-31 09:25:23 +00:00
|
|
|
if (within == kInnerPointer) { \
|
|
|
|
if (space_number != CODE_SPACE || new_object->IsCode()) { \
|
|
|
|
Code* new_code_object = reinterpret_cast<Code*>(new_object); \
|
|
|
|
new_object = reinterpret_cast<Object*>( \
|
|
|
|
new_code_object->instruction_start()); \
|
|
|
|
} else { \
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(space_number == CODE_SPACE); \
|
2013-06-12 15:03:44 +00:00
|
|
|
Cell* cell = Cell::cast(new_object); \
|
2012-07-31 09:25:23 +00:00
|
|
|
new_object = reinterpret_cast<Object*>( \
|
|
|
|
cell->ValueAddress()); \
|
|
|
|
} \
|
2010-05-20 13:54:31 +00:00
|
|
|
} \
|
|
|
|
if (how == kFromCode) { \
|
|
|
|
Address location_of_branch_data = \
|
|
|
|
reinterpret_cast<Address>(current); \
|
2012-03-21 14:29:14 +00:00
|
|
|
Assembler::deserialization_set_special_target_at( \
|
|
|
|
location_of_branch_data, \
|
2014-03-12 15:23:54 +00:00
|
|
|
Code::cast(HeapObject::FromAddress(current_object_address)), \
|
2012-03-21 14:29:14 +00:00
|
|
|
reinterpret_cast<Address>(new_object)); \
|
|
|
|
location_of_branch_data += Assembler::kSpecialTargetSize; \
|
|
|
|
current = reinterpret_cast<Object**>(location_of_branch_data); \
|
|
|
|
current_was_incremented = true; \
|
2010-05-20 13:54:31 +00:00
|
|
|
} 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 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) \
|
2012-09-14 11:16:56 +00:00
|
|
|
CASE_BODY(where, how, within, NEW_SPACE) \
|
2010-05-20 13:54:31 +00:00
|
|
|
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) \
|
2013-06-12 15:03:44 +00:00
|
|
|
CASE_STATEMENT(where, how, within, PROPERTY_CELL_SPACE) \
|
2010-05-20 13:54:31 +00:00
|
|
|
CASE_STATEMENT(where, how, within, MAP_SPACE) \
|
2012-09-14 11:16:56 +00:00
|
|
|
CASE_BODY(where, how, within, kAnyOldSpace)
|
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
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
#define COMMON_RAW_LENGTHS(f) \
|
|
|
|
f(1) \
|
|
|
|
f(2) \
|
|
|
|
f(3) \
|
|
|
|
f(4) \
|
|
|
|
f(5) \
|
|
|
|
f(6) \
|
|
|
|
f(7) \
|
|
|
|
f(8) \
|
|
|
|
f(9) \
|
|
|
|
f(10) \
|
|
|
|
f(11) \
|
|
|
|
f(12) \
|
|
|
|
f(13) \
|
|
|
|
f(14) \
|
|
|
|
f(15) \
|
|
|
|
f(16) \
|
|
|
|
f(17) \
|
|
|
|
f(18) \
|
|
|
|
f(19) \
|
|
|
|
f(20) \
|
|
|
|
f(21) \
|
|
|
|
f(22) \
|
|
|
|
f(23) \
|
|
|
|
f(24) \
|
|
|
|
f(25) \
|
|
|
|
f(26) \
|
|
|
|
f(27) \
|
|
|
|
f(28) \
|
|
|
|
f(29) \
|
|
|
|
f(30) \
|
|
|
|
f(31)
|
|
|
|
|
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.
|
2012-09-14 11:16:56 +00:00
|
|
|
#define RAW_CASE(index) \
|
|
|
|
case kRawData + index: { \
|
|
|
|
byte* raw_data_out = reinterpret_cast<byte*>(current); \
|
|
|
|
source_->CopyRaw(raw_data_out, index * kPointerSize); \
|
|
|
|
current = \
|
|
|
|
reinterpret_cast<Object**>(raw_data_out + index * kPointerSize); \
|
|
|
|
break; \
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
|
|
|
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);
|
2009-10-27 11:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-20 13:54:31 +00:00
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance)
|
|
|
|
SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance + 16) {
|
2011-10-20 12:27:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
SIXTEEN_CASES(kRootArrayConstants + kHasSkipDistance)
|
|
|
|
SIXTEEN_CASES(kRootArrayConstants + kHasSkipDistance + 16) {
|
|
|
|
int root_id = RootArrayConstantFromByteCode(data);
|
|
|
|
int skip = source_->GetInt();
|
|
|
|
current = reinterpret_cast<Object**>(
|
|
|
|
reinterpret_cast<intptr_t>(current) + skip);
|
|
|
|
Object* object = isolate->heap()->roots_array_start()[root_id];
|
|
|
|
ASSERT(!isolate->heap()->InNewSpace(object));
|
|
|
|
*current++ = object;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
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);
|
2012-09-14 11:16:56 +00:00
|
|
|
STATIC_ASSERT(kMaxRepeats == 13);
|
|
|
|
case kConstantRepeat:
|
|
|
|
FOUR_CASES(kConstantRepeat + 1)
|
|
|
|
FOUR_CASES(kConstantRepeat + 5)
|
|
|
|
FOUR_CASES(kConstantRepeat + 9) {
|
2011-10-20 12:27:10 +00:00
|
|
|
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.
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kNewObject, kPlain, kStartOfObject)
|
2012-07-31 09:25:23 +00:00
|
|
|
// Support for direct instruction pointers in functions. It's an inner
|
|
|
|
// pointer because it points at the entry point, not at the start of the
|
|
|
|
// code object.
|
2012-09-14 11:16:56 +00:00
|
|
|
CASE_STATEMENT(kNewObject, kPlain, kInnerPointer, CODE_SPACE)
|
|
|
|
CASE_BODY(kNewObject, kPlain, kInnerPointer, CODE_SPACE)
|
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.
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kNewObject, kFromCode, kInnerPointer)
|
2010-05-20 13:54:31 +00:00
|
|
|
// 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)
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kBackrefWithSkip, kPlain, kStartOfObject)
|
2014-03-11 20:52:00 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_MIPS) || V8_OOL_CONSTANT_POOL
|
2012-03-21 14:29:14 +00:00
|
|
|
// Deserialize a new object from pointer found in code and write
|
2014-03-11 20:52:00 +00:00
|
|
|
// a pointer to it to the current object. Required only for MIPS or ARM
|
|
|
|
// with ool constant pool, and omitted on the other architectures because
|
|
|
|
// it is fully unrolled and would cause bloat.
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kNewObject, kFromCode, kStartOfObject)
|
2012-03-21 14:29:14 +00:00
|
|
|
// Find a recently deserialized code object using its offset from the
|
|
|
|
// current allocation point and write a pointer to it to the current
|
2014-03-11 20:52:00 +00:00
|
|
|
// object. Required only for MIPS or ARM with ool constant pool.
|
2012-03-21 14:29:14 +00:00
|
|
|
ALL_SPACES(kBackref, kFromCode, kStartOfObject)
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kBackrefWithSkip, kFromCode, kStartOfObject)
|
2012-03-21 14:29:14 +00:00
|
|
|
#endif
|
2010-05-20 13:54:31 +00:00
|
|
|
// 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.
|
2012-07-31 09:25:23 +00:00
|
|
|
ALL_SPACES(kBackref, kFromCode, kInnerPointer)
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kBackrefWithSkip, kFromCode, kInnerPointer)
|
2012-07-31 09:25:23 +00:00
|
|
|
ALL_SPACES(kBackref, kPlain, kInnerPointer)
|
2012-09-14 11:16:56 +00:00
|
|
|
ALL_SPACES(kBackrefWithSkip, kPlain, kInnerPointer)
|
2010-05-20 13:54:31 +00:00
|
|
|
// Find an object in the roots array and write a pointer to it to the
|
|
|
|
// current object.
|
|
|
|
CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0)
|
2012-09-14 11:16:56 +00:00
|
|
|
CASE_BODY(kRootArray, kPlain, kStartOfObject, 0)
|
2010-05-20 13:54:31 +00:00
|
|
|
// 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,
|
2012-09-14 11:16:56 +00:00
|
|
|
0)
|
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.
|
2012-07-31 09:25:23 +00:00
|
|
|
CASE_STATEMENT(kPartialSnapshotCache, kPlain, kInnerPointer, 0)
|
2010-08-20 07:10:18 +00:00
|
|
|
CASE_BODY(kPartialSnapshotCache,
|
|
|
|
kPlain,
|
2012-07-31 09:25:23 +00:00
|
|
|
kInnerPointer,
|
2012-09-14 11:16:56 +00:00
|
|
|
0)
|
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,
|
2012-09-14 11:16:56 +00:00
|
|
|
0)
|
2010-05-20 13:54:31 +00:00
|
|
|
// 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,
|
2012-09-14 11:16:56 +00:00
|
|
|
0)
|
2010-05-20 13:54:31 +00:00
|
|
|
|
|
|
|
#undef CASE_STATEMENT
|
|
|
|
#undef CASE_BODY
|
|
|
|
#undef ALL_SPACES
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
case kSkip: {
|
2012-09-14 11:16:56 +00:00
|
|
|
int size = source_->GetInt();
|
|
|
|
current = reinterpret_cast<Object**>(
|
|
|
|
reinterpret_cast<intptr_t>(current) + size);
|
2011-09-19 18:36:47 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT_EQ(limit, current);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(integer < 1 << 22);
|
|
|
|
integer <<= 2;
|
|
|
|
int bytes = 1;
|
|
|
|
if (integer > 0xff) bytes = 2;
|
|
|
|
if (integer > 0xffff) bytes = 3;
|
|
|
|
integer |= bytes;
|
|
|
|
Put(static_cast<int>(integer & 0xff), "IntPart1");
|
|
|
|
if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
|
|
|
|
if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink)
|
|
|
|
: isolate_(isolate),
|
|
|
|
sink_(sink),
|
|
|
|
external_reference_encoder_(new ExternalReferenceEncoder(isolate)),
|
2011-10-20 12:27:10 +00:00
|
|
|
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.
|
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() {
|
2013-09-03 11:54:08 +00:00
|
|
|
Isolate* isolate = this->isolate();
|
2009-10-27 11:54:01 +00:00
|
|
|
// No active threads.
|
2013-09-03 11:54:08 +00:00
|
|
|
CHECK_EQ(NULL, isolate->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());
|
2013-08-05 09:46:23 +00:00
|
|
|
CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles());
|
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());
|
2014-02-17 10:41:25 +00:00
|
|
|
isolate->heap()->IterateSmiRoots(this);
|
2013-09-11 07:14:41 +00:00
|
|
|
isolate->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);
|
2012-09-14 11:16:56 +00:00
|
|
|
Pad();
|
2010-01-12 15:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-22 08:50:46 +00:00
|
|
|
bool Serializer::ShouldBeSkipped(Object** current) {
|
|
|
|
Object** roots = isolate()->heap()->roots_array_start();
|
|
|
|
return current == &roots[Heap::kStoreBufferTopRootIndex]
|
|
|
|
|| current == &roots[Heap::kStackLimitRootIndex]
|
|
|
|
|| current == &roots[Heap::kRealStackLimitRootIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::VisitPointers(Object** start, Object** end) {
|
2013-09-03 11:54:08 +00:00
|
|
|
Isolate* isolate = this->isolate();;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
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
|
|
|
}
|
2013-10-22 08:50:46 +00:00
|
|
|
if (ShouldBeSkipped(current)) {
|
2011-09-19 18:36:47 +00:00
|
|
|
sink_->Put(kSkip, "Skip");
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->PutInt(kPointerSize, "SkipOneWord");
|
2011-09-19 18:36:47 +00:00
|
|
|
} else if ((*current)->IsSmi()) {
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->Put(kRawData + 1, "Smi");
|
2009-11-03 21:00:43 +00:00
|
|
|
for (int i = 0; i < kPointerSize; i++) {
|
|
|
|
sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-14 11:16:56 +00:00
|
|
|
SerializeObject(*current, kPlain, kStartOfObject, 0);
|
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
|
2012-06-19 18:38:03 +00:00
|
|
|
// snapshot 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.
|
2013-09-03 11:54:08 +00:00
|
|
|
void SerializerDeserializer::Iterate(Isolate* isolate,
|
|
|
|
ObjectVisitor* visitor) {
|
2012-06-19 18:38:03 +00:00
|
|
|
if (Serializer::enabled()) return;
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
if (isolate->serialize_partial_snapshot_cache_length() <= i) {
|
|
|
|
// Extend the array ready to get a value from the visitor when
|
|
|
|
// deserializing.
|
|
|
|
isolate->PushToPartialSnapshotCache(Smi::FromInt(0));
|
|
|
|
}
|
|
|
|
Object** cache = isolate->serialize_partial_snapshot_cache();
|
|
|
|
visitor->VisitPointers(&cache[i], &cache[i + 1]);
|
|
|
|
// Sentinel is the undefined object, which is a root so it will not normally
|
|
|
|
// be found in the cache.
|
|
|
|
if (cache[i] == isolate->heap()->undefined_value()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
|
2013-09-03 11:54:08 +00:00
|
|
|
Isolate* isolate = this->isolate();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
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();
|
2012-06-19 18:38:03 +00:00
|
|
|
isolate->PushToPartialSnapshotCache(heap_object);
|
|
|
|
startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
|
2010-01-27 08:25:48 +00:00
|
|
|
// We don't recurse from the startup snapshot generator into the partial
|
|
|
|
// snapshot generator.
|
2012-06-19 18:38:03 +00:00
|
|
|
ASSERT(length == isolate->serialize_partial_snapshot_cache_length() - 1);
|
2011-03-18 20:35:07 +00:00
|
|
|
return length;
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 14:29:14 +00:00
|
|
|
int Serializer::RootIndex(HeapObject* heap_object, HowToCode from) {
|
2013-09-03 11:54:08 +00:00
|
|
|
Heap* heap = isolate()->heap();
|
2011-10-20 12:27:10 +00:00
|
|
|
if (heap->InNewSpace(heap_object)) return kInvalidRootIndex;
|
|
|
|
for (int i = 0; i < root_index_wave_front_; i++) {
|
|
|
|
Object* root = heap->roots_array_start()[i];
|
2012-03-21 14:29:14 +00:00
|
|
|
if (!root->IsSmi() && root == heap_object) {
|
2014-03-11 20:52:00 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_MIPS) || V8_OOL_CONSTANT_POOL
|
2012-03-21 14:29:14 +00:00
|
|
|
if (from == kFromCode) {
|
|
|
|
// In order to avoid code bloat in the deserializer we don't have
|
|
|
|
// support for the encoding that specifies a particular root should
|
2014-03-11 20:52:00 +00:00
|
|
|
// be written from within code.
|
2012-03-21 14:29:14 +00:00
|
|
|
return kInvalidRootIndex;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
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,
|
2012-09-14 11:16:56 +00:00
|
|
|
WhereToPoint where_to_point,
|
|
|
|
int skip) {
|
2010-01-27 08:25:48 +00:00
|
|
|
int offset = CurrentAllocationAddress(space) - address;
|
2012-09-14 11:16:56 +00:00
|
|
|
// Shift out the bits that are always 0.
|
|
|
|
offset >>= kObjectAlignmentBits;
|
|
|
|
if (skip == 0) {
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer");
|
2012-09-14 11:16:56 +00:00
|
|
|
} else {
|
|
|
|
sink_->Put(kBackrefWithSkip + how_to_code + where_to_point + space,
|
|
|
|
"BackRefSerWithSkip");
|
|
|
|
sink_->PutInt(skip, "BackRefSkipDistance");
|
2010-01-27 08:25:48 +00:00
|
|
|
}
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->PutInt(offset, "offset");
|
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,
|
2012-09-14 11:16:56 +00:00
|
|
|
WhereToPoint where_to_point,
|
|
|
|
int skip) {
|
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;
|
2012-03-21 14:29:14 +00:00
|
|
|
if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) {
|
2012-09-14 11:16:56 +00:00
|
|
|
PutRoot(root_index, heap_object, how_to_code, where_to_point, skip);
|
2011-10-20 12:27:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
if (address_mapper_.IsMapped(heap_object)) {
|
2012-09-14 11:16:56 +00:00
|
|
|
int space = SpaceOfObject(heap_object);
|
2010-01-27 08:25:48 +00:00
|
|
|
int address = address_mapper_.MappedTo(heap_object);
|
|
|
|
SerializeReferenceToPreviousObject(space,
|
|
|
|
address,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
2012-09-14 11:16:56 +00:00
|
|
|
where_to_point,
|
|
|
|
skip);
|
2010-01-27 08:25:48 +00:00
|
|
|
} else {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (skip != 0) {
|
|
|
|
sink_->Put(kSkip, "FlushPendingSkip");
|
|
|
|
sink_->PutInt(skip, "SkipDistance");
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
// 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() {
|
2012-06-19 18:38:03 +00:00
|
|
|
// This phase comes right after the partial serialization (of the snapshot).
|
|
|
|
// After we have done the partial serialization the partial snapshot cache
|
|
|
|
// will contain some references needed to decode the partial snapshot. We
|
|
|
|
// add one entry with 'undefined' which is the sentinel that the deserializer
|
|
|
|
// uses to know it is done deserializing the array.
|
2013-09-03 11:54:08 +00:00
|
|
|
Object* undefined = isolate()->heap()->undefined_value();
|
2012-06-19 18:38:03 +00:00
|
|
|
VisitPointer(&undefined);
|
2013-09-11 07:14:41 +00:00
|
|
|
isolate()->heap()->IterateWeakRoots(this, VISIT_ALL);
|
2012-09-14 11:16:56 +00:00
|
|
|
Pad();
|
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,
|
2012-09-14 11:16:56 +00:00
|
|
|
SerializerDeserializer::WhereToPoint where_to_point,
|
|
|
|
int skip) {
|
2011-10-20 12:27:10 +00:00
|
|
|
if (how_to_code == kPlain &&
|
|
|
|
where_to_point == kStartOfObject &&
|
|
|
|
root_index < kRootArrayNumberOfConstantEncodings &&
|
2013-09-11 07:14:41 +00:00
|
|
|
!isolate()->heap()->InNewSpace(object)) {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (skip == 0) {
|
|
|
|
sink_->Put(kRootArrayConstants + kNoSkipDistance + root_index,
|
|
|
|
"RootConstant");
|
2011-10-20 12:27:10 +00:00
|
|
|
} else {
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->Put(kRootArrayConstants + kHasSkipDistance + root_index,
|
|
|
|
"RootConstant");
|
|
|
|
sink_->PutInt(skip, "SkipInPutRoot");
|
2011-10-20 12:27:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (skip != 0) {
|
|
|
|
sink_->Put(kSkip, "SkipFromPutRoot");
|
|
|
|
sink_->PutInt(skip, "SkipFromPutRootDistance");
|
|
|
|
}
|
2011-10-20 12:27:10 +00:00
|
|
|
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,
|
2012-09-14 11:16:56 +00:00
|
|
|
WhereToPoint where_to_point,
|
|
|
|
int skip) {
|
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() ==
|
2012-10-25 11:52:37 +00:00
|
|
|
heap_object->GetHeap()->empty_fixed_array());
|
2012-01-19 13:51:45 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
int root_index;
|
2012-03-21 14:29:14 +00:00
|
|
|
if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) {
|
2012-09-14 11:16:56 +00:00
|
|
|
PutRoot(root_index, heap_object, how_to_code, where_to_point, skip);
|
2010-01-27 08:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldBeInThePartialSnapshotCache(heap_object)) {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (skip != 0) {
|
|
|
|
sink_->Put(kSkip, "SkipFromSerializeObject");
|
|
|
|
sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:25:48 +00:00
|
|
|
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));
|
2013-02-28 17:03:34 +00:00
|
|
|
// All the internalized strings that the partial snapshot needs should be
|
|
|
|
// either in the root table or in the partial snapshot cache.
|
|
|
|
ASSERT(!heap_object->IsInternalizedString());
|
2010-01-27 08:25:48 +00:00
|
|
|
|
|
|
|
if (address_mapper_.IsMapped(heap_object)) {
|
2012-09-14 11:16:56 +00:00
|
|
|
int space = SpaceOfObject(heap_object);
|
2010-01-27 08:25:48 +00:00
|
|
|
int address = address_mapper_.MappedTo(heap_object);
|
|
|
|
SerializeReferenceToPreviousObject(space,
|
|
|
|
address,
|
2010-05-20 13:54:31 +00:00
|
|
|
how_to_code,
|
2012-09-14 11:16:56 +00:00
|
|
|
where_to_point,
|
|
|
|
skip);
|
2009-10-27 11:54:01 +00:00
|
|
|
} else {
|
2012-09-14 11:16:56 +00:00
|
|
|
if (skip != 0) {
|
|
|
|
sink_->Put(kSkip, "SkipFromSerializeObject");
|
|
|
|
sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
|
|
|
|
}
|
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");
|
|
|
|
|
2013-07-26 13:50:23 +00:00
|
|
|
ASSERT(code_address_map_);
|
|
|
|
const char* code_name = code_address_map_->Lookup(object_->address());
|
|
|
|
LOG(serializer_->isolate_,
|
|
|
|
CodeNameEvent(object_->address(), sink_->Position(), code_name));
|
|
|
|
LOG(serializer_->isolate_,
|
2011-03-18 20:35:07 +00:00
|
|
|
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.
|
2012-09-14 11:16:56 +00:00
|
|
|
int offset = serializer_->Allocate(space, size);
|
2010-01-27 08:25:48 +00:00
|
|
|
serializer_->address_mapper()->AddMapping(object_, offset);
|
2009-10-27 11:54:01 +00:00
|
|
|
|
|
|
|
// Serialize the map (first word of the object).
|
2012-09-14 11:16:56 +00:00
|
|
|
serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0);
|
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);
|
2012-03-21 14:29:14 +00:00
|
|
|
int root_index = serializer_->RootIndex(current_contents, kPlain);
|
2011-10-21 15:20:53 +00:00
|
|
|
// 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]) {
|
2013-09-11 07:14:41 +00:00
|
|
|
ASSERT(!serializer_->isolate()->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 {
|
2012-09-14 11:16:56 +00:00
|
|
|
serializer_->SerializeObject(
|
|
|
|
current_contents, kPlain, kStartOfObject, 0);
|
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) {
|
2014-03-11 20:52:00 +00:00
|
|
|
// Out-of-line constant pool entries will be visited by the ConstantPoolArray.
|
|
|
|
if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
int skip = OutputRawData(rinfo->target_address_address(),
|
|
|
|
kCanReturnSkipInsteadOfSkipping);
|
2013-11-07 07:37:28 +00:00
|
|
|
HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
|
|
|
|
Object* object = rinfo->target_object();
|
|
|
|
serializer_->SerializeObject(object, how_to_code, kStartOfObject, skip);
|
2011-11-11 12:28:42 +00:00
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-23 10:47:51 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitExternalReference(Address* p) {
|
2013-11-07 07:37:28 +00:00
|
|
|
int skip = OutputRawData(reinterpret_cast<Address>(p),
|
|
|
|
kCanReturnSkipInsteadOfSkipping);
|
2013-10-23 10:47:51 +00:00
|
|
|
sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
|
|
|
|
sink_->PutInt(skip, "SkipB4ExternalRef");
|
2013-11-07 07:37:28 +00:00
|
|
|
Address target = *p;
|
|
|
|
sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
|
2013-10-23 10:47:51 +00:00
|
|
|
bytes_processed_so_far_ += kPointerSize;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-11 12:28:42 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) {
|
2013-11-07 07:37:28 +00:00
|
|
|
int skip = OutputRawData(rinfo->target_address_address(),
|
|
|
|
kCanReturnSkipInsteadOfSkipping);
|
|
|
|
HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
|
|
|
|
sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->PutInt(skip, "SkipB4ExternalRef");
|
2013-11-07 07:37:28 +00:00
|
|
|
Address target = rinfo->target_reference();
|
|
|
|
sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
|
2011-11-11 12:28:42 +00:00
|
|
|
bytes_processed_so_far_ += rinfo->target_address_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 12:08:40 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
|
2013-11-07 07:37:28 +00:00
|
|
|
int skip = OutputRawData(rinfo->target_address_address(),
|
|
|
|
kCanReturnSkipInsteadOfSkipping);
|
|
|
|
HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
|
|
|
|
sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->PutInt(skip, "SkipB4ExternalRef");
|
2013-11-07 07:37:28 +00:00
|
|
|
Address target = rinfo->target_address();
|
|
|
|
sink_->PutInt(serializer_->EncodeExternalReference(target), "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) {
|
2014-03-11 20:52:00 +00:00
|
|
|
// Out-of-line constant pool entries will be visited by the ConstantPoolArray.
|
|
|
|
if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
|
|
|
|
|
2013-11-07 07:37:28 +00:00
|
|
|
int skip = OutputRawData(rinfo->target_address_address(),
|
|
|
|
kCanReturnSkipInsteadOfSkipping);
|
|
|
|
Code* object = Code::GetCodeFromTargetAddress(rinfo->target_address());
|
|
|
|
serializer_->SerializeObject(object, kFromCode, kInnerPointer, skip);
|
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) {
|
2012-09-14 11:16:56 +00:00
|
|
|
int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping);
|
2013-11-07 07:37:28 +00:00
|
|
|
Code* object = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
|
|
|
|
serializer_->SerializeObject(object, kPlain, kInnerPointer, skip);
|
2010-08-20 07:10:18 +00:00
|
|
|
bytes_processed_so_far_ += kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
void Serializer::ObjectSerializer::VisitCell(RelocInfo* rinfo) {
|
2014-03-11 20:52:00 +00:00
|
|
|
// Out-of-line constant pool entries will be visited by the ConstantPoolArray.
|
|
|
|
if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping);
|
2013-11-07 07:37:28 +00:00
|
|
|
Cell* object = Cell::cast(rinfo->target_cell());
|
|
|
|
serializer_->SerializeObject(object, kPlain, kInnerPointer, skip);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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++) {
|
2013-09-11 07:14:41 +00:00
|
|
|
Object* source =
|
|
|
|
serializer_->isolate()->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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 10:14:48 +00:00
|
|
|
static Code* CloneCodeObject(HeapObject* code) {
|
|
|
|
Address copy = new byte[code->Size()];
|
|
|
|
OS::MemCopy(copy, code->address(), code->Size());
|
|
|
|
return Code::cast(HeapObject::FromAddress(copy));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void WipeOutRelocations(Code* code) {
|
|
|
|
int mode_mask =
|
|
|
|
RelocInfo::kCodeTargetMask |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
|
|
|
|
for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
|
2014-03-11 20:52:00 +00:00
|
|
|
if (!(FLAG_enable_ool_constant_pool && it.rinfo()->IsInConstantPool())) {
|
|
|
|
it.rinfo()->WipeOut();
|
|
|
|
}
|
2013-11-05 10:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
int Serializer::ObjectSerializer::OutputRawData(
|
|
|
|
Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) {
|
2009-10-27 11:54:01 +00:00
|
|
|
Address object_start = object_->address();
|
2013-11-05 10:14:48 +00:00
|
|
|
int base = bytes_processed_so_far_;
|
2009-11-11 09:50:06 +00:00
|
|
|
int up_to_offset = static_cast<int>(up_to - object_start);
|
2012-09-14 11:16:56 +00:00
|
|
|
int to_skip = up_to_offset - bytes_processed_so_far_;
|
|
|
|
int bytes_to_output = to_skip;
|
|
|
|
bytes_processed_so_far_ += to_skip;
|
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.
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(to_skip >= 0);
|
|
|
|
bool outputting_code = false;
|
|
|
|
if (to_skip != 0 && code_object_ && !code_has_been_output_) {
|
|
|
|
// Output the code all at once and fix later.
|
|
|
|
bytes_to_output = object_->Size() + to_skip - bytes_processed_so_far_;
|
|
|
|
outputting_code = true;
|
|
|
|
code_has_been_output_ = true;
|
|
|
|
}
|
|
|
|
if (bytes_to_output != 0 &&
|
|
|
|
(!code_object_ || outputting_code)) {
|
|
|
|
#define RAW_CASE(index) \
|
|
|
|
if (!outputting_code && bytes_to_output == index * kPointerSize && \
|
|
|
|
index * kPointerSize == to_skip) { \
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->PutSection(kRawData + index, "RawDataFixed"); \
|
2012-09-14 11:16:56 +00:00
|
|
|
to_skip = 0; /* This insn already skips. */ \
|
2009-11-03 21:00:43 +00:00
|
|
|
} else /* NOLINT */
|
|
|
|
COMMON_RAW_LENGTHS(RAW_CASE)
|
|
|
|
#undef RAW_CASE
|
|
|
|
{ /* NOLINT */
|
2012-09-14 11:16:56 +00:00
|
|
|
// We always end up here if we are outputting the code of a code object.
|
2010-05-20 13:54:31 +00:00
|
|
|
sink_->Put(kRawData, "RawData");
|
2012-09-14 11:16:56 +00:00
|
|
|
sink_->PutInt(bytes_to_output, "length");
|
2009-11-03 21:00:43 +00:00
|
|
|
}
|
2013-11-05 10:14:48 +00:00
|
|
|
|
|
|
|
// To make snapshots reproducible, we need to wipe out all pointers in code.
|
|
|
|
if (code_object_) {
|
|
|
|
Code* code = CloneCodeObject(object_);
|
|
|
|
WipeOutRelocations(code);
|
|
|
|
// We need to wipe out the header fields *after* wiping out the
|
|
|
|
// relocations, because some of these fields are needed for the latter.
|
|
|
|
code->WipeOutHeader();
|
|
|
|
object_start = code->address();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* description = code_object_ ? "Code" : "Byte";
|
2012-09-14 11:16:56 +00:00
|
|
|
for (int i = 0; i < bytes_to_output; i++) {
|
2013-11-05 10:14:48 +00:00
|
|
|
sink_->PutSection(object_start[base + i], description);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2013-11-05 10:14:48 +00:00
|
|
|
if (code_object_) delete[] object_start;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2012-09-14 11:16:56 +00:00
|
|
|
if (to_skip != 0 && return_skip == kIgnoringReturn) {
|
|
|
|
sink_->Put(kSkip, "Skip");
|
|
|
|
sink_->PutInt(to_skip, "SkipDistance");
|
|
|
|
to_skip = 0;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2012-09-14 11:16:56 +00:00
|
|
|
return to_skip;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 11:16:56 +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);
|
2013-09-11 07:14:41 +00:00
|
|
|
if (object->GetHeap()->InSpace(object, s)) {
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(i < kNumberOfSpaces);
|
2009-10-27 11:54:01 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
int Serializer::Allocate(int space, int size) {
|
2009-11-16 12:08:40 +00:00
|
|
|
CHECK(space >= 0 && space < kNumberOfSpaces);
|
2009-10-27 11:54:01 +00:00
|
|
|
int allocation_address = fullness_[space];
|
|
|
|
fullness_[space] = allocation_address + size;
|
|
|
|
return allocation_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
int Serializer::SpaceAreaSize(int space) {
|
|
|
|
if (space == CODE_SPACE) {
|
|
|
|
return isolate_->memory_allocator()->CodePageAreaSize();
|
|
|
|
} else {
|
|
|
|
return Page::kPageSize - Page::kObjectStartOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
void Serializer::Pad() {
|
|
|
|
// The non-branching GetInt will read up to 3 bytes too far, so we need
|
|
|
|
// to pad the snapshot to make sure we don't read over the end.
|
|
|
|
for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) {
|
|
|
|
sink_->Put(kNop, "Padding");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SnapshotByteSource::AtEOF() {
|
2012-09-14 13:19:42 +00:00
|
|
|
if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
|
2012-09-14 11:16:56 +00:00
|
|
|
for (int x = position_; x < length_; x++) {
|
|
|
|
if (data_[x] != SerializerDeserializer::nop()) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|