annotate test/runtime/6929067/invoke.c @ 1320:3b3d12e645e7

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