src/share/vm/c1/c1_LIRGenerator.cpp

Wed, 13 Apr 2011 17:56:43 -0700

author
johnc
date
Wed, 13 Apr 2011 17:56:43 -0700
changeset 2786
59766fd005ff
parent 2781
e1162778c1c8
child 2787
5d046bf49ce7
permissions
-rw-r--r--

7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
Summary: Allow long type for offset in G1 code in compiler implementations of Unsafe.getObject
Reviewed-by: never, iveresov

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

mercurial