annotate agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java @ 1602:136b78722a08

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