|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 <stdio.h> |
| 25 | +#include <stdlib.h> |
| 26 | + |
| 27 | +#include "jni.h" |
| 28 | + |
| 29 | +static const char* jni_error_code(int ret) { |
| 30 | + switch(ret) { |
| 31 | + case JNI_OK: return "JNI_OK"; |
| 32 | + case JNI_ERR: return "JNI_ERR"; |
| 33 | + case JNI_EDETACHED: return "JNI_EDETACHED"; |
| 34 | + case JNI_EVERSION: return "JNI_EVERSION"; |
| 35 | + case JNI_ENOMEM: return "JNI_ENOMEM"; |
| 36 | + case JNI_EEXIST: return "JNI_EEXIST"; |
| 37 | + case JNI_EINVAL: return "JNI_EINVAL"; |
| 38 | + default: return "Invalid JNI error code"; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +JNIEXPORT jboolean JNICALL |
| 43 | +Java_TestActiveDestroy_tryDestroyJavaVM(JNIEnv *env, jclass cls) { |
| 44 | + JavaVM* jvm; |
| 45 | + int res = (*env)->GetJavaVM(env, &jvm); |
| 46 | + if (res != JNI_OK) { |
| 47 | + fprintf(stderr, "GetJavaVM failed: %s\n", jni_error_code(res)); |
| 48 | + exit(1); |
| 49 | + } |
| 50 | + printf("Calling DestroyJavaVM from active thread\n"); |
| 51 | + res = (*jvm)->DestroyJavaVM(jvm); |
| 52 | + printf("DestroyJavaVM returned: %s\n", jni_error_code(res)); |
| 53 | + return res == JNI_OK; |
| 54 | +} |
0 commit comments