| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 void ThreadHeap::attach(ThreadState* thread) | 255 void ThreadHeap::attach(ThreadState* thread) |
| 256 { | 256 { |
| 257 MutexLocker locker(m_threadAttachMutex); | 257 MutexLocker locker(m_threadAttachMutex); |
| 258 m_threads.add(thread); | 258 m_threads.add(thread); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void ThreadHeap::detach(ThreadState* thread) | 261 void ThreadHeap::detach(ThreadState* thread) |
| 262 { | 262 { |
| 263 ASSERT(ThreadState::current() == thread); | 263 ASSERT(ThreadState::current() == thread); |
| 264 bool isLastThread = false; |
| 264 { | 265 { |
| 265 // Grab the threadAttachMutex to ensure only one thread can shutdown at | 266 // Grab the threadAttachMutex to ensure only one thread can shutdown at |
| 266 // a time and that no other thread can do a global GC. It also allows | 267 // a time and that no other thread can do a global GC. It also allows |
| 267 // safe iteration of the m_threads set which happens as part of | 268 // safe iteration of the m_threads set which happens as part of |
| 268 // thread local GC asserts. We enter a safepoint while waiting for the | 269 // thread local GC asserts. We enter a safepoint while waiting for the |
| 269 // lock to avoid a dead-lock where another thread has already requested | 270 // lock to avoid a dead-lock where another thread has already requested |
| 270 // GC. | 271 // GC. |
| 271 SafePointAwareMutexLocker locker(m_threadAttachMutex, BlinkGC::NoHeapPoi
ntersOnStack); | 272 SafePointAwareMutexLocker locker(m_threadAttachMutex, BlinkGC::NoHeapPoi
ntersOnStack); |
| 272 thread->runTerminationGC(); | 273 thread->runTerminationGC(); |
| 273 ASSERT(m_threads.contains(thread)); | 274 ASSERT(m_threads.contains(thread)); |
| 274 m_threads.remove(thread); | 275 m_threads.remove(thread); |
| 276 isLastThread = m_threads.isEmpty(); |
| 275 } | 277 } |
| 276 // The main thread must be the last thread that gets detached. | 278 // The last thread begin detached should be the owning thread, which would |
| 277 ASSERT(!thread->isMainThread() || m_threads.isEmpty()); | 279 // be the main thread for the mainThreadHeap and a per thread heap enabled |
| 280 // thread otherwise. |
| 281 if (isLastThread) |
| 282 DCHECK(thread->perThreadHeapEnabled() || thread->isMainThread()); |
| 278 if (thread->isMainThread()) | 283 if (thread->isMainThread()) |
| 279 DCHECK_EQ(heapStats().allocatedSpace(), 0u); | 284 DCHECK_EQ(heapStats().allocatedSpace(), 0u); |
| 280 if (m_threads.isEmpty()) | 285 if (isLastThread) |
| 281 delete this; | 286 delete this; |
| 282 } | 287 } |
| 283 | 288 |
| 284 bool ThreadHeap::park() | 289 bool ThreadHeap::park() |
| 285 { | 290 { |
| 286 return m_safePointBarrier->parkOthers(); | 291 return m_safePointBarrier->parkOthers(); |
| 287 } | 292 } |
| 288 | 293 |
| 289 void ThreadHeap::resume() | 294 void ThreadHeap::resume() |
| 290 { | 295 { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); | 794 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); |
| 790 | 795 |
| 791 m_stats.reset(); | 796 m_stats.reset(); |
| 792 for (ThreadState* state : m_threads) | 797 for (ThreadState* state : m_threads) |
| 793 state->resetHeapCounters(); | 798 state->resetHeapCounters(); |
| 794 } | 799 } |
| 795 | 800 |
| 796 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; | 801 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; |
| 797 | 802 |
| 798 } // namespace blink | 803 } // namespace blink |
| OLD | NEW |