src/share/vm/opto/c2compiler.cpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/c2compiler.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,166 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "opto/c2compiler.hpp"
    1.30 +#include "opto/runtime.hpp"
    1.31 +#ifdef TARGET_ARCH_MODEL_x86_32
    1.32 +# include "adfiles/ad_x86_32.hpp"
    1.33 +#endif
    1.34 +#ifdef TARGET_ARCH_MODEL_x86_64
    1.35 +# include "adfiles/ad_x86_64.hpp"
    1.36 +#endif
    1.37 +#ifdef TARGET_ARCH_MODEL_sparc
    1.38 +# include "adfiles/ad_sparc.hpp"
    1.39 +#endif
    1.40 +#ifdef TARGET_ARCH_MODEL_zero
    1.41 +# include "adfiles/ad_zero.hpp"
    1.42 +#endif
    1.43 +#ifdef TARGET_ARCH_MODEL_arm
    1.44 +# include "adfiles/ad_arm.hpp"
    1.45 +#endif
    1.46 +#ifdef TARGET_ARCH_MODEL_ppc_32
    1.47 +# include "adfiles/ad_ppc_32.hpp"
    1.48 +#endif
    1.49 +#ifdef TARGET_ARCH_MODEL_ppc_64
    1.50 +# include "adfiles/ad_ppc_64.hpp"
    1.51 +#endif
    1.52 +
    1.53 +// register information defined by ADLC
    1.54 +extern const char register_save_policy[];
    1.55 +extern const int  register_save_type[];
    1.56 +
    1.57 +const char* C2Compiler::retry_no_subsuming_loads() {
    1.58 +  return "retry without subsuming loads";
    1.59 +}
    1.60 +const char* C2Compiler::retry_no_escape_analysis() {
    1.61 +  return "retry without escape analysis";
    1.62 +}
    1.63 +bool C2Compiler::init_c2_runtime() {
    1.64 +
    1.65 +  // Check assumptions used while running ADLC
    1.66 +  Compile::adlc_verification();
    1.67 +  assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
    1.68 +
    1.69 +  for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
    1.70 +      OptoReg::vm2opto[i] = OptoReg::Bad;
    1.71 +  }
    1.72 +
    1.73 +  for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
    1.74 +    VMReg r = OptoReg::as_VMReg(i);
    1.75 +    if (r->is_valid()) {
    1.76 +      OptoReg::vm2opto[r->value()] = i;
    1.77 +    }
    1.78 +  }
    1.79 +
    1.80 +  // Check that runtime and architecture description agree on callee-saved-floats
    1.81 +  bool callee_saved_floats = false;
    1.82 +  for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
    1.83 +    // Is there a callee-saved float or double?
    1.84 +    if( register_save_policy[i] == 'E' /* callee-saved */ &&
    1.85 +       (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
    1.86 +      callee_saved_floats = true;
    1.87 +    }
    1.88 +  }
    1.89 +
    1.90 +  DEBUG_ONLY( Node::init_NodeProperty(); )
    1.91 +
    1.92 +  Compile::pd_compiler2_init();
    1.93 +
    1.94 +  CompilerThread* thread = CompilerThread::current();
    1.95 +
    1.96 +  HandleMark handle_mark(thread);
    1.97 +  return OptoRuntime::generate(thread->env());
    1.98 +}
    1.99 +
   1.100 +
   1.101 +void C2Compiler::initialize() {
   1.102 +  // The first compiler thread that gets here will initialize the
   1.103 +  // small amount of global state (and runtime stubs) that C2 needs.
   1.104 +
   1.105 +  // There is a race possible once at startup and then we're fine
   1.106 +
   1.107 +  // Note that this is being called from a compiler thread not the
   1.108 +  // main startup thread.
   1.109 +  if (should_perform_init()) {
   1.110 +    bool successful = C2Compiler::init_c2_runtime();
   1.111 +    int new_state = (successful) ? initialized : failed;
   1.112 +    set_state(new_state);
   1.113 +  }
   1.114 +}
   1.115 +
   1.116 +void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
   1.117 +  assert(is_initialized(), "Compiler thread must be initialized");
   1.118 +
   1.119 +  bool subsume_loads = SubsumeLoads;
   1.120 +  bool do_escape_analysis = DoEscapeAnalysis && !env->jvmti_can_access_local_variables();
   1.121 +  bool eliminate_boxing = EliminateAutoBox;
   1.122 +  while (!env->failing()) {
   1.123 +    // Attempt to compile while subsuming loads into machine instructions.
   1.124 +    Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis, eliminate_boxing);
   1.125 +
   1.126 +
   1.127 +    // Check result and retry if appropriate.
   1.128 +    if (C.failure_reason() != NULL) {
   1.129 +      if (C.failure_reason_is(retry_no_subsuming_loads())) {
   1.130 +        assert(subsume_loads, "must make progress");
   1.131 +        subsume_loads = false;
   1.132 +        continue;  // retry
   1.133 +      }
   1.134 +      if (C.failure_reason_is(retry_no_escape_analysis())) {
   1.135 +        assert(do_escape_analysis, "must make progress");
   1.136 +        do_escape_analysis = false;
   1.137 +        continue;  // retry
   1.138 +      }
   1.139 +      if (C.has_boxed_value()) {
   1.140 +        // Recompile without boxing elimination regardless failure reason.
   1.141 +        assert(eliminate_boxing, "must make progress");
   1.142 +        eliminate_boxing = false;
   1.143 +        continue;  // retry
   1.144 +      }
   1.145 +      // Pass any other failure reason up to the ciEnv.
   1.146 +      // Note that serious, irreversible failures are already logged
   1.147 +      // on the ciEnv via env->record_method_not_compilable().
   1.148 +      env->record_failure(C.failure_reason());
   1.149 +    }
   1.150 +    if (StressRecompilation) {
   1.151 +      if (subsume_loads) {
   1.152 +        subsume_loads = false;
   1.153 +        continue;  // retry
   1.154 +      }
   1.155 +      if (do_escape_analysis) {
   1.156 +        do_escape_analysis = false;
   1.157 +        continue;  // retry
   1.158 +      }
   1.159 +    }
   1.160 +
   1.161 +    // No retry; just break the loop.
   1.162 +    break;
   1.163 +  }
   1.164 +}
   1.165 +
   1.166 +
   1.167 +void C2Compiler::print_timers() {
   1.168 +  // do nothing
   1.169 +}

mercurial