Skip to content
Permalink
Browse files

8234608: [TESTBUG] Fix G1 redefineClasses tests and a memory leak

Co-authored-by: Ian Rogers <irogers@google.com>
Co-authored-by: Thomas Schatzl <thomas.schatzl@oracle.com>
Reviewed-by: tschatzl, sjohanss
  • Loading branch information
3 people committed Feb 13, 2020
1 parent 683a5b1 commit f844943273f094d925dcb02bdc43d07c0ad9ae98
@@ -69,7 +69,8 @@ s loaded by null classloader.
This behavior can be adjusted with "-compilationLevel" and "-compilationNumber" options. First
one has self-explaining name, latter sets number of optimization/deoptimozation of each class.
- Next aspect is class redefinition.
You can enable classes redefinition with "-redefineClasses" flag.
You can enable classes redefinition with "-redefineClasses" flag. Valid options are "true" and
"false".

Test implementation details:
Test supposed to be ran with G1 gc and -XX:+ExplicitGCProvokesConcurrent option. In the end of exec
@@ -48,6 +48,8 @@ JNIEXPORT jclass JNICALL Java_gc_g1_unloading_classloaders_JNIClassloader_loadTh
jbyte * arrayContent = env->GetByteArrayElements(bytecode, NULL);
jsize bytecodeLength = env->GetArrayLength(bytecode);
jclass returnValue = env->DefineClass(classNameChar, classLoader, arrayContent, bytecodeLength);
env->ReleaseByteArrayElements(bytecode, arrayContent, JNI_ABORT);
env->ReleaseStringUTFChars(className, classNameChar);
if (!returnValue) {
printf("ERROR: DefineClass call returned NULL by some reason. Classloading failed.\n");
}
@@ -56,12 +58,12 @@ JNIEXPORT jclass JNICALL Java_gc_g1_unloading_classloaders_JNIClassloader_loadTh
}

/*
* Class: gc_g1_unloading_unloading_loading_ClassLoadingThread
* Class: gc_g1_unloading_unloading_loading_ClassLoadingHelper
* Method: makeRedefinition0
* Signature: (ILjava/lang/Class;[B)I
*/
JNIEXPORT jint JNICALL Java_gc_g1_unloading_loading_ClassLoadingThread_makeRedefinition0(JNIEnv *env,
jclass cls, jint fl, jclass redefCls, jbyteArray classBytes) {
JNIEXPORT jint JNICALL Java_gc_g1_unloading_loading_ClassLoadingHelper_makeRedefinition0(JNIEnv *env,
jclass clazz, jint fl, jclass redefCls, jbyteArray classBytes) {
JavaVM * jvm;
jvmtiEnv * jvmti;
jvmtiError err;
@@ -99,15 +101,15 @@ JNIEXPORT jint JNICALL Java_gc_g1_unloading_loading_ClassLoadingThread_makeRede
classDef.klass = redefCls;
classDef.class_byte_count =
env->GetArrayLength(classBytes);
classDef.class_bytes = (unsigned char *)
env->GetByteArrayElements(classBytes,
NULL);
jbyte * class_bytes = env->GetByteArrayElements(classBytes, NULL);
classDef.class_bytes = (unsigned char *)class_bytes;

if (fl == 2) {
printf(">>>>>>>> Invoke RedefineClasses():\n");
printf("\tnew class byte count=%d\n", classDef.class_byte_count);
}
err = jvmti->RedefineClasses(1, &classDef);
env->ReleaseByteArrayElements(classBytes, class_bytes, JNI_ABORT);
if (err != JVMTI_ERROR_NONE) {
printf("%s: Failed to call RedefineClasses():\n", __FILE__);
printf("\tthe function returned error %d\n", err);
@@ -53,8 +53,8 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -inMemoryCompilation
* -redefineClasses true
* -inMemoryCompilation true
* -keep classloader
* -numberOfChecksLimit 4
* -stressTime 180
@@ -53,8 +53,8 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -inMemoryCompilation
* -redefineClasses true
* -inMemoryCompilation true
* -keep class
* -numberOfChecksLimit 4
* -stressTime 180
@@ -53,8 +53,8 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -inMemoryCompilation
* -redefineClasses true
* -inMemoryCompilation true
* -keep object
* -numberOfChecksLimit 4
* -stressTime 180
@@ -53,7 +53,7 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -redefineClasses true
* -keep classloader
* -numberOfChecksLimit 4
* -stressTime 180
@@ -53,7 +53,7 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -redefineClasses true
* -keep class
* -numberOfChecksLimit 4
* -stressTime 180
@@ -53,7 +53,7 @@
* -Xlog:gc:gc.log
* -XX:-UseGCOverheadLimit
* gc.g1.unloading.UnloadingTest
* -redefineClasses
* -redefineClasses true
* -keep object
* -numberOfChecksLimit 4
* -stressTime 180

0 comments on commit f844943

Please sign in to comment.