src/share/vm/c1/c1_Compilation.cpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 6723
0bf37f737702
child 6876
710a3c8b516e
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

duke@435 1 /*
mikael@6198 2 * Copyright (c) 1999, 2013, 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_CFGPrinter.hpp"
stefank@2314 27 #include "c1/c1_Compilation.hpp"
stefank@2314 28 #include "c1/c1_IR.hpp"
stefank@2314 29 #include "c1/c1_LIRAssembler.hpp"
stefank@2314 30 #include "c1/c1_LinearScan.hpp"
stefank@2314 31 #include "c1/c1_MacroAssembler.hpp"
stefank@2314 32 #include "c1/c1_ValueMap.hpp"
stefank@2314 33 #include "c1/c1_ValueStack.hpp"
stefank@2314 34 #include "code/debugInfoRec.hpp"
vlivanov@4154 35 #include "compiler/compileLog.hpp"
roland@4860 36 #include "c1/c1_RangeCheckElimination.hpp"
duke@435 37
duke@435 38
duke@435 39 typedef enum {
duke@435 40 _t_compile,
duke@435 41 _t_setup,
duke@435 42 _t_buildIR,
roland@4860 43 _t_optimize_blocks,
roland@4860 44 _t_optimize_null_checks,
roland@4860 45 _t_rangeCheckElimination,
duke@435 46 _t_emit_lir,
duke@435 47 _t_linearScan,
duke@435 48 _t_lirGeneration,
duke@435 49 _t_lir_schedule,
duke@435 50 _t_codeemit,
duke@435 51 _t_codeinstall,
duke@435 52 max_phase_timers
duke@435 53 } TimerName;
duke@435 54
duke@435 55 static const char * timer_name[] = {
duke@435 56 "compile",
duke@435 57 "setup",
duke@435 58 "buildIR",
roland@4860 59 "optimize_blocks",
roland@4860 60 "optimize_null_checks",
roland@4860 61 "rangeCheckElimination",
duke@435 62 "emit_lir",
duke@435 63 "linearScan",
duke@435 64 "lirGeneration",
duke@435 65 "lir_schedule",
duke@435 66 "codeemit",
duke@435 67 "codeinstall"
duke@435 68 };
duke@435 69
duke@435 70 static elapsedTimer timers[max_phase_timers];
duke@435 71 static int totalInstructionNodes = 0;
duke@435 72
duke@435 73 class PhaseTraceTime: public TraceTime {
duke@435 74 private:
duke@435 75 JavaThread* _thread;
vlivanov@4154 76 CompileLog* _log;
vlivanov@5630 77 TimerName _timer;
duke@435 78
duke@435 79 public:
vlivanov@4154 80 PhaseTraceTime(TimerName timer)
vlivanov@5630 81 : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose),
vlivanov@5630 82 _log(NULL), _timer(timer)
vlivanov@5630 83 {
vlivanov@4154 84 if (Compilation::current() != NULL) {
vlivanov@4154 85 _log = Compilation::current()->log();
vlivanov@4154 86 }
vlivanov@4154 87
vlivanov@4154 88 if (_log != NULL) {
vlivanov@5630 89 _log->begin_head("phase name='%s'", timer_name[_timer]);
vlivanov@4154 90 _log->stamp();
vlivanov@4154 91 _log->end_head();
vlivanov@4154 92 }
vlivanov@4154 93 }
vlivanov@4154 94
vlivanov@4154 95 ~PhaseTraceTime() {
vlivanov@4154 96 if (_log != NULL)
vlivanov@5630 97 _log->done("phase name='%s'", timer_name[_timer]);
duke@435 98 }
duke@435 99 };
duke@435 100
duke@435 101 // Implementation of Compilation
duke@435 102
duke@435 103
duke@435 104 #ifndef PRODUCT
duke@435 105
duke@435 106 void Compilation::maybe_print_current_instruction() {
duke@435 107 if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) {
duke@435 108 _last_instruction_printed = _current_instruction;
duke@435 109 _current_instruction->print_line();
duke@435 110 }
duke@435 111 }
duke@435 112 #endif // PRODUCT
duke@435 113
duke@435 114
duke@435 115 DebugInformationRecorder* Compilation::debug_info_recorder() const {
duke@435 116 return _env->debug_info();
duke@435 117 }
duke@435 118
duke@435 119
duke@435 120 Dependencies* Compilation::dependency_recorder() const {
duke@435 121 return _env->dependencies();
duke@435 122 }
duke@435 123
duke@435 124
duke@435 125 void Compilation::initialize() {
duke@435 126 // Use an oop recorder bound to the CI environment.
duke@435 127 // (The default oop recorder is ignorant of the CI.)
duke@435 128 OopRecorder* ooprec = new OopRecorder(_env->arena());
duke@435 129 _env->set_oop_recorder(ooprec);
duke@435 130 _env->set_debug_info(new DebugInformationRecorder(ooprec));
duke@435 131 debug_info_recorder()->set_oopmaps(new OopMapSet());
duke@435 132 _env->set_dependencies(new Dependencies(_env));
duke@435 133 }
duke@435 134
duke@435 135
duke@435 136 void Compilation::build_hir() {
duke@435 137 CHECK_BAILOUT();
duke@435 138
duke@435 139 // setup ir
neliasso@4320 140 CompileLog* log = this->log();
neliasso@4320 141 if (log != NULL) {
neliasso@4320 142 log->begin_head("parse method='%d' ",
neliasso@4320 143 log->identify(_method));
neliasso@4320 144 log->stamp();
neliasso@4320 145 log->end_head();
neliasso@4320 146 }
duke@435 147 _hir = new IR(this, method(), osr_bci());
neliasso@4320 148 if (log) log->done("parse");
duke@435 149 if (!_hir->is_valid()) {
duke@435 150 bailout("invalid parsing");
duke@435 151 return;
duke@435 152 }
duke@435 153
duke@435 154 #ifndef PRODUCT
duke@435 155 if (PrintCFGToFile) {
duke@435 156 CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
duke@435 157 }
duke@435 158 #endif
duke@435 159
duke@435 160 #ifndef PRODUCT
duke@435 161 if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
duke@435 162 if (PrintIR || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
duke@435 163 #endif
duke@435 164
duke@435 165 _hir->verify();
duke@435 166
duke@435 167 if (UseC1Optimizations) {
duke@435 168 NEEDS_CLEANUP
duke@435 169 // optimization
roland@4860 170 PhaseTraceTime timeit(_t_optimize_blocks);
duke@435 171
roland@4860 172 _hir->optimize_blocks();
duke@435 173 }
duke@435 174
duke@435 175 _hir->verify();
duke@435 176
duke@435 177 _hir->split_critical_edges();
duke@435 178
duke@435 179 #ifndef PRODUCT
duke@435 180 if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
duke@435 181 if (PrintIR || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
duke@435 182 #endif
duke@435 183
duke@435 184 _hir->verify();
duke@435 185
duke@435 186 // compute block ordering for code generation
duke@435 187 // the control flow must not be changed from here on
duke@435 188 _hir->compute_code();
duke@435 189
duke@435 190 if (UseGlobalValueNumbering) {
roland@4860 191 // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.
duke@435 192 int instructions = Instruction::number_of_instructions();
duke@435 193 GlobalValueNumbering gvn(_hir);
duke@435 194 assert(instructions == Instruction::number_of_instructions(),
duke@435 195 "shouldn't have created an instructions");
duke@435 196 }
duke@435 197
roland@4860 198 _hir->verify();
roland@4860 199
roland@4860 200 #ifndef PRODUCT
roland@4860 201 if (PrintCFGToFile) {
roland@4860 202 CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false);
roland@4860 203 }
roland@4860 204 #endif
roland@4860 205
roland@4860 206 if (RangeCheckElimination) {
roland@4860 207 if (_hir->osr_entry() == NULL) {
roland@4860 208 PhaseTraceTime timeit(_t_rangeCheckElimination);
roland@4860 209 RangeCheckElimination::eliminate(_hir);
roland@4860 210 }
roland@4860 211 }
roland@4860 212
roland@4860 213 #ifndef PRODUCT
roland@4860 214 if (PrintCFGToFile) {
roland@4860 215 CFGPrinter::print_cfg(_hir, "After RangeCheckElimination", true, false);
roland@4860 216 }
roland@4860 217 #endif
roland@4860 218
roland@4860 219 if (UseC1Optimizations) {
roland@4860 220 // loop invariant code motion reorders instructions and range
roland@4860 221 // check elimination adds new instructions so do null check
roland@4860 222 // elimination after.
roland@4860 223 NEEDS_CLEANUP
roland@4860 224 // optimization
roland@4860 225 PhaseTraceTime timeit(_t_optimize_null_checks);
roland@4860 226
roland@4860 227 _hir->eliminate_null_checks();
roland@4860 228 }
roland@4860 229
roland@4860 230 _hir->verify();
roland@4860 231
duke@435 232 // compute use counts after global value numbering
duke@435 233 _hir->compute_use_counts();
duke@435 234
duke@435 235 #ifndef PRODUCT
duke@435 236 if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); }
duke@435 237 if (PrintIR || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); }
duke@435 238 #endif
duke@435 239
duke@435 240 _hir->verify();
duke@435 241 }
duke@435 242
duke@435 243
duke@435 244 void Compilation::emit_lir() {
duke@435 245 CHECK_BAILOUT();
duke@435 246
duke@435 247 LIRGenerator gen(this, method());
duke@435 248 {
duke@435 249 PhaseTraceTime timeit(_t_lirGeneration);
duke@435 250 hir()->iterate_linear_scan_order(&gen);
duke@435 251 }
duke@435 252
duke@435 253 CHECK_BAILOUT();
duke@435 254
duke@435 255 {
duke@435 256 PhaseTraceTime timeit(_t_linearScan);
duke@435 257
duke@435 258 LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
duke@435 259 set_allocator(allocator);
duke@435 260 // Assign physical registers to LIR operands using a linear scan algorithm.
duke@435 261 allocator->do_linear_scan();
duke@435 262 CHECK_BAILOUT();
duke@435 263
duke@435 264 _max_spills = allocator->max_spills();
duke@435 265 }
duke@435 266
duke@435 267 if (BailoutAfterLIR) {
duke@435 268 if (PrintLIR && !bailed_out()) {
duke@435 269 print_LIR(hir()->code());
duke@435 270 }
duke@435 271 bailout("Bailing out because of -XX:+BailoutAfterLIR");
duke@435 272 }
duke@435 273 }
duke@435 274
duke@435 275
duke@435 276 void Compilation::emit_code_epilog(LIR_Assembler* assembler) {
duke@435 277 CHECK_BAILOUT();
duke@435 278
twisti@1639 279 CodeOffsets* code_offsets = assembler->offsets();
twisti@1639 280
duke@435 281 // generate code or slow cases
duke@435 282 assembler->emit_slow_case_stubs();
duke@435 283 CHECK_BAILOUT();
duke@435 284
duke@435 285 // generate exception adapters
duke@435 286 assembler->emit_exception_entries(exception_info_list());
duke@435 287 CHECK_BAILOUT();
duke@435 288
twisti@1639 289 // Generate code for exception handler.
twisti@1639 290 code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler());
duke@435 291 CHECK_BAILOUT();
twisti@1639 292
twisti@1639 293 // Generate code for deopt handler.
twisti@1639 294 code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler());
twisti@1639 295 CHECK_BAILOUT();
twisti@1639 296
twisti@2046 297 // Emit the MethodHandle deopt handler code (if required).
twisti@2046 298 if (has_method_handle_invokes()) {
twisti@2046 299 // We can use the same code as for the normal deopt handler, we
twisti@2046 300 // just need a different entry point address.
twisti@2046 301 code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler());
twisti@2046 302 CHECK_BAILOUT();
twisti@2046 303 }
duke@435 304
never@1813 305 // Emit the handler to remove the activation from the stack and
never@1813 306 // dispatch to the caller.
never@1813 307 offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler());
never@1813 308
duke@435 309 // done
duke@435 310 masm()->flush();
duke@435 311 }
duke@435 312
duke@435 313
bobv@2421 314 bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) {
iveresov@1939 315 // Preinitialize the consts section to some large size:
iveresov@1939 316 int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo));
iveresov@1939 317 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
iveresov@1939 318 code->insts()->initialize_shared_locs((relocInfo*)locs_buffer,
iveresov@1939 319 locs_buffer_size / sizeof(relocInfo));
iveresov@1939 320 code->initialize_consts_size(Compilation::desired_max_constant_size());
iveresov@1972 321 // Call stubs + two deopt handlers (regular and MH) + exception handler
bobv@2421 322 int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size) +
bobv@2421 323 LIR_Assembler::exception_handler_size +
bobv@2421 324 (2 * LIR_Assembler::deopt_handler_size);
bobv@2421 325 if (stub_size >= code->insts_capacity()) return false;
bobv@2421 326 code->initialize_stubs_size(stub_size);
bobv@2421 327 return true;
iveresov@1939 328 }
iveresov@1939 329
iveresov@1939 330
duke@435 331 int Compilation::emit_code_body() {
duke@435 332 // emit code
bobv@2421 333 if (!setup_code_buffer(code(), allocator()->num_calls())) {
bobv@2421 334 BAILOUT_("size requested greater than avail code buffer size", 0);
bobv@2421 335 }
duke@435 336 code()->initialize_oop_recorder(env()->oop_recorder());
duke@435 337
duke@435 338 _masm = new C1_MacroAssembler(code());
duke@435 339 _masm->set_oop_recorder(env()->oop_recorder());
duke@435 340
duke@435 341 LIR_Assembler lir_asm(this);
duke@435 342
duke@435 343 lir_asm.emit_code(hir()->code());
duke@435 344 CHECK_BAILOUT_(0);
duke@435 345
duke@435 346 emit_code_epilog(&lir_asm);
duke@435 347 CHECK_BAILOUT_(0);
duke@435 348
duke@435 349 generate_exception_handler_table();
duke@435 350
duke@435 351 #ifndef PRODUCT
duke@435 352 if (PrintExceptionHandlers && Verbose) {
duke@435 353 exception_handler_table()->print();
duke@435 354 }
duke@435 355 #endif /* PRODUCT */
duke@435 356
duke@435 357 return frame_map()->framesize();
duke@435 358 }
duke@435 359
duke@435 360
duke@435 361 int Compilation::compile_java_method() {
duke@435 362 assert(!method()->is_native(), "should not reach here");
duke@435 363
duke@435 364 if (BailoutOnExceptionHandlers) {
duke@435 365 if (method()->has_exception_handlers()) {
duke@435 366 bailout("linear scan can't handle exception handlers");
duke@435 367 }
duke@435 368 }
duke@435 369
duke@435 370 CHECK_BAILOUT_(no_frame_size);
duke@435 371
iveresov@2349 372 if (is_profiling() && !method()->ensure_method_data()) {
iveresov@2349 373 BAILOUT_("mdo allocation failed", no_frame_size);
iveresov@2138 374 }
iveresov@2138 375
duke@435 376 {
duke@435 377 PhaseTraceTime timeit(_t_buildIR);
iveresov@2138 378 build_hir();
duke@435 379 }
duke@435 380 if (BailoutAfterHIR) {
duke@435 381 BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size);
duke@435 382 }
duke@435 383
duke@435 384
duke@435 385 {
duke@435 386 PhaseTraceTime timeit(_t_emit_lir);
duke@435 387
duke@435 388 _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack()));
duke@435 389 emit_lir();
duke@435 390 }
duke@435 391 CHECK_BAILOUT_(no_frame_size);
duke@435 392
duke@435 393 {
duke@435 394 PhaseTraceTime timeit(_t_codeemit);
duke@435 395 return emit_code_body();
duke@435 396 }
duke@435 397 }
duke@435 398
duke@435 399 void Compilation::install_code(int frame_size) {
duke@435 400 // frame_size is in 32-bit words so adjust it intptr_t words
duke@435 401 assert(frame_size == frame_map()->framesize(), "must match");
duke@435 402 assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
duke@435 403 _env->register_method(
duke@435 404 method(),
duke@435 405 osr_bci(),
duke@435 406 &_offsets,
duke@435 407 in_bytes(_frame_map->sp_offset_for_orig_pc()),
duke@435 408 code(),
duke@435 409 in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
duke@435 410 debug_info_recorder()->_oopmaps,
duke@435 411 exception_handler_table(),
duke@435 412 implicit_exception_table(),
duke@435 413 compiler(),
duke@435 414 _env->comp_level(),
kvn@4103 415 has_unsafe_access(),
kvn@4103 416 SharedRuntime::is_wide_vector(max_vector_size())
duke@435 417 );
duke@435 418 }
duke@435 419
duke@435 420
duke@435 421 void Compilation::compile_method() {
duke@435 422 // setup compilation
duke@435 423 initialize();
duke@435 424
duke@435 425 if (!method()->can_be_compiled()) {
duke@435 426 // Prevent race condition 6328518.
duke@435 427 // This can happen if the method is obsolete or breakpointed.
duke@435 428 bailout("Bailing out because method is not compilable");
duke@435 429 return;
duke@435 430 }
duke@435 431
kvn@1215 432 if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
duke@435 433 // We can assert evol_method because method->can_be_compiled is true.
duke@435 434 dependency_recorder()->assert_evol_method(method());
duke@435 435 }
duke@435 436
duke@435 437 if (method()->break_at_execute()) {
duke@435 438 BREAKPOINT;
duke@435 439 }
duke@435 440
duke@435 441 #ifndef PRODUCT
duke@435 442 if (PrintCFGToFile) {
duke@435 443 CFGPrinter::print_compilation(this);
duke@435 444 }
duke@435 445 #endif
duke@435 446
duke@435 447 // compile method
duke@435 448 int frame_size = compile_java_method();
duke@435 449
duke@435 450 // bailout if method couldn't be compiled
duke@435 451 // Note: make sure we mark the method as not compilable!
duke@435 452 CHECK_BAILOUT();
duke@435 453
duke@435 454 if (InstallMethods) {
duke@435 455 // install code
duke@435 456 PhaseTraceTime timeit(_t_codeinstall);
duke@435 457 install_code(frame_size);
duke@435 458 }
vlivanov@4154 459
vlivanov@4154 460 if (log() != NULL) // Print code cache state into compiler log
vlivanov@4154 461 log()->code_cache_state();
vlivanov@4154 462
duke@435 463 totalInstructionNodes += Instruction::number_of_instructions();
duke@435 464 }
duke@435 465
duke@435 466
duke@435 467 void Compilation::generate_exception_handler_table() {
duke@435 468 // Generate an ExceptionHandlerTable from the exception handler
duke@435 469 // information accumulated during the compilation.
duke@435 470 ExceptionInfoList* info_list = exception_info_list();
duke@435 471
duke@435 472 if (info_list->length() == 0) {
duke@435 473 return;
duke@435 474 }
duke@435 475
duke@435 476 // allocate some arrays for use by the collection code.
duke@435 477 const int num_handlers = 5;
duke@435 478 GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
duke@435 479 GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
duke@435 480 GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
duke@435 481
duke@435 482 for (int i = 0; i < info_list->length(); i++) {
duke@435 483 ExceptionInfo* info = info_list->at(i);
duke@435 484 XHandlers* handlers = info->exception_handlers();
duke@435 485
duke@435 486 // empty the arrays
duke@435 487 bcis->trunc_to(0);
duke@435 488 scope_depths->trunc_to(0);
duke@435 489 pcos->trunc_to(0);
duke@435 490
duke@435 491 for (int i = 0; i < handlers->length(); i++) {
duke@435 492 XHandler* handler = handlers->handler_at(i);
duke@435 493 assert(handler->entry_pco() != -1, "must have been generated");
duke@435 494
duke@435 495 int e = bcis->find(handler->handler_bci());
duke@435 496 if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
duke@435 497 // two different handlers are declared to dispatch to the same
duke@435 498 // catch bci. During parsing we created edges for each
duke@435 499 // handler but we really only need one. The exception handler
duke@435 500 // table will also get unhappy if we try to declare both since
duke@435 501 // it's nonsensical. Just skip this handler.
duke@435 502 continue;
duke@435 503 }
duke@435 504
duke@435 505 bcis->append(handler->handler_bci());
duke@435 506 if (handler->handler_bci() == -1) {
duke@435 507 // insert a wildcard handler at scope depth 0 so that the
duke@435 508 // exception lookup logic with find it.
duke@435 509 scope_depths->append(0);
duke@435 510 } else {
duke@435 511 scope_depths->append(handler->scope_count());
duke@435 512 }
duke@435 513 pcos->append(handler->entry_pco());
duke@435 514
duke@435 515 // stop processing once we hit a catch any
duke@435 516 if (handler->is_catch_all()) {
duke@435 517 assert(i == handlers->length() - 1, "catch all must be last handler");
duke@435 518 }
duke@435 519 }
duke@435 520 exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
duke@435 521 }
duke@435 522 }
duke@435 523
duke@435 524
iveresov@1939 525 Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,
iveresov@1939 526 int osr_bci, BufferBlob* buffer_blob)
duke@435 527 : _compiler(compiler)
duke@435 528 , _env(env)
vlivanov@4154 529 , _log(env->log())
duke@435 530 , _method(method)
duke@435 531 , _osr_bci(osr_bci)
duke@435 532 , _hir(NULL)
duke@435 533 , _max_spills(-1)
duke@435 534 , _frame_map(NULL)
duke@435 535 , _masm(NULL)
duke@435 536 , _has_exception_handlers(false)
duke@435 537 , _has_fpu_code(true) // pessimistic assumption
iveresov@2138 538 , _would_profile(false)
duke@435 539 , _has_unsafe_access(false)
twisti@2046 540 , _has_method_handle_invokes(false)
duke@435 541 , _bailout_msg(NULL)
duke@435 542 , _exception_info_list(NULL)
duke@435 543 , _allocator(NULL)
iveresov@1939 544 , _next_id(0)
iveresov@1939 545 , _next_block_id(0)
twisti@2103 546 , _code(buffer_blob)
roland@4860 547 , _has_access_indexed(false)
duke@435 548 , _current_instruction(NULL)
roland@6723 549 , _interpreter_frame_size(0)
duke@435 550 #ifndef PRODUCT
duke@435 551 , _last_instruction_printed(NULL)
duke@435 552 #endif // PRODUCT
duke@435 553 {
duke@435 554 PhaseTraceTime timeit(_t_compile);
duke@435 555 _arena = Thread::current()->resource_area();
iveresov@1939 556 _env->set_compiler_data(this);
duke@435 557 _exception_info_list = new ExceptionInfoList();
duke@435 558 _implicit_exception_table.set_size(0);
duke@435 559 compile_method();
iveresov@2306 560 if (bailed_out()) {
iveresov@2306 561 _env->record_method_not_compilable(bailout_msg(), !TieredCompilation);
iveresov@2306 562 if (is_profiling()) {
iveresov@2306 563 // Compilation failed, create MDO, which would signal the interpreter
iveresov@2306 564 // to start profiling on its own.
iveresov@2349 565 _method->ensure_method_data();
iveresov@2306 566 }
iveresov@2559 567 } else if (is_profiling()) {
iveresov@2349 568 ciMethodData *md = method->method_data_or_null();
iveresov@2559 569 if (md != NULL) {
iveresov@2559 570 md->set_would_profile(_would_profile);
iveresov@2559 571 }
iveresov@2138 572 }
duke@435 573 }
duke@435 574
duke@435 575 Compilation::~Compilation() {
iveresov@1939 576 _env->set_compiler_data(NULL);
duke@435 577 }
duke@435 578
duke@435 579
duke@435 580 void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) {
duke@435 581 #ifndef PRODUCT
duke@435 582 if (PrintExceptionHandlers && Verbose) {
duke@435 583 tty->print_cr(" added exception scope for pco %d", pco);
duke@435 584 }
duke@435 585 #endif
duke@435 586 // Note: we do not have program counters for these exception handlers yet
duke@435 587 exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
duke@435 588 }
duke@435 589
duke@435 590
duke@435 591 void Compilation::notice_inlined_method(ciMethod* method) {
duke@435 592 _env->notice_inlined_method(method);
duke@435 593 }
duke@435 594
duke@435 595
duke@435 596 void Compilation::bailout(const char* msg) {
duke@435 597 assert(msg != NULL, "bailout message must exist");
duke@435 598 if (!bailed_out()) {
duke@435 599 // keep first bailout message
twisti@3969 600 if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
duke@435 601 _bailout_msg = msg;
duke@435 602 }
duke@435 603 }
duke@435 604
roland@5914 605 ciKlass* Compilation::cha_exact_type(ciType* type) {
roland@5914 606 if (type != NULL && type->is_loaded() && type->is_instance_klass()) {
roland@5914 607 ciInstanceKlass* ik = type->as_instance_klass();
roland@5914 608 assert(ik->exact_klass() == NULL, "no cha for final klass");
roland@5914 609 if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
roland@5914 610 dependency_recorder()->assert_leaf_type(ik);
roland@5914 611 return ik;
roland@5914 612 }
roland@5914 613 }
roland@5914 614 return NULL;
roland@5914 615 }
duke@435 616
duke@435 617 void Compilation::print_timers() {
duke@435 618 // tty->print_cr(" Native methods : %6.3f s, Average : %2.3f", CompileBroker::_t_native_compilation.seconds(), CompileBroker::_t_native_compilation.seconds() / CompileBroker::_total_native_compile_count);
duke@435 619 float total = timers[_t_setup].seconds() + timers[_t_buildIR].seconds() + timers[_t_emit_lir].seconds() + timers[_t_lir_schedule].seconds() + timers[_t_codeemit].seconds() + timers[_t_codeinstall].seconds();
duke@435 620
duke@435 621
duke@435 622 tty->print_cr(" Detailed C1 Timings");
duke@435 623 tty->print_cr(" Setup time: %6.3f s (%4.1f%%)", timers[_t_setup].seconds(), (timers[_t_setup].seconds() / total) * 100.0);
duke@435 624 tty->print_cr(" Build IR: %6.3f s (%4.1f%%)", timers[_t_buildIR].seconds(), (timers[_t_buildIR].seconds() / total) * 100.0);
roland@4860 625 float t_optimizeIR = timers[_t_optimize_blocks].seconds() + timers[_t_optimize_null_checks].seconds();
roland@4860 626 tty->print_cr(" Optimize: %6.3f s (%4.1f%%)", t_optimizeIR, (t_optimizeIR / total) * 100.0);
roland@4860 627 tty->print_cr(" RCE: %6.3f s (%4.1f%%)", timers[_t_rangeCheckElimination].seconds(), (timers[_t_rangeCheckElimination].seconds() / total) * 100.0);
duke@435 628 tty->print_cr(" Emit LIR: %6.3f s (%4.1f%%)", timers[_t_emit_lir].seconds(), (timers[_t_emit_lir].seconds() / total) * 100.0);
duke@435 629 tty->print_cr(" LIR Gen: %6.3f s (%4.1f%%)", timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0);
duke@435 630 tty->print_cr(" Linear Scan: %6.3f s (%4.1f%%)", timers[_t_linearScan].seconds(), (timers[_t_linearScan].seconds() / total) * 100.0);
duke@435 631 NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
duke@435 632 tty->print_cr(" LIR Schedule: %6.3f s (%4.1f%%)", timers[_t_lir_schedule].seconds(), (timers[_t_lir_schedule].seconds() / total) * 100.0);
duke@435 633 tty->print_cr(" Code Emission: %6.3f s (%4.1f%%)", timers[_t_codeemit].seconds(), (timers[_t_codeemit].seconds() / total) * 100.0);
duke@435 634 tty->print_cr(" Code Installation: %6.3f s (%4.1f%%)", timers[_t_codeinstall].seconds(), (timers[_t_codeinstall].seconds() / total) * 100.0);
duke@435 635 tty->print_cr(" Instruction Nodes: %6d nodes", totalInstructionNodes);
duke@435 636
duke@435 637 NOT_PRODUCT(LinearScan::print_statistics());
duke@435 638 }
duke@435 639
duke@435 640
duke@435 641 #ifndef PRODUCT
duke@435 642 void Compilation::compile_only_this_method() {
duke@435 643 ResourceMark rm;
duke@435 644 fileStream stream(fopen("c1_compile_only", "wt"));
duke@435 645 stream.print_cr("# c1 compile only directives");
duke@435 646 compile_only_this_scope(&stream, hir()->top_scope());
duke@435 647 }
duke@435 648
duke@435 649
duke@435 650 void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
duke@435 651 st->print("CompileOnly=");
duke@435 652 scope->method()->holder()->name()->print_symbol_on(st);
duke@435 653 st->print(".");
duke@435 654 scope->method()->name()->print_symbol_on(st);
duke@435 655 st->cr();
duke@435 656 }
duke@435 657
duke@435 658
duke@435 659 void Compilation::exclude_this_method() {
duke@435 660 fileStream stream(fopen(".hotspot_compiler", "at"));
duke@435 661 stream.print("exclude ");
duke@435 662 method()->holder()->name()->print_symbol_on(&stream);
duke@435 663 stream.print(" ");
duke@435 664 method()->name()->print_symbol_on(&stream);
duke@435 665 stream.cr();
duke@435 666 stream.cr();
duke@435 667 }
duke@435 668 #endif

mercurial