1 /*
2 * Copyright (c) 1998, 2014, 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
177 for (i = 0; i < nof_compatible_versions; ++i) {
178 version_type runtime = compatible_versions_list[i].runtime;
179 version_type comptime = compatible_versions_list[i].compiletime;
180
181 if ((major_runtime == runtime.major || runtime.major == -1) &&
182 (minor_runtime == runtime.minor || runtime.minor == -1) &&
183 (major_compiletime == comptime.major || comptime.major == -1) &&
184 (minor_compiletime == comptime.minor || comptime.minor == -1)) {
185 return JNI_TRUE;
186 }
187 }
188
189 return major_runtime == major_compiletime &&
190 minor_runtime >= minor_compiletime;
191 }
192
193 /* OnLoad startup:
194 * Returning JNI_ERR will cause the java_g VM to core dump, be careful.
195 */
196 JNIEXPORT jint JNICALL
197 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
198 {
199 jvmtiError error;
200 jvmtiCapabilities needed_capabilities;
201 jvmtiCapabilities potential_capabilities;
202 jint jvmtiCompileTimeMajorVersion;
203 jint jvmtiCompileTimeMinorVersion;
204 jint jvmtiCompileTimeMicroVersion;
205
206 /* See if it's already loaded */
207 if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
208 ERROR_MESSAGE(("Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options."));
209 return JNI_ERR;
210 }
211
212 /* If gdata is defined and the VM died, why are we here? */
213 if ( gdata!=NULL && gdata->vmDead ) {
214 ERROR_MESSAGE(("JDWP unable to load, VM died"));
215 return JNI_ERR;
216 }
217
363 }
364
365 /* Set callbacks just for 3 functions */
366 (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
367 gdata->callbacks.VMInit = &cbEarlyVMInit;
368 gdata->callbacks.VMDeath = &cbEarlyVMDeath;
369 gdata->callbacks.Exception = &cbEarlyException;
370 error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
371 (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
372 if (error != JVMTI_ERROR_NONE) {
373 ERROR_MESSAGE(("JDWP unable to set JVMTI event callbacks: %s(%d)",
374 jvmtiErrorText(error), error));
375 return JNI_ERR;
376 }
377
378 LOG_MISC(("OnLoad: DONE"));
379 return JNI_OK;
380 }
381
382 JNIEXPORT void JNICALL
383 Agent_OnUnload(JavaVM *vm)
384 {
385
386 gdata->isLoaded = JNI_FALSE;
387
388 /* Cleanup, but make sure VM is alive before using JNI, and
389 * make sure JVMTI environment is ok before deallocating
390 * memory allocated through JVMTI, which all of it is.
391 */
392
393 /*
394 * Close transport before exit
395 */
396 if (transport_is_open()) {
397 transport_close();
398 }
399 }
400
401 /*
402 * Phase 2: Initial events. Phase 2 consists of waiting for the
403 * event that triggers full initialization. Under normal circumstances
|
1 /*
2 * Copyright (c) 1998, 2015, 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
177 for (i = 0; i < nof_compatible_versions; ++i) {
178 version_type runtime = compatible_versions_list[i].runtime;
179 version_type comptime = compatible_versions_list[i].compiletime;
180
181 if ((major_runtime == runtime.major || runtime.major == -1) &&
182 (minor_runtime == runtime.minor || runtime.minor == -1) &&
183 (major_compiletime == comptime.major || comptime.major == -1) &&
184 (minor_compiletime == comptime.minor || comptime.minor == -1)) {
185 return JNI_TRUE;
186 }
187 }
188
189 return major_runtime == major_compiletime &&
190 minor_runtime >= minor_compiletime;
191 }
192
193 /* OnLoad startup:
194 * Returning JNI_ERR will cause the java_g VM to core dump, be careful.
195 */
196 JNIEXPORT jint JNICALL
197 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
198 {
199 jvmtiError error;
200 jvmtiCapabilities needed_capabilities;
201 jvmtiCapabilities potential_capabilities;
202 jint jvmtiCompileTimeMajorVersion;
203 jint jvmtiCompileTimeMinorVersion;
204 jint jvmtiCompileTimeMicroVersion;
205
206 /* See if it's already loaded */
207 if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
208 ERROR_MESSAGE(("Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options."));
209 return JNI_ERR;
210 }
211
212 /* If gdata is defined and the VM died, why are we here? */
213 if ( gdata!=NULL && gdata->vmDead ) {
214 ERROR_MESSAGE(("JDWP unable to load, VM died"));
215 return JNI_ERR;
216 }
217
363 }
364
365 /* Set callbacks just for 3 functions */
366 (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
367 gdata->callbacks.VMInit = &cbEarlyVMInit;
368 gdata->callbacks.VMDeath = &cbEarlyVMDeath;
369 gdata->callbacks.Exception = &cbEarlyException;
370 error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
371 (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
372 if (error != JVMTI_ERROR_NONE) {
373 ERROR_MESSAGE(("JDWP unable to set JVMTI event callbacks: %s(%d)",
374 jvmtiErrorText(error), error));
375 return JNI_ERR;
376 }
377
378 LOG_MISC(("OnLoad: DONE"));
379 return JNI_OK;
380 }
381
382 JNIEXPORT void JNICALL
383 DEF_Agent_OnUnload(JavaVM *vm)
384 {
385
386 gdata->isLoaded = JNI_FALSE;
387
388 /* Cleanup, but make sure VM is alive before using JNI, and
389 * make sure JVMTI environment is ok before deallocating
390 * memory allocated through JVMTI, which all of it is.
391 */
392
393 /*
394 * Close transport before exit
395 */
396 if (transport_is_open()) {
397 transport_close();
398 }
399 }
400
401 /*
402 * Phase 2: Initial events. Phase 2 consists of waiting for the
403 * event that triggers full initialization. Under normal circumstances
|