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