OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); | 1368 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); |
1369 } | 1369 } |
1370 | 1370 |
1371 // Simulate one final GC to make sure the candidate queue is sane. | 1371 // Simulate one final GC to make sure the candidate queue is sane. |
1372 heap->CollectAllGarbage(Heap::kNoGCFlags); | 1372 heap->CollectAllGarbage(Heap::kNoGCFlags); |
1373 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); | 1373 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); |
1374 CHECK(function->is_compiled() || !function->IsOptimized()); | 1374 CHECK(function->is_compiled() || !function->IsOptimized()); |
1375 } | 1375 } |
1376 | 1376 |
1377 | 1377 |
| 1378 TEST(CompilationCacheCachingBehavior) { |
| 1379 // If we do not flush code, or have the compilation cache turned off, this |
| 1380 // test is invalid. |
| 1381 if (!FLAG_flush_code || !FLAG_flush_code_incrementally || |
| 1382 !FLAG_compilation_cache) { |
| 1383 return; |
| 1384 } |
| 1385 CcTest::InitializeVM(); |
| 1386 Isolate* isolate = CcTest::i_isolate(); |
| 1387 Factory* factory = isolate->factory(); |
| 1388 Heap* heap = isolate->heap(); |
| 1389 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 1390 |
| 1391 v8::HandleScope scope(CcTest::isolate()); |
| 1392 const char* raw_source = |
| 1393 "function foo() {" |
| 1394 " var x = 42;" |
| 1395 " var y = 42;" |
| 1396 " var z = x + y;" |
| 1397 "};" |
| 1398 "foo()"; |
| 1399 Handle<String> source = factory->InternalizeUtf8String(raw_source); |
| 1400 Handle<Context> native_context = isolate->native_context(); |
| 1401 |
| 1402 { |
| 1403 v8::HandleScope scope(CcTest::isolate()); |
| 1404 CompileRun(raw_source); |
| 1405 } |
| 1406 |
| 1407 // On first compilation, only a hash is inserted in the code cache. We can't |
| 1408 // find that value. |
| 1409 MaybeHandle<SharedFunctionInfo> info = compilation_cache->LookupScript( |
| 1410 source, Handle<Object>(), 0, 0, true, native_context); |
| 1411 CHECK(info.is_null()); |
| 1412 |
| 1413 { |
| 1414 v8::HandleScope scope(CcTest::isolate()); |
| 1415 CompileRun(raw_source); |
| 1416 } |
| 1417 |
| 1418 // On second compilation, the hash is replaced by a real cache entry mapping |
| 1419 // the source to the shared function info containing the code. |
| 1420 info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, true, |
| 1421 native_context); |
| 1422 CHECK(!info.is_null()); |
| 1423 |
| 1424 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 1425 |
| 1426 // On second compilation, the hash is replaced by a real cache entry mapping |
| 1427 // the source to the shared function info containing the code. |
| 1428 info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, true, |
| 1429 native_context); |
| 1430 CHECK(!info.is_null()); |
| 1431 |
| 1432 while (!info.ToHandleChecked()->code()->IsOld()) { |
| 1433 info.ToHandleChecked()->code()->MakeOlder(NO_MARKING_PARITY); |
| 1434 } |
| 1435 |
| 1436 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 1437 // Ensure code aging cleared the entry from the cache. |
| 1438 info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, true, |
| 1439 native_context); |
| 1440 CHECK(info.is_null()); |
| 1441 |
| 1442 { |
| 1443 v8::HandleScope scope(CcTest::isolate()); |
| 1444 CompileRun(raw_source); |
| 1445 } |
| 1446 |
| 1447 // On first compilation, only a hash is inserted in the code cache. We can't |
| 1448 // find that value. |
| 1449 info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, true, |
| 1450 native_context); |
| 1451 CHECK(info.is_null()); |
| 1452 |
| 1453 for (int i = 0; i < CompilationCacheTable::kHashGenerations; i++) { |
| 1454 compilation_cache->MarkCompactPrologue(); |
| 1455 } |
| 1456 |
| 1457 { |
| 1458 v8::HandleScope scope(CcTest::isolate()); |
| 1459 CompileRun(raw_source); |
| 1460 } |
| 1461 |
| 1462 // If we aged the cache before caching the script, ensure that we didn't cache |
| 1463 // on next compilation. |
| 1464 info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, true, |
| 1465 native_context); |
| 1466 CHECK(info.is_null()); |
| 1467 } |
| 1468 |
| 1469 |
1378 // Count the number of native contexts in the weak list of native contexts. | 1470 // Count the number of native contexts in the weak list of native contexts. |
1379 int CountNativeContexts() { | 1471 int CountNativeContexts() { |
1380 int count = 0; | 1472 int count = 0; |
1381 Object* object = CcTest::heap()->native_contexts_list(); | 1473 Object* object = CcTest::heap()->native_contexts_list(); |
1382 while (!object->IsUndefined()) { | 1474 while (!object->IsUndefined()) { |
1383 count++; | 1475 count++; |
1384 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); | 1476 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); |
1385 } | 1477 } |
1386 return count; | 1478 return count; |
1387 } | 1479 } |
(...skipping 3223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4611 #ifdef DEBUG | 4703 #ifdef DEBUG |
4612 TEST(PathTracer) { | 4704 TEST(PathTracer) { |
4613 CcTest::InitializeVM(); | 4705 CcTest::InitializeVM(); |
4614 v8::HandleScope scope(CcTest::isolate()); | 4706 v8::HandleScope scope(CcTest::isolate()); |
4615 | 4707 |
4616 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4708 v8::Local<v8::Value> result = CompileRun("'abc'"); |
4617 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4709 Handle<Object> o = v8::Utils::OpenHandle(*result); |
4618 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4710 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
4619 } | 4711 } |
4620 #endif // DEBUG | 4712 #endif // DEBUG |
OLD | NEW |