Is there a boot loader written for booting Java virtual machine without an operating system? As far as I know Java virtual machine can run on a machine by itself, without help of an operating system.
-
1please define *a machine without an operating system* – fantaghirocco Mar 19 '21 at 15:43
-
2A machine without operating system. – maDeveloper Mar 19 '21 at 15:44
-
2@fantaghirocco I found this, see https://stackoverflow.com/a/26602133/14855830. – maDeveloper Mar 19 '21 at 15:47
-
1Java defines the *guest* language, not the host / JVM. You'd need a JVM written to run on bare-metal of whatever machine you want to run it on. (i.e. to be an OS as well as a JVM). So there isn't something generic called "Java" that a bootloader could load. – Peter Cordes Mar 19 '21 at 19:27
-
A JVM is a virtual machine written in some other language for a target. It is not some generic thing, you need to go write it. Then if you add bare metal to this it just gets worse as you have to fake the system calls without a system. Booting and loading the JVM should be the trivial part (as with most other environments). – old_timer Mar 22 '21 at 19:53
-
you are possibly better off without a JVM and use a JAVA compiler with a target backend like using gnu/GCC GCJ – old_timer Mar 22 '21 at 19:55
-
or using a bare metal friendly programming language (basically C) – old_timer Mar 22 '21 at 19:56
1 Answers
Java defines the guest language, not the host / JVM.
You'd need a JVM written to run on bare-metal of whatever machine you want to run it on. (i.e. to be an OS kernel as well as a JVM, handling interrupts and so on). So there isn't something generic called "Java" that a bootloader could load.
The mainstream JVMs like OpenJDK / HotSpot are not written to work as kernels, only to run under some existing mainstream OSes. But as you found, there are some: Can you run JVM on a computer with no operating system?
Even for a specific platform, the things a kernel needs a bootloader to do may depend on the kernel. There are a few standards, like multiboot for x86, that define a kernel file format that bootloaders like GRUB know how to recognize and load, but otherwise you'd probably expect a bare-metal JVM to come with its own custom bootloader, especially if it's for a platform other than an x86 PC. Or perhaps be bootable as an "EFI application".

- 328,167
- 45
- 605
- 847
-
-
@maDeveloper: yeah, I saw :P I saw your question because I follow the [low-level] tag. I'm not totally surprised that someone following the [java] tag didn't understand it. I guess not everyone has heard of freestanding / bare-metal code. – Peter Cordes Mar 19 '21 at 19:29
-
-
@maDeveloper: I added another paragraph after having another idea about what you might be asking about. – Peter Cordes Mar 19 '21 at 19:41
-
-
@maDeveloper: I think the last paragraph of my answer *does* in general answer your question. Obviously without knowing what kind of machine you have in mind, or which freestanding JVM you want to boot, nobody could actually write a bootloader in asm that would do whatever is necessary. The big TL:DR here is that it's specific to the JVM and the target platform. – Peter Cordes Mar 19 '21 at 22:01