It isn't possible to write a whole operating system in Java---well, at least if that code is then translated into Java bytecode. The reason is simple: the operating system needs to communicate directly with the hardware in the system (CPU, RAM, mobo controllers, PCI cards etc.). But Java bytecode is a platform-neutral set of instructions, so isn't in a form directly compatible with the CPU, nor does it provide the ability to communicate with the low-level hardware directly. So ultimately you'd need some layer written in the CPU's instruction set to execute basic commands. Once you'd done that you could write a Java bytecode-to-assembly JIT interpreter or compiler for your architecture, and then simple Java instructions could be executed. That would lay the foundation for the rest of the OS.
Is it possible to have a kernel written in Java?
Interesting comparison, but a couple of points: (1) This benchmark doesn't show any huge disadvantage of recent JVMs (e.g. Java 5 Server VM) as it's almost as good as C/C++ with the huge added advantage of bytecode portability (if you need it); (2) does this really add anything to the discussion of a fundamentally Java OS? Surely an operating system built with Java in mind from the outset (rather than having to use JNI and to interface with other external OS code) would be optimised sufficiently that it is that slight bit faster than a JVM running on another OS? Just a thought.
Originally posted by Himanshu Gupta:
[QB]Performance of java as compared to c or fortan is not satisfactory. If OS is developed in Java then it will have serious performance issues. We can see the following chart to have an idea of the performance of java with other languages.
You were probably reading an old report, or a set of benchmarks designed for high performance tasks---like numerical analysis, or DSP. There is another benchmark which shows Java 1.4 is faster than C++ for many non-numerical tasks. Assembly gets the best speed, if you have the patience to write and re-write it for each architecture. But with CPU speeds the way they are, there isn't much difference these days.
I read somewhere that java as compared to C and assembly language is very slow.
Not really---an OS doesn't do much computation at all, it just manages other processes and threads, re-draws any graphics like the desktop, I/O and networking, optimising file indexing etc. None of this is particularly CPU intensive: my Linux desktop sits at less than 2% system CPU, and my non-graphical servers mostly under 0.5%.
What I was thinking is that in OS there are a lot of calculations every second.
But the whole point of writing a Java OS is that JNI isn't really necessary---the OS provides the required native code built into the JVM (i.e. the OS) so there is no additional layer required. If you needed to use JNI in a Java OS, then the OS wouldn't really be written well in Java, would it?
Moreover i thought that using JNI...
That's an interesting question... I'd have to admit I don't know the answer immediately, having never had the inclination to read the bytecode spec.
As an exercise for the class - would the existing defined bytecodes be enough to execute all the functions needed for an OS or would some additional bytecodes be required?
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Appshttps://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous