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

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

Issue 834673008: Extend locking of GCInfo table to include slot allocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 25 matching lines...) Expand all
36 36
37 namespace blink { 37 namespace blink {
38 38
39 // GCInfo indices start from 1 for heap objects, with 0 being treated 39 // GCInfo indices start from 1 for heap objects, with 0 being treated
40 // specially as the index for freelist entries and large heap objects. 40 // specially as the index for freelist entries and large heap objects.
41 int GCInfoTable::s_gcInfoIndex = 0; 41 int GCInfoTable::s_gcInfoIndex = 0;
42 42
43 size_t GCInfoTable::s_gcInfoTableSize = 0; 43 size_t GCInfoTable::s_gcInfoTableSize = 0;
44 GCInfo const** s_gcInfoTable = nullptr; 44 GCInfo const** s_gcInfoTable = nullptr;
45 45
46 size_t GCInfoTable::allocateGCInfoSlot() 46 bool GCInfoTable::allocateGCInfoSlot(size_t& gcInfoIndexSlot)
haraken 2015/01/10 08:37:24 Nit: I'd slightly prefer a raw pointer for an outp
sof 2015/01/10 08:54:23 Done.
47 { 47 {
48 // FIXME: if multiple threads attempt to allocate the initial object 48 // Keep a global GCInfoTable lock while allocating a new slot.
49 // for a given type, there'll be a write race on updating the 'static' 49 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
50 // holding its index. Duplicate GCInfo slots might be written for the 50 MutexLocker locker(mutex);
51 // object, which is benign, but verify that the index update race is 51
52 // acceptable. 52 // If more than one thread ends up allocating a slot for
53 int index = atomicIncrement(&s_gcInfoIndex); 53 // the same GCInfo, have later threads reuse the slot
54 // allocated by the first.
55 if (gcInfoIndexSlot)
56 return false;
57
58 int index = ++s_gcInfoIndex;
54 size_t gcInfoIndex = static_cast<size_t>(index); 59 size_t gcInfoIndex = static_cast<size_t>(index);
55 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); 60 ASSERT(gcInfoIndex < GCInfoTable::maxIndex);
56 if (gcInfoIndex >= s_gcInfoTableSize) 61 if (gcInfoIndex >= s_gcInfoTableSize)
57 resize(gcInfoIndex); 62 resize();
58 63
59 return gcInfoIndex; 64 gcInfoIndexSlot = gcInfoIndex;
65 return true;
60 } 66 }
61 67
62 void GCInfoTable::resize(size_t index) 68 void GCInfoTable::resize()
63 { 69 {
64 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
65 MutexLocker locker(mutex);
66
67 // Keep a lock while expanding the shared table; check
68 // if another thread have already resized.
69 if (index < s_gcInfoTableSize)
70 return;
71
72 // (Light) experimentation suggests that Blink doesn't need 70 // (Light) experimentation suggests that Blink doesn't need
73 // more than this while handling content on popular web properties. 71 // more than this while handling content on popular web properties.
74 const size_t initialSize = 512; 72 const size_t initialSize = 512;
75 73
76 size_t newSize = s_gcInfoTableSize ? 2 * s_gcInfoTableSize : initialSize; 74 size_t newSize = s_gcInfoTableSize ? 2 * s_gcInfoTableSize : initialSize;
77 ASSERT(newSize < GCInfoTable::maxIndex); 75 ASSERT(newSize < GCInfoTable::maxIndex);
78 s_gcInfoTable = reinterpret_cast<GCInfo const**>(realloc(s_gcInfoTable, newS ize * sizeof(GCInfo))); 76 s_gcInfoTable = reinterpret_cast<GCInfo const**>(realloc(s_gcInfoTable, newS ize * sizeof(GCInfo)));
79 ASSERT(s_gcInfoTable); 77 ASSERT(s_gcInfoTable);
80 memset(reinterpret_cast<uint8_t*>(s_gcInfoTable) + s_gcInfoTableSize * sizeo f(GCInfo), 0, (newSize - s_gcInfoTableSize) * sizeof(GCInfo)); 78 memset(reinterpret_cast<uint8_t*>(s_gcInfoTable) + s_gcInfoTableSize * sizeo f(GCInfo), 0, (newSize - s_gcInfoTableSize) * sizeof(GCInfo));
81 s_gcInfoTableSize = newSize; 79 s_gcInfoTableSize = newSize;
82 } 80 }
83 81
84 void GCInfoTable::init() 82 void GCInfoTable::init()
85 { 83 {
86 RELEASE_ASSERT(!s_gcInfoTable); 84 RELEASE_ASSERT(!s_gcInfoTable);
87 resize(0); 85 resize();
88 } 86 }
89 87
90 void GCInfoTable::shutdown() 88 void GCInfoTable::shutdown()
91 { 89 {
92 free(s_gcInfoTable); 90 free(s_gcInfoTable);
93 s_gcInfoTable = nullptr; 91 s_gcInfoTable = nullptr;
94 } 92 }
95 93
96 StackFrameDepth* Visitor::m_stackFrameDepth = nullptr; 94 StackFrameDepth* Visitor::m_stackFrameDepth = nullptr;
97 95
98 #if ENABLE(ASSERT) 96 #if ENABLE(ASSERT)
99 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex) 97 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex)
100 { 98 {
101 HeapObjectHeader::fromPayload(payload)->checkHeader(); 99 HeapObjectHeader::fromPayload(payload)->checkHeader();
102 #if !defined(COMPONENT_BUILD) 100 #if !defined(COMPONENT_BUILD)
103 // On component builds we cannot compare the gcInfos as they are statically 101 // On component builds we cannot compare the gcInfos as they are statically
104 // defined in each of the components and hence will not match. 102 // defined in each of the components and hence will not match.
105 BaseHeapPage* page = pageFromObject(payload); 103 BaseHeapPage* page = pageFromObject(payload);
106 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex); 104 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex);
107 #endif 105 #endif
108 } 106 }
109 #endif 107 #endif
110 108
111 } 109 }
OLDNEW
« Source/platform/heap/Visitor.h ('K') | « Source/platform/heap/Visitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698