src/share/vm/c1/c1_LIRGenerator.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9228
617b86d17edb
parent 9618
3999f5f297f2
child 9852
70aa912cebe5
permissions
-rw-r--r--

Merge

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

mercurial