< prev index next >

test/com/sun/jdi/FetchLocals.java

Print this page
rev 16891 : 8177507: line number sensitive tests for jdi should be unified
Reviewed-by: duke
   1 /** hard coded linenumbers in test - DO NOT CHANGE
   2  *  @test/nodynamiccopyright/

























   3  *  @bug 4386002 4429245
   4  *  @summary Test fix for: Incorrect values reported for some locals of type long
   5  *
   6  *  @author Tim Bell
   7  *
   8  *  @run build TestScaffold VMConnection TargetListener TargetAdapter
   9  *  @run compile -g FetchLocals.java
  10  *  @run driver FetchLocals
  11  */
  12 import com.sun.jdi.*;
  13 import com.sun.jdi.event.*;
  14 import java.util.*;
  15 
  16 class FetchLocalsDebugee {
  17     public long testMethod() {
  18         short s = 12345;
  19         int i = 8675309;
  20         boolean pt = true;
  21         long w = 973230999L;
  22         byte b = 0x3b;
  23         long x = w * 1000L;
  24         char c = '\u005A';      // 005A = "Z"
  25         long y = 22;


  42         System.out.print("     (0x");
  43         System.out.print(Long.toHexString(w));
  44         System.out.println(")");
  45 
  46         System.out.print("x is: ");
  47         System.out.print(x);
  48         System.out.print("  (0x");
  49         System.out.print(Long.toHexString(x));
  50         System.out.println(")");
  51 
  52         System.out.print("y is: ");
  53         System.out.print(y);
  54         System.out.print("            (0x");
  55         System.out.print(Long.toHexString(y));
  56         System.out.println(")");
  57 
  58         System.out.print("f is: ");
  59         System.out.println(f);
  60         System.out.print("d is: ");
  61         System.out.println(d);
  62         System.out.println();   // Thie is Line 63...
  63         if (w == 0xde00ad00be00ef00L) {
  64           System.out.print  ("The debugger was here.  w modified to: 0x");
  65           System.out.println(Long.toHexString(w));
  66         } else {
  67           System.out.print  ("w contains : 0x");
  68           System.out.println(Long.toHexString(w));
  69         }
  70         System.out.println();
  71         return x;
  72     }
  73     public static void main(String[] args) {
  74         System.out.print  ("FetchLocalsDebugee");
  75         System.out.println(" Starting up...");
  76         FetchLocalsDebugee my = new FetchLocalsDebugee ();
  77         long result = my.testMethod();
  78         System.out.print  ("testMethod() returned: ");
  79         System.out.print  (result);
  80         System.out.print  (" (0x");
  81         System.out.print  (Long.toHexString(result));
  82         System.out.println(")");
  83 
  84         System.out.print  ("FetchLocalsDebugee");
  85         System.out.println(" Shutting down...");
  86     }
  87 }
  88 
  89 public class FetchLocals extends TestScaffold {

  90 
  91     FetchLocals (String args[]) {
  92         super(args);
  93     }
  94 
  95     public static void main(String[] args)
  96         throws Exception
  97     {
  98         new FetchLocals (args).startTests();
  99     }
 100 
 101     /** Express a 64 bit double as a hex string
 102       */
 103     private static String hexify(double d) {
 104         long bits = Double.doubleToLongBits(d);
 105         return (" (0x" + java.lang.Long.toHexString(bits) + ")");
 106     }
 107     /** Express a 32 bit float as a hex string
 108       */
 109     private static String hexify(float f) {


 338 
 339         lv = sf.visibleVariableByName("d");
 340         DoubleValue doubleV = (DoubleValue) sf.getValue(lv);
 341         double dTmp = 7.77;
 342         test("d", doubleV, dTmp);
 343         dTmp = java.lang.Math.E;
 344         doubleV = vm().mirrorOf(dTmp);
 345         sf.setValue(lv, doubleV);
 346         doubleV = (DoubleValue) sf.getValue(lv);
 347         test("d", doubleV, dTmp);
 348     }
 349 
 350     protected void runTests()
 351         throws Exception
 352     {
 353         startToMain("FetchLocalsDebugee");
 354         /*
 355          * Get to the bottom of testMethod():
 356          */
 357         try {
 358             BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", 63);
 359             /*
 360              * Fetch values from fields; what did we get?
 361              */
 362             StackFrame sf = bpe.thread().frame(0);
 363             testLocalVariables (sf);
 364 
 365         } catch(Exception ex) {
 366             ex.printStackTrace();
 367             testFailed = true;
 368         } finally {
 369             // Allow application to complete and shut down
 370             resumeToVMDisconnect();
 371         }
 372         if (!testFailed) {
 373             System.out.println("FetchLocals: passed");
 374         } else {
 375             throw new Exception("FetchLocals: failed");
 376         }
 377     }
 378 }
   1 /*
   2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 //    THIS TEST IS LINE NUMBER SENSITIVE
  25 
  26 /**
  27  * @test
  28  * @bug 4386002 4429245
  29  * @summary Test fix for: Incorrect values reported for some locals of type long

  30  * @author Tim Bell
  31  *
  32  * @run build TestScaffold VMConnection TargetListener TargetAdapter
  33  * @run compile -g FetchLocals.java
  34  * @run driver FetchLocals
  35  */
  36 import com.sun.jdi.*;
  37 import com.sun.jdi.event.*;
  38 import java.util.*;
  39 
  40 class FetchLocalsDebugee {
  41     public long testMethod() {
  42         short s = 12345;
  43         int i = 8675309;
  44         boolean pt = true;
  45         long w = 973230999L;
  46         byte b = 0x3b;
  47         long x = w * 1000L;
  48         char c = '\u005A';      // 005A = "Z"
  49         long y = 22;


  66         System.out.print("     (0x");
  67         System.out.print(Long.toHexString(w));
  68         System.out.println(")");
  69 
  70         System.out.print("x is: ");
  71         System.out.print(x);
  72         System.out.print("  (0x");
  73         System.out.print(Long.toHexString(x));
  74         System.out.println(")");
  75 
  76         System.out.print("y is: ");
  77         System.out.print(y);
  78         System.out.print("            (0x");
  79         System.out.print(Long.toHexString(y));
  80         System.out.println(")");
  81 
  82         System.out.print("f is: ");
  83         System.out.println(f);
  84         System.out.print("d is: ");
  85         System.out.println(d);
  86         System.out.println();   // This is FetchLocals::LINE
  87         if (w == 0xde00ad00be00ef00L) {
  88           System.out.print  ("The debugger was here.  w modified to: 0x");
  89           System.out.println(Long.toHexString(w));
  90         } else {
  91           System.out.print  ("w contains : 0x");
  92           System.out.println(Long.toHexString(w));
  93         }
  94         System.out.println();
  95         return x;
  96     }
  97     public static void main(String[] args) {
  98         System.out.print  ("FetchLocalsDebugee");
  99         System.out.println(" Starting up...");
 100         FetchLocalsDebugee my = new FetchLocalsDebugee ();
 101         long result = my.testMethod();
 102         System.out.print  ("testMethod() returned: ");
 103         System.out.print  (result);
 104         System.out.print  (" (0x");
 105         System.out.print  (Long.toHexString(result));
 106         System.out.println(")");
 107 
 108         System.out.print  ("FetchLocalsDebugee");
 109         System.out.println(" Shutting down...");
 110     }
 111 }
 112 
 113 public class FetchLocals extends TestScaffold {
 114     static final int LINE = 86;
 115 
 116     FetchLocals (String args[]) {
 117         super(args);
 118     }
 119 
 120     public static void main(String[] args)
 121         throws Exception
 122     {
 123         new FetchLocals (args).startTests();
 124     }
 125 
 126     /** Express a 64 bit double as a hex string
 127       */
 128     private static String hexify(double d) {
 129         long bits = Double.doubleToLongBits(d);
 130         return (" (0x" + java.lang.Long.toHexString(bits) + ")");
 131     }
 132     /** Express a 32 bit float as a hex string
 133       */
 134     private static String hexify(float f) {


 363 
 364         lv = sf.visibleVariableByName("d");
 365         DoubleValue doubleV = (DoubleValue) sf.getValue(lv);
 366         double dTmp = 7.77;
 367         test("d", doubleV, dTmp);
 368         dTmp = java.lang.Math.E;
 369         doubleV = vm().mirrorOf(dTmp);
 370         sf.setValue(lv, doubleV);
 371         doubleV = (DoubleValue) sf.getValue(lv);
 372         test("d", doubleV, dTmp);
 373     }
 374 
 375     protected void runTests()
 376         throws Exception
 377     {
 378         startToMain("FetchLocalsDebugee");
 379         /*
 380          * Get to the bottom of testMethod():
 381          */
 382         try {
 383             BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", LINE);
 384             /*
 385              * Fetch values from fields; what did we get?
 386              */
 387             StackFrame sf = bpe.thread().frame(0);
 388             testLocalVariables (sf);
 389 
 390         } catch(Exception ex) {
 391             ex.printStackTrace();
 392             testFailed = true;
 393         } finally {
 394             // Allow application to complete and shut down
 395             resumeToVMDisconnect();
 396         }
 397         if (!testFailed) {
 398             System.out.println("FetchLocals: passed");
 399         } else {
 400             throw new Exception("FetchLocals: failed");
 401         }
 402     }
 403 }
< prev index next >