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 2500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 Handle<JSObject> o = | 2511 Handle<JSObject> o = |
2512 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2512 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2513 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2513 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2514 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); | 2514 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); |
2515 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); | 2515 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); |
2516 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); | 2516 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); |
2517 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); | 2517 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); |
2518 } | 2518 } |
2519 | 2519 |
2520 | 2520 |
| 2521 // Make sure pretenuring feedback is gathered for constructed objects as well |
| 2522 // as for literals. |
| 2523 TEST(OptimizedPretenuringConstructorCalls) { |
| 2524 if (!FLAG_allocation_site_pretenuring || !i::FLAG_pretenuring_call_new) { |
| 2525 // FLAG_pretenuring_call_new needs to be synced with the snapshot. |
| 2526 return; |
| 2527 } |
| 2528 i::FLAG_allow_natives_syntax = true; |
| 2529 i::FLAG_max_new_space_size = 2048; |
| 2530 CcTest::InitializeVM(); |
| 2531 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
| 2532 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2533 v8::HandleScope scope(CcTest::isolate()); |
| 2534 |
| 2535 v8::Local<v8::Value> res = CompileRun( |
| 2536 "var number_elements = 20000;" |
| 2537 "var elements = new Array(number_elements);" |
| 2538 "function foo() {" |
| 2539 " this.a = 3;" |
| 2540 " this.b = {};" |
| 2541 "}" |
| 2542 "function f() {" |
| 2543 " for (var i = 0; i < number_elements; i++) {" |
| 2544 " elements[i] = new foo();" |
| 2545 " }" |
| 2546 " return elements[number_elements - 1];" |
| 2547 "};" |
| 2548 "f(); f(); f();" |
| 2549 "%OptimizeFunctionOnNextCall(f);" |
| 2550 "f();"); |
| 2551 |
| 2552 Handle<JSObject> o = |
| 2553 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2554 |
| 2555 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
| 2556 } |
| 2557 |
| 2558 |
2521 // Test regular array literals allocation. | 2559 // Test regular array literals allocation. |
2522 TEST(OptimizedAllocationArrayLiterals) { | 2560 TEST(OptimizedAllocationArrayLiterals) { |
2523 i::FLAG_allow_natives_syntax = true; | 2561 i::FLAG_allow_natives_syntax = true; |
2524 CcTest::InitializeVM(); | 2562 CcTest::InitializeVM(); |
2525 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2563 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2526 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2564 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2527 v8::HandleScope scope(CcTest::isolate()); | 2565 v8::HandleScope scope(CcTest::isolate()); |
2528 | 2566 |
2529 v8::Local<v8::Value> res = CompileRun( | 2567 v8::Local<v8::Value> res = CompileRun( |
2530 "function f() {" | 2568 "function f() {" |
2531 " var numbers = new Array(1, 2, 3);" | 2569 " var numbers = new Array(1, 2, 3);" |
2532 " numbers[0] = 3.14;" | 2570 " numbers[0] = 3.14;" |
2533 " return numbers;" | 2571 " return numbers;" |
2534 "};" | 2572 "};" |
2535 "f(); f(); f();" | 2573 "f(); f(); f();" |
2536 "%OptimizeFunctionOnNextCall(f);" | 2574 "%OptimizeFunctionOnNextCall(f);" |
2537 "f();"); | 2575 "f();"); |
2538 CHECK_EQ(static_cast<int>(3.14), | 2576 CHECK_EQ(static_cast<int>(3.14), |
2539 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); | 2577 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); |
2540 | 2578 |
2541 Handle<JSObject> o = | 2579 Handle<JSObject> o = |
2542 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2580 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2543 | 2581 |
2544 CHECK(CcTest::heap()->InNewSpace(o->elements())); | 2582 CHECK(CcTest::heap()->InNewSpace(o->elements())); |
2545 } | 2583 } |
2546 | 2584 |
2547 | 2585 |
| 2586 // Test global pretenuring call new. |
2548 TEST(OptimizedPretenuringCallNew) { | 2587 TEST(OptimizedPretenuringCallNew) { |
2549 i::FLAG_allow_natives_syntax = true; | 2588 i::FLAG_allow_natives_syntax = true; |
2550 i::FLAG_allocation_site_pretenuring = false; | 2589 i::FLAG_allocation_site_pretenuring = false; |
2551 i::FLAG_pretenuring_call_new = true; | 2590 i::FLAG_pretenuring_call_new = true; |
2552 CcTest::InitializeVM(); | 2591 CcTest::InitializeVM(); |
2553 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2592 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2554 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2593 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2555 v8::HandleScope scope(CcTest::isolate()); | 2594 v8::HandleScope scope(CcTest::isolate()); |
2556 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); | 2595 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); |
2557 | 2596 |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3738 v8::Handle<v8::Object> global = CcTest::global(); | 3777 v8::Handle<v8::Object> global = CcTest::global(); |
3739 v8::Handle<v8::Function> g = | 3778 v8::Handle<v8::Function> g = |
3740 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); | 3779 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); |
3741 v8::Handle<v8::Value> args1[] = { v8_num(1) }; | 3780 v8::Handle<v8::Value> args1[] = { v8_num(1) }; |
3742 heap->DisableInlineAllocation(); | 3781 heap->DisableInlineAllocation(); |
3743 heap->set_allocation_timeout(1); | 3782 heap->set_allocation_timeout(1); |
3744 g->Call(global, 1, args1); | 3783 g->Call(global, 1, args1); |
3745 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3784 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
3746 } | 3785 } |
3747 #endif | 3786 #endif |
OLD | NEW |