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 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 return; | 2524 return; |
2525 } | 2525 } |
2526 i::FLAG_allow_natives_syntax = true; | 2526 i::FLAG_allow_natives_syntax = true; |
2527 i::FLAG_expose_gc = true; | 2527 i::FLAG_expose_gc = true; |
2528 CcTest::InitializeVM(); | 2528 CcTest::InitializeVM(); |
2529 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2529 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2530 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2530 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2531 v8::HandleScope scope(CcTest::isolate()); | 2531 v8::HandleScope scope(CcTest::isolate()); |
2532 | 2532 |
2533 i::ScopedVector<char> source(1024); | 2533 i::ScopedVector<char> source(1024); |
| 2534 // Call new is doing slack tracking for the first |
| 2535 // JSFunction::kGenerousAllocationCount allocations, and we can't find |
| 2536 // mementos during that time. |
2534 i::OS::SNPrintF( | 2537 i::OS::SNPrintF( |
2535 source, | 2538 source, |
2536 "var number_elements = %d;" | 2539 "var number_elements = %d;" |
2537 "var elements = new Array(number_elements);" | 2540 "var elements = new Array(number_elements);" |
2538 "function foo() {" | 2541 "function foo() {" |
2539 " this.a = 3;" | 2542 " this.a = 3;" |
2540 " this.b = {};" | 2543 " this.b = {};" |
2541 "}" | 2544 "}" |
2542 "function f() {" | 2545 "function f() {" |
2543 " for (var i = 0; i < number_elements; i++) {" | 2546 " for (var i = 0; i < number_elements; i++) {" |
2544 " elements[i] = new foo();" | 2547 " elements[i] = new foo();" |
2545 " }" | 2548 " }" |
2546 " return elements[number_elements - 1];" | 2549 " return elements[number_elements - 1];" |
2547 "};" | 2550 "};" |
2548 "f(); gc();" | 2551 "f(); gc();" |
2549 "f(); f();" | 2552 "f(); f();" |
2550 "%%OptimizeFunctionOnNextCall(f);" | 2553 "%%OptimizeFunctionOnNextCall(f);" |
2551 "f();", | 2554 "f();", |
2552 AllocationSite::kPretenureMinimumCreated); | 2555 AllocationSite::kPretenureMinimumCreated + |
| 2556 JSFunction::kGenerousAllocationCount); |
2553 | 2557 |
2554 v8::Local<v8::Value> res = CompileRun(source.start()); | 2558 v8::Local<v8::Value> res = CompileRun(source.start()); |
2555 | 2559 |
2556 Handle<JSObject> o = | 2560 Handle<JSObject> o = |
2557 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2561 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2558 | 2562 |
2559 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2563 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2560 } | 2564 } |
2561 | 2565 |
2562 | 2566 |
2563 TEST(OptimizedPretenuringCallNew) { | 2567 TEST(OptimizedPretenuringCallNew) { |
2564 if (!i::FLAG_pretenuring_call_new) { | 2568 if (!i::FLAG_pretenuring_call_new) { |
2565 // FLAG_pretenuring_call_new needs to be synced with the snapshot. | 2569 // FLAG_pretenuring_call_new needs to be synced with the snapshot. |
2566 return; | 2570 return; |
2567 } | 2571 } |
2568 i::FLAG_allow_natives_syntax = true; | 2572 i::FLAG_allow_natives_syntax = true; |
2569 i::FLAG_expose_gc = true; | 2573 i::FLAG_expose_gc = true; |
2570 CcTest::InitializeVM(); | 2574 CcTest::InitializeVM(); |
2571 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2575 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2572 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2576 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2573 v8::HandleScope scope(CcTest::isolate()); | 2577 v8::HandleScope scope(CcTest::isolate()); |
2574 | 2578 |
2575 i::ScopedVector<char> source(1024); | 2579 i::ScopedVector<char> source(1024); |
| 2580 // Call new is doing slack tracking for the first |
| 2581 // JSFunction::kGenerousAllocationCount allocations, and we can't find |
| 2582 // mementos during that time. |
2576 i::OS::SNPrintF( | 2583 i::OS::SNPrintF( |
2577 source, | 2584 source, |
2578 "var number_elements = 100;" | 2585 "var number_elements = %d;" |
2579 "var elements = new Array(number_elements);" | 2586 "var elements = new Array(number_elements);" |
2580 "function g() { this.a = 0; }" | 2587 "function g() { this.a = 0; }" |
2581 "function f() {" | 2588 "function f() {" |
2582 " for (var i = 0; i < number_elements; i++) {" | 2589 " for (var i = 0; i < number_elements; i++) {" |
2583 " elements[i] = new g();" | 2590 " elements[i] = new g();" |
2584 " }" | 2591 " }" |
2585 " return elements[number_elements - 1];" | 2592 " return elements[number_elements - 1];" |
2586 "};" | 2593 "};" |
2587 "f(); gc();" | 2594 "f(); gc();" |
2588 "f(); f();" | 2595 "f(); f();" |
2589 "%%OptimizeFunctionOnNextCall(f);" | 2596 "%%OptimizeFunctionOnNextCall(f);" |
2590 "f();", | 2597 "f();", |
2591 AllocationSite::kPretenureMinimumCreated); | 2598 AllocationSite::kPretenureMinimumCreated + |
| 2599 JSFunction::kGenerousAllocationCount); |
2592 | 2600 |
2593 v8::Local<v8::Value> res = CompileRun(source.start()); | 2601 v8::Local<v8::Value> res = CompileRun(source.start()); |
2594 | 2602 |
2595 Handle<JSObject> o = | 2603 Handle<JSObject> o = |
2596 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2604 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2597 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2605 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2598 } | 2606 } |
2599 | 2607 |
2600 | 2608 |
2601 // Test regular array literals allocation. | 2609 // Test regular array literals allocation. |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3796 Handle<JSFunction> bar_handle = | 3804 Handle<JSFunction> bar_handle = |
3797 v8::Utils::OpenHandle( | 3805 v8::Utils::OpenHandle( |
3798 *v8::Handle<v8::Function>::Cast( | 3806 *v8::Handle<v8::Function>::Cast( |
3799 CcTest::global()->Get(v8_str("bar")))); | 3807 CcTest::global()->Get(v8_str("bar")))); |
3800 CHECK_EQ(bar_handle->code(), function_bar); | 3808 CHECK_EQ(bar_handle->code(), function_bar); |
3801 } | 3809 } |
3802 | 3810 |
3803 // Now make sure that a gc should get rid of the function, even though we | 3811 // Now make sure that a gc should get rid of the function, even though we |
3804 // still have the allocation site alive. | 3812 // still have the allocation site alive. |
3805 for (int i = 0; i < 4; i++) { | 3813 for (int i = 0; i < 4; i++) { |
3806 heap->CollectAllGarbage(false); | 3814 heap->CollectAllGarbage(Heap::kNoGCFlags); |
3807 } | 3815 } |
3808 | 3816 |
3809 // The site still exists because of our global handle, but the code is no | 3817 // The site still exists because of our global handle, but the code is no |
3810 // longer referred to by dependent_code(). | 3818 // longer referred to by dependent_code(). |
3811 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 3819 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
3812 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 3820 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
3813 CHECK(!(site->dependent_code()->is_code_at(index))); | 3821 CHECK(!(site->dependent_code()->is_code_at(index))); |
3814 } | 3822 } |
3815 | 3823 |
3816 | 3824 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4267 #ifdef DEBUG | 4275 #ifdef DEBUG |
4268 TEST(PathTracer) { | 4276 TEST(PathTracer) { |
4269 CcTest::InitializeVM(); | 4277 CcTest::InitializeVM(); |
4270 v8::HandleScope scope(CcTest::isolate()); | 4278 v8::HandleScope scope(CcTest::isolate()); |
4271 | 4279 |
4272 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4280 v8::Local<v8::Value> result = CompileRun("'abc'"); |
4273 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4281 Handle<Object> o = v8::Utils::OpenHandle(*result); |
4274 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4282 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
4275 } | 4283 } |
4276 #endif // DEBUG | 4284 #endif // DEBUG |
OLD | NEW |