1 /*
2 * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_C2_G1BARRIERSETC2_HPP
26 #define SHARE_GC_G1_C2_G1BARRIERSETC2_HPP
27
28 #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
29
30 class PhaseTransform;
31 class Type;
32 class TypeFunc;
33
34 const int G1C2BarrierPre = 1;
35 const int G1C2BarrierPost = 2;
36 const int G1C2BarrierPostNotNull = 4;
37
38 class G1BarrierStubC2 : public BarrierStubC2 {
39 public:
40 static bool needs_pre_barrier(const MachNode* node);
41 static bool needs_post_barrier(const MachNode* node);
42 static bool post_new_val_may_be_null(const MachNode* node);
43
44 G1BarrierStubC2(const MachNode* node);
45 virtual void emit_code(MacroAssembler& masm) = 0;
46 };
47
48 class G1PreBarrierStubC2 : public G1BarrierStubC2 {
49 private:
50 Register _obj;
51 Register _pre_val;
52 Register _thread;
53 Register _tmp1;
54 Register _tmp2;
55
56 protected:
57 G1PreBarrierStubC2(const MachNode* node);
58
59 public:
60 static bool needs_barrier(const MachNode* node);
61 static G1PreBarrierStubC2* create(const MachNode* node);
62 void initialize_registers(Register obj, Register pre_val, Register thread, Register tmp1 = noreg, Register tmp2 = noreg);
63 Register obj() const;
64 Register pre_val() const;
65 Register thread() const;
66 Register tmp1() const;
67 Register tmp2() const;
68 virtual void emit_code(MacroAssembler& masm);
69 };
70
71 class G1BarrierSetC2: public CardTableBarrierSetC2 {
72 private:
73 void analyze_dominating_barriers() const;
74
75 protected:
76 bool g1_can_remove_pre_barrier(GraphKit* kit,
77 PhaseValues* phase,
78 Node* adr,
79 BasicType bt,
80 uint adr_idx) const;
81
82 bool g1_can_remove_post_barrier(GraphKit* kit,
83 PhaseValues* phase, Node* store,
84 Node* adr) const;
85
86 int get_store_barrier(C2Access& access) const;
87
88 virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
89 virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
90 virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
91 Node* new_val, const Type* value_type) const;
92 virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
93 Node* new_val, const Type* value_type) const;
94 virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const;
95
96 public:
97 virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
98 virtual void eliminate_gc_barrier_data(Node* node) const;
99 virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
100 virtual uint estimated_barrier_size(const Node* node) const;
101 virtual bool can_initialize_object(const StoreNode* store) const;
102 virtual void clone_at_expansion(PhaseMacroExpand* phase,
103 ArrayCopyNode* ac) const;
104 virtual void* create_barrier_state(Arena* comp_arena) const;
105 virtual void emit_stubs(CodeBuffer& cb) const;
106 virtual void elide_dominated_barrier(MachNode* mach) const;
107 virtual void late_barrier_analysis() const;
108
109 #ifndef PRODUCT
110 virtual void dump_barrier_data(const MachNode* mach, outputStream* st) const;
111 #endif
112 };
113
114 #endif // SHARE_GC_G1_C2_G1BARRIERSETC2_HPP