类.getConstantPool()
如果您从 rt.jar 库反编译 java 中的 java.lang.Class 类,您会注意到有一个本机方法声明:
native ConstantPool getConstantPool();
我不久前使用 Sun 的 .class 文件规范进行了类反编译,并且我能够从每个 .class 文件中获取常量池记录。 但这实际上是反编译类。
只是在Class班级看到这个签名,我感到很惊讶。 所以我所做的是在 Main() 方法中编写了一小段代码:
ConstantPool cp = new ConstantPool();
cp.getMethodAtIfLoaded(0);
如果你反编译 sun.reflect.ConstantPool 类,你会发现它有很多与类、方法相关的方法、参数、声明的字段等。
当我执行应用程序时,我收到此 HotSpot 异常:
#
# 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 the ConstantPool of any class? 考虑到 getConstantPool() 是一个本机/非公共方法,我认为 Sun 不希望我直接调用它。
If you decompile the java.lang.Class class in java from the rt.jar library you will notice there is a native method declaration:
native ConstantPool getConstantPool();
I played a while ago with class decompilation using Sun's .class file specification and I was able to obtain the constant pool record from each .class file. But that was actually decompiling classes.
It's just that I was surprised to see this signature in the Class class. So what I did is 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 it has a lot of method related to classes, method, parameters, fields declared, etc.
When I execute the app, 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 the ConstantPool of any class? Considering the fact that getConstantPool() is a native/non-public method I assume Sun does not want me to call it directly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sun.* 下的类不是公共 API,可能会更改,恕不另行通知,并且会执行各种操作。 幸运的是,不受信任的代码根本无法访问它们。 javac 对象供其使用。
无需反编译代码 - 原始来源可用,尽管不一定是最新的。
Classes under sun.* are not public APIs, may change without notice and do all sorts. Forutnately untrusted code cannot access them at all. javac objects to their use.
There's no need to decompile the code - the original source is available, although not necessarily up to date.