c2compiler.cpp revision 1472
1N/A/*
1N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1N/A *
1N/A * This code is free software; you can redistribute it and/or modify it
1N/A * under the terms of the GNU General Public License version 2 only, as
1N/A * published by the Free Software Foundation.
1N/A *
1N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1N/A * version 2 for more details (a copy is included in the LICENSE file that
1N/A * accompanied this code).
1N/A *
1N/A * You should have received a copy of the GNU General Public License version
1N/A * 2 along with this work; if not, write to the Free Software Foundation,
1N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1N/A *
1N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1N/A * or visit www.oracle.com if you need additional information or have any
1N/A * questions.
1N/A *
1N/A */
1N/A
1N/A#include "incls/_precompiled.incl"
1N/A#include "incls/_c2compiler.cpp.incl"
1N/A
1N/A
1N/Avolatile int C2Compiler::_runtimes = uninitialized;
1N/A
1N/A// register information defined by ADLC
1N/Aextern const char register_save_policy[];
1N/Aextern const int register_save_type[];
1N/A
1N/Aconst char* C2Compiler::retry_no_subsuming_loads() {
1N/A return "retry without subsuming loads";
1N/A}
1N/Aconst char* C2Compiler::retry_no_escape_analysis() {
1N/A return "retry without escape analysis";
1N/A}
1N/Avoid C2Compiler::initialize_runtime() {
1N/A
1N/A // Check assumptions used while running ADLC
1N/A Compile::adlc_verification();
1N/A assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
1N/A
1N/A for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
1N/A OptoReg::vm2opto[i] = OptoReg::Bad;
1N/A }
1N/A
1N/A for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
1N/A VMReg r = OptoReg::as_VMReg(i);
1N/A if (r->is_valid()) {
1N/A OptoReg::vm2opto[r->value()] = i;
1N/A }
1N/A }
1N/A
1N/A // Check that runtime and architecture description agree on callee-saved-floats
1N/A bool callee_saved_floats = false;
1N/A for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
1N/A // Is there a callee-saved float or double?
1N/A if( register_save_policy[i] == 'E' /* callee-saved */ &&
1N/A (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
1N/A callee_saved_floats = true;
1N/A }
1N/A }
1N/A
1N/A DEBUG_ONLY( Node::init_NodeProperty(); )
1N/A
1N/A Compile::pd_compiler2_init();
1N/A
1N/A CompilerThread* thread = CompilerThread::current();
1N/A
1N/A HandleMark handle_mark(thread);
1N/A
1N/A OptoRuntime::generate(thread->env());
1N/A
1N/A}
1N/A
1N/A
1N/Avoid C2Compiler::initialize() {
1N/A
1N/A // This method can only be called once per C2Compiler object
1N/A // The first compiler thread that gets here will initialize the
1N/A // small amount of global state (and runtime stubs) that c2 needs.
1N/A
1N/A // There is a race possible once at startup and then we're fine
1N/A
1N/A // Note that this is being called from a compiler thread not the
1N/A // main startup thread.
1N/A
1N/A if (_runtimes != initialized) {
1N/A initialize_runtimes( initialize_runtime, &_runtimes);
1N/A }
1N/A
1N/A // Mark this compiler object as ready to roll
1N/A mark_initialized();
1N/A}
1N/A
1N/Avoid C2Compiler::compile_method(ciEnv* env,
1N/A ciMethod* target,
1N/A int entry_bci) {
1N/A if (!is_initialized()) {
1N/A initialize();
1N/A }
1N/A bool subsume_loads = true;
1N/A bool do_escape_analysis = DoEscapeAnalysis &&
1N/A !env->jvmti_can_access_local_variables();
1N/A while (!env->failing()) {
1N/A // Attempt to compile while subsuming loads into machine instructions.
1N/A Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis);
1N/A
1N/A // Check result and retry if appropriate.
1N/A if (C.failure_reason() != NULL) {
1N/A if (C.failure_reason_is(retry_no_subsuming_loads())) {
1N/A assert(subsume_loads, "must make progress");
1N/A subsume_loads = false;
1N/A continue; // retry
1N/A }
1N/A if (C.failure_reason_is(retry_no_escape_analysis())) {
1N/A assert(do_escape_analysis, "must make progress");
1N/A do_escape_analysis = false;
1N/A continue; // retry
1N/A }
1N/A // Pass any other failure reason up to the ciEnv.
1N/A // Note that serious, irreversible failures are already logged
1N/A // on the ciEnv via env->record_method_not_compilable().
1N/A env->record_failure(C.failure_reason());
1N/A }
1N/A
1N/A // No retry; just break the loop.
1N/A break;
1N/A }
1N/A}
1N/A
1N/A
1N/Avoid C2Compiler::print_timers() {
1N/A // do nothing
1N/A}
1N/A