src/cpu/x86/vm/c1_LIRGenerator_x86.cpp

Wed, 17 Jun 2015 17:48:25 -0700

author
ascarpino
date
Wed, 17 Jun 2015 17:48:25 -0700
changeset 9788
44ef77ad417c
parent 9614
bb44c0e88235
child 9637
eef07cd490d4
child 9843
a6f289d66efe
permissions
-rw-r--r--

8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
Reviewed-by: kvn, jrose, phh

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

mercurial