| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 CHECK(v8_isolate); | 415 CHECK(v8_isolate); |
| 416 startup_blob.Dispose(); | 416 startup_blob.Dispose(); |
| 417 { | 417 { |
| 418 v8::Isolate::Scope isolate_scope(v8_isolate); | 418 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 419 | 419 |
| 420 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 420 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 421 HandleScope handle_scope(isolate); | 421 HandleScope handle_scope(isolate); |
| 422 Handle<Object> root; | 422 Handle<Object> root; |
| 423 Handle<JSGlobalProxy> global_proxy = | 423 Handle<JSGlobalProxy> global_proxy = |
| 424 isolate->factory()->NewUninitializedJSGlobalProxy( | 424 isolate->factory()->NewUninitializedJSGlobalProxy( |
| 425 JSGlobalProxy::SizeWithInternalFields(0)); | 425 JSGlobalProxy::SizeWithEmbedderFields(0)); |
| 426 { | 426 { |
| 427 SnapshotData snapshot_data(partial_blob); | 427 SnapshotData snapshot_data(partial_blob); |
| 428 Deserializer deserializer(&snapshot_data); | 428 Deserializer deserializer(&snapshot_data); |
| 429 root = deserializer | 429 root = deserializer |
| 430 .DeserializePartial(isolate, global_proxy, | 430 .DeserializePartial(isolate, global_proxy, |
| 431 v8::DeserializeInternalFieldsCallback()) | 431 v8::DeserializeInternalFieldsCallback()) |
| 432 .ToHandleChecked(); | 432 .ToHandleChecked(); |
| 433 CHECK(root->IsContext()); | 433 CHECK(root->IsContext()); |
| 434 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); | 434 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); |
| 435 } | 435 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 CHECK(v8_isolate); | 540 CHECK(v8_isolate); |
| 541 startup_blob.Dispose(); | 541 startup_blob.Dispose(); |
| 542 { | 542 { |
| 543 v8::Isolate::Scope isolate_scope(v8_isolate); | 543 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 544 | 544 |
| 545 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 545 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 546 HandleScope handle_scope(isolate); | 546 HandleScope handle_scope(isolate); |
| 547 Handle<Object> root; | 547 Handle<Object> root; |
| 548 Handle<JSGlobalProxy> global_proxy = | 548 Handle<JSGlobalProxy> global_proxy = |
| 549 isolate->factory()->NewUninitializedJSGlobalProxy( | 549 isolate->factory()->NewUninitializedJSGlobalProxy( |
| 550 JSGlobalProxy::SizeWithInternalFields(0)); | 550 JSGlobalProxy::SizeWithEmbedderFields(0)); |
| 551 { | 551 { |
| 552 SnapshotData snapshot_data(partial_blob); | 552 SnapshotData snapshot_data(partial_blob); |
| 553 Deserializer deserializer(&snapshot_data); | 553 Deserializer deserializer(&snapshot_data); |
| 554 root = deserializer | 554 root = deserializer |
| 555 .DeserializePartial(isolate, global_proxy, | 555 .DeserializePartial(isolate, global_proxy, |
| 556 v8::DeserializeInternalFieldsCallback()) | 556 v8::DeserializeInternalFieldsCallback()) |
| 557 .ToHandleChecked(); | 557 .ToHandleChecked(); |
| 558 CHECK(root->IsContext()); | 558 CHECK(root->IsContext()); |
| 559 Handle<Context> context = Handle<Context>::cast(root); | 559 Handle<Context> context = Handle<Context>::cast(root); |
| 560 | 560 |
| (...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 delete[] blob.data; | 2082 delete[] blob.data; |
| 2083 } | 2083 } |
| 2084 | 2084 |
| 2085 struct InternalFieldData { | 2085 struct InternalFieldData { |
| 2086 uint32_t data; | 2086 uint32_t data; |
| 2087 }; | 2087 }; |
| 2088 | 2088 |
| 2089 v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, | 2089 v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, |
| 2090 void* data) { | 2090 void* data) { |
| 2091 CHECK_EQ(reinterpret_cast<void*>(2016), data); | 2091 CHECK_EQ(reinterpret_cast<void*>(2016), data); |
| 2092 InternalFieldData* internal_field = static_cast<InternalFieldData*>( | 2092 InternalFieldData* embedder_field = static_cast<InternalFieldData*>( |
| 2093 holder->GetAlignedPointerFromInternalField(index)); | 2093 holder->GetAlignedPointerFromInternalField(index)); |
| 2094 int size = sizeof(*internal_field); | 2094 int size = sizeof(*embedder_field); |
| 2095 char* payload = new char[size]; | 2095 char* payload = new char[size]; |
| 2096 // We simply use memcpy to serialize the content. | 2096 // We simply use memcpy to serialize the content. |
| 2097 memcpy(payload, internal_field, size); | 2097 memcpy(payload, embedder_field, size); |
| 2098 return {payload, size}; | 2098 return {payload, size}; |
| 2099 } | 2099 } |
| 2100 | 2100 |
| 2101 std::vector<InternalFieldData*> deserialized_data; | 2101 std::vector<InternalFieldData*> deserialized_data; |
| 2102 | 2102 |
| 2103 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, | 2103 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, |
| 2104 v8::StartupData payload, void* data) { | 2104 v8::StartupData payload, void* data) { |
| 2105 CHECK_EQ(reinterpret_cast<void*>(2017), data); | 2105 CHECK_EQ(reinterpret_cast<void*>(2017), data); |
| 2106 InternalFieldData* internal_field = new InternalFieldData{0}; | 2106 InternalFieldData* embedder_field = new InternalFieldData{0}; |
| 2107 memcpy(internal_field, payload.data, payload.raw_size); | 2107 memcpy(embedder_field, payload.data, payload.raw_size); |
| 2108 holder->SetAlignedPointerInInternalField(index, internal_field); | 2108 holder->SetAlignedPointerInInternalField(index, embedder_field); |
| 2109 deserialized_data.push_back(internal_field); | 2109 deserialized_data.push_back(embedder_field); |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 TEST(SnapshotCreatorTemplates) { | 2112 TEST(SnapshotCreatorTemplates) { |
| 2113 DisableAlwaysOpt(); | 2113 DisableAlwaysOpt(); |
| 2114 v8::StartupData blob; | 2114 v8::StartupData blob; |
| 2115 | 2115 |
| 2116 { | 2116 { |
| 2117 InternalFieldData* a1 = new InternalFieldData{11}; | 2117 InternalFieldData* a1 = new InternalFieldData{11}; |
| 2118 InternalFieldData* b0 = new InternalFieldData{20}; | 2118 InternalFieldData* b0 = new InternalFieldData{20}; |
| 2119 InternalFieldData* c0 = new InternalFieldData{30}; | 2119 InternalFieldData* c0 = new InternalFieldData{30}; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2208 v8::Local<v8::FunctionTemplate> fun_template = | 2208 v8::Local<v8::FunctionTemplate> fun_template = |
| 2209 v8::FunctionTemplate::FromSnapshot(isolate, 0).ToLocalChecked(); | 2209 v8::FunctionTemplate::FromSnapshot(isolate, 0).ToLocalChecked(); |
| 2210 CHECK(!fun_template.IsEmpty()); | 2210 CHECK(!fun_template.IsEmpty()); |
| 2211 v8::Local<v8::Function> fun = | 2211 v8::Local<v8::Function> fun = |
| 2212 fun_template->GetFunction(context).ToLocalChecked(); | 2212 fun_template->GetFunction(context).ToLocalChecked(); |
| 2213 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); | 2213 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); |
| 2214 ExpectInt32("g()", 42); | 2214 ExpectInt32("g()", 42); |
| 2215 // Check that it instantiates to the same prototype. | 2215 // Check that it instantiates to the same prototype. |
| 2216 ExpectTrue("g.prototype === f.prototype"); | 2216 ExpectTrue("g.prototype === f.prototype"); |
| 2217 | 2217 |
| 2218 // Retrieve internal fields. | 2218 // Retrieve embedder fields. |
| 2219 v8::Local<v8::Object> a = context->Global() | 2219 v8::Local<v8::Object> a = context->Global() |
| 2220 ->Get(context, v8_str("a")) | 2220 ->Get(context, v8_str("a")) |
| 2221 .ToLocalChecked() | 2221 .ToLocalChecked() |
| 2222 ->ToObject(context) | 2222 ->ToObject(context) |
| 2223 .ToLocalChecked(); | 2223 .ToLocalChecked(); |
| 2224 v8::Local<v8::Object> b = | 2224 v8::Local<v8::Object> b = |
| 2225 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); | 2225 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); |
| 2226 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( | 2226 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( |
| 2227 a->GetAlignedPointerFromInternalField(1)); | 2227 a->GetAlignedPointerFromInternalField(1)); |
| 2228 v8::Local<v8::Value> a2 = a->GetInternalField(2); | 2228 v8::Local<v8::Value> a2 = a->GetInternalField(2); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 } | 2459 } |
| 2460 delete[] blob.data; | 2460 delete[] blob.data; |
| 2461 } | 2461 } |
| 2462 | 2462 |
| 2463 TEST(SerializationMemoryStats) { | 2463 TEST(SerializationMemoryStats) { |
| 2464 FLAG_profile_deserialization = true; | 2464 FLAG_profile_deserialization = true; |
| 2465 FLAG_always_opt = false; | 2465 FLAG_always_opt = false; |
| 2466 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2466 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 2467 delete[] blob.data; | 2467 delete[] blob.data; |
| 2468 } | 2468 } |
| OLD | NEW |