any way to make all apps run in same JVM ?

Say Im a application user and I want to start up 9 or 10 different Java applications. Is there anyway to run all the applications in the same JVM ? If each applicaiton needs its own JVM instance, memory use could quickly get big!

Compare this to Visual Basic where the runtime machine (vb runtime) is in a DLL that each application can share the services of.

[378 byte] By [mtndood] at [2007-9-26 2:16:10]
«« moving Files
»» Hex?
# 1

I did compare it. Looking into the directory where I installed the JDK, I found something called "jvm.dll", and its size is 277K. I would have guessed that it's a shared DLL, but perhaps I'm wrong and you could explain why. At any rate, it would take more than 10 Java applications to use up memory at only 277K per time.

DrClap at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

When you run a java command, you invoke the JVM. Try running multiple Java applications and take a look at the processes running on your machine. You should see multiple processes (called "javaw" if your using windows) and each process will be using around 7MB. I think i need to do some reading on the architecture of the Java runtime. I think there is a paticular reason for making each application get its own JVM instance- i just dont know what it is yet.

mtndood at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

The native code of the JVM is fairly small.

However, most of the work of the JVM is done by java classes not by the native code. So when it starts up it loads a number of classes that it needs, regardless of what you are doing.

All of that stuff takes space.

The reason you don't want an app to run in the same space as another app, is the same reason you don't want another process to run in the same space as another process. If one app crashes every other app crashes too. That is why Win 9x, crashes less than Win 3.1, and Win NT crashes less often than both.

jschell at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

just thining out loud here:

Im coming from the Visual Basic world. With VB your runtime services are contained in a DLL. Each application that was built with VB requires the runtime in order to work. The difference is that the runtime is loaded into the process space of the application. With the JVM, its kind of the other way around. The Java app (usually very small by comparison) is loaded into the same process space of the JVM. In the end, its very similar.

mtndood at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

just thinking out loud here:

Im coming from the Visual Basic world. With VB your runtime services are contained in a DLL. Each application that was built with VB requires the runtime in order to work. The difference is that the runtime is loaded into the process space of the application. With the JVM, its kind of the other way around. The Java app (usually very small by comparison) is loaded into the same process space of the JVM. In the end, its very similar.

mtndood at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

I don't think so.

When you run anything in windows you get one process space. Each process has it own data space - like heap and stack. This has nothing to do with java nor VB. The Java JVM and VB use the data space do do what they do.

The code space for dlls, is supposed to be shared (although I have the faint impression that even that stopped being true.) Most of the dlls (in this discussion) consist of code. The VB dll is large because VB has a lot of stuff in it and it is all in that dll. Java doesn't.

Note that even if the code is shared between applications, it is still in the process space of each application (the magic of virtual memory.)

jschell at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
I'm ignorant about this too. But I suspect that the Web Start application manager starts all apps in a single VM. If you find out for sure, let me know.
walpj at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8

Web Start uses a separate VM for each app instance.

See the following topic in the JCP forum for speculation about improving resource management of client-side Java by adding application management as a standard feature.

http://forum.java.sun.com/thread.jsp?forum=25&thread=156163

walpj at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 9
Just for the sake of curiosity has someone added the total size of the classes that a minimal java application loads?Something like a main method that is empty and executed with the option -verbose:class to know them.
Botella at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 10

>Just for the sake of curiosity has someone added the total size of the classes

>that a minimal java application loads?

I haven't seen that anywhere. I went ahead and generated the raw data for 1.3.1 and posted it in this topic in the JRE forum. It includes a list of the classes loaded and the complete file list of rt.jar with file sizes. Perhaps a patient person (or a person deft with grep, perl, access, excel, etc.) can calculate the requested statistic.

http://forum.java.sun.com/thread.jsp?forum=32&thread=157380

Alternately, anyone who wants this raw data can request a zip file via e-mail from me.

Joe Walp <joewalp@yahoo.com>

walpj at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 11

>I went ahead and generated the raw data for 1.3.1

I don't think that would be the complete picture although it would give a starting point.

A class file defines a class. It does not specify how much room the class will take when loaded. And certainly not when running.

For instance to get System.out to function it takes at least two and perhaps more instances of other classes to run it. And System.out is created regardless of whether it is used, on every start up.

jschell at 2007-6-29 9:14:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 12

> > I went ahead and generated the raw data for 1.3.1

>

> A class file defines a class. It does not specify how much room the class

> will take when loaded. And certainly not when running.

In that case one would need a profiler like OptimizeIt to acquire the data. I don't have access to one.

walpj at 2007-6-29 9:14:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 13
BTW, the plug-in uses a single VM for all applets. But it doesn't appear to use provide any facility for unloading classes after an applet terminates. See the following topic in the JCP forum for details. http://forum.java.sun.com/thread.jsp?forum=25&thread=156163
walpj at 2007-6-29 9:14:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 14
The jsh project on sourceforge manages multiple apps in a single VM.https://sourceforge.net/projects/jsh/
walpj at 2007-6-29 9:14:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...