source: trunk/openjdk/hotspot/test/runtime/6929067/invoke.c

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

File size: 1.7 KB
Line 
1#include <assert.h>
2#include <jni.h>
3#include <alloca.h>
4
5#include <pthread.h>
6
7union env_union
8{
9 void *void_env;
10 JNIEnv *jni_env;
11};
12
13union env_union tmp;
14JNIEnv* env;
15JavaVM* jvm;
16JavaVMInitArgs vm_args;
17JavaVMOption options[1];
18jclass class_id;
19jmethodID method_id;
20jint result;
21
22long 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}
31
32void *
33floobydust (void *p)
34{
35 (*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL);
36 env = tmp.jni_env;
37
38 class_id = (*env)->FindClass (env, "T");
39 assert (class_id);
40
41 method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V");
42 assert (method_id);
43
44 (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
45
46 (*jvm)->DetachCurrentThread(jvm);
47
48 printf("%ld\n", product(5000,5000));
49
50 (*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL);
51 env = tmp.jni_env;
52
53 class_id = (*env)->FindClass (env, "T");
54 assert (class_id);
55
56 method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V");
57 assert (method_id);
58
59 (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL);
60
61 (*jvm)->DetachCurrentThread(jvm);
62
63 printf("%ld\n", product(5000,5000));
64
65 return NULL;
66}
67
68int
69main (int argc, const char** argv)
70{
71 options[0].optionString = "-Xss320k";
72
73 vm_args.version = JNI_VERSION_1_2;
74 vm_args.ignoreUnrecognized = JNI_TRUE;
75 vm_args.options = options;
76 vm_args.nOptions = 1;
77
78 result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args);
79 assert (result >= 0);
80
81 env = tmp.jni_env;
82
83 floobydust (NULL);
84
85 pthread_t thr;
86 pthread_create (&thr, NULL, floobydust, NULL);
87 pthread_join (thr, NULL);
88
89 return 0;
90}
Note: See TracBrowser for help on using the repository browser.