*
The moose likes Java in General and the fly likes Java OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java OS" Watch "Java OS" New topic
Author

Java OS

Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
I have heard rumors of a "Java OS". I've never tried it myself, but it made me curious. Is it possible to have a kernel written in Java? And if so, how would someone go about making one? Pointers to readings, tutorials, etc. would be greatly appreciated.


I never know what to put in my signature...
Peter Lawrey
Ranch Hand

Joined: Dec 21, 2008
Posts: 62
I would just have a look at these.
http://www.google.co.uk/search?q=java+os
[ December 31, 2008: Message edited by: Peter Lawrey ]
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Is it possible to have a kernel written in Java?
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.

The fundamental point here is that you need a JVM to run Java bytecode in. That JVM has to be written either for another operating system and let that OS take care of the low-level instructions (as most are at the moment), or written directly for a processor set. The latter would pretty much constitute a "Java OS", but you can't write the JVM in Java, or we'd be going round in circles! The jnode project is an example "Java OS", and it has modules written in x86 assembly to provide the necessary native code.

There are other concerns too of course: like driver compatibility, portability, development and support, provision of various APIs like graphics and networking---the existing JVMs use well-established OS libraries, and it's a lot of work to duplicate those. Ultimately you lose a lot of that by writing a new OS just for Java.

Of course, as a human you could write the entire OS in Java source code or bytecode, if you had a way to turn the result into assembly for your particularly processor (as per GCJ)... but then it's not really Java, is it?!


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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.



My Blog SCJP 5 SCWCD 5
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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.
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41148
    
  45
I agree with Charles - the chart actually shows that the difference due to the underlying language is so small as to be negligible as a deciding factor.

Of course, Linpack performance indicates precisely nothing about suitability for systems programming.


Ping & DNS - my free Android networking tools app
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

I read somewhere that java as compared to C and assembly language is very slow. What I was thinking is that in OS there are a lot of calculations every second. Moreover i thought that using JNI means more code and thus more computations as what can be done using C/Assembly in less time has to be done following a process of byte code interacting with some interface which really does the same work.


I may be wrong but I just wrote what I have in my mind.
Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
Thanks guys! So ultimately, though it's (sort of) possible to write an OS in Java, it may or may not be super practical. Correct?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
I read somewhere that java as compared to C and assembly language is very slow.
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.
What I was thinking is that in OS there are a lot of calculations every second.
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%.
Moreover i thought that using JNI...
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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Now - suppose you created your own CPU that could execute bytecode directly on the hardware. No interpretation at all.

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?

Have fun

Bill
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Thanks Charles Lyons. Your reply updated my years long old information.
[ January 01, 2009: Message edited by: Himanshu Gupta ]
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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?
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.

Without further research I'd guess yes, because Java must have all the basic computational operations which any software requires. I can't think of many basic CPU instructions which aren't covered by Java operators. On the other hand, it has no way to move things around structures unique to your processor (like registers). Yet if the processor was designed specifically for Java, I guess it could provide some Java way to do this. For example, through static method invocations which generate bytecode understood directly by the processor---e.g. "static void move(int a,int b)" on a CPU-specific class which would move data from register a into register b. I suppose memory allocation and GC would be a bit trickier, but not impossible.

BTW, do you have a "model answer" to this yourself or is this totally open ended?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
Since operating systems can be written in assembler, and Java bytecode is similar to an assembler, it would appear likely that a Java-enabled chip would allow one to build an OS in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java OS
 
Similar Threads
Different colored text?
Using SpringLayout with JPanel
Address space and thread space in threads
Complete Stall on Closing Application
Setting a priority