test/hotspot/jtreg/vmTestbase/nsk/jvmti/PopFrame/popframe002.java
changeset 53074 1e213c37befa
parent 50260 46c67f5e27c2
equal deleted inserted replaced
53073:11033c4ada54 53074:1e213c37befa
    44 public class popframe002 {
    44 public class popframe002 {
    45     static final int PASSED = 0;
    45     static final int PASSED = 0;
    46     static final int FAILED = 2;
    46     static final int FAILED = 2;
    47     static final int JCK_STATUS_BASE = 95;
    47     static final int JCK_STATUS_BASE = 95;
    48 
    48 
    49     static boolean DEBUG_MODE = false;
       
    50     static volatile boolean popFdone = false;
    49     static volatile boolean popFdone = false;
    51     static volatile int totRes = PASSED;
    50     static volatile int totRes = PASSED;
    52     private PrintStream out;
    51     private PrintStream out;
    53     private popFrameCls popFrameClsThr;
    52     private popFrameCls popFrameClsThr;
    54     static Object readi = new Object(); // for notification about readiness
    53     static Object readi = new Object(); // for notification about readiness
    63                 System.getProperty("java.library.path"));
    62                 System.getProperty("java.library.path"));
    64             throw e;
    63             throw e;
    65         }
    64         }
    66     }
    65     }
    67 
    66 
       
    67     // t_case:
       
    68     //   1 - PopFrame for NULL thread
       
    69     //   2 - PopFrame for invalid thread (not Thread object)
       
    70     //   3 - PopFrame for non-suspended thread
    68     native static int doPopFrame(int t_case, popFrameCls popFrameClsThr);
    71     native static int doPopFrame(int t_case, popFrameCls popFrameClsThr);
    69 
    72 
    70     public static void main(String[] argv) {
    73     public static void main(String[] argv) {
    71         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
    74         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
    72 
    75 
    79 
    82 
    80     private int runIt(String argv[], PrintStream out) {
    83     private int runIt(String argv[], PrintStream out) {
    81         int retValue = 0;
    84         int retValue = 0;
    82 
    85 
    83         this.out = out;
    86         this.out = out;
    84         for (int i = 0; i < argv.length; i++) {
       
    85             if (argv[i].equals("-v")) // verbose mode
       
    86                 DEBUG_MODE = true;
       
    87         }
       
    88 
    87 
    89         popFrameClsThr = new popFrameCls();
    88         popFrameClsThr = new popFrameCls();
    90         synchronized (barrier) { // force a child thread to pause
    89         synchronized (barrier) { // force a child thread to pause
    91             synchronized(readi) {
    90             synchronized(readi) {
    92                 popFrameClsThr.start(); // start the child thread
    91                 popFrameClsThr.start(); // start the child thread
    93 // wait until the thread will enter into a necessary method
    92                 // wait until the thread will enter into a necessary method
    94                 try {
    93                 try {
    95                     readi.wait(); // wait for the child readiness
    94                     readi.wait(); // wait for the child readiness
    96                 } catch (Exception e) {
    95                 } catch (Exception e) {
    97                     out.println("TEST FAILURE: waiting for " +
    96                     out.println("TEST FAILURE: waiting for " +
    98                         popFrameClsThr.toString() + ": caught " + e);
    97                         popFrameClsThr.toString() + ": caught " + e);
    99                     return FAILED;
    98                     return FAILED;
   100                 }
    99                 }
   101             }
   100             }
   102 
   101 
   103 /* check that if PopFrame() would be invoked with NULL pointer to
   102             /* check that if PopFrame() would be invoked with NULL pointer to
   104    the thread, it will return the error JVMTI_ERROR_NULL_POINTER */
   103                the thread, it will return the error JVMTI_ERROR_NULL_POINTER */
   105             if (DEBUG_MODE)
   104             totRes = retValue = doPopFrame(1, popFrameClsThr);
   106                 totRes = retValue = doPopFrame(1, popFrameClsThr);
   105             if (retValue == PASSED) {
   107             else
       
   108                 totRes = retValue = doPopFrame(0, popFrameClsThr);
       
   109             if (DEBUG_MODE && retValue == PASSED)
       
   110                 out.println("Check #1 PASSED:\n" +
   106                 out.println("Check #1 PASSED:\n" +
   111                     "\tPopFrame(), being invoked with NULL pointer " +
   107                         "\tPopFrame(), being invoked with NULL pointer " +
   112                     "to the thread,\n" +
   108                         "to the thread,\n" +
   113                     "\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");
   109                         "\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");
       
   110             }
   114 
   111 
   115 /* check that if the thread, whose top frame is to be popped,
   112             /* check that if the thread, whose top frame is to be popped,
   116   is invalid, the PopFrame() will return the error
   113                is invalid, the PopFrame() will return the error
   117   JVMTI_ERROR_INVALID_THREAD */
   114                JVMTI_ERROR_INVALID_THREAD */
   118             if (DEBUG_MODE)
   115             retValue = doPopFrame(2, popFrameClsThr);
   119                 retValue = doPopFrame(3, popFrameClsThr);
       
   120             else
       
   121                 retValue = doPopFrame(2, popFrameClsThr);
       
   122             if (retValue == FAILED) {
   116             if (retValue == FAILED) {
   123                 popFdone = true;
   117                 popFdone = true;
   124                 totRes = FAILED;
   118                 totRes = FAILED;
   125             } else
   119             } else {
   126                 if (DEBUG_MODE && retValue == PASSED)
   120                 out.println("Check #2 PASSED:\n" +
   127                     out.println("Check #3 PASSED:\n" +
       
   128                         "\tPopFrame(), being invoked with " +
   121                         "\tPopFrame(), being invoked with " +
   129                         "the invalid thread,\n" +
   122                         "the invalid thread,\n" +
   130                         "\treturned the appropriate error " +
   123                         "\treturned the appropriate error " +
   131                         "JVMTI_ERROR_INVALID_THREAD");
   124                         "JVMTI_ERROR_INVALID_THREAD");
       
   125             }
   132 
   126 
   133 /* check that if the thread, whose top frame is to be popped,
   127             /* check that if the thread, whose top frame is to be popped,
   134   has not been suspended, the PopFrame() will return the error
   128                has not been suspended, the PopFrame() will return the error
   135   JVMTI_ERROR_THREAD_NOT_SUSPENDED */
   129                JVMTI_ERROR_THREAD_NOT_SUSPENDED */
   136             if (DEBUG_MODE)
   130             retValue = doPopFrame(3, popFrameClsThr);
   137                 retValue = doPopFrame(5, popFrameClsThr);
       
   138             else
       
   139                 retValue = doPopFrame(4, popFrameClsThr);
       
   140             if (retValue == FAILED) {
   131             if (retValue == FAILED) {
   141                 popFdone = true;
   132                 popFdone = true;
   142                 totRes = FAILED;
   133                 totRes = FAILED;
   143             } else
   134             } else {
   144                 if (DEBUG_MODE && retValue == PASSED)
   135                 out.println("Check #3 PASSED:\n" +
   145                     out.println("Check #5 PASSED:\n" +
       
   146                         "\tPopFrame(), being invoked with " +
   136                         "\tPopFrame(), being invoked with " +
   147                         "the non suspended thread,\n" +
   137                         "the non suspended thread,\n" +
   148                         "\treturned the appropriate error " +
   138                         "\treturned the appropriate error " +
   149                         "JVMTI_ERROR_THREAD_NOT_SUSPENDED");
   139                         "JVMTI_ERROR_THREAD_NOT_SUSPENDED");
       
   140             }
   150         }
   141         }
   151 
   142 
   152         return totRes;
   143         return totRes;
   153     }
   144     }
   154 
   145 
   157             boolean compl = true;
   148             boolean compl = true;
   158 
   149 
   159             if (popframe002.popFdone) { // popping has been done
   150             if (popframe002.popFdone) { // popping has been done
   160                 out.println("TEST FAILED: frame with popFrameCls.run() was popped");
   151                 out.println("TEST FAILED: frame with popFrameCls.run() was popped");
   161                 popframe002.totRes = FAILED;
   152                 popframe002.totRes = FAILED;
   162             }
   153             } else {
   163             else {
       
   164                 synchronized(readi) {
   154                 synchronized(readi) {
   165                     readi.notify(); // notify the main thread
   155                     readi.notify(); // notify the main thread
   166                 }
   156                 }
   167             }
   157             }
   168             if (DEBUG_MODE)
       
   169                 out.println("popFrameCls (" + this +
       
   170                     "): inside run()");
       
   171             try {
   158             try {
   172 // pause here and get the main thread a chance to run
   159                 // pause here and get the main thread a chance to run
   173                 synchronized (popframe002.barrier) {}
   160                 synchronized (popframe002.barrier) {}
   174                 compl = false;
   161                 compl = false;
   175             } catch (Exception e) {
   162             } catch (Exception e) {
   176                 out.println("FAILURE: popFrameCls (" + this +
   163                 out.println("FAILURE: popFrameCls (" + this +
   177                     "): caught " + e);
   164                     "): caught " + e);