OLD | NEW |
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 CHECK_EQ( | 151 CHECK_EQ( |
152 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); | 152 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
153 | 153 |
154 // Check shrunk capacity. | 154 // Check shrunk capacity. |
155 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); | 155 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 // Test that weak map values on an evacuation candidate which are not reachable | 159 // Test that weak map values on an evacuation candidate which are not reachable |
160 // by other paths are correctly recorded in the slots buffer. | 160 // by other paths are correctly recorded in the slots buffer. |
161 TEST(Regress2060) { | 161 TEST(Regress2060a) { |
162 FLAG_always_compact = true; | 162 FLAG_always_compact = true; |
163 LocalContext context; | 163 LocalContext context; |
164 v8::HandleScope scope; | 164 v8::HandleScope scope; |
165 Handle<JSFunction> function = | 165 Handle<JSFunction> function = |
166 FACTORY->NewFunction(FACTORY->function_symbol(), FACTORY->null_value()); | 166 FACTORY->NewFunction(FACTORY->function_symbol(), FACTORY->null_value()); |
167 Handle<JSObject> key = FACTORY->NewJSObject(function); | 167 Handle<JSObject> key = FACTORY->NewJSObject(function); |
168 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); | 168 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
169 | 169 |
170 // Start second old-space page so that values land on evacuation candidate. | 170 // Start second old-space page so that values land on evacuation candidate. |
171 Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); | 171 Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); |
172 FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); | 172 FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); |
173 | 173 |
174 // Fill up weak map with values on an evacuation candidate. | 174 // Fill up weak map with values on an evacuation candidate. |
175 { | 175 { |
176 v8::HandleScope scope; | 176 v8::HandleScope scope; |
177 for (int i = 0; i < 32; i++) { | 177 for (int i = 0; i < 32; i++) { |
178 Handle<JSObject> object = FACTORY->NewJSObject(function, TENURED); | 178 Handle<JSObject> object = FACTORY->NewJSObject(function, TENURED); |
179 CHECK(!HEAP->InNewSpace(object->address())); | 179 CHECK(!HEAP->InNewSpace(object->address())); |
180 CHECK(!first_page->Contains(object->address())); | 180 CHECK(!first_page->Contains(object->address())); |
181 PutIntoWeakMap(weakmap, key, object); | 181 PutIntoWeakMap(weakmap, key, object); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 // Force compacting garbage collection. | 185 // Force compacting garbage collection. |
186 CHECK(FLAG_always_compact); | 186 CHECK(FLAG_always_compact); |
187 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 187 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
188 } | 188 } |
| 189 |
| 190 |
| 191 // Test that weak map keys on an evacuation candidate which are reachable by |
| 192 // other strong paths are correctly recorded in the slots buffer. |
| 193 TEST(Regress2060b) { |
| 194 FLAG_always_compact = true; |
| 195 FLAG_verify_heap = true; |
| 196 LocalContext context; |
| 197 v8::HandleScope scope; |
| 198 Handle<JSFunction> function = |
| 199 FACTORY->NewFunction(FACTORY->function_symbol(), FACTORY->null_value()); |
| 200 |
| 201 // Start second old-space page so that keys land on evacuation candidate. |
| 202 Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); |
| 203 FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); |
| 204 |
| 205 // Fill up weak map with keys on an evacuation candidate. |
| 206 Handle<JSObject> keys[32]; |
| 207 for (int i = 0; i < 32; i++) { |
| 208 keys[i] = FACTORY->NewJSObject(function, TENURED); |
| 209 CHECK(!HEAP->InNewSpace(keys[i]->address())); |
| 210 CHECK(!first_page->Contains(keys[i]->address())); |
| 211 } |
| 212 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
| 213 for (int i = 0; i < 32; i++) { |
| 214 PutIntoWeakMap(weakmap, keys[i], Handle<Smi>(Smi::FromInt(i))); |
| 215 } |
| 216 |
| 217 // Force compacting garbage collection. The subsequent collections are used |
| 218 // to verify that key references were actually updated. |
| 219 CHECK(FLAG_always_compact); |
| 220 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 221 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 222 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 223 } |
OLD | NEW |