OLD | NEW |
---|---|
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 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "platform/heap/Visitor.h" | 32 #include "platform/heap/Visitor.h" |
33 | 33 |
34 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
35 #include "platform/heap/Heap.h" | 35 #include "platform/heap/Heap.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 // gcInfoIndex should start from 1. | 39 // GCInfo indices start from 1 for heap objects, with 0 being treated |
40 // Since atomicIncrement(&s_gcInfoIndex) (which is defined in | 40 // specially as the index for freelist entries and large heap objects. |
41 // RETURN_GCINFO_INDEX) returns an incremented value of s_gcInfoIndex, | 41 int GCInfoTable::s_gcInfoIndex = 0; |
42 // the initial value of s_gcInfoIndex should be set to 0. | 42 |
43 int s_gcInfoIndex = 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() | |
47 { | |
48 // FIXME: if multiple threads attempt to allocate the initial object | |
49 // for a given type, there'll be a write race on updating the 'static' | |
50 // holding its index. Duplicate GCInfo slots might be written for the | |
haraken
2015/01/07 15:45:43
ah, this is a good point...
BTW, I begin to wonde
sof
2015/01/07 18:57:48
Yes, -fno-threadsafe-statics would be in effect th
| |
51 // object, which is benign, but verify that the index update race is | |
52 // acceptable. | |
53 int index = atomicIncrement(&s_gcInfoIndex); | |
54 size_t gcInfoIndex = static_cast<size_t>(index); | |
55 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); | |
56 if (gcInfoIndex >= s_gcInfoTableSize) | |
57 resize(gcInfoIndex); | |
58 | |
59 return gcInfoIndex; | |
60 } | |
61 | |
62 void GCInfoTable::resize(size_t index) | |
63 { | |
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 | |
73 // more than this while handling content on popular web properties. | |
74 const size_t initialSize = 512; | |
75 | |
76 size_t newSize = s_gcInfoTableSize ? 2 * s_gcInfoTableSize : initialSize; | |
77 ASSERT(newSize < GCInfoTable::maxIndex); | |
78 s_gcInfoTable = reinterpret_cast<GCInfo const**>(realloc(s_gcInfoTable, newS ize * sizeof(GCInfo))); | |
79 ASSERT(s_gcInfoTable); | |
80 memset(reinterpret_cast<uint8_t*>(s_gcInfoTable) + s_gcInfoTableSize * sizeo f(GCInfo), 0, (newSize - s_gcInfoTableSize) * sizeof(GCInfo)); | |
81 s_gcInfoTableSize = newSize; | |
82 } | |
83 | |
84 void GCInfoTable::init() | |
85 { | |
86 RELEASE_ASSERT(!s_gcInfoTable); | |
87 resize(0); | |
88 } | |
89 | |
90 void GCInfoTable::shutdown() | |
91 { | |
92 free(s_gcInfoTable); | |
93 s_gcInfoTable = nullptr; | |
94 } | |
95 | |
46 int Visitor::m_traceDepth = 0; | 96 int Visitor::m_traceDepth = 0; |
47 | 97 |
48 #if ENABLE(ASSERT) | 98 #if ENABLE(ASSERT) |
49 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex) | 99 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex) |
50 { | 100 { |
51 HeapObjectHeader::fromPayload(payload)->checkHeader(); | 101 HeapObjectHeader::fromPayload(payload)->checkHeader(); |
52 #if !defined(COMPONENT_BUILD) | 102 #if !defined(COMPONENT_BUILD) |
53 // On component builds we cannot compare the gcInfos as they are statically | 103 // On component builds we cannot compare the gcInfos as they are statically |
54 // defined in each of the components and hence will not match. | 104 // defined in each of the components and hence will not match. |
55 BaseHeapPage* page = pageFromObject(payload); | 105 BaseHeapPage* page = pageFromObject(payload); |
56 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex); | 106 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex); |
57 #endif | 107 #endif |
58 } | 108 } |
59 #endif | 109 #endif |
60 | 110 |
61 } | 111 } |
OLD | NEW |