Chromium Code Reviews| 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 2494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2505 Handle<JSObject> o = | 2505 Handle<JSObject> o = |
| 2506 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2506 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2507 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2507 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
| 2508 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); | 2508 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); |
| 2509 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); | 2509 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); |
| 2510 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); | 2510 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); |
| 2511 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); | 2511 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); |
| 2512 } | 2512 } |
| 2513 | 2513 |
| 2514 | 2514 |
| 2515 // Make sure pretenuring feedback is gathered for constructed objects as well | |
| 2516 // as for literals. | |
| 2517 TEST(OptimizedPretenuringConstructorCalls) { | |
| 2518 i::FLAG_allow_natives_syntax = true; | |
| 2519 i::FLAG_allocation_site_pretenuring = true; | |
| 2520 i::FLAG_pretenuring_call_new = true; | |
| 2521 i::FLAG_max_new_space_size = 2048; | |
| 2522 CcTest::InitializeVM(); | |
| 2523 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | |
| 2524 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
| 2525 v8::HandleScope scope(CcTest::isolate()); | |
| 2526 | |
| 2527 v8::Local<v8::Value> res = CompileRun( | |
| 2528 "var number_elements = 20000;" | |
| 2529 "var elements = new Array(number_elements);" | |
| 2530 "function foo() {" | |
| 2531 " this.a = 3;" | |
| 2532 " this.b = {};" | |
| 2533 " return this;" | |
|
Hannes Payer (out of office)
2014/02/18 16:24:26
remove return this;
mvstanton
2014/02/19 08:40:26
Done.
| |
| 2534 "}" | |
| 2535 "function f() {" | |
| 2536 " for (var i = 0; i < number_elements; i++) {" | |
| 2537 " elements[i] = new foo();" | |
| 2538 " }" | |
| 2539 " return elements[number_elements - 1];" | |
| 2540 "};" | |
| 2541 "f(); f(); f();" | |
| 2542 "%OptimizeFunctionOnNextCall(f);" | |
| 2543 "f();"); | |
| 2544 | |
| 2545 Handle<JSObject> o = | |
| 2546 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
| 2547 | |
| 2548 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | |
| 2549 } | |
| 2550 | |
| 2551 | |
| 2515 // Test regular array literals allocation. | 2552 // Test regular array literals allocation. |
| 2516 TEST(OptimizedAllocationArrayLiterals) { | 2553 TEST(OptimizedAllocationArrayLiterals) { |
| 2517 i::FLAG_allow_natives_syntax = true; | 2554 i::FLAG_allow_natives_syntax = true; |
| 2518 CcTest::InitializeVM(); | 2555 CcTest::InitializeVM(); |
| 2519 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2556 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
| 2520 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2557 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2521 v8::HandleScope scope(CcTest::isolate()); | 2558 v8::HandleScope scope(CcTest::isolate()); |
| 2522 | 2559 |
| 2523 v8::Local<v8::Value> res = CompileRun( | 2560 v8::Local<v8::Value> res = CompileRun( |
| 2524 "function f() {" | 2561 "function f() {" |
| 2525 " var numbers = new Array(1, 2, 3);" | 2562 " var numbers = new Array(1, 2, 3);" |
| 2526 " numbers[0] = 3.14;" | 2563 " numbers[0] = 3.14;" |
| 2527 " return numbers;" | 2564 " return numbers;" |
| 2528 "};" | 2565 "};" |
| 2529 "f(); f(); f();" | 2566 "f(); f(); f();" |
| 2530 "%OptimizeFunctionOnNextCall(f);" | 2567 "%OptimizeFunctionOnNextCall(f);" |
| 2531 "f();"); | 2568 "f();"); |
| 2532 CHECK_EQ(static_cast<int>(3.14), | 2569 CHECK_EQ(static_cast<int>(3.14), |
| 2533 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); | 2570 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); |
| 2534 | 2571 |
| 2535 Handle<JSObject> o = | 2572 Handle<JSObject> o = |
| 2536 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2573 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2537 | 2574 |
| 2538 CHECK(CcTest::heap()->InNewSpace(o->elements())); | 2575 CHECK(CcTest::heap()->InNewSpace(o->elements())); |
| 2539 } | 2576 } |
| 2540 | 2577 |
| 2541 | 2578 |
| 2579 // Test that a form of call-new pretenuring works even without allocation sites. | |
|
Hannes Payer (out of office)
2014/02/18 16:24:26
Test global pretenuring of call new.
mvstanton
2014/02/19 08:40:26
Done.
| |
| 2542 TEST(OptimizedPretenuringCallNew) { | 2580 TEST(OptimizedPretenuringCallNew) { |
| 2543 i::FLAG_allow_natives_syntax = true; | 2581 i::FLAG_allow_natives_syntax = true; |
| 2544 i::FLAG_allocation_site_pretenuring = false; | 2582 i::FLAG_allocation_site_pretenuring = false; |
| 2545 i::FLAG_pretenuring_call_new = true; | 2583 i::FLAG_pretenuring_call_new = true; |
| 2546 CcTest::InitializeVM(); | 2584 CcTest::InitializeVM(); |
| 2547 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2585 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
| 2548 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2586 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2549 v8::HandleScope scope(CcTest::isolate()); | 2587 v8::HandleScope scope(CcTest::isolate()); |
| 2550 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); | 2588 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); |
| 2551 | 2589 |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3681 code = scope.CloseAndEscape(Handle<Code>(bar->code())); | 3719 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3682 } | 3720 } |
| 3683 | 3721 |
| 3684 // Now make sure that a gc should get rid of the function | 3722 // Now make sure that a gc should get rid of the function |
| 3685 for (int i = 0; i < 4; i++) { | 3723 for (int i = 0; i < 4; i++) { |
| 3686 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3724 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 3687 } | 3725 } |
| 3688 | 3726 |
| 3689 ASSERT(code->marked_for_deoptimization()); | 3727 ASSERT(code->marked_for_deoptimization()); |
| 3690 } | 3728 } |
| OLD | NEW |