src/share/vm/opto/c2compiler.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8604
04d83ba48607
child 10015
eb7ce841ccec
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial