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 #include <stdlib.h> 25 #include <string.h> 26 #include "jni_tools.h" 27 #include "agent_common.h" 28 #include "jvmti_tools.h" 29 30 extern "C" { 31 32 /* ========================================================================== */ 33 34 /* scaffold objects */ 35 static jlong timeout = 0; 36 37 /* test objects */ 38 static jrawMonitorID access_lock; 39 static jvmtiPhase phase; 40 static const char* setVerboseMode = NULL; 41 42 /* ========================================================================== */ 43 44 /* agent library initialization */ 45 #ifdef STATIC_BUILD 46 JNIEXPORT jint JNICALL Agent_OnLoad_gf08t002(JavaVM *jvm, char *options, void *reserved) { 47 return Agent_Initialize(jvm, options, reserved); 48 } 49 JNIEXPORT jint JNICALL Agent_OnAttach_gf08t002(JavaVM *jvm, char *options, void *reserved) { 50 return Agent_Initialize(jvm, options, reserved); 51 } 52 JNIEXPORT jint JNI_OnLoad_gf08t002(JavaVM *jvm, char *options, void *reserved) { 53 return JNI_VERSION_1_8; 54 } 55 #endif 56 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { 57 jvmtiEnv *jvmti = NULL; 58 59 /* init framework and parse options */ 60 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) 61 return JNI_ERR; 62 63 timeout = nsk_jvmti_getWaitTime() * 60000; 64 65 /* create JVMTI environment */ 66 if (!NSK_VERIFY((jvmti = 67 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) 68 return JNI_ERR; 69 70 setVerboseMode = nsk_jvmti_findOptionStringValue("setVerboseMode", NULL); 71 72 if (strcmp(setVerboseMode, "y") == 0 || strcmp(setVerboseMode, "yes") == 0) { 73 if (!NSK_JVMTI_VERIFY(jvmti->SetVerboseFlag(JVMTI_VERBOSE_CLASS, JNI_TRUE))) { 74 return JNI_ERR; 75 } else { 76 NSK_DISPLAY0("JVMTI_VERBOSE_CLASS mode has been set.\n"); 77 } 78 } 79 80 return JNI_OK; 81 } 82 83 /* ========================================================================== */ 84 85 }