Mail Archives: cygwin/2004/01/09/17:46:37
Thanks a lot, Igor! Adding the full path to dlltool worked.
I'm still a bit puzzled, since I would've thought if it couldn't find
the DLL it would choke on either the libjvm.dll.a build or the
compile.
Thanks again.
Moy
I don't think my mailer handles references right, but this note is
part of the following thread:
http://cygwin.com/ml/cygwin/2004-01/msg00190.html
http://cygwin.com/ml/cygwin/2004-01/msg00191.html
http://cygwin.com/ml/cygwin/2004-01/msg00194.html
Igor Pechtchanski
<pechtcha AT cs DOT nyu DOT edu> T
To: Moy Easwaran <easwarm AT nationwide DOT com>
cc: cygwin AT cygwin DOT com
bcc:
01/09/2004 05:17 PM Subject: Re: Problem with JVM 1.4.2 on
Please respond to Cygwin 1.5.5-1 on XP and 2000
cygwin
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
> <http://www.inonit.com/cygwin/jni/invocationApi/> 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 <stdio.h>
> #include <jni.h>
>
> 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
Attachment(s) have been removed:
jvm.c
--
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/
- Raw text -