hotspot/src/share/vm/opto/c2compiler.cpp
author kvn
Tue, 05 Nov 2013 17:38:04 -0800
changeset 22838 82c7497fbad4
parent 22807 1cf02ef734e2
parent 20707 b3b658c6d1f8
child 22872 b6902ee5bc8d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8107
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5353
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5353
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5353
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    26
#include "opto/c2compiler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    27
#include "opto/runtime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    28
#ifdef TARGET_ARCH_MODEL_x86_32
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    29
# include "adfiles/ad_x86_32.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    30
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    31
#ifdef TARGET_ARCH_MODEL_x86_64
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    32
# include "adfiles/ad_x86_64.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    33
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    34
#ifdef TARGET_ARCH_MODEL_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    35
# include "adfiles/ad_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    36
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    37
#ifdef TARGET_ARCH_MODEL_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    38
# include "adfiles/ad_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    39
#endif
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    40
#ifdef TARGET_ARCH_MODEL_arm
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    41
# include "adfiles/ad_arm.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    42
#endif
22807
1cf02ef734e2 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 17383
diff changeset
    43
#ifdef TARGET_ARCH_MODEL_ppc_32
1cf02ef734e2 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 17383
diff changeset
    44
# include "adfiles/ad_ppc_32.hpp"
1cf02ef734e2 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 17383
diff changeset
    45
#endif
1cf02ef734e2 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 17383
diff changeset
    46
#ifdef TARGET_ARCH_MODEL_ppc_64
1cf02ef734e2 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 17383
diff changeset
    47
# include "adfiles/ad_ppc_64.hpp"
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    48
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// register information defined by ADLC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
extern const char register_save_policy[];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
extern const int  register_save_type[];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
const char* C2Compiler::retry_no_subsuming_loads() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  return "retry without subsuming loads";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    57
const char* C2Compiler::retry_no_escape_analysis() {
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    58
  return "retry without escape analysis";
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
    59
}
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
    60
bool C2Compiler::init_c2_runtime() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Check assumptions used while running ADLC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  Compile::adlc_verification();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      OptoReg::vm2opto[i] = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    VMReg r = OptoReg::as_VMReg(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    if (r->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      OptoReg::vm2opto[r->value()] = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Check that runtime and architecture description agree on callee-saved-floats
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  bool callee_saved_floats = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  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
    80
    // Is there a callee-saved float or double?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    if( register_save_policy[i] == 'E' /* callee-saved */ &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
       (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      callee_saved_floats = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  DEBUG_ONLY( Node::init_NodeProperty(); )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  Compile::pd_compiler2_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  CompilerThread* thread = CompilerThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
    93
  HandleMark handle_mark(thread);
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
    94
  return OptoRuntime::generate(thread->env());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void C2Compiler::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // The first compiler thread that gets here will initialize the
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   100
  // small amount of global state (and runtime stubs) that C2 needs.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // There is a race possible once at startup and then we're fine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Note that this is being called from a compiler thread not the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // main startup thread.
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   106
  if (should_perform_init()) {
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   107
    bool successful = C2Compiler::init_c2_runtime();
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   108
    int new_state = (successful) ? initialized : failed;
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   109
    set_state(new_state);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   113
void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   114
  assert(is_initialized(), "Compiler thread must be initialized");
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   115
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   116
  bool subsume_loads = SubsumeLoads;
20707
b3b658c6d1f8 8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents: 17383
diff changeset
   117
  bool do_escape_analysis = DoEscapeAnalysis && !env->jvmti_can_access_local_variables();
17383
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   118
  bool eliminate_boxing = EliminateAutoBox;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  while (!env->failing()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // Attempt to compile while subsuming loads into machine instructions.
17383
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   121
    Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis, eliminate_boxing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   123
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // Check result and retry if appropriate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    if (C.failure_reason() != NULL) {
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   126
      if (C.failure_reason_is(retry_no_subsuming_loads())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        assert(subsume_loads, "must make progress");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        subsume_loads = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        continue;  // retry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      }
211
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   131
      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
   132
        assert(do_escape_analysis, "must make progress");
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   133
        do_escape_analysis = false;
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   134
        continue;  // retry
e2b60448c234 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 1
diff changeset
   135
      }
17383
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   136
      if (C.has_boxed_value()) {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   137
        // Recompile without boxing elimination regardless failure reason.
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   138
        assert(eliminate_boxing, "must make progress");
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   139
        eliminate_boxing = false;
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   140
        continue;  // retry
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 8921
diff changeset
   141
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      // Pass any other failure reason up to the ciEnv.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      // Note that serious, irreversible failures are already logged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      // on the ciEnv via env->record_method_not_compilable().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      env->record_failure(C.failure_reason());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   147
    if (StressRecompilation) {
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   148
      if (subsume_loads) {
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   149
        subsume_loads = false;
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   150
        continue;  // retry
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   151
      }
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   152
      if (do_escape_analysis) {
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   153
        do_escape_analysis = false;
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   154
        continue;  // retry
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   155
      }
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   156
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // No retry; just break the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
void C2Compiler::print_timers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}