| 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 17 matching lines...) Expand all Loading... |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #ifdef __linux__ | 30 #ifdef __linux__ |
| 31 #include <sys/types.h> | 31 #include <sys/types.h> |
| 32 #include <sys/stat.h> | 32 #include <sys/stat.h> |
| 33 #include <fcntl.h> | 33 #include <fcntl.h> |
| 34 #include <unistd.h> | 34 #include <unistd.h> |
| 35 #include <errno.h> | 35 #include <errno.h> |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #include <utility> |
| 38 | 39 |
| 39 #include "v8.h" | 40 #include "v8.h" |
| 40 | 41 |
| 41 #include "global-handles.h" | 42 #include "global-handles.h" |
| 42 #include "snapshot.h" | 43 #include "snapshot.h" |
| 43 #include "cctest.h" | 44 #include "cctest.h" |
| 44 | 45 |
| 45 using namespace v8::internal; | 46 using namespace v8::internal; |
| 46 | 47 |
| 47 | 48 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // To give an additional chance to fail, try to force compaction which | 239 // To give an additional chance to fail, try to force compaction which |
| 239 // should be impossible right now. | 240 // should be impossible right now. |
| 240 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); | 241 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); |
| 241 // And now map pointers should be encodable again. | 242 // And now map pointers should be encodable again. |
| 242 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); | 243 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); |
| 243 } | 244 } |
| 244 #endif | 245 #endif |
| 245 | 246 |
| 246 | 247 |
| 247 static int NumberOfWeakCalls = 0; | 248 static int NumberOfWeakCalls = 0; |
| 248 static void WeakPointerCallback(v8::Isolate* isolate, | 249 static void WeakPointerCallback( |
| 249 v8::Persistent<v8::Value>* handle, | 250 const v8::WeakCallbackData<v8::Value, void>& data) { |
| 250 void* id) { | 251 std::pair<v8::Persistent<v8::Value>*, int>* p = |
| 251 ASSERT(id == reinterpret_cast<void*>(1234)); | 252 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( |
| 253 data.GetParameter()); |
| 254 ASSERT_EQ(1234, p->second); |
| 252 NumberOfWeakCalls++; | 255 NumberOfWeakCalls++; |
| 253 handle->Reset(); | 256 p->first->Reset(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 | 259 |
| 257 TEST(ObjectGroups) { | 260 TEST(ObjectGroups) { |
| 258 FLAG_incremental_marking = false; | 261 FLAG_incremental_marking = false; |
| 259 CcTest::InitializeVM(); | 262 CcTest::InitializeVM(); |
| 260 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); | 263 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
| 261 Heap* heap = CcTest::heap(); | 264 Heap* heap = CcTest::heap(); |
| 262 NumberOfWeakCalls = 0; | 265 NumberOfWeakCalls = 0; |
| 263 v8::HandleScope handle_scope(CcTest::isolate()); | 266 v8::HandleScope handle_scope(CcTest::isolate()); |
| 264 | 267 |
| 265 Handle<Object> g1s1 = | 268 Handle<Object> g1s1 = |
| 266 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 269 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 267 Handle<Object> g1s2 = | 270 Handle<Object> g1s2 = |
| 268 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 271 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 269 Handle<Object> g1c1 = | 272 Handle<Object> g1c1 = |
| 270 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 273 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 271 global_handles->MakeWeak(g1s1.location(), | 274 std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234); |
| 272 reinterpret_cast<void*>(1234), | 275 GlobalHandles::MakeWeak(g1s1.location(), |
| 273 &WeakPointerCallback); | 276 reinterpret_cast<void*>(&g1s1_and_id), |
| 274 global_handles->MakeWeak(g1s2.location(), | 277 &WeakPointerCallback); |
| 275 reinterpret_cast<void*>(1234), | 278 std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234); |
| 276 &WeakPointerCallback); | 279 GlobalHandles::MakeWeak(g1s2.location(), |
| 277 global_handles->MakeWeak(g1c1.location(), | 280 reinterpret_cast<void*>(&g1s2_and_id), |
| 278 reinterpret_cast<void*>(1234), | 281 &WeakPointerCallback); |
| 279 &WeakPointerCallback); | 282 std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234); |
| 283 GlobalHandles::MakeWeak(g1c1.location(), |
| 284 reinterpret_cast<void*>(&g1c1_and_id), |
| 285 &WeakPointerCallback); |
| 280 | 286 |
| 281 Handle<Object> g2s1 = | 287 Handle<Object> g2s1 = |
| 282 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 288 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 283 Handle<Object> g2s2 = | 289 Handle<Object> g2s2 = |
| 284 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 290 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 285 Handle<Object> g2c1 = | 291 Handle<Object> g2c1 = |
| 286 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); | 292 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 287 global_handles->MakeWeak(g2s1.location(), | 293 std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234); |
| 288 reinterpret_cast<void*>(1234), | 294 GlobalHandles::MakeWeak(g2s1.location(), |
| 289 &WeakPointerCallback); | 295 reinterpret_cast<void*>(&g2s1_and_id), |
| 290 global_handles->MakeWeak(g2s2.location(), | 296 &WeakPointerCallback); |
| 291 reinterpret_cast<void*>(1234), | 297 std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234); |
| 292 &WeakPointerCallback); | 298 GlobalHandles::MakeWeak(g2s2.location(), |
| 293 global_handles->MakeWeak(g2c1.location(), | 299 reinterpret_cast<void*>(&g2s2_and_id), |
| 294 reinterpret_cast<void*>(1234), | 300 &WeakPointerCallback); |
| 295 &WeakPointerCallback); | 301 std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234); |
| 302 GlobalHandles::MakeWeak(g2c1.location(), |
| 303 reinterpret_cast<void*>(&g2c1_and_id), |
| 304 &WeakPointerCallback); |
| 296 | 305 |
| 297 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | 306 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
| 298 | 307 |
| 299 // Connect group 1 and 2, make a cycle. | 308 // Connect group 1 and 2, make a cycle. |
| 300 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 309 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 301 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 310 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 302 | 311 |
| 303 { | 312 { |
| 304 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 313 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 305 Object** g1_children[] = { g1c1.location() }; | 314 Object** g1_children[] = { g1c1.location() }; |
| 306 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 315 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 307 Object** g2_children[] = { g2c1.location() }; | 316 Object** g2_children[] = { g2c1.location() }; |
| 308 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 317 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 309 global_handles->AddImplicitReferences( | 318 global_handles->AddImplicitReferences( |
| 310 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 319 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 311 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 320 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 312 global_handles->AddImplicitReferences( | 321 global_handles->AddImplicitReferences( |
| 313 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 322 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
| 314 } | 323 } |
| 315 // Do a full GC | 324 // Do a full GC |
| 316 heap->CollectGarbage(OLD_POINTER_SPACE); | 325 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 317 | 326 |
| 318 // All object should be alive. | 327 // All object should be alive. |
| 319 CHECK_EQ(0, NumberOfWeakCalls); | 328 CHECK_EQ(0, NumberOfWeakCalls); |
| 320 | 329 |
| 321 // Weaken the root. | 330 // Weaken the root. |
| 322 global_handles->MakeWeak(root.location(), | 331 std::pair<Handle<Object>*, int> root_and_id(&root, 1234); |
| 323 reinterpret_cast<void*>(1234), | 332 GlobalHandles::MakeWeak(root.location(), |
| 324 &WeakPointerCallback); | 333 reinterpret_cast<void*>(&root_and_id), |
| 334 &WeakPointerCallback); |
| 325 // But make children strong roots---all the objects (except for children) | 335 // But make children strong roots---all the objects (except for children) |
| 326 // should be collectable now. | 336 // should be collectable now. |
| 327 global_handles->ClearWeakness(g1c1.location()); | 337 global_handles->ClearWeakness(g1c1.location()); |
| 328 global_handles->ClearWeakness(g2c1.location()); | 338 global_handles->ClearWeakness(g2c1.location()); |
| 329 | 339 |
| 330 // Groups are deleted, rebuild groups. | 340 // Groups are deleted, rebuild groups. |
| 331 { | 341 { |
| 332 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 342 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 333 Object** g1_children[] = { g1c1.location() }; | 343 Object** g1_children[] = { g1c1.location() }; |
| 334 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 344 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 335 Object** g2_children[] = { g2c1.location() }; | 345 Object** g2_children[] = { g2c1.location() }; |
| 336 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 346 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 337 global_handles->AddImplicitReferences( | 347 global_handles->AddImplicitReferences( |
| 338 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 348 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 339 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 349 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 340 global_handles->AddImplicitReferences( | 350 global_handles->AddImplicitReferences( |
| 341 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 351 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
| 342 } | 352 } |
| 343 | 353 |
| 344 heap->CollectGarbage(OLD_POINTER_SPACE); | 354 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 345 | 355 |
| 346 // All objects should be gone. 5 global handles in total. | 356 // All objects should be gone. 5 global handles in total. |
| 347 CHECK_EQ(5, NumberOfWeakCalls); | 357 CHECK_EQ(5, NumberOfWeakCalls); |
| 348 | 358 |
| 349 // And now make children weak again and collect them. | 359 // And now make children weak again and collect them. |
| 350 global_handles->MakeWeak(g1c1.location(), | 360 GlobalHandles::MakeWeak(g1c1.location(), |
| 351 reinterpret_cast<void*>(1234), | 361 reinterpret_cast<void*>(&g1c1_and_id), |
| 352 &WeakPointerCallback); | 362 &WeakPointerCallback); |
| 353 global_handles->MakeWeak(g2c1.location(), | 363 GlobalHandles::MakeWeak(g2c1.location(), |
| 354 reinterpret_cast<void*>(1234), | 364 reinterpret_cast<void*>(&g2c1_and_id), |
| 355 &WeakPointerCallback); | 365 &WeakPointerCallback); |
| 356 | 366 |
| 357 heap->CollectGarbage(OLD_POINTER_SPACE); | 367 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 358 CHECK_EQ(7, NumberOfWeakCalls); | 368 CHECK_EQ(7, NumberOfWeakCalls); |
| 359 } | 369 } |
| 360 | 370 |
| 361 | 371 |
| 362 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 372 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| 363 public: | 373 public: |
| 364 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 374 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
| 365 | 375 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 535 |
| 526 | 536 |
| 527 TEST(RegressJoinThreadsOnIsolateDeinit) { | 537 TEST(RegressJoinThreadsOnIsolateDeinit) { |
| 528 intptr_t size_limit = ShortLivingIsolate() * 2; | 538 intptr_t size_limit = ShortLivingIsolate() * 2; |
| 529 for (int i = 0; i < 10; i++) { | 539 for (int i = 0; i < 10; i++) { |
| 530 CHECK_GT(size_limit, ShortLivingIsolate()); | 540 CHECK_GT(size_limit, ShortLivingIsolate()); |
| 531 } | 541 } |
| 532 } | 542 } |
| 533 | 543 |
| 534 #endif // __linux__ and !USE_SIMULATOR | 544 #endif // __linux__ and !USE_SIMULATOR |
| OLD | NEW |