hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 5882 6b2aecc4f7d8
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
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: 1
diff changeset
     2
 * Copyright (c) 2001, 2005, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
package sun.jvm.hotspot.oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
/** Minimal port of the VM's oop map generator for interpreted frames */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
public class GenerateOopMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  interface JumpClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    public void process(GenerateOopMap c, int bcpDelta, int[] data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // These two should be removed. But requires som code to be cleaned up
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private static final int MAXARGSIZE     =   256;      // This should be enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private static final int MAX_LOCAL_VARS = 65536;      // 16-bit entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private static final boolean TraceMonitorMismatch = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private static final boolean TraceOopMapRewrites = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Commonly used constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  static CellTypeState[] epsilonCTS = { CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  static CellTypeState   refCTS     = CellTypeState.ref;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static CellTypeState   valCTS     = CellTypeState.value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static CellTypeState[]    vCTS    = { CellTypeState.value, CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  static CellTypeState[]    rCTS    = { CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static CellTypeState[]   rrCTS    = { CellTypeState.ref,   CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static CellTypeState[]   vrCTS    = { CellTypeState.value, CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  static CellTypeState[]   vvCTS    = { CellTypeState.value, CellTypeState.value, CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  static CellTypeState[]  rvrCTS    = { CellTypeState.ref,   CellTypeState.value, CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  static CellTypeState[]  vvrCTS    = { CellTypeState.value, CellTypeState.value, CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static CellTypeState[]  vvvCTS    = { CellTypeState.value, CellTypeState.value, CellTypeState.value, CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static CellTypeState[] vvvrCTS    = { CellTypeState.value, CellTypeState.value, CellTypeState.value, CellTypeState.ref,   CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static CellTypeState[] vvvvCTS    = { CellTypeState.value, CellTypeState.value, CellTypeState.value, CellTypeState.value, CellTypeState.bottom };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  /** Specialization of SignatureIterator - compute the effects of a call */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static class ComputeCallStack extends SignatureIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    CellTypeStateList _effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    int _idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    void set(CellTypeState state)         { _effect.get(_idx++).set(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    int  length()                         { return _idx; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    public void doBool  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    public void doChar  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    public void doFloat ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    public void doByte  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    public void doShort ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    public void doInt   ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    public void doVoid  ()              { set(CellTypeState.bottom);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    public void doObject(int begin, int end) { set(CellTypeState.ref); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    public void doArray (int begin, int end) { set(CellTypeState.ref); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    public void doDouble()              { set(CellTypeState.value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                                          set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    public void doLong  ()              { set(CellTypeState.value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                                          set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    ComputeCallStack(Symbol signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      super(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    // Compute methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    int computeForParameters(boolean is_static, CellTypeStateList effect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      _idx    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      _effect = effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      if (!is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        effect.get(_idx++).set(CellTypeState.ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      iterateParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      return length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    int computeForReturntype(CellTypeStateList effect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      _idx    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      _effect = effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      iterateReturntype();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      set(CellTypeState.bottom);  // Always terminate with a bottom state, so ppush works
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      return length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  /** Specialization of SignatureIterator - in order to set up first stack frame */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  static class ComputeEntryStack extends SignatureIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    CellTypeStateList _effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    int _idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    void set(CellTypeState state)         { _effect.get(_idx++).set(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    int  length()                         { return _idx; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    public void doBool  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    public void doChar  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    public void doFloat ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    public void doByte  ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    public void doShort ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    public void doInt   ()              { set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    public void doVoid  ()              { set(CellTypeState.bottom);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    public void doObject(int begin, int end) { set(CellTypeState.makeSlotRef(_idx)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    public void doArray (int begin, int end) { set(CellTypeState.makeSlotRef(_idx)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    public void doDouble()              { set(CellTypeState.value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
                                          set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    public void doLong  ()              { set(CellTypeState.value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                                          set(CellTypeState.value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    ComputeEntryStack(Symbol signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      super(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    // Compute methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    int computeForParameters(boolean is_static, CellTypeStateList effect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      _idx    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      _effect = effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      if (!is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        effect.get(_idx++).set(CellTypeState.makeSlotRef(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      iterateParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      return length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    int computeForReturntype(CellTypeStateList effect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      _idx    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      _effect = effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      iterateReturntype();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      set(CellTypeState.bottom);  // Always terminate with a bottom state, so ppush works
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      return length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  /** Contains maping between jsr targets and there return addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      One-to-many mapping. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static class RetTableEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    private static int _init_nof_jsrs; // Default size of jsrs list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    private int _target_bci;           // Target PC address of jump (bytecode index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    private List/*<int>*/ _jsrs;       // List of return addresses  (bytecode index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    private RetTableEntry _next;       // Link to next entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    RetTableEntry(int target, RetTableEntry next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      _target_bci = target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      _jsrs = new ArrayList(_init_nof_jsrs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      _next = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    int targetBci()  { return _target_bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    int nofJsrs()    { return _jsrs.size(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    int jsrs(int i)  { return ((Integer) _jsrs.get(i)).intValue(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // Update entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    void addJsr  (int return_bci)     { _jsrs.add(new Integer(return_bci)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    void addDelta(int bci, int delta) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      if (_target_bci > bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        _target_bci += delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      for (int k = 0; k < nofJsrs(); k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        int jsr = jsrs(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        if (jsr > bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
          _jsrs.set(k, new Integer(jsr+delta));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    RetTableEntry next()               { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  static class RetTable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    private RetTableEntry _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    private static int _init_nof_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    private void addJsr(int return_bci, int target_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      RetTableEntry entry = _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      // Scan table for entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      for (;(entry != null) && (entry.targetBci() != target_bci); entry = entry.next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      if (entry == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        // Allocate new entry and put in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        entry = new RetTableEntry(target_bci, _first);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        _first = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      // Now "entry" is set.  Make sure that the entry is initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      // and has room for the new jsr.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      entry.addJsr(return_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    RetTable() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    void computeRetTable(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      BytecodeStream i = new BytecodeStream(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      int bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      while( (bytecode = i.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        switch (bytecode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
          addJsr(i.nextBCI(), i.dest());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          addJsr(i.nextBCI(), i.dest_w());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    void updateRetTable(int bci, int delta) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      RetTableEntry cur = _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      while(cur != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        cur.addDelta(bci, delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        cur = cur.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    RetTableEntry findJsrsForTarget(int targBci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      RetTableEntry cur = _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      while(cur != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
          Assert.that(cur.targetBci() != -1, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        if (cur.targetBci() == targBci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
          return cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        cur = cur.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      throw new RuntimeException("Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  static class BasicBlock {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    private boolean _changed;              // Reached a fixpoint or not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    static final int _dead_basic_block = -2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    // Alive but not yet reached by analysis
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    static final int _unreached        = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    // >=0: Alive and has a merged state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    int                     _bci;          // Start of basic block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    int                     _end_bci;      // Bci of last instruction in basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    int                     _max_locals;   // Determines split between vars and stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    int                     _max_stack;    // Determines split between stack and monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    CellTypeStateList       _state;        // State (vars, stack) at entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    int                     _stack_top;    // -1 indicates bottom stack value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    int                     _monitor_top;  // -1 indicates bottom monitor stack value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    CellTypeStateList       vars()  { return _state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    CellTypeStateList       stack() { return _state.subList(_max_locals, _state.size()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    boolean changed()               { return _changed; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    void    setChanged(boolean s)   { _changed = s; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    // Analysis has reached this basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    boolean isReachable()           { return _stack_top >= 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // All basicblocks that are unreachable are going to have a _stack_top == _dead_basic_block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    // This info. is setup in a pre-parse before the real abstract interpretation starts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    boolean isDead()                { return _stack_top == _dead_basic_block; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    boolean isAlive()               { return _stack_top != _dead_basic_block; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    void    markAsAlive()           {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
        Assert.that(isDead(), "must be dead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        _stack_top = _unreached;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // Protected routines for GenerateOopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  // _monitor_top is set to this constant to indicate that a monitor matching
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // problem was encountered prior to this point in control flow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  protected static final int bad_monitors = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // Main variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  Method   _method;         // The method we are examining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  RetTable _rt;             // Contains the return address mappings
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  int      _max_locals;     // Cached value of no. of locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  int      _max_stack;      // Cached value of max. stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  int      _max_monitors;   // Cached value of max. monitor stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  boolean  _has_exceptions; // True, if exceptions exist for method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  boolean  _got_error;      // True, if an error occured during interpretation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  String   _error_msg;      // Error message. Set if _got_error is true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  //  bool     _did_rewriting;  // was bytecodes rewritten
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  //  bool     _did_relocation; // was relocation neccessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  boolean  _monitor_safe;   // The monitors in this method have been determined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
                            // to be safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // Working Cell type state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  int               _state_len;     // Size of states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  CellTypeStateList _state;         // list of states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  char[]            _state_vec_buf; // Buffer used to print a readable version of a state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  int               _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  int               _monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // Timing and statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  //  static elapsedTimer _total_oopmap_time;   // Holds cumulative oopmap generation time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  //  static long         _total_byte_count;    // Holds cumulative number of bytes inspected
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  // Monitor query logic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  int _report_for_exit_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  int _matching_enter_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // Cell type methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  void            initState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    _state_len = _max_locals + _max_stack + _max_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    _state     = new CellTypeStateList(_state_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    _state_vec_buf = new char[Math.max(_max_locals, Math.max(_max_stack, Math.max(_max_monitors, 1)))];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  void            makeContextUninitialized () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    CellTypeStateList vs = vars();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    for (int i = 0; i < _max_locals; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      vs.get(i).set(CellTypeState.uninit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    _stack_top = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    _monitor_top = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  int             methodsigToEffect          (Symbol signature, boolean isStatic, CellTypeStateList effect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    ComputeEntryStack ces = new ComputeEntryStack(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    return ces.computeForParameters(isStatic, effect);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  boolean         mergeStateVectors          (CellTypeStateList cts, CellTypeStateList bbts) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    int len = _max_locals + _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    boolean change = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    for (i = len - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      CellTypeState v = cts.get(i).merge(bbts.get(i), i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      change = change || !v.equal(bbts.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      bbts.get(i).set(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    if (_max_monitors > 0 && _monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      // If there are no monitors in the program, or there has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      // a monitor matching error before this point in the program,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      // then we do not merge in the monitor state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      int base = _max_locals + _max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      len = base + _monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      for (i = len - 1; i >= base; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        CellTypeState v = cts.get(i).merge(bbts.get(i), i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
        // Can we prove that, when there has been a change, it will already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        // have been detected at this point?  That would make this equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        // check here unnecessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        change = change || !v.equal(bbts.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        bbts.get(i).set(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    return change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  void            copyState                  (CellTypeStateList dst, CellTypeStateList src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    int len = _max_locals + _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      if (src.get(i).isNonlockReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        dst.get(i).set(CellTypeState.makeSlotRef(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        dst.get(i).set(src.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    if (_max_monitors > 0 && _monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      int base = _max_locals + _max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      len = base + _monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      for (int i = base; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
        dst.get(i).set(src.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  void            mergeStateIntoBB           (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      Assert.that(bb.isAlive(), "merging state into a dead basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    if (_stack_top == bb._stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      if (_monitor_top == bb._monitor_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
        if (mergeStateVectors(_state, bb._state)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
          bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
          reportMonitorMismatch("monitor stack height merge conflict");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
        // When the monitor stacks are not matched, we set _monitor_top to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
        // bad_monitors.  This signals that, from here on, the monitor stack cannot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
        // be trusted.  In particular, monitorexit bytecodes may throw
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
        // exceptions.  We mark this block as changed so that the change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        // propagates properly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        bb._monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    } else if (!bb.isReachable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      // First time we look at this  BB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      copyState(bb._state, _state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
      bb._stack_top = _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      bb._monitor_top = _monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      throw new RuntimeException("stack height conflict: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                                 _stack_top + " vs. " + bb._stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  void            mergeState                 (int bci, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    mergeStateIntoBB(getBasicBlockAt(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  void            setVar                     (int localNo, CellTypeState cts) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      Assert.that(cts.isReference() || cts.isValue() || cts.isAddress(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
                  "wrong celltypestate");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (localNo < 0 || localNo > _max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      throw new RuntimeException("variable write error: r" + localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    vars().get(localNo).set(cts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  CellTypeState   getVar                     (int localNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      Assert.that(localNo < _max_locals + _nof_refval_conflicts, "variable read error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    if (localNo < 0 || localNo > _max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
      throw new RuntimeException("variable read error: r" + localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    return vars().get(localNo).copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  CellTypeState   pop                        () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    if ( _stack_top <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      throw new RuntimeException("stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    return  stack().get(--_stack_top).copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  void            push                       (CellTypeState cts) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    if ( _stack_top >= _max_stack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
        System.err.println("Method: " + method().getName().asString() + method().getSignature().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
                           " _stack_top: " + _stack_top + " _max_stack: " + _max_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
      throw new RuntimeException("stack overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    stack().get(_stack_top++).set(cts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
      System.err.println("After push: _stack_top: " + _stack_top +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                         " _max_stack: " + _max_stack +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
                         " just pushed: " + cts.toChar());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  CellTypeState   monitorPop                 () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      Assert.that(_monitor_top != bad_monitors, "monitorPop called on error monitor stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    if (_monitor_top == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
      // We have detected a pop of an empty monitor stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
        reportMonitorMismatch("monitor stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
      return CellTypeState.ref; // just to keep the analysis going.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    return  monitors().get(--_monitor_top).copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  void            monitorPush                (CellTypeState cts) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      Assert.that(_monitor_top != bad_monitors, "monitorPush called on error monitor stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    if (_monitor_top >= _max_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      // Some monitorenter is being executed more than once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      // This means that the monitor stack cannot be simulated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        reportMonitorMismatch("monitor stack overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    monitors().get(_monitor_top++).set(cts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  CellTypeStateList vars    ()     { return _state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  CellTypeStateList stack   ()     { return _state.subList(_max_locals, _state.size()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  CellTypeStateList monitors()     { return _state.subList(_max_locals+_max_stack, _state.size()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  void            replaceAllCTSMatches       (CellTypeState match,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
                                              CellTypeState replace) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    int len = _max_locals + _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    boolean change = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    for (i = len - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      if (match.equal(_state.get(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        _state.get(i).set(replace);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    if (_monitor_top > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      int base = _max_locals + _max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      len = base + _monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      for (i = len - 1; i >= base; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        if (match.equal(_state.get(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
          _state.get(i).set(replace);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  void            printStates                (PrintStream tty, CellTypeStateList vector, int num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    for (int i = 0; i < num; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      vector.get(i).print(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  void            printCurrentState          (PrintStream tty,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                                              BytecodeStream currentBC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
                                              boolean        detailed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    if (detailed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
      tty.print("     " + currentBC.bci() + " vars     = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      printStates(tty, vars(), _max_locals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      tty.print("    " + Bytecodes.name(currentBC.code()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      switch(currentBC.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      case Bytecodes._invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      case Bytecodes._invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
      case Bytecodes._invokeinterface:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
        // FIXME: print signature of referenced method (need more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
        // accessors in ConstantPool and ConstantPoolCache)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
        int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
        tty.print(" idx " + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
          int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
          ConstantPool cp       = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
          int nameAndTypeIdx    = cp.name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
          int signatureIdx      = cp.signature_ref_index_at(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
          symbolOop signature   = cp.symbol_at(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
          tty.print("%s", signature.as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
      tty.print("          stack    = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
      printStates(tty, stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      if (_monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
        tty.print("          monitors = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
        printStates(tty, monitors(), _monitor_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
        tty.print("          [bad monitor stack]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
      tty.print("    " + currentBC.bci() + "  vars = '" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
                stateVecToString(vars(), _max_locals) + "' ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
      tty.print("     stack = '" + stateVecToString(stack(), _stack_top) + "' ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      if (_monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
        tty.print("  monitors = '" + stateVecToString(monitors(), _monitor_top) + "'  \t" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                  Bytecodes.name(currentBC.code()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
        tty.print("  [bad monitor stack]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      switch(currentBC.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      case Bytecodes._invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      case Bytecodes._invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      case Bytecodes._invokeinterface:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
        // FIXME: print signature of referenced method (need more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
        // accessors in ConstantPool and ConstantPoolCache)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
        int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
        tty.print(" idx " + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
          int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
          constantPoolOop cp    = method().constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
          int nameAndTypeIdx    = cp.name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
          int signatureIdx      = cp.signature_ref_index_at(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
          symbolOop signature   = cp.symbol_at(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
          tty.print("%s", signature.as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  void            reportMonitorMismatch      (String msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      System.err.print("    Monitor mismatch in method ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      method().printValueOn(System.err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      System.err.println(": " + msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // Basicblock info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  BasicBlock[]    _basic_blocks;             // Array of basicblock info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  int             _gc_points;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  int             _bb_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  BitMap          _bb_hdr_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  // Basicblocks methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  void          initializeBB               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    _gc_points = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    _bb_count  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    _bb_hdr_bits = new BitMap((int) _method.getCodeSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  void          markBBHeadersAndCountGCPoints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    initializeBB();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    boolean fellThrough = false;  // False to get first BB marked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    // First mark all exception handlers as start of a basic-block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    TypeArray excps = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    for(int i = 0; i < excps.getLength(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      int handler_pc_idx = i+2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      markBB(excps.getIntAt(handler_pc_idx), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    // Then iterate through the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    BytecodeStream bcs = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    int bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    while( (bytecode = bcs.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
      int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      if (!fellThrough)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
        markBB(bci, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      fellThrough = jumpTargetsDo(bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
                                  new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
                                      public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
                                        c.markBB(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
                                      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
                                    },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
                                  null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      /* We will also mark successors of jsr's as basic block headers. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
      switch (bytecode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
      case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
          Assert.that(!fellThrough, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
        markBB(bci + Bytecodes.lengthFor(bytecode), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
          Assert.that(!fellThrough, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
        markBB(bci + Bytecodes.lengthFor(bytecode), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      if (possibleGCPoint(bcs))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        _gc_points++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  boolean       isBBHeader                  (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    return _bb_hdr_bits.at(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  int           gcPoints                    () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    return _gc_points;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  int           bbCount                     () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    return _bb_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  void          setBBMarkBit                (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    _bb_hdr_bits.atPut(bci, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  void          clear_bbmark_bit            (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    _bb_hdr_bits.atPut(bci, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  BasicBlock    getBasicBlockAt             (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
      Assert.that(bb._bci == bci, "should have found BB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    return bb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  BasicBlock    getBasicBlockContaining     (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    BasicBlock[] bbs = _basic_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    int lo = 0, hi = _bb_count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    while (lo <= hi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
      int m = (lo + hi) / 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
      int mbci = bbs[m]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
      int nbci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      if ( m == _bb_count-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
          Assert.that( bci >= mbci && bci < method().getCodeSize(), "sanity check failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
        return bbs[m];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
        nbci = bbs[m+1]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      if ( mbci <= bci && bci < nbci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
        return bbs[m];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      } else if (mbci < bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
        lo = m + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
          Assert.that(mbci > bci, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
        hi = m - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    throw new RuntimeException("should have found BB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  void          interpBB                    (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    // We do not want to do anything in case the basic-block has not been initialized. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    // will happen in the case where there is dead-code hang around in a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      Assert.that(bb.isReachable(), "should be reachable or deadcode exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    restoreState(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    BytecodeStream itr = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    // Set iterator interval to be the current basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    int lim_bci = nextBBStartPC(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    itr.setInterval(bb._bci, lim_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      System.err.println("interpBB: method = " + method().getName().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
                         method().getSignature().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
                         ", BCI interval [" + bb._bci + ", " + lim_bci + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
        System.err.print("Bytecodes:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
        for (int i = bb._bci; i < lim_bci; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
          System.err.print(" 0x" + Long.toHexString(method().getBytecodeOrBPAt(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
        System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
      Assert.that(lim_bci != bb._bci, "must be at least one instruction in a basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    itr.next(); // read first instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    // Iterates through all bytecodes except the last in a basic block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    // We handle the last one special, since there is controlflow change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    while(itr.nextBCI() < lim_bci && !_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
      if (_has_exceptions || (_monitor_top != 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
        // We do not need to interpret the results of exceptional
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
        // continuation from this instruction when the method has no
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        // exception handlers and the monitor stack is currently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
        // empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
        doExceptionEdge(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
      interp1(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    // Handle last instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    if (!_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
        Assert.that(itr.nextBCI() == lim_bci, "must point to end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      if (_has_exceptions || (_monitor_top != 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
        doExceptionEdge(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
      interp1(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      boolean fall_through = jumpTargetsDo(itr, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
          public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
            c.mergeState(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
        }, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      if (_got_error)  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      if (itr.code() == Bytecodes._ret) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
          Assert.that(!fall_through, "cannot be set if ret instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
        // Automatically handles 'wide' ret indicies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
        retJumpTargetsDo(itr, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
            public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
              c.mergeState(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
          }, itr.getIndex(), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      } else if (fall_through) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
        // Hit end of BB, but the instr. was a fall-through instruction,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
        // so perform transition as if the BB ended in a "jump".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
          Assert.that(lim_bci == _basic_blocks[bbIndex(bb) + 1]._bci, "there must be another bb");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
        mergeStateIntoBB(_basic_blocks[bbIndex(bb) + 1]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  void          restoreState                (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    for (int i = 0; i < _state_len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
      _state.get(i).set(bb._state.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    _stack_top   = bb._stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    _monitor_top = bb._monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  int           nextBBStartPC               (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    int bbNum = bbIndex(bb) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
    if (bbNum == _bb_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      return (int) method().getCodeSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    return _basic_blocks[bbNum]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  void          updateBasicBlocks           (int bci, int delta) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    BitMap bbBits = new BitMap((int) (_method.getCodeSize() + delta));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    for(int k = 0; k < _bb_count; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
      if (_basic_blocks[k]._bci > bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
        _basic_blocks[k]._bci     += delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
        _basic_blocks[k]._end_bci += delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
      bbBits.atPut(_basic_blocks[k]._bci, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
    _bb_hdr_bits = bbBits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  void markBB(int bci, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      Assert.that(bci>= 0 && bci < method().getCodeSize(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    if (isBBHeader(bci))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    //    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    //      tty.print_cr("Basicblock#%d begins at: %d", c._bb_count, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    setBBMarkBit(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
    _bb_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  // Dead code detection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  void          markReachableCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
    final int[] change = new int[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    change[0] = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    // Mark entry basic block as alive and all exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    _basic_blocks[0].markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    TypeArray excps = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    for(int i = 0; i < excps.getLength(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
      int handler_pc_idx = i+2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
      BasicBlock bb = getBasicBlockAt(excps.getIntAt(handler_pc_idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      // If block is not already alive (due to multiple exception handlers to same bb), then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
      // make it alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      if (bb.isDead())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
        bb.markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    BytecodeStream bcs = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    // Iterate through all basic blocks until we reach a fixpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    while (change[0] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      change[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      for (int i = 0; i < _bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
        BasicBlock bb = _basic_blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
        if (bb.isAlive()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
          // Position bytecodestream at last bytecode in basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
          bcs.setStart(bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
          bcs.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
          int bytecode = bcs.code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
          int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
            Assert.that(bci == bb._end_bci, "wrong bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
          boolean fell_through = jumpTargetsDo(bcs, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
              public void process(GenerateOopMap c, int bciDelta, int[] change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
                c.reachableBasicblock(bciDelta, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
            }, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
          // We will also mark successors of jsr's as alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
          switch (bytecode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
          case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
          case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
            if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
              Assert.that(!fell_through, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
            reachableBasicblock(bci + Bytecodes.lengthFor(bytecode), change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
          if (fell_through) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
            // Mark successor as alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
            if (_basic_blocks[i+1].isDead()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
              _basic_blocks[i+1].markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
              change[0] = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  void  reachableBasicblock        (int bci, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
      Assert.that(bci>= 0 && bci < method().getCodeSize(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    BasicBlock bb = getBasicBlockAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    if (bb.isDead()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      bb.markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      data[0] = 1; // Mark basicblock as changed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  // Interpretation methods (primary)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  void  doInterpretation                    () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    // "i" is just for debugging, so we can detect cases where this loop is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    // iterated more than once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
      // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
      //      if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
      //        tty.print("\n\nIteration #%d of do_interpretation loop, method:\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      //        method().print_name(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
      //        tty.print("\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
      _conflict = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      _monitor_safe = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
      // init_state is now called from init_basic_blocks.  The length of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
      // state vector cannot be determined until we have made a pass through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
      // the bytecodes counting the possible monitor entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      if (!_got_error) initBasicBlocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
      if (!_got_error) setupMethodEntryState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      if (!_got_error) interpAll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
      if (!_got_error) rewriteRefvalConflicts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    } while (_conflict && !_got_error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  void  initBasicBlocks                     () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    // Note: Could consider reserving only the needed space for each BB's state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    // (entry stack may not be of maximal height for every basic block).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    // But cumbersome since we don't know the stack heights yet.  (Nor the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    // monitor stack heights...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    _basic_blocks = new BasicBlock[_bb_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    for (int i = 0; i < _bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
      _basic_blocks[i] = new BasicBlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    // Make a pass through the bytecodes.  Count the number of monitorenters.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    // This can be used an upper bound on the monitor stack depth in programs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    // which obey stack discipline with their monitor usage.  Initialize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    // known information about basic blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    BytecodeStream j = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    int bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    int bbNo = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    int monitor_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    int prev_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    while( (bytecode = j.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      if (j.code() == Bytecodes._monitorenter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
        monitor_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      int bci = j.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
      if (isBBHeader(bci)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
        // Initialize the basicblock structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
        BasicBlock bb    = _basic_blocks[bbNo];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
        bb._bci          = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
        bb._max_locals   = _max_locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
        bb._max_stack    = _max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
        bb.setChanged(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
        bb._stack_top    = BasicBlock._dead_basic_block; // Initialize all basicblocks are dead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
        bb._monitor_top  = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
        if (bbNo > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
          _basic_blocks[bbNo - 1]._end_bci = prev_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
        bbNo++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
      // Remember prevous bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
      prev_bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // Set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    _basic_blocks[bbNo-1]._end_bci = prev_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    _max_monitors = monitor_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    // Now that we have a bound on the depth of the monitor stack, we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    // initialize the CellTypeState-related information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    initState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    // We allocate space for all state-vectors for all basicblocks in one huge chuck.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    // Then in the next part of the code, we set a pointer in each _basic_block that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    // points to each piece.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    CellTypeStateList basicBlockState = new CellTypeStateList(bbNo * _state_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    // Make a pass over the basicblocks and assign their state vectors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    for (int blockNum=0; blockNum < bbNo; blockNum++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
      BasicBlock bb = _basic_blocks[blockNum];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
      bb._state = basicBlockState.subList(blockNum * _state_len, (blockNum + 1) * _state_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
        if (blockNum + 1 < bbNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
          int bc_len = Bytecodes.javaLengthAt(_method, bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
          Assert.that(bb._end_bci + bc_len == _basic_blocks[blockNum + 1]._bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
                      "unmatched bci info in basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
      BasicBlock bb = _basic_blocks[bbNo-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
      int bc_len = Bytecodes.javaLengthAt(_method, bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
      Assert.that(bb._end_bci + bc_len == _method.getCodeSize(), "wrong end bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    // Check that the correct number of basicblocks was found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
    if (bbNo !=_bb_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
      if (bbNo < _bb_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
        throw new RuntimeException("jump into the middle of instruction?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
        throw new RuntimeException("extra basic blocks - should not happen?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    // Mark all alive blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    markReachableCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  void  setupMethodEntryState               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    // Initialize all locals to 'uninit' and set stack-height to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    makeContextUninitialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    // Initialize CellState type of arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    methodsigToEffect(method().getSignature(), method().isStatic(), vars());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    // If some references must be pre-assigned to null, then set that up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
    initializeVars();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    // This is the start state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
    mergeStateIntoBB(_basic_blocks[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
      Assert.that(_basic_blocks[0].changed(), "we are not getting off the ground");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  void  interpAll                           () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    boolean change = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    while (change && !_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
      change = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
      for (int i = 0; i < _bb_count && !_got_error; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
        BasicBlock bb = _basic_blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
        if (bb.changed()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
          if (_got_error) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
          change = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
          bb.setChanged(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
          interpBB(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  // Interpretation methods (secondary)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  /** Sets the current state to be the state after executing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      current instruction, starting in the current state. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  void  interp1                             (BytecodeStream itr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
      System.err.println(" - bci " + itr.bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    //    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    //      print_current_state(tty, itr, TraceNewOopMapGenerationDetailed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    // Should we report the results? Result is reported *before* the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
    // instruction at the current bci is executed.  However, not for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
    // calls. For calls we do not want to include the arguments, so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    // postpone the reporting until they have been popped (in method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    // ppl).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    if (_report_result == true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      switch(itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
      case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      case Bytecodes._invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      case Bytecodes._invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      case Bytecodes._invokeinterface:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
        _itr_send = itr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
        _report_result_for_send = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
        fillStackmapForOpcodes(itr, vars(), stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    // abstract interpretation of current opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    switch(itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    case Bytecodes._nop:               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    case Bytecodes._goto:              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    case Bytecodes._goto_w:            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
    case Bytecodes._iinc:              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    case Bytecodes._return:            doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    case Bytecodes._aconst_null:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
    case Bytecodes._new:               ppush1(CellTypeState.makeLineRef(itr.bci()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    case Bytecodes._iconst_m1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
    case Bytecodes._iconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
    case Bytecodes._iconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
    case Bytecodes._iconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    case Bytecodes._iconst_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
    case Bytecodes._iconst_4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    case Bytecodes._iconst_5:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    case Bytecodes._fconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    case Bytecodes._fconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
    case Bytecodes._fconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    case Bytecodes._bipush:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
    case Bytecodes._sipush:            ppush1(valCTS);             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    case Bytecodes._lconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    case Bytecodes._lconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    case Bytecodes._dconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
    case Bytecodes._dconst_1:          ppush(vvCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
    case Bytecodes._ldc2_w:            ppush(vvCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    case Bytecodes._ldc:               doLdc(itr.getIndex(), itr.bci());    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    case Bytecodes._ldc_w:             doLdc(itr.getIndexBig(), itr.bci());break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    case Bytecodes._iload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    case Bytecodes._fload:             ppload(vCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    case Bytecodes._lload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
    case Bytecodes._dload:             ppload(vvCTS,itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    case Bytecodes._aload:             ppload(rCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    case Bytecodes._iload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    case Bytecodes._fload_0:           ppload(vCTS, 0);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
    case Bytecodes._iload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    case Bytecodes._fload_1:           ppload(vCTS, 1);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
    case Bytecodes._iload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    case Bytecodes._fload_2:           ppload(vCTS, 2);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    case Bytecodes._iload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    case Bytecodes._fload_3:           ppload(vCTS, 3);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    case Bytecodes._lload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    case Bytecodes._dload_0:           ppload(vvCTS, 0);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    case Bytecodes._lload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    case Bytecodes._dload_1:           ppload(vvCTS, 1);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    case Bytecodes._lload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    case Bytecodes._dload_2:           ppload(vvCTS, 2);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    case Bytecodes._lload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    case Bytecodes._dload_3:           ppload(vvCTS, 3);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    case Bytecodes._aload_0:           ppload(rCTS, 0);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    case Bytecodes._aload_1:           ppload(rCTS, 1);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
    case Bytecodes._aload_2:           ppload(rCTS, 2);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    case Bytecodes._aload_3:           ppload(rCTS, 3);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
    case Bytecodes._iaload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    case Bytecodes._faload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    case Bytecodes._baload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    case Bytecodes._caload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    case Bytecodes._saload:            pp(vrCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    case Bytecodes._laload:            pp(vrCTS, vvCTS);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    case Bytecodes._daload:            pp(vrCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    case Bytecodes._aaload:            ppNewRef(vrCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    case Bytecodes._istore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    case Bytecodes._fstore:            ppstore(vCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    case Bytecodes._lstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    case Bytecodes._dstore:            ppstore(vvCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    case Bytecodes._astore:            doAstore(itr.getIndex());     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    case Bytecodes._istore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    case Bytecodes._fstore_0:          ppstore(vCTS, 0);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    case Bytecodes._istore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    case Bytecodes._fstore_1:          ppstore(vCTS, 1);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    case Bytecodes._istore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    case Bytecodes._fstore_2:          ppstore(vCTS, 2);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
    case Bytecodes._istore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    case Bytecodes._fstore_3:          ppstore(vCTS, 3);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    case Bytecodes._lstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    case Bytecodes._dstore_0:          ppstore(vvCTS, 0);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    case Bytecodes._lstore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    case Bytecodes._dstore_1:          ppstore(vvCTS, 1);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    case Bytecodes._lstore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    case Bytecodes._dstore_2:          ppstore(vvCTS, 2);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    case Bytecodes._lstore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    case Bytecodes._dstore_3:          ppstore(vvCTS, 3);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    case Bytecodes._astore_0:          doAstore(0);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    case Bytecodes._astore_1:          doAstore(1);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
    case Bytecodes._astore_2:          doAstore(2);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
    case Bytecodes._astore_3:          doAstore(3);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
    case Bytecodes._iastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
    case Bytecodes._fastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
    case Bytecodes._bastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    case Bytecodes._castore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
    case Bytecodes._sastore:           ppop(vvrCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    case Bytecodes._lastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    case Bytecodes._dastore:           ppop(vvvrCTS);              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    case Bytecodes._aastore:           ppop(rvrCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    case Bytecodes._pop:               ppopAny(1);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    case Bytecodes._pop2:              ppopAny(2);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    case Bytecodes._dup:               ppdupswap(1, "11");         break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    case Bytecodes._dup_x1:            ppdupswap(2, "121");        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    case Bytecodes._dup_x2:            ppdupswap(3, "1321");       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
    case Bytecodes._dup2:              ppdupswap(2, "2121");       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    case Bytecodes._dup2_x1:           ppdupswap(3, "21321");      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    case Bytecodes._dup2_x2:           ppdupswap(4, "214321");     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    case Bytecodes._swap:              ppdupswap(2, "12");         break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    case Bytecodes._iadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    case Bytecodes._fadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    case Bytecodes._isub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    case Bytecodes._fsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
    case Bytecodes._imul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
    case Bytecodes._fmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
    case Bytecodes._idiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    case Bytecodes._fdiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
    case Bytecodes._irem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
    case Bytecodes._frem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
    case Bytecodes._ishl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    case Bytecodes._ishr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    case Bytecodes._iushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    case Bytecodes._iand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
    case Bytecodes._ior:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
    case Bytecodes._ixor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    case Bytecodes._l2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    case Bytecodes._l2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    case Bytecodes._d2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    case Bytecodes._d2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    case Bytecodes._fcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
    case Bytecodes._fcmpg:             pp(vvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
    case Bytecodes._ladd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
    case Bytecodes._dadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    case Bytecodes._lsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    case Bytecodes._dsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
    case Bytecodes._lmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    case Bytecodes._dmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
    case Bytecodes._ldiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    case Bytecodes._ddiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    case Bytecodes._lrem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    case Bytecodes._drem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
    case Bytecodes._land:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
    case Bytecodes._lor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
    case Bytecodes._lxor:              pp(vvvvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    case Bytecodes._ineg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    case Bytecodes._fneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    case Bytecodes._i2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    case Bytecodes._f2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    case Bytecodes._i2c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    case Bytecodes._i2s:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    case Bytecodes._i2b:               pp(vCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    case Bytecodes._lneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
    case Bytecodes._dneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    case Bytecodes._l2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    case Bytecodes._d2l:               pp(vvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
    case Bytecodes._lshl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    case Bytecodes._lshr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    case Bytecodes._lushr:             pp(vvvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    case Bytecodes._i2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    case Bytecodes._i2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
    case Bytecodes._f2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    case Bytecodes._f2d:               pp(vCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
    case Bytecodes._lcmp:              pp(vvvvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
    case Bytecodes._dcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
    case Bytecodes._dcmpg:             pp(vvvvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    case Bytecodes._ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
    case Bytecodes._ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
    case Bytecodes._iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    case Bytecodes._ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
    case Bytecodes._ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
    case Bytecodes._ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
    case Bytecodes._tableswitch:       ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    case Bytecodes._freturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
      ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    case Bytecodes._if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
    case Bytecodes._if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
    case Bytecodes._if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
    case Bytecodes._if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    case Bytecodes._if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    case Bytecodes._if_icmple:         ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
    case Bytecodes._lreturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
      ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
    case Bytecodes._dreturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
      ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    case Bytecodes._if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
    case Bytecodes._if_acmpne:         ppop(rrCTS);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
    case Bytecodes._jsr:               doJsr(itr.dest());          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
    case Bytecodes._jsr_w:             doJsr(itr.dest_w());        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
    case Bytecodes._getstatic:         doField(true,  true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
                                               itr.getIndexBig(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
                                               itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
    case Bytecodes._putstatic:         doField(false, true,  itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
    case Bytecodes._getfield:          doField(true,  false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
    case Bytecodes._putfield:          doField(false, false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
    case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
    case Bytecodes._invokespecial:     doMethod(false, false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
    case Bytecodes._invokestatic:      doMethod(true,  false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
    case Bytecodes._invokeinterface:   doMethod(false, true,  itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    case Bytecodes._newarray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
    case Bytecodes._anewarray:         ppNewRef(vCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    case Bytecodes._checkcast:         doCheckcast(); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    case Bytecodes._arraylength:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
    case Bytecodes._instanceof:        pp(rCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    case Bytecodes._monitorenter:      doMonitorenter(itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    case Bytecodes._monitorexit:       doMonitorexit(itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    case Bytecodes._athrow:            // handled by do_exception_edge() BUT ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
      // vlh(apple): doExceptionEdge() does not get
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
      // called if method has no exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
      if ((!_has_exceptions) && (_monitor_top > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
        _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
    case Bytecodes._areturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
      ppop1(refCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
    case Bytecodes._ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
    case Bytecodes._ifnonnull:         ppop1(refCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    case Bytecodes._multianewarray:    doMultianewarray(itr.codeAt(itr.bci() + 3), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
    case Bytecodes._wide:              throw new RuntimeException("Iterator should skip this bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    case Bytecodes._ret:                                           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
      // Java opcodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
    case Bytecodes._fast_aaccess_0:     ppNewRef(rCTS, itr.bci()); break; // Pair bytecode for (aload_0, _fast_agetfield)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    case Bytecodes._fast_iaccess_0:     ppush1(valCTS);            break; // Pair bytecode for (aload_0, _fast_igetfield)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
    case Bytecodes._fast_igetfield:     pp(rCTS, vCTS);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
    case Bytecodes._fast_agetfield:     ppNewRef(rCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
    case Bytecodes._fast_aload_0:       ppload(rCTS,  0);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
    case Bytecodes._lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
    case Bytecodes._fast_linearswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    case Bytecodes._fast_binaryswitch:  ppop1(valCTS);             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
      throw new RuntimeException("unexpected opcode: " + itr.code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  void  doExceptionEdge                     (BytecodeStream itr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
    // Only check exception edge, if bytecode can trap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    if (!Bytecodes.canTrap(itr.code())) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
    switch (itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
    case Bytecodes._aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    case Bytecodes._fast_aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
      // These bytecodes can trap for rewriting.  We need to assume that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
      // they do not throw exceptions to make the monitor analysis work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
    case Bytecodes._lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
    case Bytecodes._freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    case Bytecodes._dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    case Bytecodes._areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    case Bytecodes._return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      // If the monitor stack height is not zero when we leave the method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
      // then we are either exiting with a non-empty stack or we have
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
      // found monitor trouble earlier in our analysis.  In either case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
      // assume an exception could be taken here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
      if (_monitor_top == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    case Bytecodes._monitorexit:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
      // If the monitor stack height is bad_monitors, then we have detected a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
      // monitor matching problem earlier in the analysis.  If the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
      // monitor stack height is 0, we are about to pop a monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
      // off of an empty stack.  In either case, the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      // could throw an exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
      if (_monitor_top != bad_monitors && _monitor_top != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
    if (_has_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
      int bci = itr.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
      TypeArray exct   = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
      for(int i = 0; i< exct.getLength(); i+=4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
        int start_pc   = exct.getIntAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
        int end_pc     = exct.getIntAt(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
        int handler_pc = exct.getIntAt(i+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
        int catch_type = exct.getIntAt(i+3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
        if (start_pc <= bci && bci < end_pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
          BasicBlock excBB = getBasicBlockAt(handler_pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
          CellTypeStateList excStk  = excBB.stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
          CellTypeStateList cOpStck = stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
          CellTypeState cOpStck_0 = cOpStck.get(0).copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
          int cOpStackTop = _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
          // Exception stacks are always the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
            Assert.that(method().getMaxStack() > 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
          // We remembered the size and first element of "cOpStck"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
          // above; now we temporarily set them to the appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
          // values for an exception handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
          cOpStck.get(0).set(CellTypeState.makeSlotRef(_max_locals));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
          _stack_top = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
          mergeStateIntoBB(excBB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
          // Now undo the temporary change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
          cOpStck.get(0).set(cOpStck_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
          _stack_top = cOpStackTop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
          // If this is a "catch all" handler, then we do not need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
          // consider any additional handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
          if (catch_type == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
    // It is possible that none of the exception handlers would have caught
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
    // the exception.  In this case, we will exit the method.  We must
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
    // ensure that the monitor stack is empty in this case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
    if (_monitor_top == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
    // We pessimistically assume that this exception can escape the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
    // method. (It is possible that it will always be caught, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    // we don't care to analyse the types of the catch clauses.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
    // We don't set _monitor_top to bad_monitors because there are no successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    // to this exceptional exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    if (TraceMonitorMismatch && _monitor_safe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
      // We check _monitor_safe so that we only report the first mismatched
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
      // exceptional exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
      reportMonitorMismatch("non-empty monitor stack at exceptional exit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
    _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
  void  checkType                           (CellTypeState expected, CellTypeState actual) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    if (!expected.equalKind(actual)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
      throw new RuntimeException("wrong type on stack (found: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
                                 actual.toChar() + " expected: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
                                 expected.toChar() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
  void  ppstore                             (CellTypeState[] in,  int loc_no) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
    for (int i = 0; i < in.length && !in[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
      CellTypeState expected = in[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
      CellTypeState actual   = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
      checkType(expected, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
        Assert.that(loc_no >= 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
      setVar(loc_no++, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
  void  ppload                              (CellTypeState[] out, int loc_no) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
    for (int i = 0; i < out.length && !out[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
      CellTypeState out1 = out[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
      CellTypeState vcts = getVar(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
        Assert.that(out1.canBeReference() || out1.canBeValue(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
                    "can only load refs. and values.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
      if (out1.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
          Assert.that(loc_no>=0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
        if (!vcts.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
          // We were asked to push a reference, but the type of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
          // variable can be something else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
          _conflict = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
          if (vcts.canBeUninit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
            // It is a ref-uninit conflict (at least). If there are other
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
            // problems, we'll get them in the next round
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
            addToRefInitSet(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
            vcts = out1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
            // It wasn't a ref-uninit conflict. So must be a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
            // ref-val or ref-pc conflict. Split the variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
            recordRefvalConflict(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
            vcts = out1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
          push(out1); // recover...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
          push(vcts); // preserve reference.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
        // Otherwise it is a conflict, but one that verification would
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
        // have caught if illegal. In particular, it can't be a topCTS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
        // resulting from mergeing two difference pcCTS's since the verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
        // would have rejected any use of such a merge.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
        push(out1); // handle val/init conflict
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
      loc_no++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
  void  ppush1                              (CellTypeState in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
      Assert.that(in.isReference() | in.isValue(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
      System.err.println("   - pushing " + in.toChar());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
    push(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  void  ppush                               (CellTypeState[] in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    for (int i = 0; i < in.length && !in[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
      ppush1(in[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  void  ppush                               (CellTypeStateList in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
    for (int i = 0; i < in.size() && !in.get(i).equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
      ppush1(in.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
  void  ppop1                               (CellTypeState out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
      System.err.println("   - popping " + actual.toChar() + ", expecting " + out.toChar());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    checkType(out, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
  void  ppop                                (CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
    for (int i = 0; i < out.length && !out[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
      ppop1(out[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
  void  ppopAny                             (int poplen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    if (_stack_top >= poplen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
      _stack_top -= poplen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
      throw new RuntimeException("stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
  void  pp                                  (CellTypeState[] in, CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
    ppop(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
    ppush(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  void  ppNewRef                            (CellTypeState[] in, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
    ppop(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
    ppush1(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
  void  ppdupswap                           (int poplen, String out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    CellTypeState[] actual = new CellTypeState[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
    Assert.that(poplen < 5, "this must be less than length of actual vector");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
    // pop all arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
    for(int i = 0; i < poplen; i++) actual[i] = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
    // put them back
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
    for (int i = 0; i < out.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
      char push_ch = out.charAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
      int idx = push_ch - '1';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
        Assert.that(idx >= 0 && idx < poplen, "wrong arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
      push(actual[idx]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  void  doLdc                               (int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    ConstantPool  cp  = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
    ConstantTag   tag = cp.getTagAt(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
    CellTypeState cts = (tag.isString() || tag.isUnresolvedString() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
                         tag.isKlass() || tag.isUnresolvedKlass())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
                          ? CellTypeState.makeLineRef(bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
                          : valCTS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
    ppush1(cts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
  void  doAstore                            (int idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    CellTypeState r_or_p = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
    if (!r_or_p.isAddress() && !r_or_p.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
      // We actually expected ref or pc, but we only report that we expected a ref. It does not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
      // really matter (at least for now)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
      throw new RuntimeException("wrong type on stack (found: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
                                 r_or_p.toChar() + ", expected: {pr})");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
    setVar(idx, r_or_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
  void  doJsr                               (int targBCI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    push(CellTypeState.makeAddr(targBCI));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
  void  doField                             (boolean is_get, boolean is_static, int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
    // Dig up signature for field in constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
    ConstantPool cp        = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    int nameAndTypeIdx     = cp.getNameAndTypeRefIndexAt(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
    int signatureIdx       = cp.getSignatureRefIndexAt(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
    Symbol signature       = cp.getSymbolAt(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
      System.err.println("doField: signature = " + signature.asString() + ", idx = " + idx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
                         ", nameAndTypeIdx = " + nameAndTypeIdx + ", signatureIdx = " + signatureIdx + ", bci = " + bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
    // Parse signature (espcially simple for fields)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
    // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
    char sigch = (char) signature.getByteAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
    CellTypeState[] temp = new CellTypeState[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
    CellTypeState[] eff  = sigcharToEffect(sigch, bci, temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
    CellTypeState[] in = new CellTypeState[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
    CellTypeState[] out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    int i =  0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
    if (is_get) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
      out = eff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
      out = epsilonCTS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
      i   = copyCTS(in, eff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
    if (!is_static) in[i++] = CellTypeState.ref;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
    in[i] = CellTypeState.bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
      Assert.that(i<=3, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
    pp(in, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  void  doMethod                            (boolean is_static, boolean is_interface, int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
    // Dig up signature for field in constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
    ConstantPool cp       = _method.getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
    int nameAndTypeIdx    = cp.getNameAndTypeRefIndexAt(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
    int signatureIdx      = cp.getSignatureRefIndexAt(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
    Symbol signature      = cp.getSymbolAt(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
      System.err.println("doMethod: signature = " + signature.asString() + ", idx = " + idx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
                         ", nameAndTypeIdx = " + nameAndTypeIdx + ", signatureIdx = " + signatureIdx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
                         ", bci = " + bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
    // Parse method signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
    CellTypeStateList out = new CellTypeStateList(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
    CellTypeStateList in  = new CellTypeStateList(MAXARGSIZE+1);   // Includes result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
    ComputeCallStack cse  = new ComputeCallStack(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
    // Compute return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
    int res_length = cse.computeForReturntype(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
    // Temporary hack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
    if (out.get(0).equal(CellTypeState.ref) && out.get(1).equal(CellTypeState.bottom)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
      out.get(0).set(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
      Assert.that(res_length<=4, "max value should be vv");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
    // Compute arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
    int arg_length = cse.computeForParameters(is_static, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
      Assert.that(arg_length<=MAXARGSIZE, "too many locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
    // Pop arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
    for (int i = arg_length - 1; i >= 0; i--) ppop1(in.get(i));// Do args in reverse order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
    // Report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
    if (_report_result_for_send == true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
      fillStackmapForOpcodes(_itr_send, vars(), stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
      _report_result_for_send = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    // Push return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
    ppush(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  void  doMultianewarray                    (int dims, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
      Assert.that(dims >= 1, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
    for(int i = dims -1; i >=0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
      ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
    ppush1(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  void  doMonitorenter                      (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
    if (_monitor_top == bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    // Bail out when we get repeated locks on an identical monitor.  This case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    // isn't too hard to handle and can be made to work if supporting nested
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    // redundant synchronized statements becomes a priority.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    // See also "Note" in do_monitorexit(), below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
    if (actual.isLockReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
        reportMonitorMismatch("nested redundant lock -- bailout...");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
    CellTypeState lock = CellTypeState.makeLockRef(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
    if (!actual.isInfoTop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
      replaceAllCTSMatches(actual, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
      monitorPush(lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  void  doMonitorexit                       (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
    if (_monitor_top == bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
    CellTypeState expected = monitorPop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
    if (!actual.isLockReference() || !expected.equal(actual)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      // The monitor we are exiting is not verifiably the one
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
      // on the top of our monitor stack.  This causes a monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
      // mismatch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
      // We need to mark this basic block as changed so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
      // this monitorexit will be visited again.  We need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
      // do this to ensure that we have accounted for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
      // possibility that this bytecode will throw an
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
      // exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
      BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
      bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
      bb._monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
        reportMonitorMismatch("improper monitor pair");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
      // This code is a fix for the case where we have repeated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
      // locking of the same object in straightline code.  We clear
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
      // out the lock when it is popped from the monitor stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
      // and replace it with an unobtrusive reference value that can
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      // be locked again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
      // Note: when generateOopMap is fixed to properly handle repeated,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
      //       nested, redundant locks on the same object, then this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
      //       fix will need to be removed at that time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
      replaceAllCTSMatches(actual, CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
    if (_report_for_exit_bci == bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
      _matching_enter_bci = expected.getMonitorSource();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  void  doReturnMonitorCheck                () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
    if (_monitor_top > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
      // The monitor stack must be empty when we leave the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
      // for the monitors to be properly matched.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
      // Since there are no successors to the *return bytecode, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
      // isn't necessary to set _monitor_top to bad_monitors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
        reportMonitorMismatch("non-empty monitor stack at return");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
  void  doCheckcast                         () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
    push(actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  CellTypeState[] sigcharToEffect           (char sigch, int bci, CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
    // Object and array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
    if (sigch=='L' || sigch=='[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
      out[0] = CellTypeState.makeLineRef(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
      out[1] = CellTypeState.bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
      return out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
    if (sigch == 'J' || sigch == 'D' ) return vvCTS;  // Long and Double
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
    if (sigch == 'V' ) return epsilonCTS;             // Void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
    return vCTS;                                      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  // Copies (optionally bottom/zero terminated) CTS string from "src" into "dst".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  //   Does NOT terminate with a bottom. Returns the number of cells copied.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  int copyCTS                               (CellTypeState[] dst, CellTypeState[] src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
    int idx = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
    for (; idx < src.length && !src[idx].isBottom(); idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
      dst[idx] = src[idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    return idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
  // Create result set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  boolean  _report_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  boolean  _report_result_for_send;         // Unfortunatly, stackmaps for sends are special, so we need some extra
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  BytecodeStream _itr_send;                 // variables to handle them properly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
  void  reportResult                        () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    //    if (TraceNewOopMapGeneration) tty.print_cr("Report result pass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
    // We now want to report the result of the parse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
    _report_result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
    // Prolog code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
    fillStackmapProlog(_gc_points);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
    // Mark everything changed, then do one interpretation pass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    for (int i = 0; i<_bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
      if (_basic_blocks[i].isReachable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
        _basic_blocks[i].setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
        interpBB(_basic_blocks[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
    // Note: Since we are skipping dead-code when we are reporting results, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
    // the no. of encountered gc-points might be fewer than the previously number
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    // we have counted. (dead-code is a pain - it should be removed before we get here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
    fillStackmapEpilog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
    // Report initvars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
    fillInitVars(_init_vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
    _report_result = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
  // Initvars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
  List/*<Integer>*/ _init_vars;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
  void  initializeVars                      () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
    for (int k = 0; k < _init_vars.size(); k++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
      _state.get(((Integer) _init_vars.get(k)).intValue()).set(CellTypeState.makeSlotRef(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
  void  addToRefInitSet                     (int localNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
    //    if (TraceNewOopMapGeneration)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
    //      tty.print_cr("Added init vars: %d", localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
    Integer local = new Integer(localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
    // Is it already in the set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
    if (_init_vars.contains(local))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
    _init_vars.add(local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
  // Conflicts rewrite logic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
  boolean   _conflict;                      // True, if a conflict occured during interpretation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
  int       _nof_refval_conflicts;          // No. of conflicts that require rewrites
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
  int[]     _new_var_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  void recordRefvalConflict                 (int varNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
      Assert.that(varNo>=0 && varNo< _max_locals, "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
    if (TraceOopMapRewrites) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
      System.err.println("### Conflict detected (local no: " + varNo + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
    if (_new_var_map == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
      _new_var_map = new int[_max_locals];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
      for (int k = 0; k < _max_locals; k++)  _new_var_map[k] = k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
    if ( _new_var_map[varNo] == varNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
      // Check if max. number of locals has been reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
      if (_max_locals + _nof_refval_conflicts >= MAX_LOCAL_VARS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
        throw new RuntimeException("Rewriting exceeded local variable limit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
      _new_var_map[varNo] = _max_locals + _nof_refval_conflicts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
      _nof_refval_conflicts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
  void rewriteRefvalConflicts               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
    if (_nof_refval_conflicts > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
      if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
        throw new RuntimeException("Should not reach here (method rewriting should have been done by the VM already)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
        throw new RuntimeException("Method rewriting not yet implemented in Java");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  // Rewriting-related routines are not needed here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
  //  void rewrite_refval_conflict              (int from, int to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
  //  bool rewrite_refval_conflict_inst         (BytecodeStream *i, int from, int to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
  //  bool rewrite_load_or_store                (BytecodeStream *i, Bytecodes.Code bc, Bytecodes.Code bc0, unsigned int varNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
  //  bool expand_current_instr                 (int bci, int ilen, int newIlen, u_char inst_buffer[]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  //  bool is_astore                            (BytecodeStream *itr, int *index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  //  bool is_aload                             (BytecodeStream *itr, int *index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  // List of bci's where a return address is on top of the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
  //  GrowableArray<intptr_t> *_ret_adr_tos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
  //  bool stack_top_holds_ret_addr             (int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
  //  void compute_ret_adr_at_TOS               ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
  //  void update_ret_adr_at_TOS                (int bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
  String stateVecToString                   (CellTypeStateList vec, int len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
      _state_vec_buf[i] = vec.get(i).toChar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
    return new String(_state_vec_buf, 0, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
  // Helper method. Can be used in subclasses to fx. calculate gc_points. If the current instuction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
  // is a control transfer, then calls the jmpFct all possible destinations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
  void  retJumpTargetsDo                    (BytecodeStream bcs, JumpClosure closure, int varNo, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
    CellTypeState ra = vars().get(varNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
    if (!ra.isGoodAddress()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
      throw new RuntimeException("ret returns from two jsr subroutines?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
    int target = ra.getInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
    RetTableEntry rtEnt = _rt.findJsrsForTarget(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
    int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
    for (int i = 0; i < rtEnt.nofJsrs(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
      int target_bci = rtEnt.jsrs(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
      // Make sure a jrtRet does not set the changed bit for dead basicblock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
      BasicBlock jsr_bb    = getBasicBlockContaining(target_bci - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
        BasicBlock target_bb = _basic_blocks[1 + bbIndex(jsr_bb)];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
        Assert.that(target_bb  == getBasicBlockAt(target_bci), "wrong calc. of successor basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
      boolean alive = jsr_bb.isAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
      //      if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
      //        tty.print("pc = %d, ret . %d alive: %s\n", bci, target_bci, alive ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
      if (alive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
        closure.process(this, target_bci, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
  /** If the current instruction in "c" has no effect on control flow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
      returns "true".  Otherwise, calls "closure.process()" one or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
      more times, with "c", an appropriate "pcDelta", and "data" as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
      arguments, then returns "false".  There is one exception: if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
      current instruction is a "ret", returns "false" without calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
      "jmpFct". Arrangements for tracking the control flow of a "ret"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
      must be made externally. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
  boolean jumpTargetsDo                     (BytecodeStream bcs, JumpClosure closure, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
    int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
    switch (bcs.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
    case Bytecodes._ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
    case Bytecodes._ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
    case Bytecodes._iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
    case Bytecodes._ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
    case Bytecodes._ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
    case Bytecodes._ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
    case Bytecodes._if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
    case Bytecodes._if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
    case Bytecodes._if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
    case Bytecodes._if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
    case Bytecodes._if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
    case Bytecodes._if_icmple:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
    case Bytecodes._if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
    case Bytecodes._if_acmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
    case Bytecodes._ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
    case Bytecodes._ifnonnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
      closure.process(this, bci + 3, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
    case Bytecodes._goto:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
    case Bytecodes._goto_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
      closure.process(this, bcs.dest_w(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
    case Bytecodes._tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
        BytecodeTableswitch tableswitch = BytecodeTableswitch.at(bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
        int len = tableswitch.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
        closure.process(this, bci + tableswitch.defaultOffset(), data); /* Default. jump address */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
        while (--len >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
          closure.process(this, bci + tableswitch.destOffsetAt(len), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
    case Bytecodes._fast_linearswitch:     // Java opcodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
    case Bytecodes._fast_binaryswitch:     // get_int_table handles conversions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
    case Bytecodes._lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
        BytecodeLookupswitch lookupswitch = BytecodeLookupswitch.at(bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
        int npairs = lookupswitch.numberOfPairs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
        closure.process(this, bci + lookupswitch.defaultOffset(), data); /* Default. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
        while(--npairs >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
          LookupswitchPair pair = lookupswitch.pairAt(npairs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
          closure.process(this, bci + pair.offset(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
    case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
      Assert.that(bcs.isWide()==false, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
    case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
      closure.process(this, bcs.dest_w(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
    case Bytecodes._wide:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
      throw new RuntimeException("Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
    case Bytecodes._athrow:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
    case Bytecodes._lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
    case Bytecodes._freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
    case Bytecodes._dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
    case Bytecodes._areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
    case Bytecodes._return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
    case Bytecodes._ret:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
  // Monitor matching
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
  //  int fill_out_arrays                       (int *enter, int *exit, int max);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  //  friend class RelocCallback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
  // Public routines for GenerateOopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
  public GenerateOopMap(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
    // We have to initialize all variables here, that can be queried direcly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
    _max_locals=0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
    _init_vars = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
    _rt = new RetTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
  // Compute the map.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
  public void computeMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
      System.err.println("*** GenerateOopMap: computing for " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
                         method().getMethodHolder().getName().asString() + "." +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
                         method().getName().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
                         method().getSignature().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
    // Initialize values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
    _got_error      = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
    _conflict       = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
    _max_locals     = (int) method().getMaxLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
    _max_stack      = (int) method().getMaxStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
    _has_exceptions = (method().getExceptionTable().getLength() > 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
    _nof_refval_conflicts = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
    _init_vars      = new ArrayList(5);  // There are seldom more than 5 init_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
    _report_result  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
    _report_result_for_send = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
    _report_for_exit_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
    _new_var_map    = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
    //    _ret_adr_tos    = new GrowableArray<intptr_t>(5);  // 5 seems like a good number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
    //    _did_rewriting  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
    //    _did_relocation = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
      tty.print("Method name: %s\n", method().name().as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
      if (Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
        _method.print_codes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
        tty.print_cr("Exception table:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
        typeArrayOop excps = method().exception_table();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
        for(int i = 0; i < excps.length(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
          tty.print_cr("[%d - %d] . %d", excps.int_at(i + 0), excps.int_at(i + 1), excps.int_at(i + 2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
    // if no code - do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
    // compiler needs info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
    if (method().getCodeSize() == 0 || _max_locals + method().getMaxStack() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
      fillStackmapProlog(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
      fillStackmapEpilog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
    // Step 1: Compute all jump targets and their return value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
      _rt.computeRetTable(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
    // Step 2: Find all basic blocks and count GC points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
      markBBHeadersAndCountGCPoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
    // Step 3: Calculate stack maps
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
      doInterpretation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
    // Step 4:Return results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
    if (!_got_error && reportResults())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
      reportResult();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
    if (_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
      // We could expand this code to throw somekind of exception (e.g., VerifyException). However,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
      // an exception thrown in this part of the code is likly to mean that we are executing some
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
      // illegal bytecodes (that the verifier should have caught if turned on), so we will just exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
      // with a fatal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
      throw new RuntimeException("Illegal bytecode sequence encountered while generating interpreter pointer maps - method should be rejected by verifier.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
  // Do a callback on fill_stackmap_for_opcodes for basicblock containing bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
  public void resultForBasicblock(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
    //    if (TraceNewOopMapGeneration) tty.print_cr("Report result pass for basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
    // We now want to report the result of the parse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
    _report_result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
    // Find basicblock and report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
      Assert.that(bb.isReachable(), "getting result from unreachable basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
    bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
    interpBB(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
  // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
  public int maxLocals()                                  { return _max_locals; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
  public Method method()                                  { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
  //  bool did_rewriting()                             { return _did_rewriting; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
  //  bool did_relocation()                            { return _did_relocation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
  //  static void print_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
  // Monitor query
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
  public boolean monitorSafe()                            { return _monitor_safe; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
  // Takes as input the bci of a monitorexit bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
  // Returns the bci of the corresponding monitorenter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
  // Can only be called safely after computeMap() is run.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  public int  getMonitorMatch(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
      Assert.that(_monitor_safe, "Attempt to match monitor in broken code.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
    //    if (TraceNewOopMapGeneration)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
    //      tty.print_cr("Report monitor match for bci : %d", bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
    // We want to report the line number of the monitorenter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
    _report_for_exit_bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
    _matching_enter_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
    // Find basicblock and report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
    if (bb.isReachable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
      bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
      interpBB(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
      _report_for_exit_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
        Assert.that(_matching_enter_bci != -1, "monitor matching invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
    return _matching_enter_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
  // Returns a Arena allocated object that contains pairing info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
  //  MonitorPairs* get_pairing(Arena *arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
  // copies monitor pairing info into area; area_count specifies maximum
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
  // possible number of monitor pairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
  //  int copy_pairing(int pair_count, MonitorPairs* pairs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
  private int bbIndex(BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
    for (int i = 0; i < _basic_blocks.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
      if (_basic_blocks[i] == bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
        return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
    throw new RuntimeException("Should have found block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
  // Specialization methods. Intended use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
  // - possibleGCPoint must return true for every bci for which the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
  //   stackmaps must be returned
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
  // - fillStackmapProlog is called just before the result is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
  //   reported. The arguments tells the estimated number of gc points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
  // - fillStackmapForOpcodes is called once for each bytecode index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
  //   in order (0...code_length-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
  // - fillStackmapEpilog is called after all results has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
  //   reported. Note: Since the algorithm does not report stackmaps for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
  //   deadcode, fewer gc_points might have been encounted than assumed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
  //   during the epilog. It is the responsibility of the subclass to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
  //   count the correct number.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
  // - fillInitVars are called once with the result of the init_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
  //   computation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
  // All these methods are used during a call to computeMap. Note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
  // None of the return results are valid after computeMap returns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
  // since all values are allocated as resource objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
  // All virtual method must be implemented in subclasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  public boolean allowRewrites            ()                              { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
  public boolean reportResults            ()                              { return true;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
  public boolean reportInitVars           ()                              { return true;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
  public boolean possibleGCPoint          (BytecodeStream bcs)            { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
  public void fillStackmapProlog          (int nofGCPoints)               { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
  public void fillStackmapEpilog          ()                              { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
  public void fillStackmapForOpcodes      (BytecodeStream bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
                                           CellTypeStateList vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
                                           CellTypeStateList stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
                                           int stackTop)                  { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
  public void fillInitVars                (List/*<Integer>*/ init_vars)   { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
}