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.scenarios.jni_interception.JI05;
25 
26 import java.io.*;
27 import java.util.*;
28 import nsk.share.*;
29 
30 /**
31  * The test exercises the JVMTI target area "JNI Function Interception".
32  * It implements the following scenario:<br>
33  * <code>Let agent A of first JVMTI environment redirects a JNI function,
34  * then agent B of second JVMTI environment redirects the same
35  * function. Check that last redirection takes effect in agent A.</code>
36  * <p>
37  * The test works as follows. On phase JVM_OnLoad event VMInit is
38  * enabled. Upon receiving the event, two separate agent threads are
39  * started, each of them with its own JVMTI environment. The agent A
40  * running in one JVMTI environment redirects the JNI function
41  * GetVersion(). Then that redirection is checked in the agent B
42  * running in another JVMTI environment, and vise versa for redirection
43  * made by the agent B.
44  */
45 public class ji05t001 {
46     static {
47         try {
48             System.loadLibrary("ji05t001");
49         } catch (UnsatisfiedLinkError ule) {
50             System.err.println("Could not load \"ji05t001\" library");
51             System.err.println("java.library.path:"
52                 + System.getProperty("java.library.path"));
53             throw ule;
54         }
55     }
56 
getResult()57     native int getResult();
58 
main(String args[])59     public static void main(String args[]) {
60         args = nsk.share.jvmti.JVMTITest.commonInit(args);
61 
62         // produce JCK-like exit status.
63         System.exit(run(args, System.out) + Consts.JCK_STATUS_BASE);
64     }
65 
run(String args[], PrintStream out)66     public static int run(String args[], PrintStream out) {
67         return new ji05t001().runIt(args, out);
68     }
69 
runIt(String args[], PrintStream out)70     private int runIt(String args[], PrintStream out) {
71         return getResult();
72     }
73 }
74