hotspot/src/share/vm/opto/c2compiler.cpp
author xdono
Mon, 15 Dec 2008 16:55:11 -0800
changeset 1623 a0dd9009e992
parent 670 ddf3e9583f2f
child 3171 aa289b22b577
permissions -rw-r--r--
6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 211
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_c2compiler.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
volatile int C2Compiler::_runtimes = uninitialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// register information defined by ADLC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
extern const char register_save_policy[];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
extern const int  register_save_type[];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
const char* C2Compiler::retry_no_subsuming_loads() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  return "retry without subsuming loads";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    38
const char* C2Compiler::retry_no_escape_analysis() {
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    39
  return "retry without escape analysis";
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    40
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
void C2Compiler::initialize_runtime() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // Check assumptions used while running ADLC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  Compile::adlc_verification();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      OptoReg::vm2opto[i] = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    VMReg r = OptoReg::as_VMReg(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (r->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      OptoReg::vm2opto[r->value()] = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Check that runtime and architecture description agree on callee-saved-floats
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  bool callee_saved_floats = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Is there a callee-saved float or double?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    if( register_save_policy[i] == 'E' /* callee-saved */ &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
       (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      callee_saved_floats = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  DEBUG_ONLY( Node::init_NodeProperty(); )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  Compile::pd_compiler2_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  CompilerThread* thread = CompilerThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  HandleMark  handle_mark(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  OptoRuntime::generate(thread->env());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void C2Compiler::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // This method can only be called once per C2Compiler object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // The first compiler thread that gets here will initialize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // small amount of global state (and runtime stubs) that c2 needs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // There is a race possible once at startup and then we're fine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Note that this is being called from a compiler thread not the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // main startup thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if (_runtimes != initialized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    initialize_runtimes( initialize_runtime, &_runtimes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Mark this compiler object as ready to roll
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  mark_initialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void C2Compiler::compile_method(ciEnv* env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                                ciMethod* target,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                                int entry_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (!is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  bool subsume_loads = true;
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   107
  bool do_escape_analysis = DoEscapeAnalysis;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  while (!env->failing()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    // Attempt to compile while subsuming loads into machine instructions.
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   110
    Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // Check result and retry if appropriate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (C.failure_reason() != NULL) {
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   114
      if (C.failure_reason_is(retry_no_subsuming_loads())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        assert(subsume_loads, "must make progress");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        subsume_loads = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        continue;  // retry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      }
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   119
      if (C.failure_reason_is(retry_no_escape_analysis())) {
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   120
        assert(do_escape_analysis, "must make progress");
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   121
        do_escape_analysis = false;
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   122
        continue;  // retry
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   123
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      // Pass any other failure reason up to the ciEnv.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      // Note that serious, irreversible failures are already logged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      // on the ciEnv via env->record_method_not_compilable().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      env->record_failure(C.failure_reason());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // No retry; just break the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
void C2Compiler::print_timers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}