Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/FetchLocals.java
38855 views
/** hard coded linenumbers in test - DO NOT CHANGE1* @test/nodynamiccopyright/2* @bug 4386002 44292453* @summary Test fix for: Incorrect values reported for some locals of type long4*5* @author Tim Bell6*7* @run build TestScaffold VMConnection TargetListener TargetAdapter8* @run compile -g FetchLocals.java9* @run main FetchLocals10*/11import com.sun.jdi.*;12import com.sun.jdi.event.*;13import java.util.*;1415class FetchLocalsDebugee {16public long testMethod() {17short s = 12345;18int i = 8675309;19boolean pt = true;20long w = 973230999L;21byte b = 0x3b;22long x = w * 1000L;23char c = '\u005A'; // 005A = "Z"24long y = 22;25float f = 6.66f;26double d = 7.77;2728System.out.print("pt is: ");29System.out.println(pt);30System.out.print("b is: ");31System.out.println(b);32System.out.print("c is: ");33System.out.println(c);34System.out.print("s is: ");35System.out.println(s);36System.out.print("i is: ");37System.out.println(i);3839System.out.print("w is: ");40System.out.print(w);41System.out.print(" (0x");42System.out.print(Long.toHexString(w));43System.out.println(")");4445System.out.print("x is: ");46System.out.print(x);47System.out.print(" (0x");48System.out.print(Long.toHexString(x));49System.out.println(")");5051System.out.print("y is: ");52System.out.print(y);53System.out.print(" (0x");54System.out.print(Long.toHexString(y));55System.out.println(")");5657System.out.print("f is: ");58System.out.println(f);59System.out.print("d is: ");60System.out.println(d);61System.out.println(); // Thie is Line 63...62if (w == 0xde00ad00be00ef00L) {63System.out.print ("The debugger was here. w modified to: 0x");64System.out.println(Long.toHexString(w));65} else {66System.out.print ("w contains : 0x");67System.out.println(Long.toHexString(w));68}69System.out.println();70return x;71}72public static void main(String[] args) {73System.out.print ("FetchLocalsDebugee");74System.out.println(" Starting up...");75FetchLocalsDebugee my = new FetchLocalsDebugee ();76long result = my.testMethod();77System.out.print ("testMethod() returned: ");78System.out.print (result);79System.out.print (" (0x");80System.out.print (Long.toHexString(result));81System.out.println(")");8283System.out.print ("FetchLocalsDebugee");84System.out.println(" Shutting down...");85}86}8788public class FetchLocals extends TestScaffold {8990FetchLocals (String args[]) {91super(args);92}9394public static void main(String[] args)95throws Exception96{97new FetchLocals (args).startTests();98}99100/** Express a 64 bit double as a hex string101*/102private static String hexify(double d) {103long bits = Double.doubleToLongBits(d);104return (" (0x" + java.lang.Long.toHexString(bits) + ")");105}106/** Express a 32 bit float as a hex string107*/108private static String hexify(float f) {109int bits = Float.floatToIntBits(f);110return (" (0x" + java.lang.Integer.toHexString(bits) + ")");111}112113protected void test(String name, BooleanValue testV, boolean expectV)114throws Exception115{116if (testV.value() != expectV) {117System.out.println("Error for " + name + " = " + testV.value() +118" should be: " + expectV);119testFailed = true;120} else {121System.out.print ("Tested OK: ");122System.out.print (name);123System.out.print (" = ");124System.out.println(expectV);125}126}127128protected void test(String name, ByteValue testV, byte expectV)129throws Exception130{131if (testV.value() != expectV) {132System.out.println("Error for " + name + " = " + testV.value() +133" should be: " + expectV);134testFailed = true;135} else {136System.out.print ("Tested OK: ");137System.out.print (name);138System.out.print (" = ");139System.out.println(expectV);140}141}142143protected void test(String name, CharValue testV, char expectV)144throws Exception145{146if (testV.value() != expectV) {147System.out.println("Error for " + name + " = " + testV.value() +148" should be: " + expectV);149testFailed = true;150} else {151System.out.print ("Tested OK: ");152System.out.print (name);153System.out.print (" = ");154System.out.println(expectV);155}156}157158protected void test(String name, ShortValue testV, short expectV)159throws Exception160{161if (testV.value() != expectV) {162System.out.println("Error for " + name + " = " + testV.value() +163" should be: " + expectV);164testFailed = true;165} else {166System.out.print ("Tested OK: ");167System.out.print (name);168System.out.print (" = ");169System.out.println(expectV);170}171}172173protected void test(String name, IntegerValue testV, int expectV)174throws Exception175{176if (testV.value() != expectV) {177System.out.println("Error for " + name + " = " + testV.value() +178" should be: " + expectV);179testFailed = true;180} else {181System.out.print ("Tested OK: ");182System.out.print (name);183System.out.print (" = ");184System.out.println(expectV);185}186}187188protected void test(String name, LongValue testV, long expectV)189throws Exception190{191if (testV.value() != expectV) {192System.out.println("Error for " + name + " = 0x" +193Long.toHexString(testV.value()) +194" should be: 0x" +195Long.toHexString(expectV));196testFailed = true;197} else {198System.out.print ("Tested OK: ");199System.out.print (name);200System.out.print (" = ");201System.out.println(expectV);202}203}204205protected void test(String name, FloatValue testV, float expectV)206throws Exception207{208if (testV.value() != expectV) {209System.out.println("Error for " + name + " = " + testV.value() +210hexify(testV.value()) +211" should be: " + expectV +212hexify(expectV));213testFailed = true;214} else {215System.out.print ("Tested OK: ");216System.out.print (name);217System.out.print (" = ");218System.out.println(expectV);219}220}221222protected void test(String name, DoubleValue testV, double expectV)223throws Exception224{225if (testV.value() != expectV) {226System.out.println("Error for " + name + " = " + testV.value() +227hexify(testV.value()) +228" should be: " + expectV +229hexify(expectV));230testFailed = true;231} else {232System.out.print ("Tested OK: ");233System.out.print (name);234System.out.print (" = ");235System.out.println(expectV);236}237}238239protected void testLocalVariables (StackFrame sf)240throws Exception241{242/*243* Test values in the local method testMethod ():244* 1) Read current data245* 2) Test against the expected value246* 3) Set to a new value247* 4) Read again248* 5) Test against the expected value249*/250LocalVariable lv = sf.visibleVariableByName("pt");251BooleanValue booleanV = (BooleanValue) sf.getValue(lv);252test("pt", booleanV, true);253booleanV = vm().mirrorOf(false);254sf.setValue(lv, booleanV);255booleanV = (BooleanValue) sf.getValue(lv);256test("pt", booleanV, false);257258lv = sf.visibleVariableByName("b");259ByteValue byteV = (ByteValue) sf.getValue(lv);260byte bTmp = 0x3b;261test("b", byteV, bTmp);262bTmp = 0x7e;263byteV = vm().mirrorOf(bTmp);264sf.setValue(lv, byteV);265byteV = (ByteValue) sf.getValue(lv);266test("b", byteV, bTmp);267268lv = sf.visibleVariableByName("c");269CharValue charV = (CharValue) sf.getValue(lv);270char cTmp = '\u005A';271test("c", charV, cTmp);272cTmp = 'A';273charV = vm().mirrorOf(cTmp);274sf.setValue(lv, charV);275charV = (CharValue) sf.getValue(lv);276test("c", charV, cTmp);277278lv = sf.visibleVariableByName("s");279ShortValue shortV = (ShortValue) sf.getValue(lv);280short sTmp = 12345;281test("s", shortV, sTmp);282sTmp = -32766;283shortV = vm().mirrorOf(sTmp);284sf.setValue(lv, shortV);285shortV = (ShortValue) sf.getValue(lv);286test("s", shortV, sTmp);287288lv = sf.visibleVariableByName("i");289IntegerValue integerV = (IntegerValue) sf.getValue(lv);290int iTmp = 8675309;291test("i", integerV, iTmp);292iTmp = -42;293integerV = vm().mirrorOf(iTmp);294sf.setValue(lv, integerV);295integerV = (IntegerValue) sf.getValue(lv);296test("i", integerV, iTmp);297298lv = sf.visibleVariableByName("w");299LongValue longV = (LongValue) sf.getValue(lv);300long wTmp = 973230999L;301test("w", longV, wTmp);302wTmp = 0xde00ad00be00ef00L;303longV = vm().mirrorOf(wTmp);304sf.setValue(lv, longV);305longV = (LongValue) sf.getValue(lv);306test("w", longV, wTmp);307308lv = sf.visibleVariableByName("x");309longV = (LongValue) sf.getValue(lv);310long xTmp = 973230999L * 1000L;311test("x", longV, xTmp);312xTmp = 0xca00fe00ba00be00L;313longV = vm().mirrorOf(xTmp);314sf.setValue(lv, longV);315longV = (LongValue) sf.getValue(lv);316test("x", longV, xTmp);317318lv = sf.visibleVariableByName("y");319longV = (LongValue) sf.getValue(lv);320long yTmp = 22;321test("y", longV, yTmp);322yTmp = 0xdeadbeefcafebabeL;323longV = vm().mirrorOf(yTmp);324sf.setValue(lv, longV);325longV = (LongValue) sf.getValue(lv);326test("x", longV, yTmp);327328lv = sf.visibleVariableByName("f");329FloatValue floatV = (FloatValue) sf.getValue(lv);330float fTmp = 6.66f;331test("f", floatV, fTmp);332fTmp = (float)java.lang.Math.PI;333floatV = vm().mirrorOf(fTmp);334sf.setValue(lv, floatV);335floatV = (FloatValue)sf.getValue(lv);336test("f", floatV, fTmp);337338lv = sf.visibleVariableByName("d");339DoubleValue doubleV = (DoubleValue) sf.getValue(lv);340double dTmp = 7.77;341test("d", doubleV, dTmp);342dTmp = java.lang.Math.E;343doubleV = vm().mirrorOf(dTmp);344sf.setValue(lv, doubleV);345doubleV = (DoubleValue) sf.getValue(lv);346test("d", doubleV, dTmp);347}348349protected void runTests()350throws Exception351{352startToMain("FetchLocalsDebugee");353/*354* Get to the bottom of testMethod():355*/356try {357BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", 63);358/*359* Fetch values from fields; what did we get?360*/361StackFrame sf = bpe.thread().frame(0);362testLocalVariables (sf);363364} catch(Exception ex) {365ex.printStackTrace();366testFailed = true;367} finally {368// Allow application to complete and shut down369resumeToVMDisconnect();370}371if (!testFailed) {372System.out.println("FetchLocals: passed");373} else {374throw new Exception("FetchLocals: failed");375}376}377}378379380