src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial