aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "c1/c1_CFGPrinter.hpp" aoqi@0: #include "c1/c1_Compilation.hpp" aoqi@0: #include "c1/c1_IR.hpp" aoqi@0: #include "c1/c1_LIRAssembler.hpp" aoqi@0: #include "c1/c1_LinearScan.hpp" aoqi@0: #include "c1/c1_MacroAssembler.hpp" aoqi@0: #include "c1/c1_ValueMap.hpp" aoqi@0: #include "c1/c1_ValueStack.hpp" aoqi@0: #include "code/debugInfoRec.hpp" aoqi@0: #include "compiler/compileLog.hpp" aoqi@0: #include "c1/c1_RangeCheckElimination.hpp" aoqi@0: aoqi@0: aoqi@0: typedef enum { aoqi@0: _t_compile, aoqi@0: _t_setup, aoqi@0: _t_buildIR, aoqi@0: _t_optimize_blocks, aoqi@0: _t_optimize_null_checks, aoqi@0: _t_rangeCheckElimination, aoqi@0: _t_emit_lir, aoqi@0: _t_linearScan, aoqi@0: _t_lirGeneration, aoqi@0: _t_lir_schedule, aoqi@0: _t_codeemit, aoqi@0: _t_codeinstall, aoqi@0: max_phase_timers aoqi@0: } TimerName; aoqi@0: aoqi@0: static const char * timer_name[] = { aoqi@0: "compile", aoqi@0: "setup", aoqi@0: "buildIR", aoqi@0: "optimize_blocks", aoqi@0: "optimize_null_checks", aoqi@0: "rangeCheckElimination", aoqi@0: "emit_lir", aoqi@0: "linearScan", aoqi@0: "lirGeneration", aoqi@0: "lir_schedule", aoqi@0: "codeemit", aoqi@0: "codeinstall" aoqi@0: }; aoqi@0: aoqi@0: static elapsedTimer timers[max_phase_timers]; aoqi@0: static int totalInstructionNodes = 0; aoqi@0: aoqi@0: class PhaseTraceTime: public TraceTime { aoqi@0: private: aoqi@0: JavaThread* _thread; aoqi@0: CompileLog* _log; aoqi@0: TimerName _timer; aoqi@0: aoqi@0: public: aoqi@0: PhaseTraceTime(TimerName timer) aoqi@0: : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose), aoqi@0: _log(NULL), _timer(timer) aoqi@0: { aoqi@0: if (Compilation::current() != NULL) { aoqi@0: _log = Compilation::current()->log(); aoqi@0: } aoqi@0: aoqi@0: if (_log != NULL) { aoqi@0: _log->begin_head("phase name='%s'", timer_name[_timer]); aoqi@0: _log->stamp(); aoqi@0: _log->end_head(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: ~PhaseTraceTime() { aoqi@0: if (_log != NULL) aoqi@0: _log->done("phase name='%s'", timer_name[_timer]); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // Implementation of Compilation aoqi@0: aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void Compilation::maybe_print_current_instruction() { aoqi@0: if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) { aoqi@0: _last_instruction_printed = _current_instruction; aoqi@0: _current_instruction->print_line(); aoqi@0: } aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: aoqi@0: aoqi@0: DebugInformationRecorder* Compilation::debug_info_recorder() const { aoqi@0: return _env->debug_info(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: Dependencies* Compilation::dependency_recorder() const { aoqi@0: return _env->dependencies(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::initialize() { aoqi@0: // Use an oop recorder bound to the CI environment. aoqi@0: // (The default oop recorder is ignorant of the CI.) aoqi@0: OopRecorder* ooprec = new OopRecorder(_env->arena()); aoqi@0: _env->set_oop_recorder(ooprec); aoqi@0: _env->set_debug_info(new DebugInformationRecorder(ooprec)); aoqi@0: debug_info_recorder()->set_oopmaps(new OopMapSet()); aoqi@0: _env->set_dependencies(new Dependencies(_env)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::build_hir() { aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: // setup ir aoqi@0: CompileLog* log = this->log(); aoqi@0: if (log != NULL) { aoqi@0: log->begin_head("parse method='%d' ", aoqi@0: log->identify(_method)); aoqi@0: log->stamp(); aoqi@0: log->end_head(); aoqi@0: } aoqi@0: _hir = new IR(this, method(), osr_bci()); aoqi@0: if (log) log->done("parse"); aoqi@0: if (!_hir->is_valid()) { aoqi@0: bailout("invalid parsing"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFGToFile) { aoqi@0: CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); } aoqi@0: if (PrintIR || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); } aoqi@0: #endif aoqi@0: aoqi@0: _hir->verify(); aoqi@0: aoqi@0: if (UseC1Optimizations) { aoqi@0: NEEDS_CLEANUP aoqi@0: // optimization aoqi@0: PhaseTraceTime timeit(_t_optimize_blocks); aoqi@0: aoqi@0: _hir->optimize_blocks(); aoqi@0: } aoqi@0: aoqi@0: _hir->verify(); aoqi@0: aoqi@0: _hir->split_critical_edges(); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); } aoqi@0: if (PrintIR || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); } aoqi@0: #endif aoqi@0: aoqi@0: _hir->verify(); aoqi@0: aoqi@0: // compute block ordering for code generation aoqi@0: // the control flow must not be changed from here on aoqi@0: _hir->compute_code(); aoqi@0: aoqi@0: if (UseGlobalValueNumbering) { aoqi@0: // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects. aoqi@0: int instructions = Instruction::number_of_instructions(); aoqi@0: GlobalValueNumbering gvn(_hir); aoqi@0: assert(instructions == Instruction::number_of_instructions(), aoqi@0: "shouldn't have created an instructions"); aoqi@0: } aoqi@0: aoqi@0: _hir->verify(); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFGToFile) { aoqi@0: CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: if (RangeCheckElimination) { aoqi@0: if (_hir->osr_entry() == NULL) { aoqi@0: PhaseTraceTime timeit(_t_rangeCheckElimination); aoqi@0: RangeCheckElimination::eliminate(_hir); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFGToFile) { aoqi@0: CFGPrinter::print_cfg(_hir, "After RangeCheckElimination", true, false); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: if (UseC1Optimizations) { aoqi@0: // loop invariant code motion reorders instructions and range aoqi@0: // check elimination adds new instructions so do null check aoqi@0: // elimination after. aoqi@0: NEEDS_CLEANUP aoqi@0: // optimization aoqi@0: PhaseTraceTime timeit(_t_optimize_null_checks); aoqi@0: aoqi@0: _hir->eliminate_null_checks(); aoqi@0: } aoqi@0: aoqi@0: _hir->verify(); aoqi@0: aoqi@0: // compute use counts after global value numbering aoqi@0: _hir->compute_use_counts(); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); } aoqi@0: if (PrintIR || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); } aoqi@0: #endif aoqi@0: aoqi@0: _hir->verify(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::emit_lir() { aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: LIRGenerator gen(this, method()); aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_lirGeneration); aoqi@0: hir()->iterate_linear_scan_order(&gen); aoqi@0: } aoqi@0: aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_linearScan); aoqi@0: aoqi@0: LinearScan* allocator = new LinearScan(hir(), &gen, frame_map()); aoqi@0: set_allocator(allocator); aoqi@0: // Assign physical registers to LIR operands using a linear scan algorithm. aoqi@0: allocator->do_linear_scan(); aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: _max_spills = allocator->max_spills(); aoqi@0: } aoqi@0: aoqi@0: if (BailoutAfterLIR) { aoqi@0: if (PrintLIR && !bailed_out()) { aoqi@0: print_LIR(hir()->code()); aoqi@0: } aoqi@0: bailout("Bailing out because of -XX:+BailoutAfterLIR"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::emit_code_epilog(LIR_Assembler* assembler) { aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: CodeOffsets* code_offsets = assembler->offsets(); aoqi@0: aoqi@0: // generate code or slow cases aoqi@0: assembler->emit_slow_case_stubs(); aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: // generate exception adapters aoqi@0: assembler->emit_exception_entries(exception_info_list()); aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: // Generate code for exception handler. aoqi@0: code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler()); aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: // Generate code for deopt handler. aoqi@0: code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler()); aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: // Emit the MethodHandle deopt handler code (if required). aoqi@0: if (has_method_handle_invokes()) { aoqi@0: // We can use the same code as for the normal deopt handler, we aoqi@0: // just need a different entry point address. aoqi@0: code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler()); aoqi@0: CHECK_BAILOUT(); aoqi@0: } aoqi@0: aoqi@0: // Emit the handler to remove the activation from the stack and aoqi@0: // dispatch to the caller. aoqi@0: offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler()); aoqi@0: aoqi@0: // done aoqi@0: masm()->flush(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) { aoqi@0: // Preinitialize the consts section to some large size: aoqi@0: int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo)); aoqi@0: char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); aoqi@0: code->insts()->initialize_shared_locs((relocInfo*)locs_buffer, aoqi@0: locs_buffer_size / sizeof(relocInfo)); aoqi@0: code->initialize_consts_size(Compilation::desired_max_constant_size()); aoqi@0: // Call stubs + two deopt handlers (regular and MH) + exception handler aoqi@0: int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size) + aoqi@0: LIR_Assembler::exception_handler_size + aoqi@0: (2 * LIR_Assembler::deopt_handler_size); aoqi@0: if (stub_size >= code->insts_capacity()) return false; aoqi@0: code->initialize_stubs_size(stub_size); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Compilation::emit_code_body() { aoqi@0: // emit code aoqi@0: if (!setup_code_buffer(code(), allocator()->num_calls())) { aoqi@0: BAILOUT_("size requested greater than avail code buffer size", 0); aoqi@0: } aoqi@0: code()->initialize_oop_recorder(env()->oop_recorder()); aoqi@0: aoqi@0: _masm = new C1_MacroAssembler(code()); aoqi@0: _masm->set_oop_recorder(env()->oop_recorder()); aoqi@0: aoqi@0: LIR_Assembler lir_asm(this); aoqi@0: aoqi@0: lir_asm.emit_code(hir()->code()); aoqi@0: CHECK_BAILOUT_(0); aoqi@0: aoqi@0: emit_code_epilog(&lir_asm); aoqi@0: CHECK_BAILOUT_(0); aoqi@0: aoqi@0: generate_exception_handler_table(); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintExceptionHandlers && Verbose) { aoqi@0: exception_handler_table()->print(); aoqi@0: } aoqi@0: #endif /* PRODUCT */ aoqi@0: aoqi@0: return frame_map()->framesize(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Compilation::compile_java_method() { aoqi@0: assert(!method()->is_native(), "should not reach here"); aoqi@0: aoqi@0: if (BailoutOnExceptionHandlers) { aoqi@0: if (method()->has_exception_handlers()) { aoqi@0: bailout("linear scan can't handle exception handlers"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: CHECK_BAILOUT_(no_frame_size); aoqi@0: aoqi@0: if (is_profiling() && !method()->ensure_method_data()) { aoqi@0: BAILOUT_("mdo allocation failed", no_frame_size); aoqi@0: } aoqi@0: aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_buildIR); aoqi@0: build_hir(); aoqi@0: } aoqi@0: if (BailoutAfterHIR) { aoqi@0: BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_emit_lir); aoqi@0: aoqi@0: _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack())); aoqi@0: emit_lir(); aoqi@0: } aoqi@0: CHECK_BAILOUT_(no_frame_size); aoqi@0: aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_codeemit); aoqi@0: return emit_code_body(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void Compilation::install_code(int frame_size) { aoqi@0: // frame_size is in 32-bit words so adjust it intptr_t words aoqi@0: assert(frame_size == frame_map()->framesize(), "must match"); aoqi@0: assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned"); aoqi@0: _env->register_method( aoqi@0: method(), aoqi@0: osr_bci(), aoqi@0: &_offsets, aoqi@0: in_bytes(_frame_map->sp_offset_for_orig_pc()), aoqi@0: code(), aoqi@0: in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t), aoqi@0: debug_info_recorder()->_oopmaps, aoqi@0: exception_handler_table(), aoqi@0: implicit_exception_table(), aoqi@0: compiler(), aoqi@0: _env->comp_level(), aoqi@0: has_unsafe_access(), aoqi@0: SharedRuntime::is_wide_vector(max_vector_size()) aoqi@0: ); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::compile_method() { aoqi@0: // setup compilation aoqi@0: initialize(); aoqi@0: aoqi@0: if (!method()->can_be_compiled()) { aoqi@0: // Prevent race condition 6328518. aoqi@0: // This can happen if the method is obsolete or breakpointed. aoqi@0: bailout("Bailing out because method is not compilable"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (_env->jvmti_can_hotswap_or_post_breakpoint()) { aoqi@0: // We can assert evol_method because method->can_be_compiled is true. aoqi@0: dependency_recorder()->assert_evol_method(method()); aoqi@0: } aoqi@0: aoqi@0: if (method()->break_at_execute()) { aoqi@0: BREAKPOINT; aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintCFGToFile) { aoqi@0: CFGPrinter::print_compilation(this); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // compile method aoqi@0: int frame_size = compile_java_method(); aoqi@0: aoqi@0: // bailout if method couldn't be compiled aoqi@0: // Note: make sure we mark the method as not compilable! aoqi@0: CHECK_BAILOUT(); aoqi@0: aoqi@0: if (InstallMethods) { aoqi@0: // install code aoqi@0: PhaseTraceTime timeit(_t_codeinstall); aoqi@0: install_code(frame_size); aoqi@0: } aoqi@0: aoqi@0: if (log() != NULL) // Print code cache state into compiler log aoqi@0: log()->code_cache_state(); aoqi@0: aoqi@0: totalInstructionNodes += Instruction::number_of_instructions(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::generate_exception_handler_table() { aoqi@0: // Generate an ExceptionHandlerTable from the exception handler aoqi@0: // information accumulated during the compilation. aoqi@0: ExceptionInfoList* info_list = exception_info_list(); aoqi@0: aoqi@0: if (info_list->length() == 0) { aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // allocate some arrays for use by the collection code. aoqi@0: const int num_handlers = 5; aoqi@0: GrowableArray* bcis = new GrowableArray(num_handlers); aoqi@0: GrowableArray* scope_depths = new GrowableArray(num_handlers); aoqi@0: GrowableArray* pcos = new GrowableArray(num_handlers); aoqi@0: aoqi@0: for (int i = 0; i < info_list->length(); i++) { aoqi@0: ExceptionInfo* info = info_list->at(i); aoqi@0: XHandlers* handlers = info->exception_handlers(); aoqi@0: aoqi@0: // empty the arrays aoqi@0: bcis->trunc_to(0); aoqi@0: scope_depths->trunc_to(0); aoqi@0: pcos->trunc_to(0); aoqi@0: aoqi@0: for (int i = 0; i < handlers->length(); i++) { aoqi@0: XHandler* handler = handlers->handler_at(i); aoqi@0: assert(handler->entry_pco() != -1, "must have been generated"); aoqi@0: aoqi@0: int e = bcis->find(handler->handler_bci()); aoqi@0: if (e >= 0 && scope_depths->at(e) == handler->scope_count()) { aoqi@0: // two different handlers are declared to dispatch to the same aoqi@0: // catch bci. During parsing we created edges for each aoqi@0: // handler but we really only need one. The exception handler aoqi@0: // table will also get unhappy if we try to declare both since aoqi@0: // it's nonsensical. Just skip this handler. aoqi@0: continue; aoqi@0: } aoqi@0: aoqi@0: bcis->append(handler->handler_bci()); aoqi@0: if (handler->handler_bci() == -1) { aoqi@0: // insert a wildcard handler at scope depth 0 so that the aoqi@0: // exception lookup logic with find it. aoqi@0: scope_depths->append(0); aoqi@0: } else { aoqi@0: scope_depths->append(handler->scope_count()); aoqi@0: } aoqi@0: pcos->append(handler->entry_pco()); aoqi@0: aoqi@0: // stop processing once we hit a catch any aoqi@0: if (handler->is_catch_all()) { aoqi@0: assert(i == handlers->length() - 1, "catch all must be last handler"); aoqi@0: } aoqi@0: } aoqi@0: exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, aoqi@0: int osr_bci, BufferBlob* buffer_blob) aoqi@0: : _compiler(compiler) aoqi@0: , _env(env) aoqi@0: , _log(env->log()) aoqi@0: , _method(method) aoqi@0: , _osr_bci(osr_bci) aoqi@0: , _hir(NULL) aoqi@0: , _max_spills(-1) aoqi@0: , _frame_map(NULL) aoqi@0: , _masm(NULL) aoqi@0: , _has_exception_handlers(false) aoqi@0: , _has_fpu_code(true) // pessimistic assumption aoqi@0: , _would_profile(false) aoqi@0: , _has_unsafe_access(false) aoqi@0: , _has_method_handle_invokes(false) aoqi@0: , _bailout_msg(NULL) aoqi@0: , _exception_info_list(NULL) aoqi@0: , _allocator(NULL) aoqi@0: , _next_id(0) aoqi@0: , _next_block_id(0) aoqi@0: , _code(buffer_blob) aoqi@0: , _has_access_indexed(false) aoqi@0: , _current_instruction(NULL) aoqi@0: , _interpreter_frame_size(0) aoqi@0: #ifndef PRODUCT aoqi@0: , _last_instruction_printed(NULL) aoqi@0: #endif // PRODUCT aoqi@0: { aoqi@0: PhaseTraceTime timeit(_t_compile); aoqi@0: _arena = Thread::current()->resource_area(); aoqi@0: _env->set_compiler_data(this); aoqi@0: _exception_info_list = new ExceptionInfoList(); aoqi@0: _implicit_exception_table.set_size(0); aoqi@0: compile_method(); aoqi@0: if (bailed_out()) { aoqi@0: _env->record_method_not_compilable(bailout_msg(), !TieredCompilation); aoqi@0: if (is_profiling()) { aoqi@0: // Compilation failed, create MDO, which would signal the interpreter aoqi@0: // to start profiling on its own. aoqi@0: _method->ensure_method_data(); aoqi@0: } aoqi@0: } else if (is_profiling()) { aoqi@0: ciMethodData *md = method->method_data_or_null(); aoqi@0: if (md != NULL) { aoqi@0: md->set_would_profile(_would_profile); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Compilation::~Compilation() { aoqi@0: _env->set_compiler_data(NULL); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { aoqi@0: #ifndef PRODUCT aoqi@0: if (PrintExceptionHandlers && Verbose) { aoqi@0: tty->print_cr(" added exception scope for pco %d", pco); aoqi@0: } aoqi@0: #endif aoqi@0: // Note: we do not have program counters for these exception handlers yet aoqi@0: exception_info_list()->push(new ExceptionInfo(pco, exception_handlers)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::notice_inlined_method(ciMethod* method) { aoqi@0: _env->notice_inlined_method(method); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::bailout(const char* msg) { aoqi@0: assert(msg != NULL, "bailout message must exist"); aoqi@0: if (!bailed_out()) { aoqi@0: // keep first bailout message aoqi@0: if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg); aoqi@0: _bailout_msg = msg; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: ciKlass* Compilation::cha_exact_type(ciType* type) { aoqi@0: if (type != NULL && type->is_loaded() && type->is_instance_klass()) { aoqi@0: ciInstanceKlass* ik = type->as_instance_klass(); aoqi@0: assert(ik->exact_klass() == NULL, "no cha for final klass"); aoqi@0: if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) { aoqi@0: dependency_recorder()->assert_leaf_type(ik); aoqi@0: return ik; aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: void Compilation::print_timers() { aoqi@0: // 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); aoqi@0: 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(); aoqi@0: aoqi@0: aoqi@0: tty->print_cr(" Detailed C1 Timings"); aoqi@0: tty->print_cr(" Setup time: %6.3f s (%4.1f%%)", timers[_t_setup].seconds(), (timers[_t_setup].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Build IR: %6.3f s (%4.1f%%)", timers[_t_buildIR].seconds(), (timers[_t_buildIR].seconds() / total) * 100.0); aoqi@0: float t_optimizeIR = timers[_t_optimize_blocks].seconds() + timers[_t_optimize_null_checks].seconds(); aoqi@0: tty->print_cr(" Optimize: %6.3f s (%4.1f%%)", t_optimizeIR, (t_optimizeIR / total) * 100.0); aoqi@0: tty->print_cr(" RCE: %6.3f s (%4.1f%%)", timers[_t_rangeCheckElimination].seconds(), (timers[_t_rangeCheckElimination].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Emit LIR: %6.3f s (%4.1f%%)", timers[_t_emit_lir].seconds(), (timers[_t_emit_lir].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" LIR Gen: %6.3f s (%4.1f%%)", timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Linear Scan: %6.3f s (%4.1f%%)", timers[_t_linearScan].seconds(), (timers[_t_linearScan].seconds() / total) * 100.0); aoqi@0: NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds())); aoqi@0: tty->print_cr(" LIR Schedule: %6.3f s (%4.1f%%)", timers[_t_lir_schedule].seconds(), (timers[_t_lir_schedule].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Code Emission: %6.3f s (%4.1f%%)", timers[_t_codeemit].seconds(), (timers[_t_codeemit].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Code Installation: %6.3f s (%4.1f%%)", timers[_t_codeinstall].seconds(), (timers[_t_codeinstall].seconds() / total) * 100.0); aoqi@0: tty->print_cr(" Instruction Nodes: %6d nodes", totalInstructionNodes); aoqi@0: aoqi@0: NOT_PRODUCT(LinearScan::print_statistics()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void Compilation::compile_only_this_method() { aoqi@0: ResourceMark rm; aoqi@0: fileStream stream(fopen("c1_compile_only", "wt")); aoqi@0: stream.print_cr("# c1 compile only directives"); aoqi@0: compile_only_this_scope(&stream, hir()->top_scope()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) { aoqi@0: st->print("CompileOnly="); aoqi@0: scope->method()->holder()->name()->print_symbol_on(st); aoqi@0: st->print("."); aoqi@0: scope->method()->name()->print_symbol_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Compilation::exclude_this_method() { aoqi@0: fileStream stream(fopen(".hotspot_compiler", "at")); aoqi@0: stream.print("exclude "); aoqi@0: method()->holder()->name()->print_symbol_on(&stream); aoqi@0: stream.print(" "); aoqi@0: method()->name()->print_symbol_on(&stream); aoqi@0: stream.cr(); aoqi@0: stream.cr(); aoqi@0: } aoqi@0: #endif