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 "code/aotCodeCache.hpp"
26 #include "gc/shared/c1/cardTableBarrierSetC1.hpp"
27 #include "gc/shared/cardTable.hpp"
28 #include "gc/shared/cardTableBarrierSet.hpp"
29 #include "gc/shared/gc_globals.hpp"
30 #include "utilities/macros.hpp"
31
32 #ifdef ASSERT
33 #define __ gen->lir(__FILE__, __LINE__)->
34 #else
35 #define __ gen->lir()->
36 #endif
37
38 void CardTableBarrierSetC1::store_at_resolved(LIRAccess& access, LIR_Opr value) {
39 DecoratorSet decorators = access.decorators();
40 bool is_array = (decorators & IS_ARRAY) != 0;
41 bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
42
43 if (access.is_oop()) {
44 pre_barrier(access, access.resolved_addr(),
45 LIR_OprFact::illegalOpr /* pre_val */, access.patch_emit_info());
46 }
47
48 BarrierSetC1::store_at_resolved(access, value);
49
50 if (access.is_oop()) {
51 bool precise = is_array || on_anonymous;
52 LIR_Opr post_addr = precise ? access.resolved_addr() : access.base().opr();
53 post_barrier(access, post_addr, value);
54 }
55 }
56
57 LIR_Opr CardTableBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
58 if (access.is_oop()) {
59 pre_barrier(access, access.resolved_addr(),
60 LIR_OprFact::illegalOpr /* pre_val */, nullptr);
61 }
62
63 LIR_Opr result = BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
64
65 if (access.is_oop()) {
66 post_barrier(access, access.resolved_addr(), new_value.result());
67 }
68
69 return result;
70 }
71
72 LIR_Opr CardTableBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
73 if (access.is_oop()) {
74 pre_barrier(access, access.resolved_addr(),
|
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 "ci/ciInlineKlass.hpp"
26 #include "code/aotCodeCache.hpp"
27 #include "gc/shared/c1/cardTableBarrierSetC1.hpp"
28 #include "gc/shared/cardTable.hpp"
29 #include "gc/shared/cardTableBarrierSet.hpp"
30 #include "gc/shared/gc_globals.hpp"
31 #include "utilities/macros.hpp"
32
33 #ifdef ASSERT
34 #define __ gen->lir(__FILE__, __LINE__)->
35 #else
36 #define __ gen->lir()->
37 #endif
38
39 void CardTableBarrierSetC1::store_at_resolved(LIRAccess& access, LIR_Opr value) {
40 DecoratorSet decorators = access.decorators();
41 bool is_array = (decorators & IS_ARRAY) != 0;
42 bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
43
44 // Is this a flat, atomic access that might require gc barriers on oop fields?
45 ciInlineKlass* vk = access.vk();
46 if (vk != nullptr && vk->has_object_fields()) {
47 // Add pre-barriers for oop fields
48 for (int i = 0; i < vk->nof_nonstatic_fields(); i++) {
49 ciField* field = vk->nonstatic_field_at(i);
50 if (!field->type()->is_primitive_type()) {
51 int off = access.offset().opr().as_jint() + field->offset_in_bytes() - vk->payload_offset();
52 LIRAccess inner_access(access.gen(), decorators, access.base(), LIR_OprFact::intConst(off), field->type()->basic_type(), access.patch_emit_info(), access.access_emit_info());
53 pre_barrier(inner_access, resolve_address(inner_access, false),
54 LIR_OprFact::illegalOpr /* pre_val */, inner_access.patch_emit_info());
55 }
56 }
57 }
58
59 if (access.is_oop()) {
60 pre_barrier(access, access.resolved_addr(),
61 LIR_OprFact::illegalOpr /* pre_val */, access.patch_emit_info());
62 }
63
64 BarrierSetC1::store_at_resolved(access, value);
65
66 if (access.is_oop()) {
67 bool precise = is_array || on_anonymous;
68 LIR_Opr post_addr = precise ? access.resolved_addr() : access.base().opr();
69 post_barrier(access, post_addr, value);
70 }
71
72 if (vk != nullptr && vk->has_object_fields()) {
73 // Add post-barriers for oop fields
74 for (int i = 0; i < vk->nof_nonstatic_fields(); i++) {
75 ciField* field = vk->nonstatic_field_at(i);
76 if (!field->type()->is_primitive_type()) {
77 int inner_off = field->offset_in_bytes() - vk->payload_offset();
78 int off = access.offset().opr().as_jint() + inner_off;
79 LIRAccess inner_access(access.gen(), decorators, access.base(), LIR_OprFact::intConst(off), field->type()->basic_type(), access.patch_emit_info(), access.access_emit_info());
80
81 // Shift long value to extract the narrow oop field value and zero-extend
82 LIR_Opr field_val = access.gen()->new_register(T_LONG);
83 access.gen()->lir()->unsigned_shift_right(value,
84 LIR_OprFact::intConst(inner_off << LogBitsPerByte),
85 field_val, LIR_Opr::illegalOpr());
86 LIR_Opr mask = access.gen()->load_immediate((julong) max_juint, T_LONG);
87 access.gen()->lir()->logical_and(field_val, mask, field_val);
88 LIR_Opr oop_val = access.gen()->new_register(T_OBJECT);
89 access.gen()->lir()->move(field_val, oop_val);
90
91 assert(!is_array && !on_anonymous, "not suppported");
92 post_barrier(inner_access, access.base().opr(), oop_val);
93 }
94 }
95 }
96 }
97
98 LIR_Opr CardTableBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {
99 if (access.is_oop()) {
100 pre_barrier(access, access.resolved_addr(),
101 LIR_OprFact::illegalOpr /* pre_val */, nullptr);
102 }
103
104 LIR_Opr result = BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);
105
106 if (access.is_oop()) {
107 post_barrier(access, access.resolved_addr(), new_value.result());
108 }
109
110 return result;
111 }
112
113 LIR_Opr CardTableBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {
114 if (access.is_oop()) {
115 pre_barrier(access, access.resolved_addr(),
|