Revision: 22403
Author: [email protected]
Date: Tue Jul 15 10:17:22 2014 UTC
Log: Do not dump user source code in the code serializer.
[email protected]
Review URL: https://codereview.chromium.org/390303002
http://code.google.com/p/v8/source/detail?r=22403
Modified:
/branches/bleeding_edge/src/assembler.h
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/serialize.cc
/branches/bleeding_edge/src/serialize.h
/branches/bleeding_edge/test/cctest/test-serialize.cc
=======================================
--- /branches/bleeding_edge/src/assembler.h Thu Jul 10 14:41:06 2014 UTC
+++ /branches/bleeding_edge/src/assembler.h Tue Jul 15 10:17:22 2014 UTC
@@ -972,17 +972,6 @@
private:
explicit ExternalReference(void* address)
: address_(address) {}
-
- static void* Redirect(Isolate* isolate,
- void* address,
- Type type = ExternalReference::BUILTIN_CALL) {
- ExternalReferenceRedirector* redirector =
- reinterpret_cast<ExternalReferenceRedirector*>(
- isolate->external_reference_redirector());
- if (redirector == NULL) return address;
- void* answer = (*redirector)(address, type);
- return answer;
- }
static void* Redirect(Isolate* isolate,
Address address_arg,
=======================================
--- /branches/bleeding_edge/src/compiler.cc Fri Jul 11 06:58:25 2014 UTC
+++ /branches/bleeding_edge/src/compiler.cc Tue Jul 15 10:17:22 2014 UTC
@@ -967,8 +967,7 @@
is_shared_cross_origin, context);
if (maybe_result.is_null() && FLAG_serialize_toplevel &&
cached_data_mode == CONSUME_CACHED_DATA) {
- Object* des = CodeSerializer::Deserialize(isolate, *cached_data);
- return handle(SharedFunctionInfo::cast(des), isolate);
+ return CodeSerializer::Deserialize(isolate, *cached_data, source);
}
}
@@ -1002,7 +1001,7 @@
if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result);
if (FLAG_serialize_toplevel && cached_data_mode ==
PRODUCE_CACHED_DATA) {
- *cached_data = CodeSerializer::Serialize(result);
+ *cached_data = CodeSerializer::Serialize(isolate, result, source);
}
}
if (result.is_null()) isolate->ReportPendingMessages();
=======================================
--- /branches/bleeding_edge/src/serialize.cc Tue Jul 15 08:46:47 2014 UTC
+++ /branches/bleeding_edge/src/serialize.cc Tue Jul 15 10:17:22 2014 UTC
@@ -718,7 +718,7 @@
Deserializer::Deserializer(SnapshotByteSource* source)
: isolate_(NULL),
- deserialize_code_(false),
+ attached_objects_(NULL),
source_(source),
external_reference_decoder_(NULL) {
for (int i = 0; i < LAST_SPACE + 1; i++) {
@@ -905,7 +905,7 @@
if (obj->IsAllocationSite())
RelinkAllocationSite(AllocationSite::cast(obj));
// Fix up strings from serialized user code.
- if (deserialize_code_) obj = ProcessObjectFromSerializedCode(obj);
+ if (deserializing_user_code()) obj =
ProcessObjectFromSerializedCode(obj);
*write_back = obj;
#ifdef DEBUG
@@ -971,13 +971,18 @@
emit_write_barrier = (space_number ==
NEW_SPACE); \
new_object = GetAddressFromEnd(data &
kSpaceMask); \
} else if (where == kBuiltin)
{ \
-
ASSERT(deserialize_code_); \
+
ASSERT(deserializing_user_code()); \
int builtin_id =
source_->GetInt(); \
ASSERT_LE(0,
builtin_id); \
ASSERT_LT(builtin_id,
Builtins::builtin_count); \
Builtins::Name name =
static_cast<Builtins::Name>(builtin_id); \
new_object =
isolate->builtins()->builtin(name); \
emit_write_barrier =
false; \
+ } else if (where == kAttachedReference)
{ \
+
ASSERT(deserializing_user_code()); \
+ int index =
source_->GetInt(); \
+ new_object =
attached_objects_->at(index); \
+ emit_write_barrier =
isolate->heap()->InNewSpace(new_object); \
} else
{ \
ASSERT(where ==
kBackrefWithSkip); \
int skip =
source_->GetInt(); \
@@ -1222,6 +1227,10 @@
// Find a builtin and write a pointer to it in the current code
object.
CASE_STATEMENT(kBuiltin, kFromCode, kInnerPointer, 0)
CASE_BODY(kBuiltin, kFromCode, kInnerPointer, 0)
+ // Find an object in the attached references and write a pointer to
it to
+ // the current object.
+ CASE_STATEMENT(kAttachedReference, kPlain, kStartOfObject, 0)
+ CASE_BODY(kAttachedReference, kPlain, kStartOfObject, 0)
#undef CASE_STATEMENT
#undef CASE_BODY
@@ -1875,12 +1884,13 @@
}
-ScriptData* CodeSerializer::Serialize(Handle<SharedFunctionInfo> info) {
+ScriptData* CodeSerializer::Serialize(Isolate* isolate,
+ Handle<SharedFunctionInfo> info,
+ Handle<String> source) {
// Serialize code object.
List<byte> payload;
ListSnapshotSink list_sink(&payload);
- CodeSerializer cs(info->GetIsolate(), &list_sink);
- DisallowHeapAllocation no_gc;
+ CodeSerializer cs(isolate, &list_sink, *source);
Object** location = Handle<Object>::cast(info).location();
cs.VisitPointer(location);
cs.Pad();
@@ -1908,10 +1918,18 @@
}
// TODO(yangguo) wire up stubs from stub cache.
- // TODO(yangguo) wire up script source.
+ // TODO(yangguo) wire up global object.
// TODO(yangguo) We cannot deal with different hash seeds yet.
ASSERT(!heap_object->IsHashTable());
+ if (address_mapper_.IsMapped(heap_object)) {
+ int space = SpaceOfObject(heap_object);
+ int address = address_mapper_.MappedTo(heap_object);
+ SerializeReferenceToPreviousObject(space, address, how_to_code,
+ where_to_point, skip);
+ return;
+ }
+
if (heap_object->IsCode()) {
Code* code_object = Code::cast(heap_object);
if (code_object->kind() == Code::BUILTIN) {
@@ -1920,11 +1938,8 @@
}
}
- if (address_mapper_.IsMapped(heap_object)) {
- int space = SpaceOfObject(heap_object);
- int address = address_mapper_.MappedTo(heap_object);
- SerializeReferenceToPreviousObject(space, address, how_to_code,
- where_to_point, skip);
+ if (heap_object == source_) {
+ SerializeSourceObject(how_to_code, where_to_point, skip);
return;
}
@@ -1960,21 +1975,42 @@
}
-Object* CodeSerializer::Deserialize(Isolate* isolate, ScriptData* data) {
+void CodeSerializer::SerializeSourceObject(HowToCode how_to_code,
+ WhereToPoint where_to_point,
+ int skip) {
+ if (skip != 0) {
+ sink_->Put(kSkip, "SkipFromSerializeSourceObject");
+ sink_->PutInt(skip, "SkipDistanceFromSerializeSourceObject");
+ }
+
+ ASSERT(how_to_code == kPlain && where_to_point == kStartOfObject);
+ sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source");
+ sink_->PutInt(kSourceObjectIndex, "kSourceObjectIndex");
+}
+
+
+Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate,
+ ScriptData* data,
+ Handle<String>
source) {
SerializedCodeData scd(data);
SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
Deserializer deserializer(&payload);
- deserializer.ExpectSerializedCode();
STATIC_ASSERT(NEW_SPACE == 0);
// TODO(yangguo) what happens if remaining new space is too small?
for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
deserializer.set_reservation(i, scd.GetReservation(i));
}
+ DisallowHeapAllocation no_gc;
+
+ // Prepare and register list of attached objects.
+ List<Object*> attached_objects(1);
+ attached_objects.Set(kSourceObjectIndex, *source);
+ deserializer.SetAttachedObjects(&attached_objects);
+
Object* root;
deserializer.DeserializePartial(isolate, &root);
deserializer.FlushICacheForNewCodeObjects();
- ASSERT(root->IsSharedFunctionInfo());
- return root;
+ return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root),
isolate);
}
=======================================
--- /branches/bleeding_edge/src/serialize.h Tue Jul 15 08:46:47 2014 UTC
+++ /branches/bleeding_edge/src/serialize.h Tue Jul 15 10:17:22 2014 UTC
@@ -155,9 +155,9 @@
kExternalReference = 0xb, // Pointer to an external reference.
kSkip = 0xc, // Skip n bytes.
kBuiltin = 0xd, // Builtin code object.
- // 0xe Free.
- kNop = 0xf, // Does nothing, used to pad.
- kBackref = 0x10, // Object is described relative to end.
+ kAttachedReference = 0xe, // Object is described in an attached
list.
+ kNop = 0xf, // Does nothing, used to pad.
+ kBackref = 0x10, // Object is described relative to end.
// 0x11-0x16 One per space.
kBackrefWithSkip = 0x18, // Object is described relative to end.
// 0x19-0x1e One per space.
@@ -252,9 +252,13 @@
void FlushICacheForNewCodeObjects();
- // Call this to indicate that the serialized data represents user code.
- // There are some more wiring up required in this case.
- void ExpectSerializedCode() { deserialize_code_ = true; }
+ // Serialized user code reference certain objects that are provided in a
list
+ // By calling this method, we assume that we are deserializing user code.
+ void SetAttachedObjects(List<Object*>* attached_objects) {
+ attached_objects_ = attached_objects;
+ }
+
+ bool deserializing_user_code() { return attached_objects_ != NULL; }
private:
virtual void VisitPointers(Object** start, Object** end);
@@ -297,7 +301,9 @@
// Cached current isolate.
Isolate* isolate_;
- bool deserialize_code_;
+
+ // Objects from the attached object descriptions in the serialized user
code.
+ List<Object*>* attached_objects_;
SnapshotByteSource* source_;
// This is the address of the next object that will be allocated in each
@@ -557,26 +563,42 @@
SerializeWeakReferences();
Pad();
}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StartupSerializer);
};
class CodeSerializer : public Serializer {
public:
- CodeSerializer(Isolate* isolate, SnapshotByteSink* sink)
- : Serializer(isolate, sink) {
+ CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source)
+ : Serializer(isolate, sink), source_(source) {
set_root_index_wave_front(Heap::kStrongRootListLength);
InitializeCodeAddressMap();
}
- static ScriptData* Serialize(Handle<SharedFunctionInfo> info);
+ static ScriptData* Serialize(Isolate* isolate,
+ Handle<SharedFunctionInfo> info,
+ Handle<String> source);
+
virtual void SerializeObject(Object* o, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
- static Object* Deserialize(Isolate* isolate, ScriptData* data);
+ static Handle<SharedFunctionInfo> Deserialize(Isolate* isolate,
+ ScriptData* data,
+ Handle<String> source);
+
+ static const int kSourceObjectIndex = 0;
private:
void SerializeBuiltin(Code* builtin, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
+ void SerializeSourceObject(HowToCode how_to_code, WhereToPoint
where_to_point,
+ int skip);
+
+ DisallowHeapAllocation no_gc_;
+ String* source_;
+ DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
};
=======================================
--- /branches/bleeding_edge/test/cctest/test-serialize.cc Tue Jul 15
08:46:47 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-serialize.cc Tue Jul 15
10:17:22 2014 UTC
@@ -707,6 +707,8 @@
&cache, CONSUME_CACHED_DATA,
NOT_NATIVES_CODE);
CHECK_NE(*orig, *copy);
+ CHECK(Script::cast(copy->script())->source() == *source2_string);
+
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
copy, isolate->native_context());
@@ -758,6 +760,8 @@
Handle<Context>(isolate->native_context()),
NULL,
&cache, CONSUME_CACHED_DATA,
NOT_NATIVES_CODE);
CHECK_NE(*orig, *copy);
+ CHECK(Script::cast(copy->script())->source() == *source2_string);
+
Handle<JSFunction> copy_fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
copy, isolate->native_context());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.