< prev index next >

test/vmTestbase/nsk/jvmti/PopFrame/popframe002.java

Print this page




  29  * This test checks that the JVMTI function <code>PopFrame()</code>
  30  * correctly returns the following errors:
  31  * <li><i>JVMTI_ERROR_NULL_POINTER</i>
  32  * <li><i>JVMTI_ERROR_INVALID_THREAD</i>
  33  * <li><i>JVMTI_ERROR_THREAD_NOT_SUSPENDED</i><br>
  34  * and no JVMTI events will be generated by the function.<br>
  35  * The test creates an instance of inner class <code>popFrameCls</code>
  36  * and start it in a separate thread. Then the test tries to pop frame
  37  * with the following erroneous thread's parameter of the
  38  * <code>PopFrame()</code>:
  39  * <li>NULL pointer to the thread
  40  * <li>an invalid thread
  41  * <li>the non suspended popFrameCls' thread<br><br>
  42  * The test was changed due to the bug 4448675.
  43  */
  44 public class popframe002 {
  45     static final int PASSED = 0;
  46     static final int FAILED = 2;
  47     static final int JCK_STATUS_BASE = 95;
  48 
  49     static boolean DEBUG_MODE = false;
  50     static volatile boolean popFdone = false;
  51     static volatile int totRes = PASSED;
  52     private PrintStream out;
  53     private popFrameCls popFrameClsThr;
  54     static Object readi = new Object(); // for notification about readiness
  55     static Object barrier = new Object(); // for suspending a child thread
  56 
  57     static {
  58         try {
  59             System.loadLibrary("popframe002");
  60         } catch (UnsatisfiedLinkError e) {
  61             System.err.println("Could not load popframe002 library");
  62             System.err.println("java.library.path:" +
  63                 System.getProperty("java.library.path"));
  64             throw e;
  65         }
  66     }
  67 




  68     native static int doPopFrame(int t_case, popFrameCls popFrameClsThr);
  69 
  70     public static void main(String[] argv) {
  71         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
  72 
  73         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
  74     }
  75 
  76     public static int run(String argv[], PrintStream out) {
  77         return new popframe002().runIt(argv, out);
  78     }
  79 
  80     private int runIt(String argv[], PrintStream out) {
  81         int retValue = 0;
  82 
  83         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 
  89         popFrameClsThr = new popFrameCls();
  90         synchronized (barrier) { // force a child thread to pause
  91             synchronized(readi) {
  92                 popFrameClsThr.start(); // start the child thread
  93 // wait until the thread will enter into a necessary method
  94                 try {
  95                     readi.wait(); // wait for the child readiness
  96                 } catch (Exception e) {
  97                     out.println("TEST FAILURE: waiting for " +
  98                         popFrameClsThr.toString() + ": caught " + e);
  99                     return FAILED;
 100                 }
 101             }
 102 
 103 /* check that if PopFrame() would be invoked with NULL pointer to
 104    the thread, it will return the error JVMTI_ERROR_NULL_POINTER */
 105             if (DEBUG_MODE)
 106                 totRes = retValue = doPopFrame(1, popFrameClsThr);
 107             else
 108                 totRes = retValue = doPopFrame(0, popFrameClsThr);
 109             if (DEBUG_MODE && retValue == PASSED)
 110                 out.println("Check #1 PASSED:\n" +
 111                     "\tPopFrame(), being invoked with NULL pointer " +
 112                     "to the thread,\n" +
 113                     "\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");

 114 
 115 /* check that if the thread, whose top frame is to be popped,
 116   is invalid, the PopFrame() will return the error
 117   JVMTI_ERROR_INVALID_THREAD */
 118             if (DEBUG_MODE)
 119                 retValue = doPopFrame(3, popFrameClsThr);
 120             else
 121                 retValue = doPopFrame(2, popFrameClsThr);
 122             if (retValue == FAILED) {
 123                 popFdone = true;
 124                 totRes = FAILED;
 125             } else
 126                 if (DEBUG_MODE && retValue == PASSED)
 127                     out.println("Check #3 PASSED:\n" +
 128                         "\tPopFrame(), being invoked with " +
 129                         "the invalid thread,\n" +
 130                         "\treturned the appropriate error " +
 131                         "JVMTI_ERROR_INVALID_THREAD");

 132 
 133 /* check that if the thread, whose top frame is to be popped,
 134   has not been suspended, the PopFrame() will return the error
 135   JVMTI_ERROR_THREAD_NOT_SUSPENDED */
 136             if (DEBUG_MODE)
 137                 retValue = doPopFrame(5, popFrameClsThr);
 138             else
 139                 retValue = doPopFrame(4, popFrameClsThr);
 140             if (retValue == FAILED) {
 141                 popFdone = true;
 142                 totRes = FAILED;
 143             } else
 144                 if (DEBUG_MODE && retValue == PASSED)
 145                     out.println("Check #5 PASSED:\n" +
 146                         "\tPopFrame(), being invoked with " +
 147                         "the non suspended thread,\n" +
 148                         "\treturned the appropriate error " +
 149                         "JVMTI_ERROR_THREAD_NOT_SUSPENDED");
 150         }

 151 
 152         return totRes;
 153     }
 154 
 155     class popFrameCls extends Thread {
 156         public void run() {
 157             boolean compl = true;
 158 
 159             if (popframe002.popFdone) { // popping has been done
 160                 out.println("TEST FAILED: frame with popFrameCls.run() was popped");
 161                 popframe002.totRes = FAILED;
 162             }
 163             else {
 164                 synchronized(readi) {
 165                     readi.notify(); // notify the main thread
 166                 }
 167             }
 168             if (DEBUG_MODE)
 169                 out.println("popFrameCls (" + this +
 170                     "): inside run()");
 171             try {
 172 // pause here and get the main thread a chance to run
 173                 synchronized (popframe002.barrier) {}
 174                 compl = false;
 175             } catch (Exception e) {
 176                 out.println("FAILURE: popFrameCls (" + this +
 177                     "): caught " + e);
 178                 compl = false;
 179             } finally {
 180                 if (compl) {
 181                     out.println("TEST FAILED: finally block was executed after PopFrame()");
 182                     popframe002.totRes = FAILED;
 183                 }
 184             }
 185         }
 186     }
 187 }


  29  * This test checks that the JVMTI function <code>PopFrame()</code>
  30  * correctly returns the following errors:
  31  * <li><i>JVMTI_ERROR_NULL_POINTER</i>
  32  * <li><i>JVMTI_ERROR_INVALID_THREAD</i>
  33  * <li><i>JVMTI_ERROR_THREAD_NOT_SUSPENDED</i><br>
  34  * and no JVMTI events will be generated by the function.<br>
  35  * The test creates an instance of inner class <code>popFrameCls</code>
  36  * and start it in a separate thread. Then the test tries to pop frame
  37  * with the following erroneous thread's parameter of the
  38  * <code>PopFrame()</code>:
  39  * <li>NULL pointer to the thread
  40  * <li>an invalid thread
  41  * <li>the non suspended popFrameCls' thread<br><br>
  42  * The test was changed due to the bug 4448675.
  43  */
  44 public class popframe002 {
  45     static final int PASSED = 0;
  46     static final int FAILED = 2;
  47     static final int JCK_STATUS_BASE = 95;
  48 

  49     static volatile boolean popFdone = false;
  50     static volatile int totRes = PASSED;
  51     private PrintStream out;
  52     private popFrameCls popFrameClsThr;
  53     static Object readi = new Object(); // for notification about readiness
  54     static Object barrier = new Object(); // for suspending a child thread
  55 
  56     static {
  57         try {
  58             System.loadLibrary("popframe002");
  59         } catch (UnsatisfiedLinkError e) {
  60             System.err.println("Could not load popframe002 library");
  61             System.err.println("java.library.path:" +
  62                 System.getProperty("java.library.path"));
  63             throw e;
  64         }
  65     }
  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
  71     native static int doPopFrame(int t_case, popFrameCls popFrameClsThr);
  72 
  73     public static void main(String[] argv) {
  74         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
  75 
  76         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
  77     }
  78 
  79     public static int run(String argv[], PrintStream out) {
  80         return new popframe002().runIt(argv, out);
  81     }
  82 
  83     private int runIt(String argv[], PrintStream out) {
  84         int retValue = 0;
  85 
  86         this.out = out;




  87 
  88         popFrameClsThr = new popFrameCls();
  89         synchronized (barrier) { // force a child thread to pause
  90             synchronized(readi) {
  91                 popFrameClsThr.start(); // start the child thread
  92                 // wait until the thread will enter into a necessary method
  93                 try {
  94                     readi.wait(); // wait for the child readiness
  95                 } catch (Exception e) {
  96                     out.println("TEST FAILURE: waiting for " +
  97                         popFrameClsThr.toString() + ": caught " + e);
  98                     return FAILED;
  99                 }
 100             }
 101 
 102             /* check that if PopFrame() would be invoked with NULL pointer to
 103                the thread, it will return the error JVMTI_ERROR_NULL_POINTER */

 104             totRes = retValue = doPopFrame(1, popFrameClsThr);
 105             if (retValue == PASSED) {


 106                 out.println("Check #1 PASSED:\n" +
 107                         "\tPopFrame(), being invoked with NULL pointer " +
 108                         "to the thread,\n" +
 109                         "\treturned the appropriate error JVMTI_ERROR_NULL_POINTER");
 110             }
 111 
 112             /* check that if the thread, whose top frame is to be popped,
 113                is invalid, the PopFrame() will return the error
 114                JVMTI_ERROR_INVALID_THREAD */



 115             retValue = doPopFrame(2, popFrameClsThr);
 116             if (retValue == FAILED) {
 117                 popFdone = true;
 118                 totRes = FAILED;
 119             } else {
 120                 out.println("Check #2 PASSED:\n" +

 121                         "\tPopFrame(), being invoked with " +
 122                         "the invalid thread,\n" +
 123                         "\treturned the appropriate error " +
 124                         "JVMTI_ERROR_INVALID_THREAD");
 125             }
 126 
 127             /* check that if the thread, whose top frame is to be popped,
 128                has not been suspended, the PopFrame() will return the error
 129                JVMTI_ERROR_THREAD_NOT_SUSPENDED */
 130             retValue = doPopFrame(3, popFrameClsThr);



 131             if (retValue == FAILED) {
 132                 popFdone = true;
 133                 totRes = FAILED;
 134             } else {
 135                 out.println("Check #3 PASSED:\n" +

 136                         "\tPopFrame(), being invoked with " +
 137                         "the non suspended thread,\n" +
 138                         "\treturned the appropriate error " +
 139                         "JVMTI_ERROR_THREAD_NOT_SUSPENDED");
 140             }
 141         }
 142 
 143         return totRes;
 144     }
 145 
 146     class popFrameCls extends Thread {
 147         public void run() {
 148             boolean compl = true;
 149 
 150             if (popframe002.popFdone) { // popping has been done
 151                 out.println("TEST FAILED: frame with popFrameCls.run() was popped");
 152                 popframe002.totRes = FAILED;
 153             } else {

 154                 synchronized(readi) {
 155                     readi.notify(); // notify the main thread
 156                 }
 157             }



 158             try {
 159                 // pause here and get the main thread a chance to run
 160                 synchronized (popframe002.barrier) {}
 161                 compl = false;
 162             } catch (Exception e) {
 163                 out.println("FAILURE: popFrameCls (" + this +
 164                     "): caught " + e);
 165                 compl = false;
 166             } finally {
 167                 if (compl) {
 168                     out.println("TEST FAILED: finally block was executed after PopFrame()");
 169                     popframe002.totRes = FAILED;
 170                 }
 171             }
 172         }
 173     }
 174 }
< prev index next >