hotspot/src/share/vm/c1/c1_Compilation.cpp
author xdono
Tue, 28 Jul 2009 12:12:40 -0700
changeset 3261 c7d5aae8d3f7
parent 2867 69187054225f
child 4748 3fa8d8a7c0ea
permissions -rw-r--r--
6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2867
diff changeset
     2
 * Copyright 1999-2009 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/_c1_Compilation.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
typedef enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  _t_compile,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _t_setup,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _t_optimizeIR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  _t_buildIR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _t_emit_lir,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _t_linearScan,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _t_lirGeneration,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _t_lir_schedule,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _t_codeemit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _t_codeinstall,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  max_phase_timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
} TimerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
static const char * timer_name[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  "compile",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  "setup",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  "optimizeIR",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  "buildIR",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  "emit_lir",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  "linearScan",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  "lirGeneration",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  "lir_schedule",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  "codeemit",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  "codeinstall"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
static elapsedTimer timers[max_phase_timers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
static int totalInstructionNodes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
class PhaseTraceTime: public TraceTime {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  JavaThread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  PhaseTraceTime(TimerName timer):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    TraceTime("", &timers[timer], CITime || CITimeEach, Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
Arena* Compilation::_arena = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
Compilation* Compilation::_compilation = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// Implementation of Compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
void Compilation::maybe_print_current_instruction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _last_instruction_printed = _current_instruction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _current_instruction->print_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
DebugInformationRecorder* Compilation::debug_info_recorder() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  return _env->debug_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
Dependencies* Compilation::dependency_recorder() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  return _env->dependencies();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
void Compilation::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Use an oop recorder bound to the CI environment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // (The default oop recorder is ignorant of the CI.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  OopRecorder* ooprec = new OopRecorder(_env->arena());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _env->set_oop_recorder(ooprec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _env->set_debug_info(new DebugInformationRecorder(ooprec));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  debug_info_recorder()->set_oopmaps(new OopMapSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _env->set_dependencies(new Dependencies(_env));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void Compilation::build_hir() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // setup ir
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  _hir = new IR(this, method(), osr_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (!_hir->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    bailout("invalid parsing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if (PrintCFGToFile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (UseC1Optimizations) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    NEEDS_CLEANUP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // optimization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    PhaseTraceTime timeit(_t_optimizeIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    _hir->optimize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  _hir->split_critical_edges();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // compute block ordering for code generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // the control flow must not be changed from here on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  _hir->compute_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  if (UseGlobalValueNumbering) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    int instructions = Instruction::number_of_instructions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    GlobalValueNumbering gvn(_hir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    assert(instructions == Instruction::number_of_instructions(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
           "shouldn't have created an instructions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // compute use counts after global value numbering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  _hir->compute_use_counts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  if (PrintIR  || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
void Compilation::emit_lir() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  LIRGenerator gen(this, method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    PhaseTraceTime timeit(_t_lirGeneration);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    hir()->iterate_linear_scan_order(&gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    PhaseTraceTime timeit(_t_linearScan);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    set_allocator(allocator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    // Assign physical registers to LIR operands using a linear scan algorithm.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    allocator->do_linear_scan();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    _max_spills = allocator->max_spills();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (BailoutAfterLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    if (PrintLIR && !bailed_out()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      print_LIR(hir()->code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    bailout("Bailing out because of -XX:+BailoutAfterLIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
void Compilation::emit_code_epilog(LIR_Assembler* assembler) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // generate code or slow cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assembler->emit_slow_case_stubs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // generate exception adapters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  assembler->emit_exception_entries(exception_info_list());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // generate code for exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  assembler->emit_exception_handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  assembler->emit_deopt_handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  masm()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
int Compilation::emit_code_body() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // emit code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  Runtime1::setup_code_buffer(code(), allocator()->num_calls());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  code()->initialize_oop_recorder(env()->oop_recorder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  _masm = new C1_MacroAssembler(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  _masm->set_oop_recorder(env()->oop_recorder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  LIR_Assembler lir_asm(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  lir_asm.emit_code(hir()->code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  CHECK_BAILOUT_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  emit_code_epilog(&lir_asm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  CHECK_BAILOUT_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  generate_exception_handler_table();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (PrintExceptionHandlers && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    exception_handler_table()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
#endif /* PRODUCT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  return frame_map()->framesize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
int Compilation::compile_java_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  assert(!method()->is_native(), "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  if (BailoutOnExceptionHandlers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    if (method()->has_exception_handlers()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      bailout("linear scan can't handle exception handlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  CHECK_BAILOUT_(no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    PhaseTraceTime timeit(_t_buildIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  build_hir();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (BailoutAfterHIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    PhaseTraceTime timeit(_t_emit_lir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    emit_lir();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  CHECK_BAILOUT_(no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    PhaseTraceTime timeit(_t_codeemit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    return emit_code_body();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
void Compilation::install_code(int frame_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // frame_size is in 32-bit words so adjust it intptr_t words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  assert(frame_size == frame_map()->framesize(), "must match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  _env->register_method(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    method(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    osr_bci(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    &_offsets,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    in_bytes(_frame_map->sp_offset_for_orig_pc()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    code(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    debug_info_recorder()->_oopmaps,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    exception_handler_table(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    implicit_exception_table(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    compiler(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    _env->comp_level(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    needs_debug_information(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    has_unsafe_access()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
void Compilation::compile_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // setup compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  if (!method()->can_be_compiled()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    // Prevent race condition 6328518.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // This can happen if the method is obsolete or breakpointed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    bailout("Bailing out because method is not compilable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
2867
69187054225f 6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents: 1
diff changeset
   322
  if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // We can assert evol_method because method->can_be_compiled is true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    dependency_recorder()->assert_evol_method(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  if (method()->break_at_execute()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    BREAKPOINT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  if (PrintCFGToFile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    CFGPrinter::print_compilation(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // compile method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  int frame_size = compile_java_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // bailout if method couldn't be compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  // Note: make sure we mark the method as not compilable!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (InstallMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    // install code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    PhaseTraceTime timeit(_t_codeinstall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    install_code(frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  totalInstructionNodes += Instruction::number_of_instructions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
void Compilation::generate_exception_handler_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  // Generate an ExceptionHandlerTable from the exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // information accumulated during the compilation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  ExceptionInfoList* info_list = exception_info_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  if (info_list->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // allocate some arrays for use by the collection code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  const int num_handlers = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  for (int i = 0; i < info_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    ExceptionInfo* info = info_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    XHandlers* handlers = info->exception_handlers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    // empty the arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    bcis->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    scope_depths->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    pcos->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    for (int i = 0; i < handlers->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      XHandler* handler = handlers->handler_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      assert(handler->entry_pco() != -1, "must have been generated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      int e = bcis->find(handler->handler_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        // two different handlers are declared to dispatch to the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
        // catch bci.  During parsing we created edges for each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        // handler but we really only need one.  The exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
        // table will also get unhappy if we try to declare both since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        // it's nonsensical.  Just skip this handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      bcis->append(handler->handler_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      if (handler->handler_bci() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        // insert a wildcard handler at scope depth 0 so that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        // exception lookup logic with find it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        scope_depths->append(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
        scope_depths->append(handler->scope_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      pcos->append(handler->entry_pco());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      // stop processing once we hit a catch any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      if (handler->is_catch_all()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
        assert(i == handlers->length() - 1, "catch all must be last handler");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, int osr_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
: _compiler(compiler)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
, _env(env)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
, _method(method)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
, _osr_bci(osr_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
, _hir(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
, _max_spills(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
, _frame_map(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
, _masm(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
, _has_exception_handlers(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
, _has_fpu_code(true)   // pessimistic assumption
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
, _has_unsafe_access(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
, _bailout_msg(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
, _exception_info_list(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
, _allocator(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
, _code(Runtime1::get_buffer_blob()->instructions_begin(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        Runtime1::get_buffer_blob()->instructions_size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
, _current_instruction(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
, _last_instruction_printed(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  PhaseTraceTime timeit(_t_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  assert(_arena == NULL, "shouldn't only one instance of Compilation in existence at a time");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  _arena = Thread::current()->resource_area();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  _compilation = this;
2867
69187054225f 6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents: 1
diff changeset
   438
  _needs_debug_information = _env->jvmti_can_examine_or_deopt_anywhere() ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
                               JavaMonitorsInStackTrace || AlwaysEmitDebugInfo || DeoptimizeALot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  _exception_info_list = new ExceptionInfoList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  _implicit_exception_table.set_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  compile_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
Compilation::~Compilation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  _arena = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  _compilation = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  if (PrintExceptionHandlers && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    tty->print_cr("  added exception scope for pco %d", pco);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // Note: we do not have program counters for these exception handlers yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
void Compilation::notice_inlined_method(ciMethod* method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  _env->notice_inlined_method(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
void Compilation::bailout(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  assert(msg != NULL, "bailout message must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  if (!bailed_out()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    // keep first bailout message
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    if (PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    _bailout_msg = msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
void Compilation::print_timers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  // tty->print_cr("    Native methods         : %6.3f s, Average : %2.3f", CompileBroker::_t_native_compilation.seconds(), CompileBroker::_t_native_compilation.seconds() / CompileBroker::_total_native_compile_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  float total = timers[_t_setup].seconds() + timers[_t_buildIR].seconds() + timers[_t_emit_lir].seconds() + timers[_t_lir_schedule].seconds() + timers[_t_codeemit].seconds() + timers[_t_codeinstall].seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  tty->print_cr("    Detailed C1 Timings");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  tty->print_cr("       Setup time:        %6.3f s (%4.1f%%)",    timers[_t_setup].seconds(),           (timers[_t_setup].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  tty->print_cr("       Build IR:          %6.3f s (%4.1f%%)",    timers[_t_buildIR].seconds(),         (timers[_t_buildIR].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  tty->print_cr("         Optimize:           %6.3f s (%4.1f%%)", timers[_t_optimizeIR].seconds(),      (timers[_t_optimizeIR].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  tty->print_cr("       Emit LIR:          %6.3f s (%4.1f%%)",    timers[_t_emit_lir].seconds(),        (timers[_t_emit_lir].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  tty->print_cr("         LIR Gen:          %6.3f s (%4.1f%%)",   timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  tty->print_cr("         Linear Scan:      %6.3f s (%4.1f%%)",   timers[_t_linearScan].seconds(),    (timers[_t_linearScan].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  tty->print_cr("       LIR Schedule:      %6.3f s (%4.1f%%)",    timers[_t_lir_schedule].seconds(),  (timers[_t_lir_schedule].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  tty->print_cr("       Code Emission:     %6.3f s (%4.1f%%)",    timers[_t_codeemit].seconds(),        (timers[_t_codeemit].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  tty->print_cr("       Code Installation: %6.3f s (%4.1f%%)",    timers[_t_codeinstall].seconds(),     (timers[_t_codeinstall].seconds() / total) * 100.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  tty->print_cr("       Instruction Nodes: %6d nodes",    totalInstructionNodes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  NOT_PRODUCT(LinearScan::print_statistics());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
void Compilation::compile_only_this_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  fileStream stream(fopen("c1_compile_only", "wt"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  stream.print_cr("# c1 compile only directives");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  compile_only_this_scope(&stream, hir()->top_scope());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  st->print("CompileOnly=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  scope->method()->holder()->name()->print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  st->print(".");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  scope->method()->name()->print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
void Compilation::exclude_this_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  fileStream stream(fopen(".hotspot_compiler", "at"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  stream.print("exclude ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  method()->holder()->name()->print_symbol_on(&stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  stream.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  method()->name()->print_symbol_on(&stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  stream.cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  stream.cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
#endif