| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 52 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| 53 public: | 53 public: |
| 54 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 54 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
| 55 | 55 |
| 56 bool has_been_disposed() { return has_been_disposed_; } | 56 bool has_been_disposed() { return has_been_disposed_; } |
| 57 | 57 |
| 58 virtual void Dispose() { | 58 virtual void Dispose() { |
| 59 ASSERT(!has_been_disposed_); | 59 DCHECK(!has_been_disposed_); |
| 60 has_been_disposed_ = true; | 60 has_been_disposed_ = true; |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { | 63 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { |
| 64 return other == this; | 64 return other == this; |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual intptr_t GetHash() { return 0; } | 67 virtual intptr_t GetHash() { return 0; } |
| 68 | 68 |
| 69 virtual const char* GetLabel() { return "whatever"; } | 69 virtual const char* GetLabel() { return "whatever"; } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 { | 114 { |
| 115 ResetCanSkipData(); | 115 ResetCanSkipData(); |
| 116 skippable_objects.Add(*g1s1.location()); | 116 skippable_objects.Add(*g1s1.location()); |
| 117 skippable_objects.Add(*g1s2.location()); | 117 skippable_objects.Add(*g1s2.location()); |
| 118 skippable_objects.Add(*g2s1.location()); | 118 skippable_objects.Add(*g2s1.location()); |
| 119 skippable_objects.Add(*g2s2.location()); | 119 skippable_objects.Add(*g2s2.location()); |
| 120 TestObjectVisitor visitor; | 120 TestObjectVisitor visitor; |
| 121 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 121 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 122 | 122 |
| 123 // CanSkipCallback was called for all objects. | 123 // CanSkipCallback was called for all objects. |
| 124 ASSERT(can_skip_called_objects.length() == 4); | 124 DCHECK(can_skip_called_objects.length() == 4); |
| 125 ASSERT(can_skip_called_objects.Contains(*g1s1.location())); | 125 DCHECK(can_skip_called_objects.Contains(*g1s1.location())); |
| 126 ASSERT(can_skip_called_objects.Contains(*g1s2.location())); | 126 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); |
| 127 ASSERT(can_skip_called_objects.Contains(*g2s1.location())); | 127 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); |
| 128 ASSERT(can_skip_called_objects.Contains(*g2s2.location())); | 128 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); |
| 129 | 129 |
| 130 // Nothing was visited. | 130 // Nothing was visited. |
| 131 ASSERT(visitor.visited.length() == 0); | 131 DCHECK(visitor.visited.length() == 0); |
| 132 ASSERT(!info1.has_been_disposed()); | 132 DCHECK(!info1.has_been_disposed()); |
| 133 ASSERT(!info2.has_been_disposed()); | 133 DCHECK(!info2.has_been_disposed()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Iterate again, now only skip the second object group. | 136 // Iterate again, now only skip the second object group. |
| 137 { | 137 { |
| 138 ResetCanSkipData(); | 138 ResetCanSkipData(); |
| 139 // The first grough should still be visited, since only one object is | 139 // The first grough should still be visited, since only one object is |
| 140 // skipped. | 140 // skipped. |
| 141 skippable_objects.Add(*g1s1.location()); | 141 skippable_objects.Add(*g1s1.location()); |
| 142 skippable_objects.Add(*g2s1.location()); | 142 skippable_objects.Add(*g2s1.location()); |
| 143 skippable_objects.Add(*g2s2.location()); | 143 skippable_objects.Add(*g2s2.location()); |
| 144 TestObjectVisitor visitor; | 144 TestObjectVisitor visitor; |
| 145 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 145 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 146 | 146 |
| 147 // CanSkipCallback was called for all objects. | 147 // CanSkipCallback was called for all objects. |
| 148 ASSERT(can_skip_called_objects.length() == 3 || | 148 DCHECK(can_skip_called_objects.length() == 3 || |
| 149 can_skip_called_objects.length() == 4); | 149 can_skip_called_objects.length() == 4); |
| 150 ASSERT(can_skip_called_objects.Contains(*g1s2.location())); | 150 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); |
| 151 ASSERT(can_skip_called_objects.Contains(*g2s1.location())); | 151 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); |
| 152 ASSERT(can_skip_called_objects.Contains(*g2s2.location())); | 152 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); |
| 153 | 153 |
| 154 // The first group was visited. | 154 // The first group was visited. |
| 155 ASSERT(visitor.visited.length() == 2); | 155 DCHECK(visitor.visited.length() == 2); |
| 156 ASSERT(visitor.visited.Contains(*g1s1.location())); | 156 DCHECK(visitor.visited.Contains(*g1s1.location())); |
| 157 ASSERT(visitor.visited.Contains(*g1s2.location())); | 157 DCHECK(visitor.visited.Contains(*g1s2.location())); |
| 158 ASSERT(info1.has_been_disposed()); | 158 DCHECK(info1.has_been_disposed()); |
| 159 ASSERT(!info2.has_been_disposed()); | 159 DCHECK(!info2.has_been_disposed()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Iterate again, don't skip anything. | 162 // Iterate again, don't skip anything. |
| 163 { | 163 { |
| 164 ResetCanSkipData(); | 164 ResetCanSkipData(); |
| 165 TestObjectVisitor visitor; | 165 TestObjectVisitor visitor; |
| 166 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 166 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 167 | 167 |
| 168 // CanSkipCallback was called for all objects. | 168 // CanSkipCallback was called for all objects. |
| 169 ASSERT(can_skip_called_objects.length() == 1); | 169 DCHECK(can_skip_called_objects.length() == 1); |
| 170 ASSERT(can_skip_called_objects.Contains(*g2s1.location()) || | 170 DCHECK(can_skip_called_objects.Contains(*g2s1.location()) || |
| 171 can_skip_called_objects.Contains(*g2s2.location())); | 171 can_skip_called_objects.Contains(*g2s2.location())); |
| 172 | 172 |
| 173 // The second group was visited. | 173 // The second group was visited. |
| 174 ASSERT(visitor.visited.length() == 2); | 174 DCHECK(visitor.visited.length() == 2); |
| 175 ASSERT(visitor.visited.Contains(*g2s1.location())); | 175 DCHECK(visitor.visited.Contains(*g2s1.location())); |
| 176 ASSERT(visitor.visited.Contains(*g2s2.location())); | 176 DCHECK(visitor.visited.Contains(*g2s2.location())); |
| 177 ASSERT(info2.has_been_disposed()); | 177 DCHECK(info2.has_been_disposed()); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 TEST(IterateObjectGroups) { | 182 TEST(IterateObjectGroups) { |
| 183 CcTest::InitializeVM(); | 183 CcTest::InitializeVM(); |
| 184 Isolate* isolate = CcTest::i_isolate(); | 184 Isolate* isolate = CcTest::i_isolate(); |
| 185 GlobalHandles* global_handles = isolate->global_handles(); | 185 GlobalHandles* global_handles = isolate->global_handles(); |
| 186 | 186 |
| 187 v8::HandleScope handle_scope(CcTest::isolate()); | 187 v8::HandleScope handle_scope(CcTest::isolate()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 209 { | 209 { |
| 210 ResetCanSkipData(); | 210 ResetCanSkipData(); |
| 211 skippable_objects.Add(*g1s1.location()); | 211 skippable_objects.Add(*g1s1.location()); |
| 212 skippable_objects.Add(*g1s2.location()); | 212 skippable_objects.Add(*g1s2.location()); |
| 213 skippable_objects.Add(*g2s1.location()); | 213 skippable_objects.Add(*g2s1.location()); |
| 214 skippable_objects.Add(*g2s2.location()); | 214 skippable_objects.Add(*g2s2.location()); |
| 215 TestObjectVisitor visitor; | 215 TestObjectVisitor visitor; |
| 216 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 216 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 217 | 217 |
| 218 // CanSkipCallback was called for all objects. | 218 // CanSkipCallback was called for all objects. |
| 219 ASSERT(can_skip_called_objects.length() == 4); | 219 DCHECK(can_skip_called_objects.length() == 4); |
| 220 ASSERT(can_skip_called_objects.Contains(*g1s1.location())); | 220 DCHECK(can_skip_called_objects.Contains(*g1s1.location())); |
| 221 ASSERT(can_skip_called_objects.Contains(*g1s2.location())); | 221 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); |
| 222 ASSERT(can_skip_called_objects.Contains(*g2s1.location())); | 222 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); |
| 223 ASSERT(can_skip_called_objects.Contains(*g2s2.location())); | 223 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); |
| 224 | 224 |
| 225 // Nothing was visited. | 225 // Nothing was visited. |
| 226 ASSERT(visitor.visited.length() == 0); | 226 DCHECK(visitor.visited.length() == 0); |
| 227 ASSERT(!info1.has_been_disposed()); | 227 DCHECK(!info1.has_been_disposed()); |
| 228 ASSERT(!info2.has_been_disposed()); | 228 DCHECK(!info2.has_been_disposed()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Iterate again, now only skip the second object group. | 231 // Iterate again, now only skip the second object group. |
| 232 { | 232 { |
| 233 ResetCanSkipData(); | 233 ResetCanSkipData(); |
| 234 // The first grough should still be visited, since only one object is | 234 // The first grough should still be visited, since only one object is |
| 235 // skipped. | 235 // skipped. |
| 236 skippable_objects.Add(*g1s1.location()); | 236 skippable_objects.Add(*g1s1.location()); |
| 237 skippable_objects.Add(*g2s1.location()); | 237 skippable_objects.Add(*g2s1.location()); |
| 238 skippable_objects.Add(*g2s2.location()); | 238 skippable_objects.Add(*g2s2.location()); |
| 239 TestObjectVisitor visitor; | 239 TestObjectVisitor visitor; |
| 240 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 240 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 241 | 241 |
| 242 // CanSkipCallback was called for all objects. | 242 // CanSkipCallback was called for all objects. |
| 243 ASSERT(can_skip_called_objects.length() == 3 || | 243 DCHECK(can_skip_called_objects.length() == 3 || |
| 244 can_skip_called_objects.length() == 4); | 244 can_skip_called_objects.length() == 4); |
| 245 ASSERT(can_skip_called_objects.Contains(*g1s2.location())); | 245 DCHECK(can_skip_called_objects.Contains(*g1s2.location())); |
| 246 ASSERT(can_skip_called_objects.Contains(*g2s1.location())); | 246 DCHECK(can_skip_called_objects.Contains(*g2s1.location())); |
| 247 ASSERT(can_skip_called_objects.Contains(*g2s2.location())); | 247 DCHECK(can_skip_called_objects.Contains(*g2s2.location())); |
| 248 | 248 |
| 249 // The first group was visited. | 249 // The first group was visited. |
| 250 ASSERT(visitor.visited.length() == 2); | 250 DCHECK(visitor.visited.length() == 2); |
| 251 ASSERT(visitor.visited.Contains(*g1s1.location())); | 251 DCHECK(visitor.visited.Contains(*g1s1.location())); |
| 252 ASSERT(visitor.visited.Contains(*g1s2.location())); | 252 DCHECK(visitor.visited.Contains(*g1s2.location())); |
| 253 ASSERT(info1.has_been_disposed()); | 253 DCHECK(info1.has_been_disposed()); |
| 254 ASSERT(!info2.has_been_disposed()); | 254 DCHECK(!info2.has_been_disposed()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Iterate again, don't skip anything. | 257 // Iterate again, don't skip anything. |
| 258 { | 258 { |
| 259 ResetCanSkipData(); | 259 ResetCanSkipData(); |
| 260 TestObjectVisitor visitor; | 260 TestObjectVisitor visitor; |
| 261 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); | 261 global_handles->IterateObjectGroups(&visitor, &CanSkipCallback); |
| 262 | 262 |
| 263 // CanSkipCallback was called for all objects. | 263 // CanSkipCallback was called for all objects. |
| 264 ASSERT(can_skip_called_objects.length() == 1); | 264 DCHECK(can_skip_called_objects.length() == 1); |
| 265 ASSERT(can_skip_called_objects.Contains(*g2s1.location()) || | 265 DCHECK(can_skip_called_objects.Contains(*g2s1.location()) || |
| 266 can_skip_called_objects.Contains(*g2s2.location())); | 266 can_skip_called_objects.Contains(*g2s2.location())); |
| 267 | 267 |
| 268 // The second group was visited. | 268 // The second group was visited. |
| 269 ASSERT(visitor.visited.length() == 2); | 269 DCHECK(visitor.visited.length() == 2); |
| 270 ASSERT(visitor.visited.Contains(*g2s1.location())); | 270 DCHECK(visitor.visited.Contains(*g2s1.location())); |
| 271 ASSERT(visitor.visited.Contains(*g2s2.location())); | 271 DCHECK(visitor.visited.Contains(*g2s2.location())); |
| 272 ASSERT(info2.has_been_disposed()); | 272 DCHECK(info2.has_been_disposed()); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 TEST(ImplicitReferences) { | 277 TEST(ImplicitReferences) { |
| 278 CcTest::InitializeVM(); | 278 CcTest::InitializeVM(); |
| 279 Isolate* isolate = CcTest::i_isolate(); | 279 Isolate* isolate = CcTest::i_isolate(); |
| 280 GlobalHandles* global_handles = isolate->global_handles(); | 280 GlobalHandles* global_handles = isolate->global_handles(); |
| 281 | 281 |
| 282 v8::HandleScope handle_scope(CcTest::isolate()); | 282 v8::HandleScope handle_scope(CcTest::isolate()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 299 global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1)); | 299 global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1)); |
| 300 global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2)); | 300 global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2)); |
| 301 global_handles->SetObjectGroupId(g2s2.location(), UniqueId(2)); | 301 global_handles->SetObjectGroupId(g2s2.location(), UniqueId(2)); |
| 302 global_handles->SetReferenceFromGroup(UniqueId(1), g1c1.location()); | 302 global_handles->SetReferenceFromGroup(UniqueId(1), g1c1.location()); |
| 303 global_handles->SetReferenceFromGroup(UniqueId(1), g1c2.location()); | 303 global_handles->SetReferenceFromGroup(UniqueId(1), g1c2.location()); |
| 304 global_handles->SetReferenceFromGroup(UniqueId(2), g2c1.location()); | 304 global_handles->SetReferenceFromGroup(UniqueId(2), g2c1.location()); |
| 305 | 305 |
| 306 List<ImplicitRefGroup*>* implicit_refs = | 306 List<ImplicitRefGroup*>* implicit_refs = |
| 307 global_handles->implicit_ref_groups(); | 307 global_handles->implicit_ref_groups(); |
| 308 USE(implicit_refs); | 308 USE(implicit_refs); |
| 309 ASSERT(implicit_refs->length() == 2); | 309 DCHECK(implicit_refs->length() == 2); |
| 310 ASSERT(implicit_refs->at(0)->parent == | 310 DCHECK(implicit_refs->at(0)->parent == |
| 311 reinterpret_cast<HeapObject**>(g1s1.location())); | 311 reinterpret_cast<HeapObject**>(g1s1.location())); |
| 312 ASSERT(implicit_refs->at(0)->length == 2); | 312 DCHECK(implicit_refs->at(0)->length == 2); |
| 313 ASSERT(implicit_refs->at(0)->children[0] == g1c1.location()); | 313 DCHECK(implicit_refs->at(0)->children[0] == g1c1.location()); |
| 314 ASSERT(implicit_refs->at(0)->children[1] == g1c2.location()); | 314 DCHECK(implicit_refs->at(0)->children[1] == g1c2.location()); |
| 315 ASSERT(implicit_refs->at(1)->parent == | 315 DCHECK(implicit_refs->at(1)->parent == |
| 316 reinterpret_cast<HeapObject**>(g2s1.location())); | 316 reinterpret_cast<HeapObject**>(g2s1.location())); |
| 317 ASSERT(implicit_refs->at(1)->length == 1); | 317 DCHECK(implicit_refs->at(1)->length == 1); |
| 318 ASSERT(implicit_refs->at(1)->children[0] == g2c1.location()); | 318 DCHECK(implicit_refs->at(1)->children[0] == g2c1.location()); |
| 319 global_handles->RemoveObjectGroups(); | 319 global_handles->RemoveObjectGroups(); |
| 320 global_handles->RemoveImplicitRefGroups(); | 320 global_handles->RemoveImplicitRefGroups(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 TEST(EternalHandles) { | 324 TEST(EternalHandles) { |
| 325 CcTest::InitializeVM(); | 325 CcTest::InitializeVM(); |
| 326 Isolate* isolate = CcTest::i_isolate(); | 326 Isolate* isolate = CcTest::i_isolate(); |
| 327 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 327 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 328 EternalHandles* eternal_handles = isolate->eternal_handles(); | 328 EternalHandles* eternal_handles = isolate->eternal_handles(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 { | 373 { |
| 374 HandleScope scope(isolate); | 374 HandleScope scope(isolate); |
| 375 v8::Local<v8::Object> object = v8::Object::New(v8_isolate); | 375 v8::Local<v8::Object> object = v8::Object::New(v8_isolate); |
| 376 v8::Eternal<v8::Object> eternal(v8_isolate, object); | 376 v8::Eternal<v8::Object> eternal(v8_isolate, object); |
| 377 CHECK(!eternal.IsEmpty()); | 377 CHECK(!eternal.IsEmpty()); |
| 378 CHECK(object == eternal.Get(v8_isolate)); | 378 CHECK(object == eternal.Get(v8_isolate)); |
| 379 } | 379 } |
| 380 | 380 |
| 381 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles()); | 381 CHECK_EQ(2*kArrayLength + 1, eternal_handles->NumberOfHandles()); |
| 382 } | 382 } |
| OLD | NEW |