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 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); | 1996 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
1997 } | 1997 } |
1998 | 1998 |
1999 | 1999 |
2000 TEST(PrototypeTransitionClearing) { | 2000 TEST(PrototypeTransitionClearing) { |
2001 CcTest::InitializeVM(); | 2001 CcTest::InitializeVM(); |
2002 Isolate* isolate = CcTest::i_isolate(); | 2002 Isolate* isolate = CcTest::i_isolate(); |
2003 Factory* factory = isolate->factory(); | 2003 Factory* factory = isolate->factory(); |
2004 v8::HandleScope scope(CcTest::isolate()); | 2004 v8::HandleScope scope(CcTest::isolate()); |
2005 | 2005 |
| 2006 CompileRun("var base = {};"); |
| 2007 Handle<JSObject> baseObject = |
| 2008 v8::Utils::OpenHandle( |
| 2009 *v8::Handle<v8::Object>::Cast( |
| 2010 CcTest::global()->Get(v8_str("base")))); |
| 2011 int initialTransitions = baseObject->map()->NumberOfProtoTransitions(); |
| 2012 |
2006 CompileRun( | 2013 CompileRun( |
2007 "var base = {};" | |
2008 "var live = [];" | 2014 "var live = [];" |
2009 "for (var i = 0; i < 10; i++) {" | 2015 "for (var i = 0; i < 10; i++) {" |
2010 " var object = {};" | 2016 " var object = {};" |
2011 " var prototype = {};" | 2017 " var prototype = {};" |
2012 " object.__proto__ = prototype;" | 2018 " object.__proto__ = prototype;" |
2013 " if (i >= 3) live.push(object, prototype);" | 2019 " if (i >= 3) live.push(object, prototype);" |
2014 "}"); | 2020 "}"); |
2015 | 2021 |
2016 Handle<JSObject> baseObject = | |
2017 v8::Utils::OpenHandle( | |
2018 *v8::Handle<v8::Object>::Cast( | |
2019 CcTest::global()->Get(v8_str("base")))); | |
2020 | |
2021 // Verify that only dead prototype transitions are cleared. | 2022 // Verify that only dead prototype transitions are cleared. |
2022 CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions()); | 2023 CHECK_EQ(initialTransitions + 10, |
| 2024 baseObject->map()->NumberOfProtoTransitions()); |
2023 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2025 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2024 const int transitions = 10 - 3; | 2026 const int transitions = 10 - 3; |
2025 CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions()); | 2027 CHECK_EQ(initialTransitions + transitions, |
| 2028 baseObject->map()->NumberOfProtoTransitions()); |
2026 | 2029 |
2027 // Verify that prototype transitions array was compacted. | 2030 // Verify that prototype transitions array was compacted. |
2028 FixedArray* trans = baseObject->map()->GetPrototypeTransitions(); | 2031 FixedArray* trans = baseObject->map()->GetPrototypeTransitions(); |
2029 for (int i = 0; i < transitions; i++) { | 2032 for (int i = initialTransitions; i < initialTransitions + transitions; i++) { |
2030 int j = Map::kProtoTransitionHeaderSize + | 2033 int j = Map::kProtoTransitionHeaderSize + |
2031 i * Map::kProtoTransitionElementsPerEntry; | 2034 i * Map::kProtoTransitionElementsPerEntry; |
2032 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap()); | 2035 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap()); |
2033 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset); | 2036 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset); |
2034 CHECK(proto->IsTheHole() || proto->IsJSObject()); | 2037 CHECK(proto->IsJSObject()); |
2035 } | 2038 } |
2036 | 2039 |
2037 // Make sure next prototype is placed on an old-space evacuation candidate. | 2040 // Make sure next prototype is placed on an old-space evacuation candidate. |
2038 Handle<JSObject> prototype; | 2041 Handle<JSObject> prototype; |
2039 PagedSpace* space = CcTest::heap()->old_pointer_space(); | 2042 PagedSpace* space = CcTest::heap()->old_pointer_space(); |
2040 { | 2043 { |
2041 AlwaysAllocateScope always_allocate; | 2044 AlwaysAllocateScope always_allocate; |
2042 SimulateFullSpace(space); | 2045 SimulateFullSpace(space); |
2043 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED); | 2046 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED); |
2044 } | 2047 } |
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3730 v8::Handle<v8::Object> global = CcTest::global(); | 3733 v8::Handle<v8::Object> global = CcTest::global(); |
3731 v8::Handle<v8::Function> g = | 3734 v8::Handle<v8::Function> g = |
3732 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); | 3735 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); |
3733 v8::Handle<v8::Value> args1[] = { v8_num(1) }; | 3736 v8::Handle<v8::Value> args1[] = { v8_num(1) }; |
3734 heap->DisableInlineAllocation(); | 3737 heap->DisableInlineAllocation(); |
3735 heap->set_allocation_timeout(1); | 3738 heap->set_allocation_timeout(1); |
3736 g->Call(global, 1, args1); | 3739 g->Call(global, 1, args1); |
3737 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3740 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
3738 } | 3741 } |
3739 #endif | 3742 #endif |
OLD | NEW |