11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_MacroAssembler.hpp"
29 #include "c1/c1_Runtime1.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "gc/shared/barrierSetAssembler.hpp"
32 #include "gc/shared/collectedHeap.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "oops/arrayOop.hpp"
35 #include "oops/markWord.hpp"
36 #include "runtime/basicLock.hpp"
37 #include "runtime/os.hpp"
38 #include "runtime/sharedRuntime.hpp"
39 #include "runtime/stubRoutines.hpp"
40
41 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
42 FloatRegister freg0, FloatRegister freg1,
43 Register result) {
44 if (is_float) {
45 float_compare(result, freg0, freg1, unordered_result);
46 } else {
47 double_compare(result, freg0, freg1, unordered_result);
48 }
49 }
50
51 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register basic_lock, Register temp, Label& slow_case) {
52 assert_different_registers(hdr, obj, basic_lock, temp, t0, t1);
53 int null_check_offset = -1;
54
55 verify_oop(obj);
68 assert_different_registers(hdr, obj, basic_lock, temp, t0, t1);
69
70 // load object
71 ld(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
72 verify_oop(obj);
73
74 fast_unlock(obj, hdr, temp, t1, slow_case);
75 }
76
77 // Defines obj, preserves var_size_in_bytes
78 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register tmp1, Register tmp2, Label& slow_case) {
79 if (UseTLAB) {
80 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, tmp1, tmp2, slow_case, /* is_far */ true);
81 } else {
82 j(slow_case);
83 }
84 }
85
86 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register tmp1, Register tmp2) {
87 assert_different_registers(obj, klass, len, tmp1, tmp2);
88 if (UseCompactObjectHeaders) {
89 ld(tmp1, Address(klass, Klass::prototype_header_offset()));
90 sd(tmp1, Address(obj, oopDesc::mark_offset_in_bytes()));
91 } else {
92 // This assumes that all prototype bits fitr in an int32_t
93 mv(tmp1, checked_cast<int32_t>(markWord::prototype().value()));
94 sd(tmp1, Address(obj, oopDesc::mark_offset_in_bytes()));
95 encode_klass_not_null(tmp1, klass, tmp2);
96 sw(tmp1, Address(obj, oopDesc::klass_offset_in_bytes()));
97 }
98
99 if (len->is_valid()) {
100 sw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
101 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
102 if (!is_aligned(base_offset, BytesPerWord)) {
103 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
104 // Clear gap/first 4 bytes following the length field.
105 sw(zr, Address(obj, base_offset));
106 }
107 } else if (!UseCompactObjectHeaders) {
108 store_klass_gap(obj, zr);
109 }
110 }
111
112 // preserves obj, destroys len_in_bytes
113 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register tmp) {
114 assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
115 Label done;
226 // Align-up to word boundary, because we clear the 4 bytes potentially
227 // following the length field in initialize_header().
228 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
229
230 // clear rest of allocated space
231 const Register len_zero = len;
232 if (zero_array) {
233 initialize_body(obj, arr_size, base_offset, len_zero);
234 }
235
236 membar(MacroAssembler::StoreStore);
237
238 if (CURRENT_ENV->dtrace_alloc_probes()) {
239 assert(obj == x10, "must be");
240 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
241 }
242
243 verify_oop(obj);
244 }
245
246 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
247 assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
248 // Make sure there is enough stack space for this method's activation.
249 // Note that we do this before creating a frame.
250 generate_stack_overflow_check(bang_size_in_bytes);
251 MacroAssembler::build_frame(framesize);
252
253 // Insert nmethod entry barrier into frame.
254 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
255 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
256 }
257
258 void C1_MacroAssembler::remove_frame(int framesize) {
259 MacroAssembler::remove_frame(framesize);
260 }
261
262
263 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
264 // If we have to make this method not-entrant we'll overwrite its
265 // first instruction with a jump. For this action to be legal we
266 // must ensure that this first instruction is a J, JAL or NOP.
267 // Make it a NOP.
268 IncompressibleScope scope(this); // keep the nop as 4 bytes for patching.
269 assert_alignment(pc());
270 nop(); // 4 bytes
271 }
272
273 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
274 // fp + -2: link
275 // + -1: return address
276 // + 0: argument with offset 0
277 // + 1: argument with offset 1
278 // + 2: ...
279 ld(reg, Address(fp, offset_in_words * BytesPerWord));
280 }
281
282 #ifndef PRODUCT
283
284 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
285 if (!VerifyOops) {
286 return;
287 }
288 verify_oop_addr(Address(sp, stack_offset));
289 }
290
291 void C1_MacroAssembler::verify_not_null_oop(Register r) {
292 if (!VerifyOops) return;
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_MacroAssembler.hpp"
29 #include "c1/c1_Runtime1.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "gc/shared/barrierSet.hpp"
32 #include "gc/shared/barrierSetAssembler.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "oops/arrayOop.hpp"
36 #include "oops/markWord.hpp"
37 #include "runtime/arguments.hpp"
38 #include "runtime/basicLock.hpp"
39 #include "runtime/os.hpp"
40 #include "runtime/sharedRuntime.hpp"
41 #include "runtime/stubRoutines.hpp"
42
43 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
44 FloatRegister freg0, FloatRegister freg1,
45 Register result) {
46 if (is_float) {
47 float_compare(result, freg0, freg1, unordered_result);
48 } else {
49 double_compare(result, freg0, freg1, unordered_result);
50 }
51 }
52
53 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register basic_lock, Register temp, Label& slow_case) {
54 assert_different_registers(hdr, obj, basic_lock, temp, t0, t1);
55 int null_check_offset = -1;
56
57 verify_oop(obj);
70 assert_different_registers(hdr, obj, basic_lock, temp, t0, t1);
71
72 // load object
73 ld(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
74 verify_oop(obj);
75
76 fast_unlock(obj, hdr, temp, t1, slow_case);
77 }
78
79 // Defines obj, preserves var_size_in_bytes
80 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register tmp1, Register tmp2, Label& slow_case) {
81 if (UseTLAB) {
82 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, tmp1, tmp2, slow_case, /* is_far */ true);
83 } else {
84 j(slow_case);
85 }
86 }
87
88 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register tmp1, Register tmp2) {
89 assert_different_registers(obj, klass, len, tmp1, tmp2);
90 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
91 // COH: Markword contains class pointer which is only known at runtime.
92 // Valhalla: Could have value class which has a different prototype header to a normal object.
93 // In both cases, we need to fetch dynamically.
94 ld(tmp1, Address(klass, Klass::prototype_header_offset()));
95 sd(tmp1, Address(obj, oopDesc::mark_offset_in_bytes()));
96 } else {
97 // Otherwise: Can use the statically computed prototype header which is the same for every object.
98 mv(tmp1, checked_cast<int32_t>(markWord::prototype().value()));
99 sd(tmp1, Address(obj, oopDesc::mark_offset_in_bytes()));
100 }
101
102 if (!UseCompactObjectHeaders) {
103 // COH: Markword already contains class pointer. Nothing else to do.
104 // Otherwise: Fetch klass pointer following the markword
105 encode_klass_not_null(tmp1, klass, tmp2); // Take care not to kill klass
106 sw(tmp1, Address(obj, oopDesc::klass_offset_in_bytes()));
107 }
108
109 if (len->is_valid()) {
110 sw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
111 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
112 if (!is_aligned(base_offset, BytesPerWord)) {
113 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
114 // Clear gap/first 4 bytes following the length field.
115 sw(zr, Address(obj, base_offset));
116 }
117 } else if (!UseCompactObjectHeaders) {
118 store_klass_gap(obj, zr);
119 }
120 }
121
122 // preserves obj, destroys len_in_bytes
123 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register tmp) {
124 assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
125 Label done;
236 // Align-up to word boundary, because we clear the 4 bytes potentially
237 // following the length field in initialize_header().
238 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
239
240 // clear rest of allocated space
241 const Register len_zero = len;
242 if (zero_array) {
243 initialize_body(obj, arr_size, base_offset, len_zero);
244 }
245
246 membar(MacroAssembler::StoreStore);
247
248 if (CURRENT_ENV->dtrace_alloc_probes()) {
249 assert(obj == x10, "must be");
250 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
251 }
252
253 verify_oop(obj);
254 }
255
256 void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes,
257 int sp_offset_for_orig_pc,
258 bool needs_stack_repair, bool has_scalarized_args,
259 Label* verified_inline_entry_label) {
260 assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
261
262 assert(!needs_stack_repair && !has_scalarized_args, "");
263
264 // Make sure there is enough stack space for this method's activation.
265 // Note that we do this before creating a frame.
266 generate_stack_overflow_check(bang_size_in_bytes);
267 MacroAssembler::build_frame(frame_size_in_bytes);
268
269 // Insert nmethod entry barrier into frame.
270 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
271 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
272
273 if (verified_inline_entry_label != nullptr) {
274 // Jump here from the scalarized entry points that already created the frame.
275 bind(*verified_inline_entry_label);
276 }
277 }
278
279 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
280 // If we have to make this method not-entrant we'll overwrite its
281 // first instruction with a jump. For this action to be legal we
282 // must ensure that this first instruction is a J, JAL or NOP.
283 // Make it a NOP.
284 IncompressibleScope scope(this); // keep the nop as 4 bytes for patching.
285 assert_alignment(pc());
286 nop(); // 4 bytes
287 }
288
289 int C1_MacroAssembler::scalarized_entry(const CompiledEntrySignature* ces, int frame_size_in_bytes, int bang_size_in_bytes,
290 int sp_offset_for_orig_pc, Label& verified_inline_entry_label, bool is_inline_ro_entry) {
291 Unimplemented();
292 return 0;
293 }
294
295 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
296 // fp + -2: link
297 // + -1: return address
298 // + 0: argument with offset 0
299 // + 1: argument with offset 1
300 // + 2: ...
301 ld(reg, Address(fp, offset_in_words * BytesPerWord));
302 }
303
304 #ifndef PRODUCT
305
306 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
307 if (!VerifyOops) {
308 return;
309 }
310 verify_oop_addr(Address(sp, stack_offset));
311 }
312
313 void C1_MacroAssembler::verify_not_null_oop(Register r) {
314 if (!VerifyOops) return;
|