Very poor performance with an externally lauched JVM

Hi everybody.

I have a complex commercial application that is getting me fool. When loading the application, a lot of file/decryption/array tasks are performed in order to get all the resources into memory.

The app has two possible flavours:

* A single 'jar' we can run directly (java -jar .. etc.) Running it that way it takes about 10 seconds to load.

* A different jar embedded as a resource in a MFC application. This applications extracts it to disk and launches a JVM (through jvm.dll) for the .jar to be loaded and run. In this case, it can take up to 1 minute (!!) or more to load.

Apparently, the remainder of the application is running fine (there is much less work for the CPU).

I don't understand why Java has this behaviour, or whether it is because Microsoft's Windows app is getting control of something and hence degrading the performance.

Here is my code (nothing different from usual code):

int JavaManager::run(constchar * classPath,constchar * className,

constchar * functionName,constchar * classArgs)

{

JNIEnv *env;

JavaVM *jvm;

//JDK1_1InitArgs vm_args;

jint res;

jclass cls;

jmethodID mid;

jstring jstr;

jobjectArray args = NULL;

char classPathOptions[1024];

JavaVMInitArgs vm_args;

JavaVMOption options[5];

vm_args.nOptions = 0;

_sntprintf( classPathOptions, sizeof classPathOptions,"-Djava.class.path=%s", classPath);

options[vm_args.nOptions++].optionString ="-Djava.compiler=NONE";// disable JIT

options[vm_args.nOptions++].optionString = classPathOptions;// user classes

options[vm_args.nOptions++].optionString ="-Djava.library.path=.";// set native library path

vm_args.version = JNI_VERSION_1_4;

vm_args.options = options;

vm_args.ignoreUnrecognized = TRUE;

HINSTANCE LoadMe = LoadLibrary(_javaPath);

if( !LoadMe)return JM_CREATEJAVA;

CreateJavaVM pCreateJava = (CreateJavaVM)GetProcAddress(LoadMe,"JNI_CreateJavaVM");

if( !pCreateJava)return JM_CREATEJAVA;

// Create the Java VM

res = pCreateJava(&jvm, (void **)&env, &vm_args);

if (res < 0)return JM_CREATEJAVA;

cls = env->FindClass(className);

if (cls == 0)throw JM_FINDCLASS;

mid = env->GetStaticMethodID(cls, functionName,"([Ljava/lang/String;)V");

if (mid == 0)throw JM_FINDCLASS;

if( classArgs)

{

jstr = env->NewStringUTF(classArgs);

if (jstr == 0)throw JM_FINDCLASS;

args = env->NewObjectArray(1, env->FindClass("java/lang/String"), jstr);

if (args == 0)throw JM_FINDCLASS;

}

env->CallStaticVoidMethod(cls, mid, args);

jvm->DestroyJavaVM();

//FreeLibrary(LoadMe);

return JM_OK;

}

Has anyone experienced something like that ?

Thanks!

[4225 byte] By [pablerasa] at [2007-11-27 10:58:14]
# 1

Well, I answer myself...

The problem was this line:

options[vm_args.nOptions++].optionString = "-Djava.compiler=NONE";// disable JIT

This tells VM to use Java capabilities for many tasks. More control but less performance. See the whole explanation in:

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf2.html

pablerasa at 2007-7-29 12:14:20 > top of Java-index,Java HotSpot Virtual Machine,Specifications...