Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/cctest/test-weaksets.cc

Issue 2310143002: [heap] Introduce enum of garbage collection reasons. (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-weakmaps.cc ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 NumberOfWeakCalls++; 72 NumberOfWeakCalls++;
73 p->first->Reset(); 73 p->first->Reset();
74 } 74 }
75 75
76 76
77 TEST(WeakSet_Weakness) { 77 TEST(WeakSet_Weakness) {
78 FLAG_incremental_marking = false; 78 FLAG_incremental_marking = false;
79 LocalContext context; 79 LocalContext context;
80 Isolate* isolate = GetIsolateFrom(&context); 80 Isolate* isolate = GetIsolateFrom(&context);
81 Factory* factory = isolate->factory(); 81 Factory* factory = isolate->factory();
82 Heap* heap = isolate->heap();
83 HandleScope scope(isolate); 82 HandleScope scope(isolate);
84 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); 83 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
85 GlobalHandles* global_handles = isolate->global_handles(); 84 GlobalHandles* global_handles = isolate->global_handles();
86 85
87 // Keep global reference to the key. 86 // Keep global reference to the key.
88 Handle<Object> key; 87 Handle<Object> key;
89 { 88 {
90 HandleScope scope(isolate); 89 HandleScope scope(isolate);
91 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 90 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
92 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 91 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
93 key = global_handles->Create(*object); 92 key = global_handles->Create(*object);
94 } 93 }
95 CHECK(!global_handles->IsWeak(key.location())); 94 CHECK(!global_handles->IsWeak(key.location()));
96 95
97 // Put entry into weak set. 96 // Put entry into weak set.
98 { 97 {
99 HandleScope scope(isolate); 98 HandleScope scope(isolate);
100 Handle<Smi> smi(Smi::FromInt(23), isolate); 99 Handle<Smi> smi(Smi::FromInt(23), isolate);
101 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 100 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
102 JSWeakCollection::Set(weakset, key, smi, hash); 101 JSWeakCollection::Set(weakset, key, smi, hash);
103 } 102 }
104 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 103 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
105 104
106 // Force a full GC. 105 // Force a full GC.
107 heap->CollectAllGarbage(false); 106 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
108 CHECK_EQ(0, NumberOfWeakCalls); 107 CHECK_EQ(0, NumberOfWeakCalls);
109 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 108 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
110 CHECK_EQ( 109 CHECK_EQ(
111 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 110 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
112 111
113 // Make the global reference to the key weak. 112 // Make the global reference to the key weak.
114 { 113 {
115 HandleScope scope(isolate); 114 HandleScope scope(isolate);
116 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234); 115 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
117 GlobalHandles::MakeWeak( 116 GlobalHandles::MakeWeak(
118 key.location(), reinterpret_cast<void*>(&handle_and_id), 117 key.location(), reinterpret_cast<void*>(&handle_and_id),
119 &WeakPointerCallback, v8::WeakCallbackType::kParameter); 118 &WeakPointerCallback, v8::WeakCallbackType::kParameter);
120 } 119 }
121 CHECK(global_handles->IsWeak(key.location())); 120 CHECK(global_handles->IsWeak(key.location()));
122 121
123 heap->CollectAllGarbage(false); 122 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
124 CHECK_EQ(1, NumberOfWeakCalls); 123 CHECK_EQ(1, NumberOfWeakCalls);
125 CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 124 CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
126 CHECK_EQ( 125 CHECK_EQ(
127 1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 126 1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
128 } 127 }
129 128
130 129
131 TEST(WeakSet_Shrinking) { 130 TEST(WeakSet_Shrinking) {
132 LocalContext context; 131 LocalContext context;
133 Isolate* isolate = GetIsolateFrom(&context); 132 Isolate* isolate = GetIsolateFrom(&context);
134 Factory* factory = isolate->factory(); 133 Factory* factory = isolate->factory();
135 Heap* heap = isolate->heap();
136 HandleScope scope(isolate); 134 HandleScope scope(isolate);
137 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); 135 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
138 136
139 // Check initial capacity. 137 // Check initial capacity.
140 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); 138 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity());
141 139
142 // Fill up weak set to trigger capacity change. 140 // Fill up weak set to trigger capacity change.
143 { 141 {
144 HandleScope scope(isolate); 142 HandleScope scope(isolate);
145 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 143 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
146 for (int i = 0; i < 32; i++) { 144 for (int i = 0; i < 32; i++) {
147 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 145 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
148 Handle<Smi> smi(Smi::FromInt(i), isolate); 146 Handle<Smi> smi(Smi::FromInt(i), isolate);
149 int32_t hash = Object::GetOrCreateHash(isolate, object)->value(); 147 int32_t hash = Object::GetOrCreateHash(isolate, object)->value();
150 JSWeakCollection::Set(weakset, object, smi, hash); 148 JSWeakCollection::Set(weakset, object, smi, hash);
151 } 149 }
152 } 150 }
153 151
154 // Check increased capacity. 152 // Check increased capacity.
155 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity()); 153 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity());
156 154
157 // Force a full GC. 155 // Force a full GC.
158 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 156 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements());
159 CHECK_EQ( 157 CHECK_EQ(
160 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 158 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
161 heap->CollectAllGarbage(false); 159 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
162 CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 160 CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
163 CHECK_EQ( 161 CHECK_EQ(
164 32, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 162 32, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
165 163
166 // Check shrunk capacity. 164 // Check shrunk capacity.
167 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); 165 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity());
168 } 166 }
169 167
170 168
171 // Test that weak set values on an evacuation candidate which are not reachable 169 // Test that weak set values on an evacuation candidate which are not reachable
(...skipping 22 matching lines...) Expand all
194 Handle<JSObject> object = factory->NewJSObject(function, TENURED); 192 Handle<JSObject> object = factory->NewJSObject(function, TENURED);
195 CHECK(!heap->InNewSpace(*object)); 193 CHECK(!heap->InNewSpace(*object));
196 CHECK(!first_page->Contains(object->address())); 194 CHECK(!first_page->Contains(object->address()));
197 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 195 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
198 JSWeakCollection::Set(weakset, key, object, hash); 196 JSWeakCollection::Set(weakset, key, object, hash);
199 } 197 }
200 } 198 }
201 199
202 // Force compacting garbage collection. 200 // Force compacting garbage collection.
203 CHECK(FLAG_always_compact); 201 CHECK(FLAG_always_compact);
204 heap->CollectAllGarbage(); 202 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
205 } 203 }
206 204
207 205
208 // Test that weak set keys on an evacuation candidate which are reachable by 206 // Test that weak set keys on an evacuation candidate which are reachable by
209 // other strong paths are correctly recorded in the slots buffer. 207 // other strong paths are correctly recorded in the slots buffer.
210 TEST(WeakSet_Regress2060b) { 208 TEST(WeakSet_Regress2060b) {
211 if (i::FLAG_never_compact) return; 209 if (i::FLAG_never_compact) return;
212 FLAG_always_compact = true; 210 FLAG_always_compact = true;
213 #ifdef VERIFY_HEAP 211 #ifdef VERIFY_HEAP
214 FLAG_verify_heap = true; 212 FLAG_verify_heap = true;
(...skipping 21 matching lines...) Expand all
236 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); 234 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
237 for (int i = 0; i < 32; i++) { 235 for (int i = 0; i < 32; i++) {
238 Handle<Smi> smi(Smi::FromInt(i), isolate); 236 Handle<Smi> smi(Smi::FromInt(i), isolate);
239 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); 237 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
240 JSWeakCollection::Set(weakset, keys[i], smi, hash); 238 JSWeakCollection::Set(weakset, keys[i], smi, hash);
241 } 239 }
242 240
243 // Force compacting garbage collection. The subsequent collections are used 241 // Force compacting garbage collection. The subsequent collections are used
244 // to verify that key references were actually updated. 242 // to verify that key references were actually updated.
245 CHECK(FLAG_always_compact); 243 CHECK(FLAG_always_compact);
246 heap->CollectAllGarbage(); 244 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
247 heap->CollectAllGarbage(); 245 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
248 heap->CollectAllGarbage(); 246 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
249 } 247 }
OLDNEW
« no previous file with comments | « test/cctest/test-weakmaps.cc ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698