hotspot/src/share/vm/ci/ciMethodBlocks.cpp
author twisti
Wed, 11 Aug 2010 05:51:21 -0700
changeset 6187 4fa7845f7c14
parent 6180 53c1bf468c81
child 7397 5b173b4ca846
permissions -rw-r--r--
6976186: integrate Shark HotSpot changes Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure. Reviewed-by: kvn, twisti Contributed-by: Gary Benson <gbenson@redhat.com>
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: 3261
diff changeset
     2
 * Copyright (c) 2006, 2009, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_ciMethodBlocks.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// ciMethodBlocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
ciBlock *ciMethodBlocks::block_containing(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  ciBlock *blk = _bci_to_block[bci];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  return blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
bool ciMethodBlocks::is_block_start(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(bci >=0 && bci < _code_size, "valid bytecode range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ciBlock *b = _bci_to_block[bci];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert(b != NULL, "must have block for bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  return b->start_bci() == bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// ciMethodBlocks::split_block_at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// Split the block spanning bci into two separate ranges.  The former
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// block becomes the second half and a new range is created for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// first half.  Returns the range beginning at bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
ciBlock *ciMethodBlocks::split_block_at(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ciBlock *former_block = block_containing(bci);
1399
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
    52
  ciBlock *new_block = new(_arena) ciBlock(_method, _num_blocks++, former_block->start_bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _blocks->append(new_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(former_block != NULL, "must not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  new_block->set_limit_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  former_block->set_start_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  for (int pos=bci-1; pos >= 0; pos--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    ciBlock *current_block = block_containing(pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    if (current_block == former_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // Replace it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      _bci_to_block[pos] = new_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    } else if (current_block == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      // Non-bytecode start.  Skip.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      // We are done with our backwards walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    70
  // Move an exception handler information if needed.
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    71
  if (former_block->is_handler()) {
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    72
    int ex_start = former_block->ex_start_bci();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    73
    int ex_end = former_block->ex_limit_bci();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    74
    new_block->set_exception_range(ex_start, ex_end);
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    75
    // Clear information in former_block.
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    76
    former_block->clear_exception_handler();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
    77
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  return former_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
ciBlock *ciMethodBlocks::make_block_at(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  ciBlock *cb = block_containing(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (cb == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // This is our first time visiting this bytecode.  Create
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // a fresh block and assign it this starting point.
1399
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
    86
    ciBlock *nb = new(_arena) ciBlock(_method, _num_blocks++, bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    _blocks->append(nb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
     _bci_to_block[bci] = nb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    return nb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  } else if (cb->start_bci() == bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    // The block begins at bci.  Simply return it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    // We have already created a block containing bci but
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // not starting at bci.  This existing block needs to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // be split into two.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return split_block_at(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
1399
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   101
ciBlock *ciMethodBlocks::make_dummy_block() {
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   102
  ciBlock *dum = new(_arena) ciBlock(_method, -1, 0);
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   103
  return dum;
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   104
}
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   105
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void ciMethodBlocks::do_analysis() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  ciBytecodeStream s(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  ciBlock *cur_block = block_containing(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  int limit_bci = _method->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  while (s.next() != ciBytecodeStream::EOBC()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    int bci = s.cur_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // Determine if a new block has been made at the current bci.  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // this block differs from our current range, switch to the new
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // one and end the old one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    assert(cur_block != NULL, "must always have a current block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    ciBlock *new_block = block_containing(bci);
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   118
    if (new_block == NULL || new_block == cur_block) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      // We have not marked this bci as the start of a new block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      // Keep interpreting the current_range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      _bci_to_block[bci] = cur_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      cur_block->set_limit_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      cur_block = new_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    switch (s.cur_bc()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      case Bytecodes::_ifeq        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      case Bytecodes::_ifne        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      case Bytecodes::_iflt        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      case Bytecodes::_ifge        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      case Bytecodes::_ifgt        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      case Bytecodes::_ifle        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      case Bytecodes::_if_icmpeq   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      case Bytecodes::_if_icmpne   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      case Bytecodes::_if_icmplt   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      case Bytecodes::_if_icmpge   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      case Bytecodes::_if_icmpgt   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      case Bytecodes::_if_icmple   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      case Bytecodes::_if_acmpeq   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      case Bytecodes::_if_acmpne   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      case Bytecodes::_ifnull      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      case Bytecodes::_ifnonnull   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        ciBlock *fall_through = make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        int dest_bci = s.get_dest();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        ciBlock *dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      case Bytecodes::_goto        :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        if (s.next_bci() < limit_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          (void) make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        int dest_bci = s.get_dest();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        ciBlock *dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      case Bytecodes::_jsr         :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        ciBlock *ret = make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        int dest_bci = s.get_dest();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        ciBlock *dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      case Bytecodes::_tableswitch :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
          cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
          Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
          int len = switch_->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
          ciBlock *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
          int dest_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
            dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
            dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
          dest_bci = s.cur_bci() + switch_->default_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
          make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          if (s.next_bci() < limit_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
            dest = make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
          cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
          Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
          int len = switch_->number_of_pairs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
          ciBlock *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
          int dest_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
          for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
            dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
            dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
          dest_bci = s.cur_bci() + switch_->default_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
          dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
          if (s.next_bci() < limit_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
            dest = make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      case Bytecodes::_goto_w      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        if (s.next_bci() < limit_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
          (void) make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        int dest_bci = s.get_far_dest();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        ciBlock *dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      case Bytecodes::_jsr_w       :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        ciBlock *ret = make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        int dest_bci = s.get_far_dest();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        ciBlock *dest = make_block_at(dest_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      case Bytecodes::_athrow      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        cur_block->set_may_throw();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        // fall-through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      case Bytecodes::_ret         :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      case Bytecodes::_ireturn     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      case Bytecodes::_lreturn     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      case Bytecodes::_freturn     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      case Bytecodes::_dreturn     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      case Bytecodes::_areturn     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      case Bytecodes::_return      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        cur_block->set_control_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        if (s.next_bci() < limit_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
          (void) make_block_at(s.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  //  End the last block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  cur_block->set_limit_bci(limit_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
ciMethodBlocks::ciMethodBlocks(Arena *arena, ciMethod *meth): _method(meth),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                          _arena(arena), _num_blocks(0), _code_size(meth->code_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  int block_estimate = _code_size / 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   255
  _blocks =  new(_arena) GrowableArray<ciBlock *>(_arena, block_estimate, 0, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  int b2bsize = _code_size * sizeof(ciBlock **);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  _bci_to_block = (ciBlock **) arena->Amalloc(b2bsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  Copy::zero_to_words((HeapWord*) _bci_to_block, b2bsize / sizeof(HeapWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // create initial block covering the entire method
1399
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   261
  ciBlock *b = new(arena) ciBlock(_method, _num_blocks++, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  _blocks->append(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  _bci_to_block[0] = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // create blocks for exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  if (meth->has_exception_handlers()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    for(ciExceptionHandlerStream str(meth); !str.is_done(); str.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      ciExceptionHandler* handler = str.handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      ciBlock *eb = make_block_at(handler->handler_bci());
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   270
      //
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   271
      // Several exception handlers can have the same handler_bci:
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   272
      //
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   273
      //  try {
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   274
      //    if (a.foo(b) < 0) {
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   275
      //      return a.error();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   276
      //    }
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   277
      //    return CoderResult.UNDERFLOW;
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   278
      //  } finally {
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   279
      //      a.position(b);
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   280
      //  }
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   281
      //
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   282
      //  The try block above is divided into 2 exception blocks
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   283
      //  separated by 'areturn' bci.
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   284
      //
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      int ex_start = handler->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      int ex_end = handler->limit();
2258
020bda12ecd4 6772368: REGRESSION:tomcat crashed twice with JDK 7
kvn
parents: 1399
diff changeset
   287
      // ensure a block at the start of exception range and start of following code
020bda12ecd4 6772368: REGRESSION:tomcat crashed twice with JDK 7
kvn
parents: 1399
diff changeset
   288
      (void) make_block_at(ex_start);
020bda12ecd4 6772368: REGRESSION:tomcat crashed twice with JDK 7
kvn
parents: 1399
diff changeset
   289
      if (ex_end < _code_size)
020bda12ecd4 6772368: REGRESSION:tomcat crashed twice with JDK 7
kvn
parents: 1399
diff changeset
   290
        (void) make_block_at(ex_end);
020bda12ecd4 6772368: REGRESSION:tomcat crashed twice with JDK 7
kvn
parents: 1399
diff changeset
   291
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   292
      if (eb->is_handler()) {
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   293
        // Extend old handler exception range to cover additional range.
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   294
        int old_ex_start = eb->ex_start_bci();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   295
        int old_ex_end   = eb->ex_limit_bci();
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   296
        if (ex_start > old_ex_start)
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   297
          ex_start = old_ex_start;
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   298
        if (ex_end < old_ex_end)
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   299
          ex_end = old_ex_end;
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   300
        eb->clear_exception_handler(); // Reset exception information
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   301
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      eb->set_exception_range(ex_start, ex_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // scan the bytecodes and identify blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  do_analysis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // mark blocks that have exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  if (meth->has_exception_handlers()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    for(ciExceptionHandlerStream str(meth); !str.is_done(); str.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      ciExceptionHandler* handler = str.handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      int ex_start = handler->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      int ex_end = handler->limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      int bci = ex_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      while (bci < ex_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        ciBlock *b = block_containing(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        b->set_has_handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        bci = b->limit_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
void ciMethodBlocks::clear_processed() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  for (int i = 0; i < _blocks->length(); i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    _blocks->at(i)->clear_processed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
void ciMethodBlocks::dump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  tty->print("---- blocks for method: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  _method->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  for (int i = 0; i < _blocks->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    tty->print("  B%d: ", i); _blocks->at(i)->dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
1399
9648dfd4ce09 6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents: 958
diff changeset
   343
ciBlock::ciBlock(ciMethod *method, int index, int start_bci) :
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
                         _method(method),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                         _idx(index), _flags(0), _start_bci(start_bci), _limit_bci(-1), _control_bci(fall_through_bci),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
                         _ex_start_bci(-1), _ex_limit_bci(-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
void ciBlock::set_exception_range(int start_bci, int limit_bci)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
   assert(limit_bci >= start_bci, "valid range");
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   353
   assert(!is_handler() && _ex_start_bci == -1 && _ex_limit_bci == -1, "must not be handler");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
   _ex_start_bci = start_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
   _ex_limit_bci = limit_bci;
199
fb51d01039ff 6621084: ciMethodBlocks::split_block_at() is broken for methods with exception handler
kvn
parents: 1
diff changeset
   356
   set_handler();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
#ifndef PRODUCT
958
4c4709e8b7ee 6712835: Server compiler fails with assertion (loop_count < K,"infinite loop in PhaseIterGVN::transform")
never
parents: 670
diff changeset
   360
static const char *flagnames[] = {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  "Processed",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  "Handler",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  "MayThrow",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  "Jsr",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  "Ret",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  "RetTarget",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  "HasHandler",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
void ciBlock::dump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  tty->print(" [%d .. %d), {", _start_bci, _limit_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  for (int i = 0; i < 8; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if ((_flags & (1 << i)) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      tty->print(" %s", flagnames[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  tty->print(" ]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  if (is_handler())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    tty->print(" handles(%d..%d)", _ex_start_bci, _ex_limit_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
// ciBlock::print_on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
void ciBlock::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  st->print_cr("--------------------------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  st->print   ("ciBlock [%d - %d) control : ", start_bci(), limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  if (control_bci() == fall_through_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    st->print_cr("%d:fall through", limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    st->print_cr("%d:%s", control_bci(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        Bytecodes::name(method()->java_code_at_bci(control_bci())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  if (Verbose || WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    method()->print_codes_on(start_bci(), limit_bci(), st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
#endif