author | ppunegov |
Tue, 20 Oct 2015 21:12:25 +0300 | |
changeset 33453 | b62df32d4af8 |
parent 30355 | e37c7eba132f |
child 33653 | c1ee09fe3274 |
permissions | -rw-r--r-- |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
1 |
/* |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
4 |
* |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
10 |
* |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
15 |
* accompanied this code). |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
16 |
* |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
20 |
* |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
23 |
* questions. |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
24 |
*/ |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
25 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
26 |
#include <stdio.h> |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
27 |
#include <jni.h> |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
28 |
#include "jvm.h" |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
29 |
#include "management_ext.h" |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
30 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
31 |
#define ERR_MSG_SIZE 128 |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
32 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
33 |
const JmmInterface* jmm_interface = NULL; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
34 |
JavaVM* jvm = NULL; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
35 |
jint jmm_version = 0; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
36 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
37 |
JNIEXPORT jint JNICALL |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
38 |
JNI_OnLoad(JavaVM *vm, void *reserved) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
39 |
JNIEnv* env; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
40 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
41 |
jvm = vm; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
42 |
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_2) != JNI_OK) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
43 |
return JNI_ERR; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
44 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
45 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
46 |
jmm_interface = (JmmInterface*) JVM_GetManagement(JMM_VERSION_1_0); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
47 |
if (jmm_interface == NULL) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
48 |
JNU_ThrowInternalError(env, "Unsupported Management version"); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
49 |
return JNI_ERR; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
50 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
51 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
52 |
jmm_version = jmm_interface->GetVersion(env); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
53 |
return (*env)->GetVersion(env); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
54 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
55 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
56 |
void throw_internal_error(JNIEnv* env, const char* msg) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
57 |
char errmsg[128]; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
58 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
59 |
sprintf(errmsg, "errno: %d error: %s\n", errno, msg); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
60 |
JNU_ThrowInternalError(env, errmsg); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff
changeset
|
61 |
} |