Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Fri, 9 Jan 2004 17:17:33 -0500 (EST) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Moy Easwaran cc: cygwin AT cygwin DOT com Subject: Re: Problem with JVM 1.4.2 on Cygwin 1.5.5-1 on XP and 2000 In-Reply-To: Message-ID: References: <3FFF1AB4 DOT 4010609 AT nationwide DOT com> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-1254324197-1073686653=:10405" ---559023410-1254324197-1073686653=:10405 Content-Type: TEXT/PLAIN; charset=US-ASCII On Fri, 9 Jan 2004, Moy Easwaran wrote: > I'm trying to run HelloWorld.java on a JVM invoked from C. I'm using > the basic setup in David Caldwell's excellent how-to at > et seq. > > It works fine on WinNT 4.0 and WinXP Home, but dies on WinXP Pro and > Win2000. > > There's not really much of a trail I can provide. I get a message-box > saying: "jvm.exe has encountered a problem and needs to close. We are > sorry for the invonvenience." > > It dies on JNI_CreateJavaVM with the 1.4.1 SDK. In 1.4.2, > JNI_CreateJavaVM always returns -1 (and so FindClass can't run). > > The Windows event log says: > "Faulting application jvm.exe [my executable], version 0.0.0.0, faulting module jvm.dll, version 0.0.0.0, fault address 0x000a9d63. Application Failure jvm.exe 0.0.0.0 in jvm.dll 0.0.0.0 at offset 000a9d63.." > > Any suggestions on where to look or what to look for? Help! > > Thanks much, > > Moy > > > > My steps and files are as follows: > > $ dlltool --input-def jvm.def --kill-at --dllname jvm.dll --output-lib libjvm.dll.a > $ gcc -Wall -mno-cygwin -o jvm.exe -I/cygdrive/c/j2sdk1.4.1_06/include -I/cygdrive/c/j2sdk1.4.1_06/include/win32 jvm.c -L. -ljvm > $ cat jvm.def > EXPORTS > JNI_CreateJavaVM AT 12 > JNI_GetDefaultJavaVMInitArgs AT 4 > JNI_GetCreatedJavaVMs AT 12 > > $ cat HelloWorld.java > public class HelloWorld > { > public static void main (String args []) > { > System.out.println ("Hello, world!"); > } > } > > $ cat jvm.c # this is basically the invoke.c example on inonit.com > #include > #include > > JNIEnv* create_vm() { > JavaVM* jvm; > JNIEnv* env; > JavaVMInitArgs args; > JavaVMOption options[1]; > int res; > > /* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */ > args.version = JNI_VERSION_1_2; > args.nOptions = 1; > options[0].optionString = "-Djava.class.path=c:\\test"; > args.options = options; > args.ignoreUnrecognized = JNI_TRUE; > > printf ("about to call CreateJavaVM.\n"); > res = JNI_CreateJavaVM(&jvm, (void **)&env, &args); > printf ("CreateJavaVM returned [%d].\n", res); > return env; > } > > void invoke_class(JNIEnv* env) { > jclass helloWorldClass; > jmethodID mainMethod; > jobjectArray applicationArgs; > jstring applicationArg0; > > printf ("step 2...\n"); > helloWorldClass = (*env)->FindClass(env, "HelloWorld"); > > printf ("step 3...\n"); > mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V"); > > printf ("step 4...\n"); > applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL); > applicationArg0 = (*env)->NewStringUTF(env, "From-C-program"); > // (*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0); > > printf ("step 5...\n"); > (*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs); > } > > > int main(int argc, char **argv) { > JNIEnv* env = create_vm(); > printf ("step 1 done...\n"); > invoke_class( env ); > return 0; > } FWIW, the code above just worked for me on Win2k (with an appropriate change to the "-Djava.class.path=" line -- see below). I use IBM JDK 1.4.1. I've added some debugging output to print out the class that's returned and the method id. BTW, when the java.class.path was set wrong, the class returned was '0'. I've attached my original jvm.c (the one with "-Djava.class.path=c:\\cygwin\\tmp\\javatest"). HTH, Igor $ pwd /tmp/javatest $ mount | grep java c:\Program Files\IBM\Java14 on /usr/contrib/java type user (binmode) $ java -version java version "1.4.1" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1) Classic VM (build 1.4.1, J2RE 1.4.1 IBM Windows 32 build cn1411-20030930 (JIT enabled: jitc)) $ dlltool --input-def jvm.def --kill-at --dllname "`cygpath -m /usr/contrib/java/jre/bin/classic/jvm.dll`" --output-lib libjvm.dll.a $ grep 'java.class.path' jvm.c options[0].optionString = "-Djava.class.path=c:\\cygwin\\tmp\\javatest"; $ gcc -Wall -mno-cygwin -o jvm.exe -I/usr/contrib/java/include -I/usr/contrib/java/include/win32 jvm.c -L. -ljvm $ ./jvm about to call CreateJavaVM. CreateJavaVM returned [0]. step 1 done... step 2... class = 00D654A4 step 3... method = 0982D530 step 4... step 5... Hello, world! $ perl -i -pe 's,c:\\\\cygwin\\\\tmp\\\\javatest,.,' jvm.c $ grep 'java.class.path' jvm.c options[0].optionString = "-Djava.class.path=."; $ gcc -Wall -mno-cygwin -o jvm.exe -I/usr/contrib/java/include -I/usr/contrib/java/include/win32 jvm.c -L. -ljvm $ ./jvm about to call CreateJavaVM. CreateJavaVM returned [0]. step 1 done... step 2... class = 00D654A4 step 3... method = 0982D598 step 4... step 5... Hello, world! $ mv jvm.c.bak jvm.c $ perl -i -pe 's,c:\\\\cygwin\\\\tmp\\\\javatest,c:\\\\test,' jvm.c $ grep 'java.class.path' jvm.c options[0].optionString = "-Djava.class.path=c:\\test"; $ gcc -Wall -mno-cygwin -o jvm.exe -I/usr/contrib/java/include -I/usr/contrib/java/include/win32 jvm.c -L. -ljvm $ ./jvm about to call CreateJavaVM. CreateJavaVM returned [0]. step 1 done... step 2... class = 00000000 step 3... JVMDG217: Dump Handler is Processing a Signal - Please Wait. JVMDG303: JVM Requesting Java core file JVMDG304: Java core file written to C:\cygwin\tmp\javatest\javacore.20040109.171209.3812.txt JVMDG215: Dump Handler has Processed Exception Signal 11. $ The event log says Application popup: jvm.exe - Application Error : The instruction at "0x70b0d7e3" referenced memory at "0x00000060". The memory could not be "read". -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "I have since come to realize that being between your mentor and his route to the bathroom is a major career booster." -- Patrick Naughton ---559023410-1254324197-1073686653=:10405 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="jvm.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="jvm.c" I2luY2x1ZGUgPHN0ZGlvLmg+DQ0KI2luY2x1ZGUgPGpuaS5oPg0NCg0NCg0N CkpOSUVudiogY3JlYXRlX3ZtKCkgew0NCiAgICAgICBKYXZhVk0qIGp2bTsN DQogICAgICAgSk5JRW52KiBlbnY7DQ0KICAgICAgIEphdmFWTUluaXRBcmdz IGFyZ3M7DQ0KICAgICAgIEphdmFWTU9wdGlvbiBvcHRpb25zWzFdOw0NCiAg IGludCByZXM7DQ0KDQ0KDQ0KLyogVGhlcmUgaXMgYSBuZXcgSk5JX1ZFUlNJ T05fMV80LCBidXQgaXQgZG9lc24ndCBhZGQgYW55dGhpbmcgZm9yIHRoZSBw dXJwb3NlcyBvZiBvdXIgZXhhbXBsZS4gKi8NDQphcmdzLnZlcnNpb24gPSBK TklfVkVSU0lPTl8xXzI7DQ0KYXJncy5uT3B0aW9ucyA9IDE7DQ0Kb3B0aW9u c1swXS5vcHRpb25TdHJpbmcgPSAiLURqYXZhLmNsYXNzLnBhdGg9YzpcXGN5 Z3dpblxcdG1wXFxqYXZhdGVzdCI7DQ0KYXJncy5vcHRpb25zID0gb3B0aW9u czsNDQphcmdzLmlnbm9yZVVucmVjb2duaXplZCA9IEpOSV9UUlVFOw0NCg0N CiAgIGZwcmludGYgKHN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XJyYXkoZW52LCAxLCAoKmVudiktPkZpbmRDbGFzcyhl bnYsICJqYXZhL2xhbmcvU3RyaW5nIiksIE5VTEwpOw0NCmFwcGxpY2F0aW9u QXJnMCA9ICgqZW52KS0+TmV3U3RyaW5nVVRGKGVudiwgIkZyb20tQy1wcm9n cmFtIik7DQ0KLy8gKCplbnYpLT5TZXRPYmplY3RBcnJheUVsZW1lbnQoZW52 LCBhcHBsaWNhdGlvbkFyZ3MsIDAsIGFwcGxpY2F0aW9uQXJnMCk7DQ0KDQ0K ZnByaW50ZiAoc3RkZXJyLCAic3RlcCA1Li4uXG4iKTsNDQooKmVudiktPkNh bGxTdGF0aWNWb2lkTWV0aG9kKGVudiwgaGVsbG9Xb3JsZENsYXNzLCBtYWlu TWV0aG9kLCBhcHBsaWNhdGlvbkFyZ3MpOw0NCn0NDQoNDQppbnQgbWFpbihp bnQgYXJnYywgY2hhciAqKmFyZ3YpIHsNDQogICAgICAgSk5JRW52KiBlbnYg PSBjcmVhdGVfdm0oKTsNDQogICBmcHJpbnRmIChzdGRlcnIsICJzdGVwIDEg ZG9uZS4uLlxuIik7DQ0KICAgICAgIGludm9rZV9jbGFzcyggZW52ICk7DQ0K ICAgcmV0dXJuIDA7DQ0KfQ0NCg== ---559023410-1254324197-1073686653=:10405 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ---559023410-1254324197-1073686653=:10405--