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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 2490783004: [serializer] small fixes for blink snapshot. (Closed)
Patch Set: more fixes Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 2015
2016 void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 2016 void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
2017 args.GetReturnValue().Set(v8_num(42)); 2017 args.GetReturnValue().Set(v8_num(42));
2018 } 2018 }
2019 2019
2020 void SerializedCallbackReplacement( 2020 void SerializedCallbackReplacement(
2021 const v8::FunctionCallbackInfo<v8::Value>& args) { 2021 const v8::FunctionCallbackInfo<v8::Value>& args) {
2022 args.GetReturnValue().Set(v8_num(1337)); 2022 args.GetReturnValue().Set(v8_num(1337));
2023 } 2023 }
2024 2024
2025 static int serialized_static_field = 314;
vogelheim 2016/11/10 09:37:10 Huh?
Yang 2016/11/10 10:36:19 We are just checking that this static address is c
2026
2025 intptr_t original_external_references[] = { 2027 intptr_t original_external_references[] = {
2026 reinterpret_cast<intptr_t>(SerializedCallback), 0}; 2028 reinterpret_cast<intptr_t>(SerializedCallback),
2029 reinterpret_cast<intptr_t>(&serialized_static_field), 0};
2027 2030
2028 intptr_t replaced_external_references[] = { 2031 intptr_t replaced_external_references[] = {
2029 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0}; 2032 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0};
2030 2033
2031 TEST(SnapshotCreatorExternalReferences) { 2034 TEST(SnapshotCreatorExternalReferences) {
2032 DisableAlwaysOpt(); 2035 DisableAlwaysOpt();
2033 v8::StartupData blob; 2036 v8::StartupData blob;
2034 { 2037 {
2035 v8::SnapshotCreator creator(original_external_references); 2038 v8::SnapshotCreator creator(original_external_references);
2036 v8::Isolate* isolate = creator.GetIsolate(); 2039 v8::Isolate* isolate = creator.GetIsolate();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 } 2138 }
2136 2139
2137 TEST(SnapshotCreatorTemplates) { 2140 TEST(SnapshotCreatorTemplates) {
2138 DisableAlwaysOpt(); 2141 DisableAlwaysOpt();
2139 v8::StartupData blob; 2142 v8::StartupData blob;
2140 2143
2141 { 2144 {
2142 InternalFieldData* a1 = new InternalFieldData{11}; 2145 InternalFieldData* a1 = new InternalFieldData{11};
2143 InternalFieldData* b0 = new InternalFieldData{20}; 2146 InternalFieldData* b0 = new InternalFieldData{20};
2144 InternalFieldData* c0 = new InternalFieldData{30}; 2147 InternalFieldData* c0 = new InternalFieldData{30};
2145 InternalFieldData* c1 = new InternalFieldData{31};
2146 2148
2147 v8::SnapshotCreator creator(original_external_references); 2149 v8::SnapshotCreator creator(original_external_references);
2148 v8::Isolate* isolate = creator.GetIsolate(); 2150 v8::Isolate* isolate = creator.GetIsolate();
2149 { 2151 {
2150 v8::HandleScope handle_scope(isolate); 2152 v8::HandleScope handle_scope(isolate);
2151 v8::ExtensionConfiguration* no_extension = nullptr; 2153 v8::ExtensionConfiguration* no_extension = nullptr;
2152 v8::Local<v8::ObjectTemplate> global_template = 2154 v8::Local<v8::ObjectTemplate> global_template =
2153 v8::ObjectTemplate::New(isolate); 2155 v8::ObjectTemplate::New(isolate);
2154 v8::Local<v8::FunctionTemplate> callback = 2156 v8::Local<v8::FunctionTemplate> callback =
2155 v8::FunctionTemplate::New(isolate, SerializedCallback); 2157 v8::FunctionTemplate::New(isolate, SerializedCallback);
2156 global_template->Set(v8_str("f"), callback); 2158 global_template->Set(v8_str("f"), callback);
2157 v8::Local<v8::Context> context = 2159 v8::Local<v8::Context> context =
2158 v8::Context::New(isolate, no_extension, global_template); 2160 v8::Context::New(isolate, no_extension, global_template);
2159 v8::Local<v8::ObjectTemplate> object_template = 2161 v8::Local<v8::ObjectTemplate> object_template =
2160 v8::ObjectTemplate::New(isolate); 2162 v8::ObjectTemplate::New(isolate);
2161 object_template->SetInternalFieldCount(2); 2163 object_template->SetInternalFieldCount(3);
2162 2164
2163 v8::Context::Scope context_scope(context); 2165 v8::Context::Scope context_scope(context);
2164 ExpectInt32("f()", 42); 2166 ExpectInt32("f()", 42);
2165 2167
2166 v8::Local<v8::Object> a = 2168 v8::Local<v8::Object> a =
2167 object_template->NewInstance(context).ToLocalChecked(); 2169 object_template->NewInstance(context).ToLocalChecked();
2168 v8::Local<v8::Object> b = 2170 v8::Local<v8::Object> b =
2169 object_template->NewInstance(context).ToLocalChecked(); 2171 object_template->NewInstance(context).ToLocalChecked();
2170 v8::Local<v8::Object> c = 2172 v8::Local<v8::Object> c =
2171 object_template->NewInstance(context).ToLocalChecked(); 2173 object_template->NewInstance(context).ToLocalChecked();
2174 v8::Local<v8::External> null_external =
2175 v8::External::New(isolate, nullptr);
2176 v8::Local<v8::External> field_external =
2177 v8::External::New(isolate, &serialized_static_field);
2172 a->SetInternalField(0, b); 2178 a->SetInternalField(0, b);
2173 a->SetAlignedPointerInInternalField(1, a1); 2179 a->SetAlignedPointerInInternalField(1, a1);
2174 b->SetAlignedPointerInInternalField(0, b0); 2180 b->SetAlignedPointerInInternalField(0, b0);
2175 b->SetInternalField(1, c); 2181 b->SetInternalField(1, c);
2176 c->SetAlignedPointerInInternalField(0, c0); 2182 c->SetAlignedPointerInInternalField(0, c0);
2177 c->SetAlignedPointerInInternalField(1, c1); 2183 c->SetInternalField(1, null_external);
2184 c->SetInternalField(2, field_external);
2178 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); 2185 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust());
2179 2186
2180 CHECK_EQ(0, creator.AddContext(context)); 2187 CHECK_EQ(0, creator.AddContext(context));
2181 CHECK_EQ(0, creator.AddTemplate(callback)); 2188 CHECK_EQ(0, creator.AddTemplate(callback));
2182 CHECK_EQ(1, creator.AddTemplate(global_template)); 2189 CHECK_EQ(1, creator.AddTemplate(global_template));
2183 } 2190 }
2184 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, 2191 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear,
2185 SerializeInternalFields); 2192 SerializeInternalFields);
2186 2193
2187 delete a1; 2194 delete a1;
2188 delete b0; 2195 delete b0;
2189 delete c1;
2190 delete c0; 2196 delete c0;
2191 } 2197 }
2192 2198
2193 { 2199 {
2194 v8::Isolate::CreateParams params; 2200 v8::Isolate::CreateParams params;
2195 params.snapshot_blob = &blob; 2201 params.snapshot_blob = &blob;
2196 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2202 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2197 params.external_references = original_external_references; 2203 params.external_references = original_external_references;
2198 params.deserialize_internal_fields_callback = DeserializeInternalFields; 2204 params.deserialize_internal_fields_callback = DeserializeInternalFields;
2199 v8::Isolate* isolate = v8::Isolate::New(params); 2205 v8::Isolate* isolate = v8::Isolate::New(params);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 // Retrieve internal fields. 2238 // Retrieve internal fields.
2233 v8::Local<v8::Object> a = context->Global() 2239 v8::Local<v8::Object> a = context->Global()
2234 ->Get(context, v8_str("a")) 2240 ->Get(context, v8_str("a"))
2235 .ToLocalChecked() 2241 .ToLocalChecked()
2236 ->ToObject(context) 2242 ->ToObject(context)
2237 .ToLocalChecked(); 2243 .ToLocalChecked();
2238 v8::Local<v8::Object> b = 2244 v8::Local<v8::Object> b =
2239 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); 2245 a->GetInternalField(0)->ToObject(context).ToLocalChecked();
2240 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( 2246 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>(
2241 a->GetAlignedPointerFromInternalField(1)); 2247 a->GetAlignedPointerFromInternalField(1));
2248 v8::Local<v8::Value> a2 = a->GetInternalField(2);
2249
2242 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( 2250 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>(
2243 b->GetAlignedPointerFromInternalField(0)); 2251 b->GetAlignedPointerFromInternalField(0));
2244 v8::Local<v8::Object> c = 2252 v8::Local<v8::Object> c =
2245 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); 2253 b->GetInternalField(1)->ToObject(context).ToLocalChecked();
2254 v8::Local<v8::Value> b2 = b->GetInternalField(2);
2255
2246 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( 2256 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>(
2247 c->GetAlignedPointerFromInternalField(0)); 2257 c->GetAlignedPointerFromInternalField(0));
2248 InternalFieldData* c1 = reinterpret_cast<InternalFieldData*>( 2258 v8::Local<v8::Value> c1 = c->GetInternalField(1);
2249 c->GetAlignedPointerFromInternalField(1)); 2259 v8::Local<v8::Value> c2 = c->GetInternalField(2);
2250 2260
2251 CHECK_EQ(11, a1->data); 2261 CHECK_EQ(11, a1->data);
2262 CHECK(a2->IsUndefined());
2252 CHECK_EQ(20, b0->data); 2263 CHECK_EQ(20, b0->data);
2264 CHECK(b2->IsUndefined());
2253 CHECK_EQ(30, c0->data); 2265 CHECK_EQ(30, c0->data);
2254 CHECK_EQ(31, c1->data); 2266 CHECK(c1->IsExternal());
2267 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value());
2268 CHECK_EQ(static_cast<void*>(&serialized_static_field),
2269 v8::Local<v8::External>::Cast(c2)->Value());
2255 2270
2256 // Accessing out of bound returns empty MaybeHandle. 2271 // Accessing out of bound returns empty MaybeHandle.
2257 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); 2272 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty());
2258 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); 2273 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty());
2259 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); 2274 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty());
2260 2275
2261 delete a1; 2276 delete a1;
2262 delete b0; 2277 delete b0;
2263 delete c1;
2264 delete c0; 2278 delete c0;
2265 } 2279 }
2266 2280
2267 { 2281 {
2268 // Create a context with a new object template. It is merged into the 2282 // Create a context with a new object template. It is merged into the
2269 // deserialized global object. 2283 // deserialized global object.
2270 v8::HandleScope handle_scope(isolate); 2284 v8::HandleScope handle_scope(isolate);
2271 v8::ExtensionConfiguration* no_extension = nullptr; 2285 v8::ExtensionConfiguration* no_extension = nullptr;
2272 v8::Local<v8::ObjectTemplate> global_template = 2286 v8::Local<v8::ObjectTemplate> global_template =
2273 v8::ObjectTemplate::New(isolate); 2287 v8::ObjectTemplate::New(isolate);
(...skipping 12 matching lines...) Expand all
2286 } 2300 }
2287 delete[] blob.data; 2301 delete[] blob.data;
2288 } 2302 }
2289 2303
2290 TEST(SerializationMemoryStats) { 2304 TEST(SerializationMemoryStats) {
2291 FLAG_profile_deserialization = true; 2305 FLAG_profile_deserialization = true;
2292 FLAG_always_opt = false; 2306 FLAG_always_opt = false;
2293 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 2307 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
2294 delete[] blob.data; 2308 delete[] blob.data;
2295 } 2309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698