Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 // From here on ignore all conservatively discovered | 289 // From here on ignore all conservatively discovered |
| 290 // pointers into the heap owned by this thread. | 290 // pointers into the heap owned by this thread. |
| 291 m_isCleaningUp = true; | 291 m_isCleaningUp = true; |
| 292 | 292 |
| 293 for (size_t i = 0; i < m_cleanupTasks.size(); i++) | 293 for (size_t i = 0; i < m_cleanupTasks.size(); i++) |
| 294 m_cleanupTasks[i]->preCleanup(); | 294 m_cleanupTasks[i]->preCleanup(); |
| 295 | 295 |
| 296 // After this GC we expect heap to be empty because | 296 // After this GC we expect heap to be empty because |
| 297 // preCleanup tasks should have cleared all persistent | 297 // preCleanup tasks should have cleared all persistent |
| 298 // handles that were externally owned. | 298 // handles that were externally owned. |
| 299 // FIXME: oilpan: we should perform a single GC and everything | 299 Heap::collectAllGarbage(ThreadState::NoHeapPointersOnStack); |
| 300 // should die. Unfortunately it is not the case for all objects | |
| 301 // because the hierarchy was not completely moved to the heap and | |
| 302 // some heap allocated objects own objects that contain persistents | |
| 303 // pointing to other heap allocated objects. | |
| 304 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
| 305 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
| 306 | 300 |
| 307 // Verify that all heaps are empty now. | 301 // Verify that all heaps are empty now. |
| 308 for (int i = 0; i < NumberOfHeaps; i++) | 302 for (int i = 0; i < NumberOfHeaps; i++) |
| 309 m_heaps[i]->assertEmpty(); | 303 m_heaps[i]->assertEmpty(); |
| 310 | 304 |
| 311 for (size_t i = 0; i < m_cleanupTasks.size(); i++) | 305 for (size_t i = 0; i < m_cleanupTasks.size(); i++) |
| 312 m_cleanupTasks[i]->postCleanup(); | 306 m_cleanupTasks[i]->postCleanup(); |
| 313 | 307 |
| 314 m_cleanupTasks.clear(); | 308 m_cleanupTasks.clear(); |
| 315 } | 309 } |
| 316 | 310 |
| 317 void ThreadState::detach() | 311 void ThreadState::detach() |
| 318 { | 312 { |
| 319 ThreadState* state = current(); | 313 ThreadState* state = current(); |
| 314 | |
| 315 // When ThreadState is detaching from non-main thread its | |
|
Mads Ager (chromium)
2014/03/05 07:40:34
Ah, you moved it here. Have the comment on what cl
haraken
2014/03/05 08:50:26
Done.
| |
| 316 // heap is expected to be empty (because it is going away). | |
| 317 // Perform registered cleanup tasks and garbage collection | |
| 318 // to sweep away any objects that are left on this heap. | |
| 319 // We assert that nothing must remain after this cleanup. | |
| 320 // If assertion does not hold we crash as we are potentially | |
| 321 // in the dangling pointer situation. | |
| 322 state->cleanup(); | |
| 323 | |
| 320 // Enter safe point before trying to acquire threadAttachMutex | 324 // Enter safe point before trying to acquire threadAttachMutex |
| 321 // to avoid dead lock if another thread is preparing for GC, has acquired | 325 // to avoid dead lock if another thread is preparing for GC, has acquired |
| 322 // threadAttachMutex and waiting for other threads to pause or reach a | 326 // threadAttachMutex and waiting for other threads to pause or reach a |
| 323 // safepoint. | 327 // safepoint. |
| 324 if (!state->isAtSafePoint()) | 328 if (!state->isAtSafePoint()) |
| 325 state->enterSafePointWithoutPointers(); | 329 state->enterSafePointWithoutPointers(); |
| 326 MutexLocker locker(threadAttachMutex()); | 330 MutexLocker locker(threadAttachMutex()); |
| 327 state->leaveSafePoint(); | 331 state->leaveSafePoint(); |
| 328 attachedThreads().remove(state); | 332 attachedThreads().remove(state); |
| 329 delete state; | 333 delete state; |
|
kouhei (in TOK)
2014/03/05 05:58:15
Doesn't this mean we fail if we couldn't collect a
haraken
2014/03/05 06:00:57
Yes, it means. However, there is no way to know th
| |
| 330 } | 334 } |
| 331 | 335 |
| 332 void ThreadState::visitRoots(Visitor* visitor) | 336 void ThreadState::visitRoots(Visitor* visitor) |
| 333 { | 337 { |
| 334 { | 338 { |
| 335 // All threads are at safepoints so this is not strictly necessary. | 339 // All threads are at safepoints so this is not strictly necessary. |
| 336 // However we acquire the mutex to make mutation and traversal of this | 340 // However we acquire the mutex to make mutation and traversal of this |
| 337 // list symmetrical. | 341 // list symmetrical. |
| 338 MutexLocker locker(globalRootsMutex()); | 342 MutexLocker locker(globalRootsMutex()); |
| 339 globalRoots()->trace(visitor); | 343 globalRoots()->trace(visitor); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 state->safePoint(HeapPointersOnStack); | 704 state->safePoint(HeapPointersOnStack); |
| 701 } | 705 } |
| 702 | 706 |
| 703 ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads() | 707 ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads() |
| 704 { | 708 { |
| 705 DEFINE_STATIC_LOCAL(AttachedThreadStateSet, threads, ()); | 709 DEFINE_STATIC_LOCAL(AttachedThreadStateSet, threads, ()); |
| 706 return threads; | 710 return threads; |
| 707 } | 711 } |
| 708 | 712 |
| 709 } | 713 } |
| OLD | NEW |