1 /*
2 * Copyright (c) 2003, 2017, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <jni.h>
27
28 #include "JPLISAgent.h"
29 #include "JPLISAssert.h"
30 #include "Utilities.h"
31 #include "JavaExceptions.h"
32 #include "FileSystemSupport.h" /* For uintptr_t */
33 #include "sun_instrument_InstrumentationImpl.h"
34
35 /*
36 * Copyright 2003 Wily Technology, Inc.
37 */
38
39 /**
40 * This module contains the native method implementations to back the
41 * sun.instrument.InstrumentationImpl class.
42 * The bridge between Java and native code is built by storing a native
43 * pointer to the JPLISAgent data structure in a 64 bit scalar field
44 * in the InstrumentationImpl instance which is passed to each method.
45 */
46
47
48 /*
49 * Native methods
50 */
51
52 /*
53 * Declare library specific JNI_Onload entry if static build
54 */
55 DEF_STATIC_JNI_OnLoad
56
57 /*
58 * Class: sun_instrument_InstrumentationImpl
59 * Method: isModifiableClass0
60 * Signature: (Ljava/lang/Class;)Z
61 */
62 JNIEXPORT jboolean JNICALL
Java_sun_instrument_InstrumentationImpl_isModifiableClass0(JNIEnv * jnienv,jobject implThis,jlong agent,jclass clazz)63 Java_sun_instrument_InstrumentationImpl_isModifiableClass0
64 (JNIEnv * jnienv, jobject implThis, jlong agent, jclass clazz) {
65 return isModifiableClass(jnienv, (JPLISAgent*)(intptr_t)agent, clazz);
66 }
67
68 /*
69 * Class: sun_instrument_InstrumentationImpl
70 * Method: isRetransformClassesSupported0
71 * Signature: ()Z
72 */
73 JNIEXPORT jboolean JNICALL
Java_sun_instrument_InstrumentationImpl_isRetransformClassesSupported0(JNIEnv * jnienv,jobject implThis,jlong agent)74 Java_sun_instrument_InstrumentationImpl_isRetransformClassesSupported0
75 (JNIEnv * jnienv, jobject implThis, jlong agent) {
76 return isRetransformClassesSupported(jnienv, (JPLISAgent*)(intptr_t)agent);
77 }
78
79 /*
80 * Class: sun_instrument_InstrumentationImpl
81 * Method: setHasTransformers
82 * Signature: (Z)V
83 */
84 JNIEXPORT void JNICALL
Java_sun_instrument_InstrumentationImpl_setHasTransformers(JNIEnv * jnienv,jobject implThis,jlong agent,jboolean has)85 Java_sun_instrument_InstrumentationImpl_setHasTransformers
86 (JNIEnv * jnienv, jobject implThis, jlong agent, jboolean has) {
87 setHasTransformers(jnienv, (JPLISAgent*)(intptr_t)agent, has);
88 }
89
90 /*
91 * Class: sun_instrument_InstrumentationImpl
92 * Method: setHasRetransformableTransformers
93 * Signature: (Z)V
94 */
95 JNIEXPORT void JNICALL
Java_sun_instrument_InstrumentationImpl_setHasRetransformableTransformers(JNIEnv * jnienv,jobject implThis,jlong agent,jboolean has)96 Java_sun_instrument_InstrumentationImpl_setHasRetransformableTransformers
97 (JNIEnv * jnienv, jobject implThis, jlong agent, jboolean has) {
98 setHasRetransformableTransformers(jnienv, (JPLISAgent*)(intptr_t)agent, has);
99 }
100
101 /*
102 * Class: sun_instrument_InstrumentationImpl
103 * Method: retransformClasses0
104 * Signature: ([Ljava/lang/Class;)V
105 */
106 JNIEXPORT void JNICALL
Java_sun_instrument_InstrumentationImpl_retransformClasses0(JNIEnv * jnienv,jobject implThis,jlong agent,jobjectArray classes)107 Java_sun_instrument_InstrumentationImpl_retransformClasses0
108 (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classes) {
109 retransformClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classes);
110 }
111
112 /*
113 * Class: sun_instrument_InstrumentationImpl
114 * Method: redefineClasses0
115 * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
116 */
Java_sun_instrument_InstrumentationImpl_redefineClasses0(JNIEnv * jnienv,jobject implThis,jlong agent,jobjectArray classDefinitions)117 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_redefineClasses0
118 (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classDefinitions) {
119 redefineClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classDefinitions);
120 }
121
122 /*
123 * Class: sun_instrument_InstrumentationImpl
124 * Method: getAllLoadedClasses0
125 * Signature: ()[Ljava/lang/Class;
126 */
Java_sun_instrument_InstrumentationImpl_getAllLoadedClasses0(JNIEnv * jnienv,jobject implThis,jlong agent)127 JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getAllLoadedClasses0
128 (JNIEnv * jnienv, jobject implThis, jlong agent) {
129 return getAllLoadedClasses(jnienv, (JPLISAgent*)(intptr_t)agent);
130 }
131
132 /*
133 * Class: sun_instrument_InstrumentationImpl
134 * Method: getInitiatedClasses0
135 * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
136 */
Java_sun_instrument_InstrumentationImpl_getInitiatedClasses0(JNIEnv * jnienv,jobject implThis,jlong agent,jobject classLoader)137 JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getInitiatedClasses0
138 (JNIEnv * jnienv, jobject implThis, jlong agent, jobject classLoader) {
139 return getInitiatedClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classLoader);
140 }
141
142 /*
143 * Class: sun_instrument_InstrumentationImpl
144 * Method: getObjectSize0
145 * Signature: (Ljava/lang/Object;)J
146 */
Java_sun_instrument_InstrumentationImpl_getObjectSize0(JNIEnv * jnienv,jobject implThis,jlong agent,jobject objectToSize)147 JNIEXPORT jlong JNICALL Java_sun_instrument_InstrumentationImpl_getObjectSize0
148 (JNIEnv * jnienv, jobject implThis, jlong agent, jobject objectToSize) {
149 return getObjectSize(jnienv, (JPLISAgent*)(intptr_t)agent, objectToSize);
150 }
151
152
153 /*
154 * Class: sun_instrument_InstrumentationImpl
155 * Method: appendToClassLoaderSearch0
156 * Signature: (Ljava/lang/String;Z)V
157 */
Java_sun_instrument_InstrumentationImpl_appendToClassLoaderSearch0(JNIEnv * jnienv,jobject implThis,jlong agent,jstring jarFile,jboolean isBootLoader)158 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_appendToClassLoaderSearch0
159 (JNIEnv * jnienv, jobject implThis, jlong agent, jstring jarFile, jboolean isBootLoader) {
160 appendToClassLoaderSearch(jnienv, (JPLISAgent*)(intptr_t)agent, jarFile, isBootLoader);
161 }
162
163
164 /*
165 * Class: sun_instrument_InstrumentationImpl
166 * Method: setNativeMethodPrefixes
167 * Signature: ([Ljava/lang/String;Z)V
168 */
Java_sun_instrument_InstrumentationImpl_setNativeMethodPrefixes(JNIEnv * jnienv,jobject implThis,jlong agent,jobjectArray prefixArray,jboolean isRetransformable)169 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_setNativeMethodPrefixes
170 (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray prefixArray, jboolean isRetransformable) {
171 setNativeMethodPrefixes(jnienv, (JPLISAgent*)(intptr_t)agent, prefixArray, isRetransformable);
172 }
173
174
175 /*
176 * Class: sun_instrument_InstrumentationImpl
177 * Method: loadAgent0
178 */
Java_sun_instrument_InstrumentationImpl_loadAgent0(JNIEnv * env,jclass clazz,jstring jarfile)179 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_loadAgent0
180 (JNIEnv* env, jclass clazz, jstring jarfile)
181 {
182 extern jint loadAgent(JNIEnv* env, jstring path);
183 if (loadAgent(env, jarfile) != JNI_OK) {
184 if (!(*env)->ExceptionCheck(env)) {
185 createAndThrowInternalError(env);
186 }
187 }
188 }
189
190