Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why operating systems are not written in java?

Tags:

java

All the operating systems till date have been written in C/C++ while there is none in Java. There are tonnes of Java applications but not an OS. Why?

like image 308
stillanoob Avatar asked Apr 11 '15 16:04

stillanoob


People also ask

Is it possible to write an OS in Java?

Use Java to write individual operating system components. For example, it is possible to write a file system in Java. Use Java to write a simulator for a full operating system, including the machine it is running on.

Is Java good for operating system?

Java runs very well on Windows, macOS and Linux Distributions. I work for Chronicle Software, and much of our software is open-source Java libraries, so we don't, or rather we can't, require our customers to run on a particular operating system.


2 Answers

Because we have operating systems already, mainly. Java isn't designed to run on bare metal, but that's not as big of a hurdle as it might seem at first. As C compilers provide intrinsic functions that compile to specific instructions, a Java compiler (or JIT, the distinction isn't meaningful in this context) could do the same thing. Handling the interaction of GC and the memory manager would be somewhat tricky also. But it could be done. The result is a kernel that's 95% Java and ready to run jars. What's next?

Now it's time to write an operating system. Device drivers, a filesystem, a network stack, all the other components that make it possible to do things with a computer. The Java standard library normally leans heavily on system calls to do the heavy lifting, both because it has to and because running a computer is a pain in the ass. Writing a file, for example, involves the following layers (at least, I'm not an OS guy so I've surely missed stuff):

  1. The filesystem, which has to find space for the file, update its directory structure, handle journaling, and finally decide what disk blocks need to be written and in what order.
  2. The block layer, which has to schedule concurrent writes and reads to maximize throughput while maximizing fairness.
  3. The device driver, which has to keep the device happy and poke it in the right places to make things happen. And of course every device is broken in its own special way, requiring its own driver.

And all this has to work fine and remain performant with a dozen threads accessing the disk, because a disk is essentially an enormous pile of shared mutable state.

At the end, you've got Linux, except it doesn't work as well because it doesn't have near as much effort invested into functionality and performance, and it only runs Java. Possibly you gain performance from having a single address space and no kernel/userspace distinction, but the gain isn't worth the effort involved.

There is one place where a language-specific OS makes sense: VMs. Let the underlying OS handle the hard parts of running a computer, and the tenant OS handles turning a VM into an execution environment. BareMetal and MirageOS follow this model. Why would you bother doing this instead of using Docker? That's a good question.

like image 98
Steve McKay Avatar answered Oct 13 '22 13:10

Steve McKay


Indeed there is a JavaOS http://en.wikipedia.org/wiki/JavaOS

And here is discuss about why there is not many OS written in java Is it possible to make an operating system using java?

In short, Java need to run on JVM. JVM need to run on an OS. writing an OS using Java is not a good choice.

OS needs to deal with hardware which is not doable using java (except using JNI). And that is because JVM only provided limited commands which can be used in Java. These command including add, call a method and so on. But deal with hardware need command to operate reg, memory, CPU, hardware drivers directly. These are not supported directly in JVM so JNI is needed. That is back to the start - it is still needed to write an OS using C/assembly.

Hope this helps.

like image 38
DeepNightTwo Avatar answered Oct 13 '22 13:10

DeepNightTwo