src/share/vm/c1/c1_LIRAssembler.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_Compilation.hpp"
aoqi@0 27 #include "c1/c1_Instruction.hpp"
aoqi@0 28 #include "c1/c1_InstructionPrinter.hpp"
aoqi@0 29 #include "c1/c1_LIRAssembler.hpp"
aoqi@0 30 #include "c1/c1_MacroAssembler.hpp"
aoqi@0 31 #include "c1/c1_ValueStack.hpp"
aoqi@0 32 #include "ci/ciInstance.hpp"
aoqi@0 33 #ifdef TARGET_ARCH_x86
aoqi@0 34 # include "nativeInst_x86.hpp"
aoqi@0 35 # include "vmreg_x86.inline.hpp"
aoqi@0 36 #endif
aoqi@0 37 #ifdef TARGET_ARCH_sparc
aoqi@0 38 # include "nativeInst_sparc.hpp"
aoqi@0 39 # include "vmreg_sparc.inline.hpp"
aoqi@0 40 #endif
aoqi@0 41 #ifdef TARGET_ARCH_zero
aoqi@0 42 # include "nativeInst_zero.hpp"
aoqi@0 43 # include "vmreg_zero.inline.hpp"
aoqi@0 44 #endif
aoqi@0 45 #ifdef TARGET_ARCH_arm
aoqi@0 46 # include "nativeInst_arm.hpp"
aoqi@0 47 # include "vmreg_arm.inline.hpp"
aoqi@0 48 #endif
aoqi@0 49 #ifdef TARGET_ARCH_ppc
aoqi@0 50 # include "nativeInst_ppc.hpp"
aoqi@0 51 # include "vmreg_ppc.inline.hpp"
aoqi@0 52 #endif
aoqi@0 53
aoqi@0 54
aoqi@0 55 void LIR_Assembler::patching_epilog(PatchingStub* patch, LIR_PatchCode patch_code, Register obj, CodeEmitInfo* info) {
aoqi@0 56 // we must have enough patching space so that call can be inserted
aoqi@0 57 while ((intx) _masm->pc() - (intx) patch->pc_start() < NativeCall::instruction_size) {
aoqi@0 58 _masm->nop();
aoqi@0 59 }
aoqi@0 60 patch->install(_masm, patch_code, obj, info);
aoqi@0 61 append_code_stub(patch);
aoqi@0 62
aoqi@0 63 #ifdef ASSERT
aoqi@0 64 Bytecodes::Code code = info->scope()->method()->java_code_at_bci(info->stack()->bci());
aoqi@0 65 if (patch->id() == PatchingStub::access_field_id) {
aoqi@0 66 switch (code) {
aoqi@0 67 case Bytecodes::_putstatic:
aoqi@0 68 case Bytecodes::_getstatic:
aoqi@0 69 case Bytecodes::_putfield:
aoqi@0 70 case Bytecodes::_getfield:
aoqi@0 71 break;
aoqi@0 72 default:
aoqi@0 73 ShouldNotReachHere();
aoqi@0 74 }
aoqi@0 75 } else if (patch->id() == PatchingStub::load_klass_id) {
aoqi@0 76 switch (code) {
aoqi@0 77 case Bytecodes::_new:
aoqi@0 78 case Bytecodes::_anewarray:
aoqi@0 79 case Bytecodes::_multianewarray:
aoqi@0 80 case Bytecodes::_instanceof:
aoqi@0 81 case Bytecodes::_checkcast:
aoqi@0 82 break;
aoqi@0 83 default:
aoqi@0 84 ShouldNotReachHere();
aoqi@0 85 }
aoqi@0 86 } else if (patch->id() == PatchingStub::load_mirror_id) {
aoqi@0 87 switch (code) {
aoqi@0 88 case Bytecodes::_putstatic:
aoqi@0 89 case Bytecodes::_getstatic:
aoqi@0 90 case Bytecodes::_ldc:
aoqi@0 91 case Bytecodes::_ldc_w:
aoqi@0 92 break;
aoqi@0 93 default:
aoqi@0 94 ShouldNotReachHere();
aoqi@0 95 }
aoqi@0 96 } else if (patch->id() == PatchingStub::load_appendix_id) {
aoqi@0 97 Bytecodes::Code bc_raw = info->scope()->method()->raw_code_at_bci(info->stack()->bci());
aoqi@0 98 assert(Bytecodes::has_optional_appendix(bc_raw), "unexpected appendix resolution");
aoqi@0 99 } else {
aoqi@0 100 ShouldNotReachHere();
aoqi@0 101 }
aoqi@0 102 #endif
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 PatchingStub::PatchID LIR_Assembler::patching_id(CodeEmitInfo* info) {
aoqi@0 106 IRScope* scope = info->scope();
aoqi@0 107 Bytecodes::Code bc_raw = scope->method()->raw_code_at_bci(info->stack()->bci());
aoqi@0 108 if (Bytecodes::has_optional_appendix(bc_raw)) {
aoqi@0 109 return PatchingStub::load_appendix_id;
aoqi@0 110 }
aoqi@0 111 return PatchingStub::load_mirror_id;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 //---------------------------------------------------------------
aoqi@0 115
aoqi@0 116
aoqi@0 117 LIR_Assembler::LIR_Assembler(Compilation* c):
aoqi@0 118 _compilation(c)
aoqi@0 119 , _masm(c->masm())
aoqi@0 120 , _bs(Universe::heap()->barrier_set())
aoqi@0 121 , _frame_map(c->frame_map())
aoqi@0 122 , _current_block(NULL)
aoqi@0 123 , _pending_non_safepoint(NULL)
aoqi@0 124 , _pending_non_safepoint_offset(0)
aoqi@0 125 {
aoqi@0 126 _slow_case_stubs = new CodeStubList();
aoqi@0 127 }
aoqi@0 128
aoqi@0 129
aoqi@0 130 LIR_Assembler::~LIR_Assembler() {
aoqi@0 131 }
aoqi@0 132
aoqi@0 133
aoqi@0 134 void LIR_Assembler::check_codespace() {
aoqi@0 135 CodeSection* cs = _masm->code_section();
aoqi@0 136 if (cs->remaining() < (int)(NOT_LP64(1*K)LP64_ONLY(2*K))) {
aoqi@0 137 BAILOUT("CodeBuffer overflow");
aoqi@0 138 }
aoqi@0 139 }
aoqi@0 140
aoqi@0 141
aoqi@0 142 void LIR_Assembler::append_code_stub(CodeStub* stub) {
aoqi@0 143 _slow_case_stubs->append(stub);
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 void LIR_Assembler::emit_stubs(CodeStubList* stub_list) {
aoqi@0 147 for (int m = 0; m < stub_list->length(); m++) {
aoqi@0 148 CodeStub* s = (*stub_list)[m];
aoqi@0 149
aoqi@0 150 check_codespace();
aoqi@0 151 CHECK_BAILOUT();
aoqi@0 152
aoqi@0 153 #ifndef PRODUCT
aoqi@0 154 if (CommentedAssembly) {
aoqi@0 155 stringStream st;
aoqi@0 156 s->print_name(&st);
aoqi@0 157 st.print(" slow case");
aoqi@0 158 _masm->block_comment(st.as_string());
aoqi@0 159 }
aoqi@0 160 #endif
aoqi@0 161 s->emit_code(this);
aoqi@0 162 #ifdef ASSERT
aoqi@0 163 s->assert_no_unbound_labels();
aoqi@0 164 #endif
aoqi@0 165 }
aoqi@0 166 }
aoqi@0 167
aoqi@0 168
aoqi@0 169 void LIR_Assembler::emit_slow_case_stubs() {
aoqi@0 170 emit_stubs(_slow_case_stubs);
aoqi@0 171 }
aoqi@0 172
aoqi@0 173
aoqi@0 174 bool LIR_Assembler::needs_icache(ciMethod* method) const {
aoqi@0 175 return !method->is_static();
aoqi@0 176 }
aoqi@0 177
aoqi@0 178
aoqi@0 179 int LIR_Assembler::code_offset() const {
aoqi@0 180 return _masm->offset();
aoqi@0 181 }
aoqi@0 182
aoqi@0 183
aoqi@0 184 address LIR_Assembler::pc() const {
aoqi@0 185 return _masm->pc();
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 // To bang the stack of this compiled method we use the stack size
aoqi@0 189 // that the interpreter would need in case of a deoptimization. This
aoqi@0 190 // removes the need to bang the stack in the deoptimization blob which
aoqi@0 191 // in turn simplifies stack overflow handling.
aoqi@0 192 int LIR_Assembler::bang_size_in_bytes() const {
aoqi@0 193 return MAX2(initial_frame_size_in_bytes(), _compilation->interpreter_frame_size());
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 void LIR_Assembler::emit_exception_entries(ExceptionInfoList* info_list) {
aoqi@0 197 for (int i = 0; i < info_list->length(); i++) {
aoqi@0 198 XHandlers* handlers = info_list->at(i)->exception_handlers();
aoqi@0 199
aoqi@0 200 for (int j = 0; j < handlers->length(); j++) {
aoqi@0 201 XHandler* handler = handlers->handler_at(j);
aoqi@0 202 assert(handler->lir_op_id() != -1, "handler not processed by LinearScan");
aoqi@0 203 assert(handler->entry_code() == NULL ||
aoqi@0 204 handler->entry_code()->instructions_list()->last()->code() == lir_branch ||
aoqi@0 205 handler->entry_code()->instructions_list()->last()->code() == lir_delay_slot, "last operation must be branch");
aoqi@0 206
aoqi@0 207 if (handler->entry_pco() == -1) {
aoqi@0 208 // entry code not emitted yet
aoqi@0 209 if (handler->entry_code() != NULL && handler->entry_code()->instructions_list()->length() > 1) {
aoqi@0 210 handler->set_entry_pco(code_offset());
aoqi@0 211 if (CommentedAssembly) {
aoqi@0 212 _masm->block_comment("Exception adapter block");
aoqi@0 213 }
aoqi@0 214 emit_lir_list(handler->entry_code());
aoqi@0 215 } else {
aoqi@0 216 handler->set_entry_pco(handler->entry_block()->exception_handler_pco());
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 assert(handler->entry_pco() != -1, "must be set now");
aoqi@0 220 }
aoqi@0 221 }
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224
aoqi@0 225
aoqi@0 226 void LIR_Assembler::emit_code(BlockList* hir) {
aoqi@0 227 if (PrintLIR) {
aoqi@0 228 print_LIR(hir);
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 int n = hir->length();
aoqi@0 232 for (int i = 0; i < n; i++) {
aoqi@0 233 emit_block(hir->at(i));
aoqi@0 234 CHECK_BAILOUT();
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 flush_debug_info(code_offset());
aoqi@0 238
aoqi@0 239 DEBUG_ONLY(check_no_unbound_labels());
aoqi@0 240 }
aoqi@0 241
aoqi@0 242
aoqi@0 243 void LIR_Assembler::emit_block(BlockBegin* block) {
aoqi@0 244 if (block->is_set(BlockBegin::backward_branch_target_flag)) {
aoqi@0 245 align_backward_branch_target();
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 // if this block is the start of an exception handler, record the
aoqi@0 249 // PC offset of the first instruction for later construction of
aoqi@0 250 // the ExceptionHandlerTable
aoqi@0 251 if (block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 252 block->set_exception_handler_pco(code_offset());
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 #ifndef PRODUCT
aoqi@0 256 if (PrintLIRWithAssembly) {
aoqi@0 257 // don't print Phi's
aoqi@0 258 InstructionPrinter ip(false);
aoqi@0 259 block->print(ip);
aoqi@0 260 }
aoqi@0 261 #endif /* PRODUCT */
aoqi@0 262
aoqi@0 263 assert(block->lir() != NULL, "must have LIR");
aoqi@0 264 X86_ONLY(assert(_masm->rsp_offset() == 0, "frame size should be fixed"));
aoqi@0 265
aoqi@0 266 #ifndef PRODUCT
aoqi@0 267 if (CommentedAssembly) {
aoqi@0 268 stringStream st;
aoqi@0 269 st.print_cr(" block B%d [%d, %d]", block->block_id(), block->bci(), block->end()->printable_bci());
aoqi@0 270 _masm->block_comment(st.as_string());
aoqi@0 271 }
aoqi@0 272 #endif
aoqi@0 273
aoqi@0 274 emit_lir_list(block->lir());
aoqi@0 275
aoqi@0 276 X86_ONLY(assert(_masm->rsp_offset() == 0, "frame size should be fixed"));
aoqi@0 277 }
aoqi@0 278
aoqi@0 279
aoqi@0 280 void LIR_Assembler::emit_lir_list(LIR_List* list) {
aoqi@0 281 peephole(list);
aoqi@0 282
aoqi@0 283 int n = list->length();
aoqi@0 284 for (int i = 0; i < n; i++) {
aoqi@0 285 LIR_Op* op = list->at(i);
aoqi@0 286
aoqi@0 287 check_codespace();
aoqi@0 288 CHECK_BAILOUT();
aoqi@0 289
aoqi@0 290 #ifndef PRODUCT
aoqi@0 291 if (CommentedAssembly) {
aoqi@0 292 // Don't record out every op since that's too verbose. Print
aoqi@0 293 // branches since they include block and stub names. Also print
aoqi@0 294 // patching moves since they generate funny looking code.
aoqi@0 295 if (op->code() == lir_branch ||
aoqi@0 296 (op->code() == lir_move && op->as_Op1()->patch_code() != lir_patch_none)) {
aoqi@0 297 stringStream st;
aoqi@0 298 op->print_on(&st);
aoqi@0 299 _masm->block_comment(st.as_string());
aoqi@0 300 }
aoqi@0 301 }
aoqi@0 302 if (PrintLIRWithAssembly) {
aoqi@0 303 // print out the LIR operation followed by the resulting assembly
aoqi@0 304 list->at(i)->print(); tty->cr();
aoqi@0 305 }
aoqi@0 306 #endif /* PRODUCT */
aoqi@0 307
aoqi@0 308 op->emit_code(this);
aoqi@0 309
aoqi@0 310 if (compilation()->debug_info_recorder()->recording_non_safepoints()) {
aoqi@0 311 process_debug_info(op);
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 #ifndef PRODUCT
aoqi@0 315 if (PrintLIRWithAssembly) {
aoqi@0 316 _masm->code()->decode();
aoqi@0 317 }
aoqi@0 318 #endif /* PRODUCT */
aoqi@0 319 }
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 #ifdef ASSERT
aoqi@0 323 void LIR_Assembler::check_no_unbound_labels() {
aoqi@0 324 CHECK_BAILOUT();
aoqi@0 325
aoqi@0 326 for (int i = 0; i < _branch_target_blocks.length() - 1; i++) {
aoqi@0 327 if (!_branch_target_blocks.at(i)->label()->is_bound()) {
aoqi@0 328 tty->print_cr("label of block B%d is not bound", _branch_target_blocks.at(i)->block_id());
aoqi@0 329 assert(false, "unbound label");
aoqi@0 330 }
aoqi@0 331 }
aoqi@0 332 }
aoqi@0 333 #endif
aoqi@0 334
aoqi@0 335 //----------------------------------debug info--------------------------------
aoqi@0 336
aoqi@0 337
aoqi@0 338 void LIR_Assembler::add_debug_info_for_branch(CodeEmitInfo* info) {
aoqi@0 339 _masm->code_section()->relocate(pc(), relocInfo::poll_type);
aoqi@0 340 int pc_offset = code_offset();
aoqi@0 341 flush_debug_info(pc_offset);
aoqi@0 342 info->record_debug_info(compilation()->debug_info_recorder(), pc_offset);
aoqi@0 343 if (info->exception_handlers() != NULL) {
aoqi@0 344 compilation()->add_exception_handlers_for_pco(pc_offset, info->exception_handlers());
aoqi@0 345 }
aoqi@0 346 }
aoqi@0 347
aoqi@0 348
aoqi@0 349 void LIR_Assembler::add_call_info(int pc_offset, CodeEmitInfo* cinfo) {
aoqi@0 350 flush_debug_info(pc_offset);
aoqi@0 351 cinfo->record_debug_info(compilation()->debug_info_recorder(), pc_offset);
aoqi@0 352 if (cinfo->exception_handlers() != NULL) {
aoqi@0 353 compilation()->add_exception_handlers_for_pco(pc_offset, cinfo->exception_handlers());
aoqi@0 354 }
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 static ValueStack* debug_info(Instruction* ins) {
aoqi@0 358 StateSplit* ss = ins->as_StateSplit();
aoqi@0 359 if (ss != NULL) return ss->state();
aoqi@0 360 return ins->state_before();
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 void LIR_Assembler::process_debug_info(LIR_Op* op) {
aoqi@0 364 Instruction* src = op->source();
aoqi@0 365 if (src == NULL) return;
aoqi@0 366 int pc_offset = code_offset();
aoqi@0 367 if (_pending_non_safepoint == src) {
aoqi@0 368 _pending_non_safepoint_offset = pc_offset;
aoqi@0 369 return;
aoqi@0 370 }
aoqi@0 371 ValueStack* vstack = debug_info(src);
aoqi@0 372 if (vstack == NULL) return;
aoqi@0 373 if (_pending_non_safepoint != NULL) {
aoqi@0 374 // Got some old debug info. Get rid of it.
aoqi@0 375 if (debug_info(_pending_non_safepoint) == vstack) {
aoqi@0 376 _pending_non_safepoint_offset = pc_offset;
aoqi@0 377 return;
aoqi@0 378 }
aoqi@0 379 if (_pending_non_safepoint_offset < pc_offset) {
aoqi@0 380 record_non_safepoint_debug_info();
aoqi@0 381 }
aoqi@0 382 _pending_non_safepoint = NULL;
aoqi@0 383 }
aoqi@0 384 // Remember the debug info.
aoqi@0 385 if (pc_offset > compilation()->debug_info_recorder()->last_pc_offset()) {
aoqi@0 386 _pending_non_safepoint = src;
aoqi@0 387 _pending_non_safepoint_offset = pc_offset;
aoqi@0 388 }
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 // Index caller states in s, where 0 is the oldest, 1 its callee, etc.
aoqi@0 392 // Return NULL if n is too large.
aoqi@0 393 // Returns the caller_bci for the next-younger state, also.
aoqi@0 394 static ValueStack* nth_oldest(ValueStack* s, int n, int& bci_result) {
aoqi@0 395 ValueStack* t = s;
aoqi@0 396 for (int i = 0; i < n; i++) {
aoqi@0 397 if (t == NULL) break;
aoqi@0 398 t = t->caller_state();
aoqi@0 399 }
aoqi@0 400 if (t == NULL) return NULL;
aoqi@0 401 for (;;) {
aoqi@0 402 ValueStack* tc = t->caller_state();
aoqi@0 403 if (tc == NULL) return s;
aoqi@0 404 t = tc;
aoqi@0 405 bci_result = tc->bci();
aoqi@0 406 s = s->caller_state();
aoqi@0 407 }
aoqi@0 408 }
aoqi@0 409
aoqi@0 410 void LIR_Assembler::record_non_safepoint_debug_info() {
aoqi@0 411 int pc_offset = _pending_non_safepoint_offset;
aoqi@0 412 ValueStack* vstack = debug_info(_pending_non_safepoint);
aoqi@0 413 int bci = vstack->bci();
aoqi@0 414
aoqi@0 415 DebugInformationRecorder* debug_info = compilation()->debug_info_recorder();
aoqi@0 416 assert(debug_info->recording_non_safepoints(), "sanity");
aoqi@0 417
aoqi@0 418 debug_info->add_non_safepoint(pc_offset);
aoqi@0 419
aoqi@0 420 // Visit scopes from oldest to youngest.
aoqi@0 421 for (int n = 0; ; n++) {
aoqi@0 422 int s_bci = bci;
aoqi@0 423 ValueStack* s = nth_oldest(vstack, n, s_bci);
aoqi@0 424 if (s == NULL) break;
aoqi@0 425 IRScope* scope = s->scope();
aoqi@0 426 //Always pass false for reexecute since these ScopeDescs are never used for deopt
aoqi@0 427 debug_info->describe_scope(pc_offset, scope->method(), s->bci(), false/*reexecute*/);
aoqi@0 428 }
aoqi@0 429
aoqi@0 430 debug_info->end_non_safepoint(pc_offset);
aoqi@0 431 }
aoqi@0 432
aoqi@0 433
aoqi@0 434 void LIR_Assembler::add_debug_info_for_null_check_here(CodeEmitInfo* cinfo) {
aoqi@0 435 add_debug_info_for_null_check(code_offset(), cinfo);
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 void LIR_Assembler::add_debug_info_for_null_check(int pc_offset, CodeEmitInfo* cinfo) {
aoqi@0 439 ImplicitNullCheckStub* stub = new ImplicitNullCheckStub(pc_offset, cinfo);
aoqi@0 440 append_code_stub(stub);
aoqi@0 441 }
aoqi@0 442
aoqi@0 443 void LIR_Assembler::add_debug_info_for_div0_here(CodeEmitInfo* info) {
aoqi@0 444 add_debug_info_for_div0(code_offset(), info);
aoqi@0 445 }
aoqi@0 446
aoqi@0 447 void LIR_Assembler::add_debug_info_for_div0(int pc_offset, CodeEmitInfo* cinfo) {
aoqi@0 448 DivByZeroStub* stub = new DivByZeroStub(pc_offset, cinfo);
aoqi@0 449 append_code_stub(stub);
aoqi@0 450 }
aoqi@0 451
aoqi@0 452 void LIR_Assembler::emit_rtcall(LIR_OpRTCall* op) {
aoqi@0 453 rt_call(op->result_opr(), op->addr(), op->arguments(), op->tmp(), op->info());
aoqi@0 454 }
aoqi@0 455
aoqi@0 456
aoqi@0 457 void LIR_Assembler::emit_call(LIR_OpJavaCall* op) {
aoqi@0 458 verify_oop_map(op->info());
aoqi@0 459
aoqi@0 460 if (os::is_MP()) {
aoqi@0 461 // must align calls sites, otherwise they can't be updated atomically on MP hardware
aoqi@0 462 align_call(op->code());
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 // emit the static call stub stuff out of line
aoqi@0 466 emit_static_call_stub();
aoqi@0 467
aoqi@0 468 switch (op->code()) {
aoqi@0 469 case lir_static_call:
aoqi@0 470 case lir_dynamic_call:
aoqi@0 471 call(op, relocInfo::static_call_type);
aoqi@0 472 break;
aoqi@0 473 case lir_optvirtual_call:
aoqi@0 474 call(op, relocInfo::opt_virtual_call_type);
aoqi@0 475 break;
aoqi@0 476 case lir_icvirtual_call:
aoqi@0 477 ic_call(op);
aoqi@0 478 break;
aoqi@0 479 case lir_virtual_call:
aoqi@0 480 vtable_call(op);
aoqi@0 481 break;
aoqi@0 482 default:
aoqi@0 483 fatal(err_msg_res("unexpected op code: %s", op->name()));
aoqi@0 484 break;
aoqi@0 485 }
aoqi@0 486
aoqi@0 487 // JSR 292
aoqi@0 488 // Record if this method has MethodHandle invokes.
aoqi@0 489 if (op->is_method_handle_invoke()) {
aoqi@0 490 compilation()->set_has_method_handle_invokes(true);
aoqi@0 491 }
aoqi@0 492
aoqi@0 493 #if defined(X86) && defined(TIERED)
aoqi@0 494 // C2 leave fpu stack dirty clean it
aoqi@0 495 if (UseSSE < 2) {
aoqi@0 496 int i;
aoqi@0 497 for ( i = 1; i <= 7 ; i++ ) {
aoqi@0 498 ffree(i);
aoqi@0 499 }
aoqi@0 500 if (!op->result_opr()->is_float_kind()) {
aoqi@0 501 ffree(0);
aoqi@0 502 }
aoqi@0 503 }
aoqi@0 504 #endif // X86 && TIERED
aoqi@0 505 }
aoqi@0 506
aoqi@0 507
aoqi@0 508 void LIR_Assembler::emit_opLabel(LIR_OpLabel* op) {
aoqi@0 509 _masm->bind (*(op->label()));
aoqi@0 510 }
aoqi@0 511
aoqi@0 512
aoqi@0 513 void LIR_Assembler::emit_op1(LIR_Op1* op) {
aoqi@0 514 switch (op->code()) {
aoqi@0 515 case lir_move:
aoqi@0 516 if (op->move_kind() == lir_move_volatile) {
aoqi@0 517 assert(op->patch_code() == lir_patch_none, "can't patch volatiles");
aoqi@0 518 volatile_move_op(op->in_opr(), op->result_opr(), op->type(), op->info());
aoqi@0 519 } else {
aoqi@0 520 move_op(op->in_opr(), op->result_opr(), op->type(),
aoqi@0 521 op->patch_code(), op->info(), op->pop_fpu_stack(),
aoqi@0 522 op->move_kind() == lir_move_unaligned,
aoqi@0 523 op->move_kind() == lir_move_wide);
aoqi@0 524 }
aoqi@0 525 break;
aoqi@0 526
aoqi@0 527 case lir_prefetchr:
aoqi@0 528 prefetchr(op->in_opr());
aoqi@0 529 break;
aoqi@0 530
aoqi@0 531 case lir_prefetchw:
aoqi@0 532 prefetchw(op->in_opr());
aoqi@0 533 break;
aoqi@0 534
aoqi@0 535 case lir_roundfp: {
aoqi@0 536 LIR_OpRoundFP* round_op = op->as_OpRoundFP();
aoqi@0 537 roundfp_op(round_op->in_opr(), round_op->tmp(), round_op->result_opr(), round_op->pop_fpu_stack());
aoqi@0 538 break;
aoqi@0 539 }
aoqi@0 540
aoqi@0 541 case lir_return:
aoqi@0 542 return_op(op->in_opr());
aoqi@0 543 break;
aoqi@0 544
aoqi@0 545 case lir_safepoint:
aoqi@0 546 if (compilation()->debug_info_recorder()->last_pc_offset() == code_offset()) {
aoqi@0 547 _masm->nop();
aoqi@0 548 }
aoqi@0 549 safepoint_poll(op->in_opr(), op->info());
aoqi@0 550 break;
aoqi@0 551
aoqi@0 552 case lir_fxch:
aoqi@0 553 fxch(op->in_opr()->as_jint());
aoqi@0 554 break;
aoqi@0 555
aoqi@0 556 case lir_fld:
aoqi@0 557 fld(op->in_opr()->as_jint());
aoqi@0 558 break;
aoqi@0 559
aoqi@0 560 case lir_ffree:
aoqi@0 561 ffree(op->in_opr()->as_jint());
aoqi@0 562 break;
aoqi@0 563
aoqi@0 564 case lir_branch:
aoqi@0 565 break;
aoqi@0 566
aoqi@0 567 case lir_push:
aoqi@0 568 push(op->in_opr());
aoqi@0 569 break;
aoqi@0 570
aoqi@0 571 case lir_pop:
aoqi@0 572 pop(op->in_opr());
aoqi@0 573 break;
aoqi@0 574
aoqi@0 575 case lir_neg:
aoqi@0 576 negate(op->in_opr(), op->result_opr());
aoqi@0 577 break;
aoqi@0 578
aoqi@0 579 case lir_leal:
aoqi@0 580 leal(op->in_opr(), op->result_opr());
aoqi@0 581 break;
aoqi@0 582
aoqi@0 583 case lir_null_check:
aoqi@0 584 if (GenerateCompilerNullChecks) {
aoqi@0 585 add_debug_info_for_null_check_here(op->info());
aoqi@0 586
aoqi@0 587 if (op->in_opr()->is_single_cpu()) {
aoqi@0 588 _masm->null_check(op->in_opr()->as_register());
aoqi@0 589 } else {
aoqi@0 590 Unimplemented();
aoqi@0 591 }
aoqi@0 592 }
aoqi@0 593 break;
aoqi@0 594
aoqi@0 595 case lir_monaddr:
aoqi@0 596 monitor_address(op->in_opr()->as_constant_ptr()->as_jint(), op->result_opr());
aoqi@0 597 break;
aoqi@0 598
aoqi@0 599 #ifdef SPARC
aoqi@0 600 case lir_pack64:
aoqi@0 601 pack64(op->in_opr(), op->result_opr());
aoqi@0 602 break;
aoqi@0 603
aoqi@0 604 case lir_unpack64:
aoqi@0 605 unpack64(op->in_opr(), op->result_opr());
aoqi@0 606 break;
aoqi@0 607 #endif
aoqi@0 608
aoqi@0 609 case lir_unwind:
aoqi@0 610 unwind_op(op->in_opr());
aoqi@0 611 break;
aoqi@0 612
aoqi@0 613 default:
aoqi@0 614 Unimplemented();
aoqi@0 615 break;
aoqi@0 616 }
aoqi@0 617 }
aoqi@0 618
aoqi@0 619
aoqi@0 620 void LIR_Assembler::emit_op0(LIR_Op0* op) {
aoqi@0 621 switch (op->code()) {
aoqi@0 622 case lir_word_align: {
aoqi@0 623 while (code_offset() % BytesPerWord != 0) {
aoqi@0 624 _masm->nop();
aoqi@0 625 }
aoqi@0 626 break;
aoqi@0 627 }
aoqi@0 628
aoqi@0 629 case lir_nop:
aoqi@0 630 assert(op->info() == NULL, "not supported");
aoqi@0 631 _masm->nop();
aoqi@0 632 break;
aoqi@0 633
aoqi@0 634 case lir_label:
aoqi@0 635 Unimplemented();
aoqi@0 636 break;
aoqi@0 637
aoqi@0 638 case lir_build_frame:
aoqi@0 639 build_frame();
aoqi@0 640 break;
aoqi@0 641
aoqi@0 642 case lir_std_entry:
aoqi@0 643 // init offsets
aoqi@0 644 offsets()->set_value(CodeOffsets::OSR_Entry, _masm->offset());
aoqi@0 645 _masm->align(CodeEntryAlignment);
aoqi@0 646 if (needs_icache(compilation()->method())) {
aoqi@0 647 check_icache();
aoqi@0 648 }
aoqi@0 649 offsets()->set_value(CodeOffsets::Verified_Entry, _masm->offset());
aoqi@0 650 _masm->verified_entry();
aoqi@0 651 build_frame();
aoqi@0 652 offsets()->set_value(CodeOffsets::Frame_Complete, _masm->offset());
aoqi@0 653 break;
aoqi@0 654
aoqi@0 655 case lir_osr_entry:
aoqi@0 656 offsets()->set_value(CodeOffsets::OSR_Entry, _masm->offset());
aoqi@0 657 osr_entry();
aoqi@0 658 break;
aoqi@0 659
aoqi@0 660 case lir_24bit_FPU:
aoqi@0 661 set_24bit_FPU();
aoqi@0 662 break;
aoqi@0 663
aoqi@0 664 case lir_reset_FPU:
aoqi@0 665 reset_FPU();
aoqi@0 666 break;
aoqi@0 667
aoqi@0 668 case lir_breakpoint:
aoqi@0 669 breakpoint();
aoqi@0 670 break;
aoqi@0 671
aoqi@0 672 case lir_fpop_raw:
aoqi@0 673 fpop();
aoqi@0 674 break;
aoqi@0 675
aoqi@0 676 case lir_membar:
aoqi@0 677 membar();
aoqi@0 678 break;
aoqi@0 679
aoqi@0 680 case lir_membar_acquire:
aoqi@0 681 membar_acquire();
aoqi@0 682 break;
aoqi@0 683
aoqi@0 684 case lir_membar_release:
aoqi@0 685 membar_release();
aoqi@0 686 break;
aoqi@0 687
aoqi@0 688 case lir_membar_loadload:
aoqi@0 689 membar_loadload();
aoqi@0 690 break;
aoqi@0 691
aoqi@0 692 case lir_membar_storestore:
aoqi@0 693 membar_storestore();
aoqi@0 694 break;
aoqi@0 695
aoqi@0 696 case lir_membar_loadstore:
aoqi@0 697 membar_loadstore();
aoqi@0 698 break;
aoqi@0 699
aoqi@0 700 case lir_membar_storeload:
aoqi@0 701 membar_storeload();
aoqi@0 702 break;
aoqi@0 703
aoqi@0 704 case lir_get_thread:
aoqi@0 705 get_thread(op->result_opr());
aoqi@0 706 break;
aoqi@0 707
aoqi@0 708 default:
aoqi@0 709 ShouldNotReachHere();
aoqi@0 710 break;
aoqi@0 711 }
aoqi@0 712 }
aoqi@0 713
aoqi@0 714
aoqi@0 715 void LIR_Assembler::emit_op2(LIR_Op2* op) {
aoqi@0 716 switch (op->code()) {
aoqi@0 717 case lir_cmp:
aoqi@0 718 if (op->info() != NULL) {
aoqi@0 719 assert(op->in_opr1()->is_address() || op->in_opr2()->is_address(),
aoqi@0 720 "shouldn't be codeemitinfo for non-address operands");
aoqi@0 721 add_debug_info_for_null_check_here(op->info()); // exception possible
aoqi@0 722 }
aoqi@0 723 comp_op(op->condition(), op->in_opr1(), op->in_opr2(), op);
aoqi@0 724 break;
aoqi@0 725
aoqi@0 726 case lir_cmp_l2i:
aoqi@0 727 case lir_cmp_fd2i:
aoqi@0 728 case lir_ucmp_fd2i:
aoqi@0 729 comp_fl2i(op->code(), op->in_opr1(), op->in_opr2(), op->result_opr(), op);
aoqi@0 730 break;
aoqi@0 731
aoqi@0 732 case lir_cmove:
aoqi@0 733 cmove(op->condition(), op->in_opr1(), op->in_opr2(), op->result_opr(), op->type());
aoqi@0 734 break;
aoqi@0 735
aoqi@0 736 case lir_shl:
aoqi@0 737 case lir_shr:
aoqi@0 738 case lir_ushr:
aoqi@0 739 if (op->in_opr2()->is_constant()) {
aoqi@0 740 shift_op(op->code(), op->in_opr1(), op->in_opr2()->as_constant_ptr()->as_jint(), op->result_opr());
aoqi@0 741 } else {
aoqi@0 742 shift_op(op->code(), op->in_opr1(), op->in_opr2(), op->result_opr(), op->tmp1_opr());
aoqi@0 743 }
aoqi@0 744 break;
aoqi@0 745
aoqi@0 746 case lir_add:
aoqi@0 747 case lir_sub:
aoqi@0 748 case lir_mul:
aoqi@0 749 case lir_mul_strictfp:
aoqi@0 750 case lir_div:
aoqi@0 751 case lir_div_strictfp:
aoqi@0 752 case lir_rem:
aoqi@0 753 assert(op->fpu_pop_count() < 2, "");
aoqi@0 754 arith_op(
aoqi@0 755 op->code(),
aoqi@0 756 op->in_opr1(),
aoqi@0 757 op->in_opr2(),
aoqi@0 758 op->result_opr(),
aoqi@0 759 op->info(),
aoqi@0 760 op->fpu_pop_count() == 1);
aoqi@0 761 break;
aoqi@0 762
aoqi@0 763 case lir_abs:
aoqi@0 764 case lir_sqrt:
aoqi@0 765 case lir_sin:
aoqi@0 766 case lir_tan:
aoqi@0 767 case lir_cos:
aoqi@0 768 case lir_log:
aoqi@0 769 case lir_log10:
aoqi@0 770 case lir_exp:
aoqi@0 771 case lir_pow:
aoqi@0 772 intrinsic_op(op->code(), op->in_opr1(), op->in_opr2(), op->result_opr(), op);
aoqi@0 773 break;
aoqi@0 774
aoqi@0 775 case lir_logic_and:
aoqi@0 776 case lir_logic_or:
aoqi@0 777 case lir_logic_xor:
aoqi@0 778 logic_op(
aoqi@0 779 op->code(),
aoqi@0 780 op->in_opr1(),
aoqi@0 781 op->in_opr2(),
aoqi@0 782 op->result_opr());
aoqi@0 783 break;
aoqi@0 784
aoqi@0 785 case lir_throw:
aoqi@0 786 throw_op(op->in_opr1(), op->in_opr2(), op->info());
aoqi@0 787 break;
aoqi@0 788
aoqi@0 789 case lir_xadd:
aoqi@0 790 case lir_xchg:
aoqi@0 791 atomic_op(op->code(), op->in_opr1(), op->in_opr2(), op->result_opr(), op->tmp1_opr());
aoqi@0 792 break;
aoqi@0 793
aoqi@0 794 default:
aoqi@0 795 Unimplemented();
aoqi@0 796 break;
aoqi@0 797 }
aoqi@0 798 }
aoqi@0 799
aoqi@0 800
aoqi@0 801 void LIR_Assembler::build_frame() {
aoqi@0 802 _masm->build_frame(initial_frame_size_in_bytes(), bang_size_in_bytes());
aoqi@0 803 }
aoqi@0 804
aoqi@0 805
aoqi@0 806 void LIR_Assembler::roundfp_op(LIR_Opr src, LIR_Opr tmp, LIR_Opr dest, bool pop_fpu_stack) {
aoqi@0 807 assert((src->is_single_fpu() && dest->is_single_stack()) ||
aoqi@0 808 (src->is_double_fpu() && dest->is_double_stack()),
aoqi@0 809 "round_fp: rounds register -> stack location");
aoqi@0 810
aoqi@0 811 reg2stack (src, dest, src->type(), pop_fpu_stack);
aoqi@0 812 }
aoqi@0 813
aoqi@0 814
aoqi@0 815 void LIR_Assembler::move_op(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_PatchCode patch_code, CodeEmitInfo* info, bool pop_fpu_stack, bool unaligned, bool wide) {
aoqi@0 816 if (src->is_register()) {
aoqi@0 817 if (dest->is_register()) {
aoqi@0 818 assert(patch_code == lir_patch_none && info == NULL, "no patching and info allowed here");
aoqi@0 819 reg2reg(src, dest);
aoqi@0 820 } else if (dest->is_stack()) {
aoqi@0 821 assert(patch_code == lir_patch_none && info == NULL, "no patching and info allowed here");
aoqi@0 822 reg2stack(src, dest, type, pop_fpu_stack);
aoqi@0 823 } else if (dest->is_address()) {
aoqi@0 824 reg2mem(src, dest, type, patch_code, info, pop_fpu_stack, wide, unaligned);
aoqi@0 825 } else {
aoqi@0 826 ShouldNotReachHere();
aoqi@0 827 }
aoqi@0 828
aoqi@0 829 } else if (src->is_stack()) {
aoqi@0 830 assert(patch_code == lir_patch_none && info == NULL, "no patching and info allowed here");
aoqi@0 831 if (dest->is_register()) {
aoqi@0 832 stack2reg(src, dest, type);
aoqi@0 833 } else if (dest->is_stack()) {
aoqi@0 834 stack2stack(src, dest, type);
aoqi@0 835 } else {
aoqi@0 836 ShouldNotReachHere();
aoqi@0 837 }
aoqi@0 838
aoqi@0 839 } else if (src->is_constant()) {
aoqi@0 840 if (dest->is_register()) {
aoqi@0 841 const2reg(src, dest, patch_code, info); // patching is possible
aoqi@0 842 } else if (dest->is_stack()) {
aoqi@0 843 assert(patch_code == lir_patch_none && info == NULL, "no patching and info allowed here");
aoqi@0 844 const2stack(src, dest);
aoqi@0 845 } else if (dest->is_address()) {
aoqi@0 846 assert(patch_code == lir_patch_none, "no patching allowed here");
aoqi@0 847 const2mem(src, dest, type, info, wide);
aoqi@0 848 } else {
aoqi@0 849 ShouldNotReachHere();
aoqi@0 850 }
aoqi@0 851
aoqi@0 852 } else if (src->is_address()) {
aoqi@0 853 mem2reg(src, dest, type, patch_code, info, wide, unaligned);
aoqi@0 854
aoqi@0 855 } else {
aoqi@0 856 ShouldNotReachHere();
aoqi@0 857 }
aoqi@0 858 }
aoqi@0 859
aoqi@0 860
aoqi@0 861 void LIR_Assembler::verify_oop_map(CodeEmitInfo* info) {
aoqi@0 862 #ifndef PRODUCT
aoqi@0 863 if (VerifyOops) {
aoqi@0 864 OopMapStream s(info->oop_map());
aoqi@0 865 while (!s.is_done()) {
aoqi@0 866 OopMapValue v = s.current();
aoqi@0 867 if (v.is_oop()) {
aoqi@0 868 VMReg r = v.reg();
aoqi@0 869 if (!r->is_stack()) {
aoqi@0 870 stringStream st;
aoqi@0 871 st.print("bad oop %s at %d", r->as_Register()->name(), _masm->offset());
aoqi@0 872 #ifdef SPARC
aoqi@0 873 _masm->_verify_oop(r->as_Register(), strdup(st.as_string()), __FILE__, __LINE__);
aoqi@0 874 #else
aoqi@0 875 _masm->verify_oop(r->as_Register());
aoqi@0 876 #endif
aoqi@0 877 } else {
aoqi@0 878 _masm->verify_stack_oop(r->reg2stack() * VMRegImpl::stack_slot_size);
aoqi@0 879 }
aoqi@0 880 }
aoqi@0 881 check_codespace();
aoqi@0 882 CHECK_BAILOUT();
aoqi@0 883
aoqi@0 884 s.next();
aoqi@0 885 }
aoqi@0 886 }
aoqi@0 887 #endif
aoqi@0 888 }

mercurial