| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public class Main { |
| 18 |
public static void main(String args[]) { |
| 19 |
simpleTest(); |
| 20 |
hierarchyTest(); |
| 21 |
} |
| 22 |
|
| 23 |
public static void simpleTest() { |
| 24 |
|
| 25 |
Error badClinit = null; |
| 26 |
try { |
| 27 |
new Bad(11); |
| 28 |
} catch (Error e) { |
| 29 |
badClinit = e; |
| 30 |
} |
| 31 |
|
| 32 |
try { |
| 33 |
bad.foo(); |
| 34 |
} catch (NoClassDefFoundError ncdfe) { |
| 35 |
|
| 36 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 37 |
System.out.println("Caught NoClassDefFoundError."); |
| 38 |
} else { |
| 39 |
ncdfe.printStackTrace(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
try { |
| 44 |
bad.bar(); |
| 45 |
} catch (NoClassDefFoundError ncdfe) { |
| 46 |
|
| 47 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 48 |
System.out.println("Caught NoClassDefFoundError."); |
| 49 |
} else { |
| 50 |
ncdfe.printStackTrace(); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
bad.$noinline$testResolutionTrampoline(); |
| 56 |
} |
| 57 |
|
| 58 |
public static void hierarchyTest() { |
| 59 |
|
| 60 |
Error badClinit = null; |
| 61 |
try { |
| 62 |
new BadSuper(0); |
| 63 |
} catch (Error e) { |
| 64 |
badClinit = e; |
| 65 |
} |
| 66 |
|
| 67 |
try { |
| 68 |
badSuper.foo(); |
| 69 |
} catch (NoClassDefFoundError ncdfe) { |
| 70 |
|
| 71 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 72 |
System.out.println("Caught NoClassDefFoundError."); |
| 73 |
} else { |
| 74 |
ncdfe.printStackTrace(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
try { |
| 80 |
badSub.bar(); |
| 81 |
} catch (NoClassDefFoundError ncdfe) { |
| 82 |
|
| 83 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 84 |
System.out.println("Caught NoClassDefFoundError."); |
| 85 |
} else { |
| 86 |
ncdfe.printStackTrace(); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
try { |
| 92 |
new BadSub(-1, -2).bar(); |
| 93 |
} catch (NoClassDefFoundError ncdfe) { |
| 94 |
|
| 95 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 96 |
System.out.println("Caught NoClassDefFoundError."); |
| 97 |
} else { |
| 98 |
ncdfe.printStackTrace(); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
try { |
| 104 |
badSub.allocSuper(11111); |
| 105 |
System.out.println("Allocated BadSuper!"); |
| 106 |
} catch (NoClassDefFoundError ncdfe) { |
| 107 |
|
| 108 |
if (ncdfe.getCause() == badClinit || ncdfe.getCause() == null) { |
| 109 |
System.out.println("Caught NoClassDefFoundError."); |
| 110 |
} else { |
| 111 |
ncdfe.printStackTrace(); |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
public static Bad bad; |
| 117 |
|
| 118 |
public static BadSuper badSuper; |
| 119 |
public static BadSub badSub; |
| 120 |
} |
| 121 |
|
| 122 |
class Bad { |
| 123 |
static { |
| 124 |
|
| 125 |
Main.bad = new Bad(33); |
| 126 |
staticValue = 42; |
| 127 |
if (true) { throw new Error("Bad <clinit>"); } |
| 128 |
} |
| 129 |
public void foo() { |
| 130 |
System.out.println("Bad.foo()"); |
| 131 |
System.out.println("Bad.instanceValue = " + instanceValue); |
| 132 |
System.out.println("Bad.staticValue = " + staticValue); |
| 133 |
} |
| 134 |
public void bar() { |
| 135 |
System.out.println("Bad.bar()"); |
| 136 |
System.out.println("Bad.staticValue [indirect] = " + Helper.$inline$getBadStaticValue()); |
| 137 |
} |
| 138 |
public Bad(int iv) { instanceValue = iv; } |
| 139 |
public int instanceValue; |
| 140 |
public static int staticValue; |
| 141 |
|
| 142 |
public static class Helper { |
| 143 |
public static int $inline$getBadStaticValue() { |
| 144 |
return Bad.staticValue; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
public void $noinline$testResolutionTrampoline() { |
| 149 |
|
| 150 |
$noinline$testResolutionTrampolineCallee(); |
| 151 |
} |
| 152 |
|
| 153 |
private void $noinline$testResolutionTrampolineCallee() { |
| 154 |
System.out.println("Bad.$noinline$testResolutionTrampolineCallee()"); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
class BadSuper { |
| 159 |
static { |
| 160 |
Main.badSuper = new BadSuper(1); |
| 161 |
Main.badSub = new BadSub(11, 111); |
| 162 |
BadSuper.superStaticValue = 42; |
| 163 |
BadSub.subStaticValue = 4242; |
| 164 |
if (true) { throw new Error("Bad <clinit>"); } |
| 165 |
} |
| 166 |
public void foo() { |
| 167 |
System.out.println("BadSuper.foo()"); |
| 168 |
System.out.println("BadSuper.superInstanceValue = " + superInstanceValue); |
| 169 |
System.out.println("BadSuper.superStaticValue = " + superStaticValue); |
| 170 |
} |
| 171 |
public BadSuper(int superiv) { superInstanceValue = superiv; } |
| 172 |
public int superInstanceValue; |
| 173 |
public static int superStaticValue; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
class BadSub extends BadSuper { |
| 181 |
public void bar() { |
| 182 |
System.out.println("BadSub.bar()"); |
| 183 |
System.out.println("BadSub.subInstanceValue = " + subInstanceValue); |
| 184 |
System.out.println("BadSub.subStaticValue = " + subStaticValue); |
| 185 |
System.out.println("BadSuper.superInstanceValue = " + superInstanceValue); |
| 186 |
System.out.println("BadSuper.superStaticValue = " + superStaticValue); |
| 187 |
} |
| 188 |
public BadSuper allocSuper(int superiv) { |
| 189 |
System.out.println("BadSub.allocSuper(.)"); |
| 190 |
return new BadSuper(superiv); |
| 191 |
} |
| 192 |
public BadSub(int subiv, int superiv) { |
| 193 |
super(superiv); |
| 194 |
subInstanceValue = subiv; |
| 195 |
} |
| 196 |
public int subInstanceValue; |
| 197 |
public static int subStaticValue; |
| 198 |
} |