27 #include "asm/macroAssembler.inline.hpp"
28 #include "c1/c1_MacroAssembler.hpp"
29 #include "c1/c1_Runtime1.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/markWord.hpp"
35 #include "runtime/basicLock.hpp"
36 #include "runtime/biasedLocking.hpp"
37 #include "runtime/os.hpp"
38 #include "runtime/sharedRuntime.hpp"
39 #include "runtime/stubRoutines.hpp"
40 #include "utilities/align.hpp"
41
42
43 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
44 const Register temp_reg = R12_scratch2;
45 Label Lmiss;
46
47 verify_oop(receiver);
48 MacroAssembler::null_check(receiver, oopDesc::klass_offset_in_bytes(), &Lmiss);
49 load_klass(temp_reg, receiver);
50
51 if (TrapBasedICMissChecks && TrapBasedNullChecks) {
52 trap_ic_miss_check(temp_reg, iCache);
53 } else {
54 Label Lok;
55 cmpd(CCR0, temp_reg, iCache);
56 beq(CCR0, Lok);
57 bind(Lmiss);
58 //load_const_optimized(temp_reg, SharedRuntime::get_ic_miss_stub(), R0);
59 calculate_address_from_global_toc(temp_reg, SharedRuntime::get_ic_miss_stub(), true, true, false);
60 mtctr(temp_reg);
61 bctr();
62 align(32, 12);
63 bind(Lok);
64 }
65 }
66
67
83 push_frame(frame_size_in_bytes, R0); // SP -= frame_size_in_bytes
84 }
85
86
87 void C1_MacroAssembler::verified_entry() {
88 if (C1Breakpoint) illtrap();
89 // build frame
90 }
91
92
93 void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case) {
94 assert_different_registers(Rmark, Roop, Rbox, Rscratch);
95
96 Label done, cas_failed, slow_int;
97
98 // The following move must be the first instruction of emitted since debug
99 // information may be generated for it.
100 // Load object header.
101 ld(Rmark, oopDesc::mark_offset_in_bytes(), Roop);
102
103 verify_oop(Roop);
104
105 // Save object being locked into the BasicObjectLock...
106 std(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
107
108 if (UseBiasedLocking) {
109 biased_locking_enter(CCR0, Roop, Rmark, Rscratch, R0, done, &slow_int);
110 }
111
112 // ... and mark it unlocked.
113 ori(Rmark, Rmark, markWord::unlocked_value);
114
115 // Save unlocked object header into the displaced header location on the stack.
116 std(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);
117
118 // Compare object markWord with Rmark and if equal exchange Rscratch with object markWord.
119 assert(oopDesc::mark_offset_in_bytes() == 0, "cas must take a zero displacement");
120 cmpxchgd(/*flag=*/CCR0,
121 /*current_value=*/Rscratch,
122 /*compare_value=*/Rmark,
123 /*exchange_value=*/Rbox,
140 load_const_optimized(R0, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));
141 and_(R0/*==0?*/, Rscratch, R0);
142 std(R0/*==0, perhaps*/, BasicLock::displaced_header_offset_in_bytes(), Rbox);
143 bne(CCR0, slow_int);
144
145 bind(done);
146 }
147
148
149 void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {
150 assert_different_registers(Rmark, Roop, Rbox);
151
152 Label slow_int, done;
153
154 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());
155 assert(mark_addr.disp() == 0, "cas must take a zero displacement");
156
157 if (UseBiasedLocking) {
158 // Load the object out of the BasicObjectLock.
159 ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
160 verify_oop(Roop);
161 biased_locking_exit(CCR0, Roop, R0, done);
162 }
163 // Test first it it is a fast recursive unlock.
164 ld(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);
165 cmpdi(CCR0, Rmark, 0);
166 beq(CCR0, done);
167 if (!UseBiasedLocking) {
168 // Load object.
169 ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
170 verify_oop(Roop);
171 }
172
173 // Check if it is still a light weight lock, this is is true if we see
174 // the stack address of the basicLock in the markWord of the object.
175 cmpxchgd(/*flag=*/CCR0,
176 /*current_value=*/R0,
177 /*compare_value=*/Rbox,
178 /*exchange_value=*/Rmark,
179 /*where=*/Roop,
180 MacroAssembler::MemBarRel,
181 MacroAssembler::cmpxchgx_hint_release_lock(),
182 noreg,
183 &slow_int);
184 b(done);
185 bind(slow_int);
186 b(slow_case); // far
187
188 // Done
189 bind(done);
190 }
299 #endif
300
301 // Initialize body.
302 if (var_size_in_bytes != noreg) {
303 // Use a loop.
304 addi(t1, obj, hdr_size_in_bytes); // Compute address of first element.
305 addi(t2, var_size_in_bytes, -hdr_size_in_bytes); // Compute size of body.
306 initialize_body(t1, t2);
307 } else if (con_size_in_bytes > hdr_size_in_bytes) {
308 // Use a loop.
309 initialize_body(obj, t1, t2, con_size_in_bytes, hdr_size_in_bytes);
310 }
311
312 if (CURRENT_ENV->dtrace_alloc_probes()) {
313 Unimplemented();
314 // assert(obj == O0, "must be");
315 // call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
316 // relocInfo::runtime_call_type);
317 }
318
319 verify_oop(obj);
320 }
321
322
323 void C1_MacroAssembler::allocate_array(
324 Register obj, // result: pointer to array after successful allocation
325 Register len, // array length
326 Register t1, // temp register
327 Register t2, // temp register
328 Register t3, // temp register
329 int hdr_size, // object header size in words
330 int elt_size, // element size in bytes
331 Register klass, // object klass
332 Label& slow_case // continuation point if fast allocation fails
333 ) {
334 assert_different_registers(obj, len, t1, t2, t3, klass);
335
336 // Determine alignment mask.
337 assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
338 int log2_elt_size = exact_log2(elt_size);
339
366 tlab_allocate(obj, arr_size, 0, t2, slow_case);
367 } else {
368 eden_allocate(obj, arr_size, 0, t2, t3, slow_case);
369 }
370 initialize_header(obj, klass, len, t2, t3);
371
372 // Initialize body.
373 const Register base = t2;
374 const Register index = t3;
375 addi(base, obj, hdr_size * wordSize); // compute address of first element
376 addi(index, arr_size, -(hdr_size * wordSize)); // compute index = number of bytes to clear
377 initialize_body(base, index);
378
379 if (CURRENT_ENV->dtrace_alloc_probes()) {
380 Unimplemented();
381 //assert(obj == O0, "must be");
382 //call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
383 // relocInfo::runtime_call_type);
384 }
385
386 verify_oop(obj);
387 }
388
389
390 #ifndef PRODUCT
391
392 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
393 verify_oop_addr((RegisterOrConstant)(stack_offset + STACK_BIAS), R1_SP, "broken oop in stack slot");
394 }
395
396 void C1_MacroAssembler::verify_not_null_oop(Register r) {
397 Label not_null;
398 cmpdi(CCR0, r, 0);
399 bne(CCR0, not_null);
400 stop("non-null oop required");
401 bind(not_null);
402 if (!VerifyOops) return;
403 verify_oop(r);
404 }
405
406 #endif // PRODUCT
407
408 void C1_MacroAssembler::null_check(Register r, Label* Lnull) {
409 if (TrapBasedNullChecks) { // SIGTRAP based
410 trap_null_check(r);
411 } else { // explicit
412 //const address exception_entry = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);
413 assert(Lnull != NULL, "must have Label for explicit check");
414 cmpdi(CCR0, r, 0);
415 bc_far_optimized(Assembler::bcondCRbiIs1, bi0(CCR0, Assembler::equal), *Lnull);
416 }
417 }
418
419 address C1_MacroAssembler::call_c_with_frame_resize(address dest, int frame_resize) {
420 if (frame_resize) { resize_frame(-frame_resize, R0); }
421 #if defined(ABI_ELFv2)
422 address return_pc = call_c(dest, relocInfo::runtime_call_type);
423 #else
|
27 #include "asm/macroAssembler.inline.hpp"
28 #include "c1/c1_MacroAssembler.hpp"
29 #include "c1/c1_Runtime1.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/markWord.hpp"
35 #include "runtime/basicLock.hpp"
36 #include "runtime/biasedLocking.hpp"
37 #include "runtime/os.hpp"
38 #include "runtime/sharedRuntime.hpp"
39 #include "runtime/stubRoutines.hpp"
40 #include "utilities/align.hpp"
41
42
43 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
44 const Register temp_reg = R12_scratch2;
45 Label Lmiss;
46
47 verify_oop(receiver, FILE_AND_LINE);
48 MacroAssembler::null_check(receiver, oopDesc::klass_offset_in_bytes(), &Lmiss);
49 load_klass(temp_reg, receiver);
50
51 if (TrapBasedICMissChecks && TrapBasedNullChecks) {
52 trap_ic_miss_check(temp_reg, iCache);
53 } else {
54 Label Lok;
55 cmpd(CCR0, temp_reg, iCache);
56 beq(CCR0, Lok);
57 bind(Lmiss);
58 //load_const_optimized(temp_reg, SharedRuntime::get_ic_miss_stub(), R0);
59 calculate_address_from_global_toc(temp_reg, SharedRuntime::get_ic_miss_stub(), true, true, false);
60 mtctr(temp_reg);
61 bctr();
62 align(32, 12);
63 bind(Lok);
64 }
65 }
66
67
83 push_frame(frame_size_in_bytes, R0); // SP -= frame_size_in_bytes
84 }
85
86
87 void C1_MacroAssembler::verified_entry() {
88 if (C1Breakpoint) illtrap();
89 // build frame
90 }
91
92
93 void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case) {
94 assert_different_registers(Rmark, Roop, Rbox, Rscratch);
95
96 Label done, cas_failed, slow_int;
97
98 // The following move must be the first instruction of emitted since debug
99 // information may be generated for it.
100 // Load object header.
101 ld(Rmark, oopDesc::mark_offset_in_bytes(), Roop);
102
103 verify_oop(Roop, FILE_AND_LINE);
104
105 // Save object being locked into the BasicObjectLock...
106 std(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
107
108 if (UseBiasedLocking) {
109 biased_locking_enter(CCR0, Roop, Rmark, Rscratch, R0, done, &slow_int);
110 }
111
112 // ... and mark it unlocked.
113 ori(Rmark, Rmark, markWord::unlocked_value);
114
115 // Save unlocked object header into the displaced header location on the stack.
116 std(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);
117
118 // Compare object markWord with Rmark and if equal exchange Rscratch with object markWord.
119 assert(oopDesc::mark_offset_in_bytes() == 0, "cas must take a zero displacement");
120 cmpxchgd(/*flag=*/CCR0,
121 /*current_value=*/Rscratch,
122 /*compare_value=*/Rmark,
123 /*exchange_value=*/Rbox,
140 load_const_optimized(R0, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));
141 and_(R0/*==0?*/, Rscratch, R0);
142 std(R0/*==0, perhaps*/, BasicLock::displaced_header_offset_in_bytes(), Rbox);
143 bne(CCR0, slow_int);
144
145 bind(done);
146 }
147
148
149 void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {
150 assert_different_registers(Rmark, Roop, Rbox);
151
152 Label slow_int, done;
153
154 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());
155 assert(mark_addr.disp() == 0, "cas must take a zero displacement");
156
157 if (UseBiasedLocking) {
158 // Load the object out of the BasicObjectLock.
159 ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
160 verify_oop(Roop, FILE_AND_LINE);
161 biased_locking_exit(CCR0, Roop, R0, done);
162 }
163 // Test first it it is a fast recursive unlock.
164 ld(Rmark, BasicLock::displaced_header_offset_in_bytes(), Rbox);
165 cmpdi(CCR0, Rmark, 0);
166 beq(CCR0, done);
167 if (!UseBiasedLocking) {
168 // Load object.
169 ld(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
170 verify_oop(Roop, FILE_AND_LINE);
171 }
172
173 // Check if it is still a light weight lock, this is is true if we see
174 // the stack address of the basicLock in the markWord of the object.
175 cmpxchgd(/*flag=*/CCR0,
176 /*current_value=*/R0,
177 /*compare_value=*/Rbox,
178 /*exchange_value=*/Rmark,
179 /*where=*/Roop,
180 MacroAssembler::MemBarRel,
181 MacroAssembler::cmpxchgx_hint_release_lock(),
182 noreg,
183 &slow_int);
184 b(done);
185 bind(slow_int);
186 b(slow_case); // far
187
188 // Done
189 bind(done);
190 }
299 #endif
300
301 // Initialize body.
302 if (var_size_in_bytes != noreg) {
303 // Use a loop.
304 addi(t1, obj, hdr_size_in_bytes); // Compute address of first element.
305 addi(t2, var_size_in_bytes, -hdr_size_in_bytes); // Compute size of body.
306 initialize_body(t1, t2);
307 } else if (con_size_in_bytes > hdr_size_in_bytes) {
308 // Use a loop.
309 initialize_body(obj, t1, t2, con_size_in_bytes, hdr_size_in_bytes);
310 }
311
312 if (CURRENT_ENV->dtrace_alloc_probes()) {
313 Unimplemented();
314 // assert(obj == O0, "must be");
315 // call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
316 // relocInfo::runtime_call_type);
317 }
318
319 verify_oop(obj, FILE_AND_LINE);
320 }
321
322
323 void C1_MacroAssembler::allocate_array(
324 Register obj, // result: pointer to array after successful allocation
325 Register len, // array length
326 Register t1, // temp register
327 Register t2, // temp register
328 Register t3, // temp register
329 int hdr_size, // object header size in words
330 int elt_size, // element size in bytes
331 Register klass, // object klass
332 Label& slow_case // continuation point if fast allocation fails
333 ) {
334 assert_different_registers(obj, len, t1, t2, t3, klass);
335
336 // Determine alignment mask.
337 assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
338 int log2_elt_size = exact_log2(elt_size);
339
366 tlab_allocate(obj, arr_size, 0, t2, slow_case);
367 } else {
368 eden_allocate(obj, arr_size, 0, t2, t3, slow_case);
369 }
370 initialize_header(obj, klass, len, t2, t3);
371
372 // Initialize body.
373 const Register base = t2;
374 const Register index = t3;
375 addi(base, obj, hdr_size * wordSize); // compute address of first element
376 addi(index, arr_size, -(hdr_size * wordSize)); // compute index = number of bytes to clear
377 initialize_body(base, index);
378
379 if (CURRENT_ENV->dtrace_alloc_probes()) {
380 Unimplemented();
381 //assert(obj == O0, "must be");
382 //call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
383 // relocInfo::runtime_call_type);
384 }
385
386 verify_oop(obj, FILE_AND_LINE);
387 }
388
389
390 #ifndef PRODUCT
391
392 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
393 verify_oop_addr((RegisterOrConstant)(stack_offset + STACK_BIAS), R1_SP, "broken oop in stack slot");
394 }
395
396 void C1_MacroAssembler::verify_not_null_oop(Register r) {
397 Label not_null;
398 cmpdi(CCR0, r, 0);
399 bne(CCR0, not_null);
400 stop("non-null oop required");
401 bind(not_null);
402 verify_oop(r, FILE_AND_LINE);
403 }
404
405 #endif // PRODUCT
406
407 void C1_MacroAssembler::null_check(Register r, Label* Lnull) {
408 if (TrapBasedNullChecks) { // SIGTRAP based
409 trap_null_check(r);
410 } else { // explicit
411 //const address exception_entry = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);
412 assert(Lnull != NULL, "must have Label for explicit check");
413 cmpdi(CCR0, r, 0);
414 bc_far_optimized(Assembler::bcondCRbiIs1, bi0(CCR0, Assembler::equal), *Lnull);
415 }
416 }
417
418 address C1_MacroAssembler::call_c_with_frame_resize(address dest, int frame_resize) {
419 if (frame_resize) { resize_frame(-frame_resize, R0); }
420 #if defined(ABI_ELFv2)
421 address return_pc = call_c(dest, relocInfo::runtime_call_type);
422 #else
|