/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
void Compilation::initialize() { // Use an oop recorder bound to the CI environment. // (The default oop recorder is ignorant of the CI.)
OopRecorder* ooprec = new OopRecorder(_env->arena());
_env->set_oop_recorder(ooprec);
_env->set_debug_info(new DebugInformationRecorder(ooprec));
debug_info_recorder()->set_oopmaps(new OopMapSet());
_env->set_dependencies(new Dependencies(_env));
}
void Compilation::build_hir() {
CHECK_BAILOUT();
// setup ir
CompileLog* log = this->log(); if (log != NULL) {
log->begin_head("parse method='%d' ",
log->identify(_method));
log->stamp();
log->end_head();
}
{
PhaseTraceTime timeit(_t_hir_parse);
_hir = new IR(this, method(), osr_bci());
} if (log) log->done("parse"); if (!_hir->is_valid()) {
bailout("invalid parsing"); return;
}
#ifndef PRODUCT if (PrintCFGToFile) {
CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
} #endif
#ifndef PRODUCT if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); } if (PrintIR || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); } #endif
_hir->verify();
if (UseC1Optimizations) {
NEEDS_CLEANUP // optimization
PhaseTraceTime timeit(_t_optimize_blocks);
_hir->optimize_blocks();
}
_hir->verify();
_hir->split_critical_edges();
#ifndef PRODUCT if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); } if (PrintIR || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); } #endif
_hir->verify();
// compute block ordering for code generation // the control flow must not be changed from here on
_hir->compute_code();
if (UseGlobalValueNumbering) { // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.
PhaseTraceTime timeit(_t_gvn); int instructions = Instruction::number_of_instructions();
GlobalValueNumbering gvn(_hir);
assert(instructions == Instruction::number_of_instructions(), "shouldn't have created an instructions");
}
if (UseC1Optimizations) { // loop invariant code motion reorders instructions and range // check elimination adds new instructions so do null check // elimination after.
NEEDS_CLEANUP // optimization
PhaseTraceTime timeit(_t_optimize_null_checks);
_hir->eliminate_null_checks();
}
_hir->verify();
// compute use counts after global value numbering
_hir->compute_use_counts();
#ifndef PRODUCT if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); } if (PrintIR || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); } #endif
LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
set_allocator(allocator); // Assign physical registers to LIR operands using a linear scan algorithm.
allocator->do_linear_scan();
CHECK_BAILOUT();
_max_spills = allocator->max_spills();
}
if (BailoutAfterLIR) { if (PrintLIR && !bailed_out()) {
print_LIR(hir()->code());
}
bailout("Bailing out because of -XX:+BailoutAfterLIR");
}
}
// Generate code for exception handler.
code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler());
CHECK_BAILOUT();
// Generate code for deopt handler.
code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler());
CHECK_BAILOUT();
// Emit the MethodHandle deopt handler code (if required). if (has_method_handle_invokes()) { // We can use the same code as for the normal deopt handler, we // just need a different entry point address.
code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler());
CHECK_BAILOUT();
}
// Emit the handler to remove the activation from the stack and // dispatch to the caller.
offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler());
// done
masm()->flush();
}
bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) { // Preinitialize the consts section to some large size: int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo)); char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
code->insts()->initialize_shared_locs((relocInfo*)locs_buffer,
locs_buffer_size / sizeof(relocInfo));
code->initialize_consts_size(Compilation::desired_max_constant_size()); // Call stubs + two deopt handlers (regular and MH) + exception handler int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size()) +
LIR_Assembler::exception_handler_size() +
(2 * LIR_Assembler::deopt_handler_size()); if (stub_size >= code->insts_capacity()) returnfalse;
code->initialize_stubs_size(stub_size); returntrue;
}
int Compilation::emit_code_body() { // emit code if (!setup_code_buffer(code(), allocator()->num_calls())) {
BAILOUT_("size requested greater than avail code buffer size", 0);
}
code()->initialize_oop_recorder(env()->oop_recorder());
_masm = new C1_MacroAssembler(code());
_masm->set_oop_recorder(env()->oop_recorder());
if (!method()->can_be_compiled()) { // Prevent race condition 6328518. // This can happen if the method is obsolete or breakpointed.
bailout("Bailing out because method is not compilable"); return;
}
if (_env->jvmti_can_hotswap_or_post_breakpoint()) { // We can assert evol_method because method->can_be_compiled is true.
dependency_recorder()->assert_evol_method(method());
}
if (env()->break_at_compile()) {
BREAKPOINT;
}
#ifndef PRODUCT if (PrintCFGToFile) {
CFGPrinter::print_compilation(this);
} #endif
// compile method int frame_size = compile_java_method();
// bailout if method couldn't be compiled // Note: make sure we mark the method as not compilable!
CHECK_BAILOUT();
if (should_install_code()) { // install code
PhaseTraceTime timeit(_t_codeinstall);
install_code(frame_size);
}
if (log() != NULL) // Print code cache state into compiler log
log()->code_cache_state();
void Compilation::generate_exception_handler_table() { // Generate an ExceptionHandlerTable from the exception handler // information accumulated during the compilation.
ExceptionInfoList* info_list = exception_info_list();
if (info_list->length() == 0) { return;
}
// allocate some arrays for use by the collection code. constint num_handlers = 5;
GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
for (int i = 0; i < info_list->length(); i++) {
ExceptionInfo* info = info_list->at(i);
XHandlers* handlers = info->exception_handlers();
// empty the arrays
bcis->trunc_to(0);
scope_depths->trunc_to(0);
pcos->trunc_to(0);
int prev_scope = 0; for (int i = 0; i < handlers->length(); i++) {
XHandler* handler = handlers->handler_at(i);
assert(handler->entry_pco() != -1, "must have been generated");
assert(handler->scope_count() >= prev_scope, "handlers should be sorted by scope");
if (handler->scope_count() == prev_scope) { int e = bcis->find_from_end(handler->handler_bci()); if (e >= 0 && scope_depths->at(e) == handler->scope_count()) { // two different handlers are declared to dispatch to the same // catch bci. During parsing we created edges for each // handler but we really only need one. The exception handler // table will also get unhappy if we try to declare both since // it's nonsensical. Just skip this handler. continue;
}
}
bcis->append(handler->handler_bci()); if (handler->handler_bci() == -1) { // insert a wildcard handler at scope depth 0 so that the // exception lookup logic with find it.
scope_depths->append(0);
} else {
scope_depths->append(handler->scope_count());
}
pcos->append(handler->entry_pco());
// stop processing once we hit a catch any if (handler->is_catch_all()) {
assert(i == handlers->length() - 1, "catch all must be last handler");
}
prev_scope = handler->scope_count();
}
exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
}
}
Compilation::~Compilation() { // simulate crash during compilation
assert(CICrashAt < 0 || (uintx)_env->compile_id() != (uintx)CICrashAt, "just as planned");
_env->set_compiler_data(NULL);
}
void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { #ifndef PRODUCT if (PrintExceptionHandlers && Verbose) {
tty->print_cr(" added exception scope for pco %d", pco);
} #endif // Note: we do not have program counters for these exception handlers yet
exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
}
// Called from debugger to get the interval with 'reg_num' during register allocation.
Interval* find_interval(int reg_num) { return Compilation::current()->allocator()->find_interval_at(reg_num);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.