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

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

Issue 907013002: Add payload checksum to code cache data. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1237
1238 1238
1239 static void SerializerCodeEventListener(const v8::JitCodeEvent* event) { 1239 static void SerializerCodeEventListener(const v8::JitCodeEvent* event) {
1240 if (event->type == v8::JitCodeEvent::CODE_ADDED && 1240 if (event->type == v8::JitCodeEvent::CODE_ADDED &&
1241 memcmp(event->name.str, "Script:~test", 12) == 0) { 1241 memcmp(event->name.str, "Script:~test", 12) == 0) {
1242 toplevel_test_code_event_found = true; 1242 toplevel_test_code_event_found = true;
1243 } 1243 }
1244 } 1244 }
1245 1245
1246 1246
1247 TEST(SerializeToplevelIsolates) { 1247 v8::ScriptCompiler::CachedData* ProduceCache(const char* source) {
1248 FLAG_serialize_toplevel = true;
1249
1250 const char* source = "function f() { return 'abc'; }; f() + 'def'";
1251 v8::ScriptCompiler::CachedData* cache; 1248 v8::ScriptCompiler::CachedData* cache;
1252
1253 v8::Isolate* isolate1 = v8::Isolate::New(); 1249 v8::Isolate* isolate1 = v8::Isolate::New();
1254 { 1250 {
1255 v8::Isolate::Scope iscope(isolate1); 1251 v8::Isolate::Scope iscope(isolate1);
1256 v8::HandleScope scope(isolate1); 1252 v8::HandleScope scope(isolate1);
1257 v8::Local<v8::Context> context = v8::Context::New(isolate1); 1253 v8::Local<v8::Context> context = v8::Context::New(isolate1);
1258 v8::Context::Scope context_scope(context); 1254 v8::Context::Scope context_scope(context);
1259 1255
1260 v8::Local<v8::String> source_str = v8_str(source); 1256 v8::Local<v8::String> source_str = v8_str(source);
1261 v8::ScriptOrigin origin(v8_str("test")); 1257 v8::ScriptOrigin origin(v8_str("test"));
1262 v8::ScriptCompiler::Source source(source_str, origin); 1258 v8::ScriptCompiler::Source source(source_str, origin);
1263 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( 1259 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound(
1264 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache); 1260 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache);
1265 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); 1261 const v8::ScriptCompiler::CachedData* data = source.GetCachedData();
1266 CHECK(data); 1262 CHECK(data);
1267 // Persist cached data. 1263 // Persist cached data.
1268 uint8_t* buffer = NewArray<uint8_t>(data->length); 1264 uint8_t* buffer = NewArray<uint8_t>(data->length);
1269 MemCopy(buffer, data->data, data->length); 1265 MemCopy(buffer, data->data, data->length);
1270 cache = new v8::ScriptCompiler::CachedData( 1266 cache = new v8::ScriptCompiler::CachedData(
1271 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); 1267 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned);
1272 1268
1273 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1269 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1274 CHECK(result->ToString(isolate1)->Equals(v8_str("abcdef"))); 1270 CHECK(result->ToString(isolate1)->Equals(v8_str("abcdef")));
1275 } 1271 }
1276 isolate1->Dispose(); 1272 isolate1->Dispose();
1273 return cache;
1274 }
1275
1276
1277 TEST(SerializeToplevelIsolates) {
1278 FLAG_serialize_toplevel = true;
1279
1280 const char* source = "function f() { return 'abc'; }; f() + 'def'";
1281 v8::ScriptCompiler::CachedData* cache = ProduceCache(source);
1277 1282
1278 v8::Isolate* isolate2 = v8::Isolate::New(); 1283 v8::Isolate* isolate2 = v8::Isolate::New();
1279 isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault, 1284 isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault,
1280 SerializerCodeEventListener); 1285 SerializerCodeEventListener);
1281 toplevel_test_code_event_found = false; 1286 toplevel_test_code_event_found = false;
1282 { 1287 {
1283 v8::Isolate::Scope iscope(isolate2); 1288 v8::Isolate::Scope iscope(isolate2);
1284 v8::HandleScope scope(isolate2); 1289 v8::HandleScope scope(isolate2);
1285 v8::Local<v8::Context> context = v8::Context::New(isolate2); 1290 v8::Local<v8::Context> context = v8::Context::New(isolate2);
1286 v8::Context::Scope context_scope(context); 1291 v8::Context::Scope context_scope(context);
(...skipping 13 matching lines...) Expand all
1300 } 1305 }
1301 DCHECK(toplevel_test_code_event_found); 1306 DCHECK(toplevel_test_code_event_found);
1302 isolate2->Dispose(); 1307 isolate2->Dispose();
1303 } 1308 }
1304 1309
1305 1310
1306 TEST(SerializeToplevelFlagChange) { 1311 TEST(SerializeToplevelFlagChange) {
1307 FLAG_serialize_toplevel = true; 1312 FLAG_serialize_toplevel = true;
1308 1313
1309 const char* source = "function f() { return 'abc'; }; f() + 'def'"; 1314 const char* source = "function f() { return 'abc'; }; f() + 'def'";
1310 v8::ScriptCompiler::CachedData* cache; 1315 v8::ScriptCompiler::CachedData* cache = ProduceCache(source);
1311
1312 v8::Isolate* isolate1 = v8::Isolate::New();
1313 {
1314 v8::Isolate::Scope iscope(isolate1);
1315 v8::HandleScope scope(isolate1);
1316 v8::Local<v8::Context> context = v8::Context::New(isolate1);
1317 v8::Context::Scope context_scope(context);
1318
1319 v8::Local<v8::String> source_str = v8_str(source);
1320 v8::ScriptOrigin origin(v8_str("test"));
1321 v8::ScriptCompiler::Source source(source_str, origin);
1322 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound(
1323 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache);
1324 const v8::ScriptCompiler::CachedData* data = source.GetCachedData();
1325 CHECK(data);
1326 // Persist cached data.
1327 uint8_t* buffer = NewArray<uint8_t>(data->length);
1328 MemCopy(buffer, data->data, data->length);
1329 cache = new v8::ScriptCompiler::CachedData(
1330 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned);
1331
1332 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1333 CHECK(result->ToString(isolate1)->Equals(v8_str("abcdef")));
1334 }
1335 isolate1->Dispose();
1336 1316
1337 v8::Isolate* isolate2 = v8::Isolate::New(); 1317 v8::Isolate* isolate2 = v8::Isolate::New();
1338 FLAG_allow_natives_syntax = true; // Flag change should trigger cache reject. 1318 FLAG_allow_natives_syntax = true; // Flag change should trigger cache reject.
1339 { 1319 {
1340 v8::Isolate::Scope iscope(isolate2); 1320 v8::Isolate::Scope iscope(isolate2);
1341 v8::HandleScope scope(isolate2); 1321 v8::HandleScope scope(isolate2);
1322 v8::Local<v8::Context> context = v8::Context::New(isolate2);
1323 v8::Context::Scope context_scope(context);
1324
1325 v8::Local<v8::String> source_str = v8_str(source);
1326 v8::ScriptOrigin origin(v8_str("test"));
1327 v8::ScriptCompiler::Source source(source_str, origin, cache);
1328 v8::ScriptCompiler::CompileUnbound(isolate2, &source,
1329 v8::ScriptCompiler::kConsumeCodeCache);
1330 CHECK(cache->rejected);
1331 }
1332 isolate2->Dispose();
1333 }
1334
1335
1336 TEST(SerializeToplevelBitFlip) {
1337 FLAG_serialize_toplevel = true;
1338
1339 const char* source = "function f() { return 'abc'; }; f() + 'def'";
1340 v8::ScriptCompiler::CachedData* cache = ProduceCache(source);
1341
1342 // Random bit flip.
1343 const_cast<uint8_t*>(cache->data)[337] ^= 0x40;
1344
1345 v8::Isolate* isolate2 = v8::Isolate::New();
1346 {
1347 v8::Isolate::Scope iscope(isolate2);
1348 v8::HandleScope scope(isolate2);
1342 v8::Local<v8::Context> context = v8::Context::New(isolate2); 1349 v8::Local<v8::Context> context = v8::Context::New(isolate2);
1343 v8::Context::Scope context_scope(context); 1350 v8::Context::Scope context_scope(context);
1344 1351
1345 v8::Local<v8::String> source_str = v8_str(source); 1352 v8::Local<v8::String> source_str = v8_str(source);
1346 v8::ScriptOrigin origin(v8_str("test")); 1353 v8::ScriptOrigin origin(v8_str("test"));
1347 v8::ScriptCompiler::Source source(source_str, origin, cache); 1354 v8::ScriptCompiler::Source source(source_str, origin, cache);
1348 v8::ScriptCompiler::CompileUnbound(isolate2, &source, 1355 v8::ScriptCompiler::CompileUnbound(isolate2, &source,
1349 v8::ScriptCompiler::kConsumeCodeCache); 1356 v8::ScriptCompiler::kConsumeCodeCache);
1350 CHECK(cache->rejected); 1357 CHECK(cache->rejected);
1351 } 1358 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 { 1416 {
1410 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); 1417 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
1411 script = v8::ScriptCompiler::CompileUnbound( 1418 script = v8::ScriptCompiler::CompileUnbound(
1412 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); 1419 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
1413 } 1420 }
1414 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1421 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1415 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); 1422 CHECK(result->ToString(isolate2)->Equals(v8_str("XY")));
1416 } 1423 }
1417 isolate2->Dispose(); 1424 isolate2->Dispose();
1418 } 1425 }
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698