annotate src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp @ 8227:0b85ccd62409

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