Tue, 04 Sep 2018 21:25:12 +0800
#7517 mRegP match a0_RegP
1 /*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2018, Loongson Technology. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
26 #include "precompiled.hpp"
27 #include "c1/c1_Compilation.hpp"
28 #include "c1/c1_FrameMap.hpp"
29 #include "c1/c1_Instruction.hpp"
30 #include "c1/c1_LIRAssembler.hpp"
31 #include "c1/c1_LIRGenerator.hpp"
32 #include "c1/c1_Runtime1.hpp"
33 #include "c1/c1_ValueStack.hpp"
34 #include "ci/ciArray.hpp"
35 #include "ci/ciObjArrayKlass.hpp"
36 #include "ci/ciTypeArrayKlass.hpp"
37 #include "runtime/sharedRuntime.hpp"
38 #include "runtime/stubRoutines.hpp"
39 #include "vmreg_mips.inline.hpp"
41 #ifdef ASSERT
42 #define __ gen()->lir(__FILE__, __LINE__)->
43 #else
44 #define __ gen()->lir()->
45 #endif
47 // Item will be loaded into a byte register; Intel only
48 void LIRItem::load_byte_item() {
49 load_item();
50 LIR_Opr res = result();
52 if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {
53 // make sure that it is a byte register
54 assert(!value()->type()->is_float() && !value()->type()->is_double(),
55 "can't load floats in byte register");
56 LIR_Opr reg = _gen->rlock_byte(T_BYTE);
57 __ move(res, reg);
59 _result = reg;
60 }
61 }
64 void LIRItem::load_nonconstant() {
65 LIR_Opr r = value()->operand();
66 if (r->is_constant()) {
67 _result = r;
68 } else {
69 load_item();
70 }
71 }
73 //--------------------------------------------------------------
74 // LIRGenerator
75 //--------------------------------------------------------------
76 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::_v0_oop_opr; }
77 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::_v1_opr; }
78 LIR_Opr LIRGenerator::divInOpr() { return FrameMap::_a0_opr; }//FIXME
79 LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::_f0_opr; } //FIXME
80 LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::_f0_opr; } //FIXME
81 LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::_t3_opr; } //
82 LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::_t2_opr; }
83 LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; } //
86 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
87 LIR_Opr opr;
88 switch (type->tag()) {
89 case intTag: {
90 opr = FrameMap::_v0_opr;
91 break;
92 }
93 case objectTag: {
94 opr = FrameMap::_v0_oop_opr;
95 break;
96 }
97 case longTag: {
98 opr = FrameMap::_v0_v1_long_opr;
99 break;
100 }
101 case floatTag: {
102 opr = FrameMap::_f0_float_opr;
103 break;
104 }
105 case doubleTag: {
106 opr = FrameMap::_d0_double_opr;
107 break;
108 }
109 case addressTag:
110 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
111 }
113 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
114 return opr;
115 }
117 LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) {
118 LIR_Opr reg = new_register(type);
119 set_vreg_flag(reg, callee_saved);
120 return reg;
121 }
124 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
125 return new_register(T_INT);
126 }
129 //--------- loading items into registers --------------------------------
132 // i486 instructions can inline constants
133 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
134 if (type == T_SHORT || type == T_CHAR) {
135 // there is no immediate move of word values in asembler_i486.?pp
136 return false;
137 }
138 Constant* c = v->as_Constant();
139 if (c && c->state_before() == NULL) {
140 // constants of any type can be stored directly, except for
141 // unloaded object constants.
142 return true;
143 }
144 return false;
145 }
148 bool LIRGenerator::can_inline_as_constant(Value v) const {
149 if (v->type()->is_constant() && v->type()->as_IntConstant() != NULL) {
150 return Assembler::is_simm16(v->type()->as_IntConstant()->value());
151 } else {
152 return false;
153 }
154 }
157 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
158 if (c->type() == T_INT && c->as_constant() != NULL) {
159 return Assembler::is_simm16(c->as_jint());
160 } else {
161 return false;
162 }
163 }
166 LIR_Opr LIRGenerator::safepoint_poll_register() {
167 return new_register(T_INT);
168 }
171 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
172 int shift, int disp, BasicType type) {
173 assert(base->is_register(), "must be");
174 if (index->is_constant()) {
175 disp += index->as_constant_ptr()->as_jint() << shift;
176 if (Assembler::is_simm16(disp)) {
177 return new LIR_Address(base,disp, type);
178 } else {
180 if(disp!=0){
181 #ifdef _LP64
182 LIR_Opr tmp = new_register(T_LONG);
183 #else
184 LIR_Opr tmp = new_register(T_INT);
185 #endif
186 __ move(LIR_OprFact::intConst((int)disp), tmp);
187 __ add(tmp, base, tmp);
188 return new LIR_Address(tmp, 0, type);
189 }
190 else
191 return new LIR_Address(base, 0, type);
192 }
193 } else if( index->is_register()) {
195 #ifdef _LP64
196 LIR_Opr tmpa = new_register(T_LONG);
197 #else
198 LIR_Opr tmpa = new_register(T_INT);
199 #endif
200 __ move(index, tmpa);
201 __ shift_left(tmpa, shift, tmpa);
202 __ add(tmpa,base, tmpa);
203 if (Assembler::is_simm16(disp)) {
204 return new LIR_Address(tmpa, disp, type);
205 } else {
206 if (disp!=0) {
207 #ifdef _LP64
208 LIR_Opr tmp = new_register(T_LONG);
209 #else
210 LIR_Opr tmp = new_register(T_INT);
211 #endif
213 __ move(LIR_OprFact::intConst((int)disp), tmp);
214 __ add(tmp, tmpa, tmp);
215 return new LIR_Address(tmp, 0, type);
216 } else
217 return new LIR_Address(tmpa, 0, type);
218 }
219 } else {
220 if (Assembler::is_simm16(disp)) {
221 return new LIR_Address(base,disp, type);
222 } else {
223 if (disp!=0) {
224 #ifdef _LP64
225 LIR_Opr tmp = new_register(T_LONG);
226 #else
227 LIR_Opr tmp = new_register(T_INT);
228 #endif
229 __ move(LIR_OprFact::intConst((int)disp), tmp);
230 __ add(tmp, base, tmp);
231 return new LIR_Address(tmp, 0, type);
232 } else
233 return new LIR_Address(base, 0, type);
234 }
235 }
236 }
238 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
239 BasicType type, bool needs_card_mark) {
240 int elem_size = type2aelembytes(type);
241 int shift = exact_log2(elem_size);
243 LIR_Opr base_opr;
244 int offset = arrayOopDesc::base_offset_in_bytes(type);
246 if (index_opr->is_constant()) {
247 int i = index_opr->as_constant_ptr()->as_jint();
248 int array_offset = i * elem_size;
249 if (Assembler::is_simm16(array_offset + offset)) {
250 base_opr = array_opr;
251 offset = array_offset + offset;
252 } else {
253 base_opr = new_pointer_register();
254 if (Assembler::is_simm16(array_offset)) {
255 __ add(array_opr, LIR_OprFact::intptrConst(array_offset), base_opr);
256 } else {
257 __ move(LIR_OprFact::intptrConst(array_offset), base_opr);
258 __ add(base_opr, array_opr, base_opr);
259 }
260 }
261 } else {
262 #ifdef _LP64
263 if (index_opr->type() == T_INT) {
264 LIR_Opr tmp = new_register(T_LONG);
265 __ convert(Bytecodes::_i2l, index_opr, tmp);
266 index_opr = tmp;
267 }
268 #endif
270 base_opr = new_pointer_register();
271 assert (index_opr->is_register(), "Must be register");
272 if (shift > 0) {
273 __ shift_left(index_opr, shift, base_opr);
274 __ add(base_opr, array_opr, base_opr);
275 } else {
276 __ add(index_opr, array_opr, base_opr);
277 }
278 }
279 if (needs_card_mark) {
280 // This store will need a precise card mark, so go ahead and
281 // compute the full adddres instead of computing once for the
282 // store and again for the card mark.
283 LIR_Opr ptr = new_pointer_register();
284 __ add(base_opr, LIR_OprFact::intptrConst(offset), ptr);
285 return new LIR_Address(ptr, type);
286 } else {
287 return new LIR_Address(base_opr, offset, type);
288 }
289 }
292 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
293 LIR_Opr r;
294 if (type == T_LONG) {
295 r = LIR_OprFact::longConst(x);
296 } else if (type == T_INT) {
297 r = LIR_OprFact::intConst(x);
298 } else {
299 ShouldNotReachHere();
300 }
301 return r;
302 }
304 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
305 #ifdef _LP64
306 LIR_Opr pointer = new_register(T_LONG);
307 #else
308 LIR_Opr pointer = new_register(T_INT);
309 #endif
310 __ move(LIR_OprFact::intptrConst(counter), pointer);
311 LIR_Address* addr = new LIR_Address(pointer, type);
312 increment_counter(addr, step);
313 }
315 //void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
316 // LIR_Opr pointer = new_register(T_LONG);
317 // __ move(LIR_OprFact::longConst((long)counter), pointer);
318 // LIR_Opr addr = (LIR_Opr)new LIR_Address(pointer, type);
319 // LIR_Opr c = LIR_OprFact::intConst((int)step);
320 // __ add(addr, c, addr);
321 //}
323 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
324 LIR_Opr temp = new_register(addr->type());
325 __ move(addr, temp);
326 __ add(temp, load_immediate(step, addr->type()), temp);
327 __ move(temp, addr);
328 }
331 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
332 if (tmp->is_valid()) {
333 if (is_power_of_2(c + 1)) {
334 __ move(left, result);
335 __ shift_left(result, log2_intptr(c + 1), result);
336 __ sub(result, left, result);
337 return true;
338 } else if (is_power_of_2(c - 1)) {
339 __ move(left, result);
340 __ shift_left(result, log2_intptr(c - 1), result);
341 __ add(result, left, result);
342 return true;
343 }
344 }
345 return false;
346 }
349 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
350 BasicType type = item->type();
351 __ store(item, new LIR_Address(FrameMap::_sp_opr, in_bytes(offset_from_sp), type));
352 }
354 //----------------------------------------------------------------------
355 // visitor functions
356 //----------------------------------------------------------------------
359 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
360 assert(x->is_pinned(),"");
361 bool needs_range_check = true;
362 bool use_length = x->length() != NULL;
363 bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
364 bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
365 !get_jobject_constant(x->value())->is_null_object());
367 LIRItem array(x->array(), this);
368 LIRItem index(x->index(), this);
369 LIRItem value(x->value(), this);
370 LIRItem length(this);
372 array.load_item();
373 index.load_nonconstant();
375 if (use_length) {
376 needs_range_check = x->compute_needs_range_check();
377 if (needs_range_check) {
378 length.set_instruction(x->length());
379 length.load_item();
380 }
381 }
382 if (needs_store_check) {
383 value.load_item();
384 } else {
385 value.load_for_store(x->elt_type());
386 }
388 set_no_result(x);
390 // the CodeEmitInfo must be duplicated for each different
391 // LIR-instruction because spilling can occur anywhere between two
392 // instructions and so the debug information must be different
393 CodeEmitInfo* range_check_info = state_for(x);
394 CodeEmitInfo* null_check_info = NULL;
395 if (x->needs_null_check()) {
396 null_check_info = new CodeEmitInfo(range_check_info);
397 }
399 // emit array address setup early so it schedules better
400 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);
402 if (GenerateRangeChecks && needs_range_check) {
403 if (use_length) {
404 __ branch(lir_cond_belowEqual, length.result(),index.result(),T_INT,new RangeCheckStub(range_check_info, index.result()));
405 } else {
406 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
407 // range_check also does the null check
408 null_check_info = NULL;
409 }
410 }
412 if (GenerateArrayStoreCheck && needs_store_check) {
413 LIR_Opr tmp1 = new_register(objectType);
414 LIR_Opr tmp2 = new_register(objectType);
415 LIR_Opr tmp3 = new_register(objectType);
417 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
418 __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
419 }
421 if (obj_store) {
422 // Needs GC write barriers.
423 pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr, true, false, NULL);
424 __ move(value.result(), array_addr, null_check_info);
425 // Seems to be a precise
426 post_barrier(LIR_OprFact::address(array_addr), value.result());
427 } else {
428 __ move(value.result(), array_addr, null_check_info);
429 }
430 }
433 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
434 assert(x->is_pinned(),"");
435 LIRItem obj(x->obj(), this);
436 obj.load_item();
438 set_no_result(x);
440 // "lock" stores the address of the monitor stack slot, so this is not an oop
441 #ifdef _LP64
442 LIR_Opr lock = new_register(T_LONG);
443 #else
444 LIR_Opr lock = new_register(T_INT);
445 #endif
446 // Need a scratch register for biased locking on mips
447 LIR_Opr scratch = LIR_OprFact::illegalOpr;
448 if (UseBiasedLocking) {
449 scratch = new_register(T_INT);
450 }
452 CodeEmitInfo* info_for_exception = NULL;
453 if (x->needs_null_check()) {
454 info_for_exception = state_for(x);
455 }
456 // this CodeEmitInfo must not have the xhandlers because here the
457 // object is already locked (xhandlers expect object to be unlocked)
458 CodeEmitInfo* info = state_for(x, x->state(), true);
459 monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
460 x->monitor_no(), info_for_exception, info);
461 }
464 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
465 assert(x->is_pinned(),"");
467 LIRItem obj(x->obj(), this);
468 obj.dont_load_item();
470 LIR_Opr lock = new_register(T_INT);
471 LIR_Opr obj_temp = new_register(T_INT);
472 set_no_result(x);
473 monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
474 }
477 // _ineg, _lneg, _fneg, _dneg
478 void LIRGenerator::do_NegateOp(NegateOp* x) {
479 LIRItem value(x->x(), this);
480 value.set_destroys_register();
481 value.load_item();
482 LIR_Opr reg = rlock(x);
483 __ negate(value.result(), reg);
485 set_result(x, round_item(reg));
486 }
490 // for _fadd, _fmul, _fsub, _fdiv, _frem
491 // _dadd, _dmul, _dsub, _ddiv, _drem
492 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
493 switch (x->op()) {
494 case Bytecodes::_fadd:
495 case Bytecodes::_fmul:
496 case Bytecodes::_fsub:
497 case Bytecodes::_fdiv:
498 case Bytecodes::_dadd:
499 case Bytecodes::_dmul:
500 case Bytecodes::_dsub:
501 case Bytecodes::_ddiv: {
502 LIRItem left(x->x(), this);
503 LIRItem right(x->y(), this);
504 left.load_item();
505 right.load_item();
506 rlock_result(x);
507 arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp());
508 break;
509 }
510 case Bytecodes::_frem:
511 case Bytecodes::_drem: {
512 address entry;
513 switch (x->op()) {
514 case Bytecodes::_frem:
515 entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
516 break;
517 case Bytecodes::_drem:
518 entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
519 break;
520 default:
521 ShouldNotReachHere();
522 }
523 LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);
524 set_result(x, result);
525 break;
526 }
527 default:
528 ShouldNotReachHere();
529 }
530 }
535 // for _ladd, _lmul, _lsub, _ldiv, _lrem
536 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
537 switch (x->op()) {
538 case Bytecodes::_lrem:
539 case Bytecodes::_lmul:
540 case Bytecodes::_ldiv: {
542 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
543 LIRItem right(x->y(), this);
544 right.load_item();
546 CodeEmitInfo* info = state_for(x);
547 LIR_Opr item = right.result();
548 assert(item->is_register(), "must be");
549 __ branch(lir_cond_equal,item,LIR_OprFact::longConst(0), T_LONG, new DivByZeroStub(info));
550 }
552 address entry;
553 switch (x->op()) {
554 case Bytecodes::_lrem:
555 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
556 break; // check if dividend is 0 is done elsewhere
557 case Bytecodes::_ldiv:
558 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
559 break; // check if dividend is 0 is done elsewhere
560 case Bytecodes::_lmul:
561 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
562 break;
563 default:
564 ShouldNotReachHere();
565 }
567 // order of arguments to runtime call is reversed.
568 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
569 set_result(x, result);
570 break;
571 }
572 case Bytecodes::_ladd:
573 case Bytecodes::_lsub: {
574 LIRItem left(x->x(), this);
575 LIRItem right(x->y(), this);
576 left.load_item();
577 right.load_item();
578 rlock_result(x);
580 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
581 break;
582 }
583 default:
584 ShouldNotReachHere();
585 }
586 }
591 // for: _iadd, _imul, _isub, _idiv, _irem
592 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
593 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem;
594 LIRItem left(x->x(), this);
595 LIRItem right(x->y(), this);
596 // missing test if instr is commutative and if we should swap
597 right.load_nonconstant();
598 assert(right.is_constant() || right.is_register(), "wrong state of right");
599 left.load_item();
600 rlock_result(x);
601 if (is_div_rem) {
602 CodeEmitInfo* info = state_for(x);
603 LIR_Opr tmp =new_register(T_INT);
604 if (x->op() == Bytecodes::_irem) {
605 __ irem(left.result(), right.result(), x->operand(), tmp, info);
606 } else if (x->op() == Bytecodes::_idiv) {
607 __ idiv(left.result(), right.result(), x->operand(), tmp, info);
608 }
609 } else {
610 //arithmetic_op_int(x->op(), x->operand(), left.result(),
611 //right.result(), FrameMap::G1_opr);
613 LIR_Opr tmp =new_register(T_INT);
614 arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(),
615 tmp);
616 }
617 }
620 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
621 // when an operand with use count 1 is the left operand, then it is
622 // likely that no move for 2-operand-LIR-form is necessary
623 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
624 x->swap_operands();
625 }
627 ValueTag tag = x->type()->tag();
628 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
629 switch (tag) {
630 case floatTag:
631 case doubleTag: do_ArithmeticOp_FPU(x); return;
632 case longTag: do_ArithmeticOp_Long(x); return;
633 case intTag: do_ArithmeticOp_Int(x); return;
634 }
635 ShouldNotReachHere();
636 }
639 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
640 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
641 // count must always be in rcx
642 LIRItem value(x->x(), this);
643 LIRItem count(x->y(), this);
645 ValueTag elemType = x->type()->tag();
646 bool must_load_count = !count.is_constant() || elemType == longTag;
647 if (must_load_count) {
648 // count for long must be in register
649 count.load_item();
650 } else {
651 count.dont_load_item();
652 }
653 value.load_item();
654 LIR_Opr reg = rlock_result(x);
656 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
657 }
660 // _iand, _land, _ior, _lor, _ixor, _lxor
661 void LIRGenerator::do_LogicOp(LogicOp* x) {
662 // when an operand with use count 1 is the left operand, then it is
663 // likely that no move for 2-operand-LIR-form is necessary
664 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
665 x->swap_operands();
666 }
668 LIRItem left(x->x(), this);
669 LIRItem right(x->y(), this);
671 left.load_item();
672 right.load_nonconstant();
673 LIR_Opr reg = rlock_result(x);
675 logic_op(x->op(), reg, left.result(), right.result());
676 }
680 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
681 void LIRGenerator::do_CompareOp(CompareOp* x) {
682 LIRItem left(x->x(), this);
683 LIRItem right(x->y(), this);
684 ValueTag tag = x->x()->type()->tag();
685 if (tag == longTag) {
686 left.set_destroys_register();
687 }
688 left.load_item();
689 right.load_item();
690 LIR_Opr reg = rlock_result(x);
692 if (x->x()->type()->is_float_kind()) {
693 Bytecodes::Code code = x->op();
694 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
695 } else if (x->x()->type()->tag() == longTag) {
696 __ lcmp2int(left.result(), right.result(), reg);
697 } else {
698 Unimplemented();
699 }
700 }
702 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
703 assert(x->number_of_arguments() == 4, "wrong type");
704 LIRItem obj (x->argument_at(0), this); // object
705 LIRItem offset(x->argument_at(1), this); // offset of field
706 LIRItem cmp (x->argument_at(2), this); // value to compare with field
707 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp
709 assert(obj.type()->tag() == objectTag, "invalid type");
711 //In 64bit the type can be long, sparc doesn't have this assert
712 //assert(offset.type()->tag() == intTag, "invalid type");
714 assert(cmp.type()->tag() == type->tag(), "invalid type");
715 assert(val.type()->tag() == type->tag(), "invalid type");
717 // Use temps to avoid kills
718 LIR_Opr tmp1 = new_register(type);
719 LIR_Opr tmp2 = new_register(type);
720 LIR_Opr addr = new_pointer_register();
722 // get address of field
723 obj.load_item();
724 offset.load_item();
725 cmp.load_item();
726 val.load_item();
728 __ add(obj.result(), offset.result(), addr);
730 if (type == objectType) { // Write-barrier needed for Object fields.
731 pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,
732 true /* do_load */, false /* patch */, NULL);
733 }
735 if (type == objectType)
736 __ cas_obj(addr, cmp.result(), val.result(), tmp1, tmp2, FrameMap::_at_opr);
737 else if (type == intType)
738 __ cas_int(addr, cmp.result(), val.result(), tmp1, tmp2, FrameMap::_at_opr);
739 else if (type == longType)
740 __ cas_long(addr, cmp.result(), val.result(), tmp1, tmp2, FrameMap::_at_opr);
741 else {
742 ShouldNotReachHere();
743 }
745 LIR_Opr result = rlock_result(x);
746 __ move(FrameMap::_at_opr, result);
748 if (type == objectType) { // Write-barrier needed for Object fields.
749 // Precise card mark since could either be object or array
750 post_barrier(addr, val.result());
751 }
752 }
755 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
756 switch (x->id()) {
757 case vmIntrinsics::_dabs:
758 case vmIntrinsics::_dsqrt: {
759 assert(x->number_of_arguments() == 1, "wrong type");
760 LIRItem value(x->argument_at(0), this);
761 value.load_item();
762 LIR_Opr dst = rlock_result(x);
764 switch (x->id()) {
765 case vmIntrinsics::_dsqrt: {
766 __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
767 break;
768 }
769 case vmIntrinsics::_dabs: {
770 __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
771 break;
772 }
773 }
774 break;
775 }
776 case vmIntrinsics::_dlog10: // fall through
777 case vmIntrinsics::_dlog: // fall through
778 case vmIntrinsics::_dsin: // fall through
779 case vmIntrinsics::_dtan: // fall through
780 case vmIntrinsics::_dcos: {
781 assert(x->number_of_arguments() == 1, "wrong type");
783 address runtime_entry = NULL;
784 switch (x->id()) {
785 case vmIntrinsics::_dsin:
786 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
787 break;
788 case vmIntrinsics::_dcos:
789 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
790 break;
791 case vmIntrinsics::_dtan:
792 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
793 break;
794 case vmIntrinsics::_dlog:
795 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
796 break;
797 case vmIntrinsics::_dlog10:
798 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
799 break;
800 default:
801 ShouldNotReachHere();
802 }
803 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
804 set_result(x, result);
805 break;
806 }
807 case vmIntrinsics::_dexp: {
808 assert(x->number_of_arguments() == 1, "wrong type");
809 address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
810 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
811 set_result(x, result);
812 break;
813 }
814 case vmIntrinsics::_dpow: {
815 assert(x->number_of_arguments() == 2, "wrong type");
816 address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
817 LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);
818 set_result(x, result);
819 break;
820 }
821 }
822 }
824 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
825 assert(x->number_of_arguments() == 5, "wrong type");
826 // Note: spill caller save before setting the item
827 LIRItem src (x->argument_at(0), this);
828 LIRItem src_pos (x->argument_at(1), this);
829 LIRItem dst (x->argument_at(2), this);
830 LIRItem dst_pos (x->argument_at(3), this);
831 LIRItem length (x->argument_at(4), this);
832 // load all values in callee_save_registers, as this makes the
833 // parameter passing to the fast case simpler
834 src.load_item_force (FrameMap::_t0_oop_opr);
835 src_pos.load_item_force (FrameMap::_a0_opr);
836 dst.load_item_force (FrameMap::_a1_oop_opr);
837 dst_pos.load_item_force (FrameMap::_a2_opr);
838 length.load_item_force (FrameMap::_a3_opr);
840 int flags;
841 ciArrayKlass* expected_type;
842 arraycopy_helper(x, &flags, &expected_type);
844 CodeEmitInfo* info = state_for(x, x->state());
845 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), rlock_callee_saved(T_INT), expected_type, flags, info);
846 set_no_result(x);
847 }
849 void LIRGenerator::do_update_CRC32(Intrinsic* x) { // Fu: 20130832
850 Unimplemented();
851 }
853 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
854 // _i2b, _i2c, _i2s
855 LIR_Opr fixed_register_for(BasicType type) {
856 switch (type) {
857 case T_FLOAT: return FrameMap::_f0_float_opr;
858 case T_DOUBLE: return FrameMap::_d0_double_opr;
859 case T_INT: return FrameMap::_v0_opr;
860 case T_LONG: return FrameMap::_v0_v1_long_opr;
861 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
862 }
863 }
866 void LIRGenerator::do_Convert(Convert* x) {
867 // flags that vary for the different operations and different SSE-settings
868 bool fixed_input, fixed_result, round_result, needs_stub;
870 switch (x->op()) {
871 case Bytecodes::_i2l: // fall through
872 case Bytecodes::_l2i: // fall through
873 case Bytecodes::_i2b: // fall through
874 case Bytecodes::_i2c: // fall through
875 case Bytecodes::_i2s:
876 fixed_input = false;
877 fixed_result = false;
878 round_result = false;
879 needs_stub = false; break;
880 case Bytecodes::_f2d:
881 fixed_input = UseSSE == 1;
882 fixed_result = false;
883 round_result = false;
884 needs_stub = false; break;
885 case Bytecodes::_d2f:
886 fixed_input = false;
887 fixed_result = UseSSE == 1;
888 round_result = UseSSE < 1;
889 needs_stub = false; break;
890 case Bytecodes::_i2f:
891 fixed_input = false;
892 fixed_result = false;
893 round_result = UseSSE < 1;
894 needs_stub = false; break;
895 case Bytecodes::_i2d:
896 fixed_input = false;
897 fixed_result = false;
898 round_result = false;
899 needs_stub = false; break;
900 case Bytecodes::_f2i:
901 fixed_input = false;
902 fixed_result = false;
903 round_result = false;
904 needs_stub = true; break;
905 case Bytecodes::_d2i:
906 fixed_input = false;
907 fixed_result = false;
908 round_result = false;
909 needs_stub = true; break;
910 case Bytecodes::_l2f:
911 fixed_input = false;
912 fixed_result = UseSSE >= 1;
913 round_result = UseSSE < 1;
914 needs_stub = false; break;
915 case Bytecodes::_l2d:
916 fixed_input = false;
917 fixed_result = UseSSE >= 2;
918 round_result = UseSSE < 2;
919 needs_stub = false; break;
920 case Bytecodes::_f2l:
921 fixed_input = true;
922 fixed_result = true;
923 round_result = false;
924 needs_stub = false; break;
925 case Bytecodes::_d2l:
926 fixed_input = true;
927 fixed_result = true;
928 round_result = false;
929 needs_stub = false; break;
930 default:
931 ShouldNotReachHere();
932 }
934 LIRItem value(x->value(), this);
935 value.load_item();
936 LIR_Opr input = value.result();
937 LIR_Opr result = rlock(x);
939 // arguments of lir_convert
940 LIR_Opr conv_input = input;
941 LIR_Opr conv_result = result;
942 ConversionStub* stub = NULL;
944 if (fixed_input) {
945 conv_input = fixed_register_for(input->type());
946 __ move(input, conv_input);
947 }
949 assert(fixed_result == false || round_result == false, "cannot set both");
950 if (fixed_result) {
951 conv_result = fixed_register_for(result->type());
952 } else if (round_result) {
953 result = new_register(result->type());
954 set_vreg_flag(result, must_start_in_memory);
955 }
957 if (needs_stub) {
958 stub = new ConversionStub(x->op(), conv_input, conv_result);
959 }
961 __ convert(x->op(), conv_input, conv_result, stub);
963 if (result != conv_result) {
964 __ move(conv_result, result);
965 }
967 assert(result->is_virtual(), "result must be virtual register");
968 set_result(x, result);
969 }
971 void LIRGenerator::do_NewInstance(NewInstance* x) {
972 const LIR_Opr reg = result_register_for(x->type());
973 #ifndef PRODUCT
974 if (PrintNotLoaded && !x->klass()->is_loaded()) {
975 tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());
976 }
977 #endif
978 CodeEmitInfo* info = state_for(x, x->state());
979 // LIR_Opr tmp1 = new_register(T_INT);
980 // LIR_Opr tmp2 = new_register(T_INT);
981 // LIR_Opr tmp3 = new_register(T_INT);
982 // LIR_Opr tmp4 = new_register(T_INT);
983 #ifndef _LP64
984 LIR_Opr klass_reg = FrameMap::_t4_metadata_opr;
985 #else
986 LIR_Opr klass_reg = FrameMap::_a4_metadata_opr;
987 #endif
988 new_instance(reg,
989 x->klass(),
990 x->is_unresolved(),
991 FrameMap::_t0_oop_opr,
992 FrameMap::_t1_oop_opr,
993 FrameMap::_t2_oop_opr,
994 FrameMap::_t3_oop_opr,
995 #ifndef _LP64
996 FrameMap::_t5_oop_opr,
997 FrameMap::_t6_oop_opr,
998 #else
999 FrameMap::_a5_oop_opr,
1000 FrameMap::_a6_oop_opr,
1001 #endif
1002 klass_reg,
1003 info);
1004 LIR_Opr result = rlock_result(x);
1005 __ move(reg, result);
1006 }
1009 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
1010 CodeEmitInfo* info = state_for(x, x->state());
1012 LIRItem length(x->length(), this);
1013 length.load_item_force(FrameMap::_t2_opr);
1015 LIR_Opr reg = result_register_for(x->type());
1016 LIR_Opr tmp1 = FrameMap::_t0_oop_opr;
1017 LIR_Opr tmp2 = FrameMap::_t1_oop_opr;
1018 LIR_Opr tmp3 = FrameMap::_t3_oop_opr;
1019 #ifndef _LP64
1020 LIR_Opr tmp4 = FrameMap::_t5_oop_opr;
1021 LIR_Opr tmp5 = FrameMap::_t6_oop_opr;
1022 LIR_Opr klass_reg = FrameMap::_t4_oop_opr;
1023 #else
1024 LIR_Opr tmp4 = FrameMap::_a5_oop_opr;
1025 LIR_Opr tmp5 = FrameMap::_a6_oop_opr;
1026 LIR_Opr klass_reg = FrameMap::_a4_metadata_opr;
1027 #endif
1028 LIR_Opr len = length.result();
1029 BasicType elem_type = x->elt_type();
1031 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
1033 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
1034 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4,tmp5, elem_type, klass_reg, slow_path);
1036 LIR_Opr result = rlock_result(x);
1037 __ move(reg, result);
1038 }
1042 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
1043 LIRItem length(x->length(), this);
1044 // in case of patching (i.e., object class is not yet loaded), we
1045 // need to reexecute the instruction
1046 // and therefore provide the state before the parameters have been consumed
1047 CodeEmitInfo* patching_info = NULL;
1048 if (!x->klass()->is_loaded() || PatchALot) {
1049 patching_info = state_for(x, x->state_before());
1050 }
1052 CodeEmitInfo* info = state_for(x, x->state());
1054 const LIR_Opr reg = result_register_for(x->type());
1055 LIR_Opr tmp1 = FrameMap::_t0_oop_opr;
1056 LIR_Opr tmp2 = FrameMap::_t1_oop_opr;
1057 LIR_Opr tmp3 = FrameMap::_t3_oop_opr;
1058 #ifndef _LP64
1059 LIR_Opr tmp4 = FrameMap::_t5_oop_opr;
1060 LIR_Opr tmp5 = FrameMap::_t6_oop_opr;
1061 LIR_Opr klass_reg = FrameMap::_t4_oop_opr;
1062 #else
1063 LIR_Opr tmp4 = FrameMap::_a5_oop_opr;
1064 LIR_Opr tmp5 = FrameMap::_a6_oop_opr;
1065 LIR_Opr klass_reg = FrameMap::_a4_metadata_opr;
1066 #endif
1068 length.load_item_force(FrameMap::_t2_opr);
1069 LIR_Opr len = length.result();
1071 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
1072 ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
1073 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1074 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1075 }
1076 klass2reg_with_patching(klass_reg, obj, patching_info);
1077 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, tmp5, T_OBJECT, klass_reg, slow_path);
1079 LIR_Opr result = rlock_result(x);
1080 __ move(reg, result);
1081 }
1084 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1085 Values* dims = x->dims();
1086 int i = dims->length();
1087 LIRItemList* items = new LIRItemList(dims->length(), NULL);
1088 while (i-- > 0) {
1089 LIRItem* size = new LIRItem(dims->at(i), this);
1090 items->at_put(i, size);
1091 }
1093 // need to get the info before, as the items may become invalid through item_free
1094 CodeEmitInfo* patching_info = NULL;
1095 if (!x->klass()->is_loaded() || PatchALot) {
1096 patching_info = state_for(x, x->state_before());
1097 // cannot re-use same xhandlers for multiple CodeEmitInfos, so
1098 // clone all handlers.
1099 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
1100 }
1102 CodeEmitInfo* info = state_for(x, x->state());
1104 i = dims->length();
1105 while (i-- > 0) {
1106 LIRItem* size = items->at(i);
1107 size->load_nonconstant();
1108 store_stack_parameter(size->result(), in_ByteSize(i*4));
1109 }
1111 LIR_Opr klass_reg = FrameMap::_v0_metadata_opr;
1112 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
1114 // LIR_Opr rank = FrameMap::ebx_opr;
1115 LIR_Opr rank = FrameMap::_t2_opr;
1116 __ move(LIR_OprFact::intConst(x->rank()), rank);
1117 // LIR_Opr varargs = FrameMap::ecx_opr;
1118 LIR_Opr varargs = FrameMap::_t0_opr;
1119 __ move(FrameMap::_sp_opr, varargs);
1120 LIR_OprList* args = new LIR_OprList(3);
1121 args->append(klass_reg);
1122 args->append(rank);
1123 args->append(varargs);
1124 LIR_Opr reg = result_register_for(x->type());
1125 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
1126 LIR_OprFact::illegalOpr,
1127 reg, args, info);
1129 LIR_Opr result = rlock_result(x);
1130 __ move(reg, result);
1131 }
1133 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
1134 // nothing to do for now
1135 }
1138 void LIRGenerator::do_CheckCast(CheckCast* x) {
1139 LIRItem obj(x->obj(), this);
1141 CodeEmitInfo* patching_info = NULL;
1142 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
1143 // must do this before locking the destination register as an oop register,
1144 // and before the obj is loaded (the latter is for deoptimization)
1145 patching_info = state_for(x, x->state_before());
1146 }
1147 obj.load_item();
1149 // info for exceptions
1150 CodeEmitInfo* info_for_exception = state_for(x);
1152 CodeStub* stub;
1153 if (x->is_incompatible_class_change_check()) {
1154 assert(patching_info == NULL, "can't patch this");
1155 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
1156 } else {
1157 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
1158 }
1159 LIR_Opr reg = rlock_result(x);
1160 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1161 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1162 tmp3 = new_register(objectType);
1163 }
1164 __ checkcast(reg, obj.result(), x->klass(),
1165 new_register(objectType), new_register(objectType), tmp3,
1166 x->direct_compare(), info_for_exception, patching_info, stub,
1167 x->profiled_method(), x->profiled_bci());
1168 }
1171 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1172 LIRItem obj(x->obj(), this);
1174 // result and test object may not be in same register
1175 LIR_Opr reg = rlock_result(x);
1176 CodeEmitInfo* patching_info = NULL;
1177 if ((!x->klass()->is_loaded() || PatchALot)) {
1178 // must do this before locking the destination register as an oop register
1179 patching_info = state_for(x, x->state_before());
1180 }
1181 obj.load_item();
1182 LIR_Opr tmp = new_register(objectType);
1183 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1184 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1185 tmp3 = new_register(objectType);
1186 }
1188 __ instanceof(reg, obj.result(), x->klass(),
1189 tmp, new_register(objectType), tmp3,
1190 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
1191 }
1194 void LIRGenerator::do_If(If* x) {
1195 assert(x->number_of_sux() == 2, "inconsistency");
1196 ValueTag tag = x->x()->type()->tag();
1197 bool is_safepoint = x->is_safepoint();
1199 If::Condition cond = x->cond();
1201 LIRItem xitem(x->x(), this);
1202 LIRItem yitem(x->y(), this);
1203 LIRItem* xin = &xitem;
1204 LIRItem* yin = &yitem;
1206 if (tag == longTag) {
1207 // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
1208 // mirror for other conditions
1209 if (cond == If::gtr || cond == If::leq) {
1210 cond = Instruction::mirror(cond);
1211 xin = &yitem;
1212 yin = &xitem;
1213 }
1214 xin->set_destroys_register();
1215 }
1216 xin->load_item();
1217 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
1218 // inline long zero
1219 yin->dont_load_item();
1220 } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
1221 // longs cannot handle constants at right side
1222 yin->load_item();
1223 } else {
1224 yin->dont_load_item();
1225 }
1227 // add safepoint before generating condition code so it can be recomputed
1228 if (x->is_safepoint()) {
1229 // increment backedge counter if needed
1230 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
1231 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
1232 }
1233 set_no_result(x);
1235 LIR_Opr left = xin->result();
1236 LIR_Opr right = yin->result();
1237 profile_branch(x, cond, left, right);
1238 move_to_phi(x->state());
1239 if (x->x()->type()->is_float_kind()) {
1240 __ branch(lir_cond(cond), left, right, right->type(), x->tsux(), x->usux());
1241 } else {
1242 __ branch(lir_cond(cond), left, right, right->type(), x->tsux());
1243 }
1244 assert(x->default_sux() == x->fsux(), "wrong destination above");
1245 __ jump(x->default_sux());
1246 }
1249 LIR_Opr LIRGenerator::getThreadPointer() {
1250 #ifdef _LP64
1251 //FIXME, does as_pointer need to be implemented? or 64bit can use one register.
1252 //return FrameMap::as_pointer_opr(r15_thread);
1253 LIR_Opr result = new_register(T_LONG);
1254 __ get_thread(result);
1255 return result;
1256 #else
1257 LIR_Opr result = new_register(T_INT);
1258 __ get_thread(result);
1259 return result;
1260 #endif //
1261 }
1263 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1264 store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
1265 LIR_OprList* args = new LIR_OprList();
1266 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
1267 __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
1268 }
1271 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
1272 CodeEmitInfo* info) {
1273 if (address->type() == T_LONG) {
1274 __ volatile_store_mem_reg(value, address, info);
1275 } else {
1276 __ store(value, address, info);
1277 }
1278 }
1280 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
1281 CodeEmitInfo* info) {
1283 if (address->type() == T_LONG) {
1284 __ volatile_load_mem_reg(address, result, info);
1285 } else {
1286 __ load(address, result, info);
1287 }
1288 }
1290 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
1291 BasicType type, bool is_volatile) {
1292 __ add(src, offset, FrameMap::_at_opr);
1293 if (is_volatile && type == T_LONG) {
1294 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE);
1295 LIR_Opr tmp = new_register(T_DOUBLE);
1296 __ load(addr, tmp);
1297 LIR_Opr spill = new_register(T_LONG);
1298 set_vreg_flag(spill, must_start_in_memory);
1299 __ move(tmp, spill);
1300 __ move(spill, dst);
1301 } else {
1302 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type);
1303 __ load(addr, dst);
1304 }
1305 }
1308 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
1309 BasicType type, bool is_volatile) {
1310 __ add(src, offset, FrameMap::_at_opr);
1311 if (is_volatile && type == T_LONG) {
1312 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE);
1313 LIR_Opr tmp = new_register(T_DOUBLE);
1314 LIR_Opr spill = new_register(T_DOUBLE);
1315 set_vreg_flag(spill, must_start_in_memory);
1316 __ move(data, spill);
1317 __ move(spill, tmp);
1318 __ move(tmp, addr);
1319 } else {
1320 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type);
1321 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
1322 if (is_obj) {
1323 // Do the pre-write barrier, if any.
1324 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr/* pre_val */,
1325 true/* do_load */,false /*patch*/, NULL);
1326 __ move(data, addr);
1327 assert(src->is_register(), "must be register");
1328 // Seems to be a precise address
1329 post_barrier(LIR_OprFact::address(addr), data);
1330 } else {
1331 __ move(data, addr);
1332 }
1333 }
1334 }
1336 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
1337 BasicType type = x->basic_type();
1338 LIRItem src(x->object(), this);
1339 LIRItem off(x->offset(), this);
1340 LIRItem value(x->value(), this);
1342 src.load_item();
1343 value.load_item();
1344 off.load_nonconstant();
1346 LIR_Opr dst = rlock_result(x, type);
1347 LIR_Opr data = value.result();
1348 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
1349 LIR_Opr offset = off.result();
1351 assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");
1352 LIR_Address* addr;
1353 if (offset->is_constant()) {
1354 #ifdef _LP64
1355 jlong c = offset->as_jlong();
1356 if ((jlong)((jint)c) == c) {
1357 addr = new LIR_Address(src.result(), (jint)c, type);
1358 } else {
1359 LIR_Opr tmp = new_register(T_LONG);
1360 __ move(offset, tmp);
1361 addr = new LIR_Address(src.result(), tmp, type);
1362 }
1363 #else
1364 addr = new LIR_Address(src.result(), offset->as_jint(), type);
1365 #endif
1366 } else {
1367 addr = new LIR_Address(src.result(), offset, type);
1368 }
1370 if (data != dst) {
1371 __ move(data, dst);
1372 data = dst;
1373 }
1374 if (x->is_add()) {
1375 __ xadd(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr);
1376 } else {
1377 if (is_obj) {
1378 // Do the pre-write barrier, if any.
1379 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
1380 true /* do_load */, false /* patch */, NULL);
1381 }
1382 __ xchg(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr);
1383 if (is_obj) {
1384 // Seems to be a precise address
1385 post_barrier(LIR_OprFact::address(addr), data);
1386 }
1387 }
1388 }