1 | /* |
2 | * Copyright (C) 2016 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 | #if ENABLE(B3_JIT) |
29 | |
30 | #include "B3HeapRange.h" |
31 | #include "B3Value.h" |
32 | |
33 | namespace JSC { namespace B3 { |
34 | |
35 | class JS_EXPORT_PRIVATE FenceValue : public Value { |
36 | public: |
37 | static bool accepts(Kind kind) { return kind == Fence; } |
38 | |
39 | ~FenceValue(); |
40 | |
41 | // The read/write heaps are reflected in the effects() of this value. The compiler may change |
42 | // the lowering of a Fence based on the heaps. For example, if a fence does not write anything |
43 | // then it is understood to be a store-store fence. On x86, this may lead us to not emit any |
44 | // code, while on ARM we may emit a cheaper fence (dmb ishst instead of dmb ish). We will do |
45 | // the same optimization for load-load fences, which are expressed as a Fence that writes but |
46 | // does not read. |
47 | // |
48 | // This abstraction allows us to cover all of the fences on x86 and all of the standalone fences |
49 | // on ARM. X86 really just has one fence: mfence. This fence should be used to protect stores |
50 | // from being sunk below loads. WTF calls it the storeLoadFence. A classic example is the Steele |
51 | // barrier: |
52 | // |
53 | // o.f = v => o.f = v |
54 | // if (color(o) == black) |
55 | // log(o) |
56 | // |
57 | // We are trying to ensure that if the store to o.f occurs after the collector has started |
58 | // visiting o, then we will log o. Under sequential consistency, this would work. The collector |
59 | // would set color(o) to black just before it started visiting. But x86's illusion of sequential |
60 | // consistency is broken in exactly just this store->load ordering case. The store to o.f may |
61 | // get buffered, and it may occur some time after we have loaded and checked color(o). As well, |
62 | // the collector's store to set color(o) to black may get buffered and it may occur some time |
63 | // after the collector has finished visiting o. Therefore, we need mfences. In B3 we model this |
64 | // as a Fence that reads and writes some heaps. Setting writes to the empty set will cause B3 to |
65 | // not emit any barrier on x86. |
66 | // |
67 | // On ARM there are many more fences. The Fence instruction is meant to model just two of them: |
68 | // dmb ish and dmb ishst. You can emit a dmb ishst by using a Fence with an empty write heap. |
69 | // Otherwise, you will get a dmb ish. |
70 | // FIXME: Add fenced memory accesses. https://bugs.webkit.org/show_bug.cgi?id=162349 |
71 | // FIXME: Add a Depend operation. https://bugs.webkit.org/show_bug.cgi?id=162350 |
72 | HeapRange read { HeapRange::top() }; |
73 | HeapRange write { HeapRange::top() }; |
74 | |
75 | B3_SPECIALIZE_VALUE_FOR_NO_CHILDREN |
76 | |
77 | private: |
78 | friend class Procedure; |
79 | friend class Value; |
80 | |
81 | static Opcode opcodeFromConstructor(Origin, HeapRange = HeapRange(), HeapRange = HeapRange()) { return Fence; } |
82 | FenceValue(Origin origin, HeapRange read, HeapRange write); |
83 | FenceValue(Origin origin); |
84 | }; |
85 | |
86 | } } // namespace JSC::B3 |
87 | |
88 | #endif // ENABLE(B3_JIT) |
89 | |
90 | |