hotspot/src/share/vm/c1/c1_Compilation.cpp
author kvn
Fri, 12 Oct 2012 09:22:52 -0700
changeset 13974 791cba24758f
parent 13963 e5b53c306fb5
parent 13964 01a2b863cc61
child 14628 74164bb6ec39
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13883
diff changeset
     2
 * Copyright (c) 1999, 2012, 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: 7389
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    26
#include "c1/c1_CFGPrinter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    27
#include "c1/c1_Compilation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    28
#include "c1/c1_IR.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    29
#include "c1/c1_LIRAssembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    30
#include "c1/c1_LinearScan.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    31
#include "c1/c1_MacroAssembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    32
#include "c1/c1_ValueMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    33
#include "c1/c1_ValueStack.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    34
#include "code/debugInfoRec.hpp"
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    35
#include "compiler/compileLog.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
typedef enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _t_compile,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _t_setup,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _t_optimizeIR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _t_buildIR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _t_emit_lir,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _t_linearScan,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _t_lirGeneration,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _t_lir_schedule,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _t_codeemit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _t_codeinstall,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  max_phase_timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
} TimerName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
static const char * timer_name[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  "compile",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  "setup",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  "optimizeIR",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  "buildIR",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  "emit_lir",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  "linearScan",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  "lirGeneration",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  "lir_schedule",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  "codeemit",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  "codeinstall"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
static elapsedTimer timers[max_phase_timers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
static int totalInstructionNodes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
class PhaseTraceTime: public TraceTime {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  JavaThread* _thread;
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    71
  CompileLog* _log;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
 public:
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    74
  PhaseTraceTime(TimerName timer)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    75
  : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose), _log(NULL) {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    76
    if (Compilation::current() != NULL) {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    77
      _log = Compilation::current()->log();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    78
    }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    79
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    80
    if (_log != NULL) {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    81
      _log->begin_head("phase name='%s'", timer_name[timer]);
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    82
      _log->stamp();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    83
      _log->end_head();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    84
    }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    85
  }
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    86
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    87
  ~PhaseTraceTime() {
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    88
    if (_log != NULL)
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
    89
      _log->done("phase");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// Implementation of Compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void Compilation::maybe_print_current_instruction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    _last_instruction_printed = _current_instruction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    _current_instruction->print_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
DebugInformationRecorder* Compilation::debug_info_recorder() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  return _env->debug_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
Dependencies* Compilation::dependency_recorder() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  return _env->dependencies();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
void Compilation::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Use an oop recorder bound to the CI environment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // (The default oop recorder is ignorant of the CI.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  OopRecorder* ooprec = new OopRecorder(_env->arena());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  _env->set_oop_recorder(ooprec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _env->set_debug_info(new DebugInformationRecorder(ooprec));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  debug_info_recorder()->set_oopmaps(new OopMapSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  _env->set_dependencies(new Dependencies(_env));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void Compilation::build_hir() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // setup ir
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _hir = new IR(this, method(), osr_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  if (!_hir->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    bailout("invalid parsing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (PrintCFGToFile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if (UseC1Optimizations) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    NEEDS_CLEANUP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    // optimization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    PhaseTraceTime timeit(_t_optimizeIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    _hir->optimize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  _hir->split_critical_edges();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // compute block ordering for code generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // the control flow must not be changed from here on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  _hir->compute_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  if (UseGlobalValueNumbering) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    int instructions = Instruction::number_of_instructions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    GlobalValueNumbering gvn(_hir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    assert(instructions == Instruction::number_of_instructions(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
           "shouldn't have created an instructions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // compute use counts after global value numbering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  _hir->compute_use_counts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  if (PrintIR  || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  _hir->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
void Compilation::emit_lir() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  LIRGenerator gen(this, method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    PhaseTraceTime timeit(_t_lirGeneration);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    hir()->iterate_linear_scan_order(&gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    PhaseTraceTime timeit(_t_linearScan);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    set_allocator(allocator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    // Assign physical registers to LIR operands using a linear scan algorithm.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    allocator->do_linear_scan();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    _max_spills = allocator->max_spills();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (BailoutAfterLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    if (PrintLIR && !bailed_out()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      print_LIR(hir()->code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    bailout("Bailing out because of -XX:+BailoutAfterLIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
void Compilation::emit_code_epilog(LIR_Assembler* assembler) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
4752
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   229
  CodeOffsets* code_offsets = assembler->offsets();
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   230
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // generate code or slow cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  assembler->emit_slow_case_stubs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // generate exception adapters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  assembler->emit_exception_entries(exception_info_list());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
4752
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   239
  // Generate code for exception handler.
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   240
  code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  CHECK_BAILOUT();
4752
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   242
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   243
  // Generate code for deopt handler.
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   244
  code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler());
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   245
  CHECK_BAILOUT();
67a506670cd0 6921352: JSR 292 needs its own deopt handler
twisti
parents: 4749
diff changeset
   246
6186
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   247
  // Emit the MethodHandle deopt handler code (if required).
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   248
  if (has_method_handle_invokes()) {
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   249
    // We can use the same code as for the normal deopt handler, we
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   250
    // just need a different entry point address.
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   251
    code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler());
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   252
    CHECK_BAILOUT();
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   253
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
5334
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 4752
diff changeset
   255
  // Emit the handler to remove the activation from the stack and
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 4752
diff changeset
   256
  // dispatch to the caller.
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 4752
diff changeset
   257
  offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler());
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 4752
diff changeset
   258
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  masm()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
7722
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   264
bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) {
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   265
  // Preinitialize the consts section to some large size:
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   266
  int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo));
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   267
  char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   268
  code->insts()->initialize_shared_locs((relocInfo*)locs_buffer,
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   269
                                        locs_buffer_size / sizeof(relocInfo));
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   270
  code->initialize_consts_size(Compilation::desired_max_constant_size());
5897
999579cc3f72 6962980: C1: stub area should take into account method handle deopt stub
iveresov
parents: 5707
diff changeset
   271
  // Call stubs + two deopt handlers (regular and MH) + exception handler
7722
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   272
  int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size) +
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   273
                   LIR_Assembler::exception_handler_size +
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   274
                   (2 * LIR_Assembler::deopt_handler_size);
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   275
  if (stub_size >= code->insts_capacity()) return false;
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   276
  code->initialize_stubs_size(stub_size);
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   277
  return true;
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   278
}
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   279
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   280
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
int Compilation::emit_code_body() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // emit code
7722
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   283
  if (!setup_code_buffer(code(), allocator()->num_calls())) {
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   284
    BAILOUT_("size requested greater than avail code buffer size", 0);
f0bd3dd3192f 7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents: 7432
diff changeset
   285
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  code()->initialize_oop_recorder(env()->oop_recorder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  _masm = new C1_MacroAssembler(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  _masm->set_oop_recorder(env()->oop_recorder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  LIR_Assembler lir_asm(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  lir_asm.emit_code(hir()->code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  CHECK_BAILOUT_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  emit_code_epilog(&lir_asm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  CHECK_BAILOUT_(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  generate_exception_handler_table();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  if (PrintExceptionHandlers && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    exception_handler_table()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
#endif /* PRODUCT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  return frame_map()->framesize();
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
int Compilation::compile_java_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  assert(!method()->is_native(), "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (BailoutOnExceptionHandlers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    if (method()->has_exception_handlers()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      bailout("linear scan can't handle exception handlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  CHECK_BAILOUT_(no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7397
diff changeset
   322
  if (is_profiling() && !method()->ensure_method_data()) {
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7397
diff changeset
   323
    BAILOUT_("mdo allocation failed", no_frame_size);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6418
diff changeset
   324
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6418
diff changeset
   325
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    PhaseTraceTime timeit(_t_buildIR);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6418
diff changeset
   328
    build_hir();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  if (BailoutAfterHIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    PhaseTraceTime timeit(_t_emit_lir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    emit_lir();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  CHECK_BAILOUT_(no_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    PhaseTraceTime timeit(_t_codeemit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    return emit_code_body();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
void Compilation::install_code(int frame_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // frame_size is in 32-bit words so adjust it intptr_t words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  assert(frame_size == frame_map()->framesize(), "must match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  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
   353
  _env->register_method(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    method(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    osr_bci(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    &_offsets,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    in_bytes(_frame_map->sp_offset_for_orig_pc()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    code(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    debug_info_recorder()->_oopmaps,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    exception_handler_table(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    implicit_exception_table(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    compiler(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    _env->comp_level(),
13883
6979b9850feb 7196199: java/text/Bidi/Bug6665028.java failed: Bidi run count incorrect
kvn
parents: 13391
diff changeset
   365
    has_unsafe_access(),
6979b9850feb 7196199: java/text/Bidi/Bug6665028.java failed: Bidi run count incorrect
kvn
parents: 13391
diff changeset
   366
    SharedRuntime::is_wide_vector(max_vector_size())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
void Compilation::compile_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // setup compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (!method()->can_be_compiled()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // Prevent race condition 6328518.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // This can happen if the method is obsolete or breakpointed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    bailout("Bailing out because method is not compilable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
2867
69187054225f 6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents: 1
diff changeset
   382
  if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    // We can assert evol_method because method->can_be_compiled is true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    dependency_recorder()->assert_evol_method(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  if (method()->break_at_execute()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    BREAKPOINT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  if (PrintCFGToFile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    CFGPrinter::print_compilation(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  // compile method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  int frame_size = compile_java_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // bailout if method couldn't be compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // Note: make sure we mark the method as not compilable!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  if (InstallMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    // install code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    PhaseTraceTime timeit(_t_codeinstall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    install_code(frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  }
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
   409
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
   410
  if (log() != NULL) // Print code cache state into compiler log
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
   411
    log()->code_cache_state();
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
   412
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  totalInstructionNodes += Instruction::number_of_instructions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
void Compilation::generate_exception_handler_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // Generate an ExceptionHandlerTable from the exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // information accumulated during the compilation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  ExceptionInfoList* info_list = exception_info_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  if (info_list->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  // allocate some arrays for use by the collection code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  const int num_handlers = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  for (int i = 0; i < info_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    ExceptionInfo* info = info_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    XHandlers* handlers = info->exception_handlers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    // empty the arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    bcis->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    scope_depths->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    pcos->trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    for (int i = 0; i < handlers->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      XHandler* handler = handlers->handler_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      assert(handler->entry_pco() != -1, "must have been generated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      int e = bcis->find(handler->handler_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        // two different handlers are declared to dispatch to the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        // catch bci.  During parsing we created edges for each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        // handler but we really only need one.  The exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        // table will also get unhappy if we try to declare both since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        // it's nonsensical.  Just skip this handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      bcis->append(handler->handler_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      if (handler->handler_bci() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
        // insert a wildcard handler at scope depth 0 so that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
        // exception lookup logic with find it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        scope_depths->append(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
        scope_depths->append(handler->scope_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      pcos->append(handler->entry_pco());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      // stop processing once we hit a catch any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      if (handler->is_catch_all()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
        assert(i == handlers->length() - 1, "catch all must be last handler");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   475
Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   476
                         int osr_bci, BufferBlob* buffer_blob)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
: _compiler(compiler)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
, _env(env)
13964
01a2b863cc61 7177003: C1: LogCompilation support
vlivanov
parents: 13883
diff changeset
   479
, _log(env->log())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
, _method(method)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
, _osr_bci(osr_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
, _hir(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
, _max_spills(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
, _frame_map(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
, _masm(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
, _has_exception_handlers(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
, _has_fpu_code(true)   // pessimistic assumption
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6418
diff changeset
   488
, _would_profile(false)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
, _has_unsafe_access(false)
6186
7eef4cda471c 6975855: don't emit deopt MH handler in C1 if not required
twisti
parents: 5897
diff changeset
   490
, _has_method_handle_invokes(false)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
, _bailout_msg(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
, _exception_info_list(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
, _allocator(NULL)
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   494
, _next_id(0)
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   495
, _next_block_id(0)
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6186
diff changeset
   496
, _code(buffer_blob)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
, _current_instruction(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
, _last_instruction_printed(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  PhaseTraceTime timeit(_t_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  _arena = Thread::current()->resource_area();
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   504
  _env->set_compiler_data(this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  _exception_info_list = new ExceptionInfoList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  _implicit_exception_table.set_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  compile_method();
7389
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   508
  if (bailed_out()) {
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   509
    _env->record_method_not_compilable(bailout_msg(), !TieredCompilation);
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   510
    if (is_profiling()) {
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   511
      // Compilation failed, create MDO, which would signal the interpreter
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   512
      // to start profiling on its own.
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7397
diff changeset
   513
      _method->ensure_method_data();
7389
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   514
    }
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7722
diff changeset
   515
  } else if (is_profiling()) {
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7397
diff changeset
   516
    ciMethodData *md = method->method_data_or_null();
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7722
diff changeset
   517
    if (md != NULL) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7722
diff changeset
   518
      md->set_would_profile(_would_profile);
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7722
diff changeset
   519
    }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6418
diff changeset
   520
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
Compilation::~Compilation() {
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   524
  _env->set_compiler_data(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  if (PrintExceptionHandlers && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    tty->print_cr("  added exception scope for pco %d", pco);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  // Note: we do not have program counters for these exception handlers yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
void Compilation::notice_inlined_method(ciMethod* method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  _env->notice_inlined_method(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
void Compilation::bailout(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  assert(msg != NULL, "bailout message must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  if (!bailed_out()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    // keep first bailout message
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10508
diff changeset
   548
    if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    _bailout_msg = msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
void Compilation::print_timers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  // 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
   556
  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
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  tty->print_cr("    Detailed C1 Timings");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  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
   561
  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
   562
  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
   563
  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
   564
  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
   565
  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
   566
  NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  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
   568
  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
   569
  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
   570
  tty->print_cr("       Instruction Nodes: %6d nodes",    totalInstructionNodes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  NOT_PRODUCT(LinearScan::print_statistics());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
void Compilation::compile_only_this_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  fileStream stream(fopen("c1_compile_only", "wt"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  stream.print_cr("# c1 compile only directives");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  compile_only_this_scope(&stream, hir()->top_scope());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  st->print("CompileOnly=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  scope->method()->holder()->name()->print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  st->print(".");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  scope->method()->name()->print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
void Compilation::exclude_this_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  fileStream stream(fopen(".hotspot_compiler", "at"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  stream.print("exclude ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  method()->holder()->name()->print_symbol_on(&stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  stream.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  method()->name()->print_symbol_on(&stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  stream.cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  stream.cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
#endif