test/runtime/6929067/invoke.c

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

     1 #include <assert.h>
     2 #include <jni.h>
     3 #include <alloca.h>
     5 #include <pthread.h>
     7 union env_union
     8 {
     9   void *void_env;
    10   JNIEnv *jni_env;
    11 };
    13 union env_union tmp;
    14 JNIEnv* env;
    15 JavaVM* jvm;
    16 JavaVMInitArgs vm_args;
    17 JavaVMOption options[1];
    18 jclass class_id;
    19 jmethodID method_id;
    20 jint result;
    22 long product(unsigned long n, unsigned long m) {
    23     if (m == 1) {
    24       return n;
    25     } else {
    26       int *p = alloca(sizeof (int));
    27       *p = n;
    28       return product (n, m-1) + *p;
    29     }
    30 }
    32 void *
    33 floobydust (void *p)
    34 {
    35   (*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL);
    36   env = tmp.jni_env;
    38   class_id = (*env)->FindClass (env, "T");
    39   assert (class_id);
    41   method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V");
    42   assert (method_id);
    44   (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
    46   (*jvm)->DetachCurrentThread(jvm);
    48   printf("%ld\n", product(5000,5000));
    50   (*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL);
    51   env = tmp.jni_env;
    53   class_id = (*env)->FindClass (env, "T");
    54   assert (class_id);
    56   method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V");
    57   assert (method_id);
    59   (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
    61   (*jvm)->DetachCurrentThread(jvm);
    63   printf("%ld\n", product(5000,5000));
    65   return NULL;
    66 }
    68 int
    69 main (int argc, const char** argv)
    70 {
    71   options[0].optionString = "-Xss320k";
    73   vm_args.version = JNI_VERSION_1_2;
    74   vm_args.ignoreUnrecognized = JNI_TRUE;
    75   vm_args.options = options;
    76   vm_args.nOptions = 1;
    78   result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args);
    79   assert (result >= 0);
    81   env = tmp.jni_env;
    83   floobydust (NULL);
    85   pthread_t thr;
    86   pthread_create (&thr, NULL, floobydust, NULL);
    87   pthread_join (thr, NULL);
    89   return 0;
    90 }

mercurial