blob: 8f66da04de7903ffeee137dd220938295d587c96 [file] [log] [blame]
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class Main {
public static boolean doThrow = false;
private Object objectField;
private int intField;
private float floatField;
private long longField;
private double doubleField;
private byte byteField;
private boolean booleanField;
private char charField;
private short shortField;
private volatile Object volatileObjectField;
private volatile int volatileIntField;
private volatile float volatileFloatField;
private volatile long volatileLongField;
private volatile double volatileDoubleField;
private volatile byte volatileByteField;
private volatile boolean volatileBooleanField;
private volatile char volatileCharField;
private volatile short volatileShortField;
public static void $opt$noinline$setObjectField(Main m) {
if (doThrow) { throw new Error(); }
m.objectField = null;
}
public static void $opt$noinline$setIntField(Main m) {
if (doThrow) { throw new Error(); }
m.intField = 0;
}
public static void $opt$noinline$setFloatField(Main m) {
if (doThrow) { throw new Error(); }
m.floatField = 0;
}
public static void $opt$noinline$setLongField(Main m) {
if (doThrow) { throw new Error(); }
m.longField = 0;
}
public static void $opt$noinline$setDoubleField(Main m) {
if (doThrow) { throw new Error(); }
m.doubleField = 0;
}
public static void $opt$noinline$setByteField(Main m) {
if (doThrow) { throw new Error(); }
m.byteField = 0;
}
public static void $opt$noinline$setBooleanField(Main m) {
if (doThrow) { throw new Error(); }
m.booleanField = false;
}
public static void $opt$noinline$setCharField(Main m) {
if (doThrow) { throw new Error(); }
m.charField = 0;
}
public static void $opt$noinline$setShortField(Main m) {
if (doThrow) { throw new Error(); }
m.shortField = 0;
}
public static Object $opt$noinline$getObjectField(Main m) {
if (doThrow) { throw new Error(); }
return m.objectField;
}
public static int $opt$noinline$getIntField(Main m) {
if (doThrow) { throw new Error(); }
return m.intField;
}
public static float $opt$noinline$getFloatField(Main m) {
if (doThrow) { throw new Error(); }
return m.floatField;
}
public static long $opt$noinline$getLongField(Main m) {
if (doThrow) { throw new Error(); }
return m.longField;
}
public static double $opt$noinline$getDoubleField(Main m) {
if (doThrow) { throw new Error(); }
return m.doubleField;
}
public static byte $opt$noinline$getByteField(Main m) {
if (doThrow) { throw new Error(); }
return m.byteField;
}
public static boolean $opt$noinline$getBooleanField(Main m) {
if (doThrow) { throw new Error(); }
return m.booleanField;
}
public static char $opt$noinline$getCharField(Main m) {
if (doThrow) { throw new Error(); }
return m.charField;
}
public static short $opt$noinline$getShortField(Main m) {
if (doThrow) { throw new Error(); }
return m.shortField;
}
public static void $opt$noinline$setVolatileObjectField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileObjectField = null;
}
public static void $opt$noinline$setVolatileIntField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileIntField = 0;
}
public static void $opt$noinline$setVolatileFloatField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileFloatField = 0;
}
public static void $opt$noinline$setVolatileLongField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileLongField = 0;
}
public static void $opt$noinline$setVolatileDoubleField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileDoubleField = 0;
}
public static void $opt$noinline$setVolatileByteField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileByteField = 0;
}
public static void $opt$noinline$setVolatileBooleanField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileBooleanField = false;
}
public static void $opt$noinline$setVolatileCharField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileCharField = 0;
}
public static void $opt$noinline$setVolatileShortField(Main m) {
if (doThrow) { throw new Error(); }
m.volatileShortField = 0;
}
public static Object $opt$noinline$getVolatileObjectField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileObjectField;
}
public static int $opt$noinline$getVolatileIntField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileIntField;
}
public static float $opt$noinline$getVolatileFloatField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileFloatField;
}
public static long $opt$noinline$getVolatileLongField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileLongField;
}
public static double $opt$noinline$getVolatileDoubleField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileDoubleField;
}
public static byte $opt$noinline$getVolatileByteField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileByteField;
}
public static boolean $opt$noinline$getVolatileBooleanField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileBooleanField;
}
public static char $opt$noinline$getVolatileCharField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileCharField;
}
public static short $opt$noinline$getVolatileShortField(Main m) {
if (doThrow) { throw new Error(); }
return m.volatileShortField;
}
public static void $opt$noinline$setObjectElement(Object[] a) {
if (doThrow) { throw new Error(); }
a[0] = null;
}
public static void $opt$noinline$setIntElement(int[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setFloatElement(float[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setLongElement(long[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setDoubleElement(double[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setByteElement(byte[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setBooleanElement(boolean[] a) {
if (doThrow) { throw new Error(); }
a[0] = false;
}
public static void $opt$noinline$setCharElement(char[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static void $opt$noinline$setShortElement(short[] a) {
if (doThrow) { throw new Error(); }
a[0] = 0;
}
public static Object $opt$noinline$getObjectElement(Object[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static int $opt$noinline$getIntElement(int[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static float $opt$noinline$getFloatElement(float[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static long $opt$noinline$getLongElement(long[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static double $opt$noinline$getDoubleElement(double[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static byte $opt$noinline$getByteElement(byte[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static boolean $opt$noinline$getBooleanElement(boolean[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static char $opt$noinline$getCharElement(char[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static short $opt$noinline$getShortElement(short[] a) {
if (doThrow) { throw new Error(); }
return a[0];
}
public static void main(String[] args) {
int methodLine = 42;
int thisLine = 312;
try {
$opt$noinline$setObjectField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 2, methodLine, "$opt$noinline$setObjectField");
}
try {
$opt$noinline$setIntField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setIntField");
}
try {
$opt$noinline$setFloatField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setFloatField");
}
try {
$opt$noinline$setLongField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setLongField");
}
try {
$opt$noinline$setDoubleField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setDoubleField");
}
try {
$opt$noinline$setByteField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setByteField");
}
try {
$opt$noinline$setBooleanField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setBooleanField");
}
try {
$opt$noinline$setCharField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setCharField");
}
try {
$opt$noinline$setShortField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setShortField");
}
try {
$opt$noinline$getObjectField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getObjectField");
}
try {
$opt$noinline$getIntField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getIntField");
}
try {
$opt$noinline$getFloatField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getFloatField");
}
try {
$opt$noinline$getLongField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getLongField");
}
try {
$opt$noinline$getDoubleField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getDoubleField");
}
try {
$opt$noinline$getByteField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getByteField");
}
try {
$opt$noinline$getBooleanField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getBooleanField");
}
try {
$opt$noinline$getCharField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getCharField");
}
try {
$opt$noinline$getShortField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getShortField");
}
try {
$opt$noinline$setVolatileObjectField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileObjectField");
}
try {
$opt$noinline$setVolatileIntField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileIntField");
}
try {
$opt$noinline$setVolatileFloatField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileFloatField");
}
try {
$opt$noinline$setVolatileLongField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileLongField");
}
try {
$opt$noinline$setVolatileDoubleField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileDoubleField");
}
try {
$opt$noinline$setVolatileByteField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileByteField");
}
try {
$opt$noinline$setVolatileBooleanField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileBooleanField");
}
try {
$opt$noinline$setVolatileCharField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileCharField");
}
try {
$opt$noinline$setVolatileShortField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileShortField");
}
try {
$opt$noinline$getVolatileObjectField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileObjectField");
}
try {
$opt$noinline$getVolatileIntField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileIntField");
}
try {
$opt$noinline$getVolatileFloatField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileFloatField");
}
try {
$opt$noinline$getVolatileLongField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileLongField");
}
try {
$opt$noinline$getVolatileDoubleField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileDoubleField");
}
try {
$opt$noinline$getVolatileByteField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileByteField");
}
try {
$opt$noinline$getVolatileBooleanField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileBooleanField");
}
try {
$opt$noinline$getVolatileCharField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileCharField");
}
try {
$opt$noinline$getVolatileShortField(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileShortField");
}
try {
$opt$noinline$setObjectElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setObjectElement");
}
try {
$opt$noinline$setIntElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setIntElement");
}
try {
$opt$noinline$setFloatElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setFloatElement");
}
try {
$opt$noinline$setLongElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setLongElement");
}
try {
$opt$noinline$setDoubleElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setDoubleElement");
}
try {
$opt$noinline$setByteElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setByteElement");
}
try {
$opt$noinline$setBooleanElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setBooleanElement");
}
try {
$opt$noinline$setCharElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setCharElement");
}
try {
$opt$noinline$setShortElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setShortElement");
}
try {
$opt$noinline$getObjectElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getObjectElement");
}
try {
$opt$noinline$getIntElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getIntElement");
}
try {
$opt$noinline$getFloatElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getFloatElement");
}
try {
$opt$noinline$getLongElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getLongElement");
}
try {
$opt$noinline$getDoubleElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getDoubleElement");
}
try {
$opt$noinline$getByteElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getByteElement");
}
try {
$opt$noinline$getBooleanElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getBooleanElement");
}
try {
$opt$noinline$getCharElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getCharElement");
}
try {
$opt$noinline$getShortElement(null);
throw new RuntimeException("Failed to throw NullPointerException.");
} catch (NullPointerException npe) {
check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getShortElement");
}
}
static void check(NullPointerException npe, int mainLine, int medthodLine, String methodName) {
System.out.println(methodName);
StackTraceElement[] trace = npe.getStackTrace();
checkElement(trace[0], "Main", methodName, "Main.java", medthodLine);
checkElement(trace[1], "Main", "main", "Main.java", mainLine);
}
static void checkElement(StackTraceElement element,
String declaringClass, String methodName,
String fileName, int lineNumber) {
assertEquals(declaringClass, element.getClassName());
assertEquals(methodName, element.getMethodName());
assertEquals(fileName, element.getFileName());
assertEquals(lineNumber, element.getLineNumber());
}
static void assertEquals(Object expected, Object actual) {
if (!expected.equals(actual)) {
String msg = "Expected \"" + expected + "\" but got \"" + actual + "\"";
throw new AssertionError(msg);
}
}
static void assertEquals(int expected, int actual) {
if (expected != actual) {
throw new AssertionError("Expected " + expected + " got " + actual);
}
}
}