java noob question: Is it possible to actually compile a java program?

flashbacck

Golden Member
Aug 3, 2001
1,921
0
76
Just curious. Is it possible to compile a java program so that it can run without the JVM?

n/m, I found it: http://gcc.gnu.org/java/

edit: I have some questions about Java being "slow" a few posts down
 

itachi

Senior member
Aug 17, 2004
390
0
0
no it doesn't. but it's significantly slower than running with the JVM.

if you're willing to pay, there's excelsior jet.. which costs $1200 for the standard edition, but they also have an academic license for $100, if you qualify.
you have to understand the jvm and it's heap to be able to get any real benefits out of it.. and even then it won't be significantly faster than hotspot and, in certain cases, can be slower.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: itachi
no it doesn't. but it's significantly slower than running with the JVM.
You're saying gcj is significantly slower than sun's jvm? Any particular reason for that, beyond less advanced optimizations?
 

flashbacck

Golden Member
Aug 3, 2001
1,921
0
76
Originally posted by: kamper
Originally posted by: itachi
no it doesn't. but it's significantly slower than running with the JVM.
You're saying gcj is significantly slower than sun's jvm? Any particular reason for that, beyond less advanced optimizations?

I've seen some benchmarks indicating that gcj is often slower, but I also don't understand why. Doesn't the JVM have to spend time compiling in real time? How does it make up for this time?

Also, people often complain about Java being relatively slow. I always thought that was because of processing time used by the JVM. But the fact that GCJ doesn't run faster seems to indicate this isn't the reason. So why is Java slower compared to other languages?
 

manly

Lifer
Jan 25, 2000
13,589
4,239
136
Originally posted by: flashbacck
Originally posted by: kamper
Originally posted by: itachi
no it doesn't. but it's significantly slower than running with the JVM.
You're saying gcj is significantly slower than sun's jvm? Any particular reason for that, beyond less advanced optimizations?

I've seen some benchmarks indicating that gcj is often slower, but I also don't understand why. Doesn't the JVM have to spend time compiling in real time? How does it make up for this time?

Also, people often complain about Java being relatively slow. I always thought that was because of processing time used by the JVM. But the fact that GCJ doesn't run faster seems to indicate this isn't the reason. So why is Java slower compared to other languages?
Code only has to be JIT compiled once.

For a reasonably high-level language, Java isn't that slow. It's considered by many to be resource hungry, but in comparison to today's hardware, the requirements are quite reasonable. Plus it scales across a broad array of hardware.

Compared to compiled languages, dynamic languages such as Java can also benefit from runtime optimizations. I've been out of the loop, but the micro benchmarks from (many) years past showed that Java runtimes are pretty competitive with compiled C.
 

itachi

Senior member
Aug 17, 2004
390
0
0
Originally posted by: kamper
You're saying gcj is significantly slower than sun's jvm? Any particular reason for that, beyond less advanced optimizations?
i wouldn't say less advanced optimizations.. rather a lack of.

I've seen some benchmarks indicating that gcj is often slower, but I also don't understand why. Doesn't the JVM have to spend time compiling in real time? How does it make up for this time?
gcj is slow at runtime checks (array boundary, dynamic type, etc...).

it doesn't compile everything.. with an adaptive compiler, it runs the code through the interpreter, and profiles the code, looking for execution hotspots.. which are then compiled into native machine code and stored in memory.
Also, people often complain about Java being relatively slow. I always thought that was because of processing time used by the JVM. But the fact that GCJ doesn't run faster seems to indicate this isn't the reason. So why is Java slower compared to other languages?
the jvm can't compensate for bad code or bad startup options..
if the initial heap size is too small, the jvm has to allocate a larger heap, a slow process. if the heap size is too large, the os may page out portions of the heap.
if the programmer keeps references to objects that are no longer used, the garbage collector can't reclaim the memory.
if a method from one class will never be overriden by a base class, but doesn't have the final modifier.. inlining will be less efficient.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: itachi
it doesn't compile everything.. with an adaptive compiler, it runs the code through the interpreter, and profiles the code, looking for execution hotspots.. which are then compiled into native machine code and stored in memory.
I don't know too much about gcj and whatever jitting they do, but I was more curious about the mode where it compiles java to native libraries at build time and links them to gcj compilations of the class library, c-style.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: tfinch2
Originally posted by: manly
Originally posted by: tfinch2
It still runs with an interpreter.
I hope you're trying to be sarcastic. It's 2006, not 1996.
I don't see what you're trying to get at...
Were you trying to imply that java is completely interpreter-based, or that gcj doesn't have anything more than an interpreter, or that gcj uses an interpreter for some of its operations?
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Originally posted by: kamper
Originally posted by: tfinch2
Originally posted by: manly
Originally posted by: tfinch2
It still runs with an interpreter.
I hope you're trying to be sarcastic. It's 2006, not 1996.
I don't see what you're trying to get at...
Were you trying to imply that java is completely interpreter-based, or that gcj doesn't have anything more than an interpreter, or that gcj uses an interpreter for some of its operations?

I saw "compile" and "without JVM" and thought the OP was looking for something to compile Java into machine instructions without a runtime interpreter. My mistake.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: tfinch2
I saw "compile" and "without JVM" and thought the OP was looking for something to compile Java into machine instructions without a runtime interpreter. My mistake.
I'm getting really confused here. I can't tell what you're saying is true and what isn't. So two points:

-gcj, as I understand it, can compile java into machine instructions and can run it without continual vm supervision (I imagine some form of vm still has to be present to handle java byte code that gcj hasn't compiled itself, in order to remain as jvm compliant as possible).

-Your idea of "compile Java into machine instructions without a runtime interpreter" is rather incomplete. You can compile java into vm byte code and run it just fine with or without a runtime interpreter. The spec says nothing about how the byte code should be executed and there are advantages to doing it several different ways.