Page 1 of 1

Java

Posted: Mon Feb 16, 2004 6:34 pm
by guest
Hello :) ,
Can i write my OS using Java , if so how can i do that ?
Thanks..

Re:Java

Posted: Mon Feb 16, 2004 7:42 pm
by Schol-R-LEA
The good news is, it is possible. The bad news is, it would take a lot more work.

The key issue is that Java expect a certain amount of runtime support, usually provided by the JVM. While Java can be compiled to native code, it requires additional libraries in order to do so, libraries which depend on... the operating system.

To write an OS in Java, you would have to provide that runtime support yourself, before any Java code runs. There are three basic was to do this:

a) Use a native code compiler (or write one) and write the supporting libraries for it, in a low-level language such as assembly or C;
b) Write a JVM interpreter in a low-level language, and run the OS on top of the virtual machine;
or
c) devise a limited subset of Java that does not use the higher-level tools (garbage collection, runtime type checking) and use that to implement the underlying tools for either a) or b) above (or most likely, both).

In practice, this really amounts to writing the OS kernel in some language other than Java. A) is typical of high-level compiled languages such as C++. B) is the classic approach for interpreted systems, used in JavaOS, UCSD-p Pascal, and Smalltalk-80; most of these also include some way of creatng native code executables as well, which treat the interpreter as a shared library. C) is the approach used by most FORTH systems, as well as by Squeak Smalltalk; in the case of Java, however, a 'low-level subset' would be nearly indistinguishable from C.

A search of this forum will bring up several discussions of OS development in languages other than C; most of them come to the same conclusions presented here. This does not mean you should not try it; certainly I am not one to encourage the C hegemony. ;)

Re:Java

Posted: Tue Feb 17, 2004 2:19 am
by Pype.Clicker
There are a few thing here that require our attention ... How far will you go with java in your java-based OS ? How can one -- for instance -- program a device like a hard disk or a network card in Java ? you're likely to write a stub that will expose I/O operations through a class ... Say something like an io.PortFactory and an io.memmapFactory, and then you still have to worry about interrupts and things ...

Some papers i read were comparing the performances of native-compiled JAva (with GCC 3) against JIT-compiled code... and the JIT was performing better.

What really concern me is the lack of feature in the language for explicit memory management. As you're unlikely to have a garbage collector, you'll have to find a way to get chunks of memory for your objects and then store them back as 'ready-to-be-reused' objects ...

The question i would ask myself if i were you are:
- what in Java makes you wish to use it ?
- can you find that in another language that would be easier to use for OSdev ?