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