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 | #pragma once |
27 | |
28 | #include "SamplingCounter.h" |
29 | #include <wtf/Assertions.h> |
30 | |
31 | namespace JSC { |
32 | |
33 | // This allows the JIT to distinguish between uses of the barrier for different |
34 | // kinds of writes. This is used by the JIT for profiling, and may be appropriate |
35 | // for allowing the GC implementation to specialize the JIT's write barrier code |
36 | // for different kinds of target objects. |
37 | enum WriteBarrierUseKind { |
38 | // This allows specialization for access to the property storage (either |
39 | // array element or property), but not for any other kind of property |
40 | // accesses (such as writes that are a consequence of setter execution). |
41 | WriteBarrierForPropertyAccess, |
42 | |
43 | // This allows specialization for variable accesses (such as global or |
44 | // scoped variables). |
45 | WriteBarrierForVariableAccess, |
46 | |
47 | // This captures all other forms of write barriers. It should always be |
48 | // correct to use a generic access write barrier, even when storing to |
49 | // properties. Hence, if optimization is not necessary, it is preferable |
50 | // to just use a generic access. |
51 | WriteBarrierForGenericAccess |
52 | }; |
53 | |
54 | class WriteBarrierCounters { |
55 | private: |
56 | WriteBarrierCounters() { } |
57 | |
58 | public: |
59 | #if ENABLE(WRITE_BARRIER_PROFILING) |
60 | static GlobalSamplingCounter usesWithBarrierFromCpp; |
61 | static GlobalSamplingCounter usesWithoutBarrierFromCpp; |
62 | static GlobalSamplingCounter usesWithBarrierFromJit; |
63 | static GlobalSamplingCounter usesForPropertiesFromJit; |
64 | static GlobalSamplingCounter usesForVariablesFromJit; |
65 | static GlobalSamplingCounter usesWithoutBarrierFromJit; |
66 | |
67 | static void initialize(); |
68 | |
69 | static GlobalSamplingCounter& jitCounterFor(WriteBarrierUseKind useKind) |
70 | { |
71 | switch (useKind) { |
72 | case WriteBarrierForPropertyAccess: |
73 | return usesForPropertiesFromJit; |
74 | case WriteBarrierForVariableAccess: |
75 | return usesForVariablesFromJit; |
76 | default: |
77 | ASSERT(useKind == WriteBarrierForGenericAccess); |
78 | return usesWithBarrierFromJit; |
79 | } |
80 | } |
81 | #else |
82 | // These are necessary to work around not having conditional exports. |
83 | JS_EXPORT_PRIVATE static char usesWithBarrierFromCpp; |
84 | JS_EXPORT_PRIVATE static char usesWithoutBarrierFromCpp; |
85 | #endif // ENABLE(WRITE_BARRIER_PROFILING) |
86 | |
87 | static void countWriteBarrier() |
88 | { |
89 | #if ENABLE(WRITE_BARRIER_PROFILING) |
90 | WriteBarrierCounters::usesWithBarrierFromCpp.count(); |
91 | #endif |
92 | } |
93 | }; |
94 | |
95 | } // namespace JSC |
96 | |