author | jjg |
Tue, 25 Sep 2012 13:06:58 -0700 | |
changeset 14049 | 3207422a0f9b |
parent 5847 | 1908176fd6e3 |
child 16560 | c6c7f0c26568 |
permissions | -rw-r--r-- |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
1 |
/* |
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
5847
diff
changeset
|
2 |
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
4 |
* |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
10 |
* |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
16 |
* |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
24 |
*/ |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
25 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javap; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
27 |
|
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
5847
diff
changeset
|
28 |
import java.util.Arrays; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
29 |
import java.util.HashMap; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
30 |
import java.util.Map; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
31 |
|
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
5847
diff
changeset
|
32 |
import com.sun.tools.classfile.AccessFlags; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.Attribute; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.Code_attribute; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.ConstantPool; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.ConstantPoolException; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.classfile.Descriptor; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.classfile.Instruction; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.Method; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.StackMapTable_attribute; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.StackMapTable_attribute.*; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
43 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
44 |
import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
45 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
46 |
/** |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
47 |
* Annotate instructions with stack map. |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
48 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
49 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
50 |
* If you write code that depends on this, you do so at your own risk. |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
51 |
* This code and its internal interfaces are subject to change or |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
52 |
* deletion without notice.</b> |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
53 |
*/ |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
54 |
public class StackMapWriter extends InstructionDetailWriter { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
55 |
static StackMapWriter instance(Context context) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
56 |
StackMapWriter instance = context.get(StackMapWriter.class); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
57 |
if (instance == null) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
58 |
instance = new StackMapWriter(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
59 |
return instance; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
60 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
61 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
62 |
protected StackMapWriter(Context context) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
63 |
super(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
64 |
context.put(StackMapWriter.class, this); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
65 |
classWriter = ClassWriter.instance(context); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
66 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
67 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
68 |
public void reset(Code_attribute attr) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
69 |
setStackMap((StackMapTable_attribute) attr.attributes.get(Attribute.StackMapTable)); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
70 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
71 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
72 |
void setStackMap(StackMapTable_attribute attr) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
73 |
if (attr == null) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
74 |
map = null; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
75 |
return; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
76 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
77 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
78 |
Method m = classWriter.getMethod(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
79 |
Descriptor d = m.descriptor; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
80 |
String[] args; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
81 |
try { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
82 |
ConstantPool cp = classWriter.getClassFile().constant_pool; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
83 |
String argString = d.getParameterTypes(cp); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
84 |
args = argString.substring(1, argString.length() - 1).split("[, ]+"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
85 |
} catch (ConstantPoolException e) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
86 |
return; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
87 |
} catch (InvalidDescriptor e) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
88 |
return; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
89 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
90 |
boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
91 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
92 |
verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length]; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
93 |
if (!isStatic) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
94 |
initialLocals[0] = new CustomVerificationTypeInfo("this"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
95 |
for (int i = 0; i < args.length; i++) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
96 |
initialLocals[(isStatic ? 0 : 1) + i] = |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
97 |
new CustomVerificationTypeInfo(args[i].replace(".", "/")); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
98 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
99 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
100 |
map = new HashMap<Integer, StackMap>(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
101 |
StackMapBuilder builder = new StackMapBuilder(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
102 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
103 |
// using -1 as the pc for the initial frame effectively compensates for |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
104 |
// the difference in behavior for the first stack map frame (where the |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
105 |
// pc offset is just offset_delta) compared to subsequent frames (where |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
106 |
// the pc offset is always offset_delta+1). |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
107 |
int pc = -1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
108 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
109 |
map.put(pc, new StackMap(initialLocals, empty)); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
110 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
111 |
for (int i = 0; i < attr.entries.length; i++) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
112 |
pc = attr.entries[i].accept(builder, pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
113 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
114 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
115 |
public void writeInitialDetails() { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
116 |
writeDetails(-1); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
117 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
118 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
119 |
public void writeDetails(Instruction instr) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
120 |
writeDetails(instr.getPC()); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
121 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
122 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
123 |
private void writeDetails(int pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
124 |
if (map == null) |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
125 |
return; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
126 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
127 |
StackMap m = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
128 |
if (m != null) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
129 |
print("StackMap locals: ", m.locals); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
130 |
print("StackMap stack: ", m.stack); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
131 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
132 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
133 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
134 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
135 |
void print(String label, verification_type_info[] entries) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
136 |
print(label); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
137 |
for (int i = 0; i < entries.length; i++) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
138 |
print(" "); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
139 |
print(entries[i]); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
140 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
141 |
println(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
142 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
143 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
144 |
void print(verification_type_info entry) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
145 |
if (entry == null) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
146 |
print("ERROR"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
147 |
return; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
148 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
149 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
150 |
switch (entry.tag) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
151 |
case -1: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
152 |
print(((CustomVerificationTypeInfo) entry).text); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
153 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
154 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
155 |
case ITEM_Top: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
156 |
print("top"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
157 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
158 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
159 |
case ITEM_Integer: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
160 |
print("int"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
161 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
162 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
163 |
case ITEM_Float: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
164 |
print("float"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
165 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
166 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
167 |
case ITEM_Long: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
168 |
print("long"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
169 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
170 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
171 |
case ITEM_Double: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
172 |
print("double"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
173 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
174 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
175 |
case ITEM_Null: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
176 |
print("null"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
177 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
178 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
179 |
case ITEM_UninitializedThis: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
180 |
print("uninit_this"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
181 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
182 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
183 |
case ITEM_Object: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
184 |
try { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
185 |
ConstantPool cp = classWriter.getClassFile().constant_pool; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
186 |
ConstantPool.CONSTANT_Class_info class_info = cp.getClassInfo(((Object_variable_info) entry).cpool_index); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
187 |
print(cp.getUTF8Value(class_info.name_index)); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
188 |
} catch (ConstantPoolException e) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
189 |
print("??"); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
190 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
191 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
192 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
193 |
case ITEM_Uninitialized: |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
194 |
print(((Uninitialized_variable_info) entry).offset); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
195 |
break; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
196 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
197 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
198 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
199 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
200 |
private Map<Integer, StackMap> map; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
201 |
private ClassWriter classWriter; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
202 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
203 |
class StackMapBuilder |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
204 |
implements StackMapTable_attribute.stack_map_frame.Visitor<Integer, Integer> { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
205 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
206 |
public Integer visit_same_frame(same_frame frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
207 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
208 |
StackMap m = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
209 |
assert (m != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
210 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
211 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
212 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
213 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
214 |
public Integer visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
215 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
216 |
StackMap prev = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
217 |
assert (prev != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
218 |
StackMap m = new StackMap(prev.locals, frame.stack); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
219 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
220 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
221 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
222 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
223 |
public Integer visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
224 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
225 |
StackMap prev = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
226 |
assert (prev != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
227 |
StackMap m = new StackMap(prev.locals, frame.stack); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
228 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
229 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
230 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
231 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
232 |
public Integer visit_chop_frame(chop_frame frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
233 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
234 |
StackMap prev = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
235 |
assert (prev != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
236 |
int k = 251 - frame.frame_type; |
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
5847
diff
changeset
|
237 |
verification_type_info[] new_locals = Arrays.copyOf(prev.locals, prev.locals.length - k); |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
238 |
StackMap m = new StackMap(new_locals, empty); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
239 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
240 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
241 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
242 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
243 |
public Integer visit_same_frame_extended(same_frame_extended frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
244 |
int new_pc = pc + frame.getOffsetDelta(); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
245 |
StackMap m = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
246 |
assert (m != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
247 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
248 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
249 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
250 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
251 |
public Integer visit_append_frame(append_frame frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
252 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
253 |
StackMap prev = map.get(pc); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
254 |
assert (prev != null); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
255 |
verification_type_info[] new_locals = new verification_type_info[prev.locals.length + frame.locals.length]; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
256 |
System.arraycopy(prev.locals, 0, new_locals, 0, prev.locals.length); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
257 |
System.arraycopy(frame.locals, 0, new_locals, prev.locals.length, frame.locals.length); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
258 |
StackMap m = new StackMap(new_locals, empty); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
259 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
260 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
261 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
262 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
263 |
public Integer visit_full_frame(full_frame frame, Integer pc) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
264 |
int new_pc = pc + frame.getOffsetDelta() + 1; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
265 |
StackMap m = new StackMap(frame.locals, frame.stack); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
266 |
map.put(new_pc, m); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
267 |
return new_pc; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
268 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
269 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
270 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
271 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
272 |
class StackMap { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
273 |
StackMap(verification_type_info[] locals, verification_type_info[] stack) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
274 |
this.locals = locals; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
275 |
this.stack = stack; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
276 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
277 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
278 |
private final verification_type_info[] locals; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
279 |
private final verification_type_info[] stack; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
280 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
281 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
282 |
class CustomVerificationTypeInfo extends verification_type_info { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
283 |
public CustomVerificationTypeInfo(String text) { |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
284 |
super(-1); |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
285 |
this.text = text; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
286 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
287 |
private String text; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
288 |
} |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
289 |
|
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
290 |
private final verification_type_info[] empty = { }; |
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
diff
changeset
|
291 |
} |