]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 A |
1 | /* |
2 | * Copyright (C) 2011 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
23 | * THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #ifndef WriteBarrierSupport_h | |
27 | #define WriteBarrierSupport_h | |
28 | ||
29 | #include "SamplingCounter.h" | |
30 | #include <wtf/Assertions.h> | |
31 | ||
32 | namespace JSC { | |
33 | ||
34 | // This allows the JIT to distinguish between uses of the barrier for different | |
35 | // kinds of writes. This is used by the JIT for profiling, and may be appropriate | |
36 | // for allowing the GC implementation to specialize the JIT's write barrier code | |
37 | // for different kinds of target objects. | |
38 | enum WriteBarrierUseKind { | |
39 | // This allows specialization for access to the property storage (either | |
40 | // array element or property), but not for any other kind of property | |
41 | // accesses (such as writes that are a consequence of setter execution). | |
42 | WriteBarrierForPropertyAccess, | |
43 | ||
44 | // This allows specialization for variable accesses (such as global or | |
45 | // scoped variables). | |
46 | WriteBarrierForVariableAccess, | |
47 | ||
48 | // This captures all other forms of write barriers. It should always be | |
49 | // correct to use a generic access write barrier, even when storing to | |
50 | // properties. Hence, if optimization is not necessary, it is preferable | |
51 | // to just use a generic access. | |
52 | WriteBarrierForGenericAccess | |
53 | }; | |
54 | ||
55 | class WriteBarrierCounters { | |
56 | private: | |
57 | WriteBarrierCounters() { } | |
58 | ||
59 | public: | |
60 | #if ENABLE(WRITE_BARRIER_PROFILING) | |
61 | static GlobalSamplingCounter usesWithBarrierFromCpp; | |
62 | static GlobalSamplingCounter usesWithoutBarrierFromCpp; | |
63 | static GlobalSamplingCounter usesWithBarrierFromJit; | |
64 | static GlobalSamplingCounter usesForPropertiesFromJit; | |
65 | static GlobalSamplingCounter usesForVariablesFromJit; | |
66 | static GlobalSamplingCounter usesWithoutBarrierFromJit; | |
67 | ||
68 | static void initialize(); | |
69 | ||
70 | static GlobalSamplingCounter& jitCounterFor(WriteBarrierUseKind useKind) | |
71 | { | |
72 | switch (useKind) { | |
73 | case WriteBarrierForPropertyAccess: | |
74 | return usesForPropertiesFromJit; | |
75 | case WriteBarrierForVariableAccess: | |
76 | return usesForVariablesFromJit; | |
77 | default: | |
78 | ASSERT(useKind == WriteBarrierForGenericAccess); | |
79 | return usesWithBarrierFromJit; | |
80 | } | |
81 | } | |
82 | #else | |
83 | // These are necessary to work around not having conditional exports. | |
84 | JS_EXPORTDATA static char usesWithBarrierFromCpp; | |
85 | JS_EXPORTDATA static char usesWithoutBarrierFromCpp; | |
86 | #endif // ENABLE(WRITE_BARRIER_PROFILING) | |
87 | ||
88 | static void countWriteBarrier() | |
89 | { | |
90 | #if ENABLE(WRITE_BARRIER_PROFILING) | |
91 | WriteBarrierCounters::usesWithBarrierFromCpp.count(); | |
92 | #endif | |
93 | } | |
94 | }; | |
95 | ||
96 | } // namespace JSC | |
97 | ||
98 | #endif // WriteBarrierSupport_h | |
99 |