author | dsamersoff |
Sun, 31 Mar 2013 23:47:55 +0400 | |
changeset 18218 | 42b9377e6462 |
parent 5085 | 4f0c435f8c3c |
permissions | -rw-r--r-- |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
1 |
#include <assert.h> |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
2 |
#include <jni.h> |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
3 |
#include <alloca.h> |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
4 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
5 |
#include <pthread.h> |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
6 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
7 |
union env_union |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
8 |
{ |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
9 |
void *void_env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
10 |
JNIEnv *jni_env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
11 |
}; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
12 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
13 |
union env_union tmp; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
14 |
JNIEnv* env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
15 |
JavaVM* jvm; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
16 |
JavaVMInitArgs vm_args; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
17 |
JavaVMOption options[1]; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
18 |
jclass class_id; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
19 |
jmethodID method_id; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
20 |
jint result; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
21 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
22 |
long product(unsigned long n, unsigned long m) { |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
23 |
if (m == 1) { |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
24 |
return n; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
25 |
} else { |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
26 |
int *p = alloca(sizeof (int)); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
27 |
*p = n; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
28 |
return product (n, m-1) + *p; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
29 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
30 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
31 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
32 |
void * |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
33 |
floobydust (void *p) |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
34 |
{ |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
35 |
(*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
36 |
env = tmp.jni_env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
37 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
38 |
class_id = (*env)->FindClass (env, "T"); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
39 |
assert (class_id); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
40 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
41 |
method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V"); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
42 |
assert (method_id); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
43 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
44 |
(*env)->CallStaticVoidMethod (env, class_id, method_id, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
45 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
46 |
(*jvm)->DetachCurrentThread(jvm); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
47 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
48 |
printf("%ld\n", product(5000,5000)); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
49 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
50 |
(*jvm)->AttachCurrentThread(jvm, &tmp.void_env, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
51 |
env = tmp.jni_env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
52 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
53 |
class_id = (*env)->FindClass (env, "T"); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
54 |
assert (class_id); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
55 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
56 |
method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V"); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
57 |
assert (method_id); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
58 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
59 |
(*env)->CallStaticVoidMethod (env, class_id, method_id, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
60 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
61 |
(*jvm)->DetachCurrentThread(jvm); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
62 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
63 |
printf("%ld\n", product(5000,5000)); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
64 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
65 |
return NULL; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
66 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
67 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
68 |
int |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
69 |
main (int argc, const char** argv) |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
70 |
{ |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
71 |
options[0].optionString = "-Xss320k"; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
72 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
73 |
vm_args.version = JNI_VERSION_1_2; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
74 |
vm_args.ignoreUnrecognized = JNI_TRUE; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
75 |
vm_args.options = options; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
76 |
vm_args.nOptions = 1; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
77 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
78 |
result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
79 |
assert (result >= 0); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
80 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
81 |
env = tmp.jni_env; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
82 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
83 |
floobydust (NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
84 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
85 |
pthread_t thr; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
86 |
pthread_create (&thr, NULL, floobydust, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
87 |
pthread_join (thr, NULL); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
88 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
89 |
return 0; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
diff
changeset
|
90 |
} |