How can a JVM be written in Java

后端 未结 10 678
再見小時候
再見小時候 2020-12-13 09:10

I was briefly reading about Maxine which is an open source JVM implementation that written in Java. This sounds circular to me. If java requires a virtual machine to run i

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 09:35

    It is kinda 'whooaoaa man, how can that work???' - but I think you are describing the phenomenon known as 'self-hosting':

    Languages (or toolchains/platforms) don't start out as self-hosting - they start off life having been built on an existing platform: at a certain point they become functional enough to allow programs to be written which understand the syntax which it itself happens to be written in.

    There is a great example in the classic AWK book, which introduces an AWK program which can parse (a cut-down version as it happens) other AWK programs: see link below.

    There is another example in the book "Beautiful Code" which has a Javascript program which can parse Javascript.

    I think the thing to remember on this - if you have (say) a JVM written in Java which can therefore run Java Byte code: the JVM which runs the Java JVM itself has to be hosted natively (perhaps this JVM was written in 'C' and then compiled to machine code) : this is true in any case of a self-hosting program eventually - somewhere along the line.

    So the mystery is removed - because at some point, there is a native machine-code program running below everything.

    It kinda of equivalent of being able to describe the English (etc) language using the English language itself....maybe...

    http://www.amazon.co.uk/AWK-Programming-Language-Alfred-Aho/dp/020107981X/ref=sr_1_fkmr0_3?ie=UTF8&qid=1266397076&sr=8-3-fkmr0

    http://www.amazon.co.uk/gp/search/ref=a9_sc_1?rh=i%3Astripbooks%2Ck%3Abeautiful+code&keywords=beautiful+code&ie=UTF8&qid=1266397435

    http://en.wikipedia.org/wiki/Self-hosting

提交回复
热议问题