OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 2:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: os with java?
PostPosted: Wed Dec 28, 2005 12:50 pm 
Hi, i am new in osdev, I have read must many small tutorials, and I'm now thinking on how writing my first kernel.
I know C, but I 'm more easy with OO programming especially in java language.
Then I have 2 solutions:
1-   writing a java virtual machine from scratch and then writing normal java classes for that VM. This is a little too hard for me.
2-   using a native java compiler  the gnu gcj compiler. The problem is that this compiler still need some runtime support for managing threads, memory services.

Anyone can tell me how can I use gcj compiler with my own support functions?
any other ideas for using java are welcome?


Top
  
 
 Post subject: Re:os with java?
PostPosted: Wed Dec 28, 2005 1:04 pm 
Sorry but I really don't thing java is suitable for kernel deving :

here you go : http://www.osdev.org/osfaq2/index.php/Can I use some language other than C%3F


Top
  
 
 Post subject: Re:os with java?
PostPosted: Wed Dec 28, 2005 1:10 pm 
I would recommend that you use C++. It is not as strong in OO as Java, but it is probably the best OO language for implementing what you call "support routines", which most people would consider to be the majority of the kernel. Then, you can try to use native-compiled Java for many kernel modules or drivers, if you have those, or user-space servers.


Top
  
 
 Post subject: Re:os with java?
PostPosted: Wed Dec 28, 2005 1:12 pm 
Enlight wrote:
Sorry but I really don't thing java is suitable for kernel deving

Well, Java is not suitable for the core services, that a kernel has to provide, e.g. memory-management. But Java might be suitable for the implementation of drivers. But I'm not sure whether implementing a java virtual maschine is worth it and I'm not sure about the advantage of Java compared to C++.


Top
  
 
 Post subject: Re:os with java?
PostPosted: Wed Dec 28, 2005 2:45 pm 
This is not based on java, but, its design may help you.
http://unununium.org/


Top
  
 
 Post subject: Re:os with java?
PostPosted: Wed Dec 28, 2005 6:33 pm 
Offline
Member
Member
User avatar

Joined: Fri Nov 04, 2005 12:00 am
Posts: 381
Location: Serbia
Java was invented to hide low-level details of C++ from programmer. But doing that, all the things needed for system development was removed from the language. So C++ has much more capabilities then Java, and it is much faster (more then twice if you use Java VM).


Top
 Profile  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 3:15 am 
I know it is impossible to do all the work in java, what I said it is the possibility of making the code which requires a direct handling of the memory as well as the basic code with C or Assembly and exploiting java for the other parts by using a native compiler.

Java facilitates considerably the implementation of an abstract model and we would gain much to use it.The trick is that several useful functionalities in java does not require a runtime support.


Top
  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 3:50 am 
yassine wrote:
I know it is impossible to do all the work in java, what I said it is the possibility of making the code which requires a direct handling of the memory as well as the basic code with C or Assembly and exploiting java for the other parts by using a native compiler.

Java facilitates considerably the implementation of an abstract model and we would gain much to use it.The trick is that several useful functionalities in java does not require a runtime support.


So it seems that you are already quite well prepared about the internals of java...

It's just that I can't see what java gives you (when using a native compiler) what you can't achieve in C++, with a good programming style. And AFAIK the C++ ABI is better documented than java's.

Well, it is most probably _possible_. You can use JNI for bindings to low level stuff, and write this stuff in C & assembly, yes. And once things like threading, synchronization, memory management and garbage collecting are done, the rest can be implemented in java (when you provide APIs for direct device access). But I'm not sure whether it's worth the hassle...you can implement multithreading, clean OO design and even garbage collecting on top of C++ just as fine. And C++ and java syntax aren't soo much different. Got my point?

cheers Joe


Top
  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 4:44 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
JoeKayzA wrote:
you can implement multithreading, clean OO design and even garbage collecting on top of C++ just as fine. And C++ and java syntax aren't soo much different. Got my point?


The semantics remain quite different, imho. Ever tried to explain a java developer that, in C++, he has to declare his destructor to be virtual in order to have objects properly released ?

I suggest you get a look at the Janos project. Their aim was to provide JVM equipped to run on bare hardware and providing minimalistic OS abstractions. Dunno whether that'll suit your needs, though.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 10:05 am 
You can certainly write most of your OS in Java, but the kernel, by Java's definition, is almost exactly that part of the OS which you will have to write in something like C++.


Top
  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 1:05 pm 
Hello.....
I also support C++ over Java for OS dev. I think you must create a base OS in C++ and should implement some sort of virtual machine in C++ on which java bytecode can run.
You can have something like this:

+--------------------------------+
| Java Byte Code |
+---------------+----------------+
| C++ Kernel | C++ Virtual |
| | machine |
+---------------+----------------+
| HARDWARE |
+--------------------------------+

JVM implementation can be found at:
http://42mag.com/jvm/


Top
  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 1:34 pm 
Pype.Clicker wrote:
The semantics remain quite different, imho. Ever tried to explain a java developer that, in C++, he has to declare his destructor to be virtual in order to have objects properly released ?


Well yes, but that's because in java _all_ methods are virtual by default. Aside that (and the omnipresent garbage collector), the syntax is (IMO) quite the same. At least, much more than VB. ::)

cheers Joe


Top
  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 1:36 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
I'm going to be contrarian here and say YES, you can try to write a lot of your kernel in Java, and there are some really interesting possibilities if you do. These guys wrote a kernel mostly in a dialect of C# (with maybe 17% "unsafe" C# and 5% C++ and asm).

If you want to implement an OS that resembles the most popular and well-understood architectures today (i.e. -- if you plan to use the MMU to protect processes from each other via distinct address spaces), then I agree with the others that C++ is a better choice. However, if you want to do some research in the same direction as the Singularity project (i.e. -- "Software Isolated Processes", verifiable code, etc.), then Java would be a reasonable choice for a "managed" language that can produce verifiably type-safe binaries. I'm going with the first option though, since I don't have that much spare time. ;)

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject: Re:os with java?
PostPosted: Thu Dec 29, 2005 10:55 pm 
I've been creating a Java-based OS in my spare time. I've been trolling around for quite some time, but before now most of what I need to be discussing has already been discussed. (The search button has been my friend indeed. : ) )

But anywho, now that the infamous intro is over, its always been my opinion that a Java-based OS has far to many advantages to not give it a second look. Imagine if a standard feature of your OS was to check for and generally make impossible stack overflows, buffer overuns, and fun with pointers; this includes most of the kernel as well. And not only is the protection done in software, so it can run on processors without or with minimal protection, but since user-space programs don't deal directly with addresses, you can run the same programs on processors with and without an MMU (which has been one of the only problems that I've heard about porting the Linux kernel to other platforms. Yes there is uC-Linux, but that has some of its own problems). And consider that fact that all Java code is type-safe. How many times have you screwed up something with a void pointer and it took days to figure out what had happened? And now that Java is the number one language on sourceforge, that means that most of the programs there are binary compatible with the OS.

But as have been pointed out, there are disadvantages too. Speed is one. However, if coding correctly (ie. brute-force = evil), it can be brought down to manageble levels. And there is the idea which JIT is a really bad idea. One shared by the singularity team as well as myself. I can only imagine the mess if the entire runtime of the system had to be compiled at boot. However if you staticaly(sp?) compile, you loose all the object file verification, or at least its not nearly as easy. I've been of the idea that a VM in the lines of Sun's HotSpot would work wonderfully here. But, I don't have an answer for everything, here's a few that I'd love to hear some debate/ideas about:
  • Obtaining optimizations from hardware. Ie. How do you not waste an Altivec unit?
  • Initing with all of the classes in a way pertaining to my programming model. I've been taking a lot of cues from micro-kernels in using modules, but its hard to do this without writing a whole FS/HDD driver on the C++ side of things which is something that I really want to stay away from.
  • Any thing else that anybody can think of. Please poke holes in my design philosophy; if there's a problem, I don't need to be doing much more in the kernel before i get it fixed (a gram of prevention <-> a kilo of cure : P).

And thanks all. Though you dont know it because I haven't posted before now, you've all been immeasurably helpful in the creation of my project.

*edit* I forgot another plus. More or less all of the components of the operating system (excluding the init code) can be tested on more... "mature" OS's with JVMs. Ie. I can run my VFS implementation on Windows ^^)


Top
  
 
 Post subject: Re:os with java?
PostPosted: Fri Dec 30, 2005 10:56 am 
Hi there!

trisman wrote:
...
And there is the idea which JIT is a really bad idea. One shared by the singularity team as well as myself. I can only imagine the mess if the entire runtime of the system had to be compiled at boot. However if you staticaly(sp?) compile, you loose all the object file verification, or at least its not nearly as easy.
...


So do you mean now that JIT-compilation _is_ a bad idea or not (the sentence was formed a bit ambigously)?

IMO, the best practise would probably be to use a JIT-compiler, to _cache_ the results in a safe place and check whether the "source" (actually the bytecode) files changed or not. The cached native code should also survive a reboot, so the often-used components are always ready to use at startup. Besides this, you could also offer an option for the user to compile (and move to the cache) a piece of bytecode manually. This could be useful when a new application is installed, for example: The app could be compiled during installation then.

As long as you ensure that only bytecode can be moved _into_ the system, you shouldn't have problems with verfication and safety (as these things are typically checked during JIT-compilation, AFAIK).

Another thing: Do you have a website for your project? Could you provide a link? THX :)

cheers Joe


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 166 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group