How do I get the instance of the unsafe class?
I always get the security exception. I listed the code of the OpenJDK 6 implementation. I would like to mess around with
There is another way of doing it you can find in:
http://mishadoff.com/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/
in unsafe source code, you can find:
@CallerSensitive
public static Unsafe getUnsafe() {
Class> caller = Reflection.getCallerClass();
if (!VM.isSystemDomainLoader(caller.getClassLoader()))
throw new SecurityException("Unsafe");
return theUnsafe;
}
you can add your class or jar to bootstrap classpath by using Xbootclasspath, as below:
java -Xbootclasspath:/usr/jdk1.7.0/jre/lib/rt.jar:. com.mishadoff.magic.UnsafeClient