| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 using namespace v8::internal; | 40 using namespace v8::internal; |
| 41 | 41 |
| 42 | 42 |
| 43 static void SetUpNewSpaceWithPoisonedMementoAtTop() { | 43 static void SetUpNewSpaceWithPoisonedMementoAtTop() { |
| 44 Isolate* isolate = CcTest::i_isolate(); | 44 Isolate* isolate = CcTest::i_isolate(); |
| 45 Heap* heap = isolate->heap(); | 45 Heap* heap = isolate->heap(); |
| 46 NewSpace* new_space = heap->new_space(); | 46 NewSpace* new_space = heap->new_space(); |
| 47 | 47 |
| 48 // Make sure we can allocate some objects without causing a GC later. | 48 // Make sure we can allocate some objects without causing a GC later. |
| 49 heap->CollectAllGarbage(); | 49 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 50 | 50 |
| 51 // Allocate a string, the GC may suspect a memento behind the string. | 51 // Allocate a string, the GC may suspect a memento behind the string. |
| 52 Handle<SeqOneByteString> string = | 52 Handle<SeqOneByteString> string = |
| 53 isolate->factory()->NewRawOneByteString(12).ToHandleChecked(); | 53 isolate->factory()->NewRawOneByteString(12).ToHandleChecked(); |
| 54 CHECK(*string); | 54 CHECK(*string); |
| 55 | 55 |
| 56 // Create an allocation memento behind the string with a garbage allocation | 56 // Create an allocation memento behind the string with a garbage allocation |
| 57 // site pointer. | 57 // site pointer. |
| 58 AllocationMemento* memento = | 58 AllocationMemento* memento = |
| 59 reinterpret_cast<AllocationMemento*>(new_space->top() + kHeapObjectTag); | 59 reinterpret_cast<AllocationMemento*>(new_space->top() + kHeapObjectTag); |
| 60 memento->set_map_no_write_barrier(heap->allocation_memento_map()); | 60 memento->set_map_no_write_barrier(heap->allocation_memento_map()); |
| 61 memento->set_allocation_site( | 61 memento->set_allocation_site( |
| 62 reinterpret_cast<AllocationSite*>(kHeapObjectTag), SKIP_WRITE_BARRIER); | 62 reinterpret_cast<AllocationSite*>(kHeapObjectTag), SKIP_WRITE_BARRIER); |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 TEST(Regress340063) { | 66 TEST(Regress340063) { |
| 67 CcTest::InitializeVM(); | 67 CcTest::InitializeVM(); |
| 68 if (!i::FLAG_allocation_site_pretenuring) return; | 68 if (!i::FLAG_allocation_site_pretenuring) return; |
| 69 v8::HandleScope scope(CcTest::isolate()); | 69 v8::HandleScope scope(CcTest::isolate()); |
| 70 | 70 |
| 71 SetUpNewSpaceWithPoisonedMementoAtTop(); | 71 SetUpNewSpaceWithPoisonedMementoAtTop(); |
| 72 | 72 |
| 73 // Call GC to see if we can handle a poisonous memento right after the | 73 // Call GC to see if we can handle a poisonous memento right after the |
| 74 // current new space top pointer. | 74 // current new space top pointer. |
| 75 CcTest::i_isolate()->heap()->CollectAllGarbage( | 75 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 76 Heap::kAbortIncrementalMarkingMask); | |
| 77 } | 76 } |
| 78 | 77 |
| 79 | 78 |
| 80 TEST(Regress470390) { | 79 TEST(Regress470390) { |
| 81 CcTest::InitializeVM(); | 80 CcTest::InitializeVM(); |
| 82 if (!i::FLAG_allocation_site_pretenuring) return; | 81 if (!i::FLAG_allocation_site_pretenuring) return; |
| 83 v8::HandleScope scope(CcTest::isolate()); | 82 v8::HandleScope scope(CcTest::isolate()); |
| 84 | 83 |
| 85 SetUpNewSpaceWithPoisonedMementoAtTop(); | 84 SetUpNewSpaceWithPoisonedMementoAtTop(); |
| 86 | 85 |
| 87 // Set the new space limit to be equal to the top. | 86 // Set the new space limit to be equal to the top. |
| 88 Address top = CcTest::i_isolate()->heap()->new_space()->top(); | 87 Address top = CcTest::i_isolate()->heap()->new_space()->top(); |
| 89 *(CcTest::i_isolate()->heap()->new_space()->allocation_limit_address()) = top; | 88 *(CcTest::i_isolate()->heap()->new_space()->allocation_limit_address()) = top; |
| 90 | 89 |
| 91 // Call GC to see if we can handle a poisonous memento right after the | 90 // Call GC to see if we can handle a poisonous memento right after the |
| 92 // current new space top pointer. | 91 // current new space top pointer. |
| 93 CcTest::i_isolate()->heap()->CollectAllGarbage( | 92 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 94 Heap::kAbortIncrementalMarkingMask); | |
| 95 } | 93 } |
| 96 | 94 |
| 97 | 95 |
| 98 TEST(BadMementoAfterTopForceScavenge) { | 96 TEST(BadMementoAfterTopForceScavenge) { |
| 99 CcTest::InitializeVM(); | 97 CcTest::InitializeVM(); |
| 100 if (!i::FLAG_allocation_site_pretenuring) return; | 98 if (!i::FLAG_allocation_site_pretenuring) return; |
| 101 v8::HandleScope scope(CcTest::isolate()); | 99 v8::HandleScope scope(CcTest::isolate()); |
| 102 | 100 |
| 103 SetUpNewSpaceWithPoisonedMementoAtTop(); | 101 SetUpNewSpaceWithPoisonedMementoAtTop(); |
| 104 | 102 |
| 105 // Force GC to test the poisoned memento handling | 103 // Force GC to test the poisoned memento handling |
| 106 CcTest::i_isolate()->heap()->CollectGarbage(i::NEW_SPACE); | 104 CcTest::CollectGarbage(i::NEW_SPACE); |
| 107 } | 105 } |
| OLD | NEW |