test/com/sun/jdi/MethodExitReturnValuesTest.java

Print this page
rev 6587 : 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads


 192         Array.getBoolean(arrBoolean, 0);
 193         Array.get(arrObject, 0);
 194         stringValue.intern();
 195     }
 196 
 197     public static void main(String[] args) {
 198         // The debugger will stop at the start of main,
 199         // enable method exit events, and then do
 200         // a resume.
 201 
 202         MethodExitReturnValuesTarg xx =
 203             new MethodExitReturnValuesTarg();
 204 
 205         doit(xx);
 206     }
 207 }
 208 
 209 
 210 
 211 public class MethodExitReturnValuesTest extends TestScaffold {
 212 
 213     /*
 214      * Class patterns for which we don't want events (copied
 215      * from the "Trace.java" example):
 216      *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
 217      */
 218     private String[] excludes = {
 219         "javax.*",
 220         "sun.*",
 221         "com.sun.*",
 222         "com.oracle.*",
 223         "oracle.*"};
 224 
 225     static VirtualMachineManager vmm ;
 226     ClassType targetClass;
 227     Field theValueField;
 228     static int successes = 0;
 229     static final int expectedSuccesses = 44;  // determined by inspection :-)
 230 
 231     MethodExitReturnValuesTest(String args[]) {
 232         super(args);
 233     }
 234 
 235     public static void main(String[] args)      throws Exception {
 236         MethodExitReturnValuesTest meee = new MethodExitReturnValuesTest(args);
 237         vmm = Bootstrap.virtualMachineManager();
 238         meee.startTests();
 239     }
 240 
 241     // These are the methods that check for correct return values.
 242 
 243     void ckByteValue(Value retValue) {


 470 
 471     void ckVoidValue(Value retValue) {
 472         System.out.println("Passed: Void");
 473         successes++;
 474     }
 475 
 476     void ckSinValue(Value retValue) {
 477         double rv = ((DoubleValue)retValue).value();
 478         double vv = StrictMath.sin(MethodExitReturnValuesTarg.doubleValue);
 479         if (rv != vv) {
 480             failure("failure: sin: expected " + vv + ", got " + rv);
 481         } else {
 482             System.out.println("Passed: sin " + rv);
 483             successes++;
 484         }
 485     }
 486 
 487     // This is the MethodExitEvent handler.
 488     public void methodExited(MethodExitEvent event) {
 489         String origMethodName = event.method().name();





 490         if (vmm.majorInterfaceVersion() >= 1 &&
 491             vmm.minorInterfaceVersion() >= 6 &&
 492             vm().canGetMethodReturnValues()) {
 493             Value retValue = event.returnValue();
 494 
 495             if ("sin".equals(origMethodName)) {
 496                 ckSinValue(retValue);
 497                 return;
 498             }
 499 
 500             if (!origMethodName.startsWith("s_") &&
 501                 !origMethodName.startsWith("i_")) {
 502                 // Check native methods
 503                 if ("getByte".equals(origMethodName))         ckByteValue(retValue);
 504                 else if ("getChar".equals(origMethodName))    ckCharValue(retValue);
 505                 else if ("getDouble".equals(origMethodName))  ckDoubleValue(retValue);
 506                 else if ("getFloat".equals(origMethodName))   ckFloatValue(retValue);
 507                 else if ("getInt".equals(origMethodName))     ckIntValue(retValue);
 508                 else if ("getLong".equals(origMethodName))    ckLongValue(retValue);
 509                 else if ("getShort".equals(origMethodName))   ckShortValue(retValue);


 544         }
 545     }
 546 
 547     protected void runTests() throws Exception {
 548         /*
 549          * Get to the top of main()
 550          * to determine targetClass and mainThread
 551          */
 552         BreakpointEvent bpe = startToMain("MethodExitReturnValuesTarg");
 553         targetClass = (ClassType)bpe.location().declaringType();
 554         mainThread = bpe.thread();
 555 
 556         theValueField = targetClass.fieldByName("theValue");
 557 
 558         /*
 559          * Ask for method exit events
 560          */
 561         MethodExitRequest exitRequest =
 562             eventRequestManager().createMethodExitRequest();
 563 
 564         for (int i=0; i<excludes.length; ++i) {
 565             exitRequest.addClassExclusionFilter(excludes[i]);
 566         }
 567         int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
 568         //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
 569         //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
 570         exitRequest.setSuspendPolicy(sessionSuspendPolicy);
 571         exitRequest.enable();
 572 
 573         /*
 574          * We are now set up to receive the notifications we want.
 575          * Here we go.  This adds 'this' as a listener so
 576          * that our handlers above will be called.
 577          */
 578 
 579         listenUntilVMDisconnect();
 580 
 581         if (successes != expectedSuccesses) {
 582             failure("failure: Expected " + expectedSuccesses + ", but got " + successes);
 583         }
 584         System.out.println("All done, " + successes + " passed");
 585 
 586 


 192         Array.getBoolean(arrBoolean, 0);
 193         Array.get(arrObject, 0);
 194         stringValue.intern();
 195     }
 196 
 197     public static void main(String[] args) {
 198         // The debugger will stop at the start of main,
 199         // enable method exit events, and then do
 200         // a resume.
 201 
 202         MethodExitReturnValuesTarg xx =
 203             new MethodExitReturnValuesTarg();
 204 
 205         doit(xx);
 206     }
 207 }
 208 
 209 
 210 
 211 public class MethodExitReturnValuesTest extends TestScaffold {
 212     // Classes which we are interested in
 213     private String[] includes = {
 214         "MethodExitReturnValuesTarg",
 215         "java.lang.reflect.Array",
 216         "java.lang.StrictMath",
 217         "java.lang.String"
 218     };





 219 
 220     static VirtualMachineManager vmm ;
 221     ClassType targetClass;
 222     Field theValueField;
 223     static int successes = 0;
 224     static final int expectedSuccesses = 44;  // determined by inspection :-)
 225 
 226     MethodExitReturnValuesTest(String args[]) {
 227         super(args);
 228     }
 229 
 230     public static void main(String[] args)      throws Exception {
 231         MethodExitReturnValuesTest meee = new MethodExitReturnValuesTest(args);
 232         vmm = Bootstrap.virtualMachineManager();
 233         meee.startTests();
 234     }
 235 
 236     // These are the methods that check for correct return values.
 237 
 238     void ckByteValue(Value retValue) {


 465 
 466     void ckVoidValue(Value retValue) {
 467         System.out.println("Passed: Void");
 468         successes++;
 469     }
 470 
 471     void ckSinValue(Value retValue) {
 472         double rv = ((DoubleValue)retValue).value();
 473         double vv = StrictMath.sin(MethodExitReturnValuesTarg.doubleValue);
 474         if (rv != vv) {
 475             failure("failure: sin: expected " + vv + ", got " + rv);
 476         } else {
 477             System.out.println("Passed: sin " + rv);
 478             successes++;
 479         }
 480     }
 481 
 482     // This is the MethodExitEvent handler.
 483     public void methodExited(MethodExitEvent event) {
 484         String origMethodName = event.method().name();
 485 
 486         if (!Arrays.asList(includes).contains(event.method().declaringType().name())) {
 487             return;
 488         }
 489 
 490         if (vmm.majorInterfaceVersion() >= 1 &&
 491             vmm.minorInterfaceVersion() >= 6 &&
 492             vm().canGetMethodReturnValues()) {
 493             Value retValue = event.returnValue();
 494 
 495             if ("sin".equals(origMethodName)) {
 496                 ckSinValue(retValue);
 497                 return;
 498             }
 499 
 500             if (!origMethodName.startsWith("s_") &&
 501                 !origMethodName.startsWith("i_")) {
 502                 // Check native methods
 503                 if ("getByte".equals(origMethodName))         ckByteValue(retValue);
 504                 else if ("getChar".equals(origMethodName))    ckCharValue(retValue);
 505                 else if ("getDouble".equals(origMethodName))  ckDoubleValue(retValue);
 506                 else if ("getFloat".equals(origMethodName))   ckFloatValue(retValue);
 507                 else if ("getInt".equals(origMethodName))     ckIntValue(retValue);
 508                 else if ("getLong".equals(origMethodName))    ckLongValue(retValue);
 509                 else if ("getShort".equals(origMethodName))   ckShortValue(retValue);


 544         }
 545     }
 546 
 547     protected void runTests() throws Exception {
 548         /*
 549          * Get to the top of main()
 550          * to determine targetClass and mainThread
 551          */
 552         BreakpointEvent bpe = startToMain("MethodExitReturnValuesTarg");
 553         targetClass = (ClassType)bpe.location().declaringType();
 554         mainThread = bpe.thread();
 555 
 556         theValueField = targetClass.fieldByName("theValue");
 557 
 558         /*
 559          * Ask for method exit events
 560          */
 561         MethodExitRequest exitRequest =
 562             eventRequestManager().createMethodExitRequest();
 563 



 564         int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
 565         //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
 566         //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
 567         exitRequest.setSuspendPolicy(sessionSuspendPolicy);
 568         exitRequest.enable();
 569 
 570         /*
 571          * We are now set up to receive the notifications we want.
 572          * Here we go.  This adds 'this' as a listener so
 573          * that our handlers above will be called.
 574          */
 575 
 576         listenUntilVMDisconnect();
 577 
 578         if (successes != expectedSuccesses) {
 579             failure("failure: Expected " + expectedSuccesses + ", but got " + successes);
 580         }
 581         System.out.println("All done, " + successes + " passed");
 582 
 583