Class.getConstantPool ()

If you decompile the java.lang.Class class in java from the rt.jar library, you will notice that there is a native method declaration:

native ConstantPool getConstantPool();

      

I was playing around a while ago with decompiling a class using the Sun.class file spec and I was able to get a persistent pool entry from each .class file. But these were actually decompiling classes.

I was just surprised to see this signature in the classroom class. So what I did, I wrote a small piece of code in the Main () method:

ConstantPool cp = new ConstantPool();
cp.getMethodAtIfLoaded(0);

      

If you decompile the sun.reflect.ConstantPool class , you will notice that it has many methods related to classes, methods, parameters, declared fields, etc.

When I run the application I get this HotSpot exception:

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7e01d3, pid=2816, tid=5464
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_15-b04 mixed mode)
# Problematic frame:
# V  [jvm.dll+0xa01d3]
#
# An error report file with more information is saved as hs_err_pid2816.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

      

Why can't I get ConstantPool of any class? Given that getConstantPool () is a native / non-public method, I'm guessing Sun doesn't want me to call it directly.

+1


source to share


1 answer


Classes under the sun. * are not public APIs, they can change without notice and do all kinds. Forutnately untrusted code cannot access them at all. javac to use them.



There is no need to decompile the code - the original source is available , although not necessarily updated.

+1


source







All Articles