Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: src/serialize.cc

Issue 10918067: Refactoring of snapshots. This simplifies and improves (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/serialize.h ('k') | src/snapshot.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/serialize.cc
===================================================================
--- src/serialize.cc (revision 12497)
+++ src/serialize.cc (working copy)
@@ -599,109 +599,34 @@
: isolate_(NULL),
source_(source),
external_reference_decoder_(NULL) {
-}
-
-
-// This routine both allocates a new object, and also keeps
-// track of where objects have been allocated so that we can
-// fix back references when deserializing.
-Address Deserializer::Allocate(int space_index, Space* space, int size) {
- Address address;
- if (!SpaceIsLarge(space_index)) {
- ASSERT(!SpaceIsPaged(space_index) ||
- size <= Page::kPageSize - Page::kObjectStartOffset);
- MaybeObject* maybe_new_allocation;
- if (space_index == NEW_SPACE) {
- maybe_new_allocation =
- reinterpret_cast<NewSpace*>(space)->AllocateRaw(size);
- } else {
- maybe_new_allocation =
- reinterpret_cast<PagedSpace*>(space)->AllocateRaw(size);
- }
- ASSERT(!maybe_new_allocation->IsFailure());
- Object* new_allocation = maybe_new_allocation->ToObjectUnchecked();
- HeapObject* new_object = HeapObject::cast(new_allocation);
- address = new_object->address();
- high_water_[space_index] = address + size;
- } else {
- ASSERT(SpaceIsLarge(space_index));
- LargeObjectSpace* lo_space = reinterpret_cast<LargeObjectSpace*>(space);
- Object* new_allocation;
- if (space_index == kLargeData || space_index == kLargeFixedArray) {
- new_allocation =
- lo_space->AllocateRaw(size, NOT_EXECUTABLE)->ToObjectUnchecked();
- } else {
- ASSERT_EQ(kLargeCode, space_index);
- new_allocation =
- lo_space->AllocateRaw(size, EXECUTABLE)->ToObjectUnchecked();
- }
- HeapObject* new_object = HeapObject::cast(new_allocation);
- // Record all large objects in the same space.
- address = new_object->address();
- pages_[LO_SPACE].Add(address);
+ for (int i = 0; i < LAST_SPACE + 1; i++) {
+ reservations_[i] = kUninitializedReservation;
}
- last_object_address_ = address;
- return address;
}
-// This returns the address of an object that has been described in the
-// snapshot as being offset bytes back in a particular space.
-HeapObject* Deserializer::GetAddressFromEnd(int space) {
- int offset = source_->GetInt();
- ASSERT(!SpaceIsLarge(space));
- offset <<= kObjectAlignmentBits;
- return HeapObject::FromAddress(high_water_[space] - offset);
-}
-
-
-// This returns the address of an object that has been described in the
-// snapshot as being offset bytes into a particular space.
-HeapObject* Deserializer::GetAddressFromStart(int space) {
- int offset = source_->GetInt();
- if (SpaceIsLarge(space)) {
- // Large spaces have one object per 'page'.
- return HeapObject::FromAddress(pages_[LO_SPACE][offset]);
- }
- offset <<= kObjectAlignmentBits;
- if (space == NEW_SPACE) {
- // New space has only one space - numbered 0.
- return HeapObject::FromAddress(pages_[space][0] + offset);
- }
- ASSERT(SpaceIsPaged(space));
- int page_of_pointee = offset >> kPageSizeBits;
- Address object_address = pages_[space][page_of_pointee] +
- (offset & Page::kPageAlignmentMask);
- return HeapObject::FromAddress(object_address);
-}
-
-
void Deserializer::Deserialize() {
isolate_ = Isolate::Current();
ASSERT(isolate_ != NULL);
- {
- // Don't GC while deserializing - just expand the heap.
- AlwaysAllocateScope always_allocate;
- // Don't use the free lists while deserializing.
- LinearAllocationScope allocate_linearly;
- // No active threads.
- ASSERT_EQ(NULL, isolate_->thread_manager()->FirstThreadStateInUse());
- // No active handles.
- ASSERT(isolate_->handle_scope_implementer()->blocks()->is_empty());
- ASSERT_EQ(NULL, external_reference_decoder_);
- external_reference_decoder_ = new ExternalReferenceDecoder();
- isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
- isolate_->heap()->IterateWeakRoots(this, VISIT_ALL);
+ 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_);
+ external_reference_decoder_ = new ExternalReferenceDecoder();
+ 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());
+ isolate_->heap()->set_native_contexts_list(
+ isolate_->heap()->undefined_value());
- // 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();
- }
+ // 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();
}
}
@@ -713,10 +638,10 @@
void Deserializer::DeserializePartial(Object** root) {
isolate_ = Isolate::Current();
- // Don't GC while deserializing - just expand the heap.
- AlwaysAllocateScope always_allocate;
- // Don't use the free lists while deserializing.
- LinearAllocationScope allocate_linearly;
+ for (int i = NEW_SPACE; i < kNumberOfSpaces; i++) {
+ ASSERT(reservations_[i] != kUninitializedReservation);
+ }
+ isolate_->heap()->ReserveSpace(reservations_, &high_water_[0]);
if (external_reference_decoder_ == NULL) {
external_reference_decoder_ = new ExternalReferenceDecoder();
}
@@ -758,10 +683,9 @@
// 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.
void Deserializer::ReadObject(int space_number,
- Space* space,
Object** write_back) {
int size = source_->GetInt() << kObjectAlignmentBits;
- Address address = Allocate(space_number, space, size);
+ Address address = Allocate(space_number, size);
*write_back = HeapObject::FromAddress(address);
Object** current = reinterpret_cast<Object**>(address);
Object** limit = current + (size >> kPointerSizeLog2);
@@ -770,44 +694,19 @@
}
ReadChunk(current, limit, space_number, address);
#ifdef DEBUG
- bool is_codespace = (space == HEAP->code_space()) ||
- ((space == HEAP->lo_space()) && (space_number == kLargeCode));
+ bool is_codespace = (space_number == CODE_SPACE);
ASSERT(HeapObject::FromAddress(address)->IsCode() == is_codespace);
#endif
}
-
-// This macro is always used with a constant argument so it should all fold
-// away to almost nothing in the generated code. It might be nicer to do this
-// with the ternary operator but there are type issues with that.
-#define ASSIGN_DEST_SPACE(space_number) \
- Space* dest_space; \
- if (space_number == NEW_SPACE) { \
- dest_space = isolate->heap()->new_space(); \
- } else if (space_number == OLD_POINTER_SPACE) { \
- dest_space = isolate->heap()->old_pointer_space(); \
- } else if (space_number == OLD_DATA_SPACE) { \
- dest_space = isolate->heap()->old_data_space(); \
- } else if (space_number == CODE_SPACE) { \
- dest_space = isolate->heap()->code_space(); \
- } else if (space_number == MAP_SPACE) { \
- dest_space = isolate->heap()->map_space(); \
- } else if (space_number == CELL_SPACE) { \
- dest_space = isolate->heap()->cell_space(); \
- } else { \
- ASSERT(space_number >= LO_SPACE); \
- dest_space = isolate->heap()->lo_space(); \
- }
-
-
-static const int kUnknownOffsetFromStart = -1;
-
-
void Deserializer::ReadChunk(Object** current,
Object** limit,
int source_space,
Address current_object_address) {
Isolate* const isolate = isolate_;
+ // 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.
bool write_barrier_needed = (current_object_address != NULL &&
source_space != NEW_SPACE &&
source_space != CELL_SPACE &&
@@ -823,21 +722,19 @@
ASSERT((within & ~kWhereToPointMask) == 0); \
ASSERT((space_number & ~kSpaceMask) == 0);
-#define CASE_BODY(where, how, within, space_number_if_any, offset_from_start) \
+#define CASE_BODY(where, how, within, space_number_if_any) \
{ \
bool emit_write_barrier = false; \
bool current_was_incremented = false; \
int space_number = space_number_if_any == kAnyOldSpace ? \
(data & kSpaceMask) : space_number_if_any; \
if (where == kNewObject && how == kPlain && within == kStartOfObject) {\
- ASSIGN_DEST_SPACE(space_number) \
- ReadObject(space_number, dest_space, current); \
+ ReadObject(space_number, current); \
emit_write_barrier = (space_number == NEW_SPACE); \
} else { \
Object* new_object = NULL; /* May not be a real Object pointer. */ \
if (where == kNewObject) { \
- ASSIGN_DEST_SPACE(space_number) \
- ReadObject(space_number, dest_space, &new_object); \
+ ReadObject(space_number, &new_object); \
} else if (where == kRootArray) { \
int root_id = source_->GetInt(); \
new_object = isolate->heap()->roots_array_start()[root_id]; \
@@ -848,6 +745,9 @@
[cache_index]; \
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
} else if (where == kExternalReference) { \
+ int skip = source_->GetInt(); \
+ current = reinterpret_cast<Object**>(reinterpret_cast<Address>( \
+ current) + skip); \
int reference_id = source_->GetInt(); \
Address address = external_reference_decoder_-> \
Decode(reference_id); \
@@ -856,15 +756,12 @@
emit_write_barrier = (space_number == NEW_SPACE); \
new_object = GetAddressFromEnd(data & kSpaceMask); \
} else { \
- ASSERT(where == kFromStart); \
- if (offset_from_start == kUnknownOffsetFromStart) { \
- emit_write_barrier = (space_number == NEW_SPACE); \
- new_object = GetAddressFromStart(data & kSpaceMask); \
- } else { \
- Address object_address = pages_[space_number][0] + \
- (offset_from_start << kObjectAlignmentBits); \
- new_object = HeapObject::FromAddress(object_address); \
- } \
+ 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); \
} \
if (within == kInnerPointer) { \
if (space_number != CODE_SPACE || new_object->IsCode()) { \
@@ -872,7 +769,7 @@
new_object = reinterpret_cast<Object*>( \
new_code_object->instruction_start()); \
} else { \
- ASSERT(space_number == CODE_SPACE || space_number == kLargeCode);\
+ ASSERT(space_number == CODE_SPACE); \
JSGlobalPropertyCell* cell = \
JSGlobalPropertyCell::cast(new_object); \
new_object = reinterpret_cast<Object*>( \
@@ -904,48 +801,19 @@
break; \
} \
-// This generates a case and a body for each space. The large object spaces are
-// very rare in snapshots so they are grouped in one body.
-#define ONE_PER_SPACE(where, how, within) \
- CASE_STATEMENT(where, how, within, NEW_SPACE) \
- CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
- CASE_BODY(where, how, within, OLD_DATA_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
- CASE_BODY(where, how, within, OLD_POINTER_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, CODE_SPACE) \
- CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, CELL_SPACE) \
- CASE_BODY(where, how, within, CELL_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, MAP_SPACE) \
- CASE_BODY(where, how, within, MAP_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, kLargeData) \
- CASE_STATEMENT(where, how, within, kLargeCode) \
- CASE_STATEMENT(where, how, within, kLargeFixedArray) \
- CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
-
// This generates a case and a body for the new space (which has to do extra
// write barrier handling) and handles the other spaces with 8 fall-through
// cases and one body.
#define ALL_SPACES(where, how, within) \
CASE_STATEMENT(where, how, within, NEW_SPACE) \
- CASE_BODY(where, how, within, NEW_SPACE, kUnknownOffsetFromStart) \
+ CASE_BODY(where, how, within, NEW_SPACE) \
CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
CASE_STATEMENT(where, how, within, CODE_SPACE) \
CASE_STATEMENT(where, how, within, CELL_SPACE) \
CASE_STATEMENT(where, how, within, MAP_SPACE) \
- CASE_STATEMENT(where, how, within, kLargeData) \
- CASE_STATEMENT(where, how, within, kLargeCode) \
- CASE_STATEMENT(where, how, within, kLargeFixedArray) \
- CASE_BODY(where, how, within, kAnyOldSpace, kUnknownOffsetFromStart)
+ CASE_BODY(where, how, within, kAnyOldSpace)
-#define ONE_PER_CODE_SPACE(where, how, within) \
- CASE_STATEMENT(where, how, within, CODE_SPACE) \
- CASE_BODY(where, how, within, CODE_SPACE, kUnknownOffsetFromStart) \
- CASE_STATEMENT(where, how, within, kLargeCode) \
- CASE_BODY(where, how, within, kLargeCode, kUnknownOffsetFromStart)
-
#define FOUR_CASES(byte_code) \
case byte_code: \
case byte_code + 1: \
@@ -958,14 +826,48 @@
FOUR_CASES(byte_code + 8) \
FOUR_CASES(byte_code + 12)
+#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)
+
// We generate 15 cases and bodies that process special tags that combine
// the raw data tag and the length into one byte.
-#define RAW_CASE(index, size) \
- case kRawData + index: { \
- byte* raw_data_out = reinterpret_cast<byte*>(current); \
- source_->CopyRaw(raw_data_out, size); \
- current = reinterpret_cast<Object**>(raw_data_out + size); \
- break; \
+#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; \
}
COMMON_RAW_LENGTHS(RAW_CASE)
#undef RAW_CASE
@@ -976,12 +878,11 @@
int size = source_->GetInt();
byte* raw_data_out = reinterpret_cast<byte*>(current);
source_->CopyRaw(raw_data_out, size);
- current = reinterpret_cast<Object**>(raw_data_out + size);
break;
}
- SIXTEEN_CASES(kRootArrayLowConstants)
- SIXTEEN_CASES(kRootArrayHighConstants) {
+ SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance)
+ SIXTEEN_CASES(kRootArrayConstants + kNoSkipDistance + 16) {
int root_id = RootArrayConstantFromByteCode(data);
Object* object = isolate->heap()->roots_array_start()[root_id];
ASSERT(!isolate->heap()->InNewSpace(object));
@@ -989,6 +890,18 @@
break;
}
+ 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;
+ }
+
case kRepeat: {
int repeats = source_->GetInt();
Object* object = current[-1];
@@ -1000,10 +913,11 @@
STATIC_ASSERT(kRootArrayNumberOfConstantEncodings ==
Heap::kOldSpaceRoots);
- STATIC_ASSERT(kMaxRepeats == 12);
- FOUR_CASES(kConstantRepeat)
- FOUR_CASES(kConstantRepeat + 4)
- FOUR_CASES(kConstantRepeat + 8) {
+ STATIC_ASSERT(kMaxRepeats == 13);
+ case kConstantRepeat:
+ FOUR_CASES(kConstantRepeat + 1)
+ FOUR_CASES(kConstantRepeat + 5)
+ FOUR_CASES(kConstantRepeat + 9) {
int repeats = RepeatsForCode(data);
Object* object = current[-1];
ASSERT(!isolate->heap()->InNewSpace(object));
@@ -1014,100 +928,80 @@
// Deserialize a new object and write a pointer to it to the current
// object.
- ONE_PER_SPACE(kNewObject, kPlain, kStartOfObject)
+ ALL_SPACES(kNewObject, kPlain, kStartOfObject)
// 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.
- ONE_PER_CODE_SPACE(kNewObject, kPlain, kInnerPointer)
+ CASE_STATEMENT(kNewObject, kPlain, kInnerPointer, CODE_SPACE)
+ CASE_BODY(kNewObject, kPlain, kInnerPointer, CODE_SPACE)
// Deserialize a new code object and write a pointer to its first
// instruction to the current code object.
- ONE_PER_SPACE(kNewObject, kFromCode, kInnerPointer)
+ ALL_SPACES(kNewObject, kFromCode, kInnerPointer)
// 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)
+ ALL_SPACES(kBackrefWithSkip, kPlain, kStartOfObject)
#if V8_TARGET_ARCH_MIPS
// Deserialize a new object from pointer found in code and write
// a pointer to it to the current object. Required only for MIPS, and
// omitted on the other architectures because it is fully unrolled and
// would cause bloat.
- ONE_PER_SPACE(kNewObject, kFromCode, kStartOfObject)
+ ALL_SPACES(kNewObject, kFromCode, kStartOfObject)
// Find a recently deserialized code object using its offset from the
// current allocation point and write a pointer to it to the current
// object. Required only for MIPS.
ALL_SPACES(kBackref, kFromCode, kStartOfObject)
- // Find an already deserialized code object using its offset from
- // the start and write a pointer to it to the current object.
- // Required only for MIPS.
- ALL_SPACES(kFromStart, kFromCode, kStartOfObject)
+ ALL_SPACES(kBackrefWithSkip, kFromCode, kStartOfObject)
#endif
// Find a recently deserialized code object using its offset from the
// current allocation point and write a pointer to its first instruction
// to the current code object or the instruction pointer in a function
// object.
ALL_SPACES(kBackref, kFromCode, kInnerPointer)
+ ALL_SPACES(kBackrefWithSkip, kFromCode, kInnerPointer)
ALL_SPACES(kBackref, kPlain, kInnerPointer)
- // Find an already deserialized object using its offset from the start
- // and write a pointer to it to the current object.
- ALL_SPACES(kFromStart, kPlain, kStartOfObject)
- ALL_SPACES(kFromStart, kPlain, kInnerPointer)
- // Find an already deserialized code object using its offset from the
- // start and write a pointer to its first instruction to the current code
- // object.
- ALL_SPACES(kFromStart, kFromCode, kInnerPointer)
+ ALL_SPACES(kBackrefWithSkip, kPlain, kInnerPointer)
// Find an object in the roots array and write a pointer to it to the
// current object.
CASE_STATEMENT(kRootArray, kPlain, kStartOfObject, 0)
- CASE_BODY(kRootArray, kPlain, kStartOfObject, 0, kUnknownOffsetFromStart)
+ CASE_BODY(kRootArray, kPlain, kStartOfObject, 0)
// Find an object in the partial snapshots cache and write a pointer to it
// to the current object.
CASE_STATEMENT(kPartialSnapshotCache, kPlain, kStartOfObject, 0)
CASE_BODY(kPartialSnapshotCache,
kPlain,
kStartOfObject,
- 0,
- kUnknownOffsetFromStart)
+ 0)
// Find an code entry in the partial snapshots cache and
// write a pointer to it to the current object.
CASE_STATEMENT(kPartialSnapshotCache, kPlain, kInnerPointer, 0)
CASE_BODY(kPartialSnapshotCache,
kPlain,
kInnerPointer,
- 0,
- kUnknownOffsetFromStart)
+ 0)
// Find an external reference and write a pointer to it to the current
// object.
CASE_STATEMENT(kExternalReference, kPlain, kStartOfObject, 0)
CASE_BODY(kExternalReference,
kPlain,
kStartOfObject,
- 0,
- kUnknownOffsetFromStart)
+ 0)
// Find an external reference and write a pointer to it in the current
// code object.
CASE_STATEMENT(kExternalReference, kFromCode, kStartOfObject, 0)
CASE_BODY(kExternalReference,
kFromCode,
kStartOfObject,
- 0,
- kUnknownOffsetFromStart)
+ 0)
#undef CASE_STATEMENT
#undef CASE_BODY
-#undef ONE_PER_SPACE
#undef ALL_SPACES
-#undef ASSIGN_DEST_SPACE
- case kNewPage: {
- int space = source_->Get();
- pages_[space].Add(last_object_address_);
- if (space == CODE_SPACE) {
- CPU::FlushICache(last_object_address_, Page::kPageSize);
- }
- break;
- }
-
case kSkip: {
- current++;
+ int size = source_->GetInt();
+ current = reinterpret_cast<Object**>(
+ reinterpret_cast<intptr_t>(current) + size);
break;
}
@@ -1132,18 +1026,20 @@
UNREACHABLE();
}
}
- ASSERT_EQ(current, limit);
+ ASSERT_EQ(limit, current);
}
void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
- const int max_shift = ((kPointerSize * kBitsPerByte) / 7) * 7;
- for (int shift = max_shift; shift > 0; shift -= 7) {
- if (integer >= static_cast<uintptr_t>(1u) << shift) {
- Put((static_cast<int>((integer >> shift)) & 0x7f) | 0x80, "IntPart");
- }
- }
- PutSection(static_cast<int>(integer & 0x7f), "IntLastPart");
+ 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");
}
@@ -1151,7 +1047,6 @@
: sink_(sink),
current_root_index_(0),
external_reference_encoder_(new ExternalReferenceEncoder),
- large_object_total_(0),
root_index_wave_front_(0) {
isolate_ = Isolate::Current();
// The serializer is meant to be used only to generate initial heap images
@@ -1184,6 +1079,7 @@
void PartialSerializer::Serialize(Object** object) {
this->VisitPointer(object);
+ Pad();
}
@@ -1198,14 +1094,14 @@
if (reinterpret_cast<Address>(current) ==
isolate->heap()->store_buffer()->TopAddress()) {
sink_->Put(kSkip, "Skip");
+ sink_->PutInt(kPointerSize, "SkipOneWord");
} else if ((*current)->IsSmi()) {
- sink_->Put(kRawData, "RawData");
- sink_->PutInt(kPointerSize, "length");
+ sink_->Put(kRawData + 1, "Smi");
for (int i = 0; i < kPointerSize; i++) {
sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
}
} else {
- SerializeObject(*current, kPlain, kStartOfObject);
+ SerializeObject(*current, kPlain, kStartOfObject, 0);
}
}
}
@@ -1292,58 +1188,50 @@
int space,
int address,
HowToCode how_to_code,
- WhereToPoint where_to_point) {
+ WhereToPoint where_to_point,
+ int skip) {
int offset = CurrentAllocationAddress(space) - address;
- bool from_start = true;
- if (SpaceIsPaged(space)) {
- // For paged space it is simple to encode back from current allocation if
- // the object is on the same page as the current allocation pointer.
- if ((CurrentAllocationAddress(space) >> kPageSizeBits) ==
- (address >> kPageSizeBits)) {
- from_start = false;
- address = offset;
- }
- } else if (space == NEW_SPACE) {
- // For new space it is always simple to encode back from current allocation.
- if (offset < address) {
- from_start = false;
- address = offset;
- }
- }
- // If we are actually dealing with real offsets (and not a numbering of
- // all objects) then we should shift out the bits that are always 0.
- if (!SpaceIsLarge(space)) address >>= kObjectAlignmentBits;
- if (from_start) {
- sink_->Put(kFromStart + how_to_code + where_to_point + space, "RefSer");
- sink_->PutInt(address, "address");
- } else {
+ // Shift out the bits that are always 0.
+ offset >>= kObjectAlignmentBits;
+ if (skip == 0) {
sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRefSer");
- sink_->PutInt(address, "address");
+ } else {
+ sink_->Put(kBackrefWithSkip + how_to_code + where_to_point + space,
+ "BackRefSerWithSkip");
+ sink_->PutInt(skip, "BackRefSkipDistance");
}
+ sink_->PutInt(offset, "offset");
}
void StartupSerializer::SerializeObject(
Object* o,
HowToCode how_to_code,
- WhereToPoint where_to_point) {
+ WhereToPoint where_to_point,
+ int skip) {
CHECK(o->IsHeapObject());
HeapObject* heap_object = HeapObject::cast(o);
int root_index;
if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) {
- PutRoot(root_index, heap_object, how_to_code, where_to_point);
+ PutRoot(root_index, heap_object, how_to_code, where_to_point, skip);
return;
}
if (address_mapper_.IsMapped(heap_object)) {
- int space = SpaceOfAlreadySerializedObject(heap_object);
+ int space = SpaceOfObject(heap_object);
int address = address_mapper_.MappedTo(heap_object);
SerializeReferenceToPreviousObject(space,
address,
how_to_code,
- where_to_point);
+ where_to_point,
+ skip);
} else {
+ if (skip != 0) {
+ sink_->Put(kSkip, "FlushPendingSkip");
+ sink_->PutInt(skip, "SkipDistance");
+ }
+
// Object has not yet been serialized. Serialize it here.
ObjectSerializer object_serializer(this,
heap_object,
@@ -1365,25 +1253,32 @@
Object* undefined = isolate->heap()->undefined_value();
VisitPointer(&undefined);
HEAP->IterateWeakRoots(this, VISIT_ALL);
+ Pad();
}
void Serializer::PutRoot(int root_index,
HeapObject* object,
SerializerDeserializer::HowToCode how_to_code,
- SerializerDeserializer::WhereToPoint where_to_point) {
+ SerializerDeserializer::WhereToPoint where_to_point,
+ int skip) {
if (how_to_code == kPlain &&
where_to_point == kStartOfObject &&
root_index < kRootArrayNumberOfConstantEncodings &&
!HEAP->InNewSpace(object)) {
- if (root_index < kRootArrayNumberOfLowConstantEncodings) {
- sink_->Put(kRootArrayLowConstants + root_index, "RootLoConstant");
+ if (skip == 0) {
+ sink_->Put(kRootArrayConstants + kNoSkipDistance + root_index,
+ "RootConstant");
} else {
- sink_->Put(kRootArrayHighConstants + root_index -
- kRootArrayNumberOfLowConstantEncodings,
- "RootHiConstant");
+ sink_->Put(kRootArrayConstants + kHasSkipDistance + root_index,
+ "RootConstant");
+ sink_->PutInt(skip, "SkipInPutRoot");
}
} else {
+ if (skip != 0) {
+ sink_->Put(kSkip, "SkipFromPutRoot");
+ sink_->PutInt(skip, "SkipFromPutRootDistance");
+ }
sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
sink_->PutInt(root_index, "root_index");
}
@@ -1393,7 +1288,8 @@
void PartialSerializer::SerializeObject(
Object* o,
HowToCode how_to_code,
- WhereToPoint where_to_point) {
+ WhereToPoint where_to_point,
+ int skip) {
CHECK(o->IsHeapObject());
HeapObject* heap_object = HeapObject::cast(o);
@@ -1406,11 +1302,16 @@
int root_index;
if ((root_index = RootIndex(heap_object, how_to_code)) != kInvalidRootIndex) {
- PutRoot(root_index, heap_object, how_to_code, where_to_point);
+ PutRoot(root_index, heap_object, how_to_code, where_to_point, skip);
return;
}
if (ShouldBeInThePartialSnapshotCache(heap_object)) {
+ if (skip != 0) {
+ sink_->Put(kSkip, "SkipFromSerializeObject");
+ sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
+ }
+
int cache_index = PartialSnapshotCacheIndex(heap_object);
sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point,
"PartialSnapshotCache");
@@ -1427,13 +1328,18 @@
ASSERT(!heap_object->IsSymbol());
if (address_mapper_.IsMapped(heap_object)) {
- int space = SpaceOfAlreadySerializedObject(heap_object);
+ int space = SpaceOfObject(heap_object);
int address = address_mapper_.MappedTo(heap_object);
SerializeReferenceToPreviousObject(space,
address,
how_to_code,
- where_to_point);
+ where_to_point,
+ skip);
} else {
+ if (skip != 0) {
+ sink_->Put(kSkip, "SkipFromSerializeObject");
+ sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
+ }
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this,
heap_object,
@@ -1457,16 +1363,11 @@
SnapshotPositionEvent(object_->address(), sink_->Position()));
// Mark this object as already serialized.
- bool start_new_page;
- int offset = serializer_->Allocate(space, size, &start_new_page);
+ int offset = serializer_->Allocate(space, size);
serializer_->address_mapper()->AddMapping(object_, offset);
- if (start_new_page) {
- sink_->Put(kNewPage, "NewPage");
- sink_->PutSection(space, "NewPageSpace");
- }
// Serialize the map (first word of the object).
- serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject);
+ serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0);
// Serialize the rest of the object.
CHECK_EQ(0, bytes_processed_so_far_);
@@ -1507,7 +1408,8 @@
sink_->Put(CodeForRepeats(repeat_count), "SerializeRepeats");
}
} else {
- serializer_->SerializeObject(current_contents, kPlain, kStartOfObject);
+ serializer_->SerializeObject(
+ current_contents, kPlain, kStartOfObject, 0);
bytes_processed_so_far_ += kPointerSize;
current++;
}
@@ -1519,9 +1421,10 @@
void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) {
Object** current = rinfo->target_object_address();
- OutputRawData(rinfo->target_address_address());
+ int skip = OutputRawData(rinfo->target_address_address(),
+ kCanReturnSkipInsteadOfSkipping);
HowToCode representation = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
- serializer_->SerializeObject(*current, representation, kStartOfObject);
+ serializer_->SerializeObject(*current, representation, kStartOfObject, skip);
bytes_processed_so_far_ += rinfo->target_address_size();
}
@@ -1529,10 +1432,12 @@
void Serializer::ObjectSerializer::VisitExternalReferences(Address* start,
Address* end) {
Address references_start = reinterpret_cast<Address>(start);
- OutputRawData(references_start);
+ int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping);
for (Address* current = start; current < end; current++) {
sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
+ sink_->PutInt(skip, "SkipB4ExternalRef");
+ skip = 0;
int reference_id = serializer_->EncodeExternalReference(*current);
sink_->PutInt(reference_id, "reference id");
}
@@ -1542,12 +1447,13 @@
void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) {
Address references_start = rinfo->target_address_address();
- OutputRawData(references_start);
+ int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping);
Address* current = rinfo->target_reference_address();
int representation = rinfo->IsCodedSpecially() ?
kFromCode + kStartOfObject : kPlain + kStartOfObject;
sink_->Put(kExternalReference + representation, "ExternalRef");
+ sink_->PutInt(skip, "SkipB4ExternalRef");
int reference_id = serializer_->EncodeExternalReference(*current);
sink_->PutInt(reference_id, "reference id");
bytes_processed_so_far_ += rinfo->target_address_size();
@@ -1556,7 +1462,7 @@
void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
Address target_start = rinfo->target_address_address();
- OutputRawData(target_start);
+ int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping);
Address target = rinfo->target_address();
uint32_t encoding = serializer_->EncodeExternalReference(target);
CHECK(target == NULL ? encoding == 0 : encoding != 0);
@@ -1568,6 +1474,7 @@
representation = kStartOfObject + kPlain;
}
sink_->Put(kExternalReference + representation, "ExternalReference");
+ sink_->PutInt(skip, "SkipB4ExternalRef");
sink_->PutInt(encoding, "reference id");
bytes_processed_so_far_ += rinfo->target_address_size();
}
@@ -1576,17 +1483,17 @@
void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) {
CHECK(RelocInfo::IsCodeTarget(rinfo->rmode()));
Address target_start = rinfo->target_address_address();
- OutputRawData(target_start);
+ int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping);
Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
- serializer_->SerializeObject(target, kFromCode, kInnerPointer);
+ serializer_->SerializeObject(target, kFromCode, kInnerPointer, skip);
bytes_processed_so_far_ += rinfo->target_address_size();
}
void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) {
Code* target = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
- OutputRawData(entry_address);
- serializer_->SerializeObject(target, kPlain, kInnerPointer);
+ int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping);
+ serializer_->SerializeObject(target, kPlain, kInnerPointer, skip);
bytes_processed_so_far_ += kPointerSize;
}
@@ -1595,8 +1502,8 @@
ASSERT(rinfo->rmode() == RelocInfo::GLOBAL_PROPERTY_CELL);
JSGlobalPropertyCell* cell =
JSGlobalPropertyCell::cast(rinfo->target_cell());
- OutputRawData(rinfo->pc());
- serializer_->SerializeObject(cell, kPlain, kInnerPointer);
+ int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping);
+ serializer_->SerializeObject(cell, kPlain, kInnerPointer, skip);
}
@@ -1624,31 +1531,50 @@
}
-void Serializer::ObjectSerializer::OutputRawData(Address up_to) {
+int Serializer::ObjectSerializer::OutputRawData(
+ Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) {
Address object_start = object_->address();
+ Address base = object_start + bytes_processed_so_far_;
int up_to_offset = static_cast<int>(up_to - object_start);
- int skipped = up_to_offset - bytes_processed_so_far_;
+ int to_skip = up_to_offset - bytes_processed_so_far_;
+ int bytes_to_output = to_skip;
+ bytes_processed_so_far_ += to_skip;
// 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.
- ASSERT(skipped >= 0);
- if (skipped != 0) {
- Address base = object_start + bytes_processed_so_far_;
-#define RAW_CASE(index, length) \
- if (skipped == length) { \
+ 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) { \
sink_->PutSection(kRawData + index, "RawDataFixed"); \
+ to_skip = 0; /* This insn already skips. */ \
} else /* NOLINT */
COMMON_RAW_LENGTHS(RAW_CASE)
#undef RAW_CASE
{ /* NOLINT */
+ // We always end up here if we are outputting the code of a code object.
sink_->Put(kRawData, "RawData");
- sink_->PutInt(skipped, "length");
+ sink_->PutInt(bytes_to_output, "length");
}
- for (int i = 0; i < skipped; i++) {
+ for (int i = 0; i < bytes_to_output; i++) {
unsigned int data = base[i];
sink_->PutSection(data, "Byte");
}
- bytes_processed_so_far_ += skipped;
}
+ if (to_skip != 0 && return_skip == kIgnoringReturn) {
+ sink_->Put(kSkip, "Skip");
+ sink_->PutInt(to_skip, "SkipDistance");
+ to_skip = 0;
+ }
+ return to_skip;
}
@@ -1656,15 +1582,7 @@
for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
AllocationSpace s = static_cast<AllocationSpace>(i);
if (HEAP->InSpace(object, s)) {
- if (i == LO_SPACE) {
- if (object->IsCode()) {
- return kLargeCode;
- } else if (object->IsFixedArray()) {
- return kLargeFixedArray;
- } else {
- return kLargeData;
- }
- }
+ ASSERT(i < kNumberOfSpaces);
return i;
}
}
@@ -1673,46 +1591,8 @@
}
-int Serializer::SpaceOfAlreadySerializedObject(HeapObject* object) {
- for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
- AllocationSpace s = static_cast<AllocationSpace>(i);
- if (HEAP->InSpace(object, s)) {
- return i;
- }
- }
- UNREACHABLE();
- return 0;
-}
-
-
-int Serializer::Allocate(int space, int size, bool* new_page) {
+int Serializer::Allocate(int space, int size) {
CHECK(space >= 0 && space < kNumberOfSpaces);
- if (SpaceIsLarge(space)) {
- // In large object space we merely number the objects instead of trying to
- // determine some sort of address.
- *new_page = true;
- large_object_total_ += size;
- return fullness_[LO_SPACE]++;
- }
- *new_page = false;
- if (fullness_[space] == 0) {
- *new_page = true;
- }
- if (SpaceIsPaged(space)) {
- // Paged spaces are a little special. We encode their addresses as if the
- // pages were all contiguous and each page were filled up in the range
- // 0 - Page::kObjectAreaSize. In practice the pages may not be contiguous
- // and allocation does not start at offset 0 in the page, but this scheme
- // means the deserializer can get the page number quickly by shifting the
- // serialized address.
- CHECK(IsPowerOf2(Page::kPageSize));
- int used_in_this_page = (fullness_[space] & (Page::kPageSize - 1));
- CHECK(size <= SpaceAreaSize(space));
- if (used_in_this_page + size > SpaceAreaSize(space)) {
- *new_page = true;
- fullness_[space] = RoundUp(fullness_[space], Page::kPageSize);
- }
- }
int allocation_address = fullness_[space];
fullness_[space] = allocation_address + size;
return allocation_address;
@@ -1728,4 +1608,21 @@
}
+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() {
+ if (0u + length_ - position_ > sizeof(uint32_t)) return false;
+ for (int x = position_; x < length_; x++) {
+ if (data_[x] != SerializerDeserializer::nop()) return false;
+ }
+ return true;
+}
+
} } // namespace v8::internal
« no previous file with comments | « src/serialize.h ('k') | src/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698