src/cpu/mips/vm/c1_LIRGenerator_mips.cpp

Thu, 24 May 2018 19:49:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:49:50 +0800
changeset 8865
ffcdff41a92f
parent 8863
5376ce0dc552
child 9130
4cd0a8696e8e
permissions
-rw-r--r--

some C1 fix
Contributed-by: chenhaoxuan, zhaixiang, aoqi

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

mercurial