1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/mips/vm/c1_LIRGenerator_mips.cpp Fri Apr 29 00:06:10 2016 +0800 1.3 @@ -0,0 +1,1474 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "precompiled.hpp" 1.30 +#include "c1/c1_Compilation.hpp" 1.31 +#include "c1/c1_FrameMap.hpp" 1.32 +#include "c1/c1_Instruction.hpp" 1.33 +#include "c1/c1_LIRAssembler.hpp" 1.34 +#include "c1/c1_LIRGenerator.hpp" 1.35 +#include "c1/c1_Runtime1.hpp" 1.36 +#include "c1/c1_ValueStack.hpp" 1.37 +#include "ci/ciArray.hpp" 1.38 +#include "ci/ciObjArrayKlass.hpp" 1.39 +#include "ci/ciTypeArrayKlass.hpp" 1.40 +#include "runtime/sharedRuntime.hpp" 1.41 +#include "runtime/stubRoutines.hpp" 1.42 +#include "vmreg_mips.inline.hpp" 1.43 + 1.44 +#ifdef ASSERT 1.45 +#define __ gen()->lir(__FILE__, __LINE__)-> 1.46 +#else 1.47 +#define __ gen()->lir()-> 1.48 +#endif 1.49 + 1.50 +// Item will be loaded into a byte register; Intel only 1.51 +void LIRItem::load_byte_item() { 1.52 + load_item(); 1.53 + LIR_Opr res = result(); 1.54 + 1.55 + if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) { 1.56 + // make sure that it is a byte register 1.57 + assert(!value()->type()->is_float() && !value()->type()->is_double(), 1.58 + "can't load floats in byte register"); 1.59 + LIR_Opr reg = _gen->rlock_byte(T_BYTE); 1.60 + __ move(res, reg); 1.61 + 1.62 + _result = reg; 1.63 + } 1.64 +} 1.65 + 1.66 + 1.67 +void LIRItem::load_nonconstant() { 1.68 + LIR_Opr r = value()->operand(); 1.69 + if (r->is_constant()) { 1.70 + _result = r; 1.71 + } else { 1.72 + load_item(); 1.73 + } 1.74 +} 1.75 + 1.76 +//-------------------------------------------------------------- 1.77 +// LIRGenerator 1.78 +//-------------------------------------------------------------- 1.79 +LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::_v0_oop_opr; } 1.80 +LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::_v1_opr; } 1.81 +LIR_Opr LIRGenerator::divInOpr() { return FrameMap::_a0_opr; }//FIXME 1.82 +LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::_f0_opr; } //FIXME 1.83 +LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::_f0_opr; } //FIXME 1.84 +LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::_t3_opr; } // 1.85 +LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::_t2_opr; } 1.86 +LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; } // 1.87 + 1.88 + 1.89 +LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) { 1.90 + LIR_Opr opr; 1.91 + switch (type->tag()) { 1.92 + case intTag: 1.93 + { 1.94 + opr = FrameMap::_v0_opr; 1.95 + break; 1.96 + } 1.97 + case objectTag: 1.98 + { 1.99 + opr = FrameMap::_v0_oop_opr; 1.100 + break; 1.101 + } 1.102 + case longTag: 1.103 + { 1.104 + opr = FrameMap::_v0_v1_long_opr; 1.105 + break; 1.106 + } 1.107 + case floatTag: 1.108 + { 1.109 + opr = FrameMap::_f0_float_opr; 1.110 + break; 1.111 + } 1.112 + case doubleTag: { 1.113 + opr = FrameMap::_d0_double_opr; 1.114 + break; 1.115 + } 1.116 + case addressTag: 1.117 + default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr; 1.118 + } 1.119 + 1.120 + assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch"); 1.121 + return opr; 1.122 +} 1.123 + 1.124 +LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) { 1.125 + LIR_Opr reg = new_register(type); 1.126 + set_vreg_flag(reg, callee_saved); 1.127 + return reg; 1.128 +} 1.129 + 1.130 + 1.131 +LIR_Opr LIRGenerator::rlock_byte(BasicType type) { 1.132 + return new_register(T_INT); 1.133 +} 1.134 + 1.135 +/* 1.136 +LIR_Opr LIRGenerator::rlock_byte(BasicType type) { 1.137 + LIR_Opr reg = new_register(T_INT); 1.138 + set_vreg_flag(reg, LIRGenerator::byte_reg); 1.139 + return reg; 1.140 +} 1.141 +*/ 1.142 + 1.143 +//--------- loading items into registers -------------------------------- 1.144 + 1.145 + 1.146 +// i486 instructions can inline constants 1.147 +bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const { 1.148 + if (type == T_SHORT || type == T_CHAR) { 1.149 + // there is no immediate move of word values in asembler_i486.?pp 1.150 + return false; 1.151 + } 1.152 + Constant* c = v->as_Constant(); 1.153 + if (c && c->state_before() == NULL) { 1.154 + // constants of any type can be stored directly, except for 1.155 + // unloaded object constants. 1.156 + return true; 1.157 + } 1.158 + return false; 1.159 +} 1.160 + 1.161 + 1.162 +bool LIRGenerator::can_inline_as_constant(Value v) const { 1.163 + if (v->type()->is_constant() && v->type()->as_IntConstant() != NULL) { 1.164 + return Assembler::is_simm16(v->type()->as_IntConstant()->value()); 1.165 + } else { 1.166 + return false; 1.167 + } 1.168 +} 1.169 + 1.170 + 1.171 +bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const { 1.172 + if (c->type() == T_INT && c->as_constant() != NULL) { 1.173 + return Assembler::is_simm16(c->as_jint()); 1.174 + } else { 1.175 + return false; 1.176 + } 1.177 +} 1.178 + 1.179 + 1.180 +LIR_Opr LIRGenerator::safepoint_poll_register() { 1.181 + return new_register(T_INT); 1.182 +} 1.183 + 1.184 +LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index, 1.185 + int shift, int disp, BasicType type) { 1.186 + /* assert(base->is_register(), "must be"); 1.187 + if (index->is_constant()) { 1.188 + return new LIR_Address(base, 1.189 + (index->as_constant_ptr()->as_jint() << shift) + disp, 1.190 + type); 1.191 + } else { 1.192 + return new LIR_Address(base, index, (LIR_Address::Scale)shift, disp, type); 1.193 + } 1.194 + */ 1.195 + assert(base->is_register(), "must be"); 1.196 + 1.197 + if (index->is_constant()) { 1.198 + disp += index->as_constant_ptr()->as_jint() << shift; 1.199 + if (Assembler::is_simm16(disp)) { 1.200 + return new LIR_Address(base,disp, type); 1.201 + } else { 1.202 + 1.203 + if(disp!=0){ 1.204 +#ifdef _LP64 1.205 + LIR_Opr tmp = new_register(T_LONG); 1.206 +#else 1.207 + LIR_Opr tmp = new_register(T_INT); 1.208 +#endif 1.209 + 1.210 + __ move(LIR_OprFact::intConst((int)disp), tmp); 1.211 + __ add(tmp, base, tmp); 1.212 + return new LIR_Address(tmp, 0, type); 1.213 + 1.214 + } 1.215 + else 1.216 + return new LIR_Address(base, 0, type); 1.217 + 1.218 + } 1.219 + 1.220 + } 1.221 + else if( index->is_register()){ 1.222 + 1.223 +#ifdef _LP64 1.224 + LIR_Opr tmpa = new_register(T_LONG); 1.225 +#else 1.226 + LIR_Opr tmpa = new_register(T_INT); 1.227 +#endif 1.228 + __ move(index, tmpa); 1.229 + __ shift_left(tmpa, shift, tmpa); 1.230 + __ add(tmpa,base, tmpa); 1.231 + if (Assembler::is_simm16(disp)) { 1.232 + return new LIR_Address(tmpa, disp, type); 1.233 + } else { 1.234 + 1.235 + if(disp!=0){ 1.236 +#ifdef _LP64 1.237 + LIR_Opr tmp = new_register(T_LONG); 1.238 +#else 1.239 + LIR_Opr tmp = new_register(T_INT); 1.240 +#endif 1.241 + 1.242 + __ move(LIR_OprFact::intConst((int)disp), tmp); 1.243 + __ add(tmp, tmpa, tmp); 1.244 + return new LIR_Address(tmp, 0, type); 1.245 + } 1.246 + else 1.247 + return new LIR_Address(tmpa, 0, type); 1.248 + } 1.249 + 1.250 + } 1.251 + else { 1.252 + 1.253 + if (Assembler::is_simm16(disp)) { 1.254 + return new LIR_Address(base,disp, type); 1.255 + } else { 1.256 + if(disp!=0){ 1.257 +#ifdef _LP64 1.258 + LIR_Opr tmp = new_register(T_LONG); 1.259 +#else 1.260 + LIR_Opr tmp = new_register(T_INT); 1.261 +#endif 1.262 + 1.263 + __ move(LIR_OprFact::intConst((int)disp), tmp); 1.264 + __ add(tmp, base, tmp); 1.265 + return new LIR_Address(tmp, 0, type); 1.266 + } 1.267 + else 1.268 + return new LIR_Address(base, 0, type); 1.269 + } 1.270 + 1.271 + 1.272 + 1.273 + 1.274 + } 1.275 +} 1.276 + 1.277 +LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,BasicType type, bool needs_card_mark) { 1.278 + int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type); 1.279 + 1.280 + LIR_Address* addr; 1.281 + if (index_opr->is_constant()) { 1.282 + int elem_size = _type2aelembytes[type]; 1.283 + addr = new LIR_Address(array_opr, 1.284 + offset_in_bytes + index_opr->as_jint() * elem_size, type); 1.285 + } else if( index_opr->is_register()){ 1.286 +#ifdef _LP64 1.287 + LIR_Opr tmp = new_register(T_LONG); 1.288 +#else 1.289 + LIR_Opr tmp = new_register(T_INT); 1.290 +#endif 1.291 + __ move(index_opr, tmp); 1.292 + __ shift_left(tmp, LIR_Address::scale(type),tmp); 1.293 + __ add(tmp, array_opr, tmp); 1.294 + addr = new LIR_Address(tmp, offset_in_bytes,type); 1.295 + // addr = new LIR_Address(array_opr, 1.296 +// index_opr, 1.297 +// LIR_Address::scale(type), 1.298 +// offset_in_bytes, type); 1.299 + 1.300 + } 1.301 + else{ 1.302 + addr = new LIR_Address(array_opr, 1.303 + offset_in_bytes, type); 1.304 + } 1.305 + 1.306 + if (needs_card_mark) { 1.307 + // This store will need a precise card mark, so go ahead and 1.308 + // compute the full adddres instead of computing once for the 1.309 + // store and again for the card mark. 1.310 +#ifdef _LP64 1.311 + LIR_Opr tmp = new_register(T_ADDRESS); 1.312 +#else 1.313 + LIR_Opr tmp = new_register(T_INT); 1.314 +#endif 1.315 + __ leal(LIR_OprFact::address(addr), tmp); 1.316 + return new LIR_Address(tmp, 0, type); 1.317 + } else { 1.318 + return addr; 1.319 + } 1.320 + 1.321 + 1.322 +} 1.323 + 1.324 +LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) { 1.325 + LIR_Opr r; 1.326 + if (type == T_LONG) { 1.327 + r = LIR_OprFact::longConst(x); 1.328 + } else if (type == T_INT) { 1.329 + r = LIR_OprFact::intConst(x); 1.330 + } else { 1.331 + ShouldNotReachHere(); 1.332 + } 1.333 + return r; 1.334 +} 1.335 + 1.336 + 1.337 +void LIRGenerator::increment_counter(address counter, BasicType type, int step) { 1.338 + LIR_Opr temp = new_register(T_INT); 1.339 + LIR_Opr pointer = new_register(T_INT); 1.340 +#ifndef _LP64 1.341 +//by_css 1.342 + __ move(LIR_OprFact::intConst((int)counter), pointer); 1.343 +#else 1.344 + __ move(LIR_OprFact::longConst((long)counter), pointer); 1.345 +#endif 1.346 + LIR_Opr addr = (LIR_Opr)new LIR_Address(pointer, type); 1.347 + LIR_Opr c = LIR_OprFact::intConst((int)step); 1.348 + __ add(addr, c, addr); 1.349 +} 1.350 + 1.351 + 1.352 +void LIRGenerator::increment_counter(LIR_Address* addr, int step) { 1.353 + Unimplemented(); 1.354 +} 1.355 + 1.356 +bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { 1.357 + if (tmp->is_valid()) { 1.358 + if (is_power_of_2(c + 1)) { 1.359 + __ move(left, result); 1.360 + __ shift_left(result, log2_intptr(c + 1), result); 1.361 + __ sub(result, left, result); 1.362 + return true; 1.363 + } else if (is_power_of_2(c - 1)) { 1.364 + __ move(left, result); 1.365 + __ shift_left(result, log2_intptr(c - 1), result); 1.366 + __ add(result, left, result); 1.367 + return true; 1.368 + } 1.369 + } 1.370 + return false; 1.371 +} 1.372 + 1.373 +void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) { 1.374 + BasicType type = item->type(); 1.375 + __ store(item, new LIR_Address(FrameMap::_sp_opr, in_bytes(offset_from_sp), type)); 1.376 +} 1.377 + 1.378 + 1.379 +//---------------------------------------------------------------------- 1.380 +// visitor functions 1.381 +//---------------------------------------------------------------------- 1.382 + 1.383 + 1.384 +void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { 1.385 + assert(x->is_pinned(),""); 1.386 + bool needs_range_check = true; 1.387 + bool use_length = x->length() != NULL; 1.388 + bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT; 1.389 + bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL || 1.390 + !get_jobject_constant(x->value())->is_null_object()); 1.391 + 1.392 + LIRItem array(x->array(), this); 1.393 + LIRItem index(x->index(), this); 1.394 + LIRItem value(x->value(), this); 1.395 + LIRItem length(this); 1.396 + 1.397 + array.load_item(); 1.398 + index.load_nonconstant(); 1.399 + 1.400 + if (use_length) { 1.401 + needs_range_check = x->compute_needs_range_check(); 1.402 + if (needs_range_check) { 1.403 + length.set_instruction(x->length()); 1.404 + length.load_item(); 1.405 + } 1.406 + } 1.407 + if (needs_store_check) { 1.408 + value.load_item(); 1.409 + } else { 1.410 + value.load_for_store(x->elt_type()); 1.411 + } 1.412 + 1.413 + set_no_result(x); 1.414 + 1.415 + // the CodeEmitInfo must be duplicated for each different 1.416 + // LIR-instruction because spilling can occur anywhere between two 1.417 + // instructions and so the debug information must be different 1.418 + CodeEmitInfo* range_check_info = state_for(x); 1.419 + CodeEmitInfo* null_check_info = NULL; 1.420 + if (x->needs_null_check()) { 1.421 + null_check_info = new CodeEmitInfo(range_check_info); 1.422 + } 1.423 + 1.424 + // emit array address setup early so it schedules better 1.425 + LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store); 1.426 + 1.427 + if (GenerateRangeChecks && needs_range_check) { 1.428 + if (use_length) { 1.429 + __ branch(lir_cond_belowEqual, length.result(),index.result(),T_INT,new RangeCheckStub(range_check_info, index.result())); 1.430 + } else { 1.431 + array_range_check(array.result(), index.result(), null_check_info, range_check_info); 1.432 + // range_check also does the null check 1.433 + null_check_info = NULL; 1.434 + } 1.435 + } 1.436 + 1.437 + if (GenerateArrayStoreCheck && needs_store_check) { 1.438 + LIR_Opr tmp1 = new_register(objectType); 1.439 + LIR_Opr tmp2 = new_register(objectType); 1.440 + LIR_Opr tmp3 = new_register(objectType); 1.441 + 1.442 + CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info); 1.443 + __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci()); 1.444 + } 1.445 + 1.446 + if (obj_store) { 1.447 + // Needs GC write barriers. 1.448 + pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr, true, false, NULL); 1.449 + __ move(value.result(), array_addr, null_check_info); 1.450 + // Seems to be a precise 1.451 + post_barrier(LIR_OprFact::address(array_addr), value.result()); 1.452 + } else { 1.453 + __ move(value.result(), array_addr, null_check_info); 1.454 + } 1.455 +} 1.456 + 1.457 + 1.458 +void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { 1.459 + assert(x->is_pinned(),""); 1.460 + LIRItem obj(x->obj(), this); 1.461 + obj.load_item(); 1.462 + 1.463 + set_no_result(x); 1.464 + 1.465 + // "lock" stores the address of the monitor stack slot, so this is not an oop 1.466 +#ifdef _LP64 1.467 + LIR_Opr lock = new_register(T_LONG); 1.468 +#else 1.469 + LIR_Opr lock = new_register(T_INT); 1.470 +#endif 1.471 + // Need a scratch register for biased locking on mips 1.472 + LIR_Opr scratch = LIR_OprFact::illegalOpr; 1.473 + if (UseBiasedLocking) { 1.474 + scratch = new_register(T_INT); 1.475 + } 1.476 + 1.477 + CodeEmitInfo* info_for_exception = NULL; 1.478 + if (x->needs_null_check()) { 1.479 + info_for_exception = state_for(x); 1.480 + } 1.481 + // this CodeEmitInfo must not have the xhandlers because here the 1.482 + // object is already locked (xhandlers expect object to be unlocked) 1.483 + CodeEmitInfo* info = state_for(x, x->state(), true); 1.484 + monitor_enter(obj.result(), lock, syncTempOpr(), scratch, 1.485 + x->monitor_no(), info_for_exception, info); 1.486 +} 1.487 + 1.488 + 1.489 +void LIRGenerator::do_MonitorExit(MonitorExit* x) { 1.490 + assert(x->is_pinned(),""); 1.491 + 1.492 + LIRItem obj(x->obj(), this); 1.493 + obj.dont_load_item(); 1.494 + 1.495 + LIR_Opr lock = new_register(T_INT); 1.496 + LIR_Opr obj_temp = new_register(T_INT); 1.497 + set_no_result(x); 1.498 + monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no()); 1.499 +} 1.500 + 1.501 + 1.502 +// _ineg, _lneg, _fneg, _dneg 1.503 +void LIRGenerator::do_NegateOp(NegateOp* x) { 1.504 + LIRItem value(x->x(), this); 1.505 + value.set_destroys_register(); 1.506 + value.load_item(); 1.507 + LIR_Opr reg = rlock(x); 1.508 + __ negate(value.result(), reg); 1.509 + 1.510 + set_result(x, round_item(reg)); 1.511 +} 1.512 + 1.513 + 1.514 + 1.515 +// for _fadd, _fmul, _fsub, _fdiv, _frem 1.516 +// _dadd, _dmul, _dsub, _ddiv, _drem 1.517 +void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) { 1.518 + LIR_Opr tmp; 1.519 + LIRItem left(x->x(), this); 1.520 + LIRItem right(x->y(), this); 1.521 + left.load_item(); 1.522 + right.load_item(); 1.523 + rlock_result(x); 1.524 + switch (x->op()) { 1.525 + case Bytecodes::_drem: 1.526 + tmp = new_register(T_DOUBLE); 1.527 + __ frem(left.result(), right.result(), x->operand(), tmp); 1.528 + 1.529 + break; 1.530 + case Bytecodes::_frem: 1.531 + tmp = new_register(T_FLOAT); 1.532 + __ frem(left.result(), right.result(), x->operand(), tmp); 1.533 + break; 1.534 + default: arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp()); 1.535 + } 1.536 +} 1.537 + 1.538 + 1.539 + 1.540 + 1.541 +// for _ladd, _lmul, _lsub, _ldiv, _lrem 1.542 +void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) { 1.543 + switch (x->op()) { 1.544 + case Bytecodes::_lrem: 1.545 + case Bytecodes::_lmul: 1.546 + case Bytecodes::_ldiv: { 1.547 + 1.548 + if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) { 1.549 + LIRItem right(x->y(), this); 1.550 + right.load_item(); 1.551 + 1.552 + CodeEmitInfo* info = state_for(x); 1.553 + LIR_Opr item = right.result(); 1.554 + assert(item->is_register(), "must be"); 1.555 + __ branch(lir_cond_equal,item,LIR_OprFact::longConst(0), T_LONG, new DivByZeroStub(info)); 1.556 + } 1.557 + 1.558 + address entry; 1.559 + switch (x->op()) { 1.560 + case Bytecodes::_lrem: 1.561 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem); 1.562 + break; // check if dividend is 0 is done elsewhere 1.563 + case Bytecodes::_ldiv: 1.564 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv); 1.565 + break; // check if dividend is 0 is done elsewhere 1.566 + case Bytecodes::_lmul: 1.567 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul); 1.568 + break; 1.569 + default: 1.570 + ShouldNotReachHere(); 1.571 + } 1.572 + // order of arguments to runtime call is reversed. 1.573 + LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL); 1.574 + set_result(x, result); 1.575 + break; 1.576 + } 1.577 + /* _ladd, _lsub is delete in sharedRuntime.hpp 1.578 + case Bytecodes::_ladd: 1.579 + case Bytecodes::_lsub: { 1.580 + address entry; 1.581 + switch (x->op()) { 1.582 + case Bytecodes::_ladd: 1.583 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::ladd); 1.584 + break; // check if dividend is 0 is done elsewhere 1.585 + case Bytecodes::_lsub: 1.586 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lsub); 1.587 + break; // check if dividend is 0 is done elsewhere 1.588 + default: 1.589 + ShouldNotReachHere(); 1.590 + } 1.591 + 1.592 + // order of arguments to runtime call is reversed. 1.593 + LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL); 1.594 + set_result(x, result); 1.595 + break; 1.596 + }*/ 1.597 + 1.598 +/* { 1.599 + LIRItem left(x->x(), this); 1.600 + LIRItem right(x->y(), this); 1.601 + left.load_item(); 1.602 + right.load_item(); 1.603 + rlock_result(x); 1.604 + 1.605 + arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL); 1.606 + break; 1.607 + } 1.608 +*/ 1.609 + default: ShouldNotReachHere(); 1.610 + } 1.611 +} 1.612 + 1.613 + 1.614 + 1.615 + 1.616 +// for: _iadd, _imul, _isub, _idiv, _irem 1.617 +void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { 1.618 + bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem; 1.619 + LIRItem left(x->x(), this); 1.620 + LIRItem right(x->y(), this); 1.621 + // missing test if instr is commutative and if we should swap 1.622 + right.load_nonconstant(); 1.623 + assert(right.is_constant() || right.is_register(), "wrong state of right"); 1.624 + left.load_item(); 1.625 + rlock_result(x); 1.626 + if (is_div_rem) { 1.627 + CodeEmitInfo* info = state_for(x); 1.628 + LIR_Opr tmp =new_register(T_INT); 1.629 + if (x->op() == Bytecodes::_irem) { 1.630 + __ irem(left.result(), right.result(), x->operand(), tmp, info); 1.631 + } else if (x->op() == Bytecodes::_idiv) { 1.632 + __ idiv(left.result(), right.result(), x->operand(), tmp, info); 1.633 + } 1.634 + } else { 1.635 + //arithmetic_op_int(x->op(), x->operand(), left.result(), 1.636 + //right.result(), FrameMap::G1_opr); 1.637 + 1.638 + LIR_Opr tmp =new_register(T_INT); 1.639 + arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(), 1.640 + tmp); 1.641 + } 1.642 +} 1.643 + 1.644 + 1.645 +void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) { 1.646 + // when an operand with use count 1 is the left operand, then it is 1.647 + // likely that no move for 2-operand-LIR-form is necessary 1.648 + if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) { 1.649 + x->swap_operands(); 1.650 + } 1.651 + 1.652 + ValueTag tag = x->type()->tag(); 1.653 + assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters"); 1.654 + switch (tag) { 1.655 + case floatTag: 1.656 + case doubleTag: do_ArithmeticOp_FPU(x); return; 1.657 + case longTag: do_ArithmeticOp_Long(x); return; 1.658 + case intTag: do_ArithmeticOp_Int(x); return; 1.659 + } 1.660 + ShouldNotReachHere(); 1.661 +} 1.662 + 1.663 + 1.664 +// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr 1.665 +void LIRGenerator::do_ShiftOp(ShiftOp* x) { 1.666 + if(x->op() == Bytecodes::_lshl 1.667 + || x->op() == Bytecodes::_lshr 1.668 + || x->op() == Bytecodes::_lushr) { 1.669 + address entry; 1.670 + /* lushr, lshr, lshl, is delete in ShredRuntime.hpp 1.671 + switch (x->op()) { 1.672 + case Bytecodes::_lshl: 1.673 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lshl); 1.674 + break; // check if dividend is 0 is done elsewhere 1.675 + case Bytecodes::_lshr: 1.676 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lshr); 1.677 + break; // check if dividend is 0 is done elsewhere 1.678 + case Bytecodes::_lushr: 1.679 + entry = CAST_FROM_FN_PTR(address, SharedRuntime::lushr); 1.680 + break; 1.681 + default: 1.682 + ShouldNotReachHere(); 1.683 + } 1.684 + */ 1.685 + // order of arguments to runtime call is reversed. 1.686 + LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL); 1.687 + set_result(x, result); 1.688 + return; 1.689 + } 1.690 + 1.691 + // count must always be in rcx 1.692 + LIRItem value(x->x(), this); 1.693 + LIRItem count(x->y(), this); 1.694 + 1.695 + ValueTag elemType = x->type()->tag(); 1.696 + bool must_load_count = !count.is_constant() || elemType == longTag; 1.697 + if (must_load_count) { 1.698 + // count for long must be in register 1.699 + count.load_item(); 1.700 + } else { 1.701 + count.dont_load_item(); 1.702 + } 1.703 + value.load_item(); 1.704 + LIR_Opr reg = rlock_result(x); 1.705 + 1.706 + shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr); 1.707 +} 1.708 + 1.709 + 1.710 +// _iand, _land, _ior, _lor, _ixor, _lxor 1.711 +void LIRGenerator::do_LogicOp(LogicOp* x) { 1.712 + // when an operand with use count 1 is the left operand, then it is 1.713 + // likely that no move for 2-operand-LIR-form is necessary 1.714 + if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) { 1.715 + x->swap_operands(); 1.716 + } 1.717 + 1.718 + LIRItem left(x->x(), this); 1.719 + LIRItem right(x->y(), this); 1.720 + 1.721 + left.load_item(); 1.722 + right.load_nonconstant(); 1.723 + LIR_Opr reg = rlock_result(x); 1.724 + 1.725 + logic_op(x->op(), reg, left.result(), right.result()); 1.726 +} 1.727 + 1.728 + 1.729 + 1.730 +// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg 1.731 +void LIRGenerator::do_CompareOp(CompareOp* x) { 1.732 + LIRItem left(x->x(), this); 1.733 + LIRItem right(x->y(), this); 1.734 + ValueTag tag = x->x()->type()->tag(); 1.735 + if (tag == longTag) { 1.736 + left.set_destroys_register(); 1.737 + } 1.738 + left.load_item(); 1.739 + right.load_item(); 1.740 + LIR_Opr reg = rlock_result(x); 1.741 + 1.742 + if (x->x()->type()->is_float_kind()) { 1.743 + Bytecodes::Code code = x->op(); 1.744 + __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl)); 1.745 + } else if (x->x()->type()->tag() == longTag) { 1.746 + __ lcmp2int(left.result(), right.result(), reg); 1.747 + } else { 1.748 + Unimplemented(); 1.749 + } 1.750 +} 1.751 +/* 1.752 +void LIRGenerator::do_AttemptUpdate(Intrinsic* x) { 1.753 + assert(x->number_of_arguments() == 3, "wrong type"); 1.754 + LIRItem obj (x->argument_at(0), this); // AtomicLong object 1.755 + LIRItem cmp_value (x->argument_at(1), this); // value to compare with field 1.756 + LIRItem new_value (x->argument_at(2), this); 1.757 + // replace field with new_value if it matches cmp_value 1.758 + 1.759 + // compare value must be in edx,eax (hi,lo); may be destroyed by cmpxchg8 instruction 1.760 + // cmp_value.load_item_force(FrameMap::eax_edx_long_opr); 1.761 + cmp_value.load_item_force(FrameMap::_a0_a1_long_opr); 1.762 + 1.763 + // new value must be in ecx,ebx (hi,lo) 1.764 + // new_value.load_item_force(FrameMap::ebx_ecx_long_opr); 1.765 + new_value.load_item_force(FrameMap::_a2_a3_long_opr); 1.766 + // object pointer register is overwritten with field address 1.767 + obj.load_item(); 1.768 + 1.769 + // generate compare-and-swap; produces zero condition if swap occurs 1.770 + int value_offset = sun_misc_AtomicLongCSImpl::value_offset(); 1.771 + LIR_Opr addr = obj.result(); 1.772 + __ add(addr, LIR_OprFact::intConst(value_offset), addr); 1.773 + LIR_Opr t1 = LIR_OprFact::illegalOpr; // no temp needed 1.774 + LIR_Opr t2 = LIR_OprFact::illegalOpr; // no temp needed 1.775 + __ cas_long(addr, cmp_value.result(), new_value.result(), t1, t2, FrameMap::_at_opr); 1.776 + 1.777 + // generate conditional move of boolean result 1.778 + LIR_Opr result = rlock_result(x); 1.779 + //__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result); 1.780 + __ move(FrameMap::_at_opr, result); 1.781 +} 1.782 +*/ 1.783 +//FIXME, for mips, compareandswap is a bit different 1.784 +//I have no idea use which register 1.785 +void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) { 1.786 + assert(x->number_of_arguments() == 4, "wrong type"); 1.787 + LIRItem obj (x->argument_at(0), this); // object 1.788 + LIRItem offset(x->argument_at(1), this); // offset of field 1.789 + LIRItem cmp (x->argument_at(2), this); // value to compare with field 1.790 + LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp 1.791 + 1.792 + assert(obj.type()->tag() == objectTag, "invalid type"); 1.793 + 1.794 + //In 64bit the type can be long, sparc doesn't have this assert 1.795 + //assert(offset.type()->tag() == intTag, "invalid type"); 1.796 + 1.797 + assert(cmp.type()->tag() == type->tag(), "invalid type"); 1.798 + assert(val.type()->tag() == type->tag(), "invalid type"); 1.799 + 1.800 + // get address of field 1.801 + obj.load_item(); 1.802 + offset.load_nonconstant(); 1.803 + 1.804 + if (type == objectType) { 1.805 + // cmp.load_item_force(FrameMap::eax_oop_opr); 1.806 + cmp.load_item_force(FrameMap::_a0_oop_opr); 1.807 + val.load_item(); 1.808 + } else if (type == intType) { 1.809 + // cmp.load_item_force(FrameMap::eax_opr); 1.810 + cmp.load_item_force(FrameMap::_a0_opr); 1.811 + val.load_item(); 1.812 + } else if (type == longType) { 1.813 + //// cmp.load_item_force(FrameMap::eax_edx_long_opr); 1.814 + cmp.load_item_force(FrameMap::_a0_a1_long_opr); 1.815 + // val.load_item_force(FrameMap::ebx_ecx_long_opr); 1.816 + val.load_item_force(FrameMap::_a2_a3_long_opr); 1.817 + } else { 1.818 + ShouldNotReachHere(); 1.819 + } 1.820 + LIR_Opr addr = new_pointer_register(); 1.821 + __ move(obj.result(), addr); 1.822 + __ add(addr, offset.result(), addr); 1.823 + 1.824 + LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience 1.825 + if (type == objectType) 1.826 + __ cas_obj(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr); 1.827 + else if (type == intType) 1.828 + __ cas_int(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr); 1.829 + else if (type == longType) 1.830 + __ cas_long(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr); 1.831 + else { 1.832 + ShouldNotReachHere(); 1.833 + } 1.834 + // generate conditional move of boolean result 1.835 + LIR_Opr result = rlock_result(x); 1.836 + //cmove not exist on mips, 1.837 + // __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result); 1.838 + // our implementation of cmpxchg put result in AT 1.839 + // LIR_Opr result = rlock_result_with_hint(x, hint()); 1.840 + __ move(FrameMap::_at_opr, result); 1.841 + 1.842 + if (type == objectType) // Write-barrier needed for Object fields. 1.843 + write_barrier(addr); 1.844 +} 1.845 + 1.846 + 1.847 +void LIRGenerator::do_MathIntrinsic(Intrinsic* x) { 1.848 + switch (x->id()) { 1.849 + case vmIntrinsics::_dabs: 1.850 + case vmIntrinsics::_dsqrt: { 1.851 + assert(x->number_of_arguments() == 1, "wrong type"); 1.852 + LIRItem value(x->argument_at(0), this); 1.853 + value.load_item(); 1.854 + LIR_Opr dst = rlock_result(x); 1.855 + 1.856 + switch (x->id()) { 1.857 + case vmIntrinsics::_dsqrt: { 1.858 + __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr); 1.859 + break; 1.860 + } 1.861 + case vmIntrinsics::_dabs: { 1.862 + __ abs(value.result(), dst, LIR_OprFact::illegalOpr); 1.863 + break; 1.864 + } 1.865 + } 1.866 + break; 1.867 + } 1.868 + case vmIntrinsics::_dlog10: // fall through 1.869 + case vmIntrinsics::_dlog: // fall through 1.870 + case vmIntrinsics::_dsin: // fall through 1.871 + case vmIntrinsics::_dtan: // fall through 1.872 + case vmIntrinsics::_dcos: { 1.873 + assert(x->number_of_arguments() == 1, "wrong type"); 1.874 + 1.875 + address runtime_entry = NULL; 1.876 + switch (x->id()) { 1.877 + case vmIntrinsics::_dsin: 1.878 + runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); 1.879 + break; 1.880 + case vmIntrinsics::_dcos: 1.881 + runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); 1.882 + break; 1.883 + case vmIntrinsics::_dtan: 1.884 + runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); 1.885 + break; 1.886 + case vmIntrinsics::_dlog: 1.887 + runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); 1.888 + break; 1.889 + case vmIntrinsics::_dlog10: 1.890 + runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); 1.891 + break; 1.892 + default: 1.893 + ShouldNotReachHere(); 1.894 + } 1.895 + LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL); 1.896 + set_result(x, result); 1.897 + } 1.898 + } 1.899 +} 1.900 + 1.901 +void LIRGenerator::do_ArrayCopy(Intrinsic* x) { 1.902 + assert(x->number_of_arguments() == 5, "wrong type"); 1.903 + // Note: spill caller save before setting the item 1.904 + LIRItem src (x->argument_at(0), this); 1.905 + LIRItem src_pos (x->argument_at(1), this); 1.906 + LIRItem dst (x->argument_at(2), this); 1.907 + LIRItem dst_pos (x->argument_at(3), this); 1.908 + LIRItem length (x->argument_at(4), this); 1.909 + // load all values in callee_save_registers, as this makes the 1.910 + // parameter passing to the fast case simpler 1.911 + src.load_item_force (FrameMap::_t0_oop_opr); 1.912 + src_pos.load_item_force (FrameMap::_a0_opr); 1.913 + dst.load_item_force (FrameMap::_a1_oop_opr); 1.914 + dst_pos.load_item_force (FrameMap::_a2_opr); 1.915 + length.load_item_force (FrameMap::_a3_opr); 1.916 + 1.917 + int flags; 1.918 + ciArrayKlass* expected_type; 1.919 + arraycopy_helper(x, &flags, &expected_type); 1.920 + 1.921 + CodeEmitInfo* info = state_for(x, x->state()); 1.922 + __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), 1.923 + length.result(), rlock_callee_saved(T_INT), 1.924 + expected_type, flags, info); 1.925 + set_no_result(x); 1.926 +} 1.927 + 1.928 +void LIRGenerator::do_update_CRC32(Intrinsic* x) { // Fu: 20130832 1.929 +tty->print_cr("LIRGenerator::do_update_CRC32 unimplemented yet !"); 1.930 +Unimplemented(); 1.931 +} 1.932 + 1.933 +// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f 1.934 +// _i2b, _i2c, _i2s 1.935 +LIR_Opr fixed_register_for(BasicType type) { 1.936 + switch (type) { 1.937 + case T_FLOAT: return FrameMap::_f0_float_opr; 1.938 + case T_DOUBLE: return FrameMap::_d0_double_opr; 1.939 + case T_INT: return FrameMap::_v0_opr; 1.940 + case T_LONG: return FrameMap::_v0_v1_long_opr; 1.941 + default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr; 1.942 + } 1.943 +} 1.944 + 1.945 + 1.946 +void LIRGenerator::do_Convert(Convert* x) { 1.947 + // flags that vary for the different operations and different SSE-settings 1.948 + bool fixed_input, fixed_result, round_result, needs_stub; 1.949 + 1.950 + switch (x->op()) { 1.951 + case Bytecodes::_i2l: // fall through 1.952 + case Bytecodes::_l2i: // fall through 1.953 + case Bytecodes::_i2b: // fall through 1.954 + case Bytecodes::_i2c: // fall through 1.955 + case Bytecodes::_i2s: 1.956 + fixed_input = false; 1.957 + fixed_result = false; 1.958 + round_result = false; 1.959 + needs_stub = false; break; 1.960 + case Bytecodes::_f2d: 1.961 + fixed_input = UseSSE == 1; 1.962 + fixed_result = false; 1.963 + round_result = false; 1.964 + needs_stub = false; break; 1.965 + case Bytecodes::_d2f: 1.966 + fixed_input = false; 1.967 + fixed_result = UseSSE == 1; 1.968 + round_result = UseSSE < 1; 1.969 + needs_stub = false; break; 1.970 + case Bytecodes::_i2f: 1.971 + fixed_input = false; 1.972 + fixed_result = false; 1.973 + round_result = UseSSE < 1; 1.974 + needs_stub = false; break; 1.975 + case Bytecodes::_i2d: 1.976 + fixed_input = false; 1.977 + fixed_result = false; 1.978 + round_result = false; 1.979 + needs_stub = false; break; 1.980 + case Bytecodes::_f2i: 1.981 + fixed_input = false; 1.982 + fixed_result = false; 1.983 + round_result = false; 1.984 + needs_stub = true; break; 1.985 + case Bytecodes::_d2i: 1.986 + fixed_input = false; 1.987 + fixed_result = false; 1.988 + round_result = false; 1.989 + needs_stub = true; break; 1.990 + case Bytecodes::_l2f: 1.991 + fixed_input = false; 1.992 + fixed_result = UseSSE >= 1; 1.993 + round_result = UseSSE < 1; 1.994 + needs_stub = false; break; 1.995 + case Bytecodes::_l2d: 1.996 + fixed_input = false; 1.997 + fixed_result = UseSSE >= 2; 1.998 + round_result = UseSSE < 2; 1.999 + needs_stub = false; break; 1.1000 + case Bytecodes::_f2l: 1.1001 + fixed_input = true; 1.1002 + fixed_result = true; 1.1003 + round_result = false; 1.1004 + needs_stub = false; break; 1.1005 + case Bytecodes::_d2l: 1.1006 + fixed_input = true; 1.1007 + fixed_result = true; 1.1008 + round_result = false; 1.1009 + needs_stub = false; break; 1.1010 + default: ShouldNotReachHere(); 1.1011 + } 1.1012 + 1.1013 + LIRItem value(x->value(), this); 1.1014 + value.load_item(); 1.1015 + LIR_Opr input = value.result(); 1.1016 + LIR_Opr result = rlock(x); 1.1017 + 1.1018 + // arguments of lir_convert 1.1019 + LIR_Opr conv_input = input; 1.1020 + LIR_Opr conv_result = result; 1.1021 + ConversionStub* stub = NULL; 1.1022 + 1.1023 + if (fixed_input) { 1.1024 + conv_input = fixed_register_for(input->type()); 1.1025 + __ move(input, conv_input); 1.1026 + } 1.1027 + 1.1028 + assert(fixed_result == false || round_result == false, "cannot set both"); 1.1029 + if (fixed_result) { 1.1030 + conv_result = fixed_register_for(result->type()); 1.1031 + } else if (round_result) { 1.1032 + result = new_register(result->type()); 1.1033 + set_vreg_flag(result, must_start_in_memory); 1.1034 + } 1.1035 + 1.1036 + if (needs_stub) { 1.1037 + stub = new ConversionStub(x->op(), conv_input, conv_result); 1.1038 + } 1.1039 + 1.1040 + __ convert(x->op(), conv_input, conv_result, stub); 1.1041 + 1.1042 + if (result != conv_result) { 1.1043 + __ move(conv_result, result); 1.1044 + } 1.1045 + 1.1046 + assert(result->is_virtual(), "result must be virtual register"); 1.1047 + set_result(x, result); 1.1048 +} 1.1049 + 1.1050 +void LIRGenerator::do_NewInstance(NewInstance* x) { 1.1051 + const LIR_Opr reg = result_register_for(x->type()); 1.1052 +#ifndef PRODUCT 1.1053 + if (PrintNotLoaded && !x->klass()->is_loaded()) { 1.1054 + tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci()); 1.1055 + } 1.1056 +#endif 1.1057 + CodeEmitInfo* info = state_for(x, x->state()); 1.1058 +// LIR_Opr tmp1 = new_register(T_INT); 1.1059 +// LIR_Opr tmp2 = new_register(T_INT); 1.1060 +// LIR_Opr tmp3 = new_register(T_INT); 1.1061 +// LIR_Opr tmp4 = new_register(T_INT); 1.1062 +#ifndef _LP64 1.1063 + LIR_Opr klass_reg = FrameMap::_t4_oop_opr; 1.1064 +#else 1.1065 + LIR_Opr klass_reg = FrameMap::_a4_oop_opr; 1.1066 +#endif 1.1067 +// new_instance(reg, x->klass(), FrameMap::_t0_oop_opr, FrameMap::_t1_oop_opr,FrameMap::_t2_oop_opr, LIR_OprFact::illegalOpr, klass_reg, info); 1.1068 + new_instance(reg, 1.1069 + x->klass(), 1.1070 + FrameMap::_t0_oop_opr, 1.1071 + FrameMap::_t1_oop_opr, 1.1072 + FrameMap::_t2_oop_opr, 1.1073 + FrameMap::_t3_oop_opr, 1.1074 +#ifndef _LP64 1.1075 + FrameMap::_t5_oop_opr, 1.1076 + FrameMap::_t6_oop_opr, 1.1077 +#else 1.1078 + FrameMap::_a5_oop_opr, 1.1079 + FrameMap::_a6_oop_opr, 1.1080 +#endif 1.1081 + klass_reg, 1.1082 + info); 1.1083 + LIR_Opr result = rlock_result(x); 1.1084 + __ move(reg, result); 1.1085 + 1.1086 +} 1.1087 +void LIRGenerator::do_NewTypeArray(NewTypeArray* x) { 1.1088 + CodeEmitInfo* info = state_for(x, x->state()); 1.1089 + 1.1090 + LIRItem length(x->length(), this); 1.1091 + length.load_item_force(FrameMap::_t2_opr); 1.1092 + 1.1093 + LIR_Opr reg = result_register_for(x->type()); 1.1094 + //LIR_Opr tmp1 = new_register(T_INT); 1.1095 + //LIR_Opr tmp2 = new_register(T_INT); 1.1096 + //LIR_Opr tmp3 = new_register(T_INT); 1.1097 + //LIR_Opr tmp4 = new_register(T_INT); 1.1098 + LIR_Opr tmp1 = FrameMap::_t0_oop_opr; 1.1099 + LIR_Opr tmp2 = FrameMap::_t1_oop_opr; 1.1100 + LIR_Opr tmp3 = FrameMap::_t3_oop_opr; 1.1101 +#ifndef _LP64 1.1102 + LIR_Opr tmp4 = FrameMap::_t5_oop_opr; 1.1103 + LIR_Opr tmp5 = FrameMap::_t6_oop_opr; 1.1104 + LIR_Opr klass_reg = FrameMap::_t4_oop_opr; 1.1105 +#else 1.1106 + LIR_Opr tmp4 = FrameMap::_a5_oop_opr; 1.1107 + LIR_Opr tmp5 = FrameMap::_a6_oop_opr; 1.1108 + LIR_Opr klass_reg = FrameMap::_a4_oop_opr; 1.1109 +#endif 1.1110 + LIR_Opr len = length.result(); 1.1111 + BasicType elem_type = x->elt_type(); 1.1112 + 1.1113 + __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg); 1.1114 + 1.1115 + CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info); 1.1116 + __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4,tmp5, elem_type, klass_reg, slow_path); 1.1117 + 1.1118 + LIR_Opr result = rlock_result(x); 1.1119 + __ move(reg, result); 1.1120 +} 1.1121 + 1.1122 + 1.1123 + 1.1124 +void LIRGenerator::do_NewObjectArray(NewObjectArray* x) { 1.1125 + LIRItem length(x->length(), this); 1.1126 + // in case of patching (i.e., object class is not yet loaded), we 1.1127 + // need to reexecute the instruction 1.1128 + // and therefore provide the state before the parameters have been consumed 1.1129 + CodeEmitInfo* patching_info = NULL; 1.1130 + if (!x->klass()->is_loaded() || PatchALot) { 1.1131 + patching_info = state_for(x, x->state_before()); 1.1132 + } 1.1133 + 1.1134 + const LIR_Opr reg = result_register_for(x->type()); 1.1135 + //LIR_Opr tmp1 = new_register(T_INT); 1.1136 + //LIR_Opr tmp2 = new_register(T_INT); 1.1137 + //LIR_Opr tmp3 = new_register(T_INT); 1.1138 + //LIR_Opr tmp4 = new_register(T_INT); 1.1139 + LIR_Opr tmp1 = FrameMap::_t0_oop_opr; 1.1140 + LIR_Opr tmp2 = FrameMap::_t1_oop_opr; 1.1141 + LIR_Opr tmp3 = FrameMap::_t3_oop_opr; 1.1142 +#ifndef _LP64 1.1143 + LIR_Opr tmp4 = FrameMap::_t5_oop_opr; 1.1144 + LIR_Opr tmp5 = FrameMap::_t6_oop_opr; 1.1145 + LIR_Opr klass_reg = FrameMap::_t4_oop_opr; 1.1146 +#else 1.1147 + LIR_Opr tmp4 = FrameMap::_a5_oop_opr; 1.1148 + LIR_Opr tmp5 = FrameMap::_a6_oop_opr; 1.1149 + LIR_Opr klass_reg = FrameMap::_a4_oop_opr; 1.1150 +#endif 1.1151 + 1.1152 + length.load_item_force(FrameMap::_t2_opr); 1.1153 + 1.1154 + LIR_Opr len = length.result(); 1.1155 + CodeEmitInfo* info = state_for(x, x->state()); 1.1156 + 1.1157 + CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info); 1.1158 + ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass()); 1.1159 + if (obj == ciEnv::unloaded_ciobjarrayklass()) { 1.1160 + BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error"); 1.1161 + } 1.1162 + klass2reg_with_patching(klass_reg, obj, patching_info); 1.1163 + __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, tmp5, T_OBJECT, klass_reg, slow_path); 1.1164 + 1.1165 + LIR_Opr result = rlock_result(x); 1.1166 + __ move(reg, result); 1.1167 +} 1.1168 + 1.1169 + 1.1170 +void LIRGenerator::do_NewMultiArray(NewMultiArray* x) { 1.1171 + Values* dims = x->dims(); 1.1172 + int i = dims->length(); 1.1173 + LIRItemList* items = new LIRItemList(dims->length(), NULL); 1.1174 + while (i-- > 0) { 1.1175 + LIRItem* size = new LIRItem(dims->at(i), this); 1.1176 + items->at_put(i, size); 1.1177 + } 1.1178 + 1.1179 + // need to get the info before, as the items may become invalid through item_free 1.1180 + CodeEmitInfo* patching_info = NULL; 1.1181 + if (!x->klass()->is_loaded() || PatchALot) { 1.1182 + patching_info = state_for(x, x->state_before()); 1.1183 + // cannot re-use same xhandlers for multiple CodeEmitInfos, so 1.1184 + // clone all handlers. 1.1185 + x->set_exception_handlers(new XHandlers(x->exception_handlers())); 1.1186 + } 1.1187 + 1.1188 + CodeEmitInfo* info = state_for(x, x->state()); 1.1189 + 1.1190 + i = dims->length(); 1.1191 + while (i-- > 0) { 1.1192 + LIRItem* size = items->at(i); 1.1193 + size->load_nonconstant(); 1.1194 + store_stack_parameter(size->result(), in_ByteSize(i*4)); 1.1195 + } 1.1196 + 1.1197 + LIR_Opr reg = result_register_for(x->type()); 1.1198 + klass2reg_with_patching(reg, x->klass(), patching_info); 1.1199 + 1.1200 + // LIR_Opr rank = FrameMap::ebx_opr; 1.1201 + LIR_Opr rank = FrameMap::_t2_opr; 1.1202 + __ move(LIR_OprFact::intConst(x->rank()), rank); 1.1203 + // LIR_Opr varargs = FrameMap::ecx_opr; 1.1204 + LIR_Opr varargs = FrameMap::_t0_opr; 1.1205 + __ move(FrameMap::_sp_opr, varargs); 1.1206 + LIR_OprList* args = new LIR_OprList(3); 1.1207 + args->append(reg); 1.1208 + args->append(rank); 1.1209 + args->append(varargs); 1.1210 + __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id), 1.1211 + LIR_OprFact::illegalOpr, 1.1212 + reg, args, info); 1.1213 + LIR_Opr result = rlock_result(x); 1.1214 + __ move(reg, result); 1.1215 +} 1.1216 + 1.1217 +void LIRGenerator::do_BlockBegin(BlockBegin* x) { 1.1218 + // nothing to do for now 1.1219 +} 1.1220 + 1.1221 + 1.1222 +void LIRGenerator::do_CheckCast(CheckCast* x) { 1.1223 + LIRItem obj(x->obj(), this); 1.1224 + 1.1225 + CodeEmitInfo* patching_info = NULL; 1.1226 + if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) { 1.1227 + // must do this before locking the destination register as an oop register, 1.1228 + // and before the obj is loaded (the latter is for deoptimization) 1.1229 + patching_info = state_for(x, x->state_before()); 1.1230 + } 1.1231 + obj.load_item(); 1.1232 + 1.1233 + // info for exceptions 1.1234 + CodeEmitInfo* info_for_exception = state_for(x); 1.1235 + 1.1236 + CodeStub* stub; 1.1237 + if (x->is_incompatible_class_change_check()) { 1.1238 + assert(patching_info == NULL, "can't patch this"); 1.1239 + stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception); 1.1240 + } else { 1.1241 + stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception); 1.1242 + } 1.1243 + LIR_Opr reg = rlock_result(x); 1.1244 + LIR_Opr tmp3 = LIR_OprFact::illegalOpr; 1.1245 + if (!x->klass()->is_loaded() || UseCompressedOops) { 1.1246 + tmp3 = new_register(objectType); 1.1247 + } 1.1248 + __ checkcast(reg, obj.result(), x->klass(), 1.1249 + new_register(objectType), new_register(objectType), 1.1250 + tmp3, x->direct_compare(), info_for_exception, patching_info, stub, 1.1251 + x->profiled_method(), x->profiled_bci()); 1.1252 +} 1.1253 + 1.1254 + 1.1255 +void LIRGenerator::do_InstanceOf(InstanceOf* x) { 1.1256 + LIRItem obj(x->obj(), this); 1.1257 + 1.1258 + // result and test object may not be in same register 1.1259 + LIR_Opr reg = rlock_result(x); 1.1260 + CodeEmitInfo* patching_info = NULL; 1.1261 + if ((!x->klass()->is_loaded() || PatchALot)) { 1.1262 + // must do this before locking the destination register as an oop register 1.1263 + patching_info = state_for(x, x->state_before()); 1.1264 + } 1.1265 + obj.load_item(); 1.1266 + LIR_Opr tmp = new_register(objectType); 1.1267 + LIR_Opr tmp3 = LIR_OprFact::illegalOpr; 1.1268 + if (!x->klass()->is_loaded() || UseCompressedOops) { 1.1269 + tmp3 = new_register(objectType); 1.1270 + } 1.1271 + 1.1272 + __ instanceof(reg, obj.result(), x->klass(), 1.1273 + tmp, new_register(objectType), tmp3, 1.1274 + x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci()); 1.1275 +} 1.1276 + 1.1277 + 1.1278 +void LIRGenerator::do_If(If* x) { 1.1279 + assert(x->number_of_sux() == 2, "inconsistency"); 1.1280 + ValueTag tag = x->x()->type()->tag(); 1.1281 + bool is_safepoint = x->is_safepoint(); 1.1282 + 1.1283 + If::Condition cond = x->cond(); 1.1284 + 1.1285 + LIRItem xitem(x->x(), this); 1.1286 + LIRItem yitem(x->y(), this); 1.1287 + LIRItem* xin = &xitem; 1.1288 + LIRItem* yin = &yitem; 1.1289 + 1.1290 + if (tag == longTag) { 1.1291 + // for longs, only conditions "eql", "neq", "lss", "geq" are valid; 1.1292 + // mirror for other conditions 1.1293 + if (cond == If::gtr || cond == If::leq) { 1.1294 + cond = Instruction::mirror(cond); 1.1295 + xin = &yitem; 1.1296 + yin = &xitem; 1.1297 + } 1.1298 + xin->set_destroys_register(); 1.1299 + } 1.1300 + xin->load_item(); 1.1301 + if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) { 1.1302 + // inline long zero 1.1303 + yin->dont_load_item(); 1.1304 + } else if (tag == longTag || tag == floatTag || tag == doubleTag) { 1.1305 + // longs cannot handle constants at right side 1.1306 + yin->load_item(); 1.1307 + } else { 1.1308 + yin->dont_load_item(); 1.1309 + } 1.1310 + 1.1311 + // add safepoint before generating condition code so it can be recomputed 1.1312 + if (x->is_safepoint()) { 1.1313 + // increment backedge counter if needed 1.1314 + increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci()); 1.1315 + 1.1316 + __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); 1.1317 + } 1.1318 + set_no_result(x); 1.1319 + 1.1320 + LIR_Opr left = xin->result(); 1.1321 + LIR_Opr right = yin->result(); 1.1322 + // __ cmp(lir_cond(cond), left, right); 1.1323 + profile_branch(x, cond, left, right); 1.1324 + move_to_phi(x->state()); 1.1325 + if (x->x()->type()->is_float_kind()) { 1.1326 + __ branch(lir_cond(cond), left, right, right->type(), x->tsux(), x->usux()); 1.1327 + } else { 1.1328 + __ branch(lir_cond(cond), left, right, right->type(), x->tsux()); 1.1329 + } 1.1330 + assert(x->default_sux() == x->fsux(), "wrong destination above"); 1.1331 + __ jump(x->default_sux()); 1.1332 +} 1.1333 + 1.1334 + 1.1335 +LIR_Opr LIRGenerator::getThreadPointer() { 1.1336 +#ifdef _LP64 1.1337 +//FIXME, does as_pointer need to be implemented? or 64bit can use one register. by aoqi 1.1338 + //return FrameMap::as_pointer_opr(r15_thread); 1.1339 + LIR_Opr result = new_register(T_LONG); 1.1340 + __ get_thread(result); 1.1341 + return result; 1.1342 +#else 1.1343 + LIR_Opr result = new_register(T_INT); 1.1344 + __ get_thread(result); 1.1345 + return result; 1.1346 +#endif // 1.1347 +} 1.1348 + 1.1349 +void LIRGenerator::trace_block_entry(BlockBegin* block) { 1.1350 + store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0)); 1.1351 + LIR_OprList* args = new LIR_OprList(); 1.1352 + address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry); 1.1353 + __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args); 1.1354 +} 1.1355 + 1.1356 + 1.1357 +void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address, 1.1358 + CodeEmitInfo* info) { 1.1359 + if (address->type() == T_LONG) { 1.1360 + __ volatile_store_mem_reg(value, address, info); 1.1361 + } else { 1.1362 + __ store(value, address, info); 1.1363 + } 1.1364 +} 1.1365 + 1.1366 +void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result, 1.1367 + CodeEmitInfo* info) { 1.1368 + 1.1369 + if (address->type() == T_LONG) { 1.1370 + __ volatile_load_mem_reg(address, result, info); 1.1371 + } else { 1.1372 + __ load(address, result, info); 1.1373 + } 1.1374 +} 1.1375 + 1.1376 + 1.1377 +void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset, 1.1378 + BasicType type, bool is_volatile) { 1.1379 + __ add(src, offset, FrameMap::_at_opr); 1.1380 + if (is_volatile && type == T_LONG) { 1.1381 + LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE); 1.1382 + LIR_Opr tmp = new_register(T_DOUBLE); 1.1383 + __ load(addr, tmp); 1.1384 + LIR_Opr spill = new_register(T_LONG); 1.1385 + set_vreg_flag(spill, must_start_in_memory); 1.1386 + __ move(tmp, spill); 1.1387 + __ move(spill, dst); 1.1388 + } else { 1.1389 + LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type); 1.1390 + __ load(addr, dst); 1.1391 + } 1.1392 +} 1.1393 + 1.1394 + 1.1395 +void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, 1.1396 + BasicType type, bool is_volatile) { 1.1397 + __ add(src, offset, FrameMap::_at_opr); 1.1398 + if (is_volatile && type == T_LONG) { 1.1399 + LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE); 1.1400 + LIR_Opr tmp = new_register(T_DOUBLE); 1.1401 + LIR_Opr spill = new_register(T_DOUBLE); 1.1402 + set_vreg_flag(spill, must_start_in_memory); 1.1403 + __ move(data, spill); 1.1404 + __ move(spill, tmp); 1.1405 + __ move(tmp, addr); 1.1406 + 1.1407 + } else { 1.1408 + LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type); 1.1409 + bool is_obj = (type == T_ARRAY || type == T_OBJECT); 1.1410 + if (is_obj) { 1.1411 + // Do the pre-write barrier, if any. 1.1412 + pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr/* pre_val */, 1.1413 + true/* do_load */,false /*patch*/, NULL); 1.1414 + __ move(data, addr); 1.1415 + assert(src->is_register(), "must be register"); 1.1416 + // Seems to be a precise address 1.1417 + post_barrier(LIR_OprFact::address(addr), data); 1.1418 + } else { 1.1419 + __ move(data, addr); 1.1420 + } 1.1421 + } 1.1422 +} 1.1423 + 1.1424 +void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { 1.1425 + BasicType type = x->basic_type(); 1.1426 + LIRItem src(x->object(), this); 1.1427 + LIRItem off(x->offset(), this); 1.1428 + LIRItem value(x->value(), this); 1.1429 + 1.1430 + src.load_item(); 1.1431 + value.load_item(); 1.1432 + off.load_nonconstant(); 1.1433 + 1.1434 + LIR_Opr dst = rlock_result(x, type); 1.1435 + LIR_Opr data = value.result(); 1.1436 + bool is_obj = (type == T_ARRAY || type == T_OBJECT); 1.1437 + LIR_Opr offset = off.result(); 1.1438 + 1.1439 + assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type"); 1.1440 + LIR_Address* addr; 1.1441 + if (offset->is_constant()) { 1.1442 +#ifdef _LP64 1.1443 + jlong c = offset->as_jlong(); 1.1444 + if ((jlong)((jint)c) == c) { 1.1445 + addr = new LIR_Address(src.result(), (jint)c, type); 1.1446 + } else { 1.1447 + LIR_Opr tmp = new_register(T_LONG); 1.1448 + __ move(offset, tmp); 1.1449 + addr = new LIR_Address(src.result(), tmp, type); 1.1450 + } 1.1451 +#else 1.1452 + addr = new LIR_Address(src.result(), offset->as_jint(), type); 1.1453 +#endif 1.1454 + } else { 1.1455 + addr = new LIR_Address(src.result(), offset, type); 1.1456 + } 1.1457 + 1.1458 + if (data != dst) { 1.1459 + __ move(data, dst); 1.1460 + data = dst; 1.1461 + } 1.1462 + if (x->is_add()) { 1.1463 + __ xadd(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr); 1.1464 + } else { 1.1465 + if (is_obj) { 1.1466 + // Do the pre-write barrier, if any. 1.1467 + pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */, 1.1468 + true /* do_load */, false /* patch */, NULL); 1.1469 + } 1.1470 + __ xchg(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr); 1.1471 + if (is_obj) { 1.1472 + // Seems to be a precise address 1.1473 + post_barrier(LIR_OprFact::address(addr), data); 1.1474 + } 1.1475 + } 1.1476 +} 1.1477 +