• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // ASM: a very small and fast Java bytecode manipulation framework
2 // Copyright (c) 2000-2011 INRIA, France Telecom
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 // 1. Redistributions of source code must retain the above copyright
9 //    notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 //    notice, this list of conditions and the following disclaimer in the
12 //    documentation and/or other materials provided with the distribution.
13 // 3. Neither the name of the copyright holders nor the names of its
14 //    contributors may be used to endorse or promote products derived from
15 //    this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 // THE POSSIBILITY OF SUCH DAMAGE.
28 package jdk8;
29 
30 import java.io.UnsupportedEncodingException;
31 
32 /**
33  * Class which, compiled with the JDK 1.8.0, produces all the stack map frame types. Must be
34  * compiled with "javac -g -parameters".
35  */
36 public class AllFrames {
37 
38   Object o;
39   String s;
40   int f;
41 
AllFrames(Object o, String s)42   public AllFrames(Object o, String s) {
43     this.o = o;
44     this.s = s;
45   }
46 
47   // Frame types: full_frame.
48   // Element types: null, uninitialized_this.
AllFrames(boolean b)49   public AllFrames(boolean b) {
50     this(null, b ? "true" : "false");
51   }
52 
53   // Frame types: full_frame.
54   // Element types: null, uninitialized.
create(String s)55   public static AllFrames create(String s) {
56     return new AllFrames(null, s == null ? "" : s);
57   }
58 
59   // Frame types: same, same_locals_1_stack_item, full_frame.
60   // Element types: primitive types and object.
m0( boolean b, byte y, char c, short s, int i, float f, long l, double d, Object o, Object[] p, Object[][] q)61   public int m0(
62       boolean b,
63       byte y,
64       char c,
65       short s,
66       int i,
67       float f,
68       long l,
69       double d,
70       Object o,
71       Object[] p,
72       Object[][] q) {
73     return b
74         ? m0(!b, y, c, s, i - 1, f - 1f, l - 1l, d - 1d, o, p, q)
75         : m0(!b, y, c, s, i + 1, f + 1f, l + 1l, d + 1d, o, p, q);
76   }
77 
78   // Frame types: same, same_locals_1_stack_item.
79   // Element types: primitive types and object.
m0Static( boolean b, byte y, char c, short s, int i, float f, long l, double d, Object o, Object[] p, Object[][] q)80   public static int m0Static(
81       boolean b,
82       byte y,
83       char c,
84       short s,
85       int i,
86       float f,
87       long l,
88       double d,
89       Object o,
90       Object[] p,
91       Object[][] q) {
92     return b
93         ? m0Static(!b, y, c, s, i - 1, f - 1f, l - 1l, d - 1d, o, p, q)
94         : m0Static(!b, y, c, s, i + 1, f + 1f, l + 1l, d + 1d, o, p, q);
95   }
96 
97   // Element types: uninitialized (multiple per frame).
m0(byte[] bytes, boolean b)98   public String m0(byte[] bytes, boolean b) {
99     try {
100       return bytes == null ? null : new String(bytes, b ? "a" : "b");
101     } catch (UnsupportedEncodingException e) {
102       return null;
103     }
104   }
105 
106   // Frame types: append.
107   // Element types: top.
m1(int i, int j)108   public void m1(int i, int j) {
109     int k;
110     int l = j;
111     if (i < 0) {
112       i = -i;
113     }
114   }
115 
116   // Frame types: append.
117   // Element types: top.
m1Static(int i, int j)118   public static void m1Static(int i, int j) {
119     int k;
120     int l = j;
121     if (i < 0) {
122       i = -i;
123     }
124   }
125 
126   // Frame types: chop.
m2(int n, boolean b)127   public long m2(int n, boolean b) {
128     long total = 0;
129     if (b) {
130       int i = 0;
131       do {
132         total += i++;
133       } while (i < n);
134     } else {
135       long i = 0;
136       do {
137         total += i++;
138       } while (i < n);
139     }
140     return total;
141   }
142 
143   // Frame types: chop.
m2Static(int n, boolean b)144   public static long m2Static(int n, boolean b) {
145     long total = 0;
146     if (b) {
147       int i = 0;
148       do {
149         total += i++;
150       } while (i < n);
151     } else {
152       long i = 0;
153       do {
154         total += i++;
155       } while (i < n);
156     }
157     return total;
158   }
159 
160   // Frame types: same_frame_extended.
m3(int i)161   public int m3(int i) {
162     if (i < 0) {
163       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
164       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
165     }
166     return i;
167   }
168 
169   // Frame types: same_frame_extended.
m3Static(int i)170   public static int m3Static(int i) {
171     if (i < 0) {
172       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
173       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
174     }
175     return i;
176   }
177 
178   // Frame types: same_locals_1_stack_item_frame_extended.
m4(int i)179   public void m4(int i) {
180     i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
181     i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
182     s = i == 0 ? "true" : "false";
183   }
184 
185   // Frame merges: two non-array objects.
m5(boolean b)186   public static Number m5(boolean b) {
187     return b ? new Integer(1) : new Float(1);
188   }
189 
190   // Frame merges: two single-dimensional arrays with object type elements.
m6(boolean b)191   public static Number[] m6(boolean b) {
192     return b ? new Integer[1] : new Float[1];
193   }
194 
195   // Frame merges: two bi-dimensional arrays with object type elements.
m7(boolean b)196   public static Number[][] m7(boolean b) {
197     return b ? new Integer[1][1] : new Float[1][1];
198   }
199 
200   // Frame merges: two bi-dimensional arrays with primitive type elements.
m8(boolean b)201   public static Object[] m8(boolean b) {
202     return b ? (Object[]) new byte[1][1] : (Object[]) new short[1][1];
203   }
204 
205   // Frame merges: two single-dimensional arrays with mixed primitive / object type elements.
m9(boolean b)206   public static Object m9(boolean b) {
207     return b ? new byte[1] : new Float[1];
208   }
209 
210   // Frame merges: two bi-dimensional arrays with mixed primitive / object type elements.
m10(boolean b)211   public static Object[] m10(boolean b) {
212     return b ? (Object[]) new byte[1][1] : (Object[]) new Float[1][];
213   }
214 
215   // Frame merges: one and two dimensions arrays with identical element type.
m11(boolean b)216   public static Object m11(boolean b) {
217     return b ? new byte[1] : new byte[1][1];
218   }
219 
220   // Frame merges: one and two dimensions arrays with mixed primitive / object type elements.
m12(boolean b)221   public static Object[] m12(boolean b) {
222     return b ? new Object[1] : new byte[1][1];
223   }
224 
225   // Frame merges: two and three dimensions arrays with primitive type elements.
m13(boolean b)226   public static Object[] m13(boolean b) {
227     return b ? (Object[]) new byte[1][1] : (Object[]) new byte[1][1][1];
228   }
229 
230   // Frame merges: three and four dimensions arrays with primitive type elements.
m14(boolean b)231   public static Object[][] m14(boolean b) {
232     return b ? (Object[][]) new byte[1][1][1] : (Object[][]) new byte[1][1][1][1];
233   }
234 
235   // Frame merges: object type and single-dimensional array with primitive type elements.
m15(boolean b)236   public static Object m15(boolean b) {
237     return b ? new Integer(1) : new char[1];
238   }
239 
240   // Frame merges: object type and single-dimensional array with object type elements.
m16(boolean b)241   public static Object m16(boolean b) {
242     return b ? new Integer(1) : new Float[1];
243   }
244 
245   // Frame merges: two single-dimensional arrays with different primitive type elements.
m17(boolean b)246   public Object m17(boolean b) {
247     return b ? new int[0] : new boolean[0];
248   }
249 
250   // Frame merges: two single-dimensional arrays with different primitive type elements.
m18(boolean b)251   public Object m18(boolean b) {
252     return b ? new short[0] : new float[0];
253   }
254 
255   // Frame merges: two single-dimensional arrays with different primitive type elements.
m19(boolean b)256   public Object m19(boolean b) {
257     return b ? new double[0] : new long[0];
258   }
259 
260   // Frame merges: null type and object type.
m20(boolean b)261   public static Object m20(boolean b) {
262     return b ? null : new Integer(1);
263   }
264 
265   // Frame merges: object type and null type.
m21(boolean b)266   public static Object m21(boolean b) {
267     return b ? new Integer(1) : null;
268   }
269 
270   // Frame AALOAD from null array (no frame in original class because ASM can't compute the exact
271   // same frame as javac, but usefull for tests that compute frame types at each instruction).
m23()272   public static int m23() {
273     Integer[] array = null;
274     return array[0].intValue();
275   }
276 }
277