hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java
author jrose
Wed, 09 Jun 2010 18:50:45 -0700
changeset 5882 6b2aecc4f7d8
parent 5547 f4b087cbb361
child 7662 5f31baaff55b
permissions -rw-r--r--
6939203: JSR 292 needs method handle constants Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode. Reviewed-by: twisti, never
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:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   569
      case Bytecodes._invokedynamic:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
        // FIXME: print signature of referenced method (need more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
        // accessors in ConstantPool and ConstantPoolCache)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
        int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        tty.print(" idx " + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
          int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
          ConstantPool cp       = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
          int nameAndTypeIdx    = cp.name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
          int signatureIdx      = cp.signature_ref_index_at(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
          symbolOop signature   = cp.symbol_at(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
          tty.print("%s", signature.as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
      tty.print("          stack    = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      printStates(tty, stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      if (_monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
        tty.print("          monitors = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
        printStates(tty, monitors(), _monitor_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
        tty.print("          [bad monitor stack]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
      tty.print("    " + currentBC.bci() + "  vars = '" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
                stateVecToString(vars(), _max_locals) + "' ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      tty.print("     stack = '" + stateVecToString(stack(), _stack_top) + "' ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      if (_monitor_top != bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
        tty.print("  monitors = '" + stateVecToString(monitors(), _monitor_top) + "'  \t" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
                  Bytecodes.name(currentBC.code()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
        tty.print("  [bad monitor stack]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      switch(currentBC.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      case Bytecodes._invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      case Bytecodes._invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
      case Bytecodes._invokeinterface:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   609
      case Bytecodes._invokedynamic:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
        // FIXME: print signature of referenced method (need more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
        // accessors in ConstantPool and ConstantPoolCache)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
        int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
        tty.print(" idx " + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
          int idx = currentBC.getIndexBig();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
          constantPoolOop cp    = method().constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
          int nameAndTypeIdx    = cp.name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
          int signatureIdx      = cp.signature_ref_index_at(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
          symbolOop signature   = cp.symbol_at(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
          tty.print("%s", signature.as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  void            reportMonitorMismatch      (String msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      System.err.print("    Monitor mismatch in method ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
      method().printValueOn(System.err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
      System.err.println(": " + msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  // Basicblock info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  BasicBlock[]    _basic_blocks;             // Array of basicblock info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  int             _gc_points;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  int             _bb_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  BitMap          _bb_hdr_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  // Basicblocks methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  void          initializeBB               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    _gc_points = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    _bb_count  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    _bb_hdr_bits = new BitMap((int) _method.getCodeSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  void          markBBHeadersAndCountGCPoints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    initializeBB();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    boolean fellThrough = false;  // False to get first BB marked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    // First mark all exception handlers as start of a basic-block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    TypeArray excps = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    for(int i = 0; i < excps.getLength(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      int handler_pc_idx = i+2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      markBB(excps.getIntAt(handler_pc_idx), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    // Then iterate through the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    BytecodeStream bcs = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    int bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    while( (bytecode = bcs.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      if (!fellThrough)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
        markBB(bci, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
      fellThrough = jumpTargetsDo(bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
                                  new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
                                      public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
                                        c.markBB(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
                                      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
                                    },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
                                  null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
      /* We will also mark successors of jsr's as basic block headers. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      switch (bytecode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
          Assert.that(!fellThrough, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
        markBB(bci + Bytecodes.lengthFor(bytecode), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
      case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
          Assert.that(!fellThrough, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
        markBB(bci + Bytecodes.lengthFor(bytecode), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      if (possibleGCPoint(bcs))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        _gc_points++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  boolean       isBBHeader                  (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    return _bb_hdr_bits.at(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  int           gcPoints                    () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    return _gc_points;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  int           bbCount                     () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    return _bb_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  void          setBBMarkBit                (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    _bb_hdr_bits.atPut(bci, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  void          clear_bbmark_bit            (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    _bb_hdr_bits.atPut(bci, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  BasicBlock    getBasicBlockAt             (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
      Assert.that(bb._bci == bci, "should have found BB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    return bb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  BasicBlock    getBasicBlockContaining     (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    BasicBlock[] bbs = _basic_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    int lo = 0, hi = _bb_count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    while (lo <= hi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
      int m = (lo + hi) / 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      int mbci = bbs[m]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      int nbci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
      if ( m == _bb_count-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
          Assert.that( bci >= mbci && bci < method().getCodeSize(), "sanity check failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
        return bbs[m];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
        nbci = bbs[m+1]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      if ( mbci <= bci && bci < nbci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
        return bbs[m];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      } else if (mbci < bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
        lo = m + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
          Assert.that(mbci > bci, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
        hi = m - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
    throw new RuntimeException("should have found BB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  void          interpBB                    (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    // We do not want to do anything in case the basic-block has not been initialized. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    // will happen in the case where there is dead-code hang around in a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
      Assert.that(bb.isReachable(), "should be reachable or deadcode exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    restoreState(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    BytecodeStream itr = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    // Set iterator interval to be the current basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    int lim_bci = nextBBStartPC(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    itr.setInterval(bb._bci, lim_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      System.err.println("interpBB: method = " + method().getName().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                         method().getSignature().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
                         ", BCI interval [" + bb._bci + ", " + lim_bci + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
        System.err.print("Bytecodes:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        for (int i = bb._bci; i < lim_bci; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
          System.err.print(" 0x" + Long.toHexString(method().getBytecodeOrBPAt(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
        System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      Assert.that(lim_bci != bb._bci, "must be at least one instruction in a basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    itr.next(); // read first instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    // Iterates through all bytecodes except the last in a basic block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    // We handle the last one special, since there is controlflow change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    while(itr.nextBCI() < lim_bci && !_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      if (_has_exceptions || (_monitor_top != 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        // We do not need to interpret the results of exceptional
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
        // continuation from this instruction when the method has no
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
        // exception handlers and the monitor stack is currently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
        // empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
        doExceptionEdge(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      interp1(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
      itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    // Handle last instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    if (!_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
        Assert.that(itr.nextBCI() == lim_bci, "must point to end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      if (_has_exceptions || (_monitor_top != 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
        doExceptionEdge(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      interp1(itr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      boolean fall_through = jumpTargetsDo(itr, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
          public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
            c.mergeState(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
        }, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      if (_got_error)  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
      if (itr.code() == Bytecodes._ret) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
          Assert.that(!fall_through, "cannot be set if ret instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
        // Automatically handles 'wide' ret indicies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
        retJumpTargetsDo(itr, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
            public void process(GenerateOopMap c, int bcpDelta, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
              c.mergeState(bcpDelta, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
          }, itr.getIndex(), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
      } else if (fall_through) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
        // Hit end of BB, but the instr. was a fall-through instruction,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
        // so perform transition as if the BB ended in a "jump".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
          Assert.that(lim_bci == _basic_blocks[bbIndex(bb) + 1]._bci, "there must be another bb");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
        mergeStateIntoBB(_basic_blocks[bbIndex(bb) + 1]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  void          restoreState                (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    for (int i = 0; i < _state_len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      _state.get(i).set(bb._state.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    _stack_top   = bb._stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    _monitor_top = bb._monitor_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  int           nextBBStartPC               (BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    int bbNum = bbIndex(bb) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    if (bbNum == _bb_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      return (int) method().getCodeSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    return _basic_blocks[bbNum]._bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  void          updateBasicBlocks           (int bci, int delta) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    BitMap bbBits = new BitMap((int) (_method.getCodeSize() + delta));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    for(int k = 0; k < _bb_count; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
      if (_basic_blocks[k]._bci > bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
        _basic_blocks[k]._bci     += delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
        _basic_blocks[k]._end_bci += delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
      bbBits.atPut(_basic_blocks[k]._bci, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    _bb_hdr_bits = bbBits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  void markBB(int bci, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
      Assert.that(bci>= 0 && bci < method().getCodeSize(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    if (isBBHeader(bci))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    //    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    //      tty.print_cr("Basicblock#%d begins at: %d", c._bb_count, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    setBBMarkBit(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    _bb_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  // Dead code detection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  void          markReachableCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    final int[] change = new int[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    change[0] = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    // Mark entry basic block as alive and all exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    _basic_blocks[0].markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
    TypeArray excps = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
    for(int i = 0; i < excps.getLength(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      int handler_pc_idx = i+2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
      BasicBlock bb = getBasicBlockAt(excps.getIntAt(handler_pc_idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      // If block is not already alive (due to multiple exception handlers to same bb), then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
      // make it alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
      if (bb.isDead())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
        bb.markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    BytecodeStream bcs = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    // Iterate through all basic blocks until we reach a fixpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    while (change[0] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      change[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      for (int i = 0; i < _bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
        BasicBlock bb = _basic_blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
        if (bb.isAlive()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
          // Position bytecodestream at last bytecode in basicblock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
          bcs.setStart(bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
          bcs.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
          int bytecode = bcs.code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
          int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
            Assert.that(bci == bb._end_bci, "wrong bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
          boolean fell_through = jumpTargetsDo(bcs, new JumpClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
              public void process(GenerateOopMap c, int bciDelta, int[] change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
                c.reachableBasicblock(bciDelta, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
            }, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
          // We will also mark successors of jsr's as alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
          switch (bytecode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
          case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
          case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
            if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
              Assert.that(!fell_through, "should not happen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
            reachableBasicblock(bci + Bytecodes.lengthFor(bytecode), change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
          if (fell_through) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
            // Mark successor as alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
            if (_basic_blocks[i+1].isDead()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
              _basic_blocks[i+1].markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
              change[0] = 1;
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
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  void  reachableBasicblock        (int bci, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
      Assert.that(bci>= 0 && bci < method().getCodeSize(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    BasicBlock bb = getBasicBlockAt(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    if (bb.isDead()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      bb.markAsAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
      data[0] = 1; // Mark basicblock as changed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  // Interpretation methods (primary)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  void  doInterpretation                    () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    // "i" is just for debugging, so we can detect cases where this loop is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    // iterated more than once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
      // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      //      if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
      //        tty.print("\n\nIteration #%d of do_interpretation loop, method:\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
      //        method().print_name(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
      //        tty.print("\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
      _conflict = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
      _monitor_safe = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
      // init_state is now called from init_basic_blocks.  The length of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      // state vector cannot be determined until we have made a pass through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
      // the bytecodes counting the possible monitor entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      if (!_got_error) initBasicBlocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
      if (!_got_error) setupMethodEntryState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      if (!_got_error) interpAll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
      if (!_got_error) rewriteRefvalConflicts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    } while (_conflict && !_got_error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  void  initBasicBlocks                     () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    // Note: Could consider reserving only the needed space for each BB's state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    // (entry stack may not be of maximal height for every basic block).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    // But cumbersome since we don't know the stack heights yet.  (Nor the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    // monitor stack heights...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    _basic_blocks = new BasicBlock[_bb_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    for (int i = 0; i < _bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
      _basic_blocks[i] = new BasicBlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    // Make a pass through the bytecodes.  Count the number of monitorenters.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    // This can be used an upper bound on the monitor stack depth in programs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    // which obey stack discipline with their monitor usage.  Initialize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    // known information about basic blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    BytecodeStream j = new BytecodeStream(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    int bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    int bbNo = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    int monitor_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    int prev_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    while( (bytecode = j.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      if (j.code() == Bytecodes._monitorenter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
        monitor_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
      int bci = j.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      if (isBBHeader(bci)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
        // Initialize the basicblock structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
        BasicBlock bb    = _basic_blocks[bbNo];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
        bb._bci          = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
        bb._max_locals   = _max_locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
        bb._max_stack    = _max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
        bb.setChanged(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
        bb._stack_top    = BasicBlock._dead_basic_block; // Initialize all basicblocks are dead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
        bb._monitor_top  = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
        if (bbNo > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
          _basic_blocks[bbNo - 1]._end_bci = prev_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
        bbNo++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
      // Remember prevous bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
      prev_bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    // Set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    _basic_blocks[bbNo-1]._end_bci = prev_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    _max_monitors = monitor_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    // Now that we have a bound on the depth of the monitor stack, we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    // initialize the CellTypeState-related information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    initState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    // We allocate space for all state-vectors for all basicblocks in one huge chuck.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    // Then in the next part of the code, we set a pointer in each _basic_block that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    // points to each piece.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    CellTypeStateList basicBlockState = new CellTypeStateList(bbNo * _state_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    // Make a pass over the basicblocks and assign their state vectors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    for (int blockNum=0; blockNum < bbNo; blockNum++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
      BasicBlock bb = _basic_blocks[blockNum];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
      bb._state = basicBlockState.subList(blockNum * _state_len, (blockNum + 1) * _state_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
        if (blockNum + 1 < bbNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
          int bc_len = Bytecodes.javaLengthAt(_method, bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
          Assert.that(bb._end_bci + bc_len == _basic_blocks[blockNum + 1]._bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
                      "unmatched bci info in basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
      BasicBlock bb = _basic_blocks[bbNo-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
      int bc_len = Bytecodes.javaLengthAt(_method, bb._end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
      Assert.that(bb._end_bci + bc_len == _method.getCodeSize(), "wrong end bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    // Check that the correct number of basicblocks was found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    if (bbNo !=_bb_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
      if (bbNo < _bb_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
        throw new RuntimeException("jump into the middle of instruction?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
        throw new RuntimeException("extra basic blocks - should not happen?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    // Mark all alive blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    markReachableCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  void  setupMethodEntryState               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    // Initialize all locals to 'uninit' and set stack-height to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    makeContextUninitialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    // Initialize CellState type of arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    methodsigToEffect(method().getSignature(), method().isStatic(), vars());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    // If some references must be pre-assigned to null, then set that up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    initializeVars();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    // This is the start state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    mergeStateIntoBB(_basic_blocks[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
      Assert.that(_basic_blocks[0].changed(), "we are not getting off the ground");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  void  interpAll                           () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    boolean change = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
    while (change && !_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
      change = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
      for (int i = 0; i < _bb_count && !_got_error; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
        BasicBlock bb = _basic_blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
        if (bb.changed()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
          if (_got_error) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
          change = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
          bb.setChanged(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
          interpBB(bb);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  // Interpretation methods (secondary)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  /** Sets the current state to be the state after executing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
      current instruction, starting in the current state. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  void  interp1                             (BytecodeStream itr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      System.err.println(" - bci " + itr.bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    //    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
    //      print_current_state(tty, itr, TraceNewOopMapGenerationDetailed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
    // Should we report the results? Result is reported *before* the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    // instruction at the current bci is executed.  However, not for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    // calls. For calls we do not want to include the arguments, so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    // postpone the reporting until they have been popped (in method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
    // ppl).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    if (_report_result == true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      switch(itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      case Bytecodes._invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
      case Bytecodes._invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
      case Bytecodes._invokeinterface:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
  1139
      case Bytecodes._invokedynamic:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
        _itr_send = itr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
        _report_result_for_send = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
        fillStackmapForOpcodes(itr, vars(), stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    // abstract interpretation of current opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    switch(itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
    case Bytecodes._nop:               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    case Bytecodes._goto:              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
    case Bytecodes._goto_w:            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
    case Bytecodes._iinc:              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    case Bytecodes._return:            doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
    case Bytecodes._aconst_null:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    case Bytecodes._new:               ppush1(CellTypeState.makeLineRef(itr.bci()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
    case Bytecodes._iconst_m1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    case Bytecodes._iconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
    case Bytecodes._iconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    case Bytecodes._iconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    case Bytecodes._iconst_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    case Bytecodes._iconst_4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
    case Bytecodes._iconst_5:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    case Bytecodes._fconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
    case Bytecodes._fconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
    case Bytecodes._fconst_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    case Bytecodes._bipush:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    case Bytecodes._sipush:            ppush1(valCTS);             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
    case Bytecodes._lconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
    case Bytecodes._lconst_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
    case Bytecodes._dconst_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
    case Bytecodes._dconst_1:          ppush(vvCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    case Bytecodes._ldc2_w:            ppush(vvCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    case Bytecodes._ldc:               doLdc(itr.getIndex(), itr.bci());    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    case Bytecodes._ldc_w:             doLdc(itr.getIndexBig(), itr.bci());break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    case Bytecodes._iload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
    case Bytecodes._fload:             ppload(vCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    case Bytecodes._lload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
    case Bytecodes._dload:             ppload(vvCTS,itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    case Bytecodes._aload:             ppload(rCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    case Bytecodes._iload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
    case Bytecodes._fload_0:           ppload(vCTS, 0);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    case Bytecodes._iload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    case Bytecodes._fload_1:           ppload(vCTS, 1);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    case Bytecodes._iload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    case Bytecodes._fload_2:           ppload(vCTS, 2);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    case Bytecodes._iload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    case Bytecodes._fload_3:           ppload(vCTS, 3);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    case Bytecodes._lload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    case Bytecodes._dload_0:           ppload(vvCTS, 0);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    case Bytecodes._lload_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    case Bytecodes._dload_1:           ppload(vvCTS, 1);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    case Bytecodes._lload_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
    case Bytecodes._dload_2:           ppload(vvCTS, 2);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    case Bytecodes._lload_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    case Bytecodes._dload_3:           ppload(vvCTS, 3);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    case Bytecodes._aload_0:           ppload(rCTS, 0);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    case Bytecodes._aload_1:           ppload(rCTS, 1);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
    case Bytecodes._aload_2:           ppload(rCTS, 2);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    case Bytecodes._aload_3:           ppload(rCTS, 3);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    case Bytecodes._iaload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    case Bytecodes._faload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    case Bytecodes._baload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    case Bytecodes._caload:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    case Bytecodes._saload:            pp(vrCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    case Bytecodes._laload:            pp(vrCTS, vvCTS);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    case Bytecodes._daload:            pp(vrCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    case Bytecodes._aaload:            ppNewRef(vrCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    case Bytecodes._istore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    case Bytecodes._fstore:            ppstore(vCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    case Bytecodes._lstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    case Bytecodes._dstore:            ppstore(vvCTS, itr.getIndex()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    case Bytecodes._astore:            doAstore(itr.getIndex());     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    case Bytecodes._istore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    case Bytecodes._fstore_0:          ppstore(vCTS, 0);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    case Bytecodes._istore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
    case Bytecodes._fstore_1:          ppstore(vCTS, 1);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    case Bytecodes._istore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
    case Bytecodes._fstore_2:          ppstore(vCTS, 2);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    case Bytecodes._istore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    case Bytecodes._fstore_3:          ppstore(vCTS, 3);           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    case Bytecodes._lstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    case Bytecodes._dstore_0:          ppstore(vvCTS, 0);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    case Bytecodes._lstore_1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    case Bytecodes._dstore_1:          ppstore(vvCTS, 1);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    case Bytecodes._lstore_2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    case Bytecodes._dstore_2:          ppstore(vvCTS, 2);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    case Bytecodes._lstore_3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    case Bytecodes._dstore_3:          ppstore(vvCTS, 3);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
    case Bytecodes._astore_0:          doAstore(0);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
    case Bytecodes._astore_1:          doAstore(1);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
    case Bytecodes._astore_2:          doAstore(2);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
    case Bytecodes._astore_3:          doAstore(3);                break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    case Bytecodes._iastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
    case Bytecodes._fastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    case Bytecodes._bastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    case Bytecodes._castore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    case Bytecodes._sastore:           ppop(vvrCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    case Bytecodes._lastore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    case Bytecodes._dastore:           ppop(vvvrCTS);              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    case Bytecodes._aastore:           ppop(rvrCTS);               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    case Bytecodes._pop:               ppopAny(1);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    case Bytecodes._pop2:              ppopAny(2);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
    case Bytecodes._dup:               ppdupswap(1, "11");         break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    case Bytecodes._dup_x1:            ppdupswap(2, "121");        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    case Bytecodes._dup_x2:            ppdupswap(3, "1321");       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    case Bytecodes._dup2:              ppdupswap(2, "2121");       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    case Bytecodes._dup2_x1:           ppdupswap(3, "21321");      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    case Bytecodes._dup2_x2:           ppdupswap(4, "214321");     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    case Bytecodes._swap:              ppdupswap(2, "12");         break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    case Bytecodes._iadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
    case Bytecodes._fadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
    case Bytecodes._isub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
    case Bytecodes._fsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    case Bytecodes._imul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
    case Bytecodes._fmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
    case Bytecodes._idiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
    case Bytecodes._fdiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    case Bytecodes._irem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    case Bytecodes._frem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    case Bytecodes._ishl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
    case Bytecodes._ishr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
    case Bytecodes._iushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    case Bytecodes._iand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    case Bytecodes._ior:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    case Bytecodes._ixor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    case Bytecodes._l2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    case Bytecodes._l2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
    case Bytecodes._d2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
    case Bytecodes._d2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
    case Bytecodes._fcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
    case Bytecodes._fcmpg:             pp(vvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    case Bytecodes._ladd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
    case Bytecodes._dadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    case Bytecodes._lsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
    case Bytecodes._dsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    case Bytecodes._lmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    case Bytecodes._dmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    case Bytecodes._ldiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
    case Bytecodes._ddiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
    case Bytecodes._lrem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
    case Bytecodes._drem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
    case Bytecodes._land:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    case Bytecodes._lor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    case Bytecodes._lxor:              pp(vvvvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    case Bytecodes._ineg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    case Bytecodes._fneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    case Bytecodes._i2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    case Bytecodes._f2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
    case Bytecodes._i2c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    case Bytecodes._i2s:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
    case Bytecodes._i2b:               pp(vCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    case Bytecodes._lneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
    case Bytecodes._dneg:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
    case Bytecodes._l2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    case Bytecodes._d2l:               pp(vvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    case Bytecodes._lshl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    case Bytecodes._lshr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    case Bytecodes._lushr:             pp(vvvCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    case Bytecodes._i2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
    case Bytecodes._i2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
    case Bytecodes._f2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
    case Bytecodes._f2d:               pp(vCTS, vvCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
    case Bytecodes._lcmp:              pp(vvvvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    case Bytecodes._dcmpl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
    case Bytecodes._dcmpg:             pp(vvvvCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    case Bytecodes._ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
    case Bytecodes._ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
    case Bytecodes._iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
    case Bytecodes._ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
    case Bytecodes._ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    case Bytecodes._ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    case Bytecodes._tableswitch:       ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    case Bytecodes._freturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
    case Bytecodes._if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    case Bytecodes._if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    case Bytecodes._if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
    case Bytecodes._if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
    case Bytecodes._if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
    case Bytecodes._if_icmple:         ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
    case Bytecodes._lreturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
      ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
    case Bytecodes._dreturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
      ppop(vvCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
    case Bytecodes._if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
    case Bytecodes._if_acmpne:         ppop(rrCTS);                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
    case Bytecodes._jsr:               doJsr(itr.dest());          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
    case Bytecodes._jsr_w:             doJsr(itr.dest_w());        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
    case Bytecodes._getstatic:         doField(true,  true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
                                               itr.getIndexBig(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
                                               itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
    case Bytecodes._putstatic:         doField(false, true,  itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
    case Bytecodes._getfield:          doField(true,  false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
    case Bytecodes._putfield:          doField(false, false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
    case Bytecodes._invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    case Bytecodes._invokespecial:     doMethod(false, false, itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
    case Bytecodes._invokestatic:      doMethod(true,  false, itr.getIndexBig(), itr.bci()); break;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
  1385
    case Bytecodes._invokedynamic:     doMethod(false, true,  itr.getIndexBig(), itr.bci()); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    case Bytecodes._invokeinterface:   doMethod(false, true,  itr.getIndexBig(), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
    case Bytecodes._newarray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    case Bytecodes._anewarray:         ppNewRef(vCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    case Bytecodes._checkcast:         doCheckcast(); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
    case Bytecodes._arraylength:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    case Bytecodes._instanceof:        pp(rCTS, vCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    case Bytecodes._monitorenter:      doMonitorenter(itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    case Bytecodes._monitorexit:       doMonitorexit(itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
    case Bytecodes._athrow:            // handled by do_exception_edge() BUT ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
      // vlh(apple): doExceptionEdge() does not get
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      // called if method has no exception handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      if ((!_has_exceptions) && (_monitor_top > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
        _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
    case Bytecodes._areturn:           doReturnMonitorCheck();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
      ppop1(refCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
    case Bytecodes._ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    case Bytecodes._ifnonnull:         ppop1(refCTS); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
    case Bytecodes._multianewarray:    doMultianewarray(itr.codeAt(itr.bci() + 3), itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
    case Bytecodes._wide:              throw new RuntimeException("Iterator should skip this bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    case Bytecodes._ret:                                           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
      // Java opcodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
    case Bytecodes._fast_aaccess_0:     ppNewRef(rCTS, itr.bci()); break; // Pair bytecode for (aload_0, _fast_agetfield)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
    case Bytecodes._fast_iaccess_0:     ppush1(valCTS);            break; // Pair bytecode for (aload_0, _fast_igetfield)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
    case Bytecodes._fast_igetfield:     pp(rCTS, vCTS);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
    case Bytecodes._fast_agetfield:     ppNewRef(rCTS, itr.bci()); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    case Bytecodes._fast_aload_0:       ppload(rCTS,  0);          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
    case Bytecodes._lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    case Bytecodes._fast_linearswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    case Bytecodes._fast_binaryswitch:  ppop1(valCTS);             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
      throw new RuntimeException("unexpected opcode: " + itr.code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
  void  doExceptionEdge                     (BytecodeStream itr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    // Only check exception edge, if bytecode can trap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    if (!Bytecodes.canTrap(itr.code())) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
    switch (itr.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    case Bytecodes._aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    case Bytecodes._fast_aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
      // These bytecodes can trap for rewriting.  We need to assume that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
      // they do not throw exceptions to make the monitor analysis work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    case Bytecodes._lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    case Bytecodes._freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
    case Bytecodes._dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
    case Bytecodes._areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    case Bytecodes._return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
      // If the monitor stack height is not zero when we leave the method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
      // then we are either exiting with a non-empty stack or we have
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
      // found monitor trouble earlier in our analysis.  In either case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
      // assume an exception could be taken here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
      if (_monitor_top == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
    case Bytecodes._monitorexit:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      // If the monitor stack height is bad_monitors, then we have detected a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
      // monitor matching problem earlier in the analysis.  If the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
      // monitor stack height is 0, we are about to pop a monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
      // off of an empty stack.  In either case, the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
      // could throw an exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
      if (_monitor_top != bad_monitors && _monitor_top != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
    if (_has_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
      int bci = itr.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
      TypeArray exct   = method().getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
      for(int i = 0; i< exct.getLength(); i+=4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
        int start_pc   = exct.getIntAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
        int end_pc     = exct.getIntAt(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
        int handler_pc = exct.getIntAt(i+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
        int catch_type = exct.getIntAt(i+3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
        if (start_pc <= bci && bci < end_pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
          BasicBlock excBB = getBasicBlockAt(handler_pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
          CellTypeStateList excStk  = excBB.stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
          CellTypeStateList cOpStck = stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
          CellTypeState cOpStck_0 = cOpStck.get(0).copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
          int cOpStackTop = _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
          // Exception stacks are always the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
            Assert.that(method().getMaxStack() > 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
          // We remembered the size and first element of "cOpStck"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
          // above; now we temporarily set them to the appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
          // values for an exception handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
          cOpStck.get(0).set(CellTypeState.makeSlotRef(_max_locals));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
          _stack_top = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
          mergeStateIntoBB(excBB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
          // Now undo the temporary change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
          cOpStck.get(0).set(cOpStck_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
          _stack_top = cOpStackTop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
          // If this is a "catch all" handler, then we do not need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
          // consider any additional handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
          if (catch_type == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
    // It is possible that none of the exception handlers would have caught
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
    // the exception.  In this case, we will exit the method.  We must
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
    // ensure that the monitor stack is empty in this case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
    if (_monitor_top == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
    // We pessimistically assume that this exception can escape the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    // method. (It is possible that it will always be caught, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
    // we don't care to analyse the types of the catch clauses.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    // We don't set _monitor_top to bad_monitors because there are no successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    // to this exceptional exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    if (TraceMonitorMismatch && _monitor_safe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
      // We check _monitor_safe so that we only report the first mismatched
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
      // exceptional exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
      reportMonitorMismatch("non-empty monitor stack at exceptional exit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  void  checkType                           (CellTypeState expected, CellTypeState actual) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
    if (!expected.equalKind(actual)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
      throw new RuntimeException("wrong type on stack (found: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
                                 actual.toChar() + " expected: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
                                 expected.toChar() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
  void  ppstore                             (CellTypeState[] in,  int loc_no) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
    for (int i = 0; i < in.length && !in[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
      CellTypeState expected = in[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
      CellTypeState actual   = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
      checkType(expected, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
        Assert.that(loc_no >= 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
      setVar(loc_no++, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  void  ppload                              (CellTypeState[] out, int loc_no) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
    for (int i = 0; i < out.length && !out[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
      CellTypeState out1 = out[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
      CellTypeState vcts = getVar(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
        Assert.that(out1.canBeReference() || out1.canBeValue(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
                    "can only load refs. and values.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
      if (out1.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
          Assert.that(loc_no>=0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
        if (!vcts.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
          // We were asked to push a reference, but the type of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
          // variable can be something else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
          _conflict = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
          if (vcts.canBeUninit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
            // It is a ref-uninit conflict (at least). If there are other
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
            // problems, we'll get them in the next round
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
            addToRefInitSet(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
            vcts = out1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
            // It wasn't a ref-uninit conflict. So must be a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
            // ref-val or ref-pc conflict. Split the variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
            recordRefvalConflict(loc_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
            vcts = out1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
          push(out1); // recover...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
          push(vcts); // preserve reference.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
        // Otherwise it is a conflict, but one that verification would
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
        // have caught if illegal. In particular, it can't be a topCTS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
        // resulting from mergeing two difference pcCTS's since the verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
        // would have rejected any use of such a merge.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
        push(out1); // handle val/init conflict
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
      loc_no++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
  void  ppush1                              (CellTypeState in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
      Assert.that(in.isReference() | in.isValue(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
      System.err.println("   - pushing " + in.toChar());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    push(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  void  ppush                               (CellTypeState[] in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    for (int i = 0; i < in.length && !in[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
      ppush1(in[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  void  ppush                               (CellTypeStateList in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    for (int i = 0; i < in.size() && !in.get(i).equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
      ppush1(in.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
  void  ppop1                               (CellTypeState out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
      System.err.println("   - popping " + actual.toChar() + ", expecting " + out.toChar());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
    checkType(out, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
  void  ppop                                (CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    for (int i = 0; i < out.length && !out[i].equal(CellTypeState.bottom); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
      ppop1(out[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
  void  ppopAny                             (int poplen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    if (_stack_top >= poplen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
      _stack_top -= poplen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
      throw new RuntimeException("stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
  void  pp                                  (CellTypeState[] in, CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
    ppop(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
    ppush(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
  void  ppNewRef                            (CellTypeState[] in, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
    ppop(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    ppush1(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
  void  ppdupswap                           (int poplen, String out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
    CellTypeState[] actual = new CellTypeState[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
    Assert.that(poplen < 5, "this must be less than length of actual vector");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
    // pop all arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
    for(int i = 0; i < poplen; i++) actual[i] = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
    // put them back
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
    for (int i = 0; i < out.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
      char push_ch = out.charAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
      int idx = push_ch - '1';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
        Assert.that(idx >= 0 && idx < poplen, "wrong arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
      push(actual[idx]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  void  doLdc                               (int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    ConstantPool  cp  = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    ConstantTag   tag = cp.getTagAt(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
    CellTypeState cts = (tag.isString() || tag.isUnresolvedString() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
                         tag.isKlass() || tag.isUnresolvedKlass())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
                          ? CellTypeState.makeLineRef(bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
                          : valCTS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    ppush1(cts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  void  doAstore                            (int idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
    CellTypeState r_or_p = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
    if (!r_or_p.isAddress() && !r_or_p.isReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
      // 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
  1682
      // really matter (at least for now)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
      throw new RuntimeException("wrong type on stack (found: " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
                                 r_or_p.toChar() + ", expected: {pr})");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    setVar(idx, r_or_p);
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  doJsr                               (int targBCI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
    push(CellTypeState.makeAddr(targBCI));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
  void  doField                             (boolean is_get, boolean is_static, int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
    // Dig up signature for field in constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
    ConstantPool cp        = method().getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
    int nameAndTypeIdx     = cp.getNameAndTypeRefIndexAt(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
    int signatureIdx       = cp.getSignatureRefIndexAt(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
    Symbol signature       = cp.getSymbolAt(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
      System.err.println("doField: signature = " + signature.asString() + ", idx = " + idx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
                         ", nameAndTypeIdx = " + nameAndTypeIdx + ", signatureIdx = " + signatureIdx + ", bci = " + bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
    // Parse signature (espcially simple for fields)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
    // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
    char sigch = (char) signature.getByteAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
    CellTypeState[] temp = new CellTypeState[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    CellTypeState[] eff  = sigcharToEffect(sigch, bci, temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
    CellTypeState[] in = new CellTypeState[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
    CellTypeState[] out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
    int i =  0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
    if (is_get) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
      out = eff;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
      out = epsilonCTS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
      i   = copyCTS(in, eff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
    if (!is_static) in[i++] = CellTypeState.ref;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
    in[i] = CellTypeState.bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
      Assert.that(i<=3, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
    pp(in, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
  void  doMethod                            (boolean is_static, boolean is_interface, int idx, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
    // Dig up signature for field in constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
    ConstantPool cp       = _method.getConstants();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
  1732
    int nameAndTypeIdx    = cp.getTagAt(idx).isNameAndType() ? idx : cp.getNameAndTypeRefIndexAt(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
    int signatureIdx      = cp.getSignatureRefIndexAt(nameAndTypeIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
    Symbol signature      = cp.getSymbolAt(signatureIdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
      System.err.println("doMethod: signature = " + signature.asString() + ", idx = " + idx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
                         ", nameAndTypeIdx = " + nameAndTypeIdx + ", signatureIdx = " + signatureIdx +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
                         ", bci = " + bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
    // Parse method signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
    CellTypeStateList out = new CellTypeStateList(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
    CellTypeStateList in  = new CellTypeStateList(MAXARGSIZE+1);   // Includes result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
    ComputeCallStack cse  = new ComputeCallStack(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
    // Compute return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
    int res_length = cse.computeForReturntype(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    // Temporary hack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
    if (out.get(0).equal(CellTypeState.ref) && out.get(1).equal(CellTypeState.bottom)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
      out.get(0).set(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
      Assert.that(res_length<=4, "max value should be vv");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    // Compute arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
    int arg_length = cse.computeForParameters(is_static, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
      Assert.that(arg_length<=MAXARGSIZE, "too many locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
    // Pop arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
    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
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    // Report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
    if (_report_result_for_send == true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
      fillStackmapForOpcodes(_itr_send, vars(), stack(), _stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
      _report_result_for_send = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
    // Push return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    ppush(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  void  doMultianewarray                    (int dims, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
      Assert.that(dims >= 1, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
    for(int i = dims -1; i >=0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
      ppop1(valCTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
    ppush1(CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  void  doMonitorenter                      (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    if (_monitor_top == bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    // Bail out when we get repeated locks on an identical monitor.  This case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
    // isn't too hard to handle and can be made to work if supporting nested
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
    // redundant synchronized statements becomes a priority.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
    // See also "Note" in do_monitorexit(), below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
    if (actual.isLockReference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
        reportMonitorMismatch("nested redundant lock -- bailout...");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
    CellTypeState lock = CellTypeState.makeLockRef(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
    if (!actual.isInfoTop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
      replaceAllCTSMatches(actual, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
      monitorPush(lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  void  doMonitorexit                       (int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
    if (_monitor_top == bad_monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    CellTypeState expected = monitorPop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
    if (!actual.isLockReference() || !expected.equal(actual)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
      // The monitor we are exiting is not verifiably the one
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
      // on the top of our monitor stack.  This causes a monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
      // mismatch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
      _monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
      // We need to mark this basic block as changed so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
      // this monitorexit will be visited again.  We need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
      // do this to ensure that we have accounted for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
      // possibility that this bytecode will throw an
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
      // exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
      BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
      bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      bb._monitor_top = bad_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
        reportMonitorMismatch("improper monitor pair");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      // This code is a fix for the case where we have repeated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
      // locking of the same object in straightline code.  We clear
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
      // out the lock when it is popped from the monitor stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
      // and replace it with an unobtrusive reference value that can
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
      // be locked again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
      // Note: when generateOopMap is fixed to properly handle repeated,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
      //       nested, redundant locks on the same object, then this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
      //       fix will need to be removed at that time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
      replaceAllCTSMatches(actual, CellTypeState.makeLineRef(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
    if (_report_for_exit_bci == bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
      _matching_enter_bci = expected.getMonitorSource();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
  void  doReturnMonitorCheck                () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
    if (_monitor_top > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
      // The monitor stack must be empty when we leave the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
      // for the monitors to be properly matched.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
      _monitor_safe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
      // Since there are no successors to the *return bytecode, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
      // isn't necessary to set _monitor_top to bad_monitors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
      if (TraceMonitorMismatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
        reportMonitorMismatch("non-empty monitor stack at return");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  void  doCheckcast                         () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
    CellTypeState actual = pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
    checkType(refCTS, actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
    push(actual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  CellTypeState[] sigcharToEffect           (char sigch, int bci, CellTypeState[] out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
    // Object and array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
    if (sigch=='L' || sigch=='[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
      out[0] = CellTypeState.makeLineRef(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
      out[1] = CellTypeState.bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
      return out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
    if (sigch == 'J' || sigch == 'D' ) return vvCTS;  // Long and Double
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
    if (sigch == 'V' ) return epsilonCTS;             // Void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
    return vCTS;                                      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  // Copies (optionally bottom/zero terminated) CTS string from "src" into "dst".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  //   Does NOT terminate with a bottom. Returns the number of cells copied.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  int copyCTS                               (CellTypeState[] dst, CellTypeState[] src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    int idx = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    for (; idx < src.length && !src[idx].isBottom(); idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
      dst[idx] = src[idx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
    return idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  // Create result set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
  boolean  _report_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
  boolean  _report_result_for_send;         // Unfortunatly, stackmaps for sends are special, so we need some extra
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
  BytecodeStream _itr_send;                 // variables to handle them properly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
  void  reportResult                        () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
    //    if (TraceNewOopMapGeneration) tty.print_cr("Report result pass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
    // We now want to report the result of the parse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
    _report_result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    // Prolog code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
    fillStackmapProlog(_gc_points);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
    // Mark everything changed, then do one interpretation pass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
    for (int i = 0; i<_bb_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
      if (_basic_blocks[i].isReachable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
        _basic_blocks[i].setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
        interpBB(_basic_blocks[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
    // Note: Since we are skipping dead-code when we are reporting results, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
    // the no. of encountered gc-points might be fewer than the previously number
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
    // we have counted. (dead-code is a pain - it should be removed before we get here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
    fillStackmapEpilog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
    // Report initvars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
    fillInitVars(_init_vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
    _report_result = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  // Initvars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
  List/*<Integer>*/ _init_vars;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
  void  initializeVars                      () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
    for (int k = 0; k < _init_vars.size(); k++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
      _state.get(((Integer) _init_vars.get(k)).intValue()).set(CellTypeState.makeSlotRef(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
  void  addToRefInitSet                     (int localNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
    //    if (TraceNewOopMapGeneration)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
    //      tty.print_cr("Added init vars: %d", localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
    Integer local = new Integer(localNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
    // Is it already in the set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
    if (_init_vars.contains(local))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
    _init_vars.add(local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
  // Conflicts rewrite logic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  boolean   _conflict;                      // True, if a conflict occured during interpretation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  int       _nof_refval_conflicts;          // No. of conflicts that require rewrites
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  int[]     _new_var_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
  void recordRefvalConflict                 (int varNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
      Assert.that(varNo>=0 && varNo< _max_locals, "index out of range");
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 (TraceOopMapRewrites) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
      System.err.println("### Conflict detected (local no: " + varNo + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
    if (_new_var_map == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
      _new_var_map = new int[_max_locals];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
      for (int k = 0; k < _max_locals; k++)  _new_var_map[k] = k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
    if ( _new_var_map[varNo] == varNo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
      // Check if max. number of locals has been reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
      if (_max_locals + _nof_refval_conflicts >= MAX_LOCAL_VARS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
        throw new RuntimeException("Rewriting exceeded local variable limit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
      _new_var_map[varNo] = _max_locals + _nof_refval_conflicts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
      _nof_refval_conflicts++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
  void rewriteRefvalConflicts               () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
    if (_nof_refval_conflicts > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
      if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
        throw new RuntimeException("Should not reach here (method rewriting should have been done by the VM already)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
        throw new RuntimeException("Method rewriting not yet implemented in Java");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
  // Rewriting-related routines are not needed here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
  //  void rewrite_refval_conflict              (int from, int to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  //  bool rewrite_refval_conflict_inst         (BytecodeStream *i, int from, int to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  //  bool rewrite_load_or_store                (BytecodeStream *i, Bytecodes.Code bc, Bytecodes.Code bc0, unsigned int varNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  //  bool expand_current_instr                 (int bci, int ilen, int newIlen, u_char inst_buffer[]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
  //  bool is_astore                            (BytecodeStream *itr, int *index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
  //  bool is_aload                             (BytecodeStream *itr, int *index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
  // List of bci's where a return address is on top of the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
  //  GrowableArray<intptr_t> *_ret_adr_tos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
  //  bool stack_top_holds_ret_addr             (int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
  //  void compute_ret_adr_at_TOS               ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
  //  void update_ret_adr_at_TOS                (int bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
  String stateVecToString                   (CellTypeStateList vec, int len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
      _state_vec_buf[i] = vec.get(i).toChar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
    return new String(_state_vec_buf, 0, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  // Helper method. Can be used in subclasses to fx. calculate gc_points. If the current instuction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
  // is a control transfer, then calls the jmpFct all possible destinations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
  void  retJumpTargetsDo                    (BytecodeStream bcs, JumpClosure closure, int varNo, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
    CellTypeState ra = vars().get(varNo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
    if (!ra.isGoodAddress()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
      throw new RuntimeException("ret returns from two jsr subroutines?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
    int target = ra.getInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
    RetTableEntry rtEnt = _rt.findJsrsForTarget(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
    int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
    for (int i = 0; i < rtEnt.nofJsrs(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
      int target_bci = rtEnt.jsrs(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
      // Make sure a jrtRet does not set the changed bit for dead basicblock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
      BasicBlock jsr_bb    = getBasicBlockContaining(target_bci - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
        BasicBlock target_bb = _basic_blocks[1 + bbIndex(jsr_bb)];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
        Assert.that(target_bb  == getBasicBlockAt(target_bci), "wrong calc. of successor basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
      boolean alive = jsr_bb.isAlive();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
      //      if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
      //        tty.print("pc = %d, ret . %d alive: %s\n", bci, target_bci, alive ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
      if (alive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
        closure.process(this, target_bci, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
  /** If the current instruction in "c" has no effect on control flow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
      returns "true".  Otherwise, calls "closure.process()" one or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
      more times, with "c", an appropriate "pcDelta", and "data" as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
      arguments, then returns "false".  There is one exception: if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
      current instruction is a "ret", returns "false" without calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
      "jmpFct". Arrangements for tracking the control flow of a "ret"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
      must be made externally. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
  boolean jumpTargetsDo                     (BytecodeStream bcs, JumpClosure closure, int[] data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
    int bci = bcs.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
    switch (bcs.code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
    case Bytecodes._ifeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
    case Bytecodes._ifne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
    case Bytecodes._iflt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
    case Bytecodes._ifge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
    case Bytecodes._ifgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
    case Bytecodes._ifle:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
    case Bytecodes._if_icmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
    case Bytecodes._if_icmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
    case Bytecodes._if_icmplt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
    case Bytecodes._if_icmpge:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
    case Bytecodes._if_icmpgt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
    case Bytecodes._if_icmple:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
    case Bytecodes._if_acmpeq:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
    case Bytecodes._if_acmpne:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
    case Bytecodes._ifnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
    case Bytecodes._ifnonnull:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
      closure.process(this, bci + 3, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
    case Bytecodes._goto:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
    case Bytecodes._goto_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
      closure.process(this, bcs.dest_w(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
    case Bytecodes._tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
        BytecodeTableswitch tableswitch = BytecodeTableswitch.at(bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
        int len = tableswitch.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
        closure.process(this, bci + tableswitch.defaultOffset(), data); /* Default. jump address */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
        while (--len >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
          closure.process(this, bci + tableswitch.destOffsetAt(len), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
    case Bytecodes._fast_linearswitch:     // Java opcodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
    case Bytecodes._fast_binaryswitch:     // get_int_table handles conversions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
    case Bytecodes._lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
        BytecodeLookupswitch lookupswitch = BytecodeLookupswitch.at(bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
        int npairs = lookupswitch.numberOfPairs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
        closure.process(this, bci + lookupswitch.defaultOffset(), data); /* Default. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
        while(--npairs >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
          LookupswitchPair pair = lookupswitch.pairAt(npairs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
          closure.process(this, bci + pair.offset(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
    case Bytecodes._jsr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
      Assert.that(bcs.isWide()==false, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
      closure.process(this, bcs.dest(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
    case Bytecodes._jsr_w:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
      closure.process(this, bcs.dest_w(), data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
    case Bytecodes._wide:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
      throw new RuntimeException("Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
    case Bytecodes._athrow:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
    case Bytecodes._ireturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
    case Bytecodes._lreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
    case Bytecodes._freturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
    case Bytecodes._dreturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
    case Bytecodes._areturn:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
    case Bytecodes._return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
    case Bytecodes._ret:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
  // Monitor matching
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
  //  int fill_out_arrays                       (int *enter, int *exit, int max);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  //  friend class RelocCallback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
  // Public routines for GenerateOopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
  public GenerateOopMap(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
    // We have to initialize all variables here, that can be queried direcly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
    _max_locals=0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
    _init_vars = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
    _rt = new RetTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
  // Compute the map.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
  public void computeMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
      System.err.println("*** GenerateOopMap: computing for " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
                         method().getMethodHolder().getName().asString() + "." +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
                         method().getName().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
                         method().getSignature().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
    // Initialize values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
    _got_error      = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
    _conflict       = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
    _max_locals     = (int) method().getMaxLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
    _max_stack      = (int) method().getMaxStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
    _has_exceptions = (method().getExceptionTable().getLength() > 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
    _nof_refval_conflicts = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
    _init_vars      = new ArrayList(5);  // There are seldom more than 5 init_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
    _report_result  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
    _report_result_for_send = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
    _report_for_exit_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
    _new_var_map    = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
    //    _ret_adr_tos    = new GrowableArray<intptr_t>(5);  // 5 seems like a good number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
    //    _did_rewriting  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
    //    _did_relocation = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
    if (TraceNewOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
      tty.print("Method name: %s\n", method().name().as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
      if (Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
        _method.print_codes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
        tty.print_cr("Exception table:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
        typeArrayOop excps = method().exception_table();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
        for(int i = 0; i < excps.length(); i += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
          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
  2186
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
    // if no code - do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
    // compiler needs info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
    if (method().getCodeSize() == 0 || _max_locals + method().getMaxStack() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
      fillStackmapProlog(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
      fillStackmapEpilog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
    // Step 1: Compute all jump targets and their return value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
      _rt.computeRetTable(_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
    // Step 2: Find all basic blocks and count GC points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
      markBBHeadersAndCountGCPoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
    // Step 3: Calculate stack maps
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
    if (!_got_error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
      doInterpretation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
    // Step 4:Return results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
    if (!_got_error && reportResults())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
      reportResult();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
    if (_got_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
      // We could expand this code to throw somekind of exception (e.g., VerifyException). However,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
      // 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
  2217
      // illegal bytecodes (that the verifier should have caught if turned on), so we will just exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
      // with a fatal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
      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
  2220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
  // Do a callback on fill_stackmap_for_opcodes for basicblock containing bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
  public void resultForBasicblock(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
    // FIXME: remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
    //    if (TraceNewOopMapGeneration) tty.print_cr("Report result pass for basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
    // We now want to report the result of the parse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
    _report_result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
    // Find basicblock and report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
      Assert.that(bb.isReachable(), "getting result from unreachable basicblock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
    bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
    interpBB(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
  // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
  public int maxLocals()                                  { return _max_locals; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
  public Method method()                                  { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
  //  bool did_rewriting()                             { return _did_rewriting; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
  //  bool did_relocation()                            { return _did_relocation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
  //  static void print_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
  // Monitor query
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  public boolean monitorSafe()                            { return _monitor_safe; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
  // Takes as input the bci of a monitorexit bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
  // Returns the bci of the corresponding monitorenter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
  // Can only be called safely after computeMap() is run.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
  public int  getMonitorMatch(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
      Assert.that(_monitor_safe, "Attempt to match monitor in broken code.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
    //    if (TraceNewOopMapGeneration)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
    //      tty.print_cr("Report monitor match for bci : %d", bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
    // We want to report the line number of the monitorenter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
    _report_for_exit_bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
    _matching_enter_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
    // Find basicblock and report results
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
    BasicBlock bb = getBasicBlockContaining(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
    if (bb.isReachable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
      bb.setChanged(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
      interpBB(bb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
      _report_for_exit_bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
        Assert.that(_matching_enter_bci != -1, "monitor matching invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
    return _matching_enter_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
  // Returns a Arena allocated object that contains pairing info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
  //  MonitorPairs* get_pairing(Arena *arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
  // copies monitor pairing info into area; area_count specifies maximum
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
  // possible number of monitor pairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
  //  int copy_pairing(int pair_count, MonitorPairs* pairs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
  private int bbIndex(BasicBlock bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
    for (int i = 0; i < _basic_blocks.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
      if (_basic_blocks[i] == bb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
        return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
    throw new RuntimeException("Should have found block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
  // Specialization methods. Intended use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
  // - possibleGCPoint must return true for every bci for which the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
  //   stackmaps must be returned
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
  // - fillStackmapProlog is called just before the result is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
  //   reported. The arguments tells the estimated number of gc points
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
  // - fillStackmapForOpcodes is called once for each bytecode index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
  //   in order (0...code_length-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
  // - fillStackmapEpilog is called after all results has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
  //   reported. Note: Since the algorithm does not report stackmaps for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
  //   deadcode, fewer gc_points might have been encounted than assumed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
  //   during the epilog. It is the responsibility of the subclass to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
  //   count the correct number.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
  // - fillInitVars are called once with the result of the init_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
  //   computation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
  // All these methods are used during a call to computeMap. Note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  // None of the return results are valid after computeMap returns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
  // since all values are allocated as resource objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
  // All virtual method must be implemented in subclasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
  public boolean allowRewrites            ()                              { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
  public boolean reportResults            ()                              { return true;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
  public boolean reportInitVars           ()                              { return true;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
  public boolean possibleGCPoint          (BytecodeStream bcs)            { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
  public void fillStackmapProlog          (int nofGCPoints)               { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
  public void fillStackmapEpilog          ()                              { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
  public void fillStackmapForOpcodes      (BytecodeStream bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
                                           CellTypeStateList vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
                                           CellTypeStateList stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
                                           int stackTop)                  { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
  public void fillInitVars                (List/*<Integer>*/ init_vars)   { throw new RuntimeException("ShouldNotReachHere"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
}