duke@435: /* trims@2708: * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "opto/c2compiler.hpp" stefank@2314: #include "opto/runtime.hpp" stefank@2314: #ifdef TARGET_ARCH_MODEL_x86_32 stefank@2314: # include "adfiles/ad_x86_32.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_MODEL_x86_64 stefank@2314: # include "adfiles/ad_x86_64.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_MODEL_sparc stefank@2314: # include "adfiles/ad_sparc.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_MODEL_zero stefank@2314: # include "adfiles/ad_zero.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_MODEL_arm bobv@2508: # include "adfiles/ad_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_MODEL_ppc bobv@2508: # include "adfiles/ad_ppc.hpp" bobv@2508: #endif duke@435: duke@435: // register information defined by ADLC duke@435: extern const char register_save_policy[]; duke@435: extern const int register_save_type[]; duke@435: duke@435: const char* C2Compiler::retry_no_subsuming_loads() { duke@435: return "retry without subsuming loads"; duke@435: } kvn@473: const char* C2Compiler::retry_no_escape_analysis() { kvn@473: return "retry without escape analysis"; kvn@473: } anoll@5919: bool C2Compiler::init_c2_runtime() { duke@435: duke@435: // Check assumptions used while running ADLC duke@435: Compile::adlc_verification(); duke@435: assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts"); duke@435: duke@435: for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) { duke@435: OptoReg::vm2opto[i] = OptoReg::Bad; duke@435: } duke@435: duke@435: for( OptoReg::Name i=OptoReg::Name(0); iis_valid()) { duke@435: OptoReg::vm2opto[r->value()] = i; duke@435: } duke@435: } duke@435: duke@435: // Check that runtime and architecture description agree on callee-saved-floats duke@435: bool callee_saved_floats = false; duke@435: for( OptoReg::Name i=OptoReg::Name(0); ienv()); duke@435: } duke@435: duke@435: duke@435: void C2Compiler::initialize() { duke@435: // The first compiler thread that gets here will initialize the anoll@5919: // small amount of global state (and runtime stubs) that C2 needs. duke@435: duke@435: // There is a race possible once at startup and then we're fine duke@435: duke@435: // Note that this is being called from a compiler thread not the duke@435: // main startup thread. anoll@5919: if (should_perform_init()) { anoll@5919: bool successful = C2Compiler::init_c2_runtime(); anoll@5919: int new_state = (successful) ? initialized : failed; anoll@5919: set_state(new_state); duke@435: } duke@435: } duke@435: anoll@5919: void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { anoll@5919: assert(is_initialized(), "Compiler thread must be initialized"); anoll@5919: kvn@2040: bool subsume_loads = SubsumeLoads; anoll@5919: bool do_escape_analysis = DoEscapeAnalysis && !env->jvmti_can_access_local_variables(); kvn@5110: bool eliminate_boxing = EliminateAutoBox; duke@435: while (!env->failing()) { duke@435: // Attempt to compile while subsuming loads into machine instructions. kvn@5110: Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis, eliminate_boxing); duke@435: kvn@2040: duke@435: // Check result and retry if appropriate. duke@435: if (C.failure_reason() != NULL) { kvn@473: if (C.failure_reason_is(retry_no_subsuming_loads())) { duke@435: assert(subsume_loads, "must make progress"); duke@435: subsume_loads = false; duke@435: continue; // retry duke@435: } kvn@473: if (C.failure_reason_is(retry_no_escape_analysis())) { kvn@473: assert(do_escape_analysis, "must make progress"); kvn@473: do_escape_analysis = false; kvn@473: continue; // retry kvn@473: } kvn@5110: if (C.has_boxed_value()) { kvn@5110: // Recompile without boxing elimination regardless failure reason. kvn@5110: assert(eliminate_boxing, "must make progress"); kvn@5110: eliminate_boxing = false; kvn@5110: continue; // retry kvn@5110: } duke@435: // Pass any other failure reason up to the ciEnv. duke@435: // Note that serious, irreversible failures are already logged duke@435: // on the ciEnv via env->record_method_not_compilable(). duke@435: env->record_failure(C.failure_reason()); duke@435: } kvn@2040: if (StressRecompilation) { kvn@2040: if (subsume_loads) { kvn@2040: subsume_loads = false; kvn@2040: continue; // retry kvn@2040: } kvn@2040: if (do_escape_analysis) { kvn@2040: do_escape_analysis = false; kvn@2040: continue; // retry kvn@2040: } kvn@2040: } duke@435: duke@435: // No retry; just break the loop. duke@435: break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void C2Compiler::print_timers() { duke@435: // do nothing duke@435: }