憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?

围绕在心里很长时间的一个问题: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作注。

转载于:https://www.cnblogs.com/aguncn/archive/2013/04/06/3003152.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值