tags:

views:

189

answers:

2

On Linux & Mac, is there anyway that I can pre-cache the JVM (either in RAM, or a state of it) so taht when I start a Java program, it starts as fast as C/C++ programs?

I am willing to waste memoory to make this happen.

+3  A: 

No. Unfortunately :(

On second thought, the reason why Java programs start faster on Windows these days, is because there is a process (Java Quickstart) which aggressively keeps a copy of the runtime library files in the memory cache which apparently helps immensely. I do not know if this approach has been ported to Linux.

Thorbjørn Ravn Andersen
What about starting a low memory/cpu consumption java program on startup and keeping it running forever (something in the line of `while (true) { sleep(10); }`. Would that not load the JVM binary and libs into memory so that they can be shared? It will not make it as fast as a native binary, but might speed up... or not?
David Rodríguez - dribeas
if they are running off a seperate jvm, i dont think that will really help much. It might warm the runtime cache, tho i dont think you ll see significant increases in speed. And the background program will needlessly eat up resources, even if its just idling.
Chii
Libraries are only loaded once in Linux, so the real memory consumption of a second JVM is quite slim, actually.
Bombe
@Bombe, I'm talking about library code in the runtime _JAR_ files, i.e. classes.
Thorbjørn Ravn Andersen
@dribeas, no, the problem is having the jar-files in the cache, not having a JVM loaded. Think of opening all files within a zipfile one by one.
Thorbjørn Ravn Andersen
+3  A: 

Would that not load the JVM binary and libs into memory so that they can be shared?

Yes, but only in the same JVM instance. So you have to load your application into this instance, as servlet container do.

The whole bootleneck of the JVM invocation is class loading, that is the reason for the Java Quickstart that Thorbjørn mentioned.

So you can put the class libs on faster media (ram disk) this will probably fasten your (first) startup. I once installed Netbeans + JSDK on a RAM disk and it starts really fast but once started it will run equal fast than loaded from disk.

PeterMmm