Debian Codegraph @

project/debug/unix/staticJVM.cpp

raw
1 #if defined(_HPUX) && !defined(_IA64)
2 #include <dl.h>
3 #else
4 #include <dlfcn.h>
5 #endif // HPUX
6 #include <errno.h>
7 #include <string>
8 #include <cstring>
9 #include <cstdio>
10 #include <sstream>
11 //#include <jni.h>
12 #include "../../../native/jni_include/jni.h"
13
14 #define USE_JNI_VERSION JNI_VERSION_1_4
15 JavaVM *jvm;
16
17 int main(int argc, char** argv)
18 {
19 if (argc < 1)
20 {
21 printf("Usage: %s [JVM_ARGS]\n", argv[0]);
22 exit(-1);
23 }
24
25 // Pack the arguments
26 printf("Pack JVM arguments\n");
27 JavaVMInitArgs jniArgs;
28 jniArgs.options = NULL;
29 jniArgs.version = USE_JNI_VERSION;
30 jniArgs.ignoreUnrecognized = false;
31 jniArgs.nOptions = (jint) argc - 1;
32 printf(" Num options: %d\n", jniArgs.nOptions);
33 jniArgs.options = (JavaVMOption*) malloc(sizeof (JavaVMOption) * jniArgs.nOptions);
34 memset(jniArgs.options, 0, sizeof (JavaVMOption) * jniArgs.nOptions);
35 for (int i = 0; i < jniArgs.nOptions; i++)
36 {
37 printf(" Option %s\n", argv[i + 1]);
38 jniArgs.options[i].optionString = (char*) argv[i + 1];
39 }
40
41 // Launch the JVM
42 printf("Create JVM\n");
43 JNIEnv* env;
44 jint rc = JNI_CreateJavaVM(&jvm, (JNIEnv**) &env, (void*) &jniArgs);
45 free(jniArgs.options);
46 if (rc != JNI_OK)
47 {
48 printf(" Create JVM failed. (%d)\n", rc);
49 exit(-1);
50 }
51
52 // Create some resources
53 printf("Create Java resources\n");
54 jclass cls = env->FindClass("java/lang/Object");
55 jmethodID mth = env->GetMethodID(cls, "toString", "()Ljava/lang/String;");
56 mth = env->GetMethodID(cls, "equals", "(Ljava/lang/Object;)Z");
57 mth = env->GetMethodID(cls, "hashCode", "()I");
58 mth = env->GetMethodID(cls, "getClass", "()Ljava/lang/Class;");
59
60
61 // Destroy the JVM
62 printf("Destroy JVM\n");
63 jvm->DestroyJavaVM();
64
65 printf("Success\n");
66 }