• 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   // Element types: uninitialized (multiple per frame).
m0(byte[] bytes, boolean b)79   public String m0(byte[] bytes, boolean b) {
80     try {
81       return bytes == null ? null : new String(bytes, b ? "a" : "b");
82     } catch (UnsupportedEncodingException e) {
83       return null;
84     }
85   }
86 
87   // Frame types: append.
88   // Element types: top.
m1(int i, int j)89   public void m1(int i, int j) {
90     int k;
91     int l = j;
92     if (i < 0) {
93       i = -i;
94     }
95   }
96 
97   // Frame types: chop.
m2(int n, boolean b)98   public long m2(int n, boolean b) {
99     long total = 0;
100     if (b) {
101       int i = 0;
102       do {
103         total += i++;
104       } while (i < n);
105     } else {
106       long i = 0;
107       do {
108         total += i++;
109       } while (i < n);
110     }
111     return total;
112   }
113 
114   // Frame types: same_frame_extended.
m3(int i)115   public int m3(int i) {
116     if (i < 0) {
117       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
118       i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
119     }
120     return i;
121   }
122 
123   // Frame types: same_locals_1_stack_item_frame_extended.
m4(int i)124   public void m4(int i) {
125     i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
126     i = i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i;
127     s = i == 0 ? "true" : "false";
128   }
129 
130   // Frame merges: two non-array objects.
m5(boolean b)131   public static Number m5(boolean b) {
132     return b ? new Integer(1) : new Float(1);
133   }
134 
135   // Frame merges: two single-dimensional arrays with object type elements.
m6(boolean b)136   public static Number[] m6(boolean b) {
137     return b ? new Integer[1] : new Float[1];
138   }
139 
140   // Frame merges: two bi-dimensional arrays with object type elements.
m7(boolean b)141   public static Number[][] m7(boolean b) {
142     return b ? new Integer[1][1] : new Float[1][1];
143   }
144 
145   // Frame merges: two bi-dimensional arrays with primitive type elements.
m8(boolean b)146   public static Object[] m8(boolean b) {
147     return b ? (Object[]) new byte[1][1] : (Object[]) new short[1][1];
148   }
149 
150   // Frame merges: two single-dimensional arrays with mixed primitive / object type elements.
m9(boolean b)151   public static Object m9(boolean b) {
152     return b ? new byte[1] : new Float[1];
153   }
154 
155   // Frame merges: two bi-dimensional arrays with mixed primitive / object type elements.
m10(boolean b)156   public static Object[] m10(boolean b) {
157     return b ? (Object[]) new byte[1][1] : (Object[]) new Float[1][];
158   }
159 
160   // Frame merges: one and two dimensions arrays with identical element type.
m11(boolean b)161   public static Object m11(boolean b) {
162     return b ? new byte[1] : new byte[1][1];
163   }
164 
165   // Frame merges: one and two dimensions arrays with mixed primitive / object type elements.
m12(boolean b)166   public static Object[] m12(boolean b) {
167     return b ? new Object[1] : new byte[1][1];
168   }
169 
170   // Frame merges: two and three dimensions arrays with primitive type elements.
m13(boolean b)171   public static Object[] m13(boolean b) {
172     return b ? (Object[]) new byte[1][1] : (Object[]) new byte[1][1][1];
173   }
174 
175   // Frame merges: three and four dimensions arrays with primitive type elements.
m14(boolean b)176   public static Object[][] m14(boolean b) {
177     return b ? (Object[][]) new byte[1][1][1] : (Object[][]) new byte[1][1][1][1];
178   }
179 
180   // Frame merges: object type and single-dimensional array with primitive type elements.
m15(boolean b)181   public static Object m15(boolean b) {
182     return b ? new Integer(1) : new char[1];
183   }
184 
185   // Frame merges: object type and single-dimensional array with object type elements.
m16(boolean b)186   public static Object m16(boolean b) {
187     return b ? new Integer(1) : new Float[1];
188   }
189 
190   // Frame merges: two single-dimensional arrays with different primitive type elements.
m17(boolean b)191   public Object m17(boolean b) {
192     return b ? new int[0] : new boolean[0];
193   }
194 
195   // Frame merges: two single-dimensional arrays with different primitive type elements.
m18(boolean b)196   public Object m18(boolean b) {
197     return b ? new short[0] : new float[0];
198   }
199 
200   // Frame merges: two single-dimensional arrays with different primitive type elements.
m19(boolean b)201   public Object m19(boolean b) {
202     return b ? new double[0] : new long[0];
203   }
204 
205   // Frame merges: null type and object type.
m20(boolean b)206   public static Object m20(boolean b) {
207     return b ? null : new Integer(1);
208   }
209 
210   // Frame merges: object type and null type.
m21(boolean b)211   public static Object m21(boolean b) {
212     return b ? new Integer(1) : null;
213   }
214 
215   // Frame AALOAD from null array (no frame in original class because ASM can't compute the exact
216   // same frame as javac, but usefull for tests that compute frame types at each instruction).
m23()217   public static int m23() {
218     Integer[] array = null;
219     return array[0].intValue();
220   }
221 }
222