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 #include "gc/shared/c1/modRefBarrierSetC1.hpp"
26 #include "utilities/macros.hpp"
27
28 #ifdef ASSERT
29 #define __ gen->lir(__FILE__, __LINE__)->
30 #else
31 #define __ gen->lir()->
32 #endif
33
34 void ModRefBarrierSetC1::store_at_resolved(LIRAccess& access, LIR_Opr value) {
35 DecoratorSet decorators = access.decorators();
36 bool is_array = (decorators & IS_ARRAY) != 0;
37 bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
38
39 if (access.is_oop()) {
40 pre_barrier(access, access.resolved_addr(),
41 LIR_OprFact::illegalOpr /* pre_val */, access.patch_emit_info());
42 }
43
44 BarrierSetC1::store_at_resolved(access, value);
45
46 if (access.is_oop()) {
47 bool precise = is_array || on_anonymous;
48 LIR_Opr post_addr = precise ? access.resolved_addr() : access.base().opr();
49 post_barrier(access, post_addr, value);
50 }
51 }
52
53 LIR_Opr ModRefBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
54 if (access.is_oop()) {
55 pre_barrier(access, access.resolved_addr(),
56 LIR_OprFact::illegalOpr /* pre_val */, nullptr);
57 }
58
59 LIR_Opr result = BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
60
61 if (access.is_oop()) {
62 post_barrier(access, access.resolved_addr(), new_value.result());
63 }
64
65 return result;
66 }
67
68 LIR_Opr ModRefBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
69 if (access.is_oop()) {
70 pre_barrier(access, access.resolved_addr(),
71 LIR_OprFact::illegalOpr /* pre_val */, nullptr);
72 }
73
74 LIR_Opr result = BarrierSetC1::atomic_xchg_at_resolved(access, value);
75
76 if (access.is_oop()) {
77 post_barrier(access, access.resolved_addr(), value.result());
78 }
79
80 return result;
81 }
82
83 // This overrides the default to resolve the address into a register,
84 // assuming it will be used by a write barrier anyway.
85 LIR_Opr ModRefBarrierSetC1::resolve_address(LIRAccess& access, bool resolve_in_register) {
86 DecoratorSet decorators = access.decorators();
87 bool needs_patching = (decorators & C1_NEEDS_PATCHING) != 0;
88 bool is_write = (decorators & ACCESS_WRITE) != 0;
89 bool is_array = (decorators & IS_ARRAY) != 0;
90 bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
91 bool precise = is_array || on_anonymous;
92 resolve_in_register |= !needs_patching && is_write && access.is_oop() && precise;
93 return BarrierSetC1::resolve_address(access, resolve_in_register);
94 }