| 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <utility> | 28 #include <utility> |
| 29 | 29 |
| 30 #include "src/v8.h" | 30 #include "src/v8.h" |
| 31 | 31 |
| 32 #include "src/global-handles.h" | 32 #include "src/global-handles.h" |
| 33 #include "test/cctest/cctest.h" | 33 #include "test/cctest/cctest.h" |
| 34 #include "test/cctest/heap/utils-inl.h" | 34 #include "test/cctest/heap/heap-utils.h" |
| 35 | 35 |
| 36 using namespace v8::internal; | 36 using namespace v8::internal; |
| 37 | 37 |
| 38 static Isolate* GetIsolateFrom(LocalContext* context) { | 38 static Isolate* GetIsolateFrom(LocalContext* context) { |
| 39 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); | 39 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 | 42 |
| 43 static Handle<JSWeakSet> AllocateJSWeakSet(Isolate* isolate) { | 43 static Handle<JSWeakSet> AllocateJSWeakSet(Isolate* isolate) { |
| 44 Factory* factory = isolate->factory(); | 44 Factory* factory = isolate->factory(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 Factory* factory = isolate->factory(); | 169 Factory* factory = isolate->factory(); |
| 170 Heap* heap = isolate->heap(); | 170 Heap* heap = isolate->heap(); |
| 171 HandleScope scope(isolate); | 171 HandleScope scope(isolate); |
| 172 Handle<JSFunction> function = factory->NewFunction( | 172 Handle<JSFunction> function = factory->NewFunction( |
| 173 factory->function_string()); | 173 factory->function_string()); |
| 174 Handle<JSObject> key = factory->NewJSObject(function); | 174 Handle<JSObject> key = factory->NewJSObject(function); |
| 175 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); | 175 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); |
| 176 | 176 |
| 177 // Start second old-space page so that values land on evacuation candidate. | 177 // Start second old-space page so that values land on evacuation candidate. |
| 178 Page* first_page = heap->old_space()->anchor()->next_page(); | 178 Page* first_page = heap->old_space()->anchor()->next_page(); |
| 179 SimulateFullSpace(heap->old_space()); | 179 heap::SimulateFullSpace(heap->old_space()); |
| 180 | 180 |
| 181 // Fill up weak set with values on an evacuation candidate. | 181 // Fill up weak set with values on an evacuation candidate. |
| 182 { | 182 { |
| 183 HandleScope scope(isolate); | 183 HandleScope scope(isolate); |
| 184 for (int i = 0; i < 32; i++) { | 184 for (int i = 0; i < 32; i++) { |
| 185 Handle<JSObject> object = factory->NewJSObject(function, TENURED); | 185 Handle<JSObject> object = factory->NewJSObject(function, TENURED); |
| 186 CHECK(!heap->InNewSpace(*object)); | 186 CHECK(!heap->InNewSpace(*object)); |
| 187 CHECK(!first_page->Contains(object->address())); | 187 CHECK(!first_page->Contains(object->address())); |
| 188 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); | 188 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); |
| 189 JSWeakCollection::Set(weakset, key, object, hash); | 189 JSWeakCollection::Set(weakset, key, object, hash); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 208 LocalContext context; | 208 LocalContext context; |
| 209 Isolate* isolate = GetIsolateFrom(&context); | 209 Isolate* isolate = GetIsolateFrom(&context); |
| 210 Factory* factory = isolate->factory(); | 210 Factory* factory = isolate->factory(); |
| 211 Heap* heap = isolate->heap(); | 211 Heap* heap = isolate->heap(); |
| 212 HandleScope scope(isolate); | 212 HandleScope scope(isolate); |
| 213 Handle<JSFunction> function = factory->NewFunction( | 213 Handle<JSFunction> function = factory->NewFunction( |
| 214 factory->function_string()); | 214 factory->function_string()); |
| 215 | 215 |
| 216 // Start second old-space page so that keys land on evacuation candidate. | 216 // Start second old-space page so that keys land on evacuation candidate. |
| 217 Page* first_page = heap->old_space()->anchor()->next_page(); | 217 Page* first_page = heap->old_space()->anchor()->next_page(); |
| 218 SimulateFullSpace(heap->old_space()); | 218 heap::SimulateFullSpace(heap->old_space()); |
| 219 | 219 |
| 220 // Fill up weak set with keys on an evacuation candidate. | 220 // Fill up weak set with keys on an evacuation candidate. |
| 221 Handle<JSObject> keys[32]; | 221 Handle<JSObject> keys[32]; |
| 222 for (int i = 0; i < 32; i++) { | 222 for (int i = 0; i < 32; i++) { |
| 223 keys[i] = factory->NewJSObject(function, TENURED); | 223 keys[i] = factory->NewJSObject(function, TENURED); |
| 224 CHECK(!heap->InNewSpace(*keys[i])); | 224 CHECK(!heap->InNewSpace(*keys[i])); |
| 225 CHECK(!first_page->Contains(keys[i]->address())); | 225 CHECK(!first_page->Contains(keys[i]->address())); |
| 226 } | 226 } |
| 227 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); | 227 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); |
| 228 for (int i = 0; i < 32; i++) { | 228 for (int i = 0; i < 32; i++) { |
| 229 Handle<Smi> smi(Smi::FromInt(i), isolate); | 229 Handle<Smi> smi(Smi::FromInt(i), isolate); |
| 230 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); | 230 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); |
| 231 JSWeakCollection::Set(weakset, keys[i], smi, hash); | 231 JSWeakCollection::Set(weakset, keys[i], smi, hash); |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Force compacting garbage collection. The subsequent collections are used | 234 // Force compacting garbage collection. The subsequent collections are used |
| 235 // to verify that key references were actually updated. | 235 // to verify that key references were actually updated. |
| 236 CHECK(FLAG_always_compact); | 236 CHECK(FLAG_always_compact); |
| 237 heap->CollectAllGarbage(); | 237 heap->CollectAllGarbage(); |
| 238 heap->CollectAllGarbage(); | 238 heap->CollectAllGarbage(); |
| 239 heap->CollectAllGarbage(); | 239 heap->CollectAllGarbage(); |
| 240 } | 240 } |
| OLD | NEW |