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 #include <stdio.h>
25 #include <string.h>
26 #include "jvmti.h"
27 #include "agent_common.h"
28 #include "JVMTITools.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #ifndef JNI_ENV_ARG
35
36 #ifdef __cplusplus
37 #define JNI_ENV_ARG(x, y) y
38 #define JNI_ENV_PTR(x) x
39 #else
40 #define JNI_ENV_ARG(x,y) x, y
41 #define JNI_ENV_PTR(x) (*x)
42 #endif
43
44 #endif
45
46 #define PASSED 0
47 #define STATUS_FAILED 2
48
49 static jvmtiEnv *jvmti = NULL;
50 static jint result = PASSED;
51 static jboolean printdump = JNI_FALSE;
52
53 #ifdef STATIC_BUILD
54 JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
55 return Agent_Initialize(jvm, options, reserved);
56 }
57 JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
58 return Agent_Initialize(jvm, options, reserved);
59 }
60 JNIEXPORT jint JNI_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
61 return JNI_VERSION_1_8;
62 }
63 #endif
64 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
65 jint res;
66
67 if (options != NULL && strcmp(options, "printdump") == 0) {
68 printdump = JNI_TRUE;
69 }
70
71 res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
72 JVMTI_VERSION_1_1);
73 if (res != JNI_OK || jvmti == NULL) {
74 printf("Wrong result of a valid call to GetEnv!\n");
75 return JNI_ERR;
76 }
77
78 return JNI_OK;
79 }
80
81 JNIEXPORT jint JNICALL
82 Java_nsk_jvmti_unit_clsldrclss00x_check(JNIEnv *env, jclass appCls, jclass objCls) {
83 jvmtiError err;
84 jobject appClassloader;
85 jobject objClassloader;
86 jclass *classes;
87 jint classCount;
88 jboolean found;
89 jint i;
90
91 if (jvmti == NULL) {
92 printf("JVMTI client was not properly loaded!\n");
171 if ( env->IsSameObject(k, objCls) ) {
172 if (printdump) {
173 printf(">>> found Object class in bootstrap class loader\n");
174 }
175 found = JNI_TRUE;
176 break;
177 }
178 }
179 if (!found) {
180 printf("Error: didn't find Object class in bootstrap class loader\n");
181 result = STATUS_FAILED;
182 }
183
184 if (printdump) {
185 printf(">>> ... done\n");
186 }
187
188 return result;
189 }
190
191 #ifdef __cplusplus
192 }
193 #endif
|
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 #include <stdio.h>
25 #include <string.h>
26 #include "jvmti.h"
27 #include "agent_common.h"
28 #include "JVMTITools.h"
29
30 extern "C" {
31
32
33 #define PASSED 0
34 #define STATUS_FAILED 2
35
36 static jvmtiEnv *jvmti = NULL;
37 static jint result = PASSED;
38 static jboolean printdump = JNI_FALSE;
39
40 #ifdef STATIC_BUILD
41 JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
42 return Agent_Initialize(jvm, options, reserved);
43 }
44 JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
45 return Agent_Initialize(jvm, options, reserved);
46 }
47 JNIEXPORT jint JNI_OnLoad_clsldrclss00x(JavaVM *jvm, char *options, void *reserved) {
48 return JNI_VERSION_1_8;
49 }
50 #endif
51 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
52 jint res;
53
54 if (options != NULL && strcmp(options, "printdump") == 0) {
55 printdump = JNI_TRUE;
56 }
57
58 res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
59 if (res != JNI_OK || jvmti == NULL) {
60 printf("Wrong result of a valid call to GetEnv!\n");
61 return JNI_ERR;
62 }
63
64 return JNI_OK;
65 }
66
67 JNIEXPORT jint JNICALL
68 Java_nsk_jvmti_unit_clsldrclss00x_check(JNIEnv *env, jclass appCls, jclass objCls) {
69 jvmtiError err;
70 jobject appClassloader;
71 jobject objClassloader;
72 jclass *classes;
73 jint classCount;
74 jboolean found;
75 jint i;
76
77 if (jvmti == NULL) {
78 printf("JVMTI client was not properly loaded!\n");
157 if ( env->IsSameObject(k, objCls) ) {
158 if (printdump) {
159 printf(">>> found Object class in bootstrap class loader\n");
160 }
161 found = JNI_TRUE;
162 break;
163 }
164 }
165 if (!found) {
166 printf("Error: didn't find Object class in bootstrap class loader\n");
167 result = STATUS_FAILED;
168 }
169
170 if (printdump) {
171 printf(">>> ... done\n");
172 }
173
174 return result;
175 }
176
177 }
|