author | jcbeyler |
Thu, 27 Sep 2018 15:56:40 -0700 | |
changeset 51941 | 0f7d0bb6cfe2 |
parent 51634 | 3f189f451ff1 |
permissions | -rw-r--r-- |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
1 |
/* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
4 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
8 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
14 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
18 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
23 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
24 |
#include <stdio.h> |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
25 |
#include <string.h> |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
26 |
#include <jvmti.h> |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
27 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
28 |
#include "jni_tools.h" |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
29 |
#include "nsk_tools.h" |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
30 |
#include "JVMTITools.h" |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
31 |
#include "jvmti_tools.h" |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
32 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
33 |
extern "C" { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
34 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
35 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
36 |
static jvmtiEnv *test_jvmti = NULL; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
37 |
static jvmtiCapabilities caps; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
38 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
39 |
/* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
40 |
* Redefine a class with a new version (class file in byte array). |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
41 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
42 |
* native static public boolean redefineClassIntl(Class<?> clz, byte[] classFile); |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
43 |
* |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
44 |
* @param clz class for redefinition |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
45 |
* @param classFile new version as a byte array |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
46 |
* @return false if any errors occurred during class redefinition |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
47 |
*/ |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
48 |
JNIEXPORT jboolean JNICALL |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
49 |
Java_vm_runtime_defmeth_shared_Util_redefineClassIntl(JNIEnv *env, jclass clazz, jclass clazzToRedefine, jbyteArray bytecodeArray) { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
50 |
jvmtiClassDefinition classDef; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
51 |
jboolean result = JNI_TRUE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
52 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
53 |
if (!NSK_VERIFY(env != NULL) || !NSK_VERIFY(clazzToRedefine != NULL) || !NSK_VERIFY(bytecodeArray != NULL)) { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
54 |
return JNI_FALSE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
55 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
56 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
57 |
classDef.klass = clazzToRedefine; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
58 |
if (!NSK_JNI_VERIFY(env, |
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
59 |
(classDef.class_byte_count = /* jsize */ env->GetArrayLength(bytecodeArray)) > 0)) { |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
60 |
return JNI_FALSE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
61 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
62 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
63 |
if (!NSK_JNI_VERIFY(env, |
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
64 |
(classDef.class_bytes = (const unsigned char *) /* jbyte* */ env->GetByteArrayElements(bytecodeArray, NULL)) != NULL)) { |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
65 |
return JNI_FALSE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
66 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
67 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
68 |
if (!NSK_JVMTI_VERIFY( |
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
69 |
test_jvmti->RedefineClasses(1, &classDef))) { |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
70 |
result = JNI_FALSE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
71 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
72 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
73 |
// Need to cleanup reference to byte[] whether RedefineClasses succeeded or not |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
74 |
if (!NSK_JNI_VERIFY_VOID(env, |
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
75 |
env->ReleaseByteArrayElements(bytecodeArray, (jbyte*)classDef.class_bytes, JNI_ABORT))) { |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
76 |
return JNI_FALSE; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
77 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
78 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
79 |
return result; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
80 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
81 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
82 |
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
83 |
/* init framework and parse options */ |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
84 |
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
85 |
return JNI_ERR; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
86 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
87 |
/* create JVMTI environment */ |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
88 |
if (!NSK_VERIFY((test_jvmti = |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
89 |
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
90 |
return JNI_ERR; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
91 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
92 |
memset(&caps, 0, sizeof(jvmtiCapabilities)); |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
93 |
caps.can_redefine_classes = 1; |
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
94 |
if (!NSK_JVMTI_VERIFY(test_jvmti->AddCapabilities(&caps))) |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
95 |
return JNI_ERR; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
96 |
|
51941
0f7d0bb6cfe2
8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents:
51634
diff
changeset
|
97 |
if (!NSK_JVMTI_VERIFY(test_jvmti->GetCapabilities(&caps))) |
50243
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
98 |
return JNI_ERR; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
99 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
100 |
if (!caps.can_redefine_classes) |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
101 |
printf("Warning: RedefineClasses is not implemented\n"); |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
102 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
103 |
return JNI_OK; |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
104 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
105 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
106 |
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
107 |
return Agent_Initialize(jvm, options, reserved); |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
108 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
109 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
110 |
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *jvm, char *options, void *reserved) { |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
111 |
return Agent_Initialize(jvm, options, reserved); |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
112 |
} |
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
113 |
|
4fac3c99487d
8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff
changeset
|
114 |
} |