OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // To give an additional chance to fail, try to force compaction which | 229 // To give an additional chance to fail, try to force compaction which |
230 // should be impossible right now. | 230 // should be impossible right now. |
231 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); | 231 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); |
232 // And now map pointers should be encodable again. | 232 // And now map pointers should be encodable again. |
233 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); | 233 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); |
234 } | 234 } |
235 #endif | 235 #endif |
236 | 236 |
237 | 237 |
238 static int NumberOfWeakCalls = 0; | 238 static int NumberOfWeakCalls = 0; |
239 static void WeakPointerCallback( | 239 static void WeakPointerCallback(const v8::WeakCallbackInfo<void>& data) { |
240 const v8::WeakCallbackData<v8::Value, void>& data) { | |
241 std::pair<v8::Persistent<v8::Value>*, int>* p = | 240 std::pair<v8::Persistent<v8::Value>*, int>* p = |
242 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( | 241 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( |
243 data.GetParameter()); | 242 data.GetParameter()); |
244 CHECK_EQ(1234, p->second); | 243 CHECK_EQ(1234, p->second); |
245 NumberOfWeakCalls++; | 244 NumberOfWeakCalls++; |
246 p->first->Reset(); | 245 p->first->Reset(); |
247 } | 246 } |
248 | 247 |
249 | 248 |
250 HEAP_TEST(ObjectGroups) { | 249 HEAP_TEST(ObjectGroups) { |
251 FLAG_incremental_marking = false; | 250 FLAG_incremental_marking = false; |
252 CcTest::InitializeVM(); | 251 CcTest::InitializeVM(); |
253 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); | 252 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
254 Heap* heap = CcTest::heap(); | 253 Heap* heap = CcTest::heap(); |
255 NumberOfWeakCalls = 0; | 254 NumberOfWeakCalls = 0; |
256 v8::HandleScope handle_scope(CcTest::isolate()); | 255 v8::HandleScope handle_scope(CcTest::isolate()); |
257 | 256 |
258 Handle<Object> g1s1 = | 257 Handle<Object> g1s1 = |
259 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 258 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
260 Handle<Object> g1s2 = | 259 Handle<Object> g1s2 = |
261 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 260 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
262 Handle<Object> g1c1 = | 261 Handle<Object> g1c1 = |
263 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 262 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
264 std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234); | 263 std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234); |
265 GlobalHandles::MakeWeak(g1s1.location(), | 264 GlobalHandles::MakeWeak( |
266 reinterpret_cast<void*>(&g1s1_and_id), | 265 g1s1.location(), reinterpret_cast<void*>(&g1s1_and_id), |
267 &WeakPointerCallback); | 266 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
268 std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234); | 267 std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234); |
269 GlobalHandles::MakeWeak(g1s2.location(), | 268 GlobalHandles::MakeWeak( |
270 reinterpret_cast<void*>(&g1s2_and_id), | 269 g1s2.location(), reinterpret_cast<void*>(&g1s2_and_id), |
271 &WeakPointerCallback); | 270 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
272 std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234); | 271 std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234); |
273 GlobalHandles::MakeWeak(g1c1.location(), | 272 GlobalHandles::MakeWeak( |
274 reinterpret_cast<void*>(&g1c1_and_id), | 273 g1c1.location(), reinterpret_cast<void*>(&g1c1_and_id), |
275 &WeakPointerCallback); | 274 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
276 | 275 |
277 Handle<Object> g2s1 = | 276 Handle<Object> g2s1 = |
278 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 277 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
279 Handle<Object> g2s2 = | 278 Handle<Object> g2s2 = |
280 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 279 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
281 Handle<Object> g2c1 = | 280 Handle<Object> g2c1 = |
282 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); | 281 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked()); |
283 std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234); | 282 std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234); |
284 GlobalHandles::MakeWeak(g2s1.location(), | 283 GlobalHandles::MakeWeak( |
285 reinterpret_cast<void*>(&g2s1_and_id), | 284 g2s1.location(), reinterpret_cast<void*>(&g2s1_and_id), |
286 &WeakPointerCallback); | 285 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
287 std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234); | 286 std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234); |
288 GlobalHandles::MakeWeak(g2s2.location(), | 287 GlobalHandles::MakeWeak( |
289 reinterpret_cast<void*>(&g2s2_and_id), | 288 g2s2.location(), reinterpret_cast<void*>(&g2s2_and_id), |
290 &WeakPointerCallback); | 289 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
291 std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234); | 290 std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234); |
292 GlobalHandles::MakeWeak(g2c1.location(), | 291 GlobalHandles::MakeWeak( |
293 reinterpret_cast<void*>(&g2c1_and_id), | 292 g2c1.location(), reinterpret_cast<void*>(&g2c1_and_id), |
294 &WeakPointerCallback); | 293 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
295 | 294 |
296 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | 295 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
297 | 296 |
298 // Connect group 1 and 2, make a cycle. | 297 // Connect group 1 and 2, make a cycle. |
299 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 298 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
300 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 299 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
301 | 300 |
302 { | 301 { |
303 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 302 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
304 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 303 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
305 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 304 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
306 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), | 305 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), |
307 g1c1.location()); | 306 g1c1.location()); |
308 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 307 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
309 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), | 308 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), |
310 g2c1.location()); | 309 g2c1.location()); |
311 } | 310 } |
312 // Do a full GC | 311 // Do a full GC |
313 heap->CollectGarbage(OLD_SPACE); | 312 heap->CollectGarbage(OLD_SPACE); |
314 | 313 |
315 // All object should be alive. | 314 // All object should be alive. |
316 CHECK_EQ(0, NumberOfWeakCalls); | 315 CHECK_EQ(0, NumberOfWeakCalls); |
317 | 316 |
318 // Weaken the root. | 317 // Weaken the root. |
319 std::pair<Handle<Object>*, int> root_and_id(&root, 1234); | 318 std::pair<Handle<Object>*, int> root_and_id(&root, 1234); |
320 GlobalHandles::MakeWeak(root.location(), | 319 GlobalHandles::MakeWeak( |
321 reinterpret_cast<void*>(&root_and_id), | 320 root.location(), reinterpret_cast<void*>(&root_and_id), |
322 &WeakPointerCallback); | 321 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
323 // But make children strong roots---all the objects (except for children) | 322 // But make children strong roots---all the objects (except for children) |
324 // should be collectable now. | 323 // should be collectable now. |
325 global_handles->ClearWeakness(g1c1.location()); | 324 global_handles->ClearWeakness(g1c1.location()); |
326 global_handles->ClearWeakness(g2c1.location()); | 325 global_handles->ClearWeakness(g2c1.location()); |
327 | 326 |
328 // Groups are deleted, rebuild groups. | 327 // Groups are deleted, rebuild groups. |
329 { | 328 { |
330 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 329 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
331 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 330 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
332 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 331 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
333 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), | 332 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), |
334 g1c1.location()); | 333 g1c1.location()); |
335 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 334 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
336 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), | 335 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), |
337 g2c1.location()); | 336 g2c1.location()); |
338 } | 337 } |
339 | 338 |
340 heap->CollectGarbage(OLD_SPACE); | 339 heap->CollectGarbage(OLD_SPACE); |
341 | 340 |
342 // All objects should be gone. 5 global handles in total. | 341 // All objects should be gone. 5 global handles in total. |
343 CHECK_EQ(5, NumberOfWeakCalls); | 342 CHECK_EQ(5, NumberOfWeakCalls); |
344 | 343 |
345 // And now make children weak again and collect them. | 344 // And now make children weak again and collect them. |
346 GlobalHandles::MakeWeak(g1c1.location(), | 345 GlobalHandles::MakeWeak( |
347 reinterpret_cast<void*>(&g1c1_and_id), | 346 g1c1.location(), reinterpret_cast<void*>(&g1c1_and_id), |
348 &WeakPointerCallback); | 347 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
349 GlobalHandles::MakeWeak(g2c1.location(), | 348 GlobalHandles::MakeWeak( |
350 reinterpret_cast<void*>(&g2c1_and_id), | 349 g2c1.location(), reinterpret_cast<void*>(&g2c1_and_id), |
351 &WeakPointerCallback); | 350 &WeakPointerCallback, v8::WeakCallbackType::kParameter); |
352 | 351 |
353 heap->CollectGarbage(OLD_SPACE); | 352 heap->CollectGarbage(OLD_SPACE); |
354 CHECK_EQ(7, NumberOfWeakCalls); | 353 CHECK_EQ(7, NumberOfWeakCalls); |
355 } | 354 } |
356 | 355 |
357 | 356 |
358 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 357 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
359 public: | 358 public: |
360 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 359 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
361 | 360 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 487 |
489 | 488 |
490 TEST(RegressJoinThreadsOnIsolateDeinit) { | 489 TEST(RegressJoinThreadsOnIsolateDeinit) { |
491 intptr_t size_limit = ShortLivingIsolate() * 2; | 490 intptr_t size_limit = ShortLivingIsolate() * 2; |
492 for (int i = 0; i < 10; i++) { | 491 for (int i = 0; i < 10; i++) { |
493 CHECK_GT(size_limit, ShortLivingIsolate()); | 492 CHECK_GT(size_limit, ShortLivingIsolate()); |
494 } | 493 } |
495 } | 494 } |
496 | 495 |
497 #endif // __linux__ and !USE_SIMULATOR | 496 #endif // __linux__ and !USE_SIMULATOR |
OLD | NEW |