了解 Java 字节码和 JVM

发布于 2024-07-29 07:58:57 字数 403 浏览 10 评论 0原文

在最近提出的一个问题中,我简单的回答突出了我对 Java、JVM 以及代码如何编译和运行的许多误解。 这让我产生了一种将我的理解提升到更低水平的愿望。 我对汇编这样的低级理解没有任何问题,但字节码和 JVM 让我感到困惑。 我不知道面向对象的代码是如何在低层次上分解的。 我想知道是否有人对如何学习 JVM、字节码和 Java 的底层功能有任何建议。 是否有任何实用程序允许您直接编写和运行字节码,因为我相信实践经验是加深对它的理解的最佳方式? 此外,关于该主题的阅读建议将不胜感激。

编辑:次要问题。 所以我有一个有点子问题,答案给了我一个有趣的想法来了解 jvm,仅以可读语法编写像 Brainf**k 或 Ook 这样的非常简单的语言的合理性是什么(也许我什至可以开发它)最终支持 oo)编译成字节码是? 这会是一次很好的学习经历吗?

In a recent question asked recently my simple minded answer highlighted many of my misconceptions about Java, the JVM, and how the code gets compiled and run. This has created a desire in me to take my understanding to a lower level. I have no problems with the low level understanding like assembly how ever bytecode and the JVM confound me. How object oriented code gets broken down on a low level is lost to me. I was wondering if anyone had any suggestion on how to learn about the JVM, bytecode and the lower level functioning of Java. Are there any utilities out there that allow you to write and run bytecode directly as I believe hands on experience with something is the best way to grow in understanding of it? Additionally and reading suggestions on this topic would be appreciated.

Edit: Secondary question. So I have a kinda sub question, the answers gave me an interesting idea to learn about the jvm, what would the plausibility of writing a really simple language like brainf**k or Ook only in a readable syntax (maybe I could even develop it to support oo eventually) that compiles into bytecode be? Would that be a good learning experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

走走停停 2024-08-05 07:58:57

建议阅读:JVM 规范

您可能还想使用 BCEL - 还有其他库用于操作字节码,但这可能是最著名的一个。

Suggested reading: the JVM spec.

You might also want to play with BCEL - there are other libraries around for manipulating bytecode, but that's probably the best known one.

白日梦 2024-08-05 07:58:57

Apache BCEL 将允许您从字节码分析和手工制作 .class 文件。

javap 将允许您反汇编现有的 .class文件。 它对于构建快速测试类以了解幕后真正发生的事情特别有用。

The Apache BCEL will allow you to analyse and hand craft .class files from bytecode.

javap will allow you to disassemble existing .class files. It's particularly useful for knocking up quick test classes to understand what is really going on underneath the covers.

污味仙女 2024-08-05 07:58:57

我通过阅读 ASM 教程 以及对库本身的研究。

恕我直言,ASM 比 BECL 更好。

BCEL 已被使用
在多个项目中取得成功,例如
作为编译器、优化器、
混淆器、代码生成器和
分析工具。 不幸的是
还没有太多的发展
在过去的几年里
。 随意地
帮忙或者你可能想要一个
查看 ASM 项目:
对象网。

- http://jakarta.apache.org/bcel/

I learned by reading the ASM tutorial and mucking about with the library itself.

IMHO, ASM is better than BECL.

BCEL is already being used
successfully in several projects such
as compilers, optimizers,
obsfuscators, code generators and
analysis tools. Unfortunately there
hasn't been much development going on
over the past few years
. Feel free to
help out or you might want to have a
look into the ASM project at
objectweb.

- http://jakarta.apache.org/bcel/

2024-08-05 07:58:57

只有一个可靠的来源可以帮助您理解 JVM

Java® 虚拟机规范 Java SE 7 版本

http://docs.oracle.com/javase/specs/jvms/se7/html/index.html

There is only one reliable source for JVM understanding

The Java® Virtual Machine Specification Java SE 7 Edition

http://docs.oracle.com/javase/specs/jvms/se7/html/index.html

罪#恶を代价 2024-08-05 07:58:57

Programming for the Java Virtual Machine 是一本关于此主题的好书。 (披露:我与作者合作。)

Programming for the Java Virtual Machine is a good book for this topic. (Disclosure: I work with the author.)

请恋爱 2024-08-05 07:58:57

要了解 Java/JVM 的架构:请阅读 Wikipedia、规范和源代码。

为了理解面向对象的代码是如何在低级别上完成的:尝试用 C 等较低级别语言来模拟继承/多态/封装等功能。

在 C 中,您可以通过例如函数指针的组合来实现上述功能和嵌套结构。

For understanding Java/the JVM's architecture: read Wikipedia, the specs and the source code.

For understanding how object-orientated code is done on a low level: try and emulate features like inheritance/polymorphism/encapsulation in a lower-level language like C.

In C you can achieve the above through, for example, a combination of function pointers and nested structures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文