Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: Source/platform/heap/Heap.cpp

Issue 794223003: Cheaper thread-safe atomic initialization of static references. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add type check for initial value Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 fprintf(stderr, "\n"); 1984 fprintf(stderr, "\n");
1985 } 1985 }
1986 1986
1987 static void dumpPathToObjectOnNextGC(void* p) 1987 static void dumpPathToObjectOnNextGC(void* p)
1988 { 1988 {
1989 objectsToFindPath().add(reinterpret_cast<uintptr_t>(p)); 1989 objectsToFindPath().add(reinterpret_cast<uintptr_t>(p));
1990 } 1990 }
1991 1991
1992 static Mutex& objectGraphMutex() 1992 static Mutex& objectGraphMutex()
1993 { 1993 {
1994 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 1994 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex);
1995 return mutex; 1995 return mutex;
1996 } 1996 }
1997 1997
1998 static LiveObjectMap& previouslyLive() 1998 static LiveObjectMap& previouslyLive()
1999 { 1999 {
2000 DEFINE_STATIC_LOCAL(LiveObjectMap, map, ()); 2000 DEFINE_STATIC_LOCAL(LiveObjectMap, map, ());
2001 return map; 2001 return map;
2002 } 2002 }
2003 2003
2004 static LiveObjectMap& currentlyLive() 2004 static LiveObjectMap& currentlyLive()
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 return nullptr; 2619 return nullptr;
2620 if (PageMemoryRegion* region = s_regionTree->lookup(address)) { 2620 if (PageMemoryRegion* region = s_regionTree->lookup(address)) {
2621 BaseHeapPage* page = region->pageFromAddress(address); 2621 BaseHeapPage* page = region->pageFromAddress(address);
2622 return page && !page->orphaned() ? page : nullptr; 2622 return page && !page->orphaned() ? page : nullptr;
2623 } 2623 }
2624 return nullptr; 2624 return nullptr;
2625 } 2625 }
2626 2626
2627 static Mutex& regionTreeMutex() 2627 static Mutex& regionTreeMutex()
2628 { 2628 {
2629 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 2629 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex);
2630 return mutex; 2630 return mutex;
2631 } 2631 }
2632 2632
2633 void Heap::removePageMemoryRegion(PageMemoryRegion* region) 2633 void Heap::removePageMemoryRegion(PageMemoryRegion* region)
2634 { 2634 {
2635 // Deletion of large objects (and thus their regions) can happen 2635 // Deletion of large objects (and thus their regions) can happen
2636 // concurrently on sweeper threads. Removal can also happen during thread 2636 // concurrently on sweeper threads. Removal can also happen during thread
2637 // shutdown, but that case is safe. Regardless, we make all removals 2637 // shutdown, but that case is safe. Regardless, we make all removals
2638 // mutually exclusive. 2638 // mutually exclusive.
2639 MutexLocker locker(regionTreeMutex()); 2639 MutexLocker locker(regionTreeMutex());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 bool Heap::s_shutdownCalled = false; 2712 bool Heap::s_shutdownCalled = false;
2713 bool Heap::s_lastGCWasConservative = false; 2713 bool Heap::s_lastGCWasConservative = false;
2714 FreePagePool* Heap::s_freePagePool; 2714 FreePagePool* Heap::s_freePagePool;
2715 OrphanedPagePool* Heap::s_orphanedPagePool; 2715 OrphanedPagePool* Heap::s_orphanedPagePool;
2716 Heap::RegionTree* Heap::s_regionTree = nullptr; 2716 Heap::RegionTree* Heap::s_regionTree = nullptr;
2717 size_t Heap::s_allocatedObjectSize = 0; 2717 size_t Heap::s_allocatedObjectSize = 0;
2718 size_t Heap::s_allocatedSpace = 0; 2718 size_t Heap::s_allocatedSpace = 0;
2719 size_t Heap::s_markedObjectSize = 0; 2719 size_t Heap::s_markedObjectSize = 0;
2720 2720
2721 } // namespace blink 2721 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698