Click to See Complete Forum and Search --> : Compiling Java into the Kernel?


Ben Briggs
06-17-2001, 03:11 PM
I saw a while ago that the Linux Development team was thinking of a way that they could compile Java into the Kernel. So I have two questions about this...

1) Did they do this?
2) Does that mean Java would be as fast any other compiled language (for startup), at the expense of the computer boot up time?

If Java is as fast as languages like C and C++, I'm going to have to compile the JVM into the Kernel and learn myself some Java! :)

jemfinch
06-17-2001, 04:06 PM
Originally posted by Ben Briggs:
2) Does that mean Java would be as fast any other compiled language (for startup), at the expense of the computer boot up time?


No, it definitely wouldn't. Java will still be executed as bytecodes in a virtual machine, rather than as raw instructions on raw hardware. That still would incur a large performance penalty.

The only way to achieve the same speed as natively compiled code is to either compile to native code (duh...and that would defeat a major (if not the major) reason for java's existence) or to design a process that executes JVM bytecodes natively (which has been done, I think, but I have no linkage to prove it.) Even then, I imagine that due to the java language, certain optimizations that would be possible in other languages aren't possible for natively compiled java code (without an extremely intelligent compiler.)


If Java is as fast as languages like C and C++, I'm going to have to compile the JVM into the Kernel and learn myself some Java! :)


Compiling a JVM into the kernel would do two things:

It would decrease the number of context switches between kernel syscalls and userspace code.
It would make JVM crashes crash the entire computer.


The first is insignificant; the second most certainly isn't. A JVM is a huge piece of code that shouldn't be in the kernel; to integrate it into the kernel would be an error of Microsoftian magnitude.

Are you sure the original piece that inspired this question wasn't talking about the ability to natively execute java .class files as if they were executables? One capability the linux kernel has is to be able to associate a certain class of files (no pun intended) with an executable (such as the JVM) thus lending the appearence of a natively executed program.

Jeremy

Craig McPherson
06-17-2001, 04:14 PM
Check out "MISC Binary Support" in the kernel, aka "binfmt."

It adds support for JAVA programs into the kernel.

I don't know if you can actually use it to run Java programs, but the infrastructure is there.

[ 17 June 2001: Message edited by: Craig McPherson ]

klamath
06-17-2001, 07:23 PM
The only way to achieve the same speed as natively compiled code is to either compile to native code (duh...and that would defeat a major (if not the major) reason for java's existence


GNU GCJ does this -- the version of GCJ included with GCC 3.0 should actually be able to compile most Java programs to native code. This can be useful because although the binaries aren't portable, the source code is -- you can guarantee that the same code will compile and run everywhere, even though it does need to be re-compiled.

design a process that executes JVM bytecodes natively

You mean "processor"?

If so, Sun planned to do this for a little while (I think it was called 'MAGIC' or something), but I can't remember what happened to it. One of the coolest ideas I've heard is using a Transmeta chip to accept JVM bytecodes natively, and then code-morph them (like Transmeta does with x86 currently).

Even then, I imagine that due to the java language, certain optimizations that would be possible in other languages aren't possible for natively compiled java code (without an extremely intelligent compiler.)

Which optimizations? Compile-time Java is always going to be relatively un-optimized -- however, the optimizations done by a JIT are very impressive -- much more so than the optimizations done by a conventional native compiler.

And jemfinch is right, no one in their right mind would want to include a JVM in the kernel. Java is actually quite fast -- the start-up time can be annoying and Swing is still a bit sluggish (even with JDK 1.4, although it's getting better) -- but other than that, Java is fast. And for server-side stuff (where JVM start-up isn't important), Java outperforms nearly everyone.

Ben Briggs
06-17-2001, 10:26 PM
Thanks everyone. I'll have to save learning Java until I get a better system.

That's ok, I'm more than happy with Python :)

nanode
06-18-2001, 02:42 PM
Thanks everyone. I'll have to save learning Java until I get a better system.

Oh please...

I learned to code java on a pentium 200. It wouldn't have made a good app server, but it was just fine for learning a language.

If you are able to brush away a lot of the marketing hype, java is a well designed language. It might be verbose, not the fastest or cool enough for jemfinch, but it's consistent.

"Hacker" languages that allow elite tricks may be fun to code, but don't always make good business sense. Can you imagine maintaining Perl code from multiple developers?

Ben Briggs
06-18-2001, 03:24 PM
Here's my box:

Pentium 100
8MB RAM (40MB Swap)
541MB Hard Drive (minus the swap)

It took me 2 1/2 minutes to compile the text based "Hello World". :(

jemfinch
06-18-2001, 04:11 PM
Originally posted by nanode:
It might be verbose, not the fastest or cool enough for jemfinch, but it's consistent.


Hey, I heard that!

Java just doesn't have stuff that interests me -- first class functions, anonymous functions, useful stuff like tail recursion optimization...the list goes on and on. It just doesn't seem more useful than the other language options out there.

Jeremy

klamath
06-18-2001, 04:39 PM
It took me 2 1/2 minutes to compile the text based "Hello World".

Use 'jikes', it's a much faster Java compiler than javac.

"Hacker" languages that allow elite tricks may be fun to code, but don't always make good business sense. Can you imagine maintaining Perl code from multiple developers?

Yes, actually -- if each developer is competent and codes proper Perl (i.e. a fair amount of OO, with 'strict' and 'warnings' enabled, using good programming style), there shouldn't be a problem.

nanode
06-19-2001, 11:12 AM
Jemfinch,


Java just doesn't have stuff that interests me

Fair enough. On a regular basis I have to use java to code all sorts of uninteresting things, but I blame project management and not the language for that :)

[ 19 June 2001: Message edited by: nanode ]