hotspot/src/share/vm/c1/c1_IR.hpp
author jrose
Wed, 02 Jun 2010 22:45:42 -0700
changeset 5702 201c5cde25bb
parent 5547 f4b087cbb361
parent 5687 b862d1f189bd
child 5707 6c66849ed24e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5046
diff changeset
     2
 * Copyright (c) 1999, 2010, 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: 5046
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5046
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: 5046
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// An XHandler is a C1 internal description for an exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
class XHandler: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  ciExceptionHandler* _desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  BlockBegin*         _entry_block;  // Entry block of xhandler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  LIR_List*           _entry_code;   // LIR-operations that must be executed before jumping to entry_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  int                 _entry_pco;    // pco where entry_code (or entry_block if no entry_code) starts
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  int                 _phi_operand;  // For resolving of phi functions at begin of entry_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  int                 _scope_count;  // for filling ExceptionRangeEntry::scope_count
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  int                 _lir_op_id;    // op_id of the LIR-operation throwing to this handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  XHandler(ciExceptionHandler* desc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    : _desc(desc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    , _entry_block(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    , _entry_code(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    , _entry_pco(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    , _phi_operand(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    , _scope_count(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    , _lir_op_id(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  XHandler(XHandler* other)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    : _desc(other->_desc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    , _entry_block(other->_entry_block)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    , _entry_code(other->_entry_code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    , _entry_pco(other->_entry_pco)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    , _phi_operand(other->_phi_operand)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    , _scope_count(other->_scope_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    , _lir_op_id(other->_lir_op_id)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // accessors for data of ciExceptionHandler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int  beg_bci() const                           { return _desc->start(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int  end_bci() const                           { return _desc->limit(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int  handler_bci() const                       { return _desc->handler_bci(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  bool is_catch_all() const                      { return _desc->is_catch_all(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  int  catch_type() const                        { return _desc->catch_klass_index(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  ciInstanceKlass* catch_klass() const           { return _desc->catch_klass(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  bool covers(int bci) const                     { return beg_bci() <= bci && bci < end_bci(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // accessors for additional fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  BlockBegin* entry_block() const                { return _entry_block; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  LIR_List*   entry_code() const                 { return _entry_code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int         entry_pco() const                  { return _entry_pco; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  int         phi_operand() const                { assert(_phi_operand != -1, "not set"); return _phi_operand; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  int         scope_count() const                { assert(_scope_count != -1, "not set"); return _scope_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  DEBUG_ONLY(int lir_op_id() const               { return _lir_op_id; });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void set_entry_block(BlockBegin* entry_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    assert(entry_block->bci() == handler_bci(), "bci's must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    _entry_block = entry_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  void set_entry_code(LIR_List* entry_code)      { _entry_code = entry_code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void set_entry_pco(int entry_pco)              { _entry_pco = entry_pco; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void set_phi_operand(int phi_operand)          { _phi_operand = phi_operand; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void set_scope_count(int scope_count)          { _scope_count = scope_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  DEBUG_ONLY(void set_lir_op_id(int lir_op_id)   { _lir_op_id = lir_op_id; });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  bool equals(XHandler* other) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
define_array(_XHandlerArray, XHandler*)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
define_stack(_XHandlerList, _XHandlerArray)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// XHandlers is the C1 internal list of exception handlers for a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
class XHandlers: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  _XHandlerList    _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  XHandlers() : _list()                          { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  XHandlers(ciMethod* method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  XHandlers(XHandlers* other);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  int       length() const                       { return _list.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  XHandler* handler_at(int i) const              { return _list.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  bool      has_handlers() const                 { return _list.length() > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  void      append(XHandler* h)                  { _list.append(h); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  XHandler* remove_last()                        { return _list.pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  bool      could_catch(ciInstanceKlass* klass, bool type_is_exact) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  bool      equals(XHandlers* others) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
class IRScope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
define_array(IRScopeArray, IRScope*)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
define_stack(IRScopeList, IRScopeArray)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
class Compilation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
class IRScope: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // hierarchy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  Compilation*  _compilation;                    // the current compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  IRScope*      _caller;                         // the caller scope, or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  int           _caller_bci;                     // the caller bci of the corresponding (inlined) invoke, or < 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  ValueStack*   _caller_state;                   // the caller state, or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int           _level;                          // the inlining level
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ciMethod*     _method;                         // the corresponding method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  IRScopeList   _callees;                        // the inlined method scopes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  XHandlers*    _xhandlers;                      // the exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  int           _number_of_locks;                // the number of monitor lock slots needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  bool          _monitor_pairing_ok;             // the monitor pairing info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  BlockBegin*   _start;                          // the start block, successsors are method entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // lock stack management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  int           _lock_stack_size;                // number of expression stack elements which, if present,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                                                 // must be spilled to the stack because of exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
                                                 // handling inside inlined methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  BitMap        _requires_phi_function;          // bit is set if phi functions at loop headers are necessary for a local variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  BlockBegin* build_graph(Compilation* compilation, int osr_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  Compilation*  compilation() const              { return _compilation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  IRScope*      caller() const                   { return _caller; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  int           caller_bci() const               { return _caller_bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  ValueStack*   caller_state() const             { return _caller_state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  int           level() const                    { return _level; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  ciMethod*     method() const                   { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  int           max_stack() const;               // NOTE: expensive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  int           lock_stack_size() const          {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    assert(_lock_stack_size != -1, "uninitialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return _lock_stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  BitMap&       requires_phi_function()          { return _requires_phi_function; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // mutators
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Needed because caller state is not ready at time of IRScope construction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  void          set_caller_state(ValueStack* state) { _caller_state = state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Needed because caller state changes after IRScope construction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // Computes number of expression stack elements whose state must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // preserved in the case of an exception; these may be seen by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // caller scopes. Zero when inlining of methods containing exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // handlers is disabled, otherwise a conservative approximation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  void          compute_lock_stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // hierarchy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  bool          is_top_scope() const             { return _caller == NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  void          add_callee(IRScope* callee)      { _callees.append(callee); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  int           number_of_callees() const        { return _callees.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  IRScope*      callee_no(int i) const           { return _callees.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  int           top_scope_bci() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // accessors, graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  bool          is_valid() const                 { return start() != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  XHandlers*    xhandlers() const                { return _xhandlers; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  int           number_of_locks() const          { return _number_of_locks; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  void          set_min_number_of_locks(int n)   { if (n > _number_of_locks) _number_of_locks = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  bool          monitor_pairing_ok() const       { return _monitor_pairing_ok; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  BlockBegin*   start() const                    { return _start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
};
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
// IRScopeDebugInfo records the debug information for a particular IRScope
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// in a particular CodeEmitInfo.  This allows the information to be computed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// once early enough for the OopMap to be available to the LIR and also to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// reemited for different pcs using the same CodeEmitInfo without recomputing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// everything.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
class IRScopeDebugInfo: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  IRScope*                      _scope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  int                           _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  GrowableArray<ScopeValue*>*   _locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  GrowableArray<ScopeValue*>*   _expressions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  GrowableArray<MonitorValue*>* _monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  IRScopeDebugInfo*             _caller;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  IRScopeDebugInfo(IRScope*                      scope,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
                   int                           bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
                   GrowableArray<ScopeValue*>*   locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                   GrowableArray<ScopeValue*>*   expressions,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                   GrowableArray<MonitorValue*>* monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                   IRScopeDebugInfo*             caller):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      _scope(scope)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    , _locals(locals)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    , _bci(bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    , _expressions(expressions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    , _monitors(monitors)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    , _caller(caller) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  IRScope*                      scope()       { return _scope;       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  int                           bci()         { return _bci;         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  GrowableArray<ScopeValue*>*   locals()      { return _locals;      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  GrowableArray<ScopeValue*>*   expressions() { return _expressions; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  GrowableArray<MonitorValue*>* monitors()    { return _monitors;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  IRScopeDebugInfo*             caller()      { return _caller;      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
3600
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   242
  //Whether we should reexecute this bytecode for deopt
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   243
  bool should_reexecute();
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   244
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4894
diff changeset
   245
  void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost, bool is_method_handle_invoke = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (caller() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      // Order is significant:  Must record caller first.
3600
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   248
      caller()->record_debug_info(recorder, pc_offset, false/*topmost*/);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    DebugToken* locvals = recorder->create_scope_values(locals());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    DebugToken* expvals = recorder->create_scope_values(expressions());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    DebugToken* monvals = recorder->create_monitor_values(monitors());
3600
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   253
    // reexecute allowed only for the topmost frame
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3795
diff changeset
   254
    bool reexecute = topmost ? should_reexecute() : false;
4894
8a76fd3d098d 6910618: C2: Error: assert(d->is_oop(),"JVM_ArrayCopy: dst not an oop")
kvn
parents: 4564
diff changeset
   255
    bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.
8a76fd3d098d 6910618: C2: Error: assert(d->is_oop(),"JVM_ArrayCopy: dst not an oop")
kvn
parents: 4564
diff changeset
   256
    recorder->describe_scope(pc_offset, scope()->method(), bci(), reexecute, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
class CodeEmitInfo: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  friend class LinearScan;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  IRScopeDebugInfo* _scope_debug_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  IRScope*          _scope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  XHandlers*        _exception_handlers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  OopMap*           _oop_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  ValueStack*       _stack;                      // used by deoptimization (contains also monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  int               _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  CodeEmitInfo*     _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  int               _id;
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   272
  bool              _is_method_handle_invoke;    // true if the associated call site is a MethodHandle call site.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  FrameMap*     frame_map() const                { return scope()->compilation()->frame_map(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  Compilation*  compilation() const              { return scope()->compilation(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // use scope from ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  CodeEmitInfo(int bci, ValueStack* stack, XHandlers* exception_handlers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // used by natives
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  CodeEmitInfo(IRScope* scope, int bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    : _scope(scope)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    , _bci(bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    , _oop_map(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    , _scope_debug_info(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    , _stack(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    , _exception_handlers(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    , _next(NULL)
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   291
    , _id(-1)
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   292
    , _is_method_handle_invoke(false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // make a copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  CodeEmitInfo(CodeEmitInfo* info, bool lock_stack_only = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  OopMap* oop_map()                              { return _oop_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  ciMethod* method() const                       { return _scope->method(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  IRScope* scope() const                         { return _scope; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  XHandlers* exception_handlers() const          { return _exception_handlers; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  ValueStack* stack() const                      { return _stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  int bci() const                                { return _bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  void add_register_oop(LIR_Opr opr);
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   307
  void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  CodeEmitInfo* next() const        { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  void set_next(CodeEmitInfo* next) { _next = next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  int id() const      { return _id; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  void set_id(int id) { _id = id; }
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   314
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   315
  bool     is_method_handle_invoke() const { return _is_method_handle_invoke;     }
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5046
diff changeset
   316
  void set_is_method_handle_invoke(bool x) {        _is_method_handle_invoke = x; }
1
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
class IR: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  Compilation*     _compilation;                 // the current compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  IRScope*         _top_scope;                   // the root of the scope hierarchy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  WordSize         _locals_size;                 // the space required for all locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  int              _num_loops;                   // Total number of loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  BlockList*       _code;                        // the blocks in code generation order w/ use counts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  IR(Compilation* compilation, ciMethod* method, int osr_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  bool             is_valid() const              { return top_scope()->is_valid(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  Compilation*     compilation() const           { return _compilation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  IRScope*         top_scope() const             { return _top_scope; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  int              number_of_locks() const       { return top_scope()->number_of_locks(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  ciMethod*        method() const                { return top_scope()->method(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  BlockBegin*      start() const                 { return top_scope()->start(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  BlockBegin*      std_entry() const             { return start()->end()->as_Base()->std_entry(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  BlockBegin*      osr_entry() const             { return start()->end()->as_Base()->osr_entry(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  WordSize         locals_size() const           { return _locals_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  int              locals_size_in_words() const  { return in_words(_locals_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  BlockList*       code() const                  { return _code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  int              num_loops() const             { return _num_loops; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  int              max_stack() const             { return top_scope()->max_stack(); } // expensive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  // ir manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  void optimize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  void compute_predecessors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  void split_critical_edges();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  void compute_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  void compute_use_counts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  // The linear-scan order and the code emission order are equal, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // this may change in future
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  BlockList* linear_scan_order() {  assert(_code != NULL, "not computed"); return _code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  // iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  void iterate_preorder   (BlockClosure* closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  void iterate_postorder  (BlockClosure* closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  void iterate_linear_scan_order(BlockClosure* closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  void print(bool cfg_only, bool live_only = false)                           PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  void verify()                                                               PRODUCT_RETURN;
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
// Globally do instruction substitution and remove substituted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
// instructions from the instruction list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
class SubstitutionResolver: public BlockClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  static void substitute(Value* v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  SubstitutionResolver(IR* hir) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    hir->iterate_preorder(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  SubstitutionResolver(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    block->iterate_preorder(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  virtual void block_do(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
};