11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "c1/c1_LIRAssembler.hpp"
26 #include "c1/c1_MacroAssembler.hpp"
27 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
28 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
29 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
30
31 void LIR_OpShenandoahCompareAndSwap::emit_code(LIR_Assembler* masm) {
32 Register addr = _addr->as_register_lo();
33 Register newval = _new_value->as_register();
34 Register cmpval = _cmp_value->as_register();
35 Register tmp1 = _tmp1->as_register();
36 Register tmp2 = _tmp2->as_register();
37 assert(cmpval == rax, "wrong register");
38 assert(newval != NULL, "new val must be register");
39 assert(cmpval != newval, "cmp and new values must be in different registers");
40 assert(cmpval != addr, "cmp and addr must be in different registers");
41 assert(newval != addr, "new value and addr must be in different registers");
42 ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm->masm(), NULL, Address(addr, 0), cmpval, newval, true, true, tmp1, tmp2);
43 }
44
45 #ifdef ASSERT
46 #define __ gen->lir(__FILE__, __LINE__)->
47 #else
48 #define __ gen->lir()->
49 #endif
50
51 LIR_Opr ShenandoahBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
52
53 if (access.is_oop()) {
54 LIRGenerator* gen = access.gen();
55 if (ShenandoahSATBBarrier) {
56 pre_barrier(gen, access.access_emit_info(), access.decorators(), access.resolved_addr(),
57 LIR_OprFact::illegalOpr /* pre_val */);
58 }
59 if (ShenandoahCASBarrier) {
60 cmp_value.load_item_force(FrameMap::rax_oop_opr);
61 new_value.load_item();
62
63 LIR_Opr t1 = gen->new_register(T_OBJECT);
64 LIR_Opr t2 = gen->new_register(T_OBJECT);
65 LIR_Opr addr = access.resolved_addr()->as_address_ptr()->base();
66
67 __ append(new LIR_OpShenandoahCompareAndSwap(addr, cmp_value.result(), new_value.result(), t1, t2, LIR_OprFact::illegalOpr));
68
69 LIR_Opr result = gen->new_register(T_INT);
70 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
71 result, T_INT);
72 return result;
73 }
74 }
75 return BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
76 }
77
78 LIR_Opr ShenandoahBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
79 LIRGenerator* gen = access.gen();
80 BasicType type = access.type();
81
82 LIR_Opr result = gen->new_register(type);
83 value.load_item();
84 LIR_Opr value_opr = value.result();
85
86 if (access.is_oop()) {
87 value_opr = storeval_barrier(access.gen(), value_opr, access.access_emit_info(), access.decorators());
88 }
89
90 // Because we want a 2-arg form of xchg and xadd
91 __ move(value_opr, result);
|
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #include "precompiled.hpp"
25 #include "c1/c1_LIRAssembler.hpp"
26 #include "c1/c1_MacroAssembler.hpp"
27 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
28 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
29 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
30
31 #define __ masm->masm()->
32
33 void LIR_OpShenandoahCompareAndSwap::emit_code(LIR_Assembler* masm) {
34 Register addr = _addr->as_register_lo();
35 Register newval = _new_value->as_register();
36 Register cmpval = _cmp_value->as_register();
37 Register tmp1 = _tmp1->as_register();
38 Register tmp2 = _tmp2->as_register();
39 Register result = result_opr()->as_register();
40 assert(cmpval == rax, "wrong register");
41 assert(newval != NULL, "new val must be register");
42 assert(cmpval != newval, "cmp and new values must be in different registers");
43 assert(cmpval != addr, "cmp and addr must be in different registers");
44 assert(newval != addr, "new value and addr must be in different registers");
45
46 // Apply storeval barrier to newval.
47 ShenandoahBarrierSet::assembler()->storeval_barrier(masm->masm(), newval, tmp1);
48
49 if (UseCompressedOops) {
50 __ encode_heap_oop(cmpval);
51 __ mov(rscratch1, newval);
52 __ encode_heap_oop(rscratch1);
53 newval = rscratch1;
54 }
55
56 ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm->masm(), result, Address(addr, 0), cmpval, newval, false, tmp1, tmp2);
57 }
58
59 #undef __
60
61 #ifdef ASSERT
62 #define __ gen->lir(__FILE__, __LINE__)->
63 #else
64 #define __ gen->lir()->
65 #endif
66
67 LIR_Opr ShenandoahBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
68
69 if (access.is_oop()) {
70 LIRGenerator* gen = access.gen();
71 if (ShenandoahSATBBarrier) {
72 pre_barrier(gen, access.access_emit_info(), access.decorators(), access.resolved_addr(),
73 LIR_OprFact::illegalOpr /* pre_val */);
74 }
75 if (ShenandoahCASBarrier) {
76 cmp_value.load_item_force(FrameMap::rax_oop_opr);
77 new_value.load_item();
78
79 LIR_Opr t1 = gen->new_register(T_OBJECT);
80 LIR_Opr t2 = gen->new_register(T_OBJECT);
81 LIR_Opr addr = access.resolved_addr()->as_address_ptr()->base();
82 LIR_Opr result = gen->new_register(T_INT);
83
84 __ append(new LIR_OpShenandoahCompareAndSwap(addr, cmp_value.result(), new_value.result(), t1, t2, result));
85 return result;
86 }
87 }
88 return BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
89 }
90
91 LIR_Opr ShenandoahBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
92 LIRGenerator* gen = access.gen();
93 BasicType type = access.type();
94
95 LIR_Opr result = gen->new_register(type);
96 value.load_item();
97 LIR_Opr value_opr = value.result();
98
99 if (access.is_oop()) {
100 value_opr = storeval_barrier(access.gen(), value_opr, access.access_emit_info(), access.decorators());
101 }
102
103 // Because we want a 2-arg form of xchg and xadd
104 __ move(value_opr, result);
|