1 /*
2  * Copyright (c) 2003, 2018, 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 package nsk.jvmti.NotifyFramePop;
25 
26 import java.io.PrintStream;
27 
28 public class nframepop001 {
29 
30     final static int JCK_STATUS_BASE = 95;
31 
32     static {
33         try {
34             System.loadLibrary("nframepop001");
35         } catch (UnsatisfiedLinkError ule) {
36             System.err.println("Could not load nframepop001 library");
37             System.err.println("java.library.path:"
38                 + System.getProperty("java.library.path"));
39             throw ule;
40         }
41     }
42 
getMethIds()43     native static void getMethIds();
setFramePopNotif(Thread thr)44     native static void setFramePopNotif(Thread thr);
checkFrame(int point)45     native static void checkFrame(int point);
getRes()46     native static int getRes();
47 
48     static int fld = 0;
49     static Object start_lock = new Object();
50     static Object wait_lock = new Object();
51 
main(String args[])52     public static void main(String args[]) {
53         args = nsk.share.jvmti.JVMTITest.commonInit(args);
54 
55         // produce JCK-like exit status.
56         System.exit(run(args, System.out) + JCK_STATUS_BASE);
57     }
58 
run(String argv[], PrintStream ref)59     public static int run(String argv[], PrintStream ref) {
60         nframepop001 t = new nframepop001();
61         nframepop001a thr = new nframepop001a();
62         getMethIds();
63 
64         t.meth01(2001);
65         checkFrame(1);
66 
67         try {
68             t.meth02(2002);
69         } catch (Throwable e) {}
70         checkFrame(2);
71 
72         synchronized (wait_lock) {
73             synchronized (start_lock) {
74                 thr.start();
75                 try {
76                     start_lock.wait();
77                 } catch (InterruptedException e) {
78                     throw new Error("Unexpected: " + e);
79                 }
80             }
81             setFramePopNotif(thr);
82         }
83 
84         try {
85             thr.join();
86         } catch (InterruptedException e) {
87             throw new Error("Unexpected: " + e);
88         }
89         checkFrame(3);
90 
91         return getRes();
92     }
93 
meth01(int i)94     public void meth01(int i) {
95         try {
96             if (i > 0) {
97                 throw new Throwable();
98             }
99         } catch (Throwable e) {}
100     }
101 
meth02(int i)102     public void meth02(int i) throws Throwable {
103         try {
104             if (i > 0) {
105                 throw new Throwable();
106             }
107         } catch (Throwable e) {
108             throw e;
109         }
110     }
111 }
112 
113 class nframepop001a extends Thread {
run()114     public void run() {
115         int local = 2003;
116         synchronized (nframepop001.start_lock) {
117             nframepop001.start_lock.notify();
118         }
119         synchronized (nframepop001.wait_lock) {
120             nframepop001.fld = local;
121         }
122     }
123 }
124