| 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 2602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2613 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 2613 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
| 2614 global->Get(ctx, v8_str("g")).ToLocalChecked()); | 2614 global->Get(ctx, v8_str("g")).ToLocalChecked()); |
| 2615 g->Call(ctx, global, 0, nullptr).ToLocalChecked(); | 2615 g->Call(ctx, global, 0, nullptr).ToLocalChecked(); |
| 2616 } | 2616 } |
| 2617 | 2617 |
| 2618 CcTest::heap()->incremental_marking()->set_should_hurry(true); | 2618 CcTest::heap()->incremental_marking()->set_should_hurry(true); |
| 2619 CcTest::heap()->CollectGarbage(OLD_SPACE); | 2619 CcTest::heap()->CollectGarbage(OLD_SPACE); |
| 2620 } | 2620 } |
| 2621 | 2621 |
| 2622 | 2622 |
| 2623 static int NumberOfProtoTransitions(Map* map) { | |
| 2624 return TransitionArray::NumberOfPrototypeTransitions( | |
| 2625 TransitionArray::GetPrototypeTransitions(map)); | |
| 2626 } | |
| 2627 | |
| 2628 | |
| 2629 TEST(PrototypeTransitionClearing) { | 2623 TEST(PrototypeTransitionClearing) { |
| 2630 if (FLAG_never_compact) return; | 2624 if (FLAG_never_compact) return; |
| 2631 CcTest::InitializeVM(); | 2625 CcTest::InitializeVM(); |
| 2632 Isolate* isolate = CcTest::i_isolate(); | 2626 Isolate* isolate = CcTest::i_isolate(); |
| 2633 Factory* factory = isolate->factory(); | 2627 Factory* factory = isolate->factory(); |
| 2634 v8::HandleScope scope(CcTest::isolate()); | 2628 v8::HandleScope scope(CcTest::isolate()); |
| 2635 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); | 2629 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 2636 | 2630 |
| 2637 CompileRun("var base = {};"); | 2631 CompileRun("var base = {};"); |
| 2638 i::Handle<JSReceiver> baseObject = | 2632 i::Handle<JSReceiver> baseObject = |
| 2639 v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast( | 2633 v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast( |
| 2640 CcTest::global()->Get(ctx, v8_str("base")).ToLocalChecked())); | 2634 CcTest::global()->Get(ctx, v8_str("base")).ToLocalChecked())); |
| 2641 | 2635 |
| 2642 int initialTransitions = NumberOfProtoTransitions(baseObject->map()); | 2636 int initialTransitions = |
| 2637 TransitionArray::NumberOfPrototypeTransitionsForTest(baseObject->map()); |
| 2643 | 2638 |
| 2644 CompileRun( | 2639 CompileRun( |
| 2645 "var live = [];" | 2640 "var live = [];" |
| 2646 "for (var i = 0; i < 10; i++) {" | 2641 "for (var i = 0; i < 10; i++) {" |
| 2647 " var object = {};" | 2642 " var object = {};" |
| 2648 " var prototype = {};" | 2643 " var prototype = {};" |
| 2649 " object.__proto__ = prototype;" | 2644 " object.__proto__ = prototype;" |
| 2650 " if (i >= 3) live.push(object, prototype);" | 2645 " if (i >= 3) live.push(object, prototype);" |
| 2651 "}"); | 2646 "}"); |
| 2652 | 2647 |
| 2653 // Verify that only dead prototype transitions are cleared. | 2648 // Verify that only dead prototype transitions are cleared. |
| 2654 CHECK_EQ(initialTransitions + 10, | 2649 CHECK_EQ( |
| 2655 NumberOfProtoTransitions(baseObject->map())); | 2650 initialTransitions + 10, |
| 2651 TransitionArray::NumberOfPrototypeTransitionsForTest(baseObject->map())); |
| 2656 CcTest::heap()->CollectAllGarbage(); | 2652 CcTest::heap()->CollectAllGarbage(); |
| 2657 const int transitions = 10 - 3; | 2653 const int transitions = 10 - 3; |
| 2658 CHECK_EQ(initialTransitions + transitions, | 2654 CHECK_EQ( |
| 2659 NumberOfProtoTransitions(baseObject->map())); | 2655 initialTransitions + transitions, |
| 2656 TransitionArray::NumberOfPrototypeTransitionsForTest(baseObject->map())); |
| 2660 | 2657 |
| 2661 // Verify that prototype transitions array was compacted. | 2658 // Verify that prototype transitions array was compacted. |
| 2662 FixedArray* trans = | 2659 FixedArray* trans = |
| 2663 TransitionArray::GetPrototypeTransitions(baseObject->map()); | 2660 TransitionArray::GetPrototypeTransitions(baseObject->map()); |
| 2664 for (int i = initialTransitions; i < initialTransitions + transitions; i++) { | 2661 for (int i = initialTransitions; i < initialTransitions + transitions; i++) { |
| 2665 int j = TransitionArray::kProtoTransitionHeaderSize + i; | 2662 int j = TransitionArray::kProtoTransitionHeaderSize + i; |
| 2666 CHECK(trans->get(j)->IsWeakCell()); | 2663 CHECK(trans->get(j)->IsWeakCell()); |
| 2667 CHECK(WeakCell::cast(trans->get(j))->value()->IsMap()); | 2664 CHECK(WeakCell::cast(trans->get(j))->value()->IsMap()); |
| 2668 } | 2665 } |
| 2669 | 2666 |
| (...skipping 3779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6449 isolate->IncrementJsCallsFromApiCounter(); | 6446 isolate->IncrementJsCallsFromApiCounter(); |
| 6450 isolate->IncrementJsCallsFromApiCounter(); | 6447 isolate->IncrementJsCallsFromApiCounter(); |
| 6451 isolate->IncrementJsCallsFromApiCounter(); | 6448 isolate->IncrementJsCallsFromApiCounter(); |
| 6452 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); | 6449 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); |
| 6453 CheckDoubleEquals(2, calls_per_ms); | 6450 CheckDoubleEquals(2, calls_per_ms); |
| 6454 } | 6451 } |
| 6455 | 6452 |
| 6456 | 6453 |
| 6457 } // namespace internal | 6454 } // namespace internal |
| 6458 } // namespace v8 | 6455 } // namespace v8 |
| OLD | NEW |