Thu, 10 Oct 2013 15:44:12 +0200
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
Summary: Ensure ensure correct initialization of compiler runtime
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "opto/c2compiler.hpp" |
stefank@2314 | 27 | #include "opto/runtime.hpp" |
stefank@2314 | 28 | #ifdef TARGET_ARCH_MODEL_x86_32 |
stefank@2314 | 29 | # include "adfiles/ad_x86_32.hpp" |
stefank@2314 | 30 | #endif |
stefank@2314 | 31 | #ifdef TARGET_ARCH_MODEL_x86_64 |
stefank@2314 | 32 | # include "adfiles/ad_x86_64.hpp" |
stefank@2314 | 33 | #endif |
stefank@2314 | 34 | #ifdef TARGET_ARCH_MODEL_sparc |
stefank@2314 | 35 | # include "adfiles/ad_sparc.hpp" |
stefank@2314 | 36 | #endif |
stefank@2314 | 37 | #ifdef TARGET_ARCH_MODEL_zero |
stefank@2314 | 38 | # include "adfiles/ad_zero.hpp" |
stefank@2314 | 39 | #endif |
bobv@2508 | 40 | #ifdef TARGET_ARCH_MODEL_arm |
bobv@2508 | 41 | # include "adfiles/ad_arm.hpp" |
bobv@2508 | 42 | #endif |
bobv@2508 | 43 | #ifdef TARGET_ARCH_MODEL_ppc |
bobv@2508 | 44 | # include "adfiles/ad_ppc.hpp" |
bobv@2508 | 45 | #endif |
duke@435 | 46 | |
duke@435 | 47 | // register information defined by ADLC |
duke@435 | 48 | extern const char register_save_policy[]; |
duke@435 | 49 | extern const int register_save_type[]; |
duke@435 | 50 | |
duke@435 | 51 | const char* C2Compiler::retry_no_subsuming_loads() { |
duke@435 | 52 | return "retry without subsuming loads"; |
duke@435 | 53 | } |
kvn@473 | 54 | const char* C2Compiler::retry_no_escape_analysis() { |
kvn@473 | 55 | return "retry without escape analysis"; |
kvn@473 | 56 | } |
anoll@5919 | 57 | bool C2Compiler::init_c2_runtime() { |
duke@435 | 58 | |
duke@435 | 59 | // Check assumptions used while running ADLC |
duke@435 | 60 | Compile::adlc_verification(); |
duke@435 | 61 | assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts"); |
duke@435 | 62 | |
duke@435 | 63 | for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) { |
duke@435 | 64 | OptoReg::vm2opto[i] = OptoReg::Bad; |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) { |
duke@435 | 68 | VMReg r = OptoReg::as_VMReg(i); |
duke@435 | 69 | if (r->is_valid()) { |
duke@435 | 70 | OptoReg::vm2opto[r->value()] = i; |
duke@435 | 71 | } |
duke@435 | 72 | } |
duke@435 | 73 | |
duke@435 | 74 | // Check that runtime and architecture description agree on callee-saved-floats |
duke@435 | 75 | bool callee_saved_floats = false; |
duke@435 | 76 | for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) { |
duke@435 | 77 | // Is there a callee-saved float or double? |
duke@435 | 78 | if( register_save_policy[i] == 'E' /* callee-saved */ && |
duke@435 | 79 | (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) { |
duke@435 | 80 | callee_saved_floats = true; |
duke@435 | 81 | } |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | DEBUG_ONLY( Node::init_NodeProperty(); ) |
duke@435 | 85 | |
duke@435 | 86 | Compile::pd_compiler2_init(); |
duke@435 | 87 | |
duke@435 | 88 | CompilerThread* thread = CompilerThread::current(); |
duke@435 | 89 | |
anoll@5919 | 90 | HandleMark handle_mark(thread); |
anoll@5919 | 91 | return OptoRuntime::generate(thread->env()); |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | |
duke@435 | 95 | void C2Compiler::initialize() { |
duke@435 | 96 | // The first compiler thread that gets here will initialize the |
anoll@5919 | 97 | // small amount of global state (and runtime stubs) that C2 needs. |
duke@435 | 98 | |
duke@435 | 99 | // There is a race possible once at startup and then we're fine |
duke@435 | 100 | |
duke@435 | 101 | // Note that this is being called from a compiler thread not the |
duke@435 | 102 | // main startup thread. |
anoll@5919 | 103 | if (should_perform_init()) { |
anoll@5919 | 104 | bool successful = C2Compiler::init_c2_runtime(); |
anoll@5919 | 105 | int new_state = (successful) ? initialized : failed; |
anoll@5919 | 106 | set_state(new_state); |
duke@435 | 107 | } |
duke@435 | 108 | } |
duke@435 | 109 | |
anoll@5919 | 110 | void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { |
anoll@5919 | 111 | assert(is_initialized(), "Compiler thread must be initialized"); |
anoll@5919 | 112 | |
kvn@2040 | 113 | bool subsume_loads = SubsumeLoads; |
anoll@5919 | 114 | bool do_escape_analysis = DoEscapeAnalysis && !env->jvmti_can_access_local_variables(); |
kvn@5110 | 115 | bool eliminate_boxing = EliminateAutoBox; |
duke@435 | 116 | while (!env->failing()) { |
duke@435 | 117 | // Attempt to compile while subsuming loads into machine instructions. |
kvn@5110 | 118 | Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis, eliminate_boxing); |
duke@435 | 119 | |
kvn@2040 | 120 | |
duke@435 | 121 | // Check result and retry if appropriate. |
duke@435 | 122 | if (C.failure_reason() != NULL) { |
kvn@473 | 123 | if (C.failure_reason_is(retry_no_subsuming_loads())) { |
duke@435 | 124 | assert(subsume_loads, "must make progress"); |
duke@435 | 125 | subsume_loads = false; |
duke@435 | 126 | continue; // retry |
duke@435 | 127 | } |
kvn@473 | 128 | if (C.failure_reason_is(retry_no_escape_analysis())) { |
kvn@473 | 129 | assert(do_escape_analysis, "must make progress"); |
kvn@473 | 130 | do_escape_analysis = false; |
kvn@473 | 131 | continue; // retry |
kvn@473 | 132 | } |
kvn@5110 | 133 | if (C.has_boxed_value()) { |
kvn@5110 | 134 | // Recompile without boxing elimination regardless failure reason. |
kvn@5110 | 135 | assert(eliminate_boxing, "must make progress"); |
kvn@5110 | 136 | eliminate_boxing = false; |
kvn@5110 | 137 | continue; // retry |
kvn@5110 | 138 | } |
duke@435 | 139 | // Pass any other failure reason up to the ciEnv. |
duke@435 | 140 | // Note that serious, irreversible failures are already logged |
duke@435 | 141 | // on the ciEnv via env->record_method_not_compilable(). |
duke@435 | 142 | env->record_failure(C.failure_reason()); |
duke@435 | 143 | } |
kvn@2040 | 144 | if (StressRecompilation) { |
kvn@2040 | 145 | if (subsume_loads) { |
kvn@2040 | 146 | subsume_loads = false; |
kvn@2040 | 147 | continue; // retry |
kvn@2040 | 148 | } |
kvn@2040 | 149 | if (do_escape_analysis) { |
kvn@2040 | 150 | do_escape_analysis = false; |
kvn@2040 | 151 | continue; // retry |
kvn@2040 | 152 | } |
kvn@2040 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | // No retry; just break the loop. |
duke@435 | 156 | break; |
duke@435 | 157 | } |
duke@435 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | |
duke@435 | 161 | void C2Compiler::print_timers() { |
duke@435 | 162 | // do nothing |
duke@435 | 163 | } |