src/share/vm/c1/c1_Compilation.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_Compilation.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,668 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "c1/c1_CFGPrinter.hpp"
    1.30 +#include "c1/c1_Compilation.hpp"
    1.31 +#include "c1/c1_IR.hpp"
    1.32 +#include "c1/c1_LIRAssembler.hpp"
    1.33 +#include "c1/c1_LinearScan.hpp"
    1.34 +#include "c1/c1_MacroAssembler.hpp"
    1.35 +#include "c1/c1_ValueMap.hpp"
    1.36 +#include "c1/c1_ValueStack.hpp"
    1.37 +#include "code/debugInfoRec.hpp"
    1.38 +#include "compiler/compileLog.hpp"
    1.39 +#include "c1/c1_RangeCheckElimination.hpp"
    1.40 +
    1.41 +
    1.42 +typedef enum {
    1.43 +  _t_compile,
    1.44 +  _t_setup,
    1.45 +  _t_buildIR,
    1.46 +  _t_optimize_blocks,
    1.47 +  _t_optimize_null_checks,
    1.48 +  _t_rangeCheckElimination,
    1.49 +  _t_emit_lir,
    1.50 +  _t_linearScan,
    1.51 +  _t_lirGeneration,
    1.52 +  _t_lir_schedule,
    1.53 +  _t_codeemit,
    1.54 +  _t_codeinstall,
    1.55 +  max_phase_timers
    1.56 +} TimerName;
    1.57 +
    1.58 +static const char * timer_name[] = {
    1.59 +  "compile",
    1.60 +  "setup",
    1.61 +  "buildIR",
    1.62 +  "optimize_blocks",
    1.63 +  "optimize_null_checks",
    1.64 +  "rangeCheckElimination",
    1.65 +  "emit_lir",
    1.66 +  "linearScan",
    1.67 +  "lirGeneration",
    1.68 +  "lir_schedule",
    1.69 +  "codeemit",
    1.70 +  "codeinstall"
    1.71 +};
    1.72 +
    1.73 +static elapsedTimer timers[max_phase_timers];
    1.74 +static int totalInstructionNodes = 0;
    1.75 +
    1.76 +class PhaseTraceTime: public TraceTime {
    1.77 + private:
    1.78 +  JavaThread* _thread;
    1.79 +  CompileLog* _log;
    1.80 +  TimerName _timer;
    1.81 +
    1.82 + public:
    1.83 +  PhaseTraceTime(TimerName timer)
    1.84 +  : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose),
    1.85 +    _log(NULL), _timer(timer)
    1.86 +  {
    1.87 +    if (Compilation::current() != NULL) {
    1.88 +      _log = Compilation::current()->log();
    1.89 +    }
    1.90 +
    1.91 +    if (_log != NULL) {
    1.92 +      _log->begin_head("phase name='%s'", timer_name[_timer]);
    1.93 +      _log->stamp();
    1.94 +      _log->end_head();
    1.95 +    }
    1.96 +  }
    1.97 +
    1.98 +  ~PhaseTraceTime() {
    1.99 +    if (_log != NULL)
   1.100 +      _log->done("phase name='%s'", timer_name[_timer]);
   1.101 +  }
   1.102 +};
   1.103 +
   1.104 +// Implementation of Compilation
   1.105 +
   1.106 +
   1.107 +#ifndef PRODUCT
   1.108 +
   1.109 +void Compilation::maybe_print_current_instruction() {
   1.110 +  if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) {
   1.111 +    _last_instruction_printed = _current_instruction;
   1.112 +    _current_instruction->print_line();
   1.113 +  }
   1.114 +}
   1.115 +#endif // PRODUCT
   1.116 +
   1.117 +
   1.118 +DebugInformationRecorder* Compilation::debug_info_recorder() const {
   1.119 +  return _env->debug_info();
   1.120 +}
   1.121 +
   1.122 +
   1.123 +Dependencies* Compilation::dependency_recorder() const {
   1.124 +  return _env->dependencies();
   1.125 +}
   1.126 +
   1.127 +
   1.128 +void Compilation::initialize() {
   1.129 +  // Use an oop recorder bound to the CI environment.
   1.130 +  // (The default oop recorder is ignorant of the CI.)
   1.131 +  OopRecorder* ooprec = new OopRecorder(_env->arena());
   1.132 +  _env->set_oop_recorder(ooprec);
   1.133 +  _env->set_debug_info(new DebugInformationRecorder(ooprec));
   1.134 +  debug_info_recorder()->set_oopmaps(new OopMapSet());
   1.135 +  _env->set_dependencies(new Dependencies(_env));
   1.136 +}
   1.137 +
   1.138 +
   1.139 +void Compilation::build_hir() {
   1.140 +  CHECK_BAILOUT();
   1.141 +
   1.142 +  // setup ir
   1.143 +  CompileLog* log = this->log();
   1.144 +  if (log != NULL) {
   1.145 +    log->begin_head("parse method='%d' ",
   1.146 +                    log->identify(_method));
   1.147 +    log->stamp();
   1.148 +    log->end_head();
   1.149 +  }
   1.150 +  _hir = new IR(this, method(), osr_bci());
   1.151 +  if (log)  log->done("parse");
   1.152 +  if (!_hir->is_valid()) {
   1.153 +    bailout("invalid parsing");
   1.154 +    return;
   1.155 +  }
   1.156 +
   1.157 +#ifndef PRODUCT
   1.158 +  if (PrintCFGToFile) {
   1.159 +    CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
   1.160 +  }
   1.161 +#endif
   1.162 +
   1.163 +#ifndef PRODUCT
   1.164 +  if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
   1.165 +  if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
   1.166 +#endif
   1.167 +
   1.168 +  _hir->verify();
   1.169 +
   1.170 +  if (UseC1Optimizations) {
   1.171 +    NEEDS_CLEANUP
   1.172 +    // optimization
   1.173 +    PhaseTraceTime timeit(_t_optimize_blocks);
   1.174 +
   1.175 +    _hir->optimize_blocks();
   1.176 +  }
   1.177 +
   1.178 +  _hir->verify();
   1.179 +
   1.180 +  _hir->split_critical_edges();
   1.181 +
   1.182 +#ifndef PRODUCT
   1.183 +  if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
   1.184 +  if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
   1.185 +#endif
   1.186 +
   1.187 +  _hir->verify();
   1.188 +
   1.189 +  // compute block ordering for code generation
   1.190 +  // the control flow must not be changed from here on
   1.191 +  _hir->compute_code();
   1.192 +
   1.193 +  if (UseGlobalValueNumbering) {
   1.194 +    // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.
   1.195 +    int instructions = Instruction::number_of_instructions();
   1.196 +    GlobalValueNumbering gvn(_hir);
   1.197 +    assert(instructions == Instruction::number_of_instructions(),
   1.198 +           "shouldn't have created an instructions");
   1.199 +  }
   1.200 +
   1.201 +  _hir->verify();
   1.202 +
   1.203 +#ifndef PRODUCT
   1.204 +  if (PrintCFGToFile) {
   1.205 +    CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false);
   1.206 +  }
   1.207 +#endif
   1.208 +
   1.209 +  if (RangeCheckElimination) {
   1.210 +    if (_hir->osr_entry() == NULL) {
   1.211 +      PhaseTraceTime timeit(_t_rangeCheckElimination);
   1.212 +      RangeCheckElimination::eliminate(_hir);
   1.213 +    }
   1.214 +  }
   1.215 +
   1.216 +#ifndef PRODUCT
   1.217 +  if (PrintCFGToFile) {
   1.218 +    CFGPrinter::print_cfg(_hir, "After RangeCheckElimination", true, false);
   1.219 +  }
   1.220 +#endif
   1.221 +
   1.222 +  if (UseC1Optimizations) {
   1.223 +    // loop invariant code motion reorders instructions and range
   1.224 +    // check elimination adds new instructions so do null check
   1.225 +    // elimination after.
   1.226 +    NEEDS_CLEANUP
   1.227 +    // optimization
   1.228 +    PhaseTraceTime timeit(_t_optimize_null_checks);
   1.229 +
   1.230 +    _hir->eliminate_null_checks();
   1.231 +  }
   1.232 +
   1.233 +  _hir->verify();
   1.234 +
   1.235 +  // compute use counts after global value numbering
   1.236 +  _hir->compute_use_counts();
   1.237 +
   1.238 +#ifndef PRODUCT
   1.239 +  if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); }
   1.240 +  if (PrintIR  || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); }
   1.241 +#endif
   1.242 +
   1.243 +  _hir->verify();
   1.244 +}
   1.245 +
   1.246 +
   1.247 +void Compilation::emit_lir() {
   1.248 +  CHECK_BAILOUT();
   1.249 +
   1.250 +  LIRGenerator gen(this, method());
   1.251 +  {
   1.252 +    PhaseTraceTime timeit(_t_lirGeneration);
   1.253 +    hir()->iterate_linear_scan_order(&gen);
   1.254 +  }
   1.255 +
   1.256 +  CHECK_BAILOUT();
   1.257 +
   1.258 +  {
   1.259 +    PhaseTraceTime timeit(_t_linearScan);
   1.260 +
   1.261 +    LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
   1.262 +    set_allocator(allocator);
   1.263 +    // Assign physical registers to LIR operands using a linear scan algorithm.
   1.264 +    allocator->do_linear_scan();
   1.265 +    CHECK_BAILOUT();
   1.266 +
   1.267 +    _max_spills = allocator->max_spills();
   1.268 +  }
   1.269 +
   1.270 +  if (BailoutAfterLIR) {
   1.271 +    if (PrintLIR && !bailed_out()) {
   1.272 +      print_LIR(hir()->code());
   1.273 +    }
   1.274 +    bailout("Bailing out because of -XX:+BailoutAfterLIR");
   1.275 +  }
   1.276 +}
   1.277 +
   1.278 +
   1.279 +void Compilation::emit_code_epilog(LIR_Assembler* assembler) {
   1.280 +  CHECK_BAILOUT();
   1.281 +
   1.282 +  CodeOffsets* code_offsets = assembler->offsets();
   1.283 +
   1.284 +  // generate code or slow cases
   1.285 +  assembler->emit_slow_case_stubs();
   1.286 +  CHECK_BAILOUT();
   1.287 +
   1.288 +  // generate exception adapters
   1.289 +  assembler->emit_exception_entries(exception_info_list());
   1.290 +  CHECK_BAILOUT();
   1.291 +
   1.292 +  // Generate code for exception handler.
   1.293 +  code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler());
   1.294 +  CHECK_BAILOUT();
   1.295 +
   1.296 +  // Generate code for deopt handler.
   1.297 +  code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler());
   1.298 +  CHECK_BAILOUT();
   1.299 +
   1.300 +  // Emit the MethodHandle deopt handler code (if required).
   1.301 +  if (has_method_handle_invokes()) {
   1.302 +    // We can use the same code as for the normal deopt handler, we
   1.303 +    // just need a different entry point address.
   1.304 +    code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler());
   1.305 +    CHECK_BAILOUT();
   1.306 +  }
   1.307 +
   1.308 +  // Emit the handler to remove the activation from the stack and
   1.309 +  // dispatch to the caller.
   1.310 +  offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler());
   1.311 +
   1.312 +  // done
   1.313 +  masm()->flush();
   1.314 +}
   1.315 +
   1.316 +
   1.317 +bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) {
   1.318 +  // Preinitialize the consts section to some large size:
   1.319 +  int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo));
   1.320 +  char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
   1.321 +  code->insts()->initialize_shared_locs((relocInfo*)locs_buffer,
   1.322 +                                        locs_buffer_size / sizeof(relocInfo));
   1.323 +  code->initialize_consts_size(Compilation::desired_max_constant_size());
   1.324 +  // Call stubs + two deopt handlers (regular and MH) + exception handler
   1.325 +  int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size) +
   1.326 +                   LIR_Assembler::exception_handler_size +
   1.327 +                   (2 * LIR_Assembler::deopt_handler_size);
   1.328 +  if (stub_size >= code->insts_capacity()) return false;
   1.329 +  code->initialize_stubs_size(stub_size);
   1.330 +  return true;
   1.331 +}
   1.332 +
   1.333 +
   1.334 +int Compilation::emit_code_body() {
   1.335 +  // emit code
   1.336 +  if (!setup_code_buffer(code(), allocator()->num_calls())) {
   1.337 +    BAILOUT_("size requested greater than avail code buffer size", 0);
   1.338 +  }
   1.339 +  code()->initialize_oop_recorder(env()->oop_recorder());
   1.340 +
   1.341 +  _masm = new C1_MacroAssembler(code());
   1.342 +  _masm->set_oop_recorder(env()->oop_recorder());
   1.343 +
   1.344 +  LIR_Assembler lir_asm(this);
   1.345 +
   1.346 +  lir_asm.emit_code(hir()->code());
   1.347 +  CHECK_BAILOUT_(0);
   1.348 +
   1.349 +  emit_code_epilog(&lir_asm);
   1.350 +  CHECK_BAILOUT_(0);
   1.351 +
   1.352 +  generate_exception_handler_table();
   1.353 +
   1.354 +#ifndef PRODUCT
   1.355 +  if (PrintExceptionHandlers && Verbose) {
   1.356 +    exception_handler_table()->print();
   1.357 +  }
   1.358 +#endif /* PRODUCT */
   1.359 +
   1.360 +  return frame_map()->framesize();
   1.361 +}
   1.362 +
   1.363 +
   1.364 +int Compilation::compile_java_method() {
   1.365 +  assert(!method()->is_native(), "should not reach here");
   1.366 +
   1.367 +  if (BailoutOnExceptionHandlers) {
   1.368 +    if (method()->has_exception_handlers()) {
   1.369 +      bailout("linear scan can't handle exception handlers");
   1.370 +    }
   1.371 +  }
   1.372 +
   1.373 +  CHECK_BAILOUT_(no_frame_size);
   1.374 +
   1.375 +  if (is_profiling() && !method()->ensure_method_data()) {
   1.376 +    BAILOUT_("mdo allocation failed", no_frame_size);
   1.377 +  }
   1.378 +
   1.379 +  {
   1.380 +    PhaseTraceTime timeit(_t_buildIR);
   1.381 +    build_hir();
   1.382 +  }
   1.383 +  if (BailoutAfterHIR) {
   1.384 +    BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size);
   1.385 +  }
   1.386 +
   1.387 +
   1.388 +  {
   1.389 +    PhaseTraceTime timeit(_t_emit_lir);
   1.390 +
   1.391 +    _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack()));
   1.392 +    emit_lir();
   1.393 +  }
   1.394 +  CHECK_BAILOUT_(no_frame_size);
   1.395 +
   1.396 +  {
   1.397 +    PhaseTraceTime timeit(_t_codeemit);
   1.398 +    return emit_code_body();
   1.399 +  }
   1.400 +}
   1.401 +
   1.402 +void Compilation::install_code(int frame_size) {
   1.403 +  // frame_size is in 32-bit words so adjust it intptr_t words
   1.404 +  assert(frame_size == frame_map()->framesize(), "must match");
   1.405 +  assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
   1.406 +  _env->register_method(
   1.407 +    method(),
   1.408 +    osr_bci(),
   1.409 +    &_offsets,
   1.410 +    in_bytes(_frame_map->sp_offset_for_orig_pc()),
   1.411 +    code(),
   1.412 +    in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
   1.413 +    debug_info_recorder()->_oopmaps,
   1.414 +    exception_handler_table(),
   1.415 +    implicit_exception_table(),
   1.416 +    compiler(),
   1.417 +    _env->comp_level(),
   1.418 +    has_unsafe_access(),
   1.419 +    SharedRuntime::is_wide_vector(max_vector_size())
   1.420 +  );
   1.421 +}
   1.422 +
   1.423 +
   1.424 +void Compilation::compile_method() {
   1.425 +  // setup compilation
   1.426 +  initialize();
   1.427 +
   1.428 +  if (!method()->can_be_compiled()) {
   1.429 +    // Prevent race condition 6328518.
   1.430 +    // This can happen if the method is obsolete or breakpointed.
   1.431 +    bailout("Bailing out because method is not compilable");
   1.432 +    return;
   1.433 +  }
   1.434 +
   1.435 +  if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
   1.436 +    // We can assert evol_method because method->can_be_compiled is true.
   1.437 +    dependency_recorder()->assert_evol_method(method());
   1.438 +  }
   1.439 +
   1.440 +  if (method()->break_at_execute()) {
   1.441 +    BREAKPOINT;
   1.442 +  }
   1.443 +
   1.444 +#ifndef PRODUCT
   1.445 +  if (PrintCFGToFile) {
   1.446 +    CFGPrinter::print_compilation(this);
   1.447 +  }
   1.448 +#endif
   1.449 +
   1.450 +  // compile method
   1.451 +  int frame_size = compile_java_method();
   1.452 +
   1.453 +  // bailout if method couldn't be compiled
   1.454 +  // Note: make sure we mark the method as not compilable!
   1.455 +  CHECK_BAILOUT();
   1.456 +
   1.457 +  if (InstallMethods) {
   1.458 +    // install code
   1.459 +    PhaseTraceTime timeit(_t_codeinstall);
   1.460 +    install_code(frame_size);
   1.461 +  }
   1.462 +
   1.463 +  if (log() != NULL) // Print code cache state into compiler log
   1.464 +    log()->code_cache_state();
   1.465 +
   1.466 +  totalInstructionNodes += Instruction::number_of_instructions();
   1.467 +}
   1.468 +
   1.469 +
   1.470 +void Compilation::generate_exception_handler_table() {
   1.471 +  // Generate an ExceptionHandlerTable from the exception handler
   1.472 +  // information accumulated during the compilation.
   1.473 +  ExceptionInfoList* info_list = exception_info_list();
   1.474 +
   1.475 +  if (info_list->length() == 0) {
   1.476 +    return;
   1.477 +  }
   1.478 +
   1.479 +  // allocate some arrays for use by the collection code.
   1.480 +  const int num_handlers = 5;
   1.481 +  GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
   1.482 +  GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
   1.483 +  GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
   1.484 +
   1.485 +  for (int i = 0; i < info_list->length(); i++) {
   1.486 +    ExceptionInfo* info = info_list->at(i);
   1.487 +    XHandlers* handlers = info->exception_handlers();
   1.488 +
   1.489 +    // empty the arrays
   1.490 +    bcis->trunc_to(0);
   1.491 +    scope_depths->trunc_to(0);
   1.492 +    pcos->trunc_to(0);
   1.493 +
   1.494 +    for (int i = 0; i < handlers->length(); i++) {
   1.495 +      XHandler* handler = handlers->handler_at(i);
   1.496 +      assert(handler->entry_pco() != -1, "must have been generated");
   1.497 +
   1.498 +      int e = bcis->find(handler->handler_bci());
   1.499 +      if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
   1.500 +        // two different handlers are declared to dispatch to the same
   1.501 +        // catch bci.  During parsing we created edges for each
   1.502 +        // handler but we really only need one.  The exception handler
   1.503 +        // table will also get unhappy if we try to declare both since
   1.504 +        // it's nonsensical.  Just skip this handler.
   1.505 +        continue;
   1.506 +      }
   1.507 +
   1.508 +      bcis->append(handler->handler_bci());
   1.509 +      if (handler->handler_bci() == -1) {
   1.510 +        // insert a wildcard handler at scope depth 0 so that the
   1.511 +        // exception lookup logic with find it.
   1.512 +        scope_depths->append(0);
   1.513 +      } else {
   1.514 +        scope_depths->append(handler->scope_count());
   1.515 +    }
   1.516 +      pcos->append(handler->entry_pco());
   1.517 +
   1.518 +      // stop processing once we hit a catch any
   1.519 +      if (handler->is_catch_all()) {
   1.520 +        assert(i == handlers->length() - 1, "catch all must be last handler");
   1.521 +  }
   1.522 +    }
   1.523 +    exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
   1.524 +  }
   1.525 +}
   1.526 +
   1.527 +
   1.528 +Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,
   1.529 +                         int osr_bci, BufferBlob* buffer_blob)
   1.530 +: _compiler(compiler)
   1.531 +, _env(env)
   1.532 +, _log(env->log())
   1.533 +, _method(method)
   1.534 +, _osr_bci(osr_bci)
   1.535 +, _hir(NULL)
   1.536 +, _max_spills(-1)
   1.537 +, _frame_map(NULL)
   1.538 +, _masm(NULL)
   1.539 +, _has_exception_handlers(false)
   1.540 +, _has_fpu_code(true)   // pessimistic assumption
   1.541 +, _would_profile(false)
   1.542 +, _has_unsafe_access(false)
   1.543 +, _has_method_handle_invokes(false)
   1.544 +, _bailout_msg(NULL)
   1.545 +, _exception_info_list(NULL)
   1.546 +, _allocator(NULL)
   1.547 +, _next_id(0)
   1.548 +, _next_block_id(0)
   1.549 +, _code(buffer_blob)
   1.550 +, _has_access_indexed(false)
   1.551 +, _current_instruction(NULL)
   1.552 +, _interpreter_frame_size(0)
   1.553 +#ifndef PRODUCT
   1.554 +, _last_instruction_printed(NULL)
   1.555 +#endif // PRODUCT
   1.556 +{
   1.557 +  PhaseTraceTime timeit(_t_compile);
   1.558 +  _arena = Thread::current()->resource_area();
   1.559 +  _env->set_compiler_data(this);
   1.560 +  _exception_info_list = new ExceptionInfoList();
   1.561 +  _implicit_exception_table.set_size(0);
   1.562 +  compile_method();
   1.563 +  if (bailed_out()) {
   1.564 +    _env->record_method_not_compilable(bailout_msg(), !TieredCompilation);
   1.565 +    if (is_profiling()) {
   1.566 +      // Compilation failed, create MDO, which would signal the interpreter
   1.567 +      // to start profiling on its own.
   1.568 +      _method->ensure_method_data();
   1.569 +    }
   1.570 +  } else if (is_profiling()) {
   1.571 +    ciMethodData *md = method->method_data_or_null();
   1.572 +    if (md != NULL) {
   1.573 +      md->set_would_profile(_would_profile);
   1.574 +    }
   1.575 +  }
   1.576 +}
   1.577 +
   1.578 +Compilation::~Compilation() {
   1.579 +  _env->set_compiler_data(NULL);
   1.580 +}
   1.581 +
   1.582 +
   1.583 +void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) {
   1.584 +#ifndef PRODUCT
   1.585 +  if (PrintExceptionHandlers && Verbose) {
   1.586 +    tty->print_cr("  added exception scope for pco %d", pco);
   1.587 +  }
   1.588 +#endif
   1.589 +  // Note: we do not have program counters for these exception handlers yet
   1.590 +  exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
   1.591 +}
   1.592 +
   1.593 +
   1.594 +void Compilation::notice_inlined_method(ciMethod* method) {
   1.595 +  _env->notice_inlined_method(method);
   1.596 +}
   1.597 +
   1.598 +
   1.599 +void Compilation::bailout(const char* msg) {
   1.600 +  assert(msg != NULL, "bailout message must exist");
   1.601 +  if (!bailed_out()) {
   1.602 +    // keep first bailout message
   1.603 +    if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
   1.604 +    _bailout_msg = msg;
   1.605 +  }
   1.606 +}
   1.607 +
   1.608 +ciKlass* Compilation::cha_exact_type(ciType* type) {
   1.609 +  if (type != NULL && type->is_loaded() && type->is_instance_klass()) {
   1.610 +    ciInstanceKlass* ik = type->as_instance_klass();
   1.611 +    assert(ik->exact_klass() == NULL, "no cha for final klass");
   1.612 +    if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
   1.613 +      dependency_recorder()->assert_leaf_type(ik);
   1.614 +      return ik;
   1.615 +    }
   1.616 +  }
   1.617 +  return NULL;
   1.618 +}
   1.619 +
   1.620 +void Compilation::print_timers() {
   1.621 +  // 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);
   1.622 +  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();
   1.623 +
   1.624 +
   1.625 +  tty->print_cr("    Detailed C1 Timings");
   1.626 +  tty->print_cr("       Setup time:        %6.3f s (%4.1f%%)",    timers[_t_setup].seconds(),           (timers[_t_setup].seconds() / total) * 100.0);
   1.627 +  tty->print_cr("       Build IR:          %6.3f s (%4.1f%%)",    timers[_t_buildIR].seconds(),         (timers[_t_buildIR].seconds() / total) * 100.0);
   1.628 +  float t_optimizeIR = timers[_t_optimize_blocks].seconds() + timers[_t_optimize_null_checks].seconds();
   1.629 +  tty->print_cr("         Optimize:           %6.3f s (%4.1f%%)", t_optimizeIR,                         (t_optimizeIR / total) * 100.0);
   1.630 +  tty->print_cr("         RCE:                %6.3f s (%4.1f%%)", timers[_t_rangeCheckElimination].seconds(),      (timers[_t_rangeCheckElimination].seconds() / total) * 100.0);
   1.631 +  tty->print_cr("       Emit LIR:          %6.3f s (%4.1f%%)",    timers[_t_emit_lir].seconds(),        (timers[_t_emit_lir].seconds() / total) * 100.0);
   1.632 +  tty->print_cr("         LIR Gen:          %6.3f s (%4.1f%%)",   timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0);
   1.633 +  tty->print_cr("         Linear Scan:      %6.3f s (%4.1f%%)",   timers[_t_linearScan].seconds(),    (timers[_t_linearScan].seconds() / total) * 100.0);
   1.634 +  NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
   1.635 +  tty->print_cr("       LIR Schedule:      %6.3f s (%4.1f%%)",    timers[_t_lir_schedule].seconds(),  (timers[_t_lir_schedule].seconds() / total) * 100.0);
   1.636 +  tty->print_cr("       Code Emission:     %6.3f s (%4.1f%%)",    timers[_t_codeemit].seconds(),        (timers[_t_codeemit].seconds() / total) * 100.0);
   1.637 +  tty->print_cr("       Code Installation: %6.3f s (%4.1f%%)",    timers[_t_codeinstall].seconds(),     (timers[_t_codeinstall].seconds() / total) * 100.0);
   1.638 +  tty->print_cr("       Instruction Nodes: %6d nodes",    totalInstructionNodes);
   1.639 +
   1.640 +  NOT_PRODUCT(LinearScan::print_statistics());
   1.641 +}
   1.642 +
   1.643 +
   1.644 +#ifndef PRODUCT
   1.645 +void Compilation::compile_only_this_method() {
   1.646 +  ResourceMark rm;
   1.647 +  fileStream stream(fopen("c1_compile_only", "wt"));
   1.648 +  stream.print_cr("# c1 compile only directives");
   1.649 +  compile_only_this_scope(&stream, hir()->top_scope());
   1.650 +}
   1.651 +
   1.652 +
   1.653 +void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
   1.654 +  st->print("CompileOnly=");
   1.655 +  scope->method()->holder()->name()->print_symbol_on(st);
   1.656 +  st->print(".");
   1.657 +  scope->method()->name()->print_symbol_on(st);
   1.658 +  st->cr();
   1.659 +}
   1.660 +
   1.661 +
   1.662 +void Compilation::exclude_this_method() {
   1.663 +  fileStream stream(fopen(".hotspot_compiler", "at"));
   1.664 +  stream.print("exclude ");
   1.665 +  method()->holder()->name()->print_symbol_on(&stream);
   1.666 +  stream.print(" ");
   1.667 +  method()->name()->print_symbol_on(&stream);
   1.668 +  stream.cr();
   1.669 +  stream.cr();
   1.670 +}
   1.671 +#endif

mercurial