Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a JVM be written in Java

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 in, how can the virtual machine itself be written in Java (won't the VM code require a VM in which to run, and so on?).

Edit: Ok, so I see I overlooked the fact that Java doesn't have to run in a VM. How then does one explain how a LISP compiler can be written in LISP? Or should this be a new question altogether?

like image 227
kji Avatar asked Feb 17 '10 08:02

kji


People also ask

Can JVM be written in Java?

GraalVM has released major version 21.0 with a new component, Java on Truffle, that provides a Java Virtual Machine (JVM) implementation written in Java. GraalVM is itself a polyglot virtual machine that provides a shared runtime to execute applications written in multiple languages like Java, Python, and JavaScript.

What is the JVM coded in?

Supposing you're talking about the Hotspot JVM, which is iirc provided by Sun, it is written in C++. For more info on the various virtual machines for Java, you can check this link. javac, like most Java compilers, is written in Java.

What is JVM in Java with example?

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation.


2 Answers

Your assumption that Java requires a virtual machine is incorrect to begin with. Check out the project GCJ: The GNU Compiler for the Java Programming Language.

like image 161
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 17:09

Ignacio Vazquez-Abrams


You are asking about the chicken and the egg.

Read: http://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29

like image 24
Yuval Adam Avatar answered Sep 28 '22 16:09

Yuval Adam