1 /*
2  * Copyright (c) 2004, 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.scenarios.allocation.AP06;
25 
26 import java.io.*;
27 import java.lang.reflect.*;
28 
29 import nsk.share.*;
30 import nsk.share.jvmti.*;
31 
32 public class ap06t001 extends DebugeeClass {
33     /* number of interations to provoke garbage collecting */
34     final static int GC_TRIES = 1;
35 
main(String[] argv)36     public static void main(String[] argv) {
37         argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
38 
39         // produce JCK-like exit status
40         System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
41     }
42 
run(String argv[], PrintStream out)43     public static int run(String argv[], PrintStream out) {
44         return new ap06t001().runThis(argv, out);
45     }
46 
47     static Wicket startWicket = new Wicket();
48     static Wicket endWicket = new Wicket();
49     private static ap06t001Thread thread = null;
50 
51     /* scaffold objects */
52     static ArgumentHandler argHandler = null;
53     static Log log = null;
54     static long timeout = 0;
55     int status = Consts.TEST_PASSED;
56 
runThis(String argv[], PrintStream out)57     private int runThis(String argv[], PrintStream out) {
58         argHandler = new ArgumentHandler(argv);
59         log = new Log(out, argHandler);
60         timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
61 
62         thread = new ap06t001Thread();
63         thread.setTag();
64         thread.start();
65         startWicket.waitFor();
66 
67         status = checkStatus(status);
68 
69         endWicket.unlock();
70         if (thread.isAlive()) {
71             try {
72                 thread.join(timeout);
73             } catch (InterruptedException e) {
74                 // OK
75             }
76         }
77         return status;
78     }
79 }
80 
81 class ap06t001Thread extends Thread {
run()82     public void run() {
83         ap06t001.log.display("Checked thread started.");
84         ap06t001.startWicket.unlock();
85 
86         ap06t001.endWicket.waitFor(ap06t001.timeout);
87     }
88 
setTag()89     public native void setTag();
90 }
91