将ByteCode加载到内存中后,某些JVM会做什么? [英] What does certain JVM do after loading ByteCode into memory?

查看:94
本文介绍了将ByteCode加载到内存中后,某些JVM会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如HotSpot ..我停止了其编译模式,并在考虑类的字节码 应该由操作码呈现在内存中.

for example like HotSpot.. I stopped its complied mode and I was thinking bytecode of classes should be in the memory by the opcode presents..

但是看来我错了..所以一些专家告诉我,应该有一些 将字节码加载到内存中时的转换过程.

But it seems I am wrong.. so some experts told me that there should be some transformation processes when loading bytecode into memory..

有人能给我更多有关此问题的说明吗?

Could any body give me more instructions about this issue...?

非常感谢!

推荐答案

通过查看一个API文档,您可以得到一些提示,该API可以迫使JVM将内部表示形式转换回官方类文件格式:

You can get some hints by looking at the documentation of an API that forces the JVM to transform the internal representation back into the official class file format:

http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses(java.lang.Class ...)

初始类文件字节表示传递给ClassLoader.defineClass或redefineClasses的字节(在应用任何转换之前),但是它们可能不完全匹配.常量池可能没有相同的布局或内容.常量池可能具有更多或更少的条目.常量池条目的顺序可能不同.但是,方法的字节码中的常量池索引将对应.某些属性可能不存在.如果顺序没有意义,例如方法的顺序,则顺序可能不会保留

The initial class file bytes represent the bytes passed to ClassLoader.defineClass or redefineClasses (before any transformations were applied), however they might not exactly match them. The constant pool might not have the same layout or contents. The constant pool may have more or fewer entries. Constant pool entries may be in a different order; however, constant pool indices in the bytecodes of methods will correspond. Some attributes may not be present. Where order is not meaningful, for example the order of methods, order might not be preserved

从本文档中,您可以得出结论,可以期望访问常量池的指令看起来有所不同,至少它们可能具有不同的索引,并且您不能假定方法已放置在连续的内存空间中.这并不意味着这些是唯一的转换,但是如果需要的话,所有其他转换都可以撤消-至少在支持Instrumentation的JVM中.

From this documentation you can draw the conclusion that you can expect instructions accessing the constant pool to look different, at least they may have different indices, and that you cannot assume that methods are placed into a contiguous memory space. This does not imply that these are the only transformations, but all others can be reversed if needed— at least in a JVM that supports Instrumentation.

在运行代码时,JVM可能会用专用的VM内部指令替换指令,以优化进一步的执行.如果您想知道JVM可能使用哪种指令,则可以使用参数运行Oracle的HotSpot-Engine

While running the code the JVM might replace instructions by specialized VM-internal instructions to optimize further execution. If you are curious what kind of instruction a JVM might have you can run Oracle’s HotSpot-Engine with the arguments

-XX:+UnlockDiagnosticVMOptions -XX:+PrintInterpreter

然后它将打印解释程序使用的所有指令及其关联的本机代码表.该表将必然包含这些专门说明.例如.在我的机器和jdk 1.7上,我看到大约30条非标准字节码指令,范围在203到231之间.

Then it will print the table of all instructions and their associated native code as used by the interpreter. This table will necessarily contain these specialized instructions. E.g. on my machine and jdk 1.7 I see about 30 non-standard bytecode instructions in the range 203 to 231.

这篇关于将ByteCode加载到内存中后,某些JVM会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆