src/share/vm/c1/c1_LIRGenerator.cpp

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

author
aoqi
date
Thu, 24 May 2018 19:49:50 +0800
changeset 8865
ffcdff41a92f
parent 8860
43b19021a5a9
child 9041
95a08233f46c
permissions
-rw-r--r--

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

aoqi@0 1 /*
aoqi@8865 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #include "precompiled.hpp"
dlong@7598 32 #include "c1/c1_Defs.hpp"
aoqi@0 33 #include "c1/c1_Compilation.hpp"
aoqi@0 34 #include "c1/c1_FrameMap.hpp"
aoqi@0 35 #include "c1/c1_Instruction.hpp"
aoqi@0 36 #include "c1/c1_LIRAssembler.hpp"
aoqi@0 37 #include "c1/c1_LIRGenerator.hpp"
aoqi@0 38 #include "c1/c1_ValueStack.hpp"
aoqi@0 39 #include "ci/ciArrayKlass.hpp"
aoqi@0 40 #include "ci/ciInstance.hpp"
aoqi@0 41 #include "ci/ciObjArray.hpp"
aoqi@0 42 #include "runtime/sharedRuntime.hpp"
aoqi@0 43 #include "runtime/stubRoutines.hpp"
aoqi@0 44 #include "utilities/bitMap.inline.hpp"
aoqi@0 45 #include "utilities/macros.hpp"
aoqi@0 46 #if INCLUDE_ALL_GCS
aoqi@0 47 #include "gc_implementation/g1/heapRegion.hpp"
aoqi@0 48 #endif // INCLUDE_ALL_GCS
aoqi@0 49
aoqi@0 50 #ifdef ASSERT
aoqi@0 51 #define __ gen()->lir(__FILE__, __LINE__)->
aoqi@0 52 #else
aoqi@0 53 #define __ gen()->lir()->
aoqi@0 54 #endif
aoqi@0 55
dlong@7598 56 #ifndef PATCHED_ADDR
aoqi@0 57 #define PATCHED_ADDR (max_jint)
aoqi@0 58 #endif
aoqi@0 59
aoqi@0 60 void PhiResolverState::reset(int max_vregs) {
aoqi@0 61 // Initialize array sizes
aoqi@0 62 _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);
aoqi@0 63 _virtual_operands.trunc_to(0);
aoqi@0 64 _other_operands.at_put_grow(max_vregs - 1, NULL, NULL);
aoqi@0 65 _other_operands.trunc_to(0);
aoqi@0 66 _vreg_table.at_put_grow(max_vregs - 1, NULL, NULL);
aoqi@0 67 _vreg_table.trunc_to(0);
aoqi@0 68 }
aoqi@0 69
aoqi@0 70
aoqi@0 71
aoqi@0 72 //--------------------------------------------------------------
aoqi@0 73 // PhiResolver
aoqi@0 74
aoqi@0 75 // Resolves cycles:
aoqi@0 76 //
aoqi@0 77 // r1 := r2 becomes temp := r1
aoqi@0 78 // r2 := r1 r1 := r2
aoqi@0 79 // r2 := temp
aoqi@0 80 // and orders moves:
aoqi@0 81 //
aoqi@0 82 // r2 := r3 becomes r1 := r2
aoqi@0 83 // r1 := r2 r2 := r3
aoqi@0 84
aoqi@0 85 PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs)
aoqi@0 86 : _gen(gen)
aoqi@0 87 , _state(gen->resolver_state())
aoqi@0 88 , _temp(LIR_OprFact::illegalOpr)
aoqi@0 89 {
aoqi@0 90 // reinitialize the shared state arrays
aoqi@0 91 _state.reset(max_vregs);
aoqi@0 92 }
aoqi@0 93
aoqi@0 94
aoqi@0 95 void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) {
aoqi@0 96 assert(src->is_valid(), "");
aoqi@0 97 assert(dest->is_valid(), "");
aoqi@0 98 __ move(src, dest);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101
aoqi@0 102 void PhiResolver::move_temp_to(LIR_Opr dest) {
aoqi@0 103 assert(_temp->is_valid(), "");
aoqi@0 104 emit_move(_temp, dest);
aoqi@0 105 NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr);
aoqi@0 106 }
aoqi@0 107
aoqi@0 108
aoqi@0 109 void PhiResolver::move_to_temp(LIR_Opr src) {
aoqi@0 110 assert(_temp->is_illegal(), "");
aoqi@0 111 _temp = _gen->new_register(src->type());
aoqi@0 112 emit_move(src, _temp);
aoqi@0 113 }
aoqi@0 114
aoqi@0 115
aoqi@0 116 // Traverse assignment graph in depth first order and generate moves in post order
aoqi@0 117 // ie. two assignments: b := c, a := b start with node c:
aoqi@0 118 // Call graph: move(NULL, c) -> move(c, b) -> move(b, a)
aoqi@0 119 // Generates moves in this order: move b to a and move c to b
aoqi@0 120 // ie. cycle a := b, b := a start with node a
aoqi@0 121 // Call graph: move(NULL, a) -> move(a, b) -> move(b, a)
aoqi@0 122 // Generates moves in this order: move b to temp, move a to b, move temp to a
aoqi@0 123 void PhiResolver::move(ResolveNode* src, ResolveNode* dest) {
aoqi@0 124 if (!dest->visited()) {
aoqi@0 125 dest->set_visited();
aoqi@0 126 for (int i = dest->no_of_destinations()-1; i >= 0; i --) {
aoqi@0 127 move(dest, dest->destination_at(i));
aoqi@0 128 }
aoqi@0 129 } else if (!dest->start_node()) {
aoqi@0 130 // cylce in graph detected
aoqi@0 131 assert(_loop == NULL, "only one loop valid!");
aoqi@0 132 _loop = dest;
aoqi@0 133 move_to_temp(src->operand());
aoqi@0 134 return;
aoqi@0 135 } // else dest is a start node
aoqi@0 136
aoqi@0 137 if (!dest->assigned()) {
aoqi@0 138 if (_loop == dest) {
aoqi@0 139 move_temp_to(dest->operand());
aoqi@0 140 dest->set_assigned();
aoqi@0 141 } else if (src != NULL) {
aoqi@0 142 emit_move(src->operand(), dest->operand());
aoqi@0 143 dest->set_assigned();
aoqi@0 144 }
aoqi@0 145 }
aoqi@0 146 }
aoqi@0 147
aoqi@0 148
aoqi@0 149 PhiResolver::~PhiResolver() {
aoqi@0 150 int i;
aoqi@0 151 // resolve any cycles in moves from and to virtual registers
aoqi@0 152 for (i = virtual_operands().length() - 1; i >= 0; i --) {
aoqi@0 153 ResolveNode* node = virtual_operands()[i];
aoqi@0 154 if (!node->visited()) {
aoqi@0 155 _loop = NULL;
aoqi@0 156 move(NULL, node);
aoqi@0 157 node->set_start_node();
aoqi@0 158 assert(_temp->is_illegal(), "move_temp_to() call missing");
aoqi@0 159 }
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 // generate move for move from non virtual register to abitrary destination
aoqi@0 163 for (i = other_operands().length() - 1; i >= 0; i --) {
aoqi@0 164 ResolveNode* node = other_operands()[i];
aoqi@0 165 for (int j = node->no_of_destinations() - 1; j >= 0; j --) {
aoqi@0 166 emit_move(node->operand(), node->destination_at(j)->operand());
aoqi@0 167 }
aoqi@0 168 }
aoqi@0 169 }
aoqi@0 170
aoqi@0 171
aoqi@0 172 ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) {
aoqi@0 173 ResolveNode* node;
aoqi@0 174 if (opr->is_virtual()) {
aoqi@0 175 int vreg_num = opr->vreg_number();
aoqi@0 176 node = vreg_table().at_grow(vreg_num, NULL);
aoqi@0 177 assert(node == NULL || node->operand() == opr, "");
aoqi@0 178 if (node == NULL) {
aoqi@0 179 node = new ResolveNode(opr);
aoqi@0 180 vreg_table()[vreg_num] = node;
aoqi@0 181 }
aoqi@0 182 // Make sure that all virtual operands show up in the list when
aoqi@0 183 // they are used as the source of a move.
aoqi@0 184 if (source && !virtual_operands().contains(node)) {
aoqi@0 185 virtual_operands().append(node);
aoqi@0 186 }
aoqi@0 187 } else {
aoqi@0 188 assert(source, "");
aoqi@0 189 node = new ResolveNode(opr);
aoqi@0 190 other_operands().append(node);
aoqi@0 191 }
aoqi@0 192 return node;
aoqi@0 193 }
aoqi@0 194
aoqi@0 195
aoqi@0 196 void PhiResolver::move(LIR_Opr src, LIR_Opr dest) {
aoqi@0 197 assert(dest->is_virtual(), "");
aoqi@0 198 // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr();
aoqi@0 199 assert(src->is_valid(), "");
aoqi@0 200 assert(dest->is_valid(), "");
aoqi@0 201 ResolveNode* source = source_node(src);
aoqi@0 202 source->append(destination_node(dest));
aoqi@0 203 }
aoqi@0 204
aoqi@0 205
aoqi@0 206 //--------------------------------------------------------------
aoqi@0 207 // LIRItem
aoqi@0 208
aoqi@0 209 void LIRItem::set_result(LIR_Opr opr) {
aoqi@0 210 assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change");
aoqi@0 211 value()->set_operand(opr);
aoqi@0 212
aoqi@0 213 if (opr->is_virtual()) {
aoqi@0 214 _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL);
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 _result = opr;
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 void LIRItem::load_item() {
aoqi@0 221 if (result()->is_illegal()) {
aoqi@0 222 // update the items result
aoqi@0 223 _result = value()->operand();
aoqi@0 224 }
aoqi@0 225 if (!result()->is_register()) {
aoqi@0 226 LIR_Opr reg = _gen->new_register(value()->type());
aoqi@0 227 __ move(result(), reg);
aoqi@0 228 if (result()->is_constant()) {
aoqi@0 229 _result = reg;
aoqi@0 230 } else {
aoqi@0 231 set_result(reg);
aoqi@0 232 }
aoqi@0 233 }
aoqi@0 234 }
aoqi@0 235
aoqi@0 236
aoqi@0 237 void LIRItem::load_for_store(BasicType type) {
aoqi@0 238 if (_gen->can_store_as_constant(value(), type)) {
aoqi@0 239 _result = value()->operand();
aoqi@0 240 if (!_result->is_constant()) {
aoqi@0 241 _result = LIR_OprFact::value_type(value()->type());
aoqi@0 242 }
aoqi@0 243 } else if (type == T_BYTE || type == T_BOOLEAN) {
aoqi@0 244 load_byte_item();
aoqi@0 245 } else {
aoqi@0 246 load_item();
aoqi@0 247 }
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 void LIRItem::load_item_force(LIR_Opr reg) {
aoqi@0 251 LIR_Opr r = result();
aoqi@0 252 if (r != reg) {
aoqi@0 253 #if !defined(ARM) && !defined(E500V2)
aoqi@0 254 if (r->type() != reg->type()) {
aoqi@0 255 // moves between different types need an intervening spill slot
aoqi@0 256 r = _gen->force_to_spill(r, reg->type());
aoqi@0 257 }
aoqi@0 258 #endif
aoqi@0 259 __ move(r, reg);
aoqi@0 260 _result = reg;
aoqi@0 261 }
aoqi@0 262 }
aoqi@0 263
aoqi@0 264 ciObject* LIRItem::get_jobject_constant() const {
aoqi@0 265 ObjectType* oc = type()->as_ObjectType();
aoqi@0 266 if (oc) {
aoqi@0 267 return oc->constant_value();
aoqi@0 268 }
aoqi@0 269 return NULL;
aoqi@0 270 }
aoqi@0 271
aoqi@0 272
aoqi@0 273 jint LIRItem::get_jint_constant() const {
aoqi@0 274 assert(is_constant() && value() != NULL, "");
aoqi@0 275 assert(type()->as_IntConstant() != NULL, "type check");
aoqi@0 276 return type()->as_IntConstant()->value();
aoqi@0 277 }
aoqi@0 278
aoqi@0 279
aoqi@0 280 jint LIRItem::get_address_constant() const {
aoqi@0 281 assert(is_constant() && value() != NULL, "");
aoqi@0 282 assert(type()->as_AddressConstant() != NULL, "type check");
aoqi@0 283 return type()->as_AddressConstant()->value();
aoqi@0 284 }
aoqi@0 285
aoqi@0 286
aoqi@0 287 jfloat LIRItem::get_jfloat_constant() const {
aoqi@0 288 assert(is_constant() && value() != NULL, "");
aoqi@0 289 assert(type()->as_FloatConstant() != NULL, "type check");
aoqi@0 290 return type()->as_FloatConstant()->value();
aoqi@0 291 }
aoqi@0 292
aoqi@0 293
aoqi@0 294 jdouble LIRItem::get_jdouble_constant() const {
aoqi@0 295 assert(is_constant() && value() != NULL, "");
aoqi@0 296 assert(type()->as_DoubleConstant() != NULL, "type check");
aoqi@0 297 return type()->as_DoubleConstant()->value();
aoqi@0 298 }
aoqi@0 299
aoqi@0 300
aoqi@0 301 jlong LIRItem::get_jlong_constant() const {
aoqi@0 302 assert(is_constant() && value() != NULL, "");
aoqi@0 303 assert(type()->as_LongConstant() != NULL, "type check");
aoqi@0 304 return type()->as_LongConstant()->value();
aoqi@0 305 }
aoqi@0 306
aoqi@0 307
aoqi@0 308
aoqi@0 309 //--------------------------------------------------------------
aoqi@0 310
aoqi@0 311
aoqi@0 312 void LIRGenerator::init() {
aoqi@0 313 _bs = Universe::heap()->barrier_set();
aoqi@1 314 #ifdef MIPS64
aoqi@8865 315 assert(_bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
aoqi@8865 316 CardTableModRefBS* ct = (CardTableModRefBS*)_bs;
aoqi@8865 317 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@8865 318 //_card_table_base = new LIR_Const((intptr_t)ct->byte_map_base);
aoqi@8865 319 // //FIXME, untested in 32bit. by aoqi
aoqi@8865 320 _card_table_base = new LIR_Const(ct->byte_map_base);
aoqi@1 321 #endif
aoqi@0 322 }
aoqi@0 323
aoqi@0 324
aoqi@0 325 void LIRGenerator::block_do_prolog(BlockBegin* block) {
aoqi@0 326 #ifndef PRODUCT
aoqi@0 327 if (PrintIRWithLIR) {
aoqi@0 328 block->print();
aoqi@0 329 }
aoqi@0 330 #endif
aoqi@0 331
aoqi@0 332 // set up the list of LIR instructions
aoqi@0 333 assert(block->lir() == NULL, "LIR list already computed for this block");
aoqi@0 334 _lir = new LIR_List(compilation(), block);
aoqi@0 335 block->set_lir(_lir);
aoqi@0 336
aoqi@0 337 __ branch_destination(block->label());
aoqi@0 338
aoqi@0 339 if (LIRTraceExecution &&
aoqi@0 340 Compilation::current()->hir()->start()->block_id() != block->block_id() &&
aoqi@0 341 !block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 342 assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");
aoqi@0 343 trace_block_entry(block);
aoqi@0 344 }
aoqi@0 345 }
aoqi@0 346
aoqi@0 347
aoqi@0 348 void LIRGenerator::block_do_epilog(BlockBegin* block) {
aoqi@0 349 #ifndef PRODUCT
aoqi@0 350 if (PrintIRWithLIR) {
aoqi@0 351 tty->cr();
aoqi@0 352 }
aoqi@0 353 #endif
aoqi@0 354
aoqi@0 355 // LIR_Opr for unpinned constants shouldn't be referenced by other
aoqi@0 356 // blocks so clear them out after processing the block.
aoqi@0 357 for (int i = 0; i < _unpinned_constants.length(); i++) {
aoqi@0 358 _unpinned_constants.at(i)->clear_operand();
aoqi@0 359 }
aoqi@0 360 _unpinned_constants.trunc_to(0);
aoqi@0 361
aoqi@0 362 // clear our any registers for other local constants
aoqi@0 363 _constants.trunc_to(0);
aoqi@0 364 _reg_for_constants.trunc_to(0);
aoqi@0 365 }
aoqi@0 366
aoqi@0 367
aoqi@0 368 void LIRGenerator::block_do(BlockBegin* block) {
aoqi@0 369 CHECK_BAILOUT();
aoqi@0 370
aoqi@0 371 block_do_prolog(block);
aoqi@0 372 set_block(block);
aoqi@0 373
aoqi@0 374 for (Instruction* instr = block; instr != NULL; instr = instr->next()) {
aoqi@0 375 if (instr->is_pinned()) do_root(instr);
aoqi@0 376 }
aoqi@0 377
aoqi@0 378 set_block(NULL);
aoqi@0 379 block_do_epilog(block);
aoqi@0 380 }
aoqi@0 381
aoqi@0 382
aoqi@0 383 //-------------------------LIRGenerator-----------------------------
aoqi@0 384
aoqi@0 385 // This is where the tree-walk starts; instr must be root;
aoqi@0 386 void LIRGenerator::do_root(Value instr) {
aoqi@0 387 CHECK_BAILOUT();
aoqi@0 388
aoqi@0 389 InstructionMark im(compilation(), instr);
aoqi@0 390
aoqi@0 391 assert(instr->is_pinned(), "use only with roots");
aoqi@0 392 assert(instr->subst() == instr, "shouldn't have missed substitution");
aoqi@0 393
aoqi@0 394 instr->visit(this);
aoqi@0 395
aoqi@0 396 assert(!instr->has_uses() || instr->operand()->is_valid() ||
aoqi@0 397 instr->as_Constant() != NULL || bailed_out(), "invalid item set");
aoqi@0 398 }
aoqi@0 399
aoqi@0 400
aoqi@0 401 // This is called for each node in tree; the walk stops if a root is reached
aoqi@0 402 void LIRGenerator::walk(Value instr) {
aoqi@0 403 InstructionMark im(compilation(), instr);
aoqi@0 404 //stop walk when encounter a root
aoqi@0 405 if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) {
aoqi@0 406 assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited");
aoqi@0 407 } else {
aoqi@0 408 assert(instr->subst() == instr, "shouldn't have missed substitution");
aoqi@0 409 instr->visit(this);
aoqi@0 410 // assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use");
aoqi@0 411 }
aoqi@0 412 }
aoqi@0 413
aoqi@0 414
aoqi@0 415 CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {
aoqi@0 416 assert(state != NULL, "state must be defined");
aoqi@0 417
aoqi@0 418 #ifndef PRODUCT
aoqi@0 419 state->verify();
aoqi@0 420 #endif
aoqi@0 421
aoqi@0 422 ValueStack* s = state;
aoqi@0 423 for_each_state(s) {
aoqi@0 424 if (s->kind() == ValueStack::EmptyExceptionState) {
aoqi@0 425 assert(s->stack_size() == 0 && s->locals_size() == 0 && (s->locks_size() == 0 || s->locks_size() == 1), "state must be empty");
aoqi@0 426 continue;
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 int index;
aoqi@0 430 Value value;
aoqi@0 431 for_each_stack_value(s, index, value) {
aoqi@0 432 assert(value->subst() == value, "missed substitution");
aoqi@0 433 if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
aoqi@0 434 walk(value);
aoqi@0 435 assert(value->operand()->is_valid(), "must be evaluated now");
aoqi@0 436 }
aoqi@0 437 }
aoqi@0 438
aoqi@0 439 int bci = s->bci();
aoqi@0 440 IRScope* scope = s->scope();
aoqi@0 441 ciMethod* method = scope->method();
aoqi@0 442
aoqi@0 443 MethodLivenessResult liveness = method->liveness_at_bci(bci);
aoqi@0 444 if (bci == SynchronizationEntryBCI) {
aoqi@0 445 if (x->as_ExceptionObject() || x->as_Throw()) {
aoqi@0 446 // all locals are dead on exit from the synthetic unlocker
aoqi@0 447 liveness.clear();
aoqi@0 448 } else {
aoqi@0 449 assert(x->as_MonitorEnter() || x->as_ProfileInvoke(), "only other cases are MonitorEnter and ProfileInvoke");
aoqi@0 450 }
aoqi@0 451 }
aoqi@0 452 if (!liveness.is_valid()) {
aoqi@0 453 // Degenerate or breakpointed method.
aoqi@0 454 bailout("Degenerate or breakpointed method");
aoqi@0 455 } else {
aoqi@0 456 assert((int)liveness.size() == s->locals_size(), "error in use of liveness");
aoqi@0 457 for_each_local_value(s, index, value) {
aoqi@0 458 assert(value->subst() == value, "missed substition");
aoqi@0 459 if (liveness.at(index) && !value->type()->is_illegal()) {
aoqi@0 460 if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
aoqi@0 461 walk(value);
aoqi@0 462 assert(value->operand()->is_valid(), "must be evaluated now");
aoqi@0 463 }
aoqi@0 464 } else {
aoqi@0 465 // NULL out this local so that linear scan can assume that all non-NULL values are live.
aoqi@0 466 s->invalidate_local(index);
aoqi@0 467 }
aoqi@0 468 }
aoqi@0 469 }
aoqi@0 470 }
aoqi@0 471
aoqi@0 472 return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException));
aoqi@0 473 }
aoqi@0 474
aoqi@0 475
aoqi@0 476 CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {
aoqi@0 477 return state_for(x, x->exception_state());
aoqi@0 478 }
aoqi@0 479
aoqi@0 480
rbackman@7058 481 void LIRGenerator::klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve) {
rbackman@7058 482 /* C2 relies on constant pool entries being resolved (ciTypeFlow), so if TieredCompilation
rbackman@7058 483 * is active and the class hasn't yet been resolved we need to emit a patch that resolves
rbackman@7058 484 * the class. */
rbackman@7058 485 if ((TieredCompilation && need_resolve) || !obj->is_loaded() || PatchALot) {
aoqi@0 486 assert(info != NULL, "info must be set if class is not loaded");
aoqi@0 487 __ klass2reg_patch(NULL, r, info);
aoqi@0 488 } else {
aoqi@0 489 // no patching needed
aoqi@0 490 __ metadata2reg(obj->constant_encoding(), r);
aoqi@0 491 }
aoqi@0 492 }
aoqi@0 493
aoqi@0 494
aoqi@0 495 void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index,
aoqi@0 496 CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) {
aoqi@0 497 CodeStub* stub = new RangeCheckStub(range_check_info, index);
aoqi@0 498 if (index->is_constant()) {
aoqi@1 499 #ifndef MIPS64
aoqi@0 500 cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(),
aoqi@0 501 index->as_jint(), null_check_info);
aoqi@0 502 __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
aoqi@1 503 #else
aoqi@8860 504 LIR_Opr left = LIR_OprFact::address(new LIR_Address(array, arrayOopDesc::length_offset_in_bytes(), T_INT));
aoqi@8860 505 LIR_Opr right = LIR_OprFact::intConst(index->as_jint());
aoqi@8860 506 __ null_check_for_branch(lir_cond_belowEqual, left, right, null_check_info);
aoqi@8860 507 __ branch(lir_cond_belowEqual, left, right ,T_INT, stub); // forward branch
aoqi@1 508 #endif
aoqi@0 509 } else {
aoqi@1 510 #ifndef MIPS64
aoqi@0 511 cmp_reg_mem(lir_cond_aboveEqual, index, array,
aoqi@0 512 arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info);
aoqi@0 513 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
aoqi@1 514 #else
aoqi@8860 515 LIR_Opr left = index;
aoqi@8860 516 LIR_Opr right = LIR_OprFact::address(new LIR_Address( array, arrayOopDesc::length_offset_in_bytes(), T_INT));
aoqi@8860 517 __ null_check_for_branch(lir_cond_aboveEqual, left, right, null_check_info);
aoqi@8860 518 __ branch(lir_cond_aboveEqual,left, right ,T_INT, stub); // forward branch
aoqi@1 519 #endif
aoqi@0 520 }
aoqi@0 521 }
aoqi@0 522
aoqi@0 523
aoqi@0 524 void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {
aoqi@0 525 CodeStub* stub = new RangeCheckStub(info, index, true);
aoqi@0 526 if (index->is_constant()) {
aoqi@1 527 #ifndef MIPS64
aoqi@0 528 cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info);
aoqi@0 529 __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
aoqi@1 530 #else
aoqi@8865 531 LIR_Opr left = LIR_OprFact::address(new LIR_Address(buffer, java_nio_Buffer::limit_offset(),T_INT));
aoqi@8865 532 LIR_Opr right = LIR_OprFact::intConst(index->as_jint());
aoqi@8865 533 __ null_check_for_branch(lir_cond_belowEqual, left, right, info);
aoqi@8865 534 __ branch(lir_cond_belowEqual,left, right ,T_INT, stub); // forward branch
aoqi@1 535 #endif
aoqi@0 536 } else {
aoqi@1 537 #ifndef MIPS64
aoqi@0 538 cmp_reg_mem(lir_cond_aboveEqual, index, buffer,
aoqi@0 539 java_nio_Buffer::limit_offset(), T_INT, info);
aoqi@0 540 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
aoqi@1 541 #else
aoqi@8860 542 LIR_Opr left = index;
aoqi@8860 543 LIR_Opr right = LIR_OprFact::address(new LIR_Address( buffer, java_nio_Buffer::limit_offset(), T_INT));
aoqi@8860 544 __ null_check_for_branch(lir_cond_aboveEqual, left, right, info);
aoqi@8860 545 __ branch(lir_cond_aboveEqual,left, right ,T_INT, stub); // forward branch
aoqi@1 546 #endif
aoqi@0 547 }
aoqi@0 548 __ move(index, result);
aoqi@0 549 }
aoqi@0 550
aoqi@0 551
aoqi@0 552
aoqi@0 553 void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) {
aoqi@0 554 LIR_Opr result_op = result;
aoqi@0 555 LIR_Opr left_op = left;
aoqi@0 556 LIR_Opr right_op = right;
aoqi@0 557
aoqi@0 558 if (TwoOperandLIRForm && left_op != result_op) {
aoqi@0 559 assert(right_op != result_op, "malformed");
aoqi@0 560 __ move(left_op, result_op);
aoqi@0 561 left_op = result_op;
aoqi@0 562 }
aoqi@0 563
aoqi@0 564 switch(code) {
aoqi@0 565 case Bytecodes::_dadd:
aoqi@0 566 case Bytecodes::_fadd:
aoqi@0 567 case Bytecodes::_ladd:
aoqi@0 568 case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break;
aoqi@0 569 case Bytecodes::_fmul:
aoqi@0 570 case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break;
aoqi@0 571
aoqi@0 572 case Bytecodes::_dmul:
aoqi@0 573 {
aoqi@0 574 if (is_strictfp) {
aoqi@0 575 __ mul_strictfp(left_op, right_op, result_op, tmp_op); break;
aoqi@0 576 } else {
aoqi@0 577 __ mul(left_op, right_op, result_op); break;
aoqi@0 578 }
aoqi@0 579 }
aoqi@0 580 break;
aoqi@0 581
aoqi@0 582 case Bytecodes::_imul:
aoqi@0 583 {
aoqi@0 584 bool did_strength_reduce = false;
aoqi@0 585
aoqi@0 586 if (right->is_constant()) {
aoqi@0 587 int c = right->as_jint();
aoqi@0 588 if (is_power_of_2(c)) {
aoqi@0 589 // do not need tmp here
aoqi@0 590 __ shift_left(left_op, exact_log2(c), result_op);
aoqi@0 591 did_strength_reduce = true;
aoqi@0 592 } else {
aoqi@0 593 did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);
aoqi@0 594 }
aoqi@0 595 }
aoqi@0 596 // we couldn't strength reduce so just emit the multiply
aoqi@0 597 if (!did_strength_reduce) {
aoqi@0 598 __ mul(left_op, right_op, result_op);
aoqi@0 599 }
aoqi@0 600 }
aoqi@0 601 break;
aoqi@0 602
aoqi@0 603 case Bytecodes::_dsub:
aoqi@0 604 case Bytecodes::_fsub:
aoqi@0 605 case Bytecodes::_lsub:
aoqi@0 606 case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break;
aoqi@0 607
aoqi@0 608 case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break;
aoqi@0 609 // ldiv and lrem are implemented with a direct runtime call
aoqi@0 610
aoqi@0 611 case Bytecodes::_ddiv:
aoqi@0 612 {
aoqi@0 613 if (is_strictfp) {
aoqi@0 614 __ div_strictfp (left_op, right_op, result_op, tmp_op); break;
aoqi@0 615 } else {
aoqi@0 616 __ div (left_op, right_op, result_op); break;
aoqi@0 617 }
aoqi@0 618 }
aoqi@0 619 break;
aoqi@0 620
aoqi@0 621 case Bytecodes::_drem:
aoqi@0 622 case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break;
aoqi@0 623
aoqi@0 624 default: ShouldNotReachHere();
aoqi@0 625 }
aoqi@0 626 }
aoqi@0 627
aoqi@0 628
aoqi@0 629 void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) {
aoqi@0 630 arithmetic_op(code, result, left, right, false, tmp);
aoqi@0 631 }
aoqi@0 632
aoqi@0 633
aoqi@0 634 void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) {
aoqi@0 635 arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info);
aoqi@0 636 }
aoqi@0 637
aoqi@0 638
aoqi@0 639 void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp) {
aoqi@0 640 arithmetic_op(code, result, left, right, is_strictfp, tmp);
aoqi@0 641 }
aoqi@0 642
aoqi@0 643
aoqi@0 644 void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) {
aoqi@0 645 if (TwoOperandLIRForm && value != result_op) {
aoqi@0 646 assert(count != result_op, "malformed");
aoqi@0 647 __ move(value, result_op);
aoqi@0 648 value = result_op;
aoqi@0 649 }
aoqi@0 650
aoqi@0 651 assert(count->is_constant() || count->is_register(), "must be");
aoqi@0 652 switch(code) {
aoqi@0 653 case Bytecodes::_ishl:
aoqi@0 654 case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break;
aoqi@0 655 case Bytecodes::_ishr:
aoqi@0 656 case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break;
aoqi@0 657 case Bytecodes::_iushr:
aoqi@0 658 case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break;
aoqi@0 659 default: ShouldNotReachHere();
aoqi@0 660 }
aoqi@0 661 }
aoqi@0 662
aoqi@0 663
aoqi@0 664 void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) {
aoqi@0 665 if (TwoOperandLIRForm && left_op != result_op) {
aoqi@0 666 assert(right_op != result_op, "malformed");
aoqi@0 667 __ move(left_op, result_op);
aoqi@0 668 left_op = result_op;
aoqi@0 669 }
aoqi@0 670
aoqi@0 671 switch(code) {
aoqi@0 672 case Bytecodes::_iand:
aoqi@0 673 case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break;
aoqi@0 674
aoqi@0 675 case Bytecodes::_ior:
aoqi@0 676 case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break;
aoqi@0 677
aoqi@0 678 case Bytecodes::_ixor:
aoqi@0 679 case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break;
aoqi@0 680
aoqi@0 681 default: ShouldNotReachHere();
aoqi@0 682 }
aoqi@0 683 }
aoqi@0 684
aoqi@0 685
aoqi@0 686 void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) {
aoqi@0 687 if (!GenerateSynchronizationCode) return;
aoqi@0 688 // for slow path, use debug info for state after successful locking
aoqi@0 689 CodeStub* slow_path = new MonitorEnterStub(object, lock, info);
aoqi@0 690 __ load_stack_address_monitor(monitor_no, lock);
aoqi@0 691 // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter
aoqi@0 692 __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception);
aoqi@0 693 }
aoqi@0 694
aoqi@0 695
aoqi@0 696 void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) {
aoqi@0 697 if (!GenerateSynchronizationCode) return;
aoqi@0 698 // setup registers
aoqi@0 699 LIR_Opr hdr = lock;
aoqi@0 700 lock = new_hdr;
aoqi@0 701 CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no);
aoqi@0 702 __ load_stack_address_monitor(monitor_no, lock);
aoqi@0 703 __ unlock_object(hdr, object, lock, scratch, slow_path);
aoqi@0 704 }
aoqi@0 705
rbackman@7058 706 #ifndef PRODUCT
rbackman@7058 707 void LIRGenerator::print_if_not_loaded(const NewInstance* new_instance) {
rbackman@7058 708 if (PrintNotLoaded && !new_instance->klass()->is_loaded()) {
rbackman@7058 709 tty->print_cr(" ###class not loaded at new bci %d", new_instance->printable_bci());
rbackman@7058 710 } else if (PrintNotLoaded && (TieredCompilation && new_instance->is_unresolved())) {
rbackman@7058 711 tty->print_cr(" ###class not resolved at new bci %d", new_instance->printable_bci());
rbackman@7058 712 }
rbackman@7058 713 }
rbackman@7058 714 #endif
rbackman@7058 715
aoqi@1 716 #ifndef MIPS64
rbackman@7058 717 void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) {
aoqi@1 718 #else
aoqi@8865 719 void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3,
aoqi@8865 720 LIR_Opr scratch4, LIR_Opr scratch5, LIR_Opr scratch6,LIR_Opr klass_reg, CodeEmitInfo* info) {
aoqi@1 721 #endif
rbackman@7058 722 klass2reg_with_patching(klass_reg, klass, info, is_unresolved);
aoqi@0 723 // If klass is not loaded we do not know if the klass has finalizers:
aoqi@0 724 if (UseFastNewInstance && klass->is_loaded()
aoqi@0 725 && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) {
aoqi@0 726
aoqi@0 727 Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id;
aoqi@0 728
aoqi@0 729 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id);
aoqi@0 730
aoqi@0 731 assert(klass->is_loaded(), "must be loaded");
aoqi@0 732 // allocate space for instance
aoqi@0 733 assert(klass->size_helper() >= 0, "illegal instance size");
aoqi@0 734 const int instance_size = align_object_size(klass->size_helper());
aoqi@1 735 #ifndef MIPS64
aoqi@0 736 __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4,
aoqi@0 737 oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);
aoqi@1 738 #else
aoqi@1 739 __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4, scratch5, scratch6,
aoqi@8860 740 oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);
aoqi@1 741
aoqi@1 742 #endif
aoqi@0 743 } else {
aoqi@0 744 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id);
aoqi@1 745 #ifndef MIPS64
aoqi@0 746 __ branch(lir_cond_always, T_ILLEGAL, slow_path);
aoqi@0 747 __ branch_destination(slow_path->continuation());
aoqi@1 748 #else
aoqi@1 749 __ branch(lir_cond_always, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, T_ILLEGAL, slow_path);
aoqi@1 750 __ branch_destination(slow_path->continuation());
aoqi@1 751 #endif
aoqi@0 752 }
aoqi@0 753 }
aoqi@0 754
aoqi@0 755
aoqi@0 756 static bool is_constant_zero(Instruction* inst) {
aoqi@0 757 IntConstant* c = inst->type()->as_IntConstant();
aoqi@0 758 if (c) {
aoqi@0 759 return (c->value() == 0);
aoqi@0 760 }
aoqi@0 761 return false;
aoqi@0 762 }
aoqi@0 763
aoqi@0 764
aoqi@0 765 static bool positive_constant(Instruction* inst) {
aoqi@0 766 IntConstant* c = inst->type()->as_IntConstant();
aoqi@0 767 if (c) {
aoqi@0 768 return (c->value() >= 0);
aoqi@0 769 }
aoqi@0 770 return false;
aoqi@0 771 }
aoqi@0 772
aoqi@0 773
aoqi@0 774 static ciArrayKlass* as_array_klass(ciType* type) {
aoqi@0 775 if (type != NULL && type->is_array_klass() && type->is_loaded()) {
aoqi@0 776 return (ciArrayKlass*)type;
aoqi@0 777 } else {
aoqi@0 778 return NULL;
aoqi@0 779 }
aoqi@0 780 }
aoqi@0 781
aoqi@0 782 static ciType* phi_declared_type(Phi* phi) {
aoqi@0 783 ciType* t = phi->operand_at(0)->declared_type();
aoqi@0 784 if (t == NULL) {
aoqi@0 785 return NULL;
aoqi@0 786 }
aoqi@0 787 for(int i = 1; i < phi->operand_count(); i++) {
aoqi@0 788 if (t != phi->operand_at(i)->declared_type()) {
aoqi@0 789 return NULL;
aoqi@0 790 }
aoqi@0 791 }
aoqi@0 792 return t;
aoqi@0 793 }
aoqi@0 794
aoqi@0 795 void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) {
aoqi@0 796 Instruction* src = x->argument_at(0);
aoqi@0 797 Instruction* src_pos = x->argument_at(1);
aoqi@0 798 Instruction* dst = x->argument_at(2);
aoqi@0 799 Instruction* dst_pos = x->argument_at(3);
aoqi@0 800 Instruction* length = x->argument_at(4);
aoqi@0 801
aoqi@0 802 // first try to identify the likely type of the arrays involved
aoqi@0 803 ciArrayKlass* expected_type = NULL;
aoqi@0 804 bool is_exact = false, src_objarray = false, dst_objarray = false;
aoqi@0 805 {
aoqi@0 806 ciArrayKlass* src_exact_type = as_array_klass(src->exact_type());
aoqi@0 807 ciArrayKlass* src_declared_type = as_array_klass(src->declared_type());
aoqi@0 808 Phi* phi;
aoqi@0 809 if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) {
aoqi@0 810 src_declared_type = as_array_klass(phi_declared_type(phi));
aoqi@0 811 }
aoqi@0 812 ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type());
aoqi@0 813 ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type());
aoqi@0 814 if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) {
aoqi@0 815 dst_declared_type = as_array_klass(phi_declared_type(phi));
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 if (src_exact_type != NULL && src_exact_type == dst_exact_type) {
aoqi@0 819 // the types exactly match so the type is fully known
aoqi@0 820 is_exact = true;
aoqi@0 821 expected_type = src_exact_type;
aoqi@0 822 } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) {
aoqi@0 823 ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type;
aoqi@0 824 ciArrayKlass* src_type = NULL;
aoqi@0 825 if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) {
aoqi@0 826 src_type = (ciArrayKlass*) src_exact_type;
aoqi@0 827 } else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) {
aoqi@0 828 src_type = (ciArrayKlass*) src_declared_type;
aoqi@0 829 }
aoqi@0 830 if (src_type != NULL) {
aoqi@0 831 if (src_type->element_type()->is_subtype_of(dst_type->element_type())) {
aoqi@0 832 is_exact = true;
aoqi@0 833 expected_type = dst_type;
aoqi@0 834 }
aoqi@0 835 }
aoqi@0 836 }
aoqi@0 837 // at least pass along a good guess
aoqi@0 838 if (expected_type == NULL) expected_type = dst_exact_type;
aoqi@0 839 if (expected_type == NULL) expected_type = src_declared_type;
aoqi@0 840 if (expected_type == NULL) expected_type = dst_declared_type;
aoqi@0 841
aoqi@0 842 src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass());
aoqi@0 843 dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass());
aoqi@0 844 }
aoqi@0 845
aoqi@0 846 // if a probable array type has been identified, figure out if any
aoqi@0 847 // of the required checks for a fast case can be elided.
aoqi@0 848 int flags = LIR_OpArrayCopy::all_flags;
aoqi@0 849
aoqi@0 850 if (!src_objarray)
aoqi@0 851 flags &= ~LIR_OpArrayCopy::src_objarray;
aoqi@0 852 if (!dst_objarray)
aoqi@0 853 flags &= ~LIR_OpArrayCopy::dst_objarray;
aoqi@0 854
aoqi@0 855 if (!x->arg_needs_null_check(0))
aoqi@0 856 flags &= ~LIR_OpArrayCopy::src_null_check;
aoqi@0 857 if (!x->arg_needs_null_check(2))
aoqi@0 858 flags &= ~LIR_OpArrayCopy::dst_null_check;
aoqi@0 859
aoqi@0 860
aoqi@0 861 if (expected_type != NULL) {
aoqi@0 862 Value length_limit = NULL;
aoqi@0 863
aoqi@0 864 IfOp* ifop = length->as_IfOp();
aoqi@0 865 if (ifop != NULL) {
aoqi@0 866 // look for expressions like min(v, a.length) which ends up as
aoqi@0 867 // x > y ? y : x or x >= y ? y : x
aoqi@0 868 if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) &&
aoqi@0 869 ifop->x() == ifop->fval() &&
aoqi@0 870 ifop->y() == ifop->tval()) {
aoqi@0 871 length_limit = ifop->y();
aoqi@0 872 }
aoqi@0 873 }
aoqi@0 874
aoqi@0 875 // try to skip null checks and range checks
aoqi@0 876 NewArray* src_array = src->as_NewArray();
aoqi@0 877 if (src_array != NULL) {
aoqi@0 878 flags &= ~LIR_OpArrayCopy::src_null_check;
aoqi@0 879 if (length_limit != NULL &&
aoqi@0 880 src_array->length() == length_limit &&
aoqi@0 881 is_constant_zero(src_pos)) {
aoqi@0 882 flags &= ~LIR_OpArrayCopy::src_range_check;
aoqi@0 883 }
aoqi@0 884 }
aoqi@0 885
aoqi@0 886 NewArray* dst_array = dst->as_NewArray();
aoqi@0 887 if (dst_array != NULL) {
aoqi@0 888 flags &= ~LIR_OpArrayCopy::dst_null_check;
aoqi@0 889 if (length_limit != NULL &&
aoqi@0 890 dst_array->length() == length_limit &&
aoqi@0 891 is_constant_zero(dst_pos)) {
aoqi@0 892 flags &= ~LIR_OpArrayCopy::dst_range_check;
aoqi@0 893 }
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 // check from incoming constant values
aoqi@0 897 if (positive_constant(src_pos))
aoqi@0 898 flags &= ~LIR_OpArrayCopy::src_pos_positive_check;
aoqi@0 899 if (positive_constant(dst_pos))
aoqi@0 900 flags &= ~LIR_OpArrayCopy::dst_pos_positive_check;
aoqi@0 901 if (positive_constant(length))
aoqi@0 902 flags &= ~LIR_OpArrayCopy::length_positive_check;
aoqi@0 903
aoqi@0 904 // see if the range check can be elided, which might also imply
aoqi@0 905 // that src or dst is non-null.
aoqi@0 906 ArrayLength* al = length->as_ArrayLength();
aoqi@0 907 if (al != NULL) {
aoqi@0 908 if (al->array() == src) {
aoqi@0 909 // it's the length of the source array
aoqi@0 910 flags &= ~LIR_OpArrayCopy::length_positive_check;
aoqi@0 911 flags &= ~LIR_OpArrayCopy::src_null_check;
aoqi@0 912 if (is_constant_zero(src_pos))
aoqi@0 913 flags &= ~LIR_OpArrayCopy::src_range_check;
aoqi@0 914 }
aoqi@0 915 if (al->array() == dst) {
aoqi@0 916 // it's the length of the destination array
aoqi@0 917 flags &= ~LIR_OpArrayCopy::length_positive_check;
aoqi@0 918 flags &= ~LIR_OpArrayCopy::dst_null_check;
aoqi@0 919 if (is_constant_zero(dst_pos))
aoqi@0 920 flags &= ~LIR_OpArrayCopy::dst_range_check;
aoqi@0 921 }
aoqi@0 922 }
aoqi@0 923 if (is_exact) {
aoqi@0 924 flags &= ~LIR_OpArrayCopy::type_check;
aoqi@0 925 }
aoqi@0 926 }
aoqi@0 927
aoqi@0 928 IntConstant* src_int = src_pos->type()->as_IntConstant();
aoqi@0 929 IntConstant* dst_int = dst_pos->type()->as_IntConstant();
aoqi@0 930 if (src_int && dst_int) {
aoqi@0 931 int s_offs = src_int->value();
aoqi@0 932 int d_offs = dst_int->value();
aoqi@0 933 if (src_int->value() >= dst_int->value()) {
aoqi@0 934 flags &= ~LIR_OpArrayCopy::overlapping;
aoqi@0 935 }
aoqi@0 936 if (expected_type != NULL) {
aoqi@0 937 BasicType t = expected_type->element_type()->basic_type();
aoqi@0 938 int element_size = type2aelembytes(t);
aoqi@0 939 if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&
aoqi@0 940 ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) {
aoqi@0 941 flags &= ~LIR_OpArrayCopy::unaligned;
aoqi@0 942 }
aoqi@0 943 }
aoqi@0 944 } else if (src_pos == dst_pos || is_constant_zero(dst_pos)) {
aoqi@0 945 // src and dest positions are the same, or dst is zero so assume
aoqi@0 946 // nonoverlapping copy.
aoqi@0 947 flags &= ~LIR_OpArrayCopy::overlapping;
aoqi@0 948 }
aoqi@0 949
aoqi@0 950 if (src == dst) {
aoqi@0 951 // moving within a single array so no type checks are needed
aoqi@0 952 if (flags & LIR_OpArrayCopy::type_check) {
aoqi@0 953 flags &= ~LIR_OpArrayCopy::type_check;
aoqi@0 954 }
aoqi@0 955 }
aoqi@0 956 *flagsp = flags;
aoqi@0 957 *expected_typep = (ciArrayKlass*)expected_type;
aoqi@0 958 }
aoqi@0 959
aoqi@0 960
aoqi@0 961 LIR_Opr LIRGenerator::round_item(LIR_Opr opr) {
aoqi@0 962 assert(opr->is_register(), "why spill if item is not register?");
aoqi@0 963
aoqi@0 964 if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) {
aoqi@0 965 LIR_Opr result = new_register(T_FLOAT);
aoqi@0 966 set_vreg_flag(result, must_start_in_memory);
aoqi@0 967 assert(opr->is_register(), "only a register can be spilled");
aoqi@0 968 assert(opr->value_type()->is_float(), "rounding only for floats available");
aoqi@0 969 __ roundfp(opr, LIR_OprFact::illegalOpr, result);
aoqi@0 970 return result;
aoqi@0 971 }
aoqi@0 972 return opr;
aoqi@0 973 }
aoqi@0 974
aoqi@0 975
aoqi@0 976 LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) {
aoqi@0 977 assert(type2size[t] == type2size[value->type()],
aoqi@0 978 err_msg_res("size mismatch: t=%s, value->type()=%s", type2name(t), type2name(value->type())));
aoqi@0 979 if (!value->is_register()) {
aoqi@0 980 // force into a register
aoqi@0 981 LIR_Opr r = new_register(value->type());
aoqi@0 982 __ move(value, r);
aoqi@0 983 value = r;
aoqi@0 984 }
aoqi@0 985
aoqi@0 986 // create a spill location
aoqi@0 987 LIR_Opr tmp = new_register(t);
aoqi@0 988 set_vreg_flag(tmp, LIRGenerator::must_start_in_memory);
aoqi@0 989
aoqi@0 990 // move from register to spill
aoqi@0 991 __ move(value, tmp);
aoqi@0 992 return tmp;
aoqi@0 993 }
roland@6668 994
aoqi@1 995 #ifndef MIPS64
aoqi@0 996 void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) {
aoqi@0 997 if (if_instr->should_profile()) {
aoqi@0 998 ciMethod* method = if_instr->profiled_method();
aoqi@0 999 assert(method != NULL, "method should be set if branch is profiled");
aoqi@0 1000 ciMethodData* md = method->method_data_or_null();
aoqi@0 1001 assert(md != NULL, "Sanity");
aoqi@0 1002 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());
aoqi@0 1003 assert(data != NULL, "must have profiling data");
aoqi@0 1004 assert(data->is_BranchData(), "need BranchData for two-way branches");
aoqi@0 1005 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset());
aoqi@0 1006 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
aoqi@0 1007 if (if_instr->is_swapped()) {
aoqi@0 1008 int t = taken_count_offset;
aoqi@0 1009 taken_count_offset = not_taken_count_offset;
aoqi@0 1010 not_taken_count_offset = t;
aoqi@0 1011 }
aoqi@0 1012
aoqi@0 1013 LIR_Opr md_reg = new_register(T_METADATA);
aoqi@0 1014 __ metadata2reg(md->constant_encoding(), md_reg);
aoqi@0 1015
aoqi@0 1016 LIR_Opr data_offset_reg = new_pointer_register();
aoqi@0 1017 __ cmove(lir_cond(cond),
aoqi@0 1018 LIR_OprFact::intptrConst(taken_count_offset),
aoqi@0 1019 LIR_OprFact::intptrConst(not_taken_count_offset),
aoqi@0 1020 data_offset_reg, as_BasicType(if_instr->x()->type()));
aoqi@0 1021
aoqi@0 1022 // MDO cells are intptr_t, so the data_reg width is arch-dependent.
aoqi@0 1023 LIR_Opr data_reg = new_pointer_register();
aoqi@0 1024 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());
aoqi@0 1025 __ move(data_addr, data_reg);
aoqi@0 1026 // Use leal instead of add to avoid destroying condition codes on x86
aoqi@0 1027 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);
aoqi@0 1028 __ leal(LIR_OprFact::address(fake_incr_value), data_reg);
aoqi@0 1029 __ move(data_reg, data_addr);
aoqi@0 1030 }
aoqi@0 1031 }
aoqi@1 1032 #else
aoqi@1 1033 void LIRGenerator::profile_branch(If* if_instr, If::Condition cond , LIR_Opr left, LIR_Opr right) {
aoqi@8865 1034 if (if_instr->should_profile()) {
aoqi@8865 1035 ciMethod* method = if_instr->profiled_method();
aoqi@8865 1036 assert(method != NULL, "method should be set if branch is profiled");
aoqi@8865 1037 ciMethodData* md = method->method_data_or_null();
aoqi@8865 1038 if (md == NULL) {
aoqi@8865 1039 bailout("out of memory building methodDataOop");
aoqi@8865 1040 return;
aoqi@8865 1041 }
aoqi@8865 1042 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());
aoqi@8865 1043 assert(data != NULL, "must have profiling data");
aoqi@8865 1044 assert(data->is_BranchData(), "need BranchData for two-way branches");
aoqi@8865 1045 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset());
aoqi@8865 1046 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
aoqi@8865 1047 if (if_instr->is_swapped()) {
aoqi@8865 1048 int t = taken_count_offset;
aoqi@8865 1049 taken_count_offset = not_taken_count_offset;
aoqi@8865 1050 not_taken_count_offset = t;
aoqi@8865 1051 }
aoqi@8865 1052 LIR_Opr md_reg = new_register(T_METADATA);
aoqi@8865 1053 __ metadata2reg(md->constant_encoding(), md_reg);
aoqi@8865 1054 LIR_Opr data_offset_reg = new_pointer_register();
aoqi@8865 1055
aoqi@8865 1056 LIR_Opr opr1 = LIR_OprFact::intptrConst(taken_count_offset);
aoqi@8865 1057 LIR_Opr opr2 = LIR_OprFact::intptrConst(not_taken_count_offset);
aoqi@8865 1058 LabelObj* skip = new LabelObj();
aoqi@8865 1059
aoqi@8865 1060 __ move(opr1, data_offset_reg);
aoqi@8865 1061 __ branch( lir_cond(cond), left, right, skip->label());
aoqi@8865 1062 __ move(opr2, data_offset_reg);
aoqi@8865 1063 __ branch_destination(skip->label());
aoqi@8865 1064
aoqi@8865 1065 LIR_Opr data_reg = new_pointer_register();
aoqi@8865 1066 LIR_Opr tmp_reg = new_pointer_register();
aoqi@8865 1067 __ move(data_offset_reg, tmp_reg);
aoqi@8865 1068 __ add(tmp_reg, md_reg, tmp_reg);
aoqi@8865 1069 LIR_Address* data_addr = new LIR_Address(tmp_reg, 0, data_reg->type());
aoqi@8865 1070 __ move(LIR_OprFact::address(data_addr), data_reg);
aoqi@8865 1071 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);
aoqi@8865 1072 // Use leal instead of add to avoid destroying condition codes on x86
aoqi@8865 1073 __ leal(LIR_OprFact::address(fake_incr_value), data_reg);
aoqi@8865 1074 __ move(data_reg, LIR_OprFact::address(data_addr));
aoqi@8865 1075 }
aoqi@1 1076 }
aoqi@1 1077
aoqi@1 1078 #endif
aoqi@0 1079
aoqi@0 1080 // Phi technique:
aoqi@0 1081 // This is about passing live values from one basic block to the other.
aoqi@0 1082 // In code generated with Java it is rather rare that more than one
aoqi@0 1083 // value is on the stack from one basic block to the other.
aoqi@0 1084 // We optimize our technique for efficient passing of one value
aoqi@0 1085 // (of type long, int, double..) but it can be extended.
aoqi@0 1086 // When entering or leaving a basic block, all registers and all spill
aoqi@0 1087 // slots are release and empty. We use the released registers
aoqi@0 1088 // and spill slots to pass the live values from one block
aoqi@0 1089 // to the other. The topmost value, i.e., the value on TOS of expression
aoqi@0 1090 // stack is passed in registers. All other values are stored in spilling
aoqi@0 1091 // area. Every Phi has an index which designates its spill slot
aoqi@0 1092 // At exit of a basic block, we fill the register(s) and spill slots.
aoqi@0 1093 // At entry of a basic block, the block_prolog sets up the content of phi nodes
aoqi@0 1094 // and locks necessary registers and spilling slots.
aoqi@0 1095
aoqi@0 1096
aoqi@0 1097 // move current value to referenced phi function
aoqi@0 1098 void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) {
aoqi@0 1099 Phi* phi = sux_val->as_Phi();
aoqi@0 1100 // cur_val can be null without phi being null in conjunction with inlining
aoqi@0 1101 if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) {
aoqi@0 1102 LIR_Opr operand = cur_val->operand();
aoqi@0 1103 if (cur_val->operand()->is_illegal()) {
aoqi@0 1104 assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL,
aoqi@0 1105 "these can be produced lazily");
aoqi@0 1106 operand = operand_for_instruction(cur_val);
aoqi@0 1107 }
aoqi@0 1108 resolver->move(operand, operand_for_instruction(phi));
aoqi@0 1109 }
aoqi@0 1110 }
aoqi@0 1111
aoqi@0 1112
aoqi@0 1113 // Moves all stack values into their PHI position
aoqi@0 1114 void LIRGenerator::move_to_phi(ValueStack* cur_state) {
aoqi@0 1115 BlockBegin* bb = block();
aoqi@0 1116 if (bb->number_of_sux() == 1) {
aoqi@0 1117 BlockBegin* sux = bb->sux_at(0);
aoqi@0 1118 assert(sux->number_of_preds() > 0, "invalid CFG");
aoqi@0 1119
aoqi@0 1120 // a block with only one predecessor never has phi functions
aoqi@0 1121 if (sux->number_of_preds() > 1) {
aoqi@0 1122 int max_phis = cur_state->stack_size() + cur_state->locals_size();
aoqi@0 1123 PhiResolver resolver(this, _virtual_register_number + max_phis * 2);
aoqi@0 1124
aoqi@0 1125 ValueStack* sux_state = sux->state();
aoqi@0 1126 Value sux_value;
aoqi@0 1127 int index;
aoqi@0 1128
aoqi@0 1129 assert(cur_state->scope() == sux_state->scope(), "not matching");
aoqi@0 1130 assert(cur_state->locals_size() == sux_state->locals_size(), "not matching");
aoqi@0 1131 assert(cur_state->stack_size() == sux_state->stack_size(), "not matching");
aoqi@0 1132
aoqi@0 1133 for_each_stack_value(sux_state, index, sux_value) {
aoqi@0 1134 move_to_phi(&resolver, cur_state->stack_at(index), sux_value);
aoqi@0 1135 }
aoqi@0 1136
aoqi@0 1137 for_each_local_value(sux_state, index, sux_value) {
aoqi@0 1138 move_to_phi(&resolver, cur_state->local_at(index), sux_value);
aoqi@0 1139 }
aoqi@0 1140
aoqi@0 1141 assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal");
aoqi@0 1142 }
aoqi@0 1143 }
aoqi@0 1144 }
aoqi@0 1145
aoqi@0 1146
aoqi@0 1147 LIR_Opr LIRGenerator::new_register(BasicType type) {
aoqi@0 1148 int vreg = _virtual_register_number;
aoqi@0 1149 // add a little fudge factor for the bailout, since the bailout is
aoqi@0 1150 // only checked periodically. This gives a few extra registers to
aoqi@0 1151 // hand out before we really run out, which helps us keep from
aoqi@0 1152 // tripping over assertions.
aoqi@0 1153 if (vreg + 20 >= LIR_OprDesc::vreg_max) {
aoqi@0 1154 bailout("out of virtual registers");
aoqi@0 1155 if (vreg + 2 >= LIR_OprDesc::vreg_max) {
aoqi@0 1156 // wrap it around
aoqi@0 1157 _virtual_register_number = LIR_OprDesc::vreg_base;
aoqi@0 1158 }
aoqi@0 1159 }
aoqi@0 1160 _virtual_register_number += 1;
aoqi@0 1161 return LIR_OprFact::virtual_register(vreg, type);
aoqi@0 1162 }
aoqi@0 1163
aoqi@0 1164
aoqi@0 1165 // Try to lock using register in hint
aoqi@0 1166 LIR_Opr LIRGenerator::rlock(Value instr) {
aoqi@0 1167 return new_register(instr->type());
aoqi@0 1168 }
aoqi@0 1169
aoqi@0 1170
aoqi@0 1171 // does an rlock and sets result
aoqi@0 1172 LIR_Opr LIRGenerator::rlock_result(Value x) {
aoqi@0 1173 LIR_Opr reg = rlock(x);
aoqi@0 1174 set_result(x, reg);
aoqi@0 1175 return reg;
aoqi@0 1176 }
aoqi@0 1177
aoqi@0 1178
aoqi@0 1179 // does an rlock and sets result
aoqi@0 1180 LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) {
aoqi@0 1181 LIR_Opr reg;
aoqi@0 1182 switch (type) {
aoqi@0 1183 case T_BYTE:
aoqi@0 1184 case T_BOOLEAN:
aoqi@0 1185 reg = rlock_byte(type);
aoqi@0 1186 break;
aoqi@0 1187 default:
aoqi@0 1188 reg = rlock(x);
aoqi@0 1189 break;
aoqi@0 1190 }
aoqi@0 1191
aoqi@0 1192 set_result(x, reg);
aoqi@0 1193 return reg;
aoqi@0 1194 }
aoqi@0 1195
aoqi@0 1196
aoqi@0 1197 //---------------------------------------------------------------------
aoqi@0 1198 ciObject* LIRGenerator::get_jobject_constant(Value value) {
aoqi@0 1199 ObjectType* oc = value->type()->as_ObjectType();
aoqi@0 1200 if (oc) {
aoqi@0 1201 return oc->constant_value();
aoqi@0 1202 }
aoqi@0 1203 return NULL;
aoqi@0 1204 }
aoqi@1 1205 #ifdef MIPS64
aoqi@1 1206 void LIRGenerator::write_barrier(LIR_Opr addr) {
aoqi@1 1207 if (addr->is_address()) {
aoqi@1 1208 LIR_Address* address = (LIR_Address*)addr;
aoqi@1 1209 LIR_Opr ptr = new_register(T_OBJECT);
aoqi@1 1210 if (!address->index()->is_valid() && address->disp() == 0) {
aoqi@1 1211 __ move(address->base(), ptr);
aoqi@1 1212 } else {
aoqi@1 1213 __ leal(addr, ptr);
aoqi@1 1214 }
aoqi@1 1215 addr = ptr;
aoqi@1 1216 }
aoqi@1 1217 assert(addr->is_register(), "must be a register at this point");
aoqi@1 1218
aoqi@1 1219 LIR_Opr tmp = new_pointer_register();
aoqi@1 1220 if (TwoOperandLIRForm) {
aoqi@1 1221 __ move(addr, tmp);
aoqi@1 1222 __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp);
aoqi@1 1223 } else {
aoqi@1 1224 __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp);
aoqi@1 1225 }
aoqi@1 1226 if (can_inline_as_constant(card_table_base())) {
aoqi@1 1227 __ move(LIR_OprFact::intConst(0), new LIR_Address(tmp, card_table_base()->as_jint(), T_BYTE));
aoqi@1 1228 } else {
aoqi@1 1229 __ add(tmp, load_constant(card_table_base()), tmp);
aoqi@1 1230 __ move(LIR_OprFact::intConst(0), new LIR_Address(tmp, 0, T_BYTE));
aoqi@1 1231 }
aoqi@1 1232 }
aoqi@1 1233 #endif
aoqi@0 1234
aoqi@0 1235
aoqi@0 1236 void LIRGenerator::do_ExceptionObject(ExceptionObject* x) {
aoqi@0 1237 assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block");
aoqi@0 1238 assert(block()->next() == x, "ExceptionObject must be first instruction of block");
aoqi@0 1239
aoqi@0 1240 // no moves are created for phi functions at the begin of exception
aoqi@0 1241 // handlers, so assign operands manually here
aoqi@0 1242 for_each_phi_fun(block(), phi,
aoqi@0 1243 operand_for_instruction(phi));
aoqi@0 1244
aoqi@0 1245 LIR_Opr thread_reg = getThreadPointer();
aoqi@0 1246 __ move_wide(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT),
aoqi@0 1247 exceptionOopOpr());
aoqi@0 1248 __ move_wide(LIR_OprFact::oopConst(NULL),
aoqi@0 1249 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT));
aoqi@0 1250 __ move_wide(LIR_OprFact::oopConst(NULL),
aoqi@0 1251 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT));
aoqi@0 1252
aoqi@0 1253 LIR_Opr result = new_register(T_OBJECT);
aoqi@0 1254 __ move(exceptionOopOpr(), result);
aoqi@0 1255 set_result(x, result);
aoqi@0 1256 }
aoqi@0 1257
aoqi@0 1258
aoqi@0 1259 //----------------------------------------------------------------------
aoqi@0 1260 //----------------------------------------------------------------------
aoqi@0 1261 //----------------------------------------------------------------------
aoqi@0 1262 //----------------------------------------------------------------------
aoqi@0 1263 // visitor functions
aoqi@0 1264 //----------------------------------------------------------------------
aoqi@0 1265 //----------------------------------------------------------------------
aoqi@0 1266 //----------------------------------------------------------------------
aoqi@0 1267 //----------------------------------------------------------------------
aoqi@0 1268
aoqi@0 1269 void LIRGenerator::do_Phi(Phi* x) {
aoqi@0 1270 // phi functions are never visited directly
aoqi@0 1271 ShouldNotReachHere();
aoqi@0 1272 }
aoqi@0 1273
aoqi@0 1274
aoqi@0 1275 // Code for a constant is generated lazily unless the constant is frequently used and can't be inlined.
aoqi@0 1276 void LIRGenerator::do_Constant(Constant* x) {
aoqi@0 1277 if (x->state_before() != NULL) {
aoqi@0 1278 // Any constant with a ValueStack requires patching so emit the patch here
aoqi@0 1279 LIR_Opr reg = rlock_result(x);
aoqi@0 1280 CodeEmitInfo* info = state_for(x, x->state_before());
aoqi@0 1281 __ oop2reg_patch(NULL, reg, info);
aoqi@0 1282 } else if (x->use_count() > 1 && !can_inline_as_constant(x)) {
aoqi@0 1283 if (!x->is_pinned()) {
aoqi@0 1284 // unpinned constants are handled specially so that they can be
aoqi@0 1285 // put into registers when they are used multiple times within a
aoqi@0 1286 // block. After the block completes their operand will be
aoqi@0 1287 // cleared so that other blocks can't refer to that register.
aoqi@0 1288 set_result(x, load_constant(x));
aoqi@0 1289 } else {
aoqi@0 1290 LIR_Opr res = x->operand();
aoqi@0 1291 if (!res->is_valid()) {
aoqi@0 1292 res = LIR_OprFact::value_type(x->type());
aoqi@0 1293 }
aoqi@0 1294 if (res->is_constant()) {
aoqi@0 1295 LIR_Opr reg = rlock_result(x);
aoqi@0 1296 __ move(res, reg);
aoqi@0 1297 } else {
aoqi@0 1298 set_result(x, res);
aoqi@0 1299 }
aoqi@0 1300 }
aoqi@0 1301 } else {
aoqi@0 1302 set_result(x, LIR_OprFact::value_type(x->type()));
aoqi@0 1303 }
aoqi@0 1304 }
aoqi@0 1305
aoqi@0 1306
aoqi@0 1307 void LIRGenerator::do_Local(Local* x) {
aoqi@0 1308 // operand_for_instruction has the side effect of setting the result
aoqi@0 1309 // so there's no need to do it here.
aoqi@0 1310 operand_for_instruction(x);
aoqi@0 1311 }
aoqi@0 1312
aoqi@0 1313
aoqi@0 1314 void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) {
aoqi@0 1315 Unimplemented();
aoqi@0 1316 }
aoqi@0 1317
aoqi@0 1318
aoqi@0 1319 void LIRGenerator::do_Return(Return* x) {
aoqi@0 1320 if (compilation()->env()->dtrace_method_probes()) {
aoqi@0 1321 BasicTypeList signature;
aoqi@0 1322 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
aoqi@0 1323 signature.append(T_METADATA); // Method*
aoqi@0 1324 LIR_OprList* args = new LIR_OprList();
aoqi@0 1325 args->append(getThreadPointer());
aoqi@0 1326 LIR_Opr meth = new_register(T_METADATA);
aoqi@0 1327 __ metadata2reg(method()->constant_encoding(), meth);
aoqi@0 1328 args->append(meth);
aoqi@0 1329 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
aoqi@0 1330 }
aoqi@0 1331
aoqi@0 1332 if (x->type()->is_void()) {
aoqi@0 1333 __ return_op(LIR_OprFact::illegalOpr);
aoqi@0 1334 } else {
aoqi@0 1335 LIR_Opr reg = result_register_for(x->type(), /*callee=*/true);
aoqi@0 1336 LIRItem result(x->result(), this);
aoqi@0 1337
aoqi@0 1338 result.load_item_force(reg);
aoqi@0 1339 __ return_op(result.result());
aoqi@0 1340 }
aoqi@0 1341 set_no_result(x);
aoqi@0 1342 }
aoqi@0 1343
aoqi@0 1344 // Examble: ref.get()
aoqi@0 1345 // Combination of LoadField and g1 pre-write barrier
aoqi@0 1346 void LIRGenerator::do_Reference_get(Intrinsic* x) {
aoqi@0 1347
aoqi@0 1348 const int referent_offset = java_lang_ref_Reference::referent_offset;
aoqi@0 1349 guarantee(referent_offset > 0, "referent offset not initialized");
aoqi@0 1350
aoqi@0 1351 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@0 1352
aoqi@0 1353 LIRItem reference(x->argument_at(0), this);
aoqi@0 1354 reference.load_item();
aoqi@0 1355
aoqi@0 1356 // need to perform the null check on the reference objecy
aoqi@0 1357 CodeEmitInfo* info = NULL;
aoqi@0 1358 if (x->needs_null_check()) {
aoqi@0 1359 info = state_for(x);
aoqi@0 1360 }
aoqi@0 1361
aoqi@0 1362 LIR_Address* referent_field_adr =
aoqi@0 1363 new LIR_Address(reference.result(), referent_offset, T_OBJECT);
aoqi@0 1364
aoqi@0 1365 LIR_Opr result = rlock_result(x);
aoqi@0 1366
aoqi@0 1367 __ load(referent_field_adr, result, info);
aoqi@0 1368
aoqi@0 1369 // Register the value in the referent field with the pre-barrier
aoqi@0 1370 pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,
aoqi@0 1371 result /* pre_val */,
aoqi@0 1372 false /* do_load */,
aoqi@0 1373 false /* patch */,
aoqi@0 1374 NULL /* info */);
aoqi@0 1375 }
aoqi@0 1376
aoqi@0 1377 // Example: clazz.isInstance(object)
aoqi@0 1378 void LIRGenerator::do_isInstance(Intrinsic* x) {
aoqi@0 1379 assert(x->number_of_arguments() == 2, "wrong type");
aoqi@0 1380
aoqi@0 1381 // TODO could try to substitute this node with an equivalent InstanceOf
aoqi@0 1382 // if clazz is known to be a constant Class. This will pick up newly found
aoqi@0 1383 // constants after HIR construction. I'll leave this to a future change.
aoqi@0 1384
aoqi@0 1385 // as a first cut, make a simple leaf call to runtime to stay platform independent.
aoqi@0 1386 // could follow the aastore example in a future change.
aoqi@0 1387
aoqi@0 1388 LIRItem clazz(x->argument_at(0), this);
aoqi@0 1389 LIRItem object(x->argument_at(1), this);
aoqi@0 1390 clazz.load_item();
aoqi@0 1391 object.load_item();
aoqi@0 1392 LIR_Opr result = rlock_result(x);
aoqi@0 1393
aoqi@0 1394 // need to perform null check on clazz
aoqi@0 1395 if (x->needs_null_check()) {
aoqi@0 1396 CodeEmitInfo* info = state_for(x);
aoqi@0 1397 __ null_check(clazz.result(), info);
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400 LIR_Opr call_result = call_runtime(clazz.value(), object.value(),
aoqi@0 1401 CAST_FROM_FN_PTR(address, Runtime1::is_instance_of),
aoqi@0 1402 x->type(),
aoqi@0 1403 NULL); // NULL CodeEmitInfo results in a leaf call
aoqi@0 1404 __ move(call_result, result);
aoqi@0 1405 }
aoqi@0 1406
aoqi@0 1407 // Example: object.getClass ()
aoqi@0 1408 void LIRGenerator::do_getClass(Intrinsic* x) {
aoqi@0 1409 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@0 1410
aoqi@0 1411 LIRItem rcvr(x->argument_at(0), this);
aoqi@0 1412 rcvr.load_item();
aoqi@0 1413 LIR_Opr temp = new_register(T_METADATA);
aoqi@0 1414 LIR_Opr result = rlock_result(x);
aoqi@0 1415
aoqi@0 1416 // need to perform the null check on the rcvr
aoqi@0 1417 CodeEmitInfo* info = NULL;
aoqi@0 1418 if (x->needs_null_check()) {
aoqi@0 1419 info = state_for(x);
aoqi@0 1420 }
aoqi@0 1421
aoqi@0 1422 // FIXME T_ADDRESS should actually be T_METADATA but it can't because the
aoqi@0 1423 // meaning of these two is mixed up (see JDK-8026837).
aoqi@0 1424 __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), temp, info);
aoqi@0 1425 __ move_wide(new LIR_Address(temp, in_bytes(Klass::java_mirror_offset()), T_OBJECT), result);
aoqi@0 1426 }
aoqi@0 1427
aoqi@0 1428
aoqi@0 1429 // Example: Thread.currentThread()
aoqi@0 1430 void LIRGenerator::do_currentThread(Intrinsic* x) {
aoqi@0 1431 assert(x->number_of_arguments() == 0, "wrong type");
aoqi@0 1432 LIR_Opr reg = rlock_result(x);
aoqi@0 1433 __ move_wide(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg);
aoqi@0 1434 }
aoqi@0 1435
aoqi@0 1436
aoqi@0 1437 void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) {
aoqi@0 1438 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@0 1439 LIRItem receiver(x->argument_at(0), this);
aoqi@0 1440
aoqi@0 1441 receiver.load_item();
aoqi@0 1442 BasicTypeList signature;
aoqi@0 1443 signature.append(T_OBJECT); // receiver
aoqi@0 1444 LIR_OprList* args = new LIR_OprList();
aoqi@0 1445 args->append(receiver.result());
aoqi@0 1446 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1447 call_runtime(&signature, args,
aoqi@0 1448 CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)),
aoqi@0 1449 voidType, info);
aoqi@0 1450
aoqi@0 1451 set_no_result(x);
aoqi@0 1452 }
aoqi@0 1453
aoqi@0 1454
aoqi@0 1455 //------------------------local access--------------------------------------
aoqi@0 1456
aoqi@0 1457 LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) {
aoqi@0 1458 if (x->operand()->is_illegal()) {
aoqi@0 1459 Constant* c = x->as_Constant();
aoqi@0 1460 if (c != NULL) {
aoqi@0 1461 x->set_operand(LIR_OprFact::value_type(c->type()));
aoqi@0 1462 } else {
aoqi@0 1463 assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local");
aoqi@0 1464 // allocate a virtual register for this local or phi
aoqi@0 1465 x->set_operand(rlock(x));
aoqi@0 1466 _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL);
aoqi@0 1467 }
aoqi@0 1468 }
aoqi@0 1469 return x->operand();
aoqi@0 1470 }
aoqi@0 1471
aoqi@0 1472
aoqi@0 1473 Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) {
aoqi@0 1474 if (opr->is_virtual()) {
aoqi@0 1475 return instruction_for_vreg(opr->vreg_number());
aoqi@0 1476 }
aoqi@0 1477 return NULL;
aoqi@0 1478 }
aoqi@0 1479
aoqi@0 1480
aoqi@0 1481 Instruction* LIRGenerator::instruction_for_vreg(int reg_num) {
aoqi@0 1482 if (reg_num < _instruction_for_operand.length()) {
aoqi@0 1483 return _instruction_for_operand.at(reg_num);
aoqi@0 1484 }
aoqi@0 1485 return NULL;
aoqi@0 1486 }
aoqi@0 1487
aoqi@0 1488
aoqi@0 1489 void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) {
aoqi@0 1490 if (_vreg_flags.size_in_bits() == 0) {
aoqi@0 1491 BitMap2D temp(100, num_vreg_flags);
aoqi@0 1492 temp.clear();
aoqi@0 1493 _vreg_flags = temp;
aoqi@0 1494 }
aoqi@0 1495 _vreg_flags.at_put_grow(vreg_num, f, true);
aoqi@0 1496 }
aoqi@0 1497
aoqi@0 1498 bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) {
aoqi@0 1499 if (!_vreg_flags.is_valid_index(vreg_num, f)) {
aoqi@0 1500 return false;
aoqi@0 1501 }
aoqi@0 1502 return _vreg_flags.at(vreg_num, f);
aoqi@0 1503 }
aoqi@0 1504
aoqi@0 1505
aoqi@0 1506 // Block local constant handling. This code is useful for keeping
aoqi@0 1507 // unpinned constants and constants which aren't exposed in the IR in
aoqi@0 1508 // registers. Unpinned Constant instructions have their operands
aoqi@0 1509 // cleared when the block is finished so that other blocks can't end
aoqi@0 1510 // up referring to their registers.
aoqi@0 1511
aoqi@0 1512 LIR_Opr LIRGenerator::load_constant(Constant* x) {
aoqi@0 1513 assert(!x->is_pinned(), "only for unpinned constants");
aoqi@0 1514 _unpinned_constants.append(x);
aoqi@0 1515 return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr());
aoqi@0 1516 }
aoqi@0 1517
aoqi@0 1518
aoqi@0 1519 LIR_Opr LIRGenerator::load_constant(LIR_Const* c) {
aoqi@0 1520 BasicType t = c->type();
aoqi@0 1521 for (int i = 0; i < _constants.length(); i++) {
aoqi@0 1522 LIR_Const* other = _constants.at(i);
aoqi@0 1523 if (t == other->type()) {
aoqi@0 1524 switch (t) {
aoqi@0 1525 case T_INT:
aoqi@0 1526 case T_FLOAT:
aoqi@0 1527 if (c->as_jint_bits() != other->as_jint_bits()) continue;
aoqi@0 1528 break;
aoqi@0 1529 case T_LONG:
aoqi@0 1530 case T_DOUBLE:
aoqi@0 1531 if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;
aoqi@0 1532 if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;
aoqi@0 1533 break;
aoqi@0 1534 case T_OBJECT:
aoqi@0 1535 if (c->as_jobject() != other->as_jobject()) continue;
aoqi@0 1536 break;
aoqi@0 1537 }
aoqi@0 1538 return _reg_for_constants.at(i);
aoqi@0 1539 }
aoqi@0 1540 }
aoqi@0 1541
aoqi@0 1542 LIR_Opr result = new_register(t);
aoqi@0 1543 __ move((LIR_Opr)c, result);
aoqi@0 1544 _constants.append(c);
aoqi@0 1545 _reg_for_constants.append(result);
aoqi@0 1546 return result;
aoqi@0 1547 }
aoqi@0 1548
aoqi@0 1549 // Various barriers
aoqi@0 1550
aoqi@0 1551 void LIRGenerator::pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
aoqi@0 1552 bool do_load, bool patch, CodeEmitInfo* info) {
aoqi@0 1553 // Do the pre-write barrier, if any.
aoqi@0 1554 switch (_bs->kind()) {
aoqi@0 1555 #if INCLUDE_ALL_GCS
aoqi@0 1556 case BarrierSet::G1SATBCT:
aoqi@0 1557 case BarrierSet::G1SATBCTLogging:
aoqi@0 1558 G1SATBCardTableModRef_pre_barrier(addr_opr, pre_val, do_load, patch, info);
aoqi@0 1559 break;
aoqi@0 1560 #endif // INCLUDE_ALL_GCS
aoqi@0 1561 case BarrierSet::CardTableModRef:
aoqi@0 1562 case BarrierSet::CardTableExtension:
aoqi@0 1563 // No pre barriers
aoqi@0 1564 break;
aoqi@0 1565 case BarrierSet::ModRef:
aoqi@0 1566 case BarrierSet::Other:
aoqi@0 1567 // No pre barriers
aoqi@0 1568 break;
aoqi@0 1569 default :
aoqi@0 1570 ShouldNotReachHere();
aoqi@0 1571
aoqi@0 1572 }
aoqi@0 1573 }
aoqi@0 1574
aoqi@0 1575 void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
aoqi@0 1576 switch (_bs->kind()) {
aoqi@0 1577 #if INCLUDE_ALL_GCS
aoqi@0 1578 case BarrierSet::G1SATBCT:
aoqi@0 1579 case BarrierSet::G1SATBCTLogging:
aoqi@0 1580 G1SATBCardTableModRef_post_barrier(addr, new_val);
aoqi@0 1581 break;
aoqi@0 1582 #endif // INCLUDE_ALL_GCS
aoqi@0 1583 case BarrierSet::CardTableModRef:
aoqi@0 1584 case BarrierSet::CardTableExtension:
aoqi@0 1585 CardTableModRef_post_barrier(addr, new_val);
aoqi@0 1586 break;
aoqi@0 1587 case BarrierSet::ModRef:
aoqi@0 1588 case BarrierSet::Other:
aoqi@0 1589 // No post barriers
aoqi@0 1590 break;
aoqi@0 1591 default :
aoqi@0 1592 ShouldNotReachHere();
aoqi@0 1593 }
aoqi@0 1594 }
aoqi@0 1595
aoqi@0 1596 ////////////////////////////////////////////////////////////////////////
aoqi@0 1597 #if INCLUDE_ALL_GCS
aoqi@0 1598
aoqi@0 1599 void LIRGenerator::G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
aoqi@0 1600 bool do_load, bool patch, CodeEmitInfo* info) {
aoqi@0 1601 // First we test whether marking is in progress.
aoqi@0 1602 BasicType flag_type;
aoqi@0 1603 if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {
aoqi@0 1604 flag_type = T_INT;
aoqi@0 1605 } else {
aoqi@0 1606 guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1,
aoqi@0 1607 "Assumption");
aoqi@0 1608 flag_type = T_BYTE;
aoqi@0 1609 }
aoqi@0 1610 LIR_Opr thrd = getThreadPointer();
aoqi@0 1611 LIR_Address* mark_active_flag_addr =
aoqi@0 1612 new LIR_Address(thrd,
aoqi@0 1613 in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1614 PtrQueue::byte_offset_of_active()),
aoqi@0 1615 flag_type);
aoqi@0 1616 // Read the marking-in-progress flag.
aoqi@0 1617 LIR_Opr flag_val = new_register(T_INT);
aoqi@0 1618 __ load(mark_active_flag_addr, flag_val);
aoqi@7535 1619 //MIPS not support cmp.
aoqi@1 1620 #ifndef MIPS64
aoqi@0 1621 __ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0));
aoqi@1 1622 #endif
aoqi@0 1623
aoqi@0 1624 LIR_PatchCode pre_val_patch_code = lir_patch_none;
aoqi@0 1625
aoqi@0 1626 CodeStub* slow;
aoqi@0 1627
aoqi@0 1628 if (do_load) {
aoqi@0 1629 assert(pre_val == LIR_OprFact::illegalOpr, "sanity");
aoqi@0 1630 assert(addr_opr != LIR_OprFact::illegalOpr, "sanity");
aoqi@0 1631
aoqi@0 1632 if (patch)
aoqi@0 1633 pre_val_patch_code = lir_patch_normal;
aoqi@0 1634
aoqi@0 1635 pre_val = new_register(T_OBJECT);
aoqi@0 1636
aoqi@0 1637 if (!addr_opr->is_address()) {
aoqi@0 1638 assert(addr_opr->is_register(), "must be");
aoqi@0 1639 addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, T_OBJECT));
aoqi@0 1640 }
aoqi@0 1641 slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code, info);
aoqi@0 1642 } else {
aoqi@0 1643 assert(addr_opr == LIR_OprFact::illegalOpr, "sanity");
aoqi@0 1644 assert(pre_val->is_register(), "must be");
aoqi@0 1645 assert(pre_val->type() == T_OBJECT, "must be an object");
aoqi@0 1646 assert(info == NULL, "sanity");
aoqi@0 1647
aoqi@0 1648 slow = new G1PreBarrierStub(pre_val);
aoqi@0 1649 }
aoqi@0 1650
aoqi@1 1651 #ifndef MIPS64
aoqi@0 1652 __ branch(lir_cond_notEqual, T_INT, slow);
aoqi@1 1653 #else
aoqi@1 1654 __ branch(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0), T_INT, slow);
aoqi@1 1655 #endif
aoqi@0 1656 __ branch_destination(slow->continuation());
aoqi@0 1657 }
aoqi@0 1658
aoqi@0 1659 void LIRGenerator::G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
aoqi@0 1660 // If the "new_val" is a constant NULL, no barrier is necessary.
aoqi@0 1661 if (new_val->is_constant() &&
aoqi@0 1662 new_val->as_constant_ptr()->as_jobject() == NULL) return;
aoqi@0 1663
aoqi@0 1664 if (!new_val->is_register()) {
aoqi@0 1665 LIR_Opr new_val_reg = new_register(T_OBJECT);
aoqi@0 1666 if (new_val->is_constant()) {
aoqi@0 1667 __ move(new_val, new_val_reg);
aoqi@0 1668 } else {
aoqi@0 1669 __ leal(new_val, new_val_reg);
aoqi@0 1670 }
aoqi@0 1671 new_val = new_val_reg;
aoqi@0 1672 }
aoqi@0 1673 assert(new_val->is_register(), "must be a register at this point");
aoqi@0 1674
aoqi@0 1675 if (addr->is_address()) {
aoqi@0 1676 LIR_Address* address = addr->as_address_ptr();
aoqi@0 1677 LIR_Opr ptr = new_pointer_register();
aoqi@0 1678 if (!address->index()->is_valid() && address->disp() == 0) {
aoqi@0 1679 __ move(address->base(), ptr);
aoqi@0 1680 } else {
aoqi@0 1681 assert(address->disp() != max_jint, "lea doesn't support patched addresses!");
aoqi@0 1682 __ leal(addr, ptr);
aoqi@0 1683 }
aoqi@0 1684 addr = ptr;
aoqi@0 1685 }
aoqi@0 1686 assert(addr->is_register(), "must be a register at this point");
aoqi@0 1687
aoqi@0 1688 LIR_Opr xor_res = new_pointer_register();
aoqi@0 1689 LIR_Opr xor_shift_res = new_pointer_register();
aoqi@0 1690 if (TwoOperandLIRForm ) {
aoqi@0 1691 __ move(addr, xor_res);
aoqi@0 1692 __ logical_xor(xor_res, new_val, xor_res);
aoqi@0 1693 __ move(xor_res, xor_shift_res);
aoqi@0 1694 __ unsigned_shift_right(xor_shift_res,
aoqi@0 1695 LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
aoqi@0 1696 xor_shift_res,
aoqi@0 1697 LIR_OprDesc::illegalOpr());
aoqi@0 1698 } else {
aoqi@0 1699 __ logical_xor(addr, new_val, xor_res);
aoqi@0 1700 __ unsigned_shift_right(xor_res,
aoqi@0 1701 LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
aoqi@0 1702 xor_shift_res,
aoqi@0 1703 LIR_OprDesc::illegalOpr());
aoqi@0 1704 }
aoqi@0 1705
aoqi@0 1706 if (!new_val->is_register()) {
aoqi@0 1707 LIR_Opr new_val_reg = new_register(T_OBJECT);
aoqi@0 1708 __ leal(new_val, new_val_reg);
aoqi@0 1709 new_val = new_val_reg;
aoqi@0 1710 }
aoqi@0 1711 assert(new_val->is_register(), "must be a register at this point");
aoqi@0 1712
aoqi@1 1713 #ifndef MIPS64
aoqi@0 1714 __ cmp(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst(NULL_WORD));
aoqi@0 1715
aoqi@1 1716 #endif
aoqi@0 1717 CodeStub* slow = new G1PostBarrierStub(addr, new_val);
aoqi@1 1718 #ifndef MIPS64
aoqi@0 1719 __ branch(lir_cond_notEqual, LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow);
aoqi@1 1720 #else
aoqi@1 1721 __ branch(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst((intptr_t)NULL_WORD), LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow);
aoqi@1 1722 #endif
aoqi@0 1723 __ branch_destination(slow->continuation());
aoqi@0 1724 }
aoqi@0 1725
aoqi@0 1726 #endif // INCLUDE_ALL_GCS
aoqi@0 1727 ////////////////////////////////////////////////////////////////////////
aoqi@0 1728
aoqi@0 1729 void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
aoqi@0 1730
aoqi@0 1731 assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@0 1732 LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base);
aoqi@0 1733 if (addr->is_address()) {
aoqi@0 1734 LIR_Address* address = addr->as_address_ptr();
aoqi@0 1735 // ptr cannot be an object because we use this barrier for array card marks
aoqi@0 1736 // and addr can point in the middle of an array.
aoqi@0 1737 LIR_Opr ptr = new_pointer_register();
aoqi@0 1738 if (!address->index()->is_valid() && address->disp() == 0) {
aoqi@0 1739 __ move(address->base(), ptr);
aoqi@0 1740 } else {
aoqi@0 1741 assert(address->disp() != max_jint, "lea doesn't support patched addresses!");
aoqi@0 1742 __ leal(addr, ptr);
aoqi@0 1743 }
aoqi@0 1744 addr = ptr;
aoqi@0 1745 }
aoqi@0 1746 assert(addr->is_register(), "must be a register at this point");
aoqi@0 1747
dlong@7598 1748 #ifdef CARDTABLEMODREF_POST_BARRIER_HELPER
dlong@7598 1749 CardTableModRef_post_barrier_helper(addr, card_table_base);
dlong@7598 1750 #else
aoqi@0 1751 LIR_Opr tmp = new_pointer_register();
aoqi@0 1752 if (TwoOperandLIRForm) {
aoqi@0 1753 __ move(addr, tmp);
aoqi@0 1754 __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp);
aoqi@0 1755 } else {
aoqi@0 1756 __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp);
aoqi@0 1757 }
aoqi@0 1758 if (can_inline_as_constant(card_table_base)) {
aoqi@0 1759 __ move(LIR_OprFact::intConst(0),
aoqi@0 1760 new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE));
aoqi@0 1761 } else {
aoqi@1 1762 #ifndef MIPS64
aoqi@0 1763 __ move(LIR_OprFact::intConst(0),
aoqi@0 1764 new LIR_Address(tmp, load_constant(card_table_base),
aoqi@0 1765 T_BYTE));
aoqi@1 1766 #else
aoqi@1 1767 __ add(tmp, load_constant(card_table_base), tmp);
aoqi@1 1768 __ move(LIR_OprFact::intConst(0),
aoqi@1 1769 new LIR_Address(tmp, 0,
aoqi@1 1770 T_BYTE));
aoqi@1 1771 #endif
aoqi@0 1772 }
dlong@7598 1773 #endif
aoqi@0 1774 }
aoqi@0 1775
aoqi@0 1776
aoqi@0 1777 //------------------------field access--------------------------------------
aoqi@0 1778
aoqi@0 1779 // Comment copied form templateTable_i486.cpp
aoqi@0 1780 // ----------------------------------------------------------------------------
aoqi@0 1781 // Volatile variables demand their effects be made known to all CPU's in
aoqi@0 1782 // order. Store buffers on most chips allow reads & writes to reorder; the
aoqi@0 1783 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
aoqi@0 1784 // memory barrier (i.e., it's not sufficient that the interpreter does not
aoqi@0 1785 // reorder volatile references, the hardware also must not reorder them).
aoqi@0 1786 //
aoqi@0 1787 // According to the new Java Memory Model (JMM):
aoqi@0 1788 // (1) All volatiles are serialized wrt to each other.
aoqi@0 1789 // ALSO reads & writes act as aquire & release, so:
aoqi@0 1790 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
aoqi@0 1791 // the read float up to before the read. It's OK for non-volatile memory refs
aoqi@0 1792 // that happen before the volatile read to float down below it.
aoqi@0 1793 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
aoqi@0 1794 // that happen BEFORE the write float down to after the write. It's OK for
aoqi@0 1795 // non-volatile memory refs that happen after the volatile write to float up
aoqi@0 1796 // before it.
aoqi@0 1797 //
aoqi@0 1798 // We only put in barriers around volatile refs (they are expensive), not
aoqi@0 1799 // _between_ memory refs (that would require us to track the flavor of the
aoqi@0 1800 // previous memory refs). Requirements (2) and (3) require some barriers
aoqi@0 1801 // before volatile stores and after volatile loads. These nearly cover
aoqi@0 1802 // requirement (1) but miss the volatile-store-volatile-load case. This final
aoqi@0 1803 // case is placed after volatile-stores although it could just as well go
aoqi@0 1804 // before volatile-loads.
aoqi@0 1805
aoqi@0 1806
aoqi@0 1807 void LIRGenerator::do_StoreField(StoreField* x) {
aoqi@0 1808 bool needs_patching = x->needs_patching();
aoqi@0 1809 bool is_volatile = x->field()->is_volatile();
aoqi@0 1810 BasicType field_type = x->field_type();
aoqi@0 1811 bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT);
aoqi@0 1812
aoqi@0 1813 CodeEmitInfo* info = NULL;
aoqi@0 1814 if (needs_patching) {
aoqi@0 1815 assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
aoqi@0 1816 info = state_for(x, x->state_before());
aoqi@0 1817 } else if (x->needs_null_check()) {
aoqi@0 1818 NullCheck* nc = x->explicit_null_check();
aoqi@0 1819 if (nc == NULL) {
aoqi@0 1820 info = state_for(x);
aoqi@0 1821 } else {
aoqi@0 1822 info = state_for(nc);
aoqi@0 1823 }
aoqi@0 1824 }
aoqi@0 1825
aoqi@0 1826
aoqi@0 1827 LIRItem object(x->obj(), this);
aoqi@0 1828 LIRItem value(x->value(), this);
aoqi@0 1829
aoqi@0 1830 object.load_item();
aoqi@0 1831
aoqi@0 1832 if (is_volatile || needs_patching) {
aoqi@0 1833 // load item if field is volatile (fewer special cases for volatiles)
aoqi@0 1834 // load item if field not initialized
aoqi@0 1835 // load item if field not constant
aoqi@0 1836 // because of code patching we cannot inline constants
aoqi@0 1837 if (field_type == T_BYTE || field_type == T_BOOLEAN) {
aoqi@0 1838 value.load_byte_item();
aoqi@0 1839 } else {
aoqi@0 1840 value.load_item();
aoqi@0 1841 }
aoqi@0 1842 } else {
aoqi@0 1843 value.load_for_store(field_type);
aoqi@0 1844 }
aoqi@0 1845
aoqi@0 1846 set_no_result(x);
aoqi@0 1847
aoqi@0 1848 #ifndef PRODUCT
aoqi@0 1849 if (PrintNotLoaded && needs_patching) {
aoqi@0 1850 tty->print_cr(" ###class not loaded at store_%s bci %d",
aoqi@0 1851 x->is_static() ? "static" : "field", x->printable_bci());
aoqi@0 1852 }
aoqi@0 1853 #endif
aoqi@0 1854
aoqi@0 1855 if (x->needs_null_check() &&
aoqi@0 1856 (needs_patching ||
aoqi@0 1857 MacroAssembler::needs_explicit_null_check(x->offset()))) {
vkempik@8735 1858 // Emit an explicit null check because the offset is too large.
vkempik@8735 1859 // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
vkempik@8735 1860 // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
vkempik@8735 1861 __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);
aoqi@0 1862 }
aoqi@0 1863
aoqi@0 1864 LIR_Address* address;
aoqi@0 1865 if (needs_patching) {
aoqi@0 1866 // we need to patch the offset in the instruction so don't allow
aoqi@0 1867 // generate_address to try to be smart about emitting the -1.
aoqi@0 1868 // Otherwise the patching code won't know how to find the
aoqi@0 1869 // instruction to patch.
aoqi@0 1870 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);
aoqi@0 1871 } else {
aoqi@0 1872 address = generate_address(object.result(), x->offset(), field_type);
aoqi@0 1873 }
aoqi@0 1874
aoqi@0 1875 if (is_volatile && os::is_MP()) {
aoqi@0 1876 __ membar_release();
aoqi@0 1877 }
aoqi@0 1878
aoqi@0 1879 if (is_oop) {
aoqi@0 1880 // Do the pre-write barrier, if any.
aoqi@0 1881 pre_barrier(LIR_OprFact::address(address),
aoqi@0 1882 LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 1883 true /* do_load*/,
aoqi@0 1884 needs_patching,
aoqi@0 1885 (info ? new CodeEmitInfo(info) : NULL));
aoqi@0 1886 }
aoqi@0 1887
aoqi@0 1888 if (is_volatile && !needs_patching) {
aoqi@0 1889 volatile_field_store(value.result(), address, info);
aoqi@0 1890 } else {
aoqi@0 1891 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
aoqi@0 1892 __ store(value.result(), address, info, patch_code);
aoqi@0 1893 }
aoqi@0 1894
aoqi@0 1895 if (is_oop) {
aoqi@0 1896 // Store to object so mark the card of the header
aoqi@0 1897 post_barrier(object.result(), value.result());
aoqi@0 1898 }
aoqi@0 1899
aoqi@0 1900 if (is_volatile && os::is_MP()) {
aoqi@0 1901 __ membar();
aoqi@0 1902 }
aoqi@0 1903 }
aoqi@0 1904
aoqi@0 1905
aoqi@0 1906 void LIRGenerator::do_LoadField(LoadField* x) {
aoqi@0 1907 bool needs_patching = x->needs_patching();
aoqi@0 1908 bool is_volatile = x->field()->is_volatile();
aoqi@0 1909 BasicType field_type = x->field_type();
aoqi@0 1910
aoqi@0 1911 CodeEmitInfo* info = NULL;
aoqi@0 1912 if (needs_patching) {
aoqi@0 1913 assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
aoqi@0 1914 info = state_for(x, x->state_before());
aoqi@0 1915 } else if (x->needs_null_check()) {
aoqi@0 1916 NullCheck* nc = x->explicit_null_check();
aoqi@0 1917 if (nc == NULL) {
aoqi@0 1918 info = state_for(x);
aoqi@0 1919 } else {
aoqi@0 1920 info = state_for(nc);
aoqi@0 1921 }
aoqi@0 1922 }
aoqi@0 1923
aoqi@0 1924 LIRItem object(x->obj(), this);
aoqi@0 1925
aoqi@0 1926 object.load_item();
aoqi@0 1927
aoqi@0 1928 #ifndef PRODUCT
aoqi@0 1929 if (PrintNotLoaded && needs_patching) {
aoqi@0 1930 tty->print_cr(" ###class not loaded at load_%s bci %d",
aoqi@0 1931 x->is_static() ? "static" : "field", x->printable_bci());
aoqi@0 1932 }
aoqi@0 1933 #endif
aoqi@0 1934
aoqi@0 1935 bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();
aoqi@0 1936 if (x->needs_null_check() &&
aoqi@0 1937 (needs_patching ||
aoqi@0 1938 MacroAssembler::needs_explicit_null_check(x->offset()) ||
aoqi@0 1939 stress_deopt)) {
aoqi@0 1940 LIR_Opr obj = object.result();
aoqi@0 1941 if (stress_deopt) {
aoqi@0 1942 obj = new_register(T_OBJECT);
aoqi@0 1943 __ move(LIR_OprFact::oopConst(NULL), obj);
aoqi@0 1944 }
vkempik@8735 1945 // Emit an explicit null check because the offset is too large.
vkempik@8735 1946 // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
vkempik@8735 1947 // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
vkempik@8735 1948 __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);
aoqi@0 1949 }
aoqi@0 1950
aoqi@0 1951 LIR_Opr reg = rlock_result(x, field_type);
aoqi@0 1952 LIR_Address* address;
aoqi@0 1953 if (needs_patching) {
aoqi@0 1954 // we need to patch the offset in the instruction so don't allow
aoqi@0 1955 // generate_address to try to be smart about emitting the -1.
aoqi@0 1956 // Otherwise the patching code won't know how to find the
aoqi@0 1957 // instruction to patch.
aoqi@0 1958 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);
aoqi@0 1959 } else {
aoqi@0 1960 address = generate_address(object.result(), x->offset(), field_type);
aoqi@0 1961 }
aoqi@0 1962
aoqi@0 1963 if (is_volatile && !needs_patching) {
aoqi@0 1964 volatile_field_load(address, reg, info);
aoqi@0 1965 } else {
aoqi@0 1966 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
aoqi@0 1967 __ load(address, reg, info, patch_code);
aoqi@0 1968 }
aoqi@0 1969
aoqi@0 1970 if (is_volatile && os::is_MP()) {
aoqi@0 1971 __ membar_acquire();
aoqi@0 1972 }
aoqi@0 1973 }
aoqi@0 1974
aoqi@0 1975
aoqi@0 1976 //------------------------java.nio.Buffer.checkIndex------------------------
aoqi@0 1977
aoqi@0 1978 // int java.nio.Buffer.checkIndex(int)
aoqi@0 1979 void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {
aoqi@0 1980 // NOTE: by the time we are in checkIndex() we are guaranteed that
aoqi@0 1981 // the buffer is non-null (because checkIndex is package-private and
aoqi@0 1982 // only called from within other methods in the buffer).
aoqi@0 1983 assert(x->number_of_arguments() == 2, "wrong type");
aoqi@0 1984 LIRItem buf (x->argument_at(0), this);
aoqi@0 1985 LIRItem index(x->argument_at(1), this);
aoqi@0 1986 buf.load_item();
aoqi@0 1987 index.load_item();
aoqi@0 1988
aoqi@0 1989 LIR_Opr result = rlock_result(x);
aoqi@0 1990 if (GenerateRangeChecks) {
aoqi@0 1991 CodeEmitInfo* info = state_for(x);
aoqi@0 1992 CodeStub* stub = new RangeCheckStub(info, index.result(), true);
aoqi@0 1993 if (index.result()->is_constant()) {
aoqi@1 1994 #ifndef MIPS64
aoqi@0 1995 cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info);
aoqi@0 1996 __ branch(lir_cond_belowEqual, T_INT, stub);
aoqi@1 1997 #else
aoqi@8865 1998 LIR_Opr left = LIR_OprFact::address(new LIR_Address( buf.result(),
aoqi@1 1999 java_nio_Buffer::limit_offset(),T_INT));
aoqi@8865 2000 LIR_Opr right = LIR_OprFact::intConst(index.result()->as_jint());
aoqi@1 2001 __ null_check_for_branch(lir_cond_belowEqual, left, right, info);
aoqi@8865 2002 __ branch(lir_cond_belowEqual,left, right ,T_INT, stub); // forward branch
aoqi@1 2003
aoqi@1 2004 #endif
aoqi@0 2005 } else {
aoqi@1 2006 #ifndef MIPS64
aoqi@0 2007 cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(),
aoqi@0 2008 java_nio_Buffer::limit_offset(), T_INT, info);
aoqi@0 2009 __ branch(lir_cond_aboveEqual, T_INT, stub);
aoqi@1 2010 #else
aoqi@8865 2011 LIR_Opr right = LIR_OprFact::address(new LIR_Address( buf.result(), java_nio_Buffer::limit_offset(),T_INT));
aoqi@8865 2012 LIR_Opr left = index.result();
aoqi@1 2013 __ null_check_for_branch(lir_cond_aboveEqual, left, right, info);
aoqi@8865 2014 __ branch(lir_cond_aboveEqual, left, right , T_INT, stub); // forward branch
aoqi@1 2015 #endif
aoqi@0 2016 }
aoqi@0 2017 __ move(index.result(), result);
aoqi@0 2018 } else {
aoqi@0 2019 // Just load the index into the result register
aoqi@0 2020 __ move(index.result(), result);
aoqi@0 2021 }
aoqi@0 2022 }
aoqi@0 2023
aoqi@0 2024
aoqi@0 2025 //------------------------array access--------------------------------------
aoqi@0 2026
aoqi@0 2027
aoqi@0 2028 void LIRGenerator::do_ArrayLength(ArrayLength* x) {
aoqi@0 2029 LIRItem array(x->array(), this);
aoqi@0 2030 array.load_item();
aoqi@0 2031 LIR_Opr reg = rlock_result(x);
aoqi@0 2032
aoqi@0 2033 CodeEmitInfo* info = NULL;
aoqi@0 2034 if (x->needs_null_check()) {
aoqi@0 2035 NullCheck* nc = x->explicit_null_check();
aoqi@0 2036 if (nc == NULL) {
aoqi@0 2037 info = state_for(x);
aoqi@0 2038 } else {
aoqi@0 2039 info = state_for(nc);
aoqi@0 2040 }
aoqi@0 2041 if (StressLoopInvariantCodeMotion && info->deoptimize_on_exception()) {
aoqi@0 2042 LIR_Opr obj = new_register(T_OBJECT);
aoqi@0 2043 __ move(LIR_OprFact::oopConst(NULL), obj);
aoqi@0 2044 __ null_check(obj, new CodeEmitInfo(info));
aoqi@0 2045 }
aoqi@0 2046 }
aoqi@0 2047 __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);
aoqi@0 2048 }
aoqi@0 2049
aoqi@0 2050
aoqi@0 2051 void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {
aoqi@0 2052 bool use_length = x->length() != NULL;
aoqi@0 2053 LIRItem array(x->array(), this);
aoqi@0 2054 LIRItem index(x->index(), this);
aoqi@0 2055 LIRItem length(this);
aoqi@0 2056 bool needs_range_check = x->compute_needs_range_check();
aoqi@0 2057
aoqi@0 2058 if (use_length && needs_range_check) {
aoqi@0 2059 length.set_instruction(x->length());
aoqi@0 2060 length.load_item();
aoqi@0 2061 }
aoqi@0 2062
aoqi@0 2063 array.load_item();
aoqi@0 2064 if (index.is_constant() && can_inline_as_constant(x->index())) {
aoqi@0 2065 // let it be a constant
aoqi@0 2066 index.dont_load_item();
aoqi@0 2067 } else {
aoqi@0 2068 index.load_item();
aoqi@0 2069 }
aoqi@0 2070
aoqi@0 2071 CodeEmitInfo* range_check_info = state_for(x);
aoqi@0 2072 CodeEmitInfo* null_check_info = NULL;
aoqi@0 2073 if (x->needs_null_check()) {
aoqi@0 2074 NullCheck* nc = x->explicit_null_check();
aoqi@0 2075 if (nc != NULL) {
aoqi@0 2076 null_check_info = state_for(nc);
aoqi@0 2077 } else {
aoqi@0 2078 null_check_info = range_check_info;
aoqi@0 2079 }
aoqi@0 2080 if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {
aoqi@0 2081 LIR_Opr obj = new_register(T_OBJECT);
aoqi@0 2082 __ move(LIR_OprFact::oopConst(NULL), obj);
aoqi@0 2083 __ null_check(obj, new CodeEmitInfo(null_check_info));
aoqi@0 2084 }
aoqi@0 2085 }
aoqi@0 2086
aoqi@0 2087 // emit array address setup early so it schedules better
aoqi@0 2088 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false);
aoqi@0 2089
aoqi@0 2090 if (GenerateRangeChecks && needs_range_check) {
aoqi@0 2091 if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {
aoqi@1 2092 #ifndef MIPS64
aoqi@0 2093 __ branch(lir_cond_always, T_ILLEGAL, new RangeCheckStub(range_check_info, index.result()));
aoqi@1 2094 #else
aoqi@8865 2095 tty->print_cr("LIRGenerator::do_LoadIndexed(LoadIndexed* x) unimplemented yet!");
aoqi@8865 2096 Unimplemented();
aoqi@1 2097 #endif
aoqi@0 2098 } else if (use_length) {
aoqi@0 2099 // TODO: use a (modified) version of array_range_check that does not require a
aoqi@0 2100 // constant length to be loaded to a register
aoqi@1 2101 #ifndef MIPS64
aoqi@0 2102 __ cmp(lir_cond_belowEqual, length.result(), index.result());
aoqi@0 2103 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
aoqi@1 2104 #else
aoqi@1 2105 __ branch(lir_cond_belowEqual, length.result(), index.result(),T_INT, new RangeCheckStub(range_check_info, index.result()));
aoqi@1 2106 #endif
aoqi@0 2107 } else {
aoqi@0 2108 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
aoqi@0 2109 // The range check performs the null check, so clear it out for the load
aoqi@0 2110 null_check_info = NULL;
aoqi@0 2111 }
aoqi@0 2112 }
aoqi@0 2113
aoqi@0 2114 __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info);
aoqi@0 2115 }
aoqi@0 2116
aoqi@0 2117
aoqi@0 2118 void LIRGenerator::do_NullCheck(NullCheck* x) {
aoqi@0 2119 if (x->can_trap()) {
aoqi@0 2120 LIRItem value(x->obj(), this);
aoqi@0 2121 value.load_item();
aoqi@0 2122 CodeEmitInfo* info = state_for(x);
aoqi@0 2123 __ null_check(value.result(), info);
aoqi@0 2124 }
aoqi@0 2125 }
aoqi@0 2126
aoqi@0 2127
aoqi@0 2128 void LIRGenerator::do_TypeCast(TypeCast* x) {
aoqi@0 2129 LIRItem value(x->obj(), this);
aoqi@0 2130 value.load_item();
aoqi@0 2131 // the result is the same as from the node we are casting
aoqi@0 2132 set_result(x, value.result());
aoqi@0 2133 }
aoqi@0 2134
aoqi@0 2135
aoqi@0 2136 void LIRGenerator::do_Throw(Throw* x) {
aoqi@0 2137 LIRItem exception(x->exception(), this);
aoqi@0 2138 exception.load_item();
aoqi@0 2139 set_no_result(x);
aoqi@0 2140 LIR_Opr exception_opr = exception.result();
aoqi@0 2141 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 2142
aoqi@0 2143 #ifndef PRODUCT
aoqi@0 2144 if (PrintC1Statistics) {
aoqi@0 2145 increment_counter(Runtime1::throw_count_address(), T_INT);
aoqi@0 2146 }
aoqi@0 2147 #endif
aoqi@0 2148
aoqi@0 2149 // check if the instruction has an xhandler in any of the nested scopes
aoqi@0 2150 bool unwind = false;
aoqi@0 2151 if (info->exception_handlers()->length() == 0) {
aoqi@0 2152 // this throw is not inside an xhandler
aoqi@0 2153 unwind = true;
aoqi@0 2154 } else {
aoqi@0 2155 // get some idea of the throw type
aoqi@0 2156 bool type_is_exact = true;
aoqi@0 2157 ciType* throw_type = x->exception()->exact_type();
aoqi@0 2158 if (throw_type == NULL) {
aoqi@0 2159 type_is_exact = false;
aoqi@0 2160 throw_type = x->exception()->declared_type();
aoqi@0 2161 }
aoqi@0 2162 if (throw_type != NULL && throw_type->is_instance_klass()) {
aoqi@0 2163 ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type;
aoqi@0 2164 unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact);
aoqi@0 2165 }
aoqi@0 2166 }
aoqi@0 2167
aoqi@0 2168 // do null check before moving exception oop into fixed register
aoqi@0 2169 // to avoid a fixed interval with an oop during the null check.
aoqi@0 2170 // Use a copy of the CodeEmitInfo because debug information is
aoqi@0 2171 // different for null_check and throw.
aoqi@0 2172 if (GenerateCompilerNullChecks &&
aoqi@0 2173 (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) {
aoqi@0 2174 // if the exception object wasn't created using new then it might be null.
aoqi@0 2175 __ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci())));
aoqi@0 2176 }
aoqi@0 2177
aoqi@0 2178 if (compilation()->env()->jvmti_can_post_on_exceptions()) {
aoqi@0 2179 // we need to go through the exception lookup path to get JVMTI
aoqi@0 2180 // notification done
aoqi@0 2181 unwind = false;
aoqi@0 2182 }
aoqi@0 2183
aoqi@0 2184 // move exception oop into fixed register
aoqi@0 2185 __ move(exception_opr, exceptionOopOpr());
aoqi@0 2186
aoqi@0 2187 if (unwind) {
aoqi@0 2188 __ unwind_exception(exceptionOopOpr());
aoqi@0 2189 } else {
aoqi@0 2190 __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info);
aoqi@0 2191 }
aoqi@0 2192 }
aoqi@0 2193
aoqi@0 2194
aoqi@0 2195 void LIRGenerator::do_RoundFP(RoundFP* x) {
aoqi@0 2196 LIRItem input(x->input(), this);
aoqi@0 2197 input.load_item();
aoqi@0 2198 LIR_Opr input_opr = input.result();
aoqi@0 2199 assert(input_opr->is_register(), "why round if value is not in a register?");
aoqi@0 2200 assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value");
aoqi@0 2201 if (input_opr->is_single_fpu()) {
aoqi@0 2202 set_result(x, round_item(input_opr)); // This code path not currently taken
aoqi@0 2203 } else {
aoqi@0 2204 LIR_Opr result = new_register(T_DOUBLE);
aoqi@0 2205 set_vreg_flag(result, must_start_in_memory);
aoqi@0 2206 __ roundfp(input_opr, LIR_OprFact::illegalOpr, result);
aoqi@0 2207 set_result(x, result);
aoqi@0 2208 }
aoqi@0 2209 }
aoqi@0 2210
iveresov@7205 2211 // Here UnsafeGetRaw may have x->base() and x->index() be int or long
iveresov@7205 2212 // on both 64 and 32 bits. Expecting x->base() to be always long on 64bit.
aoqi@0 2213 void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) {
aoqi@0 2214 LIRItem base(x->base(), this);
aoqi@0 2215 LIRItem idx(this);
aoqi@0 2216
aoqi@0 2217 base.load_item();
aoqi@0 2218 if (x->has_index()) {
aoqi@0 2219 idx.set_instruction(x->index());
aoqi@0 2220 idx.load_nonconstant();
aoqi@0 2221 }
aoqi@0 2222
aoqi@0 2223 LIR_Opr reg = rlock_result(x, x->basic_type());
aoqi@0 2224
aoqi@0 2225 int log2_scale = 0;
aoqi@0 2226 if (x->has_index()) {
aoqi@0 2227 log2_scale = x->log2_scale();
aoqi@0 2228 }
aoqi@0 2229
aoqi@0 2230 assert(!x->has_index() || idx.value() == x->index(), "should match");
aoqi@0 2231
aoqi@0 2232 LIR_Opr base_op = base.result();
iveresov@7205 2233 LIR_Opr index_op = idx.result();
aoqi@0 2234 #ifndef _LP64
iveresov@7233 2235 if (base_op->type() == T_LONG) {
aoqi@0 2236 base_op = new_register(T_INT);
aoqi@0 2237 __ convert(Bytecodes::_l2i, base.result(), base_op);
aoqi@0 2238 }
iveresov@7205 2239 if (x->has_index()) {
iveresov@7233 2240 if (index_op->type() == T_LONG) {
iveresov@7205 2241 LIR_Opr long_index_op = index_op;
iveresov@7233 2242 if (index_op->is_constant()) {
iveresov@7205 2243 long_index_op = new_register(T_LONG);
iveresov@7205 2244 __ move(index_op, long_index_op);
iveresov@7205 2245 }
iveresov@7205 2246 index_op = new_register(T_INT);
iveresov@7205 2247 __ convert(Bytecodes::_l2i, long_index_op, index_op);
iveresov@7205 2248 } else {
iveresov@7205 2249 assert(x->index()->type()->tag() == intTag, "must be");
iveresov@7205 2250 }
iveresov@7205 2251 }
iveresov@7205 2252 // At this point base and index should be all ints.
iveresov@7205 2253 assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");
iveresov@7205 2254 assert(!x->has_index() || index_op->type() == T_INT, "index should be an int");
iveresov@7205 2255 #else
iveresov@7205 2256 if (x->has_index()) {
iveresov@7233 2257 if (index_op->type() == T_INT) {
iveresov@7233 2258 if (!index_op->is_constant()) {
iveresov@7205 2259 index_op = new_register(T_LONG);
iveresov@7205 2260 __ convert(Bytecodes::_i2l, idx.result(), index_op);
iveresov@7205 2261 }
iveresov@7205 2262 } else {
iveresov@7233 2263 assert(index_op->type() == T_LONG, "must be");
iveresov@7233 2264 if (index_op->is_constant()) {
iveresov@7205 2265 index_op = new_register(T_LONG);
iveresov@7205 2266 __ move(idx.result(), index_op);
iveresov@7205 2267 }
iveresov@7205 2268 }
iveresov@7205 2269 }
iveresov@7205 2270 // At this point base is a long non-constant
iveresov@7205 2271 // Index is a long register or a int constant.
iveresov@7205 2272 // We allow the constant to stay an int because that would allow us a more compact encoding by
iveresov@7205 2273 // embedding an immediate offset in the address expression. If we have a long constant, we have to
iveresov@7205 2274 // move it into a register first.
iveresov@7205 2275 assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a long non-constant");
iveresov@7205 2276 assert(!x->has_index() || (index_op->type() == T_INT && index_op->is_constant()) ||
iveresov@7205 2277 (index_op->type() == T_LONG && !index_op->is_constant()), "unexpected index type");
aoqi@0 2278 #endif
aoqi@0 2279
aoqi@0 2280 BasicType dst_type = x->basic_type();
aoqi@0 2281
aoqi@0 2282 LIR_Address* addr;
aoqi@0 2283 if (index_op->is_constant()) {
aoqi@0 2284 assert(log2_scale == 0, "must not have a scale");
iveresov@7205 2285 assert(index_op->type() == T_INT, "only int constants supported");
aoqi@0 2286 addr = new LIR_Address(base_op, index_op->as_jint(), dst_type);
aoqi@0 2287 } else {
aoqi@0 2288 #ifdef X86
aoqi@0 2289 addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type);
dlong@7598 2290 #elif defined(GENERATE_ADDRESS_IS_PREFERRED)
aoqi@0 2291 addr = generate_address(base_op, index_op, log2_scale, 0, dst_type);
aoqi@0 2292 #else
aoqi@0 2293 if (index_op->is_illegal() || log2_scale == 0) {
aoqi@1 2294 #ifndef MIPS64
aoqi@0 2295 addr = new LIR_Address(base_op, index_op, dst_type);
aoqi@1 2296 #else
aoqi@1 2297 #ifdef _LP64
aoqi@1 2298 LIR_Opr ptr = new_register(T_LONG);
aoqi@1 2299 #else
aoqi@1 2300 LIR_Opr ptr = new_register(T_INT);
aoqi@1 2301 #endif
aoqi@1 2302 __ move(base_op, ptr);
aoqi@1 2303 if(index_op -> is_valid())
aoqi@1 2304 __ add(ptr, index_op, ptr);
aoqi@1 2305 addr = new LIR_Address(ptr, 0, dst_type);
aoqi@1 2306 #endif
aoqi@0 2307 } else {
aoqi@0 2308 LIR_Opr tmp = new_pointer_register();
aoqi@0 2309 __ shift_left(index_op, log2_scale, tmp);
aoqi@0 2310 addr = new LIR_Address(base_op, tmp, dst_type);
aoqi@0 2311 }
aoqi@0 2312 #endif
aoqi@0 2313 }
aoqi@0 2314
aoqi@0 2315 if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) {
aoqi@0 2316 __ unaligned_move(addr, reg);
aoqi@0 2317 } else {
aoqi@0 2318 if (dst_type == T_OBJECT && x->is_wide()) {
aoqi@0 2319 __ move_wide(addr, reg);
aoqi@0 2320 } else {
aoqi@0 2321 __ move(addr, reg);
aoqi@0 2322 }
aoqi@0 2323 }
aoqi@0 2324 }
aoqi@0 2325
aoqi@0 2326
aoqi@0 2327 void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) {
aoqi@0 2328 int log2_scale = 0;
aoqi@0 2329 BasicType type = x->basic_type();
aoqi@0 2330
aoqi@0 2331 if (x->has_index()) {
aoqi@0 2332 log2_scale = x->log2_scale();
aoqi@0 2333 }
aoqi@0 2334
aoqi@0 2335 LIRItem base(x->base(), this);
aoqi@0 2336 LIRItem value(x->value(), this);
aoqi@0 2337 LIRItem idx(this);
aoqi@0 2338
aoqi@0 2339 base.load_item();
aoqi@0 2340 if (x->has_index()) {
aoqi@0 2341 idx.set_instruction(x->index());
aoqi@0 2342 idx.load_item();
aoqi@0 2343 }
aoqi@0 2344
aoqi@0 2345 if (type == T_BYTE || type == T_BOOLEAN) {
aoqi@0 2346 value.load_byte_item();
aoqi@0 2347 } else {
aoqi@0 2348 value.load_item();
aoqi@0 2349 }
aoqi@0 2350
aoqi@0 2351 set_no_result(x);
aoqi@0 2352
aoqi@0 2353 LIR_Opr base_op = base.result();
iveresov@7205 2354 LIR_Opr index_op = idx.result();
iveresov@7205 2355
dlong@7598 2356 #ifdef GENERATE_ADDRESS_IS_PREFERRED
dlong@7598 2357 LIR_Address* addr = generate_address(base_op, index_op, log2_scale, 0, x->basic_type());
dlong@7598 2358 #else
aoqi@0 2359 #ifndef _LP64
iveresov@7233 2360 if (base_op->type() == T_LONG) {
aoqi@0 2361 base_op = new_register(T_INT);
aoqi@0 2362 __ convert(Bytecodes::_l2i, base.result(), base_op);
aoqi@0 2363 }
iveresov@7205 2364 if (x->has_index()) {
iveresov@7233 2365 if (index_op->type() == T_LONG) {
iveresov@7205 2366 index_op = new_register(T_INT);
iveresov@7205 2367 __ convert(Bytecodes::_l2i, idx.result(), index_op);
iveresov@7205 2368 }
iveresov@7205 2369 }
iveresov@7205 2370 // At this point base and index should be all ints and not constants
iveresov@7205 2371 assert(base_op->type() == T_INT && !base_op->is_constant(), "base should be an non-constant int");
iveresov@7205 2372 assert(!x->has_index() || (index_op->type() == T_INT && !index_op->is_constant()), "index should be an non-constant int");
iveresov@7205 2373 #else
iveresov@7205 2374 if (x->has_index()) {
iveresov@7233 2375 if (index_op->type() == T_INT) {
iveresov@7205 2376 index_op = new_register(T_LONG);
iveresov@7205 2377 __ convert(Bytecodes::_i2l, idx.result(), index_op);
iveresov@7205 2378 }
iveresov@7205 2379 }
iveresov@7205 2380 // At this point base and index are long and non-constant
iveresov@7205 2381 assert(base_op->type() == T_LONG && !base_op->is_constant(), "base must be a non-constant long");
iveresov@7205 2382 assert(!x->has_index() || (index_op->type() == T_LONG && !index_op->is_constant()), "index must be a non-constant long");
aoqi@0 2383 #endif
aoqi@0 2384
aoqi@0 2385 if (log2_scale != 0) {
aoqi@0 2386 // temporary fix (platform dependent code without shift on Intel would be better)
iveresov@7205 2387 // TODO: ARM also allows embedded shift in the address
roland@7924 2388 LIR_Opr tmp = new_pointer_register();
roland@7924 2389 if (TwoOperandLIRForm) {
roland@7924 2390 __ move(index_op, tmp);
roland@7924 2391 index_op = tmp;
roland@7924 2392 }
roland@7924 2393 __ shift_left(index_op, log2_scale, tmp);
roland@7924 2394 if (!TwoOperandLIRForm) {
roland@7924 2395 index_op = tmp;
roland@7924 2396 }
aoqi@0 2397 }
aoqi@0 2398
aoqi@0 2399 LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());
dlong@7598 2400 #endif // !GENERATE_ADDRESS_IS_PREFERRED
aoqi@0 2401 __ move(value.result(), addr);
aoqi@0 2402 }
aoqi@0 2403
aoqi@0 2404
aoqi@0 2405 void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {
aoqi@0 2406 BasicType type = x->basic_type();
aoqi@0 2407 LIRItem src(x->object(), this);
aoqi@0 2408 LIRItem off(x->offset(), this);
aoqi@0 2409
aoqi@0 2410 off.load_item();
aoqi@0 2411 src.load_item();
aoqi@0 2412
aoqi@0 2413 LIR_Opr value = rlock_result(x, x->basic_type());
aoqi@0 2414
aoqi@0 2415 get_Object_unsafe(value, src.result(), off.result(), type, x->is_volatile());
aoqi@0 2416
aoqi@0 2417 #if INCLUDE_ALL_GCS
aoqi@0 2418 // We might be reading the value of the referent field of a
aoqi@0 2419 // Reference object in order to attach it back to the live
aoqi@0 2420 // object graph. If G1 is enabled then we need to record
aoqi@0 2421 // the value that is being returned in an SATB log buffer.
aoqi@0 2422 //
aoqi@0 2423 // We need to generate code similar to the following...
aoqi@0 2424 //
aoqi@0 2425 // if (offset == java_lang_ref_Reference::referent_offset) {
aoqi@0 2426 // if (src != NULL) {
aoqi@0 2427 // if (klass(src)->reference_type() != REF_NONE) {
aoqi@0 2428 // pre_barrier(..., value, ...);
aoqi@0 2429 // }
aoqi@0 2430 // }
aoqi@0 2431 // }
aoqi@0 2432
aoqi@0 2433 if (UseG1GC && type == T_OBJECT) {
aoqi@0 2434 bool gen_pre_barrier = true; // Assume we need to generate pre_barrier.
aoqi@0 2435 bool gen_offset_check = true; // Assume we need to generate the offset guard.
aoqi@0 2436 bool gen_source_check = true; // Assume we need to check the src object for null.
aoqi@0 2437 bool gen_type_check = true; // Assume we need to check the reference_type.
aoqi@0 2438
aoqi@0 2439 if (off.is_constant()) {
aoqi@0 2440 jlong off_con = (off.type()->is_int() ?
aoqi@0 2441 (jlong) off.get_jint_constant() :
aoqi@0 2442 off.get_jlong_constant());
aoqi@0 2443
aoqi@0 2444
aoqi@0 2445 if (off_con != (jlong) java_lang_ref_Reference::referent_offset) {
aoqi@0 2446 // The constant offset is something other than referent_offset.
aoqi@0 2447 // We can skip generating/checking the remaining guards and
aoqi@0 2448 // skip generation of the code stub.
aoqi@0 2449 gen_pre_barrier = false;
aoqi@0 2450 } else {
aoqi@0 2451 // The constant offset is the same as referent_offset -
aoqi@0 2452 // we do not need to generate a runtime offset check.
aoqi@0 2453 gen_offset_check = false;
aoqi@0 2454 }
aoqi@0 2455 }
aoqi@0 2456
aoqi@0 2457 // We don't need to generate stub if the source object is an array
aoqi@0 2458 if (gen_pre_barrier && src.type()->is_array()) {
aoqi@0 2459 gen_pre_barrier = false;
aoqi@0 2460 }
aoqi@0 2461
aoqi@0 2462 if (gen_pre_barrier) {
aoqi@0 2463 // We still need to continue with the checks.
aoqi@0 2464 if (src.is_constant()) {
aoqi@0 2465 ciObject* src_con = src.get_jobject_constant();
aoqi@0 2466 guarantee(src_con != NULL, "no source constant");
aoqi@0 2467
aoqi@0 2468 if (src_con->is_null_object()) {
aoqi@0 2469 // The constant src object is null - We can skip
aoqi@0 2470 // generating the code stub.
aoqi@0 2471 gen_pre_barrier = false;
aoqi@0 2472 } else {
aoqi@0 2473 // Non-null constant source object. We still have to generate
aoqi@0 2474 // the slow stub - but we don't need to generate the runtime
aoqi@0 2475 // null object check.
aoqi@0 2476 gen_source_check = false;
aoqi@0 2477 }
aoqi@0 2478 }
aoqi@0 2479 }
aoqi@0 2480 if (gen_pre_barrier && !PatchALot) {
aoqi@0 2481 // Can the klass of object be statically determined to be
aoqi@0 2482 // a sub-class of Reference?
aoqi@0 2483 ciType* type = src.value()->declared_type();
aoqi@0 2484 if ((type != NULL) && type->is_loaded()) {
aoqi@0 2485 if (type->is_subtype_of(compilation()->env()->Reference_klass())) {
aoqi@0 2486 gen_type_check = false;
aoqi@0 2487 } else if (type->is_klass() &&
aoqi@0 2488 !compilation()->env()->Object_klass()->is_subtype_of(type->as_klass())) {
aoqi@0 2489 // Not Reference and not Object klass.
aoqi@0 2490 gen_pre_barrier = false;
aoqi@0 2491 }
aoqi@0 2492 }
aoqi@0 2493 }
aoqi@0 2494
aoqi@0 2495 if (gen_pre_barrier) {
aoqi@0 2496 LabelObj* Lcont = new LabelObj();
aoqi@0 2497
aoqi@0 2498 // We can have generate one runtime check here. Let's start with
aoqi@0 2499 // the offset check.
aoqi@0 2500 if (gen_offset_check) {
aoqi@0 2501 // if (offset != referent_offset) -> continue
aoqi@0 2502 // If offset is an int then we can do the comparison with the
aoqi@0 2503 // referent_offset constant; otherwise we need to move
aoqi@0 2504 // referent_offset into a temporary register and generate
aoqi@0 2505 // a reg-reg compare.
aoqi@0 2506
aoqi@0 2507 LIR_Opr referent_off;
aoqi@0 2508
aoqi@0 2509 if (off.type()->is_int()) {
aoqi@0 2510 referent_off = LIR_OprFact::intConst(java_lang_ref_Reference::referent_offset);
aoqi@0 2511 } else {
aoqi@0 2512 assert(off.type()->is_long(), "what else?");
aoqi@0 2513 referent_off = new_register(T_LONG);
aoqi@0 2514 __ move(LIR_OprFact::longConst(java_lang_ref_Reference::referent_offset), referent_off);
aoqi@0 2515 }
aoqi@1 2516 #ifndef MIPS64
aoqi@0 2517 __ cmp(lir_cond_notEqual, off.result(), referent_off);
aoqi@0 2518 __ branch(lir_cond_notEqual, as_BasicType(off.type()), Lcont->label());
aoqi@1 2519 #else
aoqi@1 2520 __ branch(lir_cond_notEqual, off.result(), referent_off, Lcont->label());
aoqi@1 2521 #endif
aoqi@0 2522 }
aoqi@0 2523 if (gen_source_check) {
aoqi@0 2524 // offset is a const and equals referent offset
aoqi@0 2525 // if (source == null) -> continue
aoqi@1 2526 #ifndef MIPS64
aoqi@0 2527 __ cmp(lir_cond_equal, src.result(), LIR_OprFact::oopConst(NULL));
aoqi@0 2528 __ branch(lir_cond_equal, T_OBJECT, Lcont->label());
aoqi@1 2529 #else
aoqi@1 2530 __ branch(lir_cond_equal, src.result(), LIR_OprFact::oopConst(NULL), Lcont->label());
aoqi@1 2531 #endif
aoqi@0 2532 }
aoqi@0 2533 LIR_Opr src_klass = new_register(T_OBJECT);
aoqi@0 2534 if (gen_type_check) {
aoqi@0 2535 // We have determined that offset == referent_offset && src != null.
aoqi@0 2536 // if (src->_klass->_reference_type == REF_NONE) -> continue
aoqi@0 2537 __ move(new LIR_Address(src.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), src_klass);
aoqi@0 2538 LIR_Address* reference_type_addr = new LIR_Address(src_klass, in_bytes(InstanceKlass::reference_type_offset()), T_BYTE);
aoqi@0 2539 LIR_Opr reference_type = new_register(T_INT);
aoqi@0 2540 __ move(reference_type_addr, reference_type);
aoqi@1 2541 #ifndef MIPS64
aoqi@0 2542 __ cmp(lir_cond_equal, reference_type, LIR_OprFact::intConst(REF_NONE));
aoqi@0 2543 __ branch(lir_cond_equal, T_INT, Lcont->label());
aoqi@1 2544 #else
aoqi@1 2545 __ branch(lir_cond_equal, reference_type, LIR_OprFact::intConst(REF_NONE), Lcont->label());
aoqi@1 2546 #endif
aoqi@0 2547 }
aoqi@0 2548 {
aoqi@0 2549 // We have determined that src->_klass->_reference_type != REF_NONE
aoqi@0 2550 // so register the value in the referent field with the pre-barrier.
aoqi@0 2551 pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,
aoqi@0 2552 value /* pre_val */,
aoqi@0 2553 false /* do_load */,
aoqi@0 2554 false /* patch */,
aoqi@0 2555 NULL /* info */);
aoqi@0 2556 }
aoqi@0 2557 __ branch_destination(Lcont->label());
aoqi@0 2558 }
aoqi@0 2559 }
aoqi@0 2560 #endif // INCLUDE_ALL_GCS
aoqi@0 2561
aoqi@0 2562 if (x->is_volatile() && os::is_MP()) __ membar_acquire();
aoqi@0 2563 }
aoqi@0 2564
aoqi@0 2565
aoqi@0 2566 void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {
aoqi@0 2567 BasicType type = x->basic_type();
aoqi@0 2568 LIRItem src(x->object(), this);
aoqi@0 2569 LIRItem off(x->offset(), this);
aoqi@0 2570 LIRItem data(x->value(), this);
aoqi@0 2571
aoqi@0 2572 src.load_item();
aoqi@0 2573 if (type == T_BOOLEAN || type == T_BYTE) {
aoqi@0 2574 data.load_byte_item();
aoqi@0 2575 } else {
aoqi@0 2576 data.load_item();
aoqi@0 2577 }
aoqi@0 2578 off.load_item();
aoqi@0 2579
aoqi@0 2580 set_no_result(x);
aoqi@0 2581
aoqi@0 2582 if (x->is_volatile() && os::is_MP()) __ membar_release();
aoqi@0 2583 put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile());
aoqi@0 2584 if (x->is_volatile() && os::is_MP()) __ membar();
aoqi@0 2585 }
aoqi@0 2586
aoqi@0 2587
aoqi@0 2588 void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) {
aoqi@0 2589 LIRItem src(x->object(), this);
aoqi@0 2590 LIRItem off(x->offset(), this);
aoqi@0 2591
aoqi@0 2592 src.load_item();
aoqi@0 2593 if (off.is_constant() && can_inline_as_constant(x->offset())) {
aoqi@0 2594 // let it be a constant
aoqi@0 2595 off.dont_load_item();
aoqi@0 2596 } else {
aoqi@0 2597 off.load_item();
aoqi@0 2598 }
aoqi@0 2599
aoqi@0 2600 set_no_result(x);
aoqi@0 2601
aoqi@0 2602 LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE);
aoqi@0 2603 __ prefetch(addr, is_store);
aoqi@0 2604 }
aoqi@0 2605
aoqi@0 2606
aoqi@0 2607 void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) {
aoqi@0 2608 do_UnsafePrefetch(x, false);
aoqi@0 2609 }
aoqi@0 2610
aoqi@0 2611
aoqi@0 2612 void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {
aoqi@0 2613 do_UnsafePrefetch(x, true);
aoqi@0 2614 }
aoqi@0 2615
aoqi@0 2616
aoqi@0 2617 void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {
aoqi@0 2618 int lng = x->length();
aoqi@0 2619
aoqi@0 2620 for (int i = 0; i < lng; i++) {
aoqi@0 2621 SwitchRange* one_range = x->at(i);
aoqi@0 2622 int low_key = one_range->low_key();
aoqi@0 2623 int high_key = one_range->high_key();
aoqi@0 2624 BlockBegin* dest = one_range->sux();
aoqi@0 2625 if (low_key == high_key) {
aoqi@1 2626 #ifndef MIPS64
aoqi@0 2627 __ cmp(lir_cond_equal, value, low_key);
aoqi@0 2628 __ branch(lir_cond_equal, T_INT, dest);
aoqi@1 2629 #else
aoqi@1 2630 __ branch(lir_cond_equal, value, LIR_OprFact::intConst(low_key), T_INT, dest);
aoqi@1 2631 #endif
aoqi@0 2632 } else if (high_key - low_key == 1) {
aoqi@1 2633 #ifndef MIPS64
aoqi@0 2634 __ cmp(lir_cond_equal, value, low_key);
aoqi@0 2635 __ branch(lir_cond_equal, T_INT, dest);
aoqi@0 2636 __ cmp(lir_cond_equal, value, high_key);
aoqi@0 2637 __ branch(lir_cond_equal, T_INT, dest);
aoqi@1 2638 #else
aoqi@1 2639 __ branch(lir_cond_equal, value, LIR_OprFact::intConst(low_key), T_INT, dest);
aoqi@1 2640 __ branch(lir_cond_equal, value, LIR_OprFact::intConst(high_key), T_INT, dest);
aoqi@1 2641
aoqi@1 2642 #endif
aoqi@0 2643 } else {
aoqi@0 2644 LabelObj* L = new LabelObj();
aoqi@1 2645 #ifndef MIPS64
aoqi@0 2646 __ cmp(lir_cond_less, value, low_key);
aoqi@0 2647 __ branch(lir_cond_less, T_INT, L->label());
aoqi@0 2648 __ cmp(lir_cond_lessEqual, value, high_key);
aoqi@0 2649 __ branch(lir_cond_lessEqual, T_INT, dest);
aoqi@0 2650 __ branch_destination(L->label());
aoqi@1 2651 #else
aoqi@1 2652 __ branch(lir_cond_less, value, LIR_OprFact::intConst(low_key), L->label());
aoqi@1 2653 __ branch(lir_cond_lessEqual, value, LIR_OprFact::intConst(high_key), T_INT, dest);
aoqi@1 2654 __ branch_destination(L->label());
aoqi@1 2655 #endif
aoqi@0 2656 }
aoqi@0 2657 }
aoqi@0 2658 __ jump(default_sux);
aoqi@0 2659 }
aoqi@0 2660
aoqi@0 2661
aoqi@0 2662 SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) {
aoqi@0 2663 SwitchRangeList* res = new SwitchRangeList();
aoqi@0 2664 int len = x->length();
aoqi@0 2665 if (len > 0) {
aoqi@0 2666 BlockBegin* sux = x->sux_at(0);
aoqi@0 2667 int key = x->lo_key();
aoqi@0 2668 BlockBegin* default_sux = x->default_sux();
aoqi@0 2669 SwitchRange* range = new SwitchRange(key, sux);
aoqi@0 2670 for (int i = 0; i < len; i++, key++) {
aoqi@0 2671 BlockBegin* new_sux = x->sux_at(i);
aoqi@0 2672 if (sux == new_sux) {
aoqi@0 2673 // still in same range
aoqi@0 2674 range->set_high_key(key);
aoqi@0 2675 } else {
aoqi@0 2676 // skip tests which explicitly dispatch to the default
aoqi@0 2677 if (sux != default_sux) {
aoqi@0 2678 res->append(range);
aoqi@0 2679 }
aoqi@0 2680 range = new SwitchRange(key, new_sux);
aoqi@0 2681 }
aoqi@0 2682 sux = new_sux;
aoqi@0 2683 }
aoqi@0 2684 if (res->length() == 0 || res->last() != range) res->append(range);
aoqi@0 2685 }
aoqi@0 2686 return res;
aoqi@0 2687 }
aoqi@0 2688
aoqi@0 2689
aoqi@0 2690 // we expect the keys to be sorted by increasing value
aoqi@0 2691 SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) {
aoqi@0 2692 SwitchRangeList* res = new SwitchRangeList();
aoqi@0 2693 int len = x->length();
aoqi@0 2694 if (len > 0) {
aoqi@0 2695 BlockBegin* default_sux = x->default_sux();
aoqi@0 2696 int key = x->key_at(0);
aoqi@0 2697 BlockBegin* sux = x->sux_at(0);
aoqi@0 2698 SwitchRange* range = new SwitchRange(key, sux);
aoqi@0 2699 for (int i = 1; i < len; i++) {
aoqi@0 2700 int new_key = x->key_at(i);
aoqi@0 2701 BlockBegin* new_sux = x->sux_at(i);
aoqi@0 2702 if (key+1 == new_key && sux == new_sux) {
aoqi@0 2703 // still in same range
aoqi@0 2704 range->set_high_key(new_key);
aoqi@0 2705 } else {
aoqi@0 2706 // skip tests which explicitly dispatch to the default
aoqi@0 2707 if (range->sux() != default_sux) {
aoqi@0 2708 res->append(range);
aoqi@0 2709 }
aoqi@0 2710 range = new SwitchRange(new_key, new_sux);
aoqi@0 2711 }
aoqi@0 2712 key = new_key;
aoqi@0 2713 sux = new_sux;
aoqi@0 2714 }
aoqi@0 2715 if (res->length() == 0 || res->last() != range) res->append(range);
aoqi@0 2716 }
aoqi@0 2717 return res;
aoqi@0 2718 }
aoqi@0 2719
aoqi@0 2720
aoqi@0 2721 void LIRGenerator::do_TableSwitch(TableSwitch* x) {
aoqi@0 2722 LIRItem tag(x->tag(), this);
aoqi@0 2723 tag.load_item();
aoqi@0 2724 set_no_result(x);
aoqi@0 2725
aoqi@0 2726 if (x->is_safepoint()) {
aoqi@0 2727 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
aoqi@0 2728 }
aoqi@0 2729
aoqi@0 2730 // move values into phi locations
aoqi@0 2731 move_to_phi(x->state());
aoqi@0 2732
aoqi@0 2733 int lo_key = x->lo_key();
aoqi@0 2734 int hi_key = x->hi_key();
aoqi@0 2735 int len = x->length();
aoqi@0 2736 LIR_Opr value = tag.result();
aoqi@0 2737 if (UseTableRanges) {
aoqi@0 2738 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
aoqi@0 2739 } else {
aoqi@0 2740 for (int i = 0; i < len; i++) {
aoqi@1 2741 #ifndef MIPS64
aoqi@0 2742 __ cmp(lir_cond_equal, value, i + lo_key);
aoqi@0 2743 __ branch(lir_cond_equal, T_INT, x->sux_at(i));
aoqi@1 2744 #else
aoqi@1 2745 __ branch(lir_cond_equal, value, LIR_OprFact::intConst(i+lo_key), T_INT, x->sux_at(i));
aoqi@1 2746 #endif
aoqi@0 2747 }
aoqi@0 2748 __ jump(x->default_sux());
aoqi@0 2749 }
aoqi@0 2750 }
aoqi@0 2751
aoqi@0 2752
aoqi@0 2753 void LIRGenerator::do_LookupSwitch(LookupSwitch* x) {
aoqi@0 2754 LIRItem tag(x->tag(), this);
aoqi@0 2755 tag.load_item();
aoqi@0 2756 set_no_result(x);
aoqi@0 2757
aoqi@0 2758 if (x->is_safepoint()) {
aoqi@0 2759 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
aoqi@0 2760 }
aoqi@0 2761
aoqi@0 2762 // move values into phi locations
aoqi@0 2763 move_to_phi(x->state());
aoqi@0 2764
aoqi@0 2765 LIR_Opr value = tag.result();
aoqi@0 2766 if (UseTableRanges) {
aoqi@0 2767 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
aoqi@0 2768 } else {
aoqi@0 2769 int len = x->length();
aoqi@0 2770 for (int i = 0; i < len; i++) {
aoqi@1 2771 #ifndef MIPS64
aoqi@0 2772 __ cmp(lir_cond_equal, value, x->key_at(i));
aoqi@0 2773 __ branch(lir_cond_equal, T_INT, x->sux_at(i));
aoqi@1 2774 #else
aoqi@1 2775 __ branch(lir_cond_equal, value, LIR_OprFact::intConst(x->key_at(i)), T_INT, x->sux_at(i));
aoqi@1 2776 #endif
aoqi@0 2777 }
aoqi@0 2778 __ jump(x->default_sux());
aoqi@0 2779 }
aoqi@0 2780 }
aoqi@0 2781
aoqi@0 2782
aoqi@0 2783 void LIRGenerator::do_Goto(Goto* x) {
aoqi@0 2784 set_no_result(x);
aoqi@0 2785
aoqi@0 2786 if (block()->next()->as_OsrEntry()) {
aoqi@0 2787 // need to free up storage used for OSR entry point
aoqi@0 2788 LIR_Opr osrBuffer = block()->next()->operand();
aoqi@0 2789 BasicTypeList signature;
iveresov@7585 2790 signature.append(NOT_LP64(T_INT) LP64_ONLY(T_LONG)); // pass a pointer to osrBuffer
aoqi@0 2791 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
aoqi@0 2792 __ move(osrBuffer, cc->args()->at(0));
aoqi@0 2793 __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
aoqi@0 2794 getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
aoqi@0 2795 }
aoqi@0 2796
aoqi@0 2797 if (x->is_safepoint()) {
aoqi@0 2798 ValueStack* state = x->state_before() ? x->state_before() : x->state();
aoqi@0 2799
aoqi@0 2800 // increment backedge counter if needed
aoqi@0 2801 CodeEmitInfo* info = state_for(x, state);
aoqi@0 2802 increment_backedge_counter(info, x->profiled_bci());
aoqi@0 2803 CodeEmitInfo* safepoint_info = state_for(x, state);
aoqi@0 2804 __ safepoint(safepoint_poll_register(), safepoint_info);
aoqi@0 2805 }
aoqi@0 2806
aoqi@0 2807 // Gotos can be folded Ifs, handle this case.
aoqi@0 2808 if (x->should_profile()) {
aoqi@0 2809 ciMethod* method = x->profiled_method();
aoqi@0 2810 assert(method != NULL, "method should be set if branch is profiled");
aoqi@0 2811 ciMethodData* md = method->method_data_or_null();
aoqi@0 2812 assert(md != NULL, "Sanity");
aoqi@0 2813 ciProfileData* data = md->bci_to_data(x->profiled_bci());
aoqi@0 2814 assert(data != NULL, "must have profiling data");
aoqi@0 2815 int offset;
aoqi@0 2816 if (x->direction() == Goto::taken) {
aoqi@0 2817 assert(data->is_BranchData(), "need BranchData for two-way branches");
aoqi@0 2818 offset = md->byte_offset_of_slot(data, BranchData::taken_offset());
aoqi@0 2819 } else if (x->direction() == Goto::not_taken) {
aoqi@0 2820 assert(data->is_BranchData(), "need BranchData for two-way branches");
aoqi@0 2821 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
aoqi@0 2822 } else {
aoqi@0 2823 assert(data->is_JumpData(), "need JumpData for branches");
aoqi@0 2824 offset = md->byte_offset_of_slot(data, JumpData::taken_offset());
aoqi@0 2825 }
aoqi@0 2826 LIR_Opr md_reg = new_register(T_METADATA);
aoqi@0 2827 __ metadata2reg(md->constant_encoding(), md_reg);
aoqi@0 2828 increment_counter(new LIR_Address(md_reg, offset,
aoqi@0 2829 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);
aoqi@0 2830 }
aoqi@0 2831
aoqi@0 2832 // emit phi-instruction move after safepoint since this simplifies
aoqi@0 2833 // describing the state as the safepoint.
aoqi@0 2834 move_to_phi(x->state());
aoqi@0 2835
aoqi@0 2836 __ jump(x->default_sux());
aoqi@0 2837 }
aoqi@0 2838
aoqi@0 2839 /**
aoqi@0 2840 * Emit profiling code if needed for arguments, parameters, return value types
aoqi@0 2841 *
aoqi@0 2842 * @param md MDO the code will update at runtime
aoqi@0 2843 * @param md_base_offset common offset in the MDO for this profile and subsequent ones
aoqi@0 2844 * @param md_offset offset in the MDO (on top of md_base_offset) for this profile
aoqi@0 2845 * @param profiled_k current profile
aoqi@0 2846 * @param obj IR node for the object to be profiled
aoqi@0 2847 * @param mdp register to hold the pointer inside the MDO (md + md_base_offset).
aoqi@0 2848 * Set once we find an update to make and use for next ones.
aoqi@0 2849 * @param not_null true if we know obj cannot be null
aoqi@0 2850 * @param signature_at_call_k signature at call for obj
aoqi@0 2851 * @param callee_signature_k signature of callee for obj
aoqi@0 2852 * at call and callee signatures differ at method handle call
aoqi@0 2853 * @return the only klass we know will ever be seen at this profile point
aoqi@0 2854 */
aoqi@0 2855 ciKlass* LIRGenerator::profile_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k,
aoqi@0 2856 Value obj, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
aoqi@0 2857 ciKlass* callee_signature_k) {
aoqi@0 2858 ciKlass* result = NULL;
aoqi@0 2859 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);
aoqi@0 2860 bool do_update = !TypeEntries::is_type_unknown(profiled_k);
aoqi@0 2861 // known not to be null or null bit already set and already set to
aoqi@0 2862 // unknown: nothing we can do to improve profiling
aoqi@0 2863 if (!do_null && !do_update) {
aoqi@0 2864 return result;
aoqi@0 2865 }
aoqi@0 2866
aoqi@0 2867 ciKlass* exact_klass = NULL;
aoqi@0 2868 Compilation* comp = Compilation::current();
aoqi@0 2869 if (do_update) {
aoqi@0 2870 // try to find exact type, using CHA if possible, so that loading
aoqi@0 2871 // the klass from the object can be avoided
aoqi@0 2872 ciType* type = obj->exact_type();
aoqi@0 2873 if (type == NULL) {
aoqi@0 2874 type = obj->declared_type();
aoqi@0 2875 type = comp->cha_exact_type(type);
aoqi@0 2876 }
aoqi@0 2877 assert(type == NULL || type->is_klass(), "type should be class");
aoqi@0 2878 exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;
aoqi@0 2879
aoqi@0 2880 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
aoqi@0 2881 }
aoqi@0 2882
aoqi@0 2883 if (!do_null && !do_update) {
aoqi@0 2884 return result;
aoqi@0 2885 }
aoqi@0 2886
aoqi@0 2887 ciKlass* exact_signature_k = NULL;
aoqi@0 2888 if (do_update) {
aoqi@0 2889 // Is the type from the signature exact (the only one possible)?
aoqi@0 2890 exact_signature_k = signature_at_call_k->exact_klass();
aoqi@0 2891 if (exact_signature_k == NULL) {
aoqi@0 2892 exact_signature_k = comp->cha_exact_type(signature_at_call_k);
aoqi@0 2893 } else {
aoqi@0 2894 result = exact_signature_k;
aoqi@0 2895 // Known statically. No need to emit any code: prevent
aoqi@0 2896 // LIR_Assembler::emit_profile_type() from emitting useless code
aoqi@0 2897 profiled_k = ciTypeEntries::with_status(result, profiled_k);
aoqi@0 2898 }
aoqi@0 2899 // exact_klass and exact_signature_k can be both non NULL but
aoqi@0 2900 // different if exact_klass is loaded after the ciObject for
aoqi@0 2901 // exact_signature_k is created.
aoqi@0 2902 if (exact_klass == NULL && exact_signature_k != NULL && exact_klass != exact_signature_k) {
aoqi@0 2903 // sometimes the type of the signature is better than the best type
aoqi@0 2904 // the compiler has
aoqi@0 2905 exact_klass = exact_signature_k;
aoqi@0 2906 }
aoqi@0 2907 if (callee_signature_k != NULL &&
aoqi@0 2908 callee_signature_k != signature_at_call_k) {
aoqi@0 2909 ciKlass* improved_klass = callee_signature_k->exact_klass();
aoqi@0 2910 if (improved_klass == NULL) {
aoqi@0 2911 improved_klass = comp->cha_exact_type(callee_signature_k);
aoqi@0 2912 }
aoqi@0 2913 if (exact_klass == NULL && improved_klass != NULL && exact_klass != improved_klass) {
aoqi@0 2914 exact_klass = exact_signature_k;
aoqi@0 2915 }
aoqi@0 2916 }
aoqi@0 2917 do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
aoqi@0 2918 }
aoqi@0 2919
aoqi@0 2920 if (!do_null && !do_update) {
aoqi@0 2921 return result;
aoqi@0 2922 }
aoqi@0 2923
aoqi@0 2924 if (mdp == LIR_OprFact::illegalOpr) {
aoqi@0 2925 mdp = new_register(T_METADATA);
aoqi@0 2926 __ metadata2reg(md->constant_encoding(), mdp);
aoqi@0 2927 if (md_base_offset != 0) {
aoqi@0 2928 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
aoqi@0 2929 mdp = new_pointer_register();
aoqi@0 2930 __ leal(LIR_OprFact::address(base_type_address), mdp);
aoqi@0 2931 }
aoqi@0 2932 }
aoqi@0 2933 LIRItem value(obj, this);
aoqi@0 2934 value.load_item();
aoqi@0 2935 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),
aoqi@0 2936 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);
aoqi@0 2937 return result;
aoqi@0 2938 }
aoqi@0 2939
aoqi@0 2940 // profile parameters on entry to the root of the compilation
aoqi@0 2941 void LIRGenerator::profile_parameters(Base* x) {
aoqi@0 2942 if (compilation()->profile_parameters()) {
aoqi@0 2943 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
aoqi@0 2944 ciMethodData* md = scope()->method()->method_data_or_null();
aoqi@0 2945 assert(md != NULL, "Sanity");
aoqi@0 2946
aoqi@0 2947 if (md->parameters_type_data() != NULL) {
aoqi@0 2948 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
aoqi@0 2949 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
aoqi@0 2950 LIR_Opr mdp = LIR_OprFact::illegalOpr;
aoqi@0 2951 for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
aoqi@0 2952 LIR_Opr src = args->at(i);
aoqi@0 2953 assert(!src->is_illegal(), "check");
aoqi@0 2954 BasicType t = src->type();
aoqi@0 2955 if (t == T_OBJECT || t == T_ARRAY) {
aoqi@0 2956 intptr_t profiled_k = parameters->type(j);
aoqi@0 2957 Local* local = x->state()->local_at(java_index)->as_Local();
aoqi@0 2958 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
aoqi@0 2959 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
aoqi@0 2960 profiled_k, local, mdp, false, local->declared_type()->as_klass(), NULL);
aoqi@0 2961 // If the profile is known statically set it once for all and do not emit any code
aoqi@0 2962 if (exact != NULL) {
aoqi@0 2963 md->set_parameter_type(j, exact);
aoqi@0 2964 }
aoqi@0 2965 j++;
aoqi@0 2966 }
aoqi@0 2967 java_index += type2size[t];
aoqi@0 2968 }
aoqi@0 2969 }
aoqi@0 2970 }
aoqi@0 2971 }
aoqi@0 2972
aoqi@0 2973 void LIRGenerator::do_Base(Base* x) {
aoqi@0 2974 __ std_entry(LIR_OprFact::illegalOpr);
aoqi@0 2975 // Emit moves from physical registers / stack slots to virtual registers
aoqi@0 2976 CallingConvention* args = compilation()->frame_map()->incoming_arguments();
aoqi@0 2977 IRScope* irScope = compilation()->hir()->top_scope();
aoqi@0 2978 int java_index = 0;
aoqi@0 2979 for (int i = 0; i < args->length(); i++) {
aoqi@0 2980 LIR_Opr src = args->at(i);
aoqi@0 2981 assert(!src->is_illegal(), "check");
aoqi@0 2982 BasicType t = src->type();
aoqi@0 2983
aoqi@0 2984 // Types which are smaller than int are passed as int, so
aoqi@0 2985 // correct the type which passed.
aoqi@0 2986 switch (t) {
aoqi@0 2987 case T_BYTE:
aoqi@0 2988 case T_BOOLEAN:
aoqi@0 2989 case T_SHORT:
aoqi@0 2990 case T_CHAR:
aoqi@0 2991 t = T_INT;
aoqi@0 2992 break;
aoqi@0 2993 }
aoqi@0 2994
aoqi@0 2995 LIR_Opr dest = new_register(t);
aoqi@0 2996 __ move(src, dest);
aoqi@0 2997
aoqi@0 2998 // Assign new location to Local instruction for this local
aoqi@0 2999 Local* local = x->state()->local_at(java_index)->as_Local();
aoqi@0 3000 assert(local != NULL, "Locals for incoming arguments must have been created");
aoqi@0 3001 #ifndef __SOFTFP__
aoqi@0 3002 // The java calling convention passes double as long and float as int.
aoqi@0 3003 assert(as_ValueType(t)->tag() == local->type()->tag(), "check");
aoqi@0 3004 #endif // __SOFTFP__
aoqi@0 3005 local->set_operand(dest);
aoqi@0 3006 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL);
aoqi@0 3007 java_index += type2size[t];
aoqi@0 3008 }
aoqi@0 3009
aoqi@0 3010 if (compilation()->env()->dtrace_method_probes()) {
aoqi@0 3011 BasicTypeList signature;
aoqi@0 3012 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
aoqi@0 3013 signature.append(T_METADATA); // Method*
aoqi@0 3014 LIR_OprList* args = new LIR_OprList();
aoqi@0 3015 args->append(getThreadPointer());
aoqi@0 3016 LIR_Opr meth = new_register(T_METADATA);
aoqi@0 3017 __ metadata2reg(method()->constant_encoding(), meth);
aoqi@0 3018 args->append(meth);
aoqi@0 3019 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);
aoqi@0 3020 }
aoqi@0 3021
aoqi@0 3022 if (method()->is_synchronized()) {
aoqi@0 3023 LIR_Opr obj;
aoqi@0 3024 if (method()->is_static()) {
aoqi@0 3025 obj = new_register(T_OBJECT);
aoqi@0 3026 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
aoqi@0 3027 } else {
aoqi@0 3028 Local* receiver = x->state()->local_at(0)->as_Local();
aoqi@0 3029 assert(receiver != NULL, "must already exist");
aoqi@0 3030 obj = receiver->operand();
aoqi@0 3031 }
aoqi@0 3032 assert(obj->is_valid(), "must be valid");
aoqi@0 3033
aoqi@0 3034 if (method()->is_synchronized() && GenerateSynchronizationCode) {
aoqi@0 3035 LIR_Opr lock = new_register(T_INT);
aoqi@0 3036 __ load_stack_address_monitor(0, lock);
aoqi@0 3037
aoqi@0 3038 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
aoqi@0 3039 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
aoqi@0 3040
aoqi@0 3041 // receiver is guaranteed non-NULL so don't need CodeEmitInfo
aoqi@0 3042 __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
aoqi@0 3043 }
aoqi@0 3044 }
aoqi@0 3045
aoqi@0 3046 // increment invocation counters if needed
aoqi@0 3047 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
aoqi@0 3048 profile_parameters(x);
aoqi@0 3049 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
aoqi@0 3050 increment_invocation_counter(info);
aoqi@0 3051 }
aoqi@0 3052
aoqi@0 3053 // all blocks with a successor must end with an unconditional jump
aoqi@0 3054 // to the successor even if they are consecutive
aoqi@0 3055 __ jump(x->default_sux());
aoqi@0 3056 }
aoqi@0 3057
aoqi@0 3058
aoqi@0 3059 void LIRGenerator::do_OsrEntry(OsrEntry* x) {
aoqi@0 3060 // construct our frame and model the production of incoming pointer
aoqi@0 3061 // to the OSR buffer.
aoqi@0 3062 __ osr_entry(LIR_Assembler::osrBufferPointer());
aoqi@0 3063 LIR_Opr result = rlock_result(x);
aoqi@0 3064 __ move(LIR_Assembler::osrBufferPointer(), result);
aoqi@0 3065 }
aoqi@0 3066
aoqi@0 3067
aoqi@0 3068 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {
aoqi@0 3069 assert(args->length() == arg_list->length(),
aoqi@0 3070 err_msg_res("args=%d, arg_list=%d", args->length(), arg_list->length()));
aoqi@0 3071 for (int i = x->has_receiver() ? 1 : 0; i < args->length(); i++) {
aoqi@0 3072 LIRItem* param = args->at(i);
aoqi@0 3073 LIR_Opr loc = arg_list->at(i);
aoqi@0 3074 if (loc->is_register()) {
aoqi@0 3075 param->load_item_force(loc);
aoqi@0 3076 } else {
aoqi@0 3077 LIR_Address* addr = loc->as_address_ptr();
aoqi@0 3078 param->load_for_store(addr->type());
aoqi@0 3079 if (addr->type() == T_OBJECT) {
aoqi@0 3080 __ move_wide(param->result(), addr);
aoqi@0 3081 } else
aoqi@0 3082 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
aoqi@0 3083 __ unaligned_move(param->result(), addr);
aoqi@0 3084 } else {
aoqi@0 3085 __ move(param->result(), addr);
aoqi@0 3086 }
aoqi@0 3087 }
aoqi@0 3088 }
aoqi@0 3089
aoqi@0 3090 if (x->has_receiver()) {
aoqi@0 3091 LIRItem* receiver = args->at(0);
aoqi@0 3092 LIR_Opr loc = arg_list->at(0);
aoqi@0 3093 if (loc->is_register()) {
aoqi@0 3094 receiver->load_item_force(loc);
aoqi@0 3095 } else {
aoqi@0 3096 assert(loc->is_address(), "just checking");
aoqi@0 3097 receiver->load_for_store(T_OBJECT);
aoqi@0 3098 __ move_wide(receiver->result(), loc->as_address_ptr());
aoqi@0 3099 }
aoqi@0 3100 }
aoqi@0 3101 }
aoqi@0 3102
aoqi@0 3103
aoqi@0 3104 // Visits all arguments, returns appropriate items without loading them
aoqi@0 3105 LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) {
aoqi@0 3106 LIRItemList* argument_items = new LIRItemList();
aoqi@0 3107 if (x->has_receiver()) {
aoqi@0 3108 LIRItem* receiver = new LIRItem(x->receiver(), this);
aoqi@0 3109 argument_items->append(receiver);
aoqi@0 3110 }
aoqi@0 3111 for (int i = 0; i < x->number_of_arguments(); i++) {
aoqi@0 3112 LIRItem* param = new LIRItem(x->argument_at(i), this);
aoqi@0 3113 argument_items->append(param);
aoqi@0 3114 }
aoqi@0 3115 return argument_items;
aoqi@0 3116 }
aoqi@0 3117
aoqi@0 3118
aoqi@0 3119 // The invoke with receiver has following phases:
aoqi@0 3120 // a) traverse and load/lock receiver;
aoqi@0 3121 // b) traverse all arguments -> item-array (invoke_visit_argument)
aoqi@0 3122 // c) push receiver on stack
aoqi@0 3123 // d) load each of the items and push on stack
aoqi@0 3124 // e) unlock receiver
aoqi@0 3125 // f) move receiver into receiver-register %o0
aoqi@0 3126 // g) lock result registers and emit call operation
aoqi@0 3127 //
aoqi@0 3128 // Before issuing a call, we must spill-save all values on stack
zmajo@7854 3129 // that are in caller-save register. "spill-save" moves those registers
aoqi@0 3130 // either in a free callee-save register or spills them if no free
aoqi@0 3131 // callee save register is available.
aoqi@0 3132 //
aoqi@0 3133 // The problem is where to invoke spill-save.
aoqi@0 3134 // - if invoked between e) and f), we may lock callee save
aoqi@0 3135 // register in "spill-save" that destroys the receiver register
aoqi@0 3136 // before f) is executed
zmajo@7854 3137 // - if we rearrange f) to be earlier (by loading %o0) it
aoqi@0 3138 // may destroy a value on the stack that is currently in %o0
aoqi@0 3139 // and is waiting to be spilled
aoqi@0 3140 // - if we keep the receiver locked while doing spill-save,
aoqi@0 3141 // we cannot spill it as it is spill-locked
aoqi@0 3142 //
aoqi@0 3143 void LIRGenerator::do_Invoke(Invoke* x) {
aoqi@0 3144 CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true);
aoqi@0 3145
aoqi@0 3146 LIR_OprList* arg_list = cc->args();
aoqi@0 3147 LIRItemList* args = invoke_visit_arguments(x);
aoqi@0 3148 LIR_Opr receiver = LIR_OprFact::illegalOpr;
aoqi@0 3149
aoqi@0 3150 // setup result register
aoqi@0 3151 LIR_Opr result_register = LIR_OprFact::illegalOpr;
aoqi@0 3152 if (x->type() != voidType) {
aoqi@0 3153 result_register = result_register_for(x->type());
aoqi@0 3154 }
aoqi@0 3155
aoqi@0 3156 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 3157
aoqi@0 3158 invoke_load_arguments(x, args, arg_list);
aoqi@0 3159
aoqi@0 3160 if (x->has_receiver()) {
aoqi@0 3161 args->at(0)->load_item_force(LIR_Assembler::receiverOpr());
aoqi@0 3162 receiver = args->at(0)->result();
aoqi@0 3163 }
aoqi@0 3164
aoqi@0 3165 // emit invoke code
aoqi@0 3166 bool optimized = x->target_is_loaded() && x->target_is_final();
aoqi@0 3167 assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match");
aoqi@0 3168
aoqi@0 3169 // JSR 292
zmajo@7854 3170 // Preserve the SP over MethodHandle call sites, if needed.
aoqi@0 3171 ciMethod* target = x->target();
aoqi@0 3172 bool is_method_handle_invoke = (// %%% FIXME: Are both of these relevant?
aoqi@0 3173 target->is_method_handle_intrinsic() ||
aoqi@0 3174 target->is_compiled_lambda_form());
aoqi@0 3175 if (is_method_handle_invoke) {
aoqi@0 3176 info->set_is_method_handle_invoke(true);
zmajo@7854 3177 if(FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {
zmajo@7854 3178 __ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr());
zmajo@7854 3179 }
aoqi@0 3180 }
aoqi@0 3181
aoqi@0 3182 switch (x->code()) {
aoqi@0 3183 case Bytecodes::_invokestatic:
aoqi@0 3184 __ call_static(target, result_register,
aoqi@0 3185 SharedRuntime::get_resolve_static_call_stub(),
aoqi@0 3186 arg_list, info);
aoqi@0 3187 break;
aoqi@0 3188 case Bytecodes::_invokespecial:
aoqi@0 3189 case Bytecodes::_invokevirtual:
aoqi@0 3190 case Bytecodes::_invokeinterface:
aoqi@0 3191 // for final target we still produce an inline cache, in order
aoqi@0 3192 // to be able to call mixed mode
aoqi@0 3193 if (x->code() == Bytecodes::_invokespecial || optimized) {
aoqi@0 3194 __ call_opt_virtual(target, receiver, result_register,
aoqi@0 3195 SharedRuntime::get_resolve_opt_virtual_call_stub(),
aoqi@0 3196 arg_list, info);
aoqi@0 3197 } else if (x->vtable_index() < 0) {
aoqi@0 3198 __ call_icvirtual(target, receiver, result_register,
aoqi@0 3199 SharedRuntime::get_resolve_virtual_call_stub(),
aoqi@0 3200 arg_list, info);
aoqi@0 3201 } else {
aoqi@0 3202 int entry_offset = InstanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size();
aoqi@0 3203 int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
aoqi@0 3204 __ call_virtual(target, receiver, result_register, vtable_offset, arg_list, info);
aoqi@0 3205 }
aoqi@0 3206 break;
aoqi@0 3207 case Bytecodes::_invokedynamic: {
aoqi@0 3208 __ call_dynamic(target, receiver, result_register,
aoqi@0 3209 SharedRuntime::get_resolve_static_call_stub(),
aoqi@0 3210 arg_list, info);
aoqi@0 3211 break;
aoqi@0 3212 }
aoqi@0 3213 default:
aoqi@0 3214 fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(x->code())));
aoqi@0 3215 break;
aoqi@0 3216 }
aoqi@0 3217
aoqi@0 3218 // JSR 292
zmajo@7854 3219 // Restore the SP after MethodHandle call sites, if needed.
zmajo@7854 3220 if (is_method_handle_invoke
zmajo@7854 3221 && FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) {
aoqi@0 3222 __ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer());
aoqi@0 3223 }
aoqi@0 3224
aoqi@0 3225 if (x->type()->is_float() || x->type()->is_double()) {
aoqi@0 3226 // Force rounding of results from non-strictfp when in strictfp
aoqi@0 3227 // scope (or when we don't know the strictness of the callee, to
aoqi@0 3228 // be safe.)
aoqi@0 3229 if (method()->is_strict()) {
aoqi@0 3230 if (!x->target_is_loaded() || !x->target_is_strictfp()) {
aoqi@0 3231 result_register = round_item(result_register);
aoqi@0 3232 }
aoqi@0 3233 }
aoqi@0 3234 }
aoqi@0 3235
aoqi@0 3236 if (result_register->is_valid()) {
aoqi@0 3237 LIR_Opr result = rlock_result(x);
aoqi@0 3238 __ move(result_register, result);
aoqi@0 3239 }
aoqi@0 3240 }
aoqi@0 3241
aoqi@0 3242
aoqi@0 3243 void LIRGenerator::do_FPIntrinsics(Intrinsic* x) {
aoqi@0 3244 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@0 3245 LIRItem value (x->argument_at(0), this);
aoqi@0 3246 LIR_Opr reg = rlock_result(x);
aoqi@0 3247 value.load_item();
aoqi@0 3248 LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type()));
aoqi@0 3249 __ move(tmp, reg);
aoqi@0 3250 }
aoqi@0 3251
aoqi@0 3252
aoqi@0 3253
aoqi@0 3254 // Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval()
aoqi@0 3255 void LIRGenerator::do_IfOp(IfOp* x) {
aoqi@0 3256 #ifdef ASSERT
aoqi@0 3257 {
aoqi@0 3258 ValueTag xtag = x->x()->type()->tag();
aoqi@0 3259 ValueTag ttag = x->tval()->type()->tag();
aoqi@0 3260 assert(xtag == intTag || xtag == objectTag, "cannot handle others");
aoqi@0 3261 assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");
aoqi@0 3262 assert(ttag == x->fval()->type()->tag(), "cannot handle others");
aoqi@0 3263 }
aoqi@0 3264 #endif
aoqi@0 3265
aoqi@0 3266 LIRItem left(x->x(), this);
aoqi@0 3267 LIRItem right(x->y(), this);
aoqi@0 3268 left.load_item();
aoqi@0 3269 if (can_inline_as_constant(right.value())) {
aoqi@0 3270 right.dont_load_item();
aoqi@0 3271 } else {
aoqi@0 3272 right.load_item();
aoqi@0 3273 }
aoqi@0 3274
aoqi@0 3275 LIRItem t_val(x->tval(), this);
aoqi@0 3276 LIRItem f_val(x->fval(), this);
aoqi@0 3277 t_val.dont_load_item();
aoqi@0 3278 f_val.dont_load_item();
aoqi@0 3279 LIR_Opr reg = rlock_result(x);
roland@6668 3280
aoqi@1 3281 #ifndef MIPS64
aoqi@0 3282 __ cmp(lir_cond(x->cond()), left.result(), right.result());
aoqi@0 3283 __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type()));
aoqi@1 3284 #else
aoqi@1 3285 LIR_Opr opr1 = t_val.result();
aoqi@1 3286 LIR_Opr opr2 = f_val.result();
aoqi@1 3287 LabelObj* skip = new LabelObj();
aoqi@1 3288 __ move(opr1, reg);
aoqi@1 3289 __ branch(lir_cond(x->cond()), left.result(), right.result(), skip->label());
aoqi@1 3290 __ move(opr2, reg);
aoqi@1 3291 __ branch_destination(skip->label());
aoqi@1 3292 #endif
aoqi@0 3293 }
aoqi@0 3294
aoqi@0 3295 void LIRGenerator::do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x) {
aoqi@0 3296 assert(x->number_of_arguments() == expected_arguments, "wrong type");
aoqi@0 3297 LIR_Opr reg = result_register_for(x->type());
aoqi@0 3298 __ call_runtime_leaf(routine, getThreadTemp(),
aoqi@0 3299 reg, new LIR_OprList());
aoqi@0 3300 LIR_Opr result = rlock_result(x);
aoqi@0 3301 __ move(reg, result);
aoqi@0 3302 }
aoqi@0 3303
aoqi@0 3304 #ifdef TRACE_HAVE_INTRINSICS
aoqi@0 3305 void LIRGenerator::do_ThreadIDIntrinsic(Intrinsic* x) {
aoqi@0 3306 LIR_Opr thread = getThreadPointer();
aoqi@0 3307 LIR_Opr osthread = new_pointer_register();
aoqi@0 3308 __ move(new LIR_Address(thread, in_bytes(JavaThread::osthread_offset()), osthread->type()), osthread);
aoqi@0 3309 size_t thread_id_size = OSThread::thread_id_size();
aoqi@0 3310 if (thread_id_size == (size_t) BytesPerLong) {
aoqi@0 3311 LIR_Opr id = new_register(T_LONG);
aoqi@0 3312 __ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_LONG), id);
aoqi@0 3313 __ convert(Bytecodes::_l2i, id, rlock_result(x));
aoqi@0 3314 } else if (thread_id_size == (size_t) BytesPerInt) {
aoqi@0 3315 __ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_INT), rlock_result(x));
aoqi@0 3316 } else {
aoqi@0 3317 ShouldNotReachHere();
aoqi@0 3318 }
aoqi@0 3319 }
aoqi@0 3320
aoqi@0 3321 void LIRGenerator::do_ClassIDIntrinsic(Intrinsic* x) {
aoqi@0 3322 CodeEmitInfo* info = state_for(x);
aoqi@0 3323 CodeEmitInfo* info2 = new CodeEmitInfo(info); // Clone for the second null check
aoqi@0 3324 BasicType klass_pointer_type = NOT_LP64(T_INT) LP64_ONLY(T_LONG);
aoqi@0 3325 assert(info != NULL, "must have info");
aoqi@0 3326 LIRItem arg(x->argument_at(1), this);
aoqi@0 3327 arg.load_item();
aoqi@0 3328 LIR_Opr klass = new_pointer_register();
aoqi@0 3329 __ move(new LIR_Address(arg.result(), java_lang_Class::klass_offset_in_bytes(), klass_pointer_type), klass, info);
aoqi@0 3330 LIR_Opr id = new_register(T_LONG);
aoqi@0 3331 ByteSize offset = TRACE_ID_OFFSET;
aoqi@0 3332 LIR_Address* trace_id_addr = new LIR_Address(klass, in_bytes(offset), T_LONG);
aoqi@0 3333 __ move(trace_id_addr, id);
aoqi@0 3334 __ logical_or(id, LIR_OprFact::longConst(0x01l), id);
aoqi@0 3335 __ store(id, trace_id_addr);
aoqi@0 3336 __ logical_and(id, LIR_OprFact::longConst(~0x3l), id);
aoqi@0 3337 __ move(id, rlock_result(x));
aoqi@0 3338 }
aoqi@0 3339 #endif
aoqi@0 3340
aoqi@0 3341 void LIRGenerator::do_Intrinsic(Intrinsic* x) {
aoqi@0 3342 switch (x->id()) {
aoqi@0 3343 case vmIntrinsics::_intBitsToFloat :
aoqi@0 3344 case vmIntrinsics::_doubleToRawLongBits :
aoqi@0 3345 case vmIntrinsics::_longBitsToDouble :
aoqi@0 3346 case vmIntrinsics::_floatToRawIntBits : {
aoqi@0 3347 do_FPIntrinsics(x);
aoqi@0 3348 break;
aoqi@0 3349 }
aoqi@0 3350
aoqi@0 3351 #ifdef TRACE_HAVE_INTRINSICS
aoqi@0 3352 case vmIntrinsics::_threadID: do_ThreadIDIntrinsic(x); break;
aoqi@0 3353 case vmIntrinsics::_classID: do_ClassIDIntrinsic(x); break;
aoqi@0 3354 case vmIntrinsics::_counterTime:
aoqi@0 3355 do_RuntimeCall(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), 0, x);
aoqi@0 3356 break;
aoqi@0 3357 #endif
aoqi@0 3358
aoqi@0 3359 case vmIntrinsics::_currentTimeMillis:
aoqi@0 3360 do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), 0, x);
aoqi@0 3361 break;
aoqi@0 3362
aoqi@0 3363 case vmIntrinsics::_nanoTime:
aoqi@0 3364 do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), 0, x);
aoqi@0 3365 break;
aoqi@0 3366
aoqi@0 3367 case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;
aoqi@0 3368 case vmIntrinsics::_isInstance: do_isInstance(x); break;
aoqi@0 3369 case vmIntrinsics::_getClass: do_getClass(x); break;
aoqi@0 3370 case vmIntrinsics::_currentThread: do_currentThread(x); break;
aoqi@0 3371
aoqi@0 3372 case vmIntrinsics::_dlog: // fall through
aoqi@0 3373 case vmIntrinsics::_dlog10: // fall through
aoqi@0 3374 case vmIntrinsics::_dabs: // fall through
aoqi@0 3375 case vmIntrinsics::_dsqrt: // fall through
aoqi@0 3376 case vmIntrinsics::_dtan: // fall through
aoqi@0 3377 case vmIntrinsics::_dsin : // fall through
aoqi@0 3378 case vmIntrinsics::_dcos : // fall through
aoqi@0 3379 case vmIntrinsics::_dexp : // fall through
aoqi@0 3380 case vmIntrinsics::_dpow : do_MathIntrinsic(x); break;
aoqi@0 3381 case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break;
aoqi@0 3382
aoqi@0 3383 // java.nio.Buffer.checkIndex
aoqi@0 3384 case vmIntrinsics::_checkIndex: do_NIOCheckIndex(x); break;
aoqi@0 3385
aoqi@0 3386 case vmIntrinsics::_compareAndSwapObject:
aoqi@0 3387 do_CompareAndSwap(x, objectType);
aoqi@0 3388 break;
aoqi@0 3389 case vmIntrinsics::_compareAndSwapInt:
aoqi@0 3390 do_CompareAndSwap(x, intType);
aoqi@0 3391 break;
aoqi@0 3392 case vmIntrinsics::_compareAndSwapLong:
aoqi@0 3393 do_CompareAndSwap(x, longType);
aoqi@0 3394 break;
aoqi@0 3395
aoqi@0 3396 case vmIntrinsics::_loadFence :
aoqi@0 3397 if (os::is_MP()) __ membar_acquire();
aoqi@0 3398 break;
aoqi@0 3399 case vmIntrinsics::_storeFence:
aoqi@0 3400 if (os::is_MP()) __ membar_release();
aoqi@0 3401 break;
aoqi@0 3402 case vmIntrinsics::_fullFence :
aoqi@0 3403 if (os::is_MP()) __ membar();
aoqi@0 3404 break;
aoqi@0 3405
aoqi@0 3406 case vmIntrinsics::_Reference_get:
aoqi@0 3407 do_Reference_get(x);
aoqi@0 3408 break;
aoqi@0 3409
aoqi@0 3410 case vmIntrinsics::_updateCRC32:
aoqi@0 3411 case vmIntrinsics::_updateBytesCRC32:
aoqi@0 3412 case vmIntrinsics::_updateByteBufferCRC32:
aoqi@0 3413 do_update_CRC32(x);
aoqi@0 3414 break;
aoqi@0 3415
aoqi@0 3416 default: ShouldNotReachHere(); break;
aoqi@0 3417 }
aoqi@0 3418 }
aoqi@0 3419
aoqi@0 3420 void LIRGenerator::profile_arguments(ProfileCall* x) {
aoqi@0 3421 if (compilation()->profile_arguments()) {
aoqi@0 3422 int bci = x->bci_of_invoke();
aoqi@0 3423 ciMethodData* md = x->method()->method_data_or_null();
aoqi@0 3424 ciProfileData* data = md->bci_to_data(bci);
aoqi@0 3425 if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
aoqi@0 3426 (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
aoqi@0 3427 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
aoqi@0 3428 int base_offset = md->byte_offset_of_slot(data, extra);
aoqi@0 3429 LIR_Opr mdp = LIR_OprFact::illegalOpr;
aoqi@0 3430 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
aoqi@0 3431
aoqi@0 3432 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
aoqi@0 3433 int start = 0;
aoqi@0 3434 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
dbuck@8657 3435 if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) {
aoqi@0 3436 // first argument is not profiled at call (method handle invoke)
aoqi@0 3437 assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected");
aoqi@0 3438 start = 1;
aoqi@0 3439 }
aoqi@0 3440 ciSignature* callee_signature = x->callee()->signature();
aoqi@0 3441 // method handle call to virtual method
dbuck@8657 3442 bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
aoqi@0 3443 ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : NULL);
aoqi@0 3444
aoqi@0 3445 bool ignored_will_link;
aoqi@0 3446 ciSignature* signature_at_call = NULL;
aoqi@0 3447 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
aoqi@0 3448 ciSignatureStream signature_at_call_stream(signature_at_call);
aoqi@0 3449
aoqi@0 3450 // if called through method handle invoke, some arguments may have been popped
aoqi@0 3451 for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) {
aoqi@0 3452 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
aoqi@0 3453 ciKlass* exact = profile_type(md, base_offset, off,
aoqi@0 3454 args->type(i), x->profiled_arg_at(i+start), mdp,
aoqi@0 3455 !x->arg_needs_null_check(i+start),
aoqi@0 3456 signature_at_call_stream.next_klass(), callee_signature_stream.next_klass());
aoqi@0 3457 if (exact != NULL) {
aoqi@0 3458 md->set_argument_type(bci, i, exact);
aoqi@0 3459 }
aoqi@0 3460 }
aoqi@0 3461 } else {
aoqi@0 3462 #ifdef ASSERT
aoqi@0 3463 Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
aoqi@0 3464 int n = x->nb_profiled_args();
aoqi@0 3465 assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() ||
aoqi@0 3466 (x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))),
aoqi@0 3467 "only at JSR292 bytecodes");
aoqi@0 3468 #endif
aoqi@0 3469 }
aoqi@0 3470 }
aoqi@0 3471 }
aoqi@0 3472
aoqi@0 3473 // profile parameters on entry to an inlined method
aoqi@0 3474 void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
aoqi@0 3475 if (compilation()->profile_parameters() && x->inlined()) {
aoqi@0 3476 ciMethodData* md = x->callee()->method_data_or_null();
aoqi@0 3477 if (md != NULL) {
aoqi@0 3478 ciParametersTypeData* parameters_type_data = md->parameters_type_data();
aoqi@0 3479 if (parameters_type_data != NULL) {
aoqi@0 3480 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters();
aoqi@0 3481 LIR_Opr mdp = LIR_OprFact::illegalOpr;
aoqi@0 3482 bool has_receiver = !x->callee()->is_static();
aoqi@0 3483 ciSignature* sig = x->callee()->signature();
aoqi@0 3484 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
aoqi@0 3485 int i = 0; // to iterate on the Instructions
aoqi@0 3486 Value arg = x->recv();
aoqi@0 3487 bool not_null = false;
aoqi@0 3488 int bci = x->bci_of_invoke();
aoqi@0 3489 Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
aoqi@0 3490 // The first parameter is the receiver so that's what we start
aoqi@0 3491 // with if it exists. One exception is method handle call to
aoqi@0 3492 // virtual method: the receiver is in the args list
aoqi@0 3493 if (arg == NULL || !Bytecodes::has_receiver(bc)) {
aoqi@0 3494 i = 1;
aoqi@0 3495 arg = x->profiled_arg_at(0);
aoqi@0 3496 not_null = !x->arg_needs_null_check(0);
aoqi@0 3497 }
aoqi@0 3498 int k = 0; // to iterate on the profile data
aoqi@0 3499 for (;;) {
aoqi@0 3500 intptr_t profiled_k = parameters->type(k);
aoqi@0 3501 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
aoqi@0 3502 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
aoqi@0 3503 profiled_k, arg, mdp, not_null, sig_stream.next_klass(), NULL);
aoqi@0 3504 // If the profile is known statically set it once for all and do not emit any code
aoqi@0 3505 if (exact != NULL) {
aoqi@0 3506 md->set_parameter_type(k, exact);
aoqi@0 3507 }
aoqi@0 3508 k++;
aoqi@0 3509 if (k >= parameters_type_data->number_of_parameters()) {
aoqi@0 3510 #ifdef ASSERT
aoqi@0 3511 int extra = 0;
aoqi@0 3512 if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&
aoqi@0 3513 x->nb_profiled_args() >= TypeProfileParmsLimit &&
aoqi@0 3514 x->recv() != NULL && Bytecodes::has_receiver(bc)) {
aoqi@0 3515 extra += 1;
aoqi@0 3516 }
aoqi@0 3517 assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
aoqi@0 3518 #endif
aoqi@0 3519 break;
aoqi@0 3520 }
aoqi@0 3521 arg = x->profiled_arg_at(i);
aoqi@0 3522 not_null = !x->arg_needs_null_check(i);
aoqi@0 3523 i++;
aoqi@0 3524 }
aoqi@0 3525 }
aoqi@0 3526 }
aoqi@0 3527 }
aoqi@0 3528 }
aoqi@0 3529
aoqi@0 3530 void LIRGenerator::do_ProfileCall(ProfileCall* x) {
aoqi@0 3531 // Need recv in a temporary register so it interferes with the other temporaries
aoqi@0 3532 LIR_Opr recv = LIR_OprFact::illegalOpr;
aoqi@0 3533 LIR_Opr mdo = new_register(T_OBJECT);
aoqi@0 3534 // tmp is used to hold the counters on SPARC
aoqi@0 3535 LIR_Opr tmp = new_pointer_register();
aoqi@0 3536
aoqi@0 3537 if (x->nb_profiled_args() > 0) {
aoqi@0 3538 profile_arguments(x);
aoqi@0 3539 }
aoqi@0 3540
aoqi@0 3541 // profile parameters on inlined method entry including receiver
aoqi@0 3542 if (x->recv() != NULL || x->nb_profiled_args() > 0) {
aoqi@0 3543 profile_parameters_at_call(x);
aoqi@0 3544 }
aoqi@0 3545
aoqi@0 3546 if (x->recv() != NULL) {
aoqi@0 3547 LIRItem value(x->recv(), this);
aoqi@0 3548 value.load_item();
aoqi@0 3549 recv = new_register(T_OBJECT);
aoqi@0 3550 __ move(value.result(), recv);
aoqi@0 3551 }
aoqi@0 3552 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
aoqi@0 3553 }
aoqi@0 3554
aoqi@0 3555 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
aoqi@0 3556 int bci = x->bci_of_invoke();
aoqi@0 3557 ciMethodData* md = x->method()->method_data_or_null();
aoqi@0 3558 ciProfileData* data = md->bci_to_data(bci);
aoqi@0 3559 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
aoqi@0 3560 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
aoqi@0 3561 LIR_Opr mdp = LIR_OprFact::illegalOpr;
aoqi@0 3562
aoqi@0 3563 bool ignored_will_link;
aoqi@0 3564 ciSignature* signature_at_call = NULL;
aoqi@0 3565 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call);
aoqi@0 3566
aoqi@0 3567 // The offset within the MDO of the entry to update may be too large
aoqi@0 3568 // to be used in load/store instructions on some platforms. So have
aoqi@0 3569 // profile_type() compute the address of the profile in a register.
aoqi@0 3570 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0,
aoqi@0 3571 ret->type(), x->ret(), mdp,
aoqi@0 3572 !x->needs_null_check(),
aoqi@0 3573 signature_at_call->return_type()->as_klass(),
aoqi@0 3574 x->callee()->signature()->return_type()->as_klass());
aoqi@0 3575 if (exact != NULL) {
aoqi@0 3576 md->set_return_type(bci, exact);
aoqi@0 3577 }
aoqi@0 3578 }
aoqi@0 3579
aoqi@0 3580 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {
aoqi@0 3581 // We can safely ignore accessors here, since c2 will inline them anyway,
aoqi@0 3582 // accessors are also always mature.
aoqi@0 3583 if (!x->inlinee()->is_accessor()) {
aoqi@0 3584 CodeEmitInfo* info = state_for(x, x->state(), true);
aoqi@0 3585 // Notify the runtime very infrequently only to take care of counter overflows
aoqi@0 3586 increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);
aoqi@0 3587 }
aoqi@0 3588 }
aoqi@0 3589
aoqi@0 3590 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) {
csahu@8316 3591 int freq_log = 0;
aoqi@0 3592 int level = compilation()->env()->comp_level();
aoqi@0 3593 if (level == CompLevel_limited_profile) {
aoqi@0 3594 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
aoqi@0 3595 } else if (level == CompLevel_full_profile) {
aoqi@0 3596 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
aoqi@0 3597 } else {
aoqi@0 3598 ShouldNotReachHere();
aoqi@0 3599 }
aoqi@0 3600 // Increment the appropriate invocation/backedge counter and notify the runtime.
aoqi@0 3601 increment_event_counter_impl(info, info->scope()->method(), (1 << freq_log) - 1, bci, backedge, true);
aoqi@0 3602 }
aoqi@0 3603
aoqi@0 3604 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
aoqi@0 3605 ciMethod *method, int frequency,
aoqi@0 3606 int bci, bool backedge, bool notify) {
aoqi@0 3607 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
aoqi@0 3608 int level = _compilation->env()->comp_level();
aoqi@0 3609 assert(level > CompLevel_simple, "Shouldn't be here");
aoqi@0 3610
aoqi@0 3611 int offset = -1;
csahu@8316 3612 LIR_Opr counter_holder = NULL;
aoqi@0 3613 if (level == CompLevel_limited_profile) {
aoqi@0 3614 MethodCounters* counters_adr = method->ensure_method_counters();
aoqi@0 3615 if (counters_adr == NULL) {
aoqi@0 3616 bailout("method counters allocation failed");
aoqi@0 3617 return;
aoqi@0 3618 }
aoqi@0 3619 counter_holder = new_pointer_register();
aoqi@0 3620 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
aoqi@0 3621 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
aoqi@0 3622 MethodCounters::invocation_counter_offset());
aoqi@0 3623 } else if (level == CompLevel_full_profile) {
aoqi@0 3624 counter_holder = new_register(T_METADATA);
aoqi@0 3625 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
aoqi@0 3626 MethodData::invocation_counter_offset());
aoqi@0 3627 ciMethodData* md = method->method_data_or_null();
aoqi@0 3628 assert(md != NULL, "Sanity");
aoqi@0 3629 __ metadata2reg(md->constant_encoding(), counter_holder);
aoqi@0 3630 } else {
aoqi@0 3631 ShouldNotReachHere();
aoqi@0 3632 }
aoqi@0 3633 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
aoqi@0 3634 LIR_Opr result = new_register(T_INT);
aoqi@0 3635 __ load(counter, result);
aoqi@0 3636 __ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result);
aoqi@0 3637 __ store(result, counter);
aoqi@0 3638 if (notify) {
aoqi@0 3639 LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT);
aoqi@0 3640 LIR_Opr meth = new_register(T_METADATA);
aoqi@0 3641 __ metadata2reg(method->constant_encoding(), meth);
aoqi@0 3642 __ logical_and(result, mask, result);
aoqi@1 3643 #ifndef MIPS64
aoqi@0 3644 __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0));
aoqi@1 3645 #endif
aoqi@0 3646 // The bci for info can point to cmp for if's we want the if bci
aoqi@0 3647 CodeStub* overflow = new CounterOverflowStub(info, bci, meth);
aoqi@1 3648 #ifndef MIPS64
aoqi@0 3649 __ branch(lir_cond_equal, T_INT, overflow);
aoqi@1 3650 #else
aoqi@1 3651 __ branch(lir_cond_equal, result, LIR_OprFact::intConst(0), T_INT, overflow);
aoqi@1 3652 #endif
aoqi@0 3653 __ branch_destination(overflow->continuation());
aoqi@0 3654 }
aoqi@0 3655 }
aoqi@0 3656
aoqi@0 3657 void LIRGenerator::do_RuntimeCall(RuntimeCall* x) {
aoqi@0 3658 LIR_OprList* args = new LIR_OprList(x->number_of_arguments());
aoqi@0 3659 BasicTypeList* signature = new BasicTypeList(x->number_of_arguments());
aoqi@0 3660
aoqi@0 3661 if (x->pass_thread()) {
aoqi@0 3662 signature->append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
aoqi@0 3663 args->append(getThreadPointer());
aoqi@0 3664 }
aoqi@0 3665
aoqi@0 3666 for (int i = 0; i < x->number_of_arguments(); i++) {
aoqi@0 3667 Value a = x->argument_at(i);
aoqi@0 3668 LIRItem* item = new LIRItem(a, this);
aoqi@0 3669 item->load_item();
aoqi@0 3670 args->append(item->result());
aoqi@0 3671 signature->append(as_BasicType(a->type()));
aoqi@0 3672 }
aoqi@0 3673
aoqi@0 3674 LIR_Opr result = call_runtime(signature, args, x->entry(), x->type(), NULL);
aoqi@0 3675 if (x->type() == voidType) {
aoqi@0 3676 set_no_result(x);
aoqi@0 3677 } else {
aoqi@0 3678 __ move(result, rlock_result(x));
aoqi@0 3679 }
aoqi@0 3680 }
aoqi@0 3681
aoqi@0 3682 #ifdef ASSERT
aoqi@0 3683 void LIRGenerator::do_Assert(Assert *x) {
aoqi@0 3684 ValueTag tag = x->x()->type()->tag();
aoqi@0 3685 If::Condition cond = x->cond();
aoqi@0 3686
aoqi@0 3687 LIRItem xitem(x->x(), this);
aoqi@0 3688 LIRItem yitem(x->y(), this);
aoqi@0 3689 LIRItem* xin = &xitem;
aoqi@0 3690 LIRItem* yin = &yitem;
aoqi@0 3691
aoqi@0 3692 assert(tag == intTag, "Only integer assertions are valid!");
aoqi@0 3693
aoqi@0 3694 xin->load_item();
aoqi@0 3695 yin->dont_load_item();
aoqi@0 3696
aoqi@0 3697 set_no_result(x);
aoqi@0 3698
aoqi@0 3699 LIR_Opr left = xin->result();
aoqi@0 3700 LIR_Opr right = yin->result();
aoqi@0 3701
aoqi@0 3702 __ lir_assert(lir_cond(x->cond()), left, right, x->message(), true);
aoqi@0 3703 }
aoqi@0 3704 #endif
aoqi@0 3705
aoqi@0 3706 void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) {
aoqi@0 3707
aoqi@0 3708
aoqi@0 3709 Instruction *a = x->x();
aoqi@0 3710 Instruction *b = x->y();
aoqi@0 3711 if (!a || StressRangeCheckElimination) {
aoqi@0 3712 assert(!b || StressRangeCheckElimination, "B must also be null");
aoqi@0 3713
aoqi@0 3714 CodeEmitInfo *info = state_for(x, x->state());
aoqi@0 3715 CodeStub* stub = new PredicateFailedStub(info);
aoqi@0 3716
aoqi@0 3717 __ jump(stub);
aoqi@0 3718 } else if (a->type()->as_IntConstant() && b->type()->as_IntConstant()) {
aoqi@0 3719 int a_int = a->type()->as_IntConstant()->value();
aoqi@0 3720 int b_int = b->type()->as_IntConstant()->value();
aoqi@0 3721
aoqi@0 3722 bool ok = false;
aoqi@0 3723
aoqi@0 3724 switch(x->cond()) {
aoqi@0 3725 case Instruction::eql: ok = (a_int == b_int); break;
aoqi@0 3726 case Instruction::neq: ok = (a_int != b_int); break;
aoqi@0 3727 case Instruction::lss: ok = (a_int < b_int); break;
aoqi@0 3728 case Instruction::leq: ok = (a_int <= b_int); break;
aoqi@0 3729 case Instruction::gtr: ok = (a_int > b_int); break;
aoqi@0 3730 case Instruction::geq: ok = (a_int >= b_int); break;
aoqi@0 3731 case Instruction::aeq: ok = ((unsigned int)a_int >= (unsigned int)b_int); break;
aoqi@0 3732 case Instruction::beq: ok = ((unsigned int)a_int <= (unsigned int)b_int); break;
aoqi@0 3733 default: ShouldNotReachHere();
aoqi@0 3734 }
aoqi@0 3735
aoqi@0 3736 if (ok) {
aoqi@0 3737
aoqi@0 3738 CodeEmitInfo *info = state_for(x, x->state());
aoqi@0 3739 CodeStub* stub = new PredicateFailedStub(info);
aoqi@0 3740
aoqi@0 3741 __ jump(stub);
aoqi@0 3742 }
aoqi@0 3743 } else {
aoqi@0 3744
aoqi@0 3745 ValueTag tag = x->x()->type()->tag();
aoqi@0 3746 If::Condition cond = x->cond();
aoqi@0 3747 LIRItem xitem(x->x(), this);
aoqi@0 3748 LIRItem yitem(x->y(), this);
aoqi@0 3749 LIRItem* xin = &xitem;
aoqi@0 3750 LIRItem* yin = &yitem;
aoqi@0 3751
aoqi@0 3752 assert(tag == intTag, "Only integer deoptimizations are valid!");
aoqi@0 3753
aoqi@0 3754 xin->load_item();
aoqi@0 3755 yin->dont_load_item();
aoqi@0 3756 set_no_result(x);
aoqi@0 3757
aoqi@0 3758 LIR_Opr left = xin->result();
aoqi@0 3759 LIR_Opr right = yin->result();
aoqi@0 3760
aoqi@0 3761 CodeEmitInfo *info = state_for(x, x->state());
aoqi@0 3762 CodeStub* stub = new PredicateFailedStub(info);
aoqi@0 3763
aoqi@1 3764 #ifndef MIPS64
aoqi@0 3765 __ cmp(lir_cond(cond), left, right);
aoqi@0 3766 __ branch(lir_cond(cond), right->type(), stub);
aoqi@1 3767 #else
aoqi@1 3768 tty->print_cr("LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) unimplemented yet!");
aoqi@1 3769 Unimplemented();
aoqi@1 3770 #endif
aoqi@0 3771 }
aoqi@0 3772 }
aoqi@0 3773
aoqi@0 3774
aoqi@0 3775 LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {
aoqi@0 3776 LIRItemList args(1);
aoqi@0 3777 LIRItem value(arg1, this);
aoqi@0 3778 args.append(&value);
aoqi@0 3779 BasicTypeList signature;
aoqi@0 3780 signature.append(as_BasicType(arg1->type()));
aoqi@0 3781
aoqi@0 3782 return call_runtime(&signature, &args, entry, result_type, info);
aoqi@0 3783 }
aoqi@0 3784
aoqi@0 3785
aoqi@0 3786 LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) {
aoqi@0 3787 LIRItemList args(2);
aoqi@0 3788 LIRItem value1(arg1, this);
aoqi@0 3789 LIRItem value2(arg2, this);
aoqi@0 3790 args.append(&value1);
aoqi@0 3791 args.append(&value2);
aoqi@0 3792 BasicTypeList signature;
aoqi@0 3793 signature.append(as_BasicType(arg1->type()));
aoqi@0 3794 signature.append(as_BasicType(arg2->type()));
aoqi@0 3795
aoqi@0 3796 return call_runtime(&signature, &args, entry, result_type, info);
aoqi@0 3797 }
aoqi@0 3798
aoqi@0 3799
aoqi@0 3800 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args,
aoqi@0 3801 address entry, ValueType* result_type, CodeEmitInfo* info) {
aoqi@0 3802 // get a result register
aoqi@0 3803 LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
aoqi@0 3804 LIR_Opr result = LIR_OprFact::illegalOpr;
aoqi@0 3805 if (result_type->tag() != voidTag) {
aoqi@0 3806 result = new_register(result_type);
aoqi@0 3807 phys_reg = result_register_for(result_type);
aoqi@0 3808 }
aoqi@0 3809
aoqi@0 3810 // move the arguments into the correct location
aoqi@0 3811 CallingConvention* cc = frame_map()->c_calling_convention(signature);
aoqi@0 3812 assert(cc->length() == args->length(), "argument mismatch");
aoqi@0 3813 for (int i = 0; i < args->length(); i++) {
aoqi@0 3814 LIR_Opr arg = args->at(i);
aoqi@0 3815 LIR_Opr loc = cc->at(i);
aoqi@0 3816 if (loc->is_register()) {
aoqi@0 3817 __ move(arg, loc);
aoqi@0 3818 } else {
aoqi@0 3819 LIR_Address* addr = loc->as_address_ptr();
aoqi@0 3820 // if (!can_store_as_constant(arg)) {
aoqi@0 3821 // LIR_Opr tmp = new_register(arg->type());
aoqi@0 3822 // __ move(arg, tmp);
aoqi@0 3823 // arg = tmp;
aoqi@0 3824 // }
aoqi@0 3825 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
aoqi@0 3826 __ unaligned_move(arg, addr);
aoqi@0 3827 } else {
aoqi@0 3828 __ move(arg, addr);
aoqi@0 3829 }
aoqi@0 3830 }
aoqi@0 3831 }
aoqi@0 3832
aoqi@0 3833 if (info) {
aoqi@0 3834 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
aoqi@0 3835 } else {
aoqi@0 3836 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
aoqi@0 3837 }
aoqi@0 3838 if (result->is_valid()) {
aoqi@0 3839 __ move(phys_reg, result);
aoqi@0 3840 }
aoqi@0 3841 return result;
aoqi@0 3842 }
aoqi@0 3843
aoqi@0 3844
aoqi@0 3845 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args,
aoqi@0 3846 address entry, ValueType* result_type, CodeEmitInfo* info) {
aoqi@0 3847 // get a result register
aoqi@0 3848 LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
aoqi@0 3849 LIR_Opr result = LIR_OprFact::illegalOpr;
aoqi@0 3850 if (result_type->tag() != voidTag) {
aoqi@0 3851 result = new_register(result_type);
aoqi@0 3852 phys_reg = result_register_for(result_type);
aoqi@0 3853 }
aoqi@0 3854
aoqi@0 3855 // move the arguments into the correct location
aoqi@0 3856 CallingConvention* cc = frame_map()->c_calling_convention(signature);
aoqi@0 3857
aoqi@0 3858 assert(cc->length() == args->length(), "argument mismatch");
aoqi@0 3859 for (int i = 0; i < args->length(); i++) {
aoqi@0 3860 LIRItem* arg = args->at(i);
aoqi@0 3861 LIR_Opr loc = cc->at(i);
aoqi@0 3862 if (loc->is_register()) {
aoqi@0 3863 arg->load_item_force(loc);
aoqi@0 3864 } else {
aoqi@0 3865 LIR_Address* addr = loc->as_address_ptr();
aoqi@0 3866 arg->load_for_store(addr->type());
aoqi@0 3867 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
aoqi@0 3868 __ unaligned_move(arg->result(), addr);
aoqi@0 3869 } else {
aoqi@0 3870 __ move(arg->result(), addr);
aoqi@0 3871 }
aoqi@0 3872 }
aoqi@0 3873 }
aoqi@0 3874
aoqi@0 3875 if (info) {
aoqi@0 3876 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
aoqi@0 3877 } else {
aoqi@0 3878 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
aoqi@0 3879 }
aoqi@0 3880 if (result->is_valid()) {
aoqi@0 3881 __ move(phys_reg, result);
aoqi@0 3882 }
aoqi@0 3883 return result;
aoqi@0 3884 }
aoqi@0 3885
aoqi@0 3886 void LIRGenerator::do_MemBar(MemBar* x) {
aoqi@0 3887 if (os::is_MP()) {
aoqi@0 3888 LIR_Code code = x->code();
aoqi@0 3889 switch(code) {
aoqi@0 3890 case lir_membar_acquire : __ membar_acquire(); break;
aoqi@0 3891 case lir_membar_release : __ membar_release(); break;
aoqi@0 3892 case lir_membar : __ membar(); break;
aoqi@0 3893 case lir_membar_loadload : __ membar_loadload(); break;
aoqi@0 3894 case lir_membar_storestore: __ membar_storestore(); break;
aoqi@0 3895 case lir_membar_loadstore : __ membar_loadstore(); break;
aoqi@0 3896 case lir_membar_storeload : __ membar_storeload(); break;
aoqi@0 3897 default : ShouldNotReachHere(); break;
aoqi@0 3898 }
aoqi@0 3899 }
aoqi@0 3900 }
kevinw@8368 3901
kevinw@8368 3902 LIR_Opr LIRGenerator::maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {
kevinw@8368 3903 if (x->check_boolean()) {
kevinw@8368 3904 LIR_Opr value_fixed = rlock_byte(T_BYTE);
kevinw@8368 3905 if (TwoOperandLIRForm) {
kevinw@8368 3906 __ move(value, value_fixed);
kevinw@8368 3907 __ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed);
kevinw@8368 3908 } else {
kevinw@8368 3909 __ logical_and(value, LIR_OprFact::intConst(1), value_fixed);
kevinw@8368 3910 }
kevinw@8368 3911 LIR_Opr klass = new_register(T_METADATA);
kevinw@8368 3912 __ move(new LIR_Address(array, oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, null_check_info);
kevinw@8368 3913 null_check_info = NULL;
kevinw@8368 3914 LIR_Opr layout = new_register(T_INT);
kevinw@8368 3915 __ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);
kevinw@8368 3916 int diffbit = Klass::layout_helper_boolean_diffbit();
kevinw@8368 3917 __ logical_and(layout, LIR_OprFact::intConst(diffbit), layout);
fujie@8859 3918 #ifdef MIPS64
fujie@8859 3919 guarantee(false, "not implemented yet for mips");
fujie@8859 3920 // __ cmp();
fujie@8859 3921 // __ cmov();
fujie@8859 3922 #else
kevinw@8368 3923 __ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0));
kevinw@8368 3924 __ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE);
fujie@8859 3925 #endif
kevinw@8368 3926 value = value_fixed;
kevinw@8368 3927 }
kevinw@8368 3928 return value;
kevinw@8368 3929 }

mercurial