annotate agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java @ 1552:c18cbe5936b8

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