src/share/vm/c1/c1_LIRGenerator.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 8882
279a5dd96f9b
child 9041
95a08233f46c
child 9618
3999f5f297f2
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial