憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?
圍繞在心里很長(zhǎng)時(shí)間的一個(gè)問題:JVM的BYTECODE真的是完全平臺(tái)無關(guān)的么?
就算JVM里指令集,寄存器,堆棧一應(yīng)俱全。
算法,數(shù)據(jù)結(jié)構(gòu)都可以完全實(shí)現(xiàn),
但如果JAVA要讀寫文件,那它會(huì)不會(huì)被JVM在解釋時(shí),翻譯成一個(gè)具體的OS的API或是SYSTEM CALL?
因?yàn)椴僮飨到y(tǒng)在內(nèi)核態(tài)工作,而JVM只是一個(gè)軟件,必須工作在用戶態(tài)呀。
那BYTECODE是全被JVM直接轉(zhuǎn)成機(jī)器碼執(zhí)行了?
帶著這個(gè)問題,上天入地,都沒有完全冰釋心中疑問。
以下幾個(gè)貼子爭(zhēng)論得挺多的。但都沒有一個(gè)定論。
誰來解答?
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平臺(tái)的結(jié)構(gòu)中,可以看出,Java虛擬機(jī)(JVM)處在核心的位置,是程序與底層操作系統(tǒng)和硬件無關(guān)的關(guān)鍵。它的下方是移植接口,移植接口由兩部分組成:適配器和Java操作系統(tǒng),其中依賴于平臺(tái)的部分稱為適配器;JVM通過移植接口在具體的平臺(tái)和操作系統(tǒng)上實(shí)現(xiàn);在JVM的上方是Java的基本類庫和擴(kuò)展類庫以及它們的API,利用JavaAPI編寫的應(yīng)用程序(application)和小程序(Javaapplet)可以在任何Java平臺(tái)上運(yùn)行而無需考慮底層平臺(tái),就是因?yàn)橛蠮ava虛擬機(jī)(JVM)實(shí)現(xiàn)了程序與操作系統(tǒng)的分離,從而實(shí)現(xiàn)了Java的平臺(tái)無關(guān)性。
The Java Virtual Machine is responsible for interpreting Java byte code and translating this into actions or Operating System calls. (這哥哥也不說哪些是直接執(zhí)行,哪些是系統(tǒng)調(diào)用呀。XXXX,關(guān)鍵時(shí)掉鏈的典型。。)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:
另外,關(guān)于操作系統(tǒng)API和SYSTEM CALL的關(guān)系,有PPT作注。
總結(jié)
以上是生活随笔為你收集整理的憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在RHEL5.0中用YUM解决RPM包的
- 下一篇: 有没有课本讲解的视频网站?就是在书上做笔