annotate src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp @ 49862:d3a8aa01f26f

8071282: remove misc dead code Summary: cleanup of dead code done Reviewed-by: kvn, thartmann
author rraghavan
date Wed, 14 Mar 2018 09:09:38 -0700
parents 0ce0ac68ace7
children 4bb58f644e4e
rev   line source
duke@1 1 /*
rraghavan@49862 2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@7397 26 #include "c1/c1_Compilation.hpp"
stefank@7397 27 #include "c1/c1_FrameMap.hpp"
stefank@7397 28 #include "c1/c1_Instruction.hpp"
stefank@7397 29 #include "c1/c1_LIRAssembler.hpp"
stefank@7397 30 #include "c1/c1_LIRGenerator.hpp"
stefank@7397 31 #include "c1/c1_Runtime1.hpp"
stefank@7397 32 #include "c1/c1_ValueStack.hpp"
stefank@7397 33 #include "ci/ciArray.hpp"
stefank@7397 34 #include "ci/ciObjArrayKlass.hpp"
stefank@7397 35 #include "ci/ciTypeArrayKlass.hpp"
rehn@48069 36 #include "runtime/safepointMechanism.hpp"
stefank@7397 37 #include "runtime/sharedRuntime.hpp"
stefank@7397 38 #include "runtime/stubRoutines.hpp"
stefank@7397 39 #include "vmreg_sparc.inline.hpp"
duke@1 40
duke@1 41 #ifdef ASSERT
duke@1 42 #define __ gen()->lir(__FILE__, __LINE__)->
duke@1 43 #else
duke@1 44 #define __ gen()->lir()->
duke@1 45 #endif
duke@1 46
duke@1 47 void LIRItem::load_byte_item() {
duke@1 48 // byte loads use same registers as other loads
duke@1 49 load_item();
duke@1 50 }
duke@1 51
duke@1 52
duke@1 53 void LIRItem::load_nonconstant() {
duke@1 54 LIR_Opr r = value()->operand();
duke@1 55 if (_gen->can_inline_as_constant(value())) {
duke@1 56 if (!r->is_constant()) {
duke@1 57 r = LIR_OprFact::value_type(value()->type());
duke@1 58 }
duke@1 59 _result = r;
duke@1 60 } else {
duke@1 61 load_item();
duke@1 62 }
duke@1 63 }
duke@1 64
duke@1 65
duke@1 66 //--------------------------------------------------------------
duke@1 67 // LIRGenerator
duke@1 68 //--------------------------------------------------------------
duke@1 69
duke@1 70 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::Oexception_opr; }
duke@1 71 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::Oissuing_pc_opr; }
mdoerr@34201 72 LIR_Opr LIRGenerator::syncLockOpr() { return new_register(T_INT); }
duke@1 73 LIR_Opr LIRGenerator::syncTempOpr() { return new_register(T_OBJECT); }
gtriantafill@46381 74 LIR_Opr LIRGenerator::getThreadTemp() { return rlock_callee_saved(T_LONG); }
duke@1 75
duke@1 76 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
duke@1 77 LIR_Opr opr;
duke@1 78 switch (type->tag()) {
duke@1 79 case intTag: opr = callee ? FrameMap::I0_opr : FrameMap::O0_opr; break;
duke@1 80 case objectTag: opr = callee ? FrameMap::I0_oop_opr : FrameMap::O0_oop_opr; break;
duke@1 81 case longTag: opr = callee ? FrameMap::in_long_opr : FrameMap::out_long_opr; break;
duke@1 82 case floatTag: opr = FrameMap::F0_opr; break;
duke@1 83 case doubleTag: opr = FrameMap::F0_double_opr; break;
duke@1 84
duke@1 85 case addressTag:
duke@1 86 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
duke@1 87 }
duke@1 88
duke@1 89 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
duke@1 90 return opr;
duke@1 91 }
duke@1 92
duke@1 93 LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) {
duke@1 94 LIR_Opr reg = new_register(type);
duke@1 95 set_vreg_flag(reg, callee_saved);
duke@1 96 return reg;
duke@1 97 }
duke@1 98
duke@1 99
duke@1 100 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
duke@1 101 return new_register(T_INT);
duke@1 102 }
duke@1 103
duke@1 104
duke@1 105
duke@1 106
duke@1 107
duke@1 108 //--------- loading items into registers --------------------------------
duke@1 109
duke@1 110 // SPARC cannot inline all constants
duke@1 111 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
duke@1 112 if (v->type()->as_IntConstant() != NULL) {
duke@1 113 return v->type()->as_IntConstant()->value() == 0;
duke@1 114 } else if (v->type()->as_LongConstant() != NULL) {
duke@1 115 return v->type()->as_LongConstant()->value() == 0L;
duke@1 116 } else if (v->type()->as_ObjectConstant() != NULL) {
duke@1 117 return v->type()->as_ObjectConstant()->value()->is_null_object();
duke@1 118 } else {
duke@1 119 return false;
duke@1 120 }
duke@1 121 }
duke@1 122
duke@1 123
duke@1 124 // only simm13 constants can be inlined
duke@1 125 bool LIRGenerator:: can_inline_as_constant(Value i) const {
duke@1 126 if (i->type()->as_IntConstant() != NULL) {
duke@1 127 return Assembler::is_simm13(i->type()->as_IntConstant()->value());
duke@1 128 } else {
duke@1 129 return can_store_as_constant(i, as_BasicType(i->type()));
duke@1 130 }
duke@1 131 }
duke@1 132
duke@1 133
duke@1 134 bool LIRGenerator:: can_inline_as_constant(LIR_Const* c) const {
duke@1 135 if (c->type() == T_INT) {
duke@1 136 return Assembler::is_simm13(c->as_jint());
duke@1 137 }
duke@1 138 return false;
duke@1 139 }
duke@1 140
duke@1 141
duke@1 142 LIR_Opr LIRGenerator::safepoint_poll_register() {
duke@1 143 return new_register(T_INT);
duke@1 144 }
duke@1 145
duke@1 146
duke@1 147
duke@1 148 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
duke@1 149 int shift, int disp, BasicType type) {
duke@1 150 assert(base->is_register(), "must be");
mdoerr@41337 151 intx large_disp = disp;
duke@1 152
duke@1 153 // accumulate fixed displacements
duke@1 154 if (index->is_constant()) {
mdoerr@41337 155 large_disp += (intx)(index->as_constant_ptr()->as_jint()) << shift;
duke@1 156 index = LIR_OprFact::illegalOpr;
duke@1 157 }
duke@1 158
duke@1 159 if (index->is_register()) {
duke@1 160 // apply the shift and accumulate the displacement
duke@1 161 if (shift > 0) {
roland@4430 162 LIR_Opr tmp = new_pointer_register();
duke@1 163 __ shift_left(index, shift, tmp);
duke@1 164 index = tmp;
duke@1 165 }
mdoerr@41337 166 if (large_disp != 0) {
roland@4430 167 LIR_Opr tmp = new_pointer_register();
mdoerr@41337 168 if (Assembler::is_simm13(large_disp)) {
mdoerr@41337 169 __ add(tmp, LIR_OprFact::intptrConst(large_disp), tmp);
duke@1 170 index = tmp;
duke@1 171 } else {
mdoerr@41337 172 __ move(LIR_OprFact::intptrConst(large_disp), tmp);
duke@1 173 __ add(tmp, index, tmp);
duke@1 174 index = tmp;
duke@1 175 }
mdoerr@41337 176 large_disp = 0;
duke@1 177 }
mdoerr@41337 178 } else if (large_disp != 0 && !Assembler::is_simm13(large_disp)) {
duke@1 179 // index is illegal so replace it with the displacement loaded into a register
roland@4430 180 index = new_pointer_register();
mdoerr@41337 181 __ move(LIR_OprFact::intptrConst(large_disp), index);
mdoerr@41337 182 large_disp = 0;
duke@1 183 }
duke@1 184
duke@1 185 // at this point we either have base + index or base + displacement
mdoerr@41337 186 if (large_disp == 0) {
duke@1 187 return new LIR_Address(base, index, type);
duke@1 188 } else {
mdoerr@41337 189 assert(Assembler::is_simm13(large_disp), "must be");
mdoerr@41337 190 return new LIR_Address(base, large_disp, type);
duke@1 191 }
duke@1 192 }
duke@1 193
duke@1 194
duke@1 195 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
duke@1 196 BasicType type, bool needs_card_mark) {
kvn@202 197 int elem_size = type2aelembytes(type);
duke@1 198 int shift = exact_log2(elem_size);
duke@1 199
duke@1 200 LIR_Opr base_opr;
mdoerr@41337 201 intx offset = arrayOopDesc::base_offset_in_bytes(type);
duke@1 202
duke@1 203 if (index_opr->is_constant()) {
mdoerr@41337 204 intx i = index_opr->as_constant_ptr()->as_jint();
mdoerr@41337 205 intx array_offset = i * elem_size;
duke@1 206 if (Assembler::is_simm13(array_offset + offset)) {
duke@1 207 base_opr = array_opr;
duke@1 208 offset = array_offset + offset;
duke@1 209 } else {
duke@1 210 base_opr = new_pointer_register();
duke@1 211 if (Assembler::is_simm13(array_offset)) {
duke@1 212 __ add(array_opr, LIR_OprFact::intptrConst(array_offset), base_opr);
duke@1 213 } else {
duke@1 214 __ move(LIR_OprFact::intptrConst(array_offset), base_opr);
duke@1 215 __ add(base_opr, array_opr, base_opr);
duke@1 216 }
duke@1 217 }
duke@1 218 } else {
duke@1 219 if (index_opr->type() == T_INT) {
duke@1 220 LIR_Opr tmp = new_register(T_LONG);
duke@1 221 __ convert(Bytecodes::_i2l, index_opr, tmp);
duke@1 222 index_opr = tmp;
duke@1 223 }
duke@1 224
duke@1 225 base_opr = new_pointer_register();
duke@1 226 assert (index_opr->is_register(), "Must be register");
duke@1 227 if (shift > 0) {
duke@1 228 __ shift_left(index_opr, shift, base_opr);
duke@1 229 __ add(base_opr, array_opr, base_opr);
duke@1 230 } else {
duke@1 231 __ add(index_opr, array_opr, base_opr);
duke@1 232 }
duke@1 233 }
duke@1 234 if (needs_card_mark) {
duke@1 235 LIR_Opr ptr = new_pointer_register();
duke@1 236 __ add(base_opr, LIR_OprFact::intptrConst(offset), ptr);
iveresov@5695 237 return new LIR_Address(ptr, type);
duke@1 238 } else {
duke@1 239 return new LIR_Address(base_opr, offset, type);
duke@1 240 }
duke@1 241 }
duke@1 242
iveresov@6453 243 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
iveresov@6453 244 LIR_Opr r;
iveresov@6453 245 if (type == T_LONG) {
iveresov@6453 246 r = LIR_OprFact::longConst(x);
iveresov@6453 247 } else if (type == T_INT) {
iveresov@6453 248 r = LIR_OprFact::intConst(x);
iveresov@6453 249 } else {
iveresov@6453 250 ShouldNotReachHere();
iveresov@6453 251 }
iveresov@6453 252 if (!Assembler::is_simm13(x)) {
iveresov@6453 253 LIR_Opr tmp = new_register(type);
iveresov@6453 254 __ move(r, tmp);
iveresov@6453 255 return tmp;
iveresov@6453 256 }
iveresov@6453 257 return r;
iveresov@6453 258 }
duke@1 259
iveresov@6453 260 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
duke@1 261 LIR_Opr pointer = new_pointer_register();
duke@1 262 __ move(LIR_OprFact::intptrConst(counter), pointer);
iveresov@6453 263 LIR_Address* addr = new LIR_Address(pointer, type);
duke@1 264 increment_counter(addr, step);
duke@1 265 }
duke@1 266
duke@1 267 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
iveresov@6453 268 LIR_Opr temp = new_register(addr->type());
duke@1 269 __ move(addr, temp);
iveresov@6453 270 __ add(temp, load_immediate(step, addr->type()), temp);
duke@1 271 __ move(temp, addr);
duke@1 272 }
duke@1 273
duke@1 274 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
duke@1 275 LIR_Opr o7opr = FrameMap::O7_opr;
duke@1 276 __ load(new LIR_Address(base, disp, T_INT), o7opr, info);
duke@1 277 __ cmp(condition, o7opr, c);
duke@1 278 }
duke@1 279
duke@1 280
duke@1 281 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
duke@1 282 LIR_Opr o7opr = FrameMap::O7_opr;
duke@1 283 __ load(new LIR_Address(base, disp, type), o7opr, info);
duke@1 284 __ cmp(condition, reg, o7opr);
duke@1 285 }
duke@1 286
duke@1 287
duke@1 288 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
duke@1 289 assert(left != result, "should be different registers");
duke@1 290 if (is_power_of_2(c + 1)) {
duke@1 291 __ shift_left(left, log2_intptr(c + 1), result);
duke@1 292 __ sub(result, left, result);
duke@1 293 return true;
duke@1 294 } else if (is_power_of_2(c - 1)) {
duke@1 295 __ shift_left(left, log2_intptr(c - 1), result);
duke@1 296 __ add(result, left, result);
duke@1 297 return true;
duke@1 298 }
duke@1 299 return false;
duke@1 300 }
duke@1 301
duke@1 302
duke@1 303 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
duke@1 304 BasicType t = item->type();
duke@1 305 LIR_Opr sp_opr = FrameMap::SP_opr;
duke@1 306 if ((t == T_LONG || t == T_DOUBLE) &&
duke@1 307 ((in_bytes(offset_from_sp) - STACK_BIAS) % 8 != 0)) {
duke@1 308 __ unaligned_move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t));
duke@1 309 } else {
duke@1 310 __ move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t));
duke@1 311 }
duke@1 312 }
duke@1 313
duke@1 314 //----------------------------------------------------------------------
duke@1 315 // visitor functions
duke@1 316 //----------------------------------------------------------------------
duke@1 317
duke@1 318
duke@1 319 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
roland@6745 320 assert(x->is_pinned(),"");
roland@16611 321 bool needs_range_check = x->compute_needs_range_check();
duke@1 322 bool use_length = x->length() != NULL;
duke@1 323 bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
duke@1 324 bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
iveresov@10562 325 !get_jobject_constant(x->value())->is_null_object() ||
iveresov@10562 326 x->should_profile());
duke@1 327
duke@1 328 LIRItem array(x->array(), this);
duke@1 329 LIRItem index(x->index(), this);
duke@1 330 LIRItem value(x->value(), this);
duke@1 331 LIRItem length(this);
duke@1 332
duke@1 333 array.load_item();
duke@1 334 index.load_nonconstant();
duke@1 335
roland@16611 336 if (use_length && needs_range_check) {
roland@16611 337 length.set_instruction(x->length());
roland@16611 338 length.load_item();
duke@1 339 }
coleenp@37480 340 if (needs_store_check || x->check_boolean()) {
duke@1 341 value.load_item();
duke@1 342 } else {
duke@1 343 value.load_for_store(x->elt_type());
duke@1 344 }
duke@1 345
duke@1 346 set_no_result(x);
duke@1 347
duke@1 348 // the CodeEmitInfo must be duplicated for each different
duke@1 349 // LIR-instruction because spilling can occur anywhere between two
duke@1 350 // instructions and so the debug information must be different
duke@1 351 CodeEmitInfo* range_check_info = state_for(x);
duke@1 352 CodeEmitInfo* null_check_info = NULL;
duke@1 353 if (x->needs_null_check()) {
duke@1 354 null_check_info = new CodeEmitInfo(range_check_info);
duke@1 355 }
duke@1 356
duke@1 357 // emit array address setup early so it schedules better
duke@1 358 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);
duke@1 359
duke@1 360 if (GenerateRangeChecks && needs_range_check) {
duke@1 361 if (use_length) {
duke@1 362 __ cmp(lir_cond_belowEqual, length.result(), index.result());
duke@1 363 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
duke@1 364 } else {
duke@1 365 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
duke@1 366 // range_check also does the null check
duke@1 367 null_check_info = NULL;
duke@1 368 }
duke@1 369 }
duke@1 370
duke@1 371 if (GenerateArrayStoreCheck && needs_store_check) {
duke@1 372 LIR_Opr tmp1 = FrameMap::G1_opr;
duke@1 373 LIR_Opr tmp2 = FrameMap::G3_opr;
duke@1 374 LIR_Opr tmp3 = FrameMap::G5_opr;
duke@1 375
duke@1 376 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
iveresov@10562 377 __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
duke@1 378 }
duke@1 379
ysr@1374 380 if (obj_store) {
ysr@1374 381 // Needs GC write barriers.
johnc@9176 382 pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,
johnc@9176 383 true /* do_load */, false /* patch */, NULL);
ysr@1374 384 }
coleenp@37480 385 LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);
coleenp@37480 386 __ move(result, array_addr, null_check_info);
duke@1 387 if (obj_store) {
never@3172 388 // Precise card mark
duke@1 389 post_barrier(LIR_OprFact::address(array_addr), value.result());
duke@1 390 }
duke@1 391 }
duke@1 392
duke@1 393
duke@1 394 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
roland@6745 395 assert(x->is_pinned(),"");
duke@1 396 LIRItem obj(x->obj(), this);
duke@1 397 obj.load_item();
duke@1 398
duke@1 399 set_no_result(x);
duke@1 400
duke@1 401 LIR_Opr lock = FrameMap::G1_opr;
duke@1 402 LIR_Opr scratch = FrameMap::G3_opr;
duke@1 403 LIR_Opr hdr = FrameMap::G4_opr;
duke@1 404
duke@1 405 CodeEmitInfo* info_for_exception = NULL;
duke@1 406 if (x->needs_null_check()) {
roland@6745 407 info_for_exception = state_for(x);
duke@1 408 }
duke@1 409
duke@1 410 // this CodeEmitInfo must not have the xhandlers because here the
duke@1 411 // object is already locked (xhandlers expects object to be unlocked)
duke@1 412 CodeEmitInfo* info = state_for(x, x->state(), true);
duke@1 413 monitor_enter(obj.result(), lock, hdr, scratch, x->monitor_no(), info_for_exception, info);
duke@1 414 }
duke@1 415
duke@1 416
duke@1 417 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
roland@6745 418 assert(x->is_pinned(),"");
duke@1 419 LIRItem obj(x->obj(), this);
duke@1 420 obj.dont_load_item();
duke@1 421
duke@1 422 set_no_result(x);
duke@1 423 LIR_Opr lock = FrameMap::G1_opr;
duke@1 424 LIR_Opr hdr = FrameMap::G3_opr;
duke@1 425 LIR_Opr obj_temp = FrameMap::G4_opr;
bobv@6176 426 monitor_exit(obj_temp, lock, hdr, LIR_OprFact::illegalOpr, x->monitor_no());
duke@1 427 }
duke@1 428
duke@1 429
duke@1 430 // _ineg, _lneg, _fneg, _dneg
duke@1 431 void LIRGenerator::do_NegateOp(NegateOp* x) {
duke@1 432 LIRItem value(x->x(), this);
duke@1 433 value.load_item();
duke@1 434 LIR_Opr reg = rlock_result(x);
duke@1 435 __ negate(value.result(), reg);
duke@1 436 }
duke@1 437
duke@1 438
duke@1 439
duke@1 440 // for _fadd, _fmul, _fsub, _fdiv, _frem
duke@1 441 // _dadd, _dmul, _dsub, _ddiv, _drem
duke@1 442 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
duke@1 443 switch (x->op()) {
duke@1 444 case Bytecodes::_fadd:
duke@1 445 case Bytecodes::_fmul:
duke@1 446 case Bytecodes::_fsub:
duke@1 447 case Bytecodes::_fdiv:
duke@1 448 case Bytecodes::_dadd:
duke@1 449 case Bytecodes::_dmul:
duke@1 450 case Bytecodes::_dsub:
duke@1 451 case Bytecodes::_ddiv: {
duke@1 452 LIRItem left(x->x(), this);
duke@1 453 LIRItem right(x->y(), this);
duke@1 454 left.load_item();
duke@1 455 right.load_item();
duke@1 456 rlock_result(x);
duke@1 457 arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp());
duke@1 458 }
duke@1 459 break;
duke@1 460
duke@1 461 case Bytecodes::_frem:
duke@1 462 case Bytecodes::_drem: {
duke@1 463 address entry;
duke@1 464 switch (x->op()) {
duke@1 465 case Bytecodes::_frem:
duke@1 466 entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
duke@1 467 break;
duke@1 468 case Bytecodes::_drem:
duke@1 469 entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
duke@1 470 break;
duke@1 471 default:
duke@1 472 ShouldNotReachHere();
duke@1 473 }
duke@1 474 LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);
duke@1 475 set_result(x, result);
duke@1 476 }
duke@1 477 break;
duke@1 478
duke@1 479 default: ShouldNotReachHere();
duke@1 480 }
duke@1 481 }
duke@1 482
duke@1 483
duke@1 484 // for _ladd, _lmul, _lsub, _ldiv, _lrem
duke@1 485 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
duke@1 486 switch (x->op()) {
duke@1 487 case Bytecodes::_lrem:
duke@1 488 case Bytecodes::_lmul:
duke@1 489 case Bytecodes::_ldiv: {
duke@1 490
duke@1 491 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
duke@1 492 LIRItem right(x->y(), this);
duke@1 493 right.load_item();
duke@1 494
duke@1 495 CodeEmitInfo* info = state_for(x);
duke@1 496 LIR_Opr item = right.result();
duke@1 497 assert(item->is_register(), "must be");
duke@1 498 __ cmp(lir_cond_equal, item, LIR_OprFact::longConst(0));
duke@1 499 __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
duke@1 500 }
duke@1 501
duke@1 502 address entry;
duke@1 503 switch (x->op()) {
duke@1 504 case Bytecodes::_lrem:
duke@1 505 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
duke@1 506 break; // check if dividend is 0 is done elsewhere
duke@1 507 case Bytecodes::_ldiv:
duke@1 508 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
duke@1 509 break; // check if dividend is 0 is done elsewhere
duke@1 510 case Bytecodes::_lmul:
duke@1 511 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
duke@1 512 break;
duke@1 513 default:
duke@1 514 ShouldNotReachHere();
duke@1 515 }
duke@1 516
duke@1 517 // order of arguments to runtime call is reversed.
duke@1 518 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
duke@1 519 set_result(x, result);
duke@1 520 break;
duke@1 521 }
duke@1 522 case Bytecodes::_ladd:
duke@1 523 case Bytecodes::_lsub: {
duke@1 524 LIRItem left(x->x(), this);
duke@1 525 LIRItem right(x->y(), this);
duke@1 526 left.load_item();
duke@1 527 right.load_item();
duke@1 528 rlock_result(x);
duke@1 529
duke@1 530 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
duke@1 531 break;
duke@1 532 }
duke@1 533 default: ShouldNotReachHere();
duke@1 534 }
duke@1 535 }
duke@1 536
duke@1 537
duke@1 538 // Returns if item is an int constant that can be represented by a simm13
duke@1 539 static bool is_simm13(LIR_Opr item) {
duke@1 540 if (item->is_constant() && item->type() == T_INT) {
duke@1 541 return Assembler::is_simm13(item->as_constant_ptr()->as_jint());
duke@1 542 } else {
duke@1 543 return false;
duke@1 544 }
duke@1 545 }
duke@1 546
duke@1 547
duke@1 548 // for: _iadd, _imul, _isub, _idiv, _irem
duke@1 549 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
duke@1 550 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem;
duke@1 551 LIRItem left(x->x(), this);
duke@1 552 LIRItem right(x->y(), this);
duke@1 553 // missing test if instr is commutative and if we should swap
duke@1 554 right.load_nonconstant();
duke@1 555 assert(right.is_constant() || right.is_register(), "wrong state of right");
duke@1 556 left.load_item();
duke@1 557 rlock_result(x);
duke@1 558 if (is_div_rem) {
duke@1 559 CodeEmitInfo* info = state_for(x);
duke@1 560 LIR_Opr tmp = FrameMap::G1_opr;
duke@1 561 if (x->op() == Bytecodes::_irem) {
duke@1 562 __ irem(left.result(), right.result(), x->operand(), tmp, info);
duke@1 563 } else if (x->op() == Bytecodes::_idiv) {
duke@1 564 __ idiv(left.result(), right.result(), x->operand(), tmp, info);
duke@1 565 }
duke@1 566 } else {
duke@1 567 arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(), FrameMap::G1_opr);
duke@1 568 }
duke@1 569 }
duke@1 570
duke@1 571
duke@1 572 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
duke@1 573 ValueTag tag = x->type()->tag();
duke@1 574 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
duke@1 575 switch (tag) {
duke@1 576 case floatTag:
duke@1 577 case doubleTag: do_ArithmeticOp_FPU(x); return;
duke@1 578 case longTag: do_ArithmeticOp_Long(x); return;
duke@1 579 case intTag: do_ArithmeticOp_Int(x); return;
duke@1 580 }
duke@1 581 ShouldNotReachHere();
duke@1 582 }
duke@1 583
duke@1 584
duke@1 585 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
duke@1 586 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
duke@1 587 LIRItem value(x->x(), this);
duke@1 588 LIRItem count(x->y(), this);
duke@1 589 // Long shift destroys count register
duke@1 590 if (value.type()->is_long()) {
duke@1 591 count.set_destroys_register();
duke@1 592 }
duke@1 593 value.load_item();
duke@1 594 // the old backend doesn't support this
duke@1 595 if (count.is_constant() && count.type()->as_IntConstant() != NULL && value.type()->is_int()) {
duke@1 596 jint c = count.get_jint_constant() & 0x1f;
duke@1 597 assert(c >= 0 && c < 32, "should be small");
duke@1 598 count.dont_load_item();
duke@1 599 } else {
duke@1 600 count.load_item();
duke@1 601 }
duke@1 602 LIR_Opr reg = rlock_result(x);
duke@1 603 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
duke@1 604 }
duke@1 605
duke@1 606
duke@1 607 // _iand, _land, _ior, _lor, _ixor, _lxor
duke@1 608 void LIRGenerator::do_LogicOp(LogicOp* x) {
duke@1 609 LIRItem left(x->x(), this);
duke@1 610 LIRItem right(x->y(), this);
duke@1 611
duke@1 612 left.load_item();
duke@1 613 right.load_nonconstant();
duke@1 614 LIR_Opr reg = rlock_result(x);
duke@1 615
duke@1 616 logic_op(x->op(), reg, left.result(), right.result());
duke@1 617 }
duke@1 618
duke@1 619
duke@1 620
duke@1 621 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
duke@1 622 void LIRGenerator::do_CompareOp(CompareOp* x) {
duke@1 623 LIRItem left(x->x(), this);
duke@1 624 LIRItem right(x->y(), this);
duke@1 625 left.load_item();
duke@1 626 right.load_item();
duke@1 627 LIR_Opr reg = rlock_result(x);
duke@1 628 if (x->x()->type()->is_float_kind()) {
duke@1 629 Bytecodes::Code code = x->op();
duke@1 630 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
duke@1 631 } else if (x->x()->type()->tag() == longTag) {
duke@1 632 __ lcmp2int(left.result(), right.result(), reg);
duke@1 633 } else {
duke@1 634 Unimplemented();
duke@1 635 }
duke@1 636 }
duke@1 637
duke@1 638
duke@1 639 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
duke@1 640 assert(x->number_of_arguments() == 4, "wrong type");
duke@1 641 LIRItem obj (x->argument_at(0), this); // object
duke@1 642 LIRItem offset(x->argument_at(1), this); // offset of field
duke@1 643 LIRItem cmp (x->argument_at(2), this); // value to compare with field
duke@1 644 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp
duke@1 645
duke@1 646 // Use temps to avoid kills
duke@1 647 LIR_Opr t1 = FrameMap::G1_opr;
duke@1 648 LIR_Opr t2 = FrameMap::G3_opr;
never@6970 649 LIR_Opr addr = new_pointer_register();
duke@1 650
duke@1 651 // get address of field
duke@1 652 obj.load_item();
duke@1 653 offset.load_item();
duke@1 654 cmp.load_item();
duke@1 655 val.load_item();
duke@1 656
duke@1 657 __ add(obj.result(), offset.result(), addr);
duke@1 658
ysr@1374 659 if (type == objectType) { // Write-barrier needed for Object fields.
johnc@9176 660 pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,
johnc@9176 661 true /* do_load */, false /* patch */, NULL);
ysr@1374 662 }
ysr@1374 663
duke@1 664 if (type == objectType)
duke@1 665 __ cas_obj(addr, cmp.result(), val.result(), t1, t2);
duke@1 666 else if (type == intType)
duke@1 667 __ cas_int(addr, cmp.result(), val.result(), t1, t2);
duke@1 668 else if (type == longType)
duke@1 669 __ cas_long(addr, cmp.result(), val.result(), t1, t2);
duke@1 670 else {
duke@1 671 ShouldNotReachHere();
duke@1 672 }
duke@1 673 // generate conditional move of boolean result
duke@1 674 LIR_Opr result = rlock_result(x);
iveresov@7713 675 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
iveresov@7713 676 result, as_BasicType(type));
duke@1 677 if (type == objectType) { // Write-barrier needed for Object fields.
never@3172 678 // Precise card mark since could either be object or array
ysr@1374 679 post_barrier(addr, val.result());
duke@1 680 }
duke@1 681 }
duke@1 682
duke@1 683
duke@1 684 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
duke@1 685 switch (x->id()) {
duke@1 686 case vmIntrinsics::_dabs:
duke@1 687 case vmIntrinsics::_dsqrt: {
duke@1 688 assert(x->number_of_arguments() == 1, "wrong type");
duke@1 689 LIRItem value(x->argument_at(0), this);
duke@1 690 value.load_item();
duke@1 691 LIR_Opr dst = rlock_result(x);
duke@1 692
duke@1 693 switch (x->id()) {
duke@1 694 case vmIntrinsics::_dsqrt: {
duke@1 695 __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
duke@1 696 break;
duke@1 697 }
duke@1 698 case vmIntrinsics::_dabs: {
duke@1 699 __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
duke@1 700 break;
duke@1 701 }
duke@1 702 }
duke@1 703 break;
duke@1 704 }
duke@1 705 case vmIntrinsics::_dlog10: // fall through
duke@1 706 case vmIntrinsics::_dlog: // fall through
duke@1 707 case vmIntrinsics::_dsin: // fall through
duke@1 708 case vmIntrinsics::_dtan: // fall through
roland@12739 709 case vmIntrinsics::_dcos: // fall through
roland@12739 710 case vmIntrinsics::_dexp: {
duke@1 711 assert(x->number_of_arguments() == 1, "wrong type");
duke@1 712
duke@1 713 address runtime_entry = NULL;
duke@1 714 switch (x->id()) {
duke@1 715 case vmIntrinsics::_dsin:
duke@1 716 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
duke@1 717 break;
duke@1 718 case vmIntrinsics::_dcos:
duke@1 719 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
duke@1 720 break;
duke@1 721 case vmIntrinsics::_dtan:
duke@1 722 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
duke@1 723 break;
duke@1 724 case vmIntrinsics::_dlog:
duke@1 725 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
duke@1 726 break;
duke@1 727 case vmIntrinsics::_dlog10:
duke@1 728 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
duke@1 729 break;
roland@12739 730 case vmIntrinsics::_dexp:
roland@12739 731 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
roland@12739 732 break;
duke@1 733 default:
duke@1 734 ShouldNotReachHere();
duke@1 735 }
duke@1 736
duke@1 737 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
duke@1 738 set_result(x, result);
roland@12739 739 break;
roland@12739 740 }
roland@12739 741 case vmIntrinsics::_dpow: {
roland@12739 742 assert(x->number_of_arguments() == 2, "wrong type");
roland@12739 743 address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
roland@12739 744 LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);
roland@12739 745 set_result(x, result);
roland@12739 746 break;
duke@1 747 }
duke@1 748 }
duke@1 749 }
duke@1 750
duke@1 751
duke@1 752 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
duke@1 753 assert(x->number_of_arguments() == 5, "wrong type");
never@3683 754
never@3683 755 // Make all state_for calls early since they can emit code
never@3683 756 CodeEmitInfo* info = state_for(x, x->state());
never@3683 757
duke@1 758 // Note: spill caller save before setting the item
duke@1 759 LIRItem src (x->argument_at(0), this);
duke@1 760 LIRItem src_pos (x->argument_at(1), this);
duke@1 761 LIRItem dst (x->argument_at(2), this);
duke@1 762 LIRItem dst_pos (x->argument_at(3), this);
duke@1 763 LIRItem length (x->argument_at(4), this);
duke@1 764 // load all values in callee_save_registers, as this makes the
duke@1 765 // parameter passing to the fast case simpler
duke@1 766 src.load_item_force (rlock_callee_saved(T_OBJECT));
duke@1 767 src_pos.load_item_force (rlock_callee_saved(T_INT));
duke@1 768 dst.load_item_force (rlock_callee_saved(T_OBJECT));
duke@1 769 dst_pos.load_item_force (rlock_callee_saved(T_INT));
duke@1 770 length.load_item_force (rlock_callee_saved(T_INT));
duke@1 771
duke@1 772 int flags;
duke@1 773 ciArrayKlass* expected_type;
duke@1 774 arraycopy_helper(x, &flags, &expected_type);
duke@1 775
duke@1 776 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(),
duke@1 777 length.result(), rlock_callee_saved(T_INT),
duke@1 778 expected_type, flags, info);
duke@1 779 set_no_result(x);
duke@1 780 }
duke@1 781
drchase@18507 782 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
kvn@34205 783 // Make all state_for calls early since they can emit code
kvn@34205 784 LIR_Opr result = rlock_result(x);
kvn@34205 785 int flags = 0;
kvn@34205 786 switch (x->id()) {
kvn@34205 787 case vmIntrinsics::_updateCRC32: {
kvn@34205 788 LIRItem crc(x->argument_at(0), this);
kvn@34205 789 LIRItem val(x->argument_at(1), this);
kvn@34205 790 // val is destroyed by update_crc32
kvn@34205 791 val.set_destroys_register();
kvn@34205 792 crc.load_item();
kvn@34205 793 val.load_item();
kvn@34205 794 __ update_crc32(crc.result(), val.result(), result);
kvn@34205 795 break;
kvn@34205 796 }
kvn@34205 797 case vmIntrinsics::_updateBytesCRC32:
kvn@34205 798 case vmIntrinsics::_updateByteBufferCRC32: {
kvn@34205 799
kvn@34205 800 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
kvn@34205 801
kvn@34205 802 LIRItem crc(x->argument_at(0), this);
kvn@34205 803 LIRItem buf(x->argument_at(1), this);
kvn@34205 804 LIRItem off(x->argument_at(2), this);
kvn@34205 805 LIRItem len(x->argument_at(3), this);
kvn@34205 806
kvn@34205 807 buf.load_item();
kvn@34205 808 off.load_nonconstant();
kvn@34205 809
kvn@34205 810 LIR_Opr index = off.result();
kvn@34205 811 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
kvn@34205 812 if(off.result()->is_constant()) {
kvn@34205 813 index = LIR_OprFact::illegalOpr;
kvn@34205 814 offset += off.result()->as_jint();
kvn@34205 815 }
kvn@34205 816
kvn@34205 817 LIR_Opr base_op = buf.result();
kvn@34205 818
kvn@34205 819 if (index->is_valid()) {
kvn@34205 820 LIR_Opr tmp = new_register(T_LONG);
kvn@34205 821 __ convert(Bytecodes::_i2l, index, tmp);
kvn@34205 822 index = tmp;
kvn@34205 823 if (index->is_constant()) {
kvn@34205 824 offset += index->as_constant_ptr()->as_jint();
kvn@34205 825 index = LIR_OprFact::illegalOpr;
kvn@34205 826 } else if (index->is_register()) {
kvn@34205 827 LIR_Opr tmp2 = new_register(T_LONG);
kvn@34205 828 LIR_Opr tmp3 = new_register(T_LONG);
kvn@34205 829 __ move(base_op, tmp2);
kvn@34205 830 __ move(index, tmp3);
kvn@34205 831 __ add(tmp2, tmp3, tmp2);
kvn@34205 832 base_op = tmp2;
kvn@34205 833 } else {
kvn@34205 834 ShouldNotReachHere();
kvn@34205 835 }
kvn@34205 836 }
kvn@34205 837
kvn@34205 838 LIR_Address* a = new LIR_Address(base_op, offset, T_BYTE);
kvn@34205 839
kvn@34205 840 BasicTypeList signature(3);
kvn@34205 841 signature.append(T_INT);
kvn@34205 842 signature.append(T_ADDRESS);
kvn@34205 843 signature.append(T_INT);
kvn@34205 844 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
kvn@34205 845 const LIR_Opr result_reg = result_register_for(x->type());
kvn@34205 846
kvn@34205 847 LIR_Opr addr = new_pointer_register();
kvn@34205 848 __ leal(LIR_OprFact::address(a), addr);
kvn@34205 849
kvn@34205 850 crc.load_item_force(cc->at(0));
kvn@34205 851 __ move(addr, cc->at(1));
kvn@34205 852 len.load_item_force(cc->at(2));
kvn@34205 853
kvn@34205 854 __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());
kvn@34205 855 __ move(result_reg, result);
kvn@34205 856
kvn@34205 857 break;
kvn@34205 858 }
kvn@34205 859 default: {
kvn@34205 860 ShouldNotReachHere();
kvn@34205 861 }
kvn@34205 862 }
drchase@18507 863 }
drchase@18507 864
kvn@38237 865 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
kvn@38237 866 // Make all state_for calls early since they can emit code
kvn@38237 867 LIR_Opr result = rlock_result(x);
kvn@38237 868 int flags = 0;
kvn@38237 869 switch (x->id()) {
kvn@38237 870 case vmIntrinsics::_updateBytesCRC32C:
kvn@38237 871 case vmIntrinsics::_updateDirectByteBufferCRC32C: {
kvn@38237 872
kvn@38237 873 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
kvn@38237 874 int array_offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
kvn@38237 875
kvn@38237 876 LIRItem crc(x->argument_at(0), this);
kvn@38237 877 LIRItem buf(x->argument_at(1), this);
kvn@38237 878 LIRItem off(x->argument_at(2), this);
kvn@38237 879 LIRItem end(x->argument_at(3), this);
kvn@38237 880
kvn@38237 881 buf.load_item();
kvn@38237 882 off.load_nonconstant();
kvn@38237 883 end.load_nonconstant();
kvn@38237 884
kvn@38237 885 // len = end - off
kvn@38237 886 LIR_Opr len = end.result();
kvn@38237 887 LIR_Opr tmpA = new_register(T_INT);
kvn@38237 888 LIR_Opr tmpB = new_register(T_INT);
kvn@38237 889 __ move(end.result(), tmpA);
kvn@38237 890 __ move(off.result(), tmpB);
kvn@38237 891 __ sub(tmpA, tmpB, tmpA);
kvn@38237 892 len = tmpA;
kvn@38237 893
kvn@38237 894 LIR_Opr index = off.result();
kvn@38237 895
kvn@38237 896 if(off.result()->is_constant()) {
kvn@38237 897 index = LIR_OprFact::illegalOpr;
kvn@38237 898 array_offset += off.result()->as_jint();
kvn@38237 899 }
kvn@38237 900
kvn@38237 901 LIR_Opr base_op = buf.result();
kvn@38237 902
kvn@38237 903 if (index->is_valid()) {
kvn@38237 904 LIR_Opr tmp = new_register(T_LONG);
kvn@38237 905 __ convert(Bytecodes::_i2l, index, tmp);
kvn@38237 906 index = tmp;
kvn@38237 907 if (index->is_constant()) {
kvn@38237 908 array_offset += index->as_constant_ptr()->as_jint();
kvn@38237 909 index = LIR_OprFact::illegalOpr;
kvn@38237 910 } else if (index->is_register()) {
kvn@38237 911 LIR_Opr tmp2 = new_register(T_LONG);
kvn@38237 912 LIR_Opr tmp3 = new_register(T_LONG);
kvn@38237 913 __ move(base_op, tmp2);
kvn@38237 914 __ move(index, tmp3);
kvn@38237 915 __ add(tmp2, tmp3, tmp2);
kvn@38237 916 base_op = tmp2;
kvn@38237 917 } else {
kvn@38237 918 ShouldNotReachHere();
kvn@38237 919 }
kvn@38237 920 }
kvn@38237 921
kvn@38237 922 LIR_Address* a = new LIR_Address(base_op, array_offset, T_BYTE);
kvn@38237 923
kvn@38237 924 BasicTypeList signature(3);
kvn@38237 925 signature.append(T_INT);
kvn@38237 926 signature.append(T_ADDRESS);
kvn@38237 927 signature.append(T_INT);
kvn@38237 928 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
kvn@38237 929 const LIR_Opr result_reg = result_register_for(x->type());
kvn@38237 930
kvn@38237 931 LIR_Opr addr = new_pointer_register();
kvn@38237 932 __ leal(LIR_OprFact::address(a), addr);
kvn@38237 933
kvn@38237 934 crc.load_item_force(cc->at(0));
kvn@38237 935 __ move(addr, cc->at(1));
kvn@38237 936 __ move(len, cc->at(2));
kvn@38237 937
kvn@38237 938 __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), getThreadTemp(), result_reg, cc->args());
kvn@38237 939 __ move(result_reg, result);
kvn@38237 940
kvn@38237 941 break;
kvn@38237 942 }
kvn@38237 943 default: {
kvn@38237 944 ShouldNotReachHere();
kvn@38237 945 }
kvn@38237 946 }
kvn@38237 947 }
kvn@38237 948
vdeshpande@41323 949 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
neliasso@46597 950 assert(x->number_of_arguments() == 3, "wrong type");
neliasso@46597 951 assert(UseFMA, "Needs FMA instructions support.");
neliasso@46597 952
neliasso@46597 953 LIRItem a(x->argument_at(0), this);
neliasso@46597 954 LIRItem b(x->argument_at(1), this);
neliasso@46597 955 LIRItem c(x->argument_at(2), this);
neliasso@46597 956
neliasso@46597 957 a.load_item();
neliasso@46597 958 b.load_item();
neliasso@46597 959 c.load_item();
neliasso@46597 960
neliasso@46597 961 LIR_Opr ina = a.result();
neliasso@46597 962 LIR_Opr inb = b.result();
neliasso@46597 963 LIR_Opr inc = c.result();
neliasso@46597 964 LIR_Opr res = rlock_result(x);
neliasso@46597 965
neliasso@46597 966 switch (x->id()) {
neliasso@46597 967 case vmIntrinsics::_fmaF: __ fmaf(ina, inb, inc, res); break;
neliasso@46597 968 case vmIntrinsics::_fmaD: __ fmad(ina, inb, inc, res); break;
neliasso@46597 969 default:
neliasso@46597 970 ShouldNotReachHere();
neliasso@46597 971 break;
neliasso@46597 972 }
vdeshpande@41323 973 }
vdeshpande@41323 974
psandoz@38238 975 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
psandoz@38238 976 fatal("vectorizedMismatch intrinsic is not implemented on this platform");
psandoz@38238 977 }
psandoz@38238 978
duke@1 979 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
duke@1 980 // _i2b, _i2c, _i2s
duke@1 981 void LIRGenerator::do_Convert(Convert* x) {
duke@1 982
duke@1 983 switch (x->op()) {
duke@1 984 case Bytecodes::_f2l:
duke@1 985 case Bytecodes::_d2l:
duke@1 986 case Bytecodes::_d2i:
duke@1 987 case Bytecodes::_l2f:
duke@1 988 case Bytecodes::_l2d: {
duke@1 989
duke@1 990 address entry;
duke@1 991 switch (x->op()) {
duke@1 992 case Bytecodes::_l2f:
duke@1 993 entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2f);
duke@1 994 break;
duke@1 995 case Bytecodes::_l2d:
duke@1 996 entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2d);
duke@1 997 break;
duke@1 998 case Bytecodes::_f2l:
duke@1 999 entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2l);
duke@1 1000 break;
duke@1 1001 case Bytecodes::_d2l:
duke@1 1002 entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2l);
duke@1 1003 break;
duke@1 1004 case Bytecodes::_d2i:
duke@1 1005 entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2i);
duke@1 1006 break;
duke@1 1007 default:
duke@1 1008 ShouldNotReachHere();
duke@1 1009 }
duke@1 1010 LIR_Opr result = call_runtime(x->value(), entry, x->type(), NULL);
duke@1 1011 set_result(x, result);
duke@1 1012 break;
duke@1 1013 }
duke@1 1014
duke@1 1015 case Bytecodes::_i2f:
duke@1 1016 case Bytecodes::_i2d: {
duke@1 1017 LIRItem value(x->value(), this);
duke@1 1018
duke@1 1019 LIR_Opr reg = rlock_result(x);
duke@1 1020 // To convert an int to double, we need to load the 32-bit int
duke@1 1021 // from memory into a single precision floating point register
duke@1 1022 // (even numbered). Then the sparc fitod instruction takes care
duke@1 1023 // of the conversion. This is a bit ugly, but is the best way to
duke@1 1024 // get the int value in a single precision floating point register
duke@1 1025 value.load_item();
duke@1 1026 LIR_Opr tmp = force_to_spill(value.result(), T_FLOAT);
duke@1 1027 __ convert(x->op(), tmp, reg);
duke@1 1028 break;
duke@1 1029 }
duke@1 1030 break;
duke@1 1031
duke@1 1032 case Bytecodes::_i2l:
duke@1 1033 case Bytecodes::_i2b:
duke@1 1034 case Bytecodes::_i2c:
duke@1 1035 case Bytecodes::_i2s:
duke@1 1036 case Bytecodes::_l2i:
duke@1 1037 case Bytecodes::_f2d:
duke@1 1038 case Bytecodes::_d2f: { // inline code
duke@1 1039 LIRItem value(x->value(), this);
duke@1 1040
duke@1 1041 value.load_item();
duke@1 1042 LIR_Opr reg = rlock_result(x);
duke@1 1043 __ convert(x->op(), value.result(), reg, false);
duke@1 1044 }
duke@1 1045 break;
duke@1 1046
duke@1 1047 case Bytecodes::_f2i: {
duke@1 1048 LIRItem value (x->value(), this);
duke@1 1049 value.set_destroys_register();
duke@1 1050 value.load_item();
duke@1 1051 LIR_Opr reg = rlock_result(x);
duke@1 1052 set_vreg_flag(reg, must_start_in_memory);
duke@1 1053 __ convert(x->op(), value.result(), reg, false);
duke@1 1054 }
duke@1 1055 break;
duke@1 1056
duke@1 1057 default: ShouldNotReachHere();
duke@1 1058 }
duke@1 1059 }
duke@1 1060
duke@1 1061
duke@1 1062 void LIRGenerator::do_NewInstance(NewInstance* x) {
rbackman@24933 1063 print_if_not_loaded(x);
rbackman@24933 1064
duke@1 1065 // This instruction can be deoptimized in the slow path : use
duke@1 1066 // O0 as result register.
duke@1 1067 const LIR_Opr reg = result_register_for(x->type());
rbackman@24933 1068
duke@1 1069 CodeEmitInfo* info = state_for(x, x->state());
duke@1 1070 LIR_Opr tmp1 = FrameMap::G1_oop_opr;
duke@1 1071 LIR_Opr tmp2 = FrameMap::G3_oop_opr;
duke@1 1072 LIR_Opr tmp3 = FrameMap::G4_oop_opr;
duke@1 1073 LIR_Opr tmp4 = FrameMap::O1_oop_opr;
roland@13742 1074 LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
rbackman@24933 1075 new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, tmp4, klass_reg, info);
duke@1 1076 LIR_Opr result = rlock_result(x);
duke@1 1077 __ move(reg, result);
duke@1 1078 }
duke@1 1079
duke@1 1080
duke@1 1081 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
never@3683 1082 // Evaluate state_for early since it may emit code
never@3683 1083 CodeEmitInfo* info = state_for(x, x->state());
never@3683 1084
duke@1 1085 LIRItem length(x->length(), this);
duke@1 1086 length.load_item();
duke@1 1087
duke@1 1088 LIR_Opr reg = result_register_for(x->type());
duke@1 1089 LIR_Opr tmp1 = FrameMap::G1_oop_opr;
duke@1 1090 LIR_Opr tmp2 = FrameMap::G3_oop_opr;
duke@1 1091 LIR_Opr tmp3 = FrameMap::G4_oop_opr;
duke@1 1092 LIR_Opr tmp4 = FrameMap::O1_oop_opr;
roland@13742 1093 LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
duke@1 1094 LIR_Opr len = length.result();
duke@1 1095 BasicType elem_type = x->elt_type();
duke@1 1096
roland@13742 1097 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
duke@1 1098
duke@1 1099 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
duke@1 1100 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
duke@1 1101
duke@1 1102 LIR_Opr result = rlock_result(x);
duke@1 1103 __ move(reg, result);
duke@1 1104 }
duke@1 1105
duke@1 1106
duke@1 1107 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
never@3683 1108 // Evaluate state_for early since it may emit code.
never@3683 1109 CodeEmitInfo* info = state_for(x, x->state());
duke@1 1110 // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
duke@1 1111 // and therefore provide the state before the parameters have been consumed
duke@1 1112 CodeEmitInfo* patching_info = NULL;
duke@1 1113 if (!x->klass()->is_loaded() || PatchALot) {
duke@1 1114 patching_info = state_for(x, x->state_before());
duke@1 1115 }
duke@1 1116
never@3683 1117 LIRItem length(x->length(), this);
duke@1 1118 length.load_item();
duke@1 1119
duke@1 1120 const LIR_Opr reg = result_register_for(x->type());
duke@1 1121 LIR_Opr tmp1 = FrameMap::G1_oop_opr;
duke@1 1122 LIR_Opr tmp2 = FrameMap::G3_oop_opr;
duke@1 1123 LIR_Opr tmp3 = FrameMap::G4_oop_opr;
duke@1 1124 LIR_Opr tmp4 = FrameMap::O1_oop_opr;
roland@13742 1125 LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
duke@1 1126 LIR_Opr len = length.result();
duke@1 1127
duke@1 1128 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
coleenp@13728 1129 ciMetadata* obj = ciObjArrayKlass::make(x->klass());
duke@1 1130 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
duke@1 1131 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
duke@1 1132 }
coleenp@13728 1133 klass2reg_with_patching(klass_reg, obj, patching_info);
duke@1 1134 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
duke@1 1135
duke@1 1136 LIR_Opr result = rlock_result(x);
duke@1 1137 __ move(reg, result);
duke@1 1138 }
duke@1 1139
duke@1 1140
duke@1 1141 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
duke@1 1142 Values* dims = x->dims();
duke@1 1143 int i = dims->length();
fzhinkin@38031 1144 LIRItemList* items = new LIRItemList(i, i, NULL);
duke@1 1145 while (i-- > 0) {
duke@1 1146 LIRItem* size = new LIRItem(dims->at(i), this);
duke@1 1147 items->at_put(i, size);
duke@1 1148 }
duke@1 1149
never@3683 1150 // Evaluate state_for early since it may emit code.
duke@1 1151 CodeEmitInfo* patching_info = NULL;
duke@1 1152 if (!x->klass()->is_loaded() || PatchALot) {
duke@1 1153 patching_info = state_for(x, x->state_before());
duke@1 1154
twisti@12959 1155 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
twisti@12959 1156 // clone all handlers (NOTE: Usually this is handled transparently
twisti@12959 1157 // by the CodeEmitInfo cloning logic in CodeStub constructors but
twisti@12959 1158 // is done explicitly here because a stub isn't being used).
duke@1 1159 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
duke@1 1160 }
never@3688 1161 CodeEmitInfo* info = state_for(x, x->state());
duke@1 1162
duke@1 1163 i = dims->length();
duke@1 1164 while (i-- > 0) {
duke@1 1165 LIRItem* size = items->at(i);
duke@1 1166 size->load_item();
duke@1 1167 store_stack_parameter (size->result(),
duke@1 1168 in_ByteSize(STACK_BIAS +
never@1066 1169 frame::memory_parameter_word_sp_offset * wordSize +
never@1066 1170 i * sizeof(jint)));
duke@1 1171 }
duke@1 1172
duke@1 1173 // This instruction can be deoptimized in the slow path : use
duke@1 1174 // O0 as result register.
roland@13742 1175 const LIR_Opr klass_reg = FrameMap::O0_metadata_opr;
roland@13742 1176 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
duke@1 1177 LIR_Opr rank = FrameMap::O1_opr;
duke@1 1178 __ move(LIR_OprFact::intConst(x->rank()), rank);
duke@1 1179 LIR_Opr varargs = FrameMap::as_pointer_opr(O2);
duke@1 1180 int offset_from_sp = (frame::memory_parameter_word_sp_offset * wordSize) + STACK_BIAS;
duke@1 1181 __ add(FrameMap::SP_opr,
duke@1 1182 LIR_OprFact::intptrConst(offset_from_sp),
duke@1 1183 varargs);
duke@1 1184 LIR_OprList* args = new LIR_OprList(3);
roland@13742 1185 args->append(klass_reg);
duke@1 1186 args->append(rank);
duke@1 1187 args->append(varargs);
roland@13742 1188 const LIR_Opr reg = result_register_for(x->type());
duke@1 1189 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
duke@1 1190 LIR_OprFact::illegalOpr,
duke@1 1191 reg, args, info);
duke@1 1192
duke@1 1193 LIR_Opr result = rlock_result(x);
duke@1 1194 __ move(reg, result);
duke@1 1195 }
duke@1 1196
duke@1 1197
duke@1 1198 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
duke@1 1199 }
duke@1 1200
duke@1 1201
duke@1 1202 void LIRGenerator::do_CheckCast(CheckCast* x) {
duke@1 1203 LIRItem obj(x->obj(), this);
duke@1 1204 CodeEmitInfo* patching_info = NULL;
duke@1 1205 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
duke@1 1206 // must do this before locking the destination register as an oop register,
duke@1 1207 // and before the obj is loaded (so x->obj()->item() is valid for creating a debug info location)
duke@1 1208 patching_info = state_for(x, x->state_before());
duke@1 1209 }
duke@1 1210 obj.load_item();
duke@1 1211 LIR_Opr out_reg = rlock_result(x);
duke@1 1212 CodeStub* stub;
coleenp@44738 1213 CodeEmitInfo* info_for_exception =
coleenp@44738 1214 (x->needs_exception_state() ? state_for(x) :
coleenp@44738 1215 state_for(x, x->state_before(), true /*ignore_xhandler*/));
duke@1 1216
duke@1 1217 if (x->is_incompatible_class_change_check()) {
duke@1 1218 assert(patching_info == NULL, "can't patch this");
duke@1 1219 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
coleenp@44738 1220 } else if (x->is_invokespecial_receiver_check()) {
coleenp@44738 1221 assert(patching_info == NULL, "can't patch this");
coleenp@44738 1222 stub = new DeoptimizeStub(info_for_exception,
coleenp@44738 1223 Deoptimization::Reason_class_check,
coleenp@44738 1224 Deoptimization::Action_none);
duke@1 1225 } else {
duke@1 1226 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
duke@1 1227 }
duke@1 1228 LIR_Opr tmp1 = FrameMap::G1_oop_opr;
duke@1 1229 LIR_Opr tmp2 = FrameMap::G3_oop_opr;
duke@1 1230 LIR_Opr tmp3 = FrameMap::G4_oop_opr;
duke@1 1231 __ checkcast(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
duke@1 1232 x->direct_compare(), info_for_exception, patching_info, stub,
duke@1 1233 x->profiled_method(), x->profiled_bci());
duke@1 1234 }
duke@1 1235
duke@1 1236
duke@1 1237 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
duke@1 1238 LIRItem obj(x->obj(), this);
duke@1 1239 CodeEmitInfo* patching_info = NULL;
duke@1 1240 if (!x->klass()->is_loaded() || PatchALot) {
duke@1 1241 patching_info = state_for(x, x->state_before());
duke@1 1242 }
duke@1 1243 // ensure the result register is not the input register because the result is initialized before the patching safepoint
duke@1 1244 obj.load_item();
duke@1 1245 LIR_Opr out_reg = rlock_result(x);
duke@1 1246 LIR_Opr tmp1 = FrameMap::G1_oop_opr;
duke@1 1247 LIR_Opr tmp2 = FrameMap::G3_oop_opr;
duke@1 1248 LIR_Opr tmp3 = FrameMap::G4_oop_opr;
iveresov@6461 1249 __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
iveresov@6461 1250 x->direct_compare(), patching_info,
iveresov@6461 1251 x->profiled_method(), x->profiled_bci());
duke@1 1252 }
duke@1 1253
duke@1 1254
duke@1 1255 void LIRGenerator::do_If(If* x) {
duke@1 1256 assert(x->number_of_sux() == 2, "inconsistency");
duke@1 1257 ValueTag tag = x->x()->type()->tag();
duke@1 1258 LIRItem xitem(x->x(), this);
duke@1 1259 LIRItem yitem(x->y(), this);
duke@1 1260 LIRItem* xin = &xitem;
duke@1 1261 LIRItem* yin = &yitem;
duke@1 1262 If::Condition cond = x->cond();
duke@1 1263
duke@1 1264 if (tag == longTag) {
duke@1 1265 // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
duke@1 1266 // mirror for other conditions
duke@1 1267 if (cond == If::gtr || cond == If::leq) {
duke@1 1268 // swap inputs
duke@1 1269 cond = Instruction::mirror(cond);
duke@1 1270 xin = &yitem;
duke@1 1271 yin = &xitem;
duke@1 1272 }
duke@1 1273 xin->set_destroys_register();
duke@1 1274 }
duke@1 1275
duke@1 1276 LIR_Opr left = LIR_OprFact::illegalOpr;
duke@1 1277 LIR_Opr right = LIR_OprFact::illegalOpr;
duke@1 1278
duke@1 1279 xin->load_item();
duke@1 1280 left = xin->result();
duke@1 1281
duke@1 1282 if (is_simm13(yin->result())) {
duke@1 1283 // inline int constants which are small enough to be immediate operands
duke@1 1284 right = LIR_OprFact::value_type(yin->value()->type());
duke@1 1285 } else if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 &&
duke@1 1286 (cond == If::eql || cond == If::neq)) {
duke@1 1287 // inline long zero
duke@1 1288 right = LIR_OprFact::value_type(yin->value()->type());
duke@1 1289 } else if (tag == objectTag && yin->is_constant() && (yin->get_jobject_constant()->is_null_object())) {
duke@1 1290 right = LIR_OprFact::value_type(yin->value()->type());
duke@1 1291 } else {
duke@1 1292 yin->load_item();
duke@1 1293 right = yin->result();
duke@1 1294 }
duke@1 1295 set_no_result(x);
duke@1 1296
duke@1 1297 // add safepoint before generating condition code so it can be recomputed
duke@1 1298 if (x->is_safepoint()) {
duke@1 1299 // increment backedge counter if needed
iveresov@6453 1300 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
rehn@48069 1301 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
duke@1 1302 }
duke@1 1303
duke@1 1304 __ cmp(lir_cond(cond), left, right);
iveresov@6453 1305 // Generate branch profiling. Profiling code doesn't kill flags.
duke@1 1306 profile_branch(x, cond);
duke@1 1307 move_to_phi(x->state());
duke@1 1308 if (x->x()->type()->is_float_kind()) {
duke@1 1309 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());
duke@1 1310 } else {
duke@1 1311 __ branch(lir_cond(cond), right->type(), x->tsux());
duke@1 1312 }
duke@1 1313 assert(x->default_sux() == x->fsux(), "wrong destination above");
duke@1 1314 __ jump(x->default_sux());
duke@1 1315 }
duke@1 1316
duke@1 1317
duke@1 1318 LIR_Opr LIRGenerator::getThreadPointer() {
duke@1 1319 return FrameMap::as_pointer_opr(G2);
duke@1 1320 }
duke@1 1321
duke@1 1322
duke@1 1323 void LIRGenerator::trace_block_entry(BlockBegin* block) {
duke@1 1324 __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::O0_opr);
duke@1 1325 LIR_OprList* args = new LIR_OprList(1);
duke@1 1326 args->append(FrameMap::O0_opr);
duke@1 1327 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
duke@1 1328 __ call_runtime_leaf(func, rlock_callee_saved(T_INT), LIR_OprFact::illegalOpr, args);
duke@1 1329 }
duke@1 1330
duke@1 1331
duke@1 1332 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
duke@1 1333 CodeEmitInfo* info) {
duke@1 1334 __ store(value, address, info);
duke@1 1335 }
duke@1 1336
duke@1 1337 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
duke@1 1338 CodeEmitInfo* info) {
duke@1 1339 __ load(address, result, info);
duke@1 1340 }
duke@1 1341
duke@1 1342
duke@1 1343 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
duke@1 1344 BasicType type, bool is_volatile) {
duke@1 1345 LIR_Opr base_op = src;
duke@1 1346 LIR_Opr index_op = offset;
duke@1 1347
duke@1 1348 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
duke@1 1349 {
duke@1 1350 if (type == T_BOOLEAN) {
duke@1 1351 type = T_BYTE;
duke@1 1352 }
duke@1 1353 LIR_Address* addr;
duke@1 1354 if (type == T_ARRAY || type == T_OBJECT) {
duke@1 1355 LIR_Opr tmp = new_pointer_register();
duke@1 1356 __ add(base_op, index_op, tmp);
iveresov@5695 1357 addr = new LIR_Address(tmp, type);
duke@1 1358 } else {
duke@1 1359 addr = new LIR_Address(base_op, index_op, type);
duke@1 1360 }
duke@1 1361
ysr@1374 1362 if (is_obj) {
johnc@9176 1363 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
johnc@9176 1364 true /* do_load */, false /* patch */, NULL);
ysr@1374 1365 // _bs->c1_write_barrier_pre(this, LIR_OprFact::address(addr));
ysr@1374 1366 }
duke@1 1367 __ move(data, addr);
duke@1 1368 if (is_obj) {
duke@1 1369 // This address is precise
duke@1 1370 post_barrier(LIR_OprFact::address(addr), data);
duke@1 1371 }
duke@1 1372 }
duke@1 1373 }
duke@1 1374
duke@1 1375
duke@1 1376 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
duke@1 1377 BasicType type, bool is_volatile) {
duke@1 1378 {
duke@1 1379 LIR_Address* addr = new LIR_Address(src, offset, type);
duke@1 1380 __ load(addr, dst);
duke@1 1381 }
duke@1 1382 }
roland@13886 1383
roland@13886 1384 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
roland@13886 1385 BasicType type = x->basic_type();
roland@13886 1386 LIRItem src(x->object(), this);
roland@13886 1387 LIRItem off(x->offset(), this);
roland@13886 1388 LIRItem value(x->value(), this);
roland@13886 1389
roland@13886 1390 src.load_item();
roland@13886 1391 value.load_item();
roland@13886 1392 off.load_nonconstant();
roland@13886 1393
roland@13886 1394 LIR_Opr dst = rlock_result(x, type);
roland@13886 1395 LIR_Opr data = value.result();
roland@13886 1396 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
roland@13886 1397 LIR_Opr offset = off.result();
roland@13886 1398
iveresov@24677 1399 // Because we want a 2-arg form of xchg
iveresov@24677 1400 __ move(data, dst);
roland@13886 1401
gtriantafill@46381 1402 assert (!x->is_add() && (type == T_INT || (is_obj && UseCompressedOops)), "unexpected type");
roland@13886 1403 LIR_Address* addr;
roland@13886 1404 if (offset->is_constant()) {
roland@13886 1405
roland@13886 1406 jlong l = offset->as_jlong();
roland@13886 1407 assert((jlong)((jint)l) == l, "offset too large for constant");
roland@13886 1408 jint c = (jint)l;
roland@13886 1409 addr = new LIR_Address(src.result(), c, type);
roland@13886 1410 } else {
roland@13886 1411 addr = new LIR_Address(src.result(), offset, type);
roland@13886 1412 }
roland@13886 1413
roland@13886 1414 LIR_Opr tmp = LIR_OprFact::illegalOpr;
roland@13886 1415 LIR_Opr ptr = LIR_OprFact::illegalOpr;
roland@13886 1416
roland@13886 1417 if (is_obj) {
roland@13886 1418 // Do the pre-write barrier, if any.
roland@13886 1419 // barriers on sparc don't work with a base + index address
roland@13886 1420 tmp = FrameMap::G3_opr;
roland@13886 1421 ptr = new_pointer_register();
roland@13886 1422 __ add(src.result(), off.result(), ptr);
roland@13886 1423 pre_barrier(ptr, LIR_OprFact::illegalOpr /* pre_val */,
roland@13886 1424 true /* do_load */, false /* patch */, NULL);
roland@13886 1425 }
iveresov@24677 1426 __ xchg(LIR_OprFact::address(addr), dst, dst, tmp);
roland@13886 1427 if (is_obj) {
roland@13886 1428 // Seems to be a precise address
roland@13886 1429 post_barrier(ptr, data);
roland@13886 1430 }
roland@13886 1431 }