This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Could you please check this into 3.0.1, too?


Tom Tromey wrote:

>Martin> PS: Has there been any progress in the implementation of the
>Martin>     invocation API?
>
>Nope.  Nobody is working on it.
>

So pessimistic, Tom! ;-)

The invocation interface is now implemented and does actually work. It 
may well need some more testing and debugging, but a simple example like 
the following does run:

// invoke.cpp

#include <jni.h>

int main(int argc, char **argv)
{
  JavaVM *jvm;
  JNIEnv *env;

  JavaVMInitArgs vm_args;

  vm_args.version = JNI_VERSION_1_2;
  JNI_GetDefaultJavaVMInitArgs(&vm_args);

  JNI_CreateJavaVM(&jvm, &env, &vm_args);

  jclass cls = env->FindClass("Test");
  jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
  env->CallStaticVoidMethod(cls, mid, 567);

  jvm->DestroyJavaVM();
}

public class Test
{
  public static void test(int i)
  {
    System.out.println ("Hello from Java: " + i);
  }
}

$ gcj -c Test.java
$ gcj Test.o invoke.cpp -fjni -o invoke -I /home/bryce/gcc/include/ -g
$ ./invoke
Hello from Java: 567


It may work even better if JNI_CreateJavaVM actually called 
_Jv_CreateJavaVM from somewhere ;-)

regards

Bryce.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]