annotate agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java @ 6725:da91efe96a93

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