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 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2357 | 2357 |
2358 static int NumberOfGlobalObjects() { | 2358 static int NumberOfGlobalObjects() { |
2359 int count = 0; | 2359 int count = 0; |
2360 HeapIterator iterator(CcTest::heap()); | 2360 HeapIterator iterator(CcTest::heap()); |
2361 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2361 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2362 if (obj->IsJSGlobalObject()) count++; | 2362 if (obj->IsJSGlobalObject()) count++; |
2363 } | 2363 } |
2364 // Subtract two to compensate for the two global objects (not global | 2364 // Subtract two to compensate for the two global objects (not global |
2365 // JSObjects, of which there would only be one) that are part of the code stub | 2365 // JSObjects, of which there would only be one) that are part of the code stub |
2366 // context, which is always present. | 2366 // context, which is always present. |
2367 return count - 1; | 2367 return count - 2; |
2368 } | 2368 } |
2369 | 2369 |
2370 | 2370 |
2371 // Test that we don't embed maps from foreign contexts into | 2371 // Test that we don't embed maps from foreign contexts into |
2372 // optimized code. | 2372 // optimized code. |
2373 TEST(LeakNativeContextViaMap) { | 2373 TEST(LeakNativeContextViaMap) { |
2374 i::FLAG_allow_natives_syntax = true; | 2374 i::FLAG_allow_natives_syntax = true; |
2375 v8::Isolate* isolate = CcTest::isolate(); | 2375 v8::Isolate* isolate = CcTest::isolate(); |
2376 v8::HandleScope outer_scope(isolate); | 2376 v8::HandleScope outer_scope(isolate); |
2377 v8::Persistent<v8::Context> ctx1p; | 2377 v8::Persistent<v8::Context> ctx1p; |
2378 v8::Persistent<v8::Context> ctx2p; | 2378 v8::Persistent<v8::Context> ctx2p; |
2379 { | 2379 { |
2380 v8::HandleScope scope(isolate); | 2380 v8::HandleScope scope(isolate); |
2381 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 2381 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
2382 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 2382 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
2383 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 2383 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
2384 } | 2384 } |
2385 | 2385 |
2386 CcTest::heap()->CollectAllAvailableGarbage(); | 2386 CcTest::heap()->CollectAllAvailableGarbage(); |
2387 CHECK_EQ(2, NumberOfGlobalObjects()); | 2387 CHECK_EQ(4, NumberOfGlobalObjects()); |
2388 | 2388 |
2389 { | 2389 { |
2390 v8::HandleScope inner_scope(isolate); | 2390 v8::HandleScope inner_scope(isolate); |
2391 CompileRun("var v = {x: 42}"); | 2391 CompileRun("var v = {x: 42}"); |
2392 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); | 2392 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); |
2393 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); | 2393 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); |
2394 v8::Local<v8::Value> v = | 2394 v8::Local<v8::Value> v = |
2395 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); | 2395 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); |
2396 ctx2->Enter(); | 2396 ctx2->Enter(); |
2397 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); | 2397 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); |
2398 v8::Local<v8::Value> res = CompileRun( | 2398 v8::Local<v8::Value> res = CompileRun( |
2399 "function f() { return o.x; }" | 2399 "function f() { return o.x; }" |
2400 "for (var i = 0; i < 10; ++i) f();" | 2400 "for (var i = 0; i < 10; ++i) f();" |
2401 "%OptimizeFunctionOnNextCall(f);" | 2401 "%OptimizeFunctionOnNextCall(f);" |
2402 "f();"); | 2402 "f();"); |
2403 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); | 2403 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); |
2404 CHECK(ctx2->Global() | 2404 CHECK(ctx2->Global() |
2405 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) | 2405 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) |
2406 .FromJust()); | 2406 .FromJust()); |
2407 ctx2->Exit(); | 2407 ctx2->Exit(); |
2408 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); | 2408 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); |
2409 ctx1p.Reset(); | 2409 ctx1p.Reset(); |
2410 isolate->ContextDisposedNotification(); | 2410 isolate->ContextDisposedNotification(); |
2411 } | 2411 } |
2412 CcTest::heap()->CollectAllAvailableGarbage(); | 2412 CcTest::heap()->CollectAllAvailableGarbage(); |
2413 CHECK_EQ(1, NumberOfGlobalObjects()); | 2413 CHECK_EQ(2, NumberOfGlobalObjects()); |
2414 ctx2p.Reset(); | 2414 ctx2p.Reset(); |
2415 CcTest::heap()->CollectAllAvailableGarbage(); | 2415 CcTest::heap()->CollectAllAvailableGarbage(); |
2416 CHECK_EQ(0, NumberOfGlobalObjects()); | 2416 CHECK_EQ(0, NumberOfGlobalObjects()); |
2417 } | 2417 } |
2418 | 2418 |
2419 | 2419 |
2420 // Test that we don't embed functions from foreign contexts into | 2420 // Test that we don't embed functions from foreign contexts into |
2421 // optimized code. | 2421 // optimized code. |
2422 TEST(LeakNativeContextViaFunction) { | 2422 TEST(LeakNativeContextViaFunction) { |
2423 i::FLAG_allow_natives_syntax = true; | 2423 i::FLAG_allow_natives_syntax = true; |
2424 v8::Isolate* isolate = CcTest::isolate(); | 2424 v8::Isolate* isolate = CcTest::isolate(); |
2425 v8::HandleScope outer_scope(isolate); | 2425 v8::HandleScope outer_scope(isolate); |
2426 v8::Persistent<v8::Context> ctx1p; | 2426 v8::Persistent<v8::Context> ctx1p; |
2427 v8::Persistent<v8::Context> ctx2p; | 2427 v8::Persistent<v8::Context> ctx2p; |
2428 { | 2428 { |
2429 v8::HandleScope scope(isolate); | 2429 v8::HandleScope scope(isolate); |
2430 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 2430 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
2431 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 2431 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
2432 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 2432 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
2433 } | 2433 } |
2434 | 2434 |
2435 CcTest::heap()->CollectAllAvailableGarbage(); | 2435 CcTest::heap()->CollectAllAvailableGarbage(); |
2436 CHECK_EQ(2, NumberOfGlobalObjects()); | 2436 CHECK_EQ(4, NumberOfGlobalObjects()); |
2437 | 2437 |
2438 { | 2438 { |
2439 v8::HandleScope inner_scope(isolate); | 2439 v8::HandleScope inner_scope(isolate); |
2440 CompileRun("var v = function() { return 42; }"); | 2440 CompileRun("var v = function() { return 42; }"); |
2441 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); | 2441 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); |
2442 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); | 2442 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); |
2443 v8::Local<v8::Value> v = | 2443 v8::Local<v8::Value> v = |
2444 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); | 2444 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); |
2445 ctx2->Enter(); | 2445 ctx2->Enter(); |
2446 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); | 2446 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); |
2447 v8::Local<v8::Value> res = CompileRun( | 2447 v8::Local<v8::Value> res = CompileRun( |
2448 "function f(x) { return x(); }" | 2448 "function f(x) { return x(); }" |
2449 "for (var i = 0; i < 10; ++i) f(o);" | 2449 "for (var i = 0; i < 10; ++i) f(o);" |
2450 "%OptimizeFunctionOnNextCall(f);" | 2450 "%OptimizeFunctionOnNextCall(f);" |
2451 "f(o);"); | 2451 "f(o);"); |
2452 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); | 2452 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); |
2453 CHECK(ctx2->Global() | 2453 CHECK(ctx2->Global() |
2454 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) | 2454 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) |
2455 .FromJust()); | 2455 .FromJust()); |
2456 ctx2->Exit(); | 2456 ctx2->Exit(); |
2457 ctx1->Exit(); | 2457 ctx1->Exit(); |
2458 ctx1p.Reset(); | 2458 ctx1p.Reset(); |
2459 isolate->ContextDisposedNotification(); | 2459 isolate->ContextDisposedNotification(); |
2460 } | 2460 } |
2461 CcTest::heap()->CollectAllAvailableGarbage(); | 2461 CcTest::heap()->CollectAllAvailableGarbage(); |
2462 CHECK_EQ(1, NumberOfGlobalObjects()); | 2462 CHECK_EQ(2, NumberOfGlobalObjects()); |
2463 ctx2p.Reset(); | 2463 ctx2p.Reset(); |
2464 CcTest::heap()->CollectAllAvailableGarbage(); | 2464 CcTest::heap()->CollectAllAvailableGarbage(); |
2465 CHECK_EQ(0, NumberOfGlobalObjects()); | 2465 CHECK_EQ(0, NumberOfGlobalObjects()); |
2466 } | 2466 } |
2467 | 2467 |
2468 | 2468 |
2469 TEST(LeakNativeContextViaMapKeyed) { | 2469 TEST(LeakNativeContextViaMapKeyed) { |
2470 i::FLAG_allow_natives_syntax = true; | 2470 i::FLAG_allow_natives_syntax = true; |
2471 v8::Isolate* isolate = CcTest::isolate(); | 2471 v8::Isolate* isolate = CcTest::isolate(); |
2472 v8::HandleScope outer_scope(isolate); | 2472 v8::HandleScope outer_scope(isolate); |
2473 v8::Persistent<v8::Context> ctx1p; | 2473 v8::Persistent<v8::Context> ctx1p; |
2474 v8::Persistent<v8::Context> ctx2p; | 2474 v8::Persistent<v8::Context> ctx2p; |
2475 { | 2475 { |
2476 v8::HandleScope scope(isolate); | 2476 v8::HandleScope scope(isolate); |
2477 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 2477 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
2478 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 2478 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
2479 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 2479 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
2480 } | 2480 } |
2481 | 2481 |
2482 CcTest::heap()->CollectAllAvailableGarbage(); | 2482 CcTest::heap()->CollectAllAvailableGarbage(); |
2483 CHECK_EQ(2, NumberOfGlobalObjects()); | 2483 CHECK_EQ(4, NumberOfGlobalObjects()); |
2484 | 2484 |
2485 { | 2485 { |
2486 v8::HandleScope inner_scope(isolate); | 2486 v8::HandleScope inner_scope(isolate); |
2487 CompileRun("var v = [42, 43]"); | 2487 CompileRun("var v = [42, 43]"); |
2488 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); | 2488 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); |
2489 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); | 2489 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); |
2490 v8::Local<v8::Value> v = | 2490 v8::Local<v8::Value> v = |
2491 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); | 2491 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); |
2492 ctx2->Enter(); | 2492 ctx2->Enter(); |
2493 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); | 2493 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); |
2494 v8::Local<v8::Value> res = CompileRun( | 2494 v8::Local<v8::Value> res = CompileRun( |
2495 "function f() { return o[0]; }" | 2495 "function f() { return o[0]; }" |
2496 "for (var i = 0; i < 10; ++i) f();" | 2496 "for (var i = 0; i < 10; ++i) f();" |
2497 "%OptimizeFunctionOnNextCall(f);" | 2497 "%OptimizeFunctionOnNextCall(f);" |
2498 "f();"); | 2498 "f();"); |
2499 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); | 2499 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); |
2500 CHECK(ctx2->Global() | 2500 CHECK(ctx2->Global() |
2501 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) | 2501 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) |
2502 .FromJust()); | 2502 .FromJust()); |
2503 ctx2->Exit(); | 2503 ctx2->Exit(); |
2504 ctx1->Exit(); | 2504 ctx1->Exit(); |
2505 ctx1p.Reset(); | 2505 ctx1p.Reset(); |
2506 isolate->ContextDisposedNotification(); | 2506 isolate->ContextDisposedNotification(); |
2507 } | 2507 } |
2508 CcTest::heap()->CollectAllAvailableGarbage(); | 2508 CcTest::heap()->CollectAllAvailableGarbage(); |
2509 CHECK_EQ(1, NumberOfGlobalObjects()); | 2509 CHECK_EQ(2, NumberOfGlobalObjects()); |
2510 ctx2p.Reset(); | 2510 ctx2p.Reset(); |
2511 CcTest::heap()->CollectAllAvailableGarbage(); | 2511 CcTest::heap()->CollectAllAvailableGarbage(); |
2512 CHECK_EQ(0, NumberOfGlobalObjects()); | 2512 CHECK_EQ(0, NumberOfGlobalObjects()); |
2513 } | 2513 } |
2514 | 2514 |
2515 | 2515 |
2516 TEST(LeakNativeContextViaMapProto) { | 2516 TEST(LeakNativeContextViaMapProto) { |
2517 i::FLAG_allow_natives_syntax = true; | 2517 i::FLAG_allow_natives_syntax = true; |
2518 v8::Isolate* isolate = CcTest::isolate(); | 2518 v8::Isolate* isolate = CcTest::isolate(); |
2519 v8::HandleScope outer_scope(isolate); | 2519 v8::HandleScope outer_scope(isolate); |
2520 v8::Persistent<v8::Context> ctx1p; | 2520 v8::Persistent<v8::Context> ctx1p; |
2521 v8::Persistent<v8::Context> ctx2p; | 2521 v8::Persistent<v8::Context> ctx2p; |
2522 { | 2522 { |
2523 v8::HandleScope scope(isolate); | 2523 v8::HandleScope scope(isolate); |
2524 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 2524 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
2525 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 2525 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
2526 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 2526 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
2527 } | 2527 } |
2528 | 2528 |
2529 CcTest::heap()->CollectAllAvailableGarbage(); | 2529 CcTest::heap()->CollectAllAvailableGarbage(); |
2530 CHECK_EQ(2, NumberOfGlobalObjects()); | 2530 CHECK_EQ(4, NumberOfGlobalObjects()); |
2531 | 2531 |
2532 { | 2532 { |
2533 v8::HandleScope inner_scope(isolate); | 2533 v8::HandleScope inner_scope(isolate); |
2534 CompileRun("var v = { y: 42}"); | 2534 CompileRun("var v = { y: 42}"); |
2535 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); | 2535 v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p); |
2536 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); | 2536 v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p); |
2537 v8::Local<v8::Value> v = | 2537 v8::Local<v8::Value> v = |
2538 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); | 2538 ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked(); |
2539 ctx2->Enter(); | 2539 ctx2->Enter(); |
2540 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); | 2540 CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust()); |
2541 v8::Local<v8::Value> res = CompileRun( | 2541 v8::Local<v8::Value> res = CompileRun( |
2542 "function f() {" | 2542 "function f() {" |
2543 " var p = {x: 42};" | 2543 " var p = {x: 42};" |
2544 " p.__proto__ = o;" | 2544 " p.__proto__ = o;" |
2545 " return p.x;" | 2545 " return p.x;" |
2546 "}" | 2546 "}" |
2547 "for (var i = 0; i < 10; ++i) f();" | 2547 "for (var i = 0; i < 10; ++i) f();" |
2548 "%OptimizeFunctionOnNextCall(f);" | 2548 "%OptimizeFunctionOnNextCall(f);" |
2549 "f();"); | 2549 "f();"); |
2550 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); | 2550 CHECK_EQ(42, res->Int32Value(ctx2).FromJust()); |
2551 CHECK(ctx2->Global() | 2551 CHECK(ctx2->Global() |
2552 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) | 2552 ->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0)) |
2553 .FromJust()); | 2553 .FromJust()); |
2554 ctx2->Exit(); | 2554 ctx2->Exit(); |
2555 ctx1->Exit(); | 2555 ctx1->Exit(); |
2556 ctx1p.Reset(); | 2556 ctx1p.Reset(); |
2557 isolate->ContextDisposedNotification(); | 2557 isolate->ContextDisposedNotification(); |
2558 } | 2558 } |
2559 CcTest::heap()->CollectAllAvailableGarbage(); | 2559 CcTest::heap()->CollectAllAvailableGarbage(); |
2560 CHECK_EQ(1, NumberOfGlobalObjects()); | 2560 CHECK_EQ(2, NumberOfGlobalObjects()); |
2561 ctx2p.Reset(); | 2561 ctx2p.Reset(); |
2562 CcTest::heap()->CollectAllAvailableGarbage(); | 2562 CcTest::heap()->CollectAllAvailableGarbage(); |
2563 CHECK_EQ(0, NumberOfGlobalObjects()); | 2563 CHECK_EQ(0, NumberOfGlobalObjects()); |
2564 } | 2564 } |
2565 | 2565 |
2566 | 2566 |
2567 TEST(InstanceOfStubWriteBarrier) { | 2567 TEST(InstanceOfStubWriteBarrier) { |
2568 i::FLAG_allow_natives_syntax = true; | 2568 i::FLAG_allow_natives_syntax = true; |
2569 #ifdef VERIFY_HEAP | 2569 #ifdef VERIFY_HEAP |
2570 i::FLAG_verify_heap = true; | 2570 i::FLAG_verify_heap = true; |
(...skipping 3876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6447 isolate->IncrementJsCallsFromApiCounter(); | 6447 isolate->IncrementJsCallsFromApiCounter(); |
6448 isolate->IncrementJsCallsFromApiCounter(); | 6448 isolate->IncrementJsCallsFromApiCounter(); |
6449 isolate->IncrementJsCallsFromApiCounter(); | 6449 isolate->IncrementJsCallsFromApiCounter(); |
6450 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); | 6450 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); |
6451 CheckDoubleEquals(2, calls_per_ms); | 6451 CheckDoubleEquals(2, calls_per_ms); |
6452 } | 6452 } |
6453 | 6453 |
6454 | 6454 |
6455 } // namespace internal | 6455 } // namespace internal |
6456 } // namespace v8 | 6456 } // namespace v8 |
OLD | NEW |