src/hotspot/share/compiler/methodLiveness.cpp
author redestad
Sun, 13 Jan 2019 12:50:05 +0100
changeset 53264 424e4908b4b8
parent 51333 f6641fcf7b7e
child 53265 febc37adfe80
permissions -rw-r--r--
8216424: Remove TimeLivenessAnalysis Reviewed-by: kvn, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53264
424e4908b4b8 8216424: Remove TimeLivenessAnalysis
redestad
parents: 51333
diff changeset
     2
 * Copyright (c) 1998, 2019, 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: 4564
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4564
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: 4564
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "ci/ciMethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciMethodBlocks.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciStreams.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "compiler/methodLiveness.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "interpreter/bytecode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "interpreter/bytecodes.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37161
diff changeset
    33
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/bitMap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// The MethodLiveness class performs a simple liveness analysis on a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// in order to decide which locals are live (that is, will be used again) at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// a particular bytecode index (bci).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// The algorithm goes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// 1. Break the method into a set of basic blocks.  For each basic block we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//    also keep track of its set of predecessors through normal control flow
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//    and predecessors through exceptional control flow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// 2. For each basic block, compute two sets, gen (the set of values used before
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//    they are defined) and kill (the set of values defined before they are used)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//    in the basic block.  A basic block "needs" the locals in its gen set to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//    perform its computation.  A basic block "provides" values for the locals in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//    its kill set, allowing a need from a successor to be ignored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// 3. Liveness information (the set of locals which are needed) is pushed backwards through
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//    the program, from blocks to their predecessors.  We compute and store liveness
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//    information for the normal/exceptional exit paths for each basic block.  When
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//    this process reaches a fixed point, we are done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// 4. When we are asked about the liveness at a particular bci with a basic block, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//    compute gen/kill sets which represent execution from that bci to the exit of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//    its blocks.  We then compose this range gen/kill information with the normal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
//    and exceptional exit information for the block to produce liveness information
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//    at that bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// The algorithm is approximate in many respects.  Notably:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// 1. We do not do the analysis necessary to match jsr's with the appropriate ret.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
//    Instead we make the conservative assumption that any ret can return to any
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//    jsr return site.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// 2. Instead of computing the effects of exceptions at every instruction, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//    summarize the effects of all exceptional continuations from the block as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
//    a single set (_exception_exit), losing some information but simplifying the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
//    analysis.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
MethodLiveness::MethodLiveness(Arena* arena, ciMethod* method)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
#ifdef COMPILER1
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
    75
  : _bci_block_start(arena, method->code_size())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _arena = arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _bit_map_size_bits = method->max_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void MethodLiveness::compute_liveness() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  if (TraceLivenessGen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    tty->print_cr("################################################################");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    tty->print("# Computing liveness information for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    method()->print_short_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
53264
424e4908b4b8 8216424: Remove TimeLivenessAnalysis
redestad
parents: 51333
diff changeset
    92
  init_basic_blocks();
424e4908b4b8 8216424: Remove TimeLivenessAnalysis
redestad
parents: 51333
diff changeset
    93
  init_gen_kill();
424e4908b4b8 8216424: Remove TimeLivenessAnalysis
redestad
parents: 51333
diff changeset
    94
  propagate_liveness();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void MethodLiveness::init_basic_blocks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  bool bailout = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  int method_len = method()->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  ciMethodBlocks *mblocks = method()->get_method_blocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Create an array to store the bci->BasicBlock mapping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  _block_map = new (arena()) GrowableArray<BasicBlock*>(arena(), method_len, method_len, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _block_count = mblocks->num_blocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _block_list = (BasicBlock **) arena()->Amalloc(sizeof(BasicBlock *) * _block_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Used for patching up jsr/ret control flow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  GrowableArray<BasicBlock*>* jsr_exit_list = new GrowableArray<BasicBlock*>(5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  GrowableArray<BasicBlock*>* ret_list = new GrowableArray<BasicBlock*>(5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // generate our block list from ciMethodBlocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  for (int blk = 0; blk < _block_count; blk++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    ciBlock *cib = mblocks->block(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
     int start_bci = cib->start_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    _block_list[blk] = new (arena()) BasicBlock(this, start_bci, cib->limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _block_map->at_put(start_bci, _block_list[blk]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
#ifdef COMPILER1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // mark all bcis where a new basic block starts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    _bci_block_start.set_bit(start_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#endif // COMPILER1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // fill in the predecessors of blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  ciBytecodeStream bytes(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  for (int blk = 0; blk < _block_count; blk++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    BasicBlock *current_block = _block_list[blk];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    int bci =  mblocks->block(blk)->control_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    if (bci == ciBlock::fall_through_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      int limit = current_block->limit_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      if (limit < method_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        BasicBlock *next = _block_map->at(limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        assert( next != NULL, "must be a block immediately following this one.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        next->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    bytes.reset_to_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    Bytecodes::Code code = bytes.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    BasicBlock *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    // Now we need to interpret the instruction's effect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    // on control flow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    assert (current_block != NULL, "we must have a current block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    switch (code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      case Bytecodes::_ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      case Bytecodes::_ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      case Bytecodes::_iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      case Bytecodes::_ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      case Bytecodes::_ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      case Bytecodes::_ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      case Bytecodes::_if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      case Bytecodes::_if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      case Bytecodes::_if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      case Bytecodes::_if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      case Bytecodes::_if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      case Bytecodes::_if_icmple:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      case Bytecodes::_if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      case Bytecodes::_if_acmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      case Bytecodes::_ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      case Bytecodes::_ifnonnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        // Two way branch.  Set predecessors at each destination.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        dest = _block_map->at(bytes.next_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        assert(dest != NULL, "must be a block immediately following this one.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        dest = _block_map->at(bytes.get_dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      case Bytecodes::_goto:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        dest = _block_map->at(bytes.get_dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      case Bytecodes::_goto_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        dest = _block_map->at(bytes.get_far_dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      case Bytecodes::_tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        {
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   186
          Bytecode_tableswitch tableswitch(&bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   188
          int len = tableswitch.length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   190
          dest = _block_map->at(bci + tableswitch.default_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
          assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
          dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
          while (--len >= 0) {
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   194
            dest = _block_map->at(bci + tableswitch.dest_offset_at(len));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
            dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        {
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   203
          Bytecode_lookupswitch lookupswitch(&bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   205
          int npairs = lookupswitch.number_of_pairs();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   207
          dest = _block_map->at(bci + lookupswitch.default_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
          assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
          dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
          while(--npairs >= 0) {
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   211
            LookupswitchPair pair = lookupswitch.pair_at(npairs);
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   212
            dest = _block_map->at( bci + pair.offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
            assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      case Bytecodes::_jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          assert(bytes.is_wide()==false, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
          dest = _block_map->at(bytes.get_dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
          dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
          BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
          assert(jsrExit != NULL, "jsr return bci must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
          jsr_exit_list->append(jsrExit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      case Bytecodes::_jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          dest = _block_map->at(bytes.get_far_dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
          assert(dest != NULL, "branch desination must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          dest->add_normal_predecessor(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
          BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
          assert(jsrExit != NULL, "jsr return bci must start a block.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
          jsr_exit_list->append(jsrExit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      case Bytecodes::_wide:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        assert(false, "wide opcodes should not be seen here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      case Bytecodes::_athrow:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      case Bytecodes::_ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      case Bytecodes::_lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      case Bytecodes::_freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      case Bytecodes::_dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      case Bytecodes::_areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      case Bytecodes::_return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        // These opcodes are  not the normal predecessors of any other opcodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      case Bytecodes::_ret:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        // We will patch up jsr/rets in a subsequent pass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        ret_list->append(current_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      case Bytecodes::_breakpoint:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        // Bail out of there are breakpoints in here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        bailout = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        // Do nothing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // Patch up the jsr/ret's.  We conservatively assume that any ret
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // can return to any jsr site.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  int ret_list_len = ret_list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  int jsr_exit_list_len = jsr_exit_list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (ret_list_len > 0 && jsr_exit_list_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    for (int i = jsr_exit_list_len - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      BasicBlock *jsrExit = jsr_exit_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      for (int i = ret_list_len - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
        jsrExit->add_normal_predecessor(ret_list->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // Compute exception edges.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  for (int b=_block_count-1; b >= 0; b--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    BasicBlock *block = _block_list[b];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    int block_start = block->start_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    int block_limit = block->limit_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    ciExceptionHandlerStream handlers(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    for (; !handlers.is_done(); handlers.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      ciExceptionHandler* handler = handlers.handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      int start       = handler->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      int limit       = handler->limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      int handler_bci = handler->handler_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      int intersect_start = MAX2(block_start, start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      int intersect_limit = MIN2(block_limit, limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      if (intersect_start < intersect_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
        // The catch range has a nonempty intersection with this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        // basic block.  That means this basic block can be an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
        // exceptional predecessor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        _block_map->at(handler_bci)->add_exception_predecessor(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        if (handler->is_catch_all()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
          // This is a catch-all block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
          if (intersect_start == block_start && intersect_limit == block_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
            // The basic block is entirely contained in this catch-all block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
            // Skip the rest of the exception handlers -- they can never be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
            // reached in execution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
void MethodLiveness::init_gen_kill() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  for (int i=_block_count-1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    _block_list[i]->compute_gen_kill(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
void MethodLiveness::propagate_liveness() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  int num_blocks = _block_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  BasicBlock *block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  // We start our work list off with all blocks in it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // Alternately, we could start off the work list with the list of all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // blocks which could exit the method directly, along with one block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // from any infinite loop.  If this matters, it can be changed.  It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // may not be clear from looking at the code, but the order of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // workList will be the opposite of the creation order of the basic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // blocks, which should be decent for quick convergence (with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  // possible exception of exception handlers, which are all created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  // early).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  _work_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  for (int i = 0; i < num_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    block = _block_list[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    block->set_next(_work_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    block->set_on_work_list(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    _work_list = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  while ((block = work_list_get()) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    block->propagate(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    NOT_PRODUCT(_total_visits++;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
void MethodLiveness::work_list_add(BasicBlock *block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  if (!block->on_work_list()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    block->set_next(_work_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    block->set_on_work_list(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    _work_list = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
MethodLiveness::BasicBlock *MethodLiveness::work_list_get() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  BasicBlock *block = _work_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  if (block != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    block->set_on_work_list(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    _work_list = block->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  return block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
MethodLivenessResult MethodLiveness::get_liveness_at(int entry_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  int bci = entry_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  bool is_entry = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  if (entry_bci == InvocationEntryBci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    is_entry = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    bci = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   373
  MethodLivenessResult answer;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (_block_count > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    assert( 0 <= bci && bci < method()->code_size(), "bci out of range" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    BasicBlock *block = _block_map->at(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    // We may not be at the block start, so search backwards to find the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    // containing bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    int t = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    while (block == NULL && t > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
     block = _block_map->at(--t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    }
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 47216
diff changeset
   385
    guarantee(block != NULL, "invalid bytecode index; must be instruction index");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    assert(bci >= block->start_bci() && bci < block->limit_bci(), "block must contain bci.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    answer = block->get_liveness_at(method(), bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    if (is_entry && method()->is_synchronized() && !method()->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      // Synchronized methods use the receiver once on entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      answer.at_put(0, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    if (TraceLivenessQuery) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      tty->print("Liveness query of ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      method()->print_short_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      tty->print(" @ %d : result is ", bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      answer.print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  return answer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
MethodLiveness::BasicBlock::BasicBlock(MethodLiveness *analyzer, int start, int limit) :
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   409
         _entry(analyzer->arena(),          analyzer->bit_map_size_bits()),
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   410
         _normal_exit(analyzer->arena(),    analyzer->bit_map_size_bits()),
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   411
         _exception_exit(analyzer->arena(), analyzer->bit_map_size_bits()),
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   412
         _gen(analyzer->arena(),            analyzer->bit_map_size_bits()),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   413
         _kill(analyzer->arena(),           analyzer->bit_map_size_bits()),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
         _last_bci(-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  _analyzer = analyzer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  _start_bci = start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  _limit_bci = limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  _normal_predecessors =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  _exception_predecessors =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
MethodLiveness::BasicBlock *MethodLiveness::BasicBlock::split(int split_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  int start = _start_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  int limit = _limit_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  if (TraceLivenessGen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    tty->print_cr(" ** Splitting block (%d,%d) at %d", start, limit, split_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  GrowableArray<BasicBlock*>* save_predecessors = _normal_predecessors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  assert (start < split_bci && split_bci < limit, "improper split");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  // Make a new block to cover the first half of the range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  BasicBlock *first_half = new (_analyzer->arena()) BasicBlock(_analyzer, start, split_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  // Assign correct values to the second half (this)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  _normal_predecessors = first_half->_normal_predecessors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  _start_bci = split_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  add_normal_predecessor(first_half);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  // Assign correct predecessors to the new first half
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  first_half->_normal_predecessors = save_predecessors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  return first_half;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
void MethodLiveness::BasicBlock::compute_gen_kill(ciMethod* method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  ciBytecodeStream bytes(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  bytes.reset_to_bci(start_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  bytes.set_max_bci(limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  compute_gen_kill_range(&bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
void MethodLiveness::BasicBlock::compute_gen_kill_range(ciBytecodeStream *bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  _gen.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  _kill.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  while (bytes->next() != ciBytecodeStream::EOBC()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    compute_gen_kill_single(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
void MethodLiveness::BasicBlock::compute_gen_kill_single(ciBytecodeStream *instruction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  int localNum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // We prohibit _gen and _kill from having locals in common.  If we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  // know that one is definitely going to be applied before the other,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  // we could save some computation time by relaxing this prohibition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  switch (instruction->cur_bc()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    case Bytecodes::_nop:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    case Bytecodes::_goto:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    case Bytecodes::_goto_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    case Bytecodes::_aconst_null:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    case Bytecodes::_new:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    case Bytecodes::_iconst_m1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    case Bytecodes::_iconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    case Bytecodes::_iconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    case Bytecodes::_iconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    case Bytecodes::_iconst_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    case Bytecodes::_iconst_4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    case Bytecodes::_iconst_5:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    case Bytecodes::_fconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    case Bytecodes::_fconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    case Bytecodes::_fconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    case Bytecodes::_bipush:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    case Bytecodes::_sipush:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    case Bytecodes::_lconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    case Bytecodes::_lconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    case Bytecodes::_dconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    case Bytecodes::_dconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    case Bytecodes::_ldc2_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    case Bytecodes::_ldc:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    case Bytecodes::_ldc_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    case Bytecodes::_iaload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    case Bytecodes::_faload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    case Bytecodes::_baload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    case Bytecodes::_caload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    case Bytecodes::_saload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    case Bytecodes::_laload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    case Bytecodes::_daload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    case Bytecodes::_aaload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    case Bytecodes::_iastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    case Bytecodes::_fastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    case Bytecodes::_bastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    case Bytecodes::_castore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    case Bytecodes::_sastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    case Bytecodes::_lastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    case Bytecodes::_dastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    case Bytecodes::_aastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    case Bytecodes::_pop:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    case Bytecodes::_pop2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    case Bytecodes::_dup:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    case Bytecodes::_dup_x1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    case Bytecodes::_dup_x2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    case Bytecodes::_dup2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    case Bytecodes::_dup2_x1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    case Bytecodes::_dup2_x2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    case Bytecodes::_swap:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    case Bytecodes::_iadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    case Bytecodes::_fadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    case Bytecodes::_isub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    case Bytecodes::_fsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    case Bytecodes::_imul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    case Bytecodes::_fmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    case Bytecodes::_idiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    case Bytecodes::_fdiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    case Bytecodes::_irem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    case Bytecodes::_frem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    case Bytecodes::_ishl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    case Bytecodes::_ishr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    case Bytecodes::_iushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    case Bytecodes::_iand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    case Bytecodes::_ior:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    case Bytecodes::_ixor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    case Bytecodes::_l2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    case Bytecodes::_l2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    case Bytecodes::_d2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    case Bytecodes::_d2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    case Bytecodes::_fcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    case Bytecodes::_fcmpg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    case Bytecodes::_ladd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    case Bytecodes::_dadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    case Bytecodes::_lsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    case Bytecodes::_dsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    case Bytecodes::_lmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    case Bytecodes::_dmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    case Bytecodes::_ldiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    case Bytecodes::_ddiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    case Bytecodes::_lrem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    case Bytecodes::_drem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    case Bytecodes::_land:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    case Bytecodes::_lor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    case Bytecodes::_lxor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    case Bytecodes::_ineg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    case Bytecodes::_fneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    case Bytecodes::_i2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    case Bytecodes::_f2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    case Bytecodes::_i2c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    case Bytecodes::_i2s:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    case Bytecodes::_i2b:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    case Bytecodes::_lneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    case Bytecodes::_dneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    case Bytecodes::_l2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    case Bytecodes::_d2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    case Bytecodes::_lshl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    case Bytecodes::_lshr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    case Bytecodes::_lushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    case Bytecodes::_i2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    case Bytecodes::_i2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    case Bytecodes::_f2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    case Bytecodes::_f2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    case Bytecodes::_lcmp:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    case Bytecodes::_dcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    case Bytecodes::_dcmpg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    case Bytecodes::_ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    case Bytecodes::_ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    case Bytecodes::_iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    case Bytecodes::_ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    case Bytecodes::_ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    case Bytecodes::_ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    case Bytecodes::_tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    case Bytecodes::_ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    case Bytecodes::_freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    case Bytecodes::_if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    case Bytecodes::_if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    case Bytecodes::_if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    case Bytecodes::_if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    case Bytecodes::_if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    case Bytecodes::_if_icmple:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    case Bytecodes::_lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    case Bytecodes::_dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    case Bytecodes::_if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    case Bytecodes::_if_acmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    case Bytecodes::_jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    case Bytecodes::_jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    case Bytecodes::_getstatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    case Bytecodes::_putstatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    case Bytecodes::_getfield:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    case Bytecodes::_putfield:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    case Bytecodes::_invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    case Bytecodes::_invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    case Bytecodes::_invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    case Bytecodes::_invokeinterface:
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 1374
diff changeset
   611
    case Bytecodes::_invokedynamic:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    case Bytecodes::_newarray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    case Bytecodes::_anewarray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    case Bytecodes::_checkcast:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    case Bytecodes::_arraylength:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    case Bytecodes::_instanceof:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    case Bytecodes::_athrow:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    case Bytecodes::_areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    case Bytecodes::_monitorenter:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    case Bytecodes::_monitorexit:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    case Bytecodes::_ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    case Bytecodes::_ifnonnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    case Bytecodes::_multianewarray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      // These bytecodes have no effect on the method's locals.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    case Bytecodes::_return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      if (instruction->method()->intrinsic_id() == vmIntrinsics::_Object_init) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
        // return from Object.init implicitly registers a finalizer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
        // for the receiver if needed, so keep it alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
        load_one(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    case Bytecodes::_lload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    case Bytecodes::_dload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
      load_two(instruction->get_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    case Bytecodes::_lload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    case Bytecodes::_dload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
      load_two(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    case Bytecodes::_lload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    case Bytecodes::_dload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      load_two(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    case Bytecodes::_lload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    case Bytecodes::_dload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      load_two(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    case Bytecodes::_lload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    case Bytecodes::_dload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      load_two(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    case Bytecodes::_iload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    case Bytecodes::_iinc:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    case Bytecodes::_fload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    case Bytecodes::_aload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    case Bytecodes::_ret:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      load_one(instruction->get_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    case Bytecodes::_iload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    case Bytecodes::_fload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    case Bytecodes::_aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      load_one(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    case Bytecodes::_iload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    case Bytecodes::_fload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    case Bytecodes::_aload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      load_one(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    case Bytecodes::_iload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    case Bytecodes::_fload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    case Bytecodes::_aload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      load_one(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    case Bytecodes::_iload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    case Bytecodes::_fload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    case Bytecodes::_aload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      load_one(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    case Bytecodes::_lstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    case Bytecodes::_dstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      store_two(localNum = instruction->get_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
    case Bytecodes::_lstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    case Bytecodes::_dstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      store_two(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    case Bytecodes::_lstore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    case Bytecodes::_dstore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
      store_two(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    case Bytecodes::_lstore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    case Bytecodes::_dstore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      store_two(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    case Bytecodes::_lstore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    case Bytecodes::_dstore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      store_two(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    case Bytecodes::_istore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    case Bytecodes::_fstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    case Bytecodes::_astore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
      store_one(instruction->get_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    case Bytecodes::_istore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    case Bytecodes::_fstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    case Bytecodes::_astore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      store_one(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    case Bytecodes::_istore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    case Bytecodes::_fstore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
    case Bytecodes::_astore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      store_one(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    case Bytecodes::_istore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    case Bytecodes::_fstore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    case Bytecodes::_astore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      store_one(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    case Bytecodes::_istore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    case Bytecodes::_fstore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    case Bytecodes::_astore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
      store_one(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
    case Bytecodes::_wide:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      fatal("Iterator should skip this bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      tty->print("unexpected opcode: %d\n", instruction->cur_bc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
void MethodLiveness::BasicBlock::load_two(int local) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  load_one(local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  load_one(local+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
void MethodLiveness::BasicBlock::load_one(int local) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  if (!_kill.at(local)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    _gen.at_put(local, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
void MethodLiveness::BasicBlock::store_two(int local) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  store_one(local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  store_one(local+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
void MethodLiveness::BasicBlock::store_one(int local) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  if (!_gen.at(local)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    _kill.at_put(local, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
void MethodLiveness::BasicBlock::propagate(MethodLiveness *ml) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  // These set operations could be combined for efficiency if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  // performance of this analysis becomes an issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  _entry.set_union(_normal_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  _entry.set_difference(_kill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  _entry.set_union(_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  // Note that we merge information from our exceptional successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  // just once, rather than at individual bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  _entry.set_union(_exception_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  if (TraceLivenessGen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    tty->print_cr(" ** Visiting block at %d **", start_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  for (i=_normal_predecessors->length()-1; i>=0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    BasicBlock *block = _normal_predecessors->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    if (block->merge_normal(_entry)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      ml->work_list_add(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  for (i=_exception_predecessors->length()-1; i>=0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    BasicBlock *block = _exception_predecessors->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    if (block->merge_exception(_entry)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      ml->work_list_add(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   813
bool MethodLiveness::BasicBlock::merge_normal(const BitMap& other) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  return _normal_exit.set_union_with_result(other);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   817
bool MethodLiveness::BasicBlock::merge_exception(const BitMap& other) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  return _exception_exit.set_union_with_result(other);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
MethodLivenessResult MethodLiveness::BasicBlock::get_liveness_at(ciMethod* method, int bci) {
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   822
  MethodLivenessResult answer(_analyzer->bit_map_size_bits());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  answer.set_is_valid();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
#ifndef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  if (bci == start_bci()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    answer.set_from(_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    return answer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  ResourceMark rm;
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   834
  ResourceBitMap g(_gen.size()); g.set_from(_gen);
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 37248
diff changeset
   835
  ResourceBitMap k(_kill.size()); k.set_from(_kill);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  if (_last_bci != bci || trueInDebug) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    ciBytecodeStream bytes(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    bytes.reset_to_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    bytes.set_max_bci(limit_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    compute_gen_kill_range(&bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    assert(_last_bci != bci ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
           (g.is_same(_gen) && k.is_same(_kill)), "cached computation is incorrect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    _last_bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  answer.set_union(_normal_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  answer.set_difference(_kill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  answer.set_union(_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  answer.set_union(_exception_exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  if (bci == start_bci()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    assert(answer.is_same(_entry), "optimized answer must be accurate");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  return answer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
void MethodLiveness::BasicBlock::print_on(outputStream *os) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  os->print_cr("===================================================================");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  os->print_cr("    Block start: %4d, limit: %4d", _start_bci, _limit_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  os->print   ("    Normal predecessors (%2d)      @", _normal_predecessors->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  for (i=0; i < _normal_predecessors->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    os->print(" %4d", _normal_predecessors->at(i)->start_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  os->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  os->print   ("    Exceptional predecessors (%2d) @", _exception_predecessors->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  for (i=0; i < _exception_predecessors->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    os->print(" %4d", _exception_predecessors->at(i)->start_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  os->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  os->print ("    Normal Exit   : ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  _normal_exit.print_on(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  os->print ("    Gen           : ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  _gen.print_on(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  os->print ("    Kill          : ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  _kill.print_on(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  os->print ("    Exception Exit: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  _exception_exit.print_on(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  os->print ("    Entry         : ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  _entry.print_on(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
#endif // PRODUCT