• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java OS

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?!
 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Charles Lyons. Your reply updated my years long old information.
[ January 01, 2009: Message edited by: Himanshu Gupta ]
 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic