2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2014-07-04 11:46:01 +02:00
|
|
|
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "opto/c2compiler.hpp"
|
2014-09-17 08:00:07 +02:00
|
|
|
#include "opto/compile.hpp"
|
2014-07-04 11:46:01 +02:00
|
|
|
#include "opto/optoreg.hpp"
|
2014-09-17 08:00:07 +02:00
|
|
|
#include "opto/output.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "opto/runtime.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// register information defined by ADLC
|
|
|
|
extern const char register_save_policy[];
|
|
|
|
extern const int register_save_type[];
|
|
|
|
|
|
|
|
const char* C2Compiler::retry_no_subsuming_loads() {
|
|
|
|
return "retry without subsuming loads";
|
|
|
|
}
|
2008-03-06 10:30:17 -08:00
|
|
|
const char* C2Compiler::retry_no_escape_analysis() {
|
|
|
|
return "retry without escape analysis";
|
|
|
|
}
|
2013-10-10 15:44:12 +02:00
|
|
|
bool C2Compiler::init_c2_runtime() {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Check assumptions used while running ADLC
|
|
|
|
Compile::adlc_verification();
|
|
|
|
assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
|
|
|
|
|
|
|
|
for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
|
|
|
|
OptoReg::vm2opto[i] = OptoReg::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
|
|
|
|
VMReg r = OptoReg::as_VMReg(i);
|
|
|
|
if (r->is_valid()) {
|
|
|
|
OptoReg::vm2opto[r->value()] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that runtime and architecture description agree on callee-saved-floats
|
|
|
|
bool callee_saved_floats = false;
|
|
|
|
for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
|
|
|
|
// Is there a callee-saved float or double?
|
|
|
|
if( register_save_policy[i] == 'E' /* callee-saved */ &&
|
|
|
|
(register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
|
|
|
|
callee_saved_floats = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_ONLY( Node::init_NodeProperty(); )
|
|
|
|
|
|
|
|
Compile::pd_compiler2_init();
|
|
|
|
|
|
|
|
CompilerThread* thread = CompilerThread::current();
|
|
|
|
|
2013-10-10 15:44:12 +02:00
|
|
|
HandleMark handle_mark(thread);
|
|
|
|
return OptoRuntime::generate(thread->env());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void C2Compiler::initialize() {
|
|
|
|
// The first compiler thread that gets here will initialize the
|
2013-10-10 15:44:12 +02:00
|
|
|
// small amount of global state (and runtime stubs) that C2 needs.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// There is a race possible once at startup and then we're fine
|
|
|
|
|
|
|
|
// Note that this is being called from a compiler thread not the
|
|
|
|
// main startup thread.
|
2013-10-10 15:44:12 +02:00
|
|
|
if (should_perform_init()) {
|
|
|
|
bool successful = C2Compiler::init_c2_runtime();
|
|
|
|
int new_state = (successful) ? initialized : failed;
|
|
|
|
set_state(new_state);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 15:44:12 +02:00
|
|
|
void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
|
|
|
|
assert(is_initialized(), "Compiler thread must be initialized");
|
|
|
|
|
2010-08-03 15:55:03 -07:00
|
|
|
bool subsume_loads = SubsumeLoads;
|
2014-02-22 10:22:05 +01:00
|
|
|
bool do_escape_analysis = DoEscapeAnalysis && !env->should_retain_local_variables();
|
2013-05-08 15:08:01 -07:00
|
|
|
bool eliminate_boxing = EliminateAutoBox;
|
2007-12-01 00:00:00 +00:00
|
|
|
while (!env->failing()) {
|
|
|
|
// Attempt to compile while subsuming loads into machine instructions.
|
2013-05-08 15:08:01 -07:00
|
|
|
Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis, eliminate_boxing);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Check result and retry if appropriate.
|
|
|
|
if (C.failure_reason() != NULL) {
|
2008-03-06 10:30:17 -08:00
|
|
|
if (C.failure_reason_is(retry_no_subsuming_loads())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(subsume_loads, "must make progress");
|
|
|
|
subsume_loads = false;
|
2014-11-24 08:48:15 +01:00
|
|
|
env->report_failure(C.failure_reason());
|
2007-12-01 00:00:00 +00:00
|
|
|
continue; // retry
|
|
|
|
}
|
2008-03-06 10:30:17 -08:00
|
|
|
if (C.failure_reason_is(retry_no_escape_analysis())) {
|
|
|
|
assert(do_escape_analysis, "must make progress");
|
|
|
|
do_escape_analysis = false;
|
2014-11-24 08:48:15 +01:00
|
|
|
env->report_failure(C.failure_reason());
|
2008-03-06 10:30:17 -08:00
|
|
|
continue; // retry
|
|
|
|
}
|
2013-05-08 15:08:01 -07:00
|
|
|
if (C.has_boxed_value()) {
|
|
|
|
// Recompile without boxing elimination regardless failure reason.
|
|
|
|
assert(eliminate_boxing, "must make progress");
|
|
|
|
eliminate_boxing = false;
|
2014-11-24 08:48:15 +01:00
|
|
|
env->report_failure(C.failure_reason());
|
2013-05-08 15:08:01 -07:00
|
|
|
continue; // retry
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
// Pass any other failure reason up to the ciEnv.
|
|
|
|
// Note that serious, irreversible failures are already logged
|
|
|
|
// on the ciEnv via env->record_method_not_compilable().
|
|
|
|
env->record_failure(C.failure_reason());
|
|
|
|
}
|
2010-08-03 15:55:03 -07:00
|
|
|
if (StressRecompilation) {
|
|
|
|
if (subsume_loads) {
|
|
|
|
subsume_loads = false;
|
|
|
|
continue; // retry
|
|
|
|
}
|
|
|
|
if (do_escape_analysis) {
|
|
|
|
do_escape_analysis = false;
|
|
|
|
continue; // retry
|
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-05-26 14:27:01 +02:00
|
|
|
// print inlining for last compilation only
|
|
|
|
C.dump_print_inlining();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// No retry; just break the loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void C2Compiler::print_timers() {
|
2014-09-25 12:10:57 +04:00
|
|
|
Compile::print_timers();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2014-09-17 08:00:07 +02:00
|
|
|
|
|
|
|
int C2Compiler::initial_code_buffer_size() {
|
|
|
|
assert(SegmentedCodeCache, "Should be only used with a segmented code cache");
|
|
|
|
return Compile::MAX_inst_size + Compile::MAX_locs_size + initial_const_capacity;
|
|
|
|
}
|