憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?
2013-04-06 22:54
351 查看
围绕在心里很长时间的一个问题:JVM的BYTECODE真的是完全平台无关的么?
就算JVM里指令集,寄存器,堆栈一应俱全。
算法,数据结构都可以完全实现,
但如果JAVA要读写文件,那它会不会被JVM在解释时,翻译成一个具体的OS的API或是SYSTEM CALL?
因为操作系统在内核态工作,而JVM只是一个软件,必须工作在用户态呀。
那BYTECODE是全被JVM直接转成机器码执行了?
带着这个问题,上天入地,都没有完全冰释心中疑问。
以下几个贴子争论得挺多的。但都没有一个定论。
谁来解答?
http://bbs.csdn.net/topics/320086053
http://wenwen.soso.com/z/q287138233.htm
http://www.189works.com/article-63310-1.html
http://www.codeproject.com/Articles/30422/How-the-Java-Virtual-Machine-JVM-Works
http://www.powerbot.org/community/topic/940642-question-about-the-jvm/
http://stackoverflow.com/questions/2748910/how-is-java-platform-independent-when-it-needs-jvm-to-run
有几句话,可以注意:
在Java平台的结构中,可以看出,Java虚拟机(JVM)处在核心的位置,是程序与底层操作系统和硬件无关的关键。它的下方是移植接口,移植接口由两部分组成:适配器和Java操作系统,其中依赖于平台的部分称为适配器;JVM通过移植接口在具体的平台和操作系统上实现;在JVM的上方是Java的基本类库和扩展类库以及它们的API,利用JavaAPI编写的应用程序(application)和小程序(Javaapplet)可以在任何Java平台上运行而无需考虑底层平台,就是因为有Java虚拟机(JVM)实现了程序与操作系统的分离,从而实现了Java的平台无关性。
The Java Virtual Machine is responsible for interpreting Java byte code and translating this into actions or Operating System calls. (这哥哥也不说哪些是直接执行,哪些是系统调用呀。XXXX,关键时掉链的典型。。)For example, a request to establish a socket connection to a remote machine will involve an Operating System call. Different Operating Systems handle sockets in different ways - but the programmer doesn't need to worry about such details. It is the responsibility of the JVM to handle these translations so that the Operating System and the CPU architecture on which the Java software is running is completely irrelevant to the eveloper.
Java source code is compiled into platform-agnostic bytecode. The host JVM will then interpret (and likely JIT) the bytecode and call the underlying native methods of the OS. So if you're running a JVM on Windows, then yes it will utilise the Win32 API. Likewise if you're running a JVM on Linux, it will make use of Linux's native libraries.
You can find many methods in the Java API with the "native" keyword: these are essentially methods which acts as a bridge between the native libraries and Java itself.
PS:
另外,关于操作系统API和SYSTEM CALL的关系,有PPT作注。
就算JVM里指令集,寄存器,堆栈一应俱全。
算法,数据结构都可以完全实现,
但如果JAVA要读写文件,那它会不会被JVM在解释时,翻译成一个具体的OS的API或是SYSTEM CALL?
因为操作系统在内核态工作,而JVM只是一个软件,必须工作在用户态呀。
那BYTECODE是全被JVM直接转成机器码执行了?
带着这个问题,上天入地,都没有完全冰释心中疑问。
以下几个贴子争论得挺多的。但都没有一个定论。
谁来解答?
http://bbs.csdn.net/topics/320086053
http://wenwen.soso.com/z/q287138233.htm
http://www.189works.com/article-63310-1.html
http://www.codeproject.com/Articles/30422/How-the-Java-Virtual-Machine-JVM-Works
http://www.powerbot.org/community/topic/940642-question-about-the-jvm/
http://stackoverflow.com/questions/2748910/how-is-java-platform-independent-when-it-needs-jvm-to-run
有几句话,可以注意:
在Java平台的结构中,可以看出,Java虚拟机(JVM)处在核心的位置,是程序与底层操作系统和硬件无关的关键。它的下方是移植接口,移植接口由两部分组成:适配器和Java操作系统,其中依赖于平台的部分称为适配器;JVM通过移植接口在具体的平台和操作系统上实现;在JVM的上方是Java的基本类库和扩展类库以及它们的API,利用JavaAPI编写的应用程序(application)和小程序(Javaapplet)可以在任何Java平台上运行而无需考虑底层平台,就是因为有Java虚拟机(JVM)实现了程序与操作系统的分离,从而实现了Java的平台无关性。
The Java Virtual Machine is responsible for interpreting Java byte code and translating this into actions or Operating System calls. (这哥哥也不说哪些是直接执行,哪些是系统调用呀。XXXX,关键时掉链的典型。。)For example, a request to establish a socket connection to a remote machine will involve an Operating System call. Different Operating Systems handle sockets in different ways - but the programmer doesn't need to worry about such details. It is the responsibility of the JVM to handle these translations so that the Operating System and the CPU architecture on which the Java software is running is completely irrelevant to the eveloper.
Java source code is compiled into platform-agnostic bytecode. The host JVM will then interpret (and likely JIT) the bytecode and call the underlying native methods of the OS. So if you're running a JVM on Windows, then yes it will utilise the Win32 API. Likewise if you're running a JVM on Linux, it will make use of Linux's native libraries.
You can find many methods in the Java API with the "native" keyword: these are essentially methods which acts as a bridge between the native libraries and Java itself.
PS:
另外,关于操作系统API和SYSTEM CALL的关系,有PPT作注。
相关文章推荐
- Bytecode Outline eclipse插件,在研究asm时挺有用的一个插件
- Bytecode Outline plugin 一个很有用的eclipse插件
- Github网站加载不完全,响应超时,如何解决 Github是一个代码托管平台和开发者社区,开发者可以在Github上创建自己的开源项目并与其他开发者协作编码。毫不夸张地说,高效利用Github是一
- Code::Blocks 是一个开放源码的全功能的跨平台C/C++集成开发环境.
- JSchemeMin:又一个JVM平台上的Scheme语言实现
- 对如何建设一个可运维高可靠的SAAS平台,我终于有了想法!!!
- 一个专为移动端开发的原创即时通讯框架,超轻量级、高度提炼,完全基于UDP协议,支持iOS、Android、标准Java平台。
- 如何才能学到Qt的精髓(信号槽之间的无关性),QT的GUI全是自己的一套,并且完全开源,提供了一个绝好机会窥视gui具体实现
- 一个python bytecode decompiler
- 深入JVM学习笔记-平台无关性
- JVM byte code
- 未能加载文件或程序集“NHibernate.ByteCode.Castle”或它的某一个依赖项。系统找不到指定的文件
- 微信公众号平台网页授权接口中获取到的授权code传递给(即一个微信公众号网页授权给)任何其他多个回调域名下的url,解决了只能设置一个网页授权回调域名的问题,解决了redirect_uri参数错误的问
- as3commons-bytecode 获取所有类的一个BUG
- Bytecode Visualizer 一个好用的class字节码查看工具
- Eclipse启动时出现jvm terminated exit code=-1错误的一个解决办法
- 什么是JVM?java被称作是平台无关的编程语言?
- 未能加载文件或程序集“NHibernate.ByteCode.LinFu”或它的某一个依赖项。系统找不到指定的文件。
- 关于一个php开发平台的想法
- JVM解析01-平台无关性