Commit ba8bbee6 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Serialize builtins by referencing canonical ones.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/383173002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22371 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5c8d0d18
This diff is collapsed.
......@@ -148,17 +148,18 @@ class SerializerDeserializer: public ObjectVisitor {
protected:
// Where the pointed-to object can be found:
enum Where {
kNewObject = 0, // Object is next in snapshot.
kNewObject = 0, // Object is next in snapshot.
// 1-6 One per space.
kRootArray = 0x9, // Object is found in root array.
kPartialSnapshotCache = 0xa, // Object is in the cache.
kExternalReference = 0xb, // Pointer to an external reference.
kSkip = 0xc, // Skip n bytes.
kNop = 0xd, // Does nothing, used to pad.
// 0xe-0xf Free.
kBackref = 0x10, // Object is described relative to end.
kRootArray = 0x9, // Object is found in root array.
kPartialSnapshotCache = 0xa, // Object is in the cache.
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.
// 0x11-0x16 One per space.
kBackrefWithSkip = 0x18, // Object is described relative to end.
kBackrefWithSkip = 0x18, // Object is described relative to end.
// 0x19-0x1e One per space.
// 0x20-0x3f Used by misc. tags below.
kPointedToMask = 0x3f
......@@ -566,14 +567,9 @@ class CodeSerializer : public Serializer {
static Object* Deserialize(Isolate* isolate, ScriptData* data);
// The data header consists of int-sized entries:
// [0] version hash
// [1] length in bytes
// [2..8] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
static const int kHeaderSize = 9;
static const int kVersionHashOffset = 0;
static const int kPayloadLengthOffset = 1;
static const int kReservationsOffset = 2;
private:
void SerializeBuiltin(Code* builtin, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
};
......
......@@ -399,48 +399,6 @@ TEST(OptimizedCodeSharing) {
}
TEST(SerializeToplevel) {
FLAG_serialize_toplevel = true;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION);
v8::Context::Scope context_scope(context);
const char* source1 = "1 + 1";
const char* source2 = "1 + 2"; // Use alternate string to verify caching.
Isolate* isolate = CcTest::i_isolate();
Handle<String> source1_string = isolate->factory()
->NewStringFromUtf8(CStrVector(source1))
.ToHandleChecked();
Handle<String> source2_string = isolate->factory()
->NewStringFromUtf8(CStrVector(source2))
.ToHandleChecked();
ScriptData* cache = NULL;
Handle<SharedFunctionInfo> orig =
Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
Handle<SharedFunctionInfo> info =
Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
CHECK_NE(*orig, *info);
Handle<JSFunction> fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
info, isolate->native_context());
Handle<JSObject> global(isolate->context()->global_object());
Handle<Object> result =
Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked();
CHECK_EQ(2, Handle<Smi>::cast(result)->value());
delete cache;
}
#ifdef ENABLE_DISASSEMBLER
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
const char* property_name) {
......
......@@ -661,3 +661,62 @@ DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
bool ArtificialFailure2 = false;
CHECK(ArtificialFailure2);
}
int CountBuiltins() {
// Check that we have not deserialized any additional builtin.
HeapIterator iterator(CcTest::heap());
DisallowHeapAllocation no_allocation;
int counter = 0;
for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++;
}
return counter;
}
TEST(SerializeToplevel) {
FLAG_serialize_toplevel = true;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION);
v8::Context::Scope context_scope(context);
const char* source1 = "1 + 1";
const char* source2 = "1 + 2"; // Use alternate string to verify caching.
Isolate* isolate = CcTest::i_isolate();
Handle<String> source1_string = isolate->factory()
->NewStringFromUtf8(CStrVector(source1))
.ToHandleChecked();
Handle<String> source2_string = isolate->factory()
->NewStringFromUtf8(CStrVector(source2))
.ToHandleChecked();
ScriptData* cache = NULL;
Handle<SharedFunctionInfo> orig =
Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
int builtins_count = CountBuiltins();
Handle<SharedFunctionInfo> info =
Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false,
Handle<Context>(isolate->native_context()), NULL,
&cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
CHECK_NE(*orig, *info);
Handle<JSFunction> fun =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
info, isolate->native_context());
Handle<JSObject> global(isolate->context()->global_object());
Handle<Object> result =
Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked();
CHECK_EQ(2, Handle<Smi>::cast(result)->value());
CHECK_EQ(builtins_count, CountBuiltins());
delete cache;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment