1 /*
2 * Copyright (c) 2018, 2021, Red Hat, Inc. 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 *
67 #endif
68
69 LIR_Opr ShenandoahBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
70
71 if (access.is_oop()) {
72 LIRGenerator* gen = access.gen();
73 if (ShenandoahSATBBarrier) {
74 pre_barrier(gen, access.access_emit_info(), access.decorators(), access.resolved_addr(),
75 LIR_OprFact::illegalOpr /* pre_val */);
76 }
77 if (ShenandoahCASBarrier) {
78 cmp_value.load_item_force(FrameMap::rax_oop_opr);
79 new_value.load_item();
80
81 LIR_Opr t1 = gen->new_register(T_OBJECT);
82 LIR_Opr t2 = gen->new_register(T_OBJECT);
83 LIR_Opr addr = access.resolved_addr()->as_address_ptr()->base();
84 LIR_Opr result = gen->new_register(T_INT);
85
86 __ append(new LIR_OpShenandoahCompareAndSwap(addr, cmp_value.result(), new_value.result(), t1, t2, result));
87 return result;
88 }
89 }
90 return BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
91 }
92
93 LIR_Opr ShenandoahBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
94 LIRGenerator* gen = access.gen();
95 BasicType type = access.type();
96
97 LIR_Opr result = gen->new_register(type);
98 value.load_item();
99 LIR_Opr value_opr = value.result();
100
101 // Because we want a 2-arg form of xchg and xadd
102 __ move(value_opr, result);
103
104 assert(type == T_INT || is_reference_type(type) LP64_ONLY( || type == T_LONG ), "unexpected type");
105 __ xchg(access.resolved_addr(), result, result, LIR_OprFact::illegalOpr);
106
107 if (access.is_oop()) {
108 result = load_reference_barrier(access.gen(), result, LIR_OprFact::addressConst(0), access.decorators());
109 LIR_Opr tmp = gen->new_register(type);
110 __ move(result, tmp);
111 result = tmp;
112 if (ShenandoahSATBBarrier) {
113 pre_barrier(access.gen(), access.access_emit_info(), access.decorators(), LIR_OprFact::illegalOpr,
114 result /* pre_val */);
115 }
116 }
117
118 return result;
119 }
|
1 /*
2 * Copyright (c) 2018, 2021, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
68 #endif
69
70 LIR_Opr ShenandoahBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
71
72 if (access.is_oop()) {
73 LIRGenerator* gen = access.gen();
74 if (ShenandoahSATBBarrier) {
75 pre_barrier(gen, access.access_emit_info(), access.decorators(), access.resolved_addr(),
76 LIR_OprFact::illegalOpr /* pre_val */);
77 }
78 if (ShenandoahCASBarrier) {
79 cmp_value.load_item_force(FrameMap::rax_oop_opr);
80 new_value.load_item();
81
82 LIR_Opr t1 = gen->new_register(T_OBJECT);
83 LIR_Opr t2 = gen->new_register(T_OBJECT);
84 LIR_Opr addr = access.resolved_addr()->as_address_ptr()->base();
85 LIR_Opr result = gen->new_register(T_INT);
86
87 __ append(new LIR_OpShenandoahCompareAndSwap(addr, cmp_value.result(), new_value.result(), t1, t2, result));
88
89 if (ShenandoahCardBarrier) {
90 post_barrier(access, access.resolved_addr(), new_value.result());
91 }
92 return result;
93 }
94 }
95 return BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
96 }
97
98 LIR_Opr ShenandoahBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
99 LIRGenerator* gen = access.gen();
100 BasicType type = access.type();
101
102 LIR_Opr result = gen->new_register(type);
103 value.load_item();
104 LIR_Opr value_opr = value.result();
105
106 // Because we want a 2-arg form of xchg and xadd
107 __ move(value_opr, result);
108
109 assert(type == T_INT || is_reference_type(type) LP64_ONLY( || type == T_LONG ), "unexpected type");
110 __ xchg(access.resolved_addr(), result, result, LIR_OprFact::illegalOpr);
111
112 if (access.is_oop()) {
113 result = load_reference_barrier(access.gen(), result, LIR_OprFact::addressConst(0), access.decorators());
114 LIR_Opr tmp = gen->new_register(type);
115 __ move(result, tmp);
116 result = tmp;
117 if (ShenandoahSATBBarrier) {
118 pre_barrier(access.gen(), access.access_emit_info(), access.decorators(), LIR_OprFact::illegalOpr,
119 result /* pre_val */);
120 }
121 if (ShenandoahCardBarrier) {
122 post_barrier(access, access.resolved_addr(), result);
123 }
124 }
125
126 return result;
127 }
|