-
-
Save anonymous/d6fbe111082b0059cbeb36b90ba87558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include "jni.h" | |
#include "jvmti.h" | |
/* | |
public class java.lang.ref.MyWeakReference extends java.lang.ref.WeakReference {}; | |
*/ | |
jbyte MyWeakReference_bytes[] = { | |
-54, -2, -70, -66, 0, 0, 0, 49, 0, 5, 1, 0, 29, 106, 97, 118, | |
97, 47, 108, 97, 110, 103, 47, 114, 101, 102, 47, 77, 121, 87, 101, 97, | |
107, 82, 101, 102, 101, 114, 101, 110, 99, 101, 7, 0, 1, 1, 0, 27, | |
106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 114, 101, 102, 47, 87, 101, | |
97, 107, 82, 101, 102, 101, 114, 101, 110, 99, 101, 7, 0, 3, 0, 1, | |
0, 2, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0 | |
}; | |
jsize MyWeakReference_len = 0x5C; | |
void JNICALL callback_ClassFileLoadHook_transform(jvmtiEnv *jvmti, JNIEnv* env, | |
jclass class_being_redefined, jobject loader, const char* name, | |
jobject protection_domain, jint class_data_len, const unsigned char* class_data, | |
jint* new_class_data_len, unsigned char** new_class_data) { | |
if (name && !strcmp(name, "java/lang/System")) { | |
(*env)->DefineClass(env, "java/lang/ref/MyWeakReference", NULL, MyWeakReference_bytes, MyWeakReference_len); | |
} | |
} | |
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { | |
jvmtiEventCallbacks callbacks; | |
jvmtiCapabilities caps; | |
jvmtiEnv *jvmti; | |
(*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_9); | |
memset(&caps, 0, sizeof(caps)); | |
memset(&callbacks, 0, sizeof(callbacks)); | |
caps.can_generate_early_vmstart = 1; | |
caps.can_generate_all_class_hook_events = 1; | |
caps.can_generate_early_class_hook_events = 1; | |
callbacks.ClassFileLoadHook = &callback_ClassFileLoadHook_transform; | |
(*jvmti)->AddCapabilities(jvmti, &caps); | |
(*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); | |
(*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app1; | |
import java.lang.ref.WeakReference; | |
public class MiscTest9 { | |
public static void main(String[] args) throws Exception { | |
WeakReference<?> weak = new WeakReference<>(new MiscTest9()); | |
boolean present = true; | |
while (present) { | |
System.out.println("Running GC"); | |
System.gc(); | |
present = weak.get() != null; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\XWork\Misc9>\Work\jvm\jdk-9-ea+160-jigsaw\bin\java -agentpath:c:\XWork\MinAgent\MinAgent\x64\Debug\MinAgent.dll -cp target\classes app1.MiscTest9 | |
Running GC | |
Running GC | |
# | |
# A fatal error has been detected by the Java Runtime Environment: | |
# | |
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007224be47, pid=11252, tid=12148 | |
# | |
# JRE version: Java(TM) SE Runtime Environment (9.0+160) (build 9-ea+160-jigsaw-nightly-h6207-20170316) | |
# Java VM: Java HotSpot(TM) 64-Bit Server VM (9-ea+160-jigsaw-nightly-h6207-20170316, mixed mode, tiered, compressed oops, g1 gc, windows-amd64) | |
# Problematic frame: | |
# V [jvm.dll+0x2abe47] UpdateRSOopClosure::do_oop+0x47 | |
# | |
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows | |
# | |
# An error report file with more information is saved as: | |
# C:\XWork\Misc9\hs_err_pid11252.log | |
# | |
# If you would like to submit a bug report, please visit: | |
# http://bugreport.java.com/bugreport/crash.jsp | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment