< prev index next >

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

Print this page




  22  */
  23 
  24 package nsk.jvmti.PopFrame;
  25 
  26 import nsk.share.Wicket;
  27 import java.io.PrintStream;
  28 
  29 /**
  30  * This test checks that a frame can be popped and<br>
  31  * no JVMTI events would be generated by the JVMTI function
  32  * <code>PopFrame()</code>.<br>
  33  * The test creates an instance of inner class <code>popFrameCls</code>
  34  * and start it in a separate thread. Then the test pops frame
  35  * from the thread's stack of the class <code>popFrameCls</code>.
  36  */
  37 public class popframe001 {
  38     static final int PASSED = 0;
  39     static final int FAILED = 2;
  40     static final int JCK_STATUS_BASE = 95;
  41 
  42     static boolean DEBUG_MODE = false;
  43     static volatile boolean popFdone = false;
  44     static volatile int totRes = PASSED;
  45     private PrintStream out;
  46     private popFrameCls popFrameClsThr;
  47     static Object barrier = new Object();
  48     static Wicket startingBarrier;
  49 
  50     static {
  51         try {
  52             System.loadLibrary("popframe001");
  53         } catch (UnsatisfiedLinkError e) {
  54             System.err.println("Could not load popframe001 library");
  55             System.err.println("java.library.path:" +
  56                 System.getProperty("java.library.path"));
  57             throw e;
  58         }
  59     }
  60 
  61     native static int doPopFrame(int vrb, popFrameCls popFrameClsThr);
  62     native static int suspThread(int vrb, popFrameCls popFrameClsThr);
  63     native static int resThread(int vrb, popFrameCls popFrameClsThr);
  64 
  65     public static void main(String[] argv) {
  66         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
  67 
  68         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
  69     }
  70 
  71     public static int run(String argv[], PrintStream out) {
  72         return new popframe001().runIt(argv, out);
  73     }
  74 
  75     private int runIt(String argv[], PrintStream out) {
  76         int retValue = 0;
  77 
  78         this.out = out;
  79         for (int i = 0; i < argv.length; i++) {
  80             if (argv[i].equals("-v")) // verbose mode
  81                 DEBUG_MODE = true;
  82         }
  83 
  84         popFrameClsThr = new popFrameCls("Tested Thread");
  85         startingBarrier = new Wicket();
  86         // start the child thread
  87         popFrameClsThr.start();
  88         startingBarrier.waitFor();
  89         // pause until the child thread exits notification-block
  90         synchronized (barrier) {
  91         }
  92 
  93         if (DEBUG_MODE) {
  94             out.println("Going to suspend the thread...");
  95             retValue = suspThread(1, popFrameClsThr);
  96         } else
  97             retValue = suspThread(0, popFrameClsThr);
  98         if (retValue != PASSED) {
  99             out.println("TEST: failed to suspend thread");
 100             return FAILED;
 101         }
 102 
 103         // pop a frame of the child thread
 104         if (DEBUG_MODE) {
 105             out.println("Going to pop a frame...");
 106             retValue = doPopFrame(1, popFrameClsThr);
 107         } else
 108             retValue = doPopFrame(0, popFrameClsThr);
 109         popFdone = true;
 110         popFrameClsThr.letItGo();
 111         if (retValue != PASSED) {
 112             out.println("TEST: failed to pop frame");
 113             resThread(0, popFrameClsThr);
 114             return FAILED;
 115         }
 116 
 117         if (DEBUG_MODE) {
 118             out.println("Going to resume the thread...");
 119             retValue = resThread(1, popFrameClsThr);
 120         } else
 121             retValue = resThread(0, popFrameClsThr);
 122         if (retValue != PASSED) {
 123             out.println("TEST: failed to resume thread");
 124             return FAILED;
 125         }
 126 
 127         try {
 128             popFrameClsThr.join();
 129         } catch (InterruptedException e) {
 130             out.println("TEST INCOMPLETE: caught " + e);
 131             return FAILED;
 132         }
 133 
 134         return totRes;
 135     }
 136 
 137     class popFrameCls extends Thread {
 138         private volatile boolean flag = true;
 139 
 140         popFrameCls(String name) {
 141             super(name);
 142         }
 143 
 144         public void run() {
 145             activeMethod();
 146             if (DEBUG_MODE)
 147                 out.println("popFrameCls (" + this +
 148                     "): exiting...");
 149         }
 150 
 151         public void activeMethod() {
 152             boolean compl = true; // complain in a finally block
 153 
 154             if (popframe001.popFdone) { // popping has been done
 155                 if (DEBUG_MODE)
 156                     out.println("popFrameCls (" + this +
 157                         "): enter activeMethod() after popping");
 158                 return;
 159             }
 160             try {
 161                 // notify the main thread
 162                 synchronized (popframe001.barrier) {
 163                     if (DEBUG_MODE)
 164                         out.println("popFrameCls (" + this +
 165                             "): notifying main thread");
 166                     popframe001.startingBarrier.unlock();
 167                     if (DEBUG_MODE)
 168                         out.println("popFrameCls (" + this +
 169                             "): inside activeMethod()");
 170                 }
 171                 // loop until the main thread pops us
 172                 int i = 0;
 173                 int n = 1000;
 174                 while (flag) {
 175                     if (n <= 0) {
 176                         n = 1000;
 177                     }
 178                     if (i > n) {
 179                         i = 0;
 180                         n--;
 181                     }
 182                     i++;
 183                 }
 184                 if (popframe001.popFdone) { // popping has been done
 185                     out.println("TEST FAILED: a tested frame has not been really popped");
 186                     popframe001.totRes = FAILED;
 187                     compl = false;
 188                 }
 189             } catch (Exception e) {


  22  */
  23 
  24 package nsk.jvmti.PopFrame;
  25 
  26 import nsk.share.Wicket;
  27 import java.io.PrintStream;
  28 
  29 /**
  30  * This test checks that a frame can be popped and<br>
  31  * no JVMTI events would be generated by the JVMTI function
  32  * <code>PopFrame()</code>.<br>
  33  * The test creates an instance of inner class <code>popFrameCls</code>
  34  * and start it in a separate thread. Then the test pops frame
  35  * from the thread's stack of the class <code>popFrameCls</code>.
  36  */
  37 public class popframe001 {
  38     static final int PASSED = 0;
  39     static final int FAILED = 2;
  40     static final int JCK_STATUS_BASE = 95;
  41 

  42     static volatile boolean popFdone = false;
  43     static volatile int totRes = PASSED;
  44     private PrintStream out;
  45     private popFrameCls popFrameClsThr;
  46     static Object barrier = new Object();
  47     static Wicket startingBarrier;
  48 
  49     static {
  50         try {
  51             System.loadLibrary("popframe001");
  52         } catch (UnsatisfiedLinkError e) {
  53             System.err.println("Could not load popframe001 library");
  54             System.err.println("java.library.path:" +
  55                 System.getProperty("java.library.path"));
  56             throw e;
  57         }
  58     }
  59 
  60     native static int doPopFrame(popFrameCls popFrameClsThr);
  61     native static int suspThread(popFrameCls popFrameClsThr);
  62     native static int resThread(popFrameCls popFrameClsThr);
  63 
  64     public static void main(String[] argv) {
  65         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
  66 
  67         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
  68     }
  69 
  70     public static int run(String argv[], PrintStream out) {
  71         return new popframe001().runIt(argv, out);
  72     }
  73 
  74     private int runIt(String argv[], PrintStream out) {
  75         int retValue = 0;
  76 
  77         this.out = out;




  78 
  79         popFrameClsThr = new popFrameCls("Tested Thread");
  80         startingBarrier = new Wicket();
  81         // start the child thread
  82         popFrameClsThr.start();
  83         startingBarrier.waitFor();
  84         // pause until the child thread exits notification-block
  85         synchronized (barrier) {
  86         }
  87 

  88         out.println("Going to suspend the thread...");
  89         retValue = suspThread(popFrameClsThr);


  90         if (retValue != PASSED) {
  91             out.println("TEST: failed to suspend thread");
  92             return FAILED;
  93         }
  94 
  95         // pop a frame of the child thread

  96         out.println("Going to pop a frame...");
  97         retValue = doPopFrame(popFrameClsThr);


  98         popFdone = true;
  99         popFrameClsThr.letItGo();
 100         if (retValue != PASSED) {
 101             out.println("TEST: failed to pop frame");
 102             resThread(popFrameClsThr);
 103             return FAILED;
 104         }
 105 

 106         out.println("Going to resume the thread...");
 107         retValue = resThread(popFrameClsThr);


 108         if (retValue != PASSED) {
 109             out.println("TEST: failed to resume thread");
 110             return FAILED;
 111         }
 112 
 113         try {
 114             popFrameClsThr.join();
 115         } catch (InterruptedException e) {
 116             out.println("TEST INCOMPLETE: caught " + e);
 117             return FAILED;
 118         }
 119 
 120         return totRes;
 121     }
 122 
 123     class popFrameCls extends Thread {
 124         private volatile boolean flag = true;
 125 
 126         popFrameCls(String name) {
 127             super(name);
 128         }
 129 
 130         public void run() {
 131             activeMethod();
 132             out.println("popFrameCls (" + this + "): exiting...");


 133         }
 134 
 135         public void activeMethod() {
 136             boolean compl = true; // complain in a finally block
 137 
 138             if (popframe001.popFdone) { // popping has been done
 139                 out.println("popFrameCls (" + this + "): enter activeMethod() after popping");


 140                 return;
 141             }
 142             try {
 143                 // notify the main thread
 144                 synchronized (popframe001.barrier) {
 145                     out.println("popFrameCls (" + this + "): notifying main thread");


 146                     popframe001.startingBarrier.unlock();
 147                     out.println("popFrameCls (" + this + "): inside activeMethod()");


 148                 }
 149                 // loop until the main thread pops us
 150                 int i = 0;
 151                 int n = 1000;
 152                 while (flag) {
 153                     if (n <= 0) {
 154                         n = 1000;
 155                     }
 156                     if (i > n) {
 157                         i = 0;
 158                         n--;
 159                     }
 160                     i++;
 161                 }
 162                 if (popframe001.popFdone) { // popping has been done
 163                     out.println("TEST FAILED: a tested frame has not been really popped");
 164                     popframe001.totRes = FAILED;
 165                     compl = false;
 166                 }
 167             } catch (Exception e) {
< prev index next >