author | anoll |
Tue, 24 Sep 2013 15:56:25 +0200 | |
changeset 20072 | 6da61000acff |
parent 19694 | 84bcddefd0d7 |
permissions | -rw-r--r-- |
19694
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
1 |
/* |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
4 |
* |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
8 |
* |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
13 |
* accompanied this code). |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
14 |
* |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
18 |
* |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
21 |
* questions. |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
22 |
*/ |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
23 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
24 |
#include <assert.h> |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
25 |
#include <jni.h> |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
26 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
27 |
#include <pthread.h> |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
28 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
29 |
JavaVM* jvm; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
30 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
31 |
void * |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
32 |
floobydust (void *p) { |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
33 |
JNIEnv *env; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
34 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
35 |
jvm->AttachCurrentThread((void**)&env, NULL); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
36 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
37 |
jclass class_id = env->FindClass ("DoOverflow"); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
38 |
assert (class_id); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
39 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
40 |
jmethodID method_id = env->GetStaticMethodID(class_id, "printIt", "()V"); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
41 |
assert (method_id); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
42 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
43 |
env->CallStaticVoidMethod(class_id, method_id, NULL); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
44 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
45 |
jvm->DetachCurrentThread(); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
46 |
} |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
47 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
48 |
int |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
49 |
main (int argc, const char** argv) { |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
50 |
JavaVMOption options[1]; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
51 |
options[0].optionString = (char*) "-Xss320k"; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
52 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
53 |
JavaVMInitArgs vm_args; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
54 |
vm_args.version = JNI_VERSION_1_2; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
55 |
vm_args.ignoreUnrecognized = JNI_TRUE; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
56 |
vm_args.options = options; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
57 |
vm_args.nOptions = 1; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
58 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
59 |
JNIEnv* env; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
60 |
jint result = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
61 |
assert(result >= 0); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
62 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
63 |
pthread_t thr; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
64 |
pthread_create(&thr, NULL, floobydust, NULL); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
65 |
pthread_join(thr, NULL); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
66 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
67 |
floobydust(NULL); |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
68 |
|
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
69 |
return 0; |
84bcddefd0d7
8009062: poor performance of JNI AttachCurrentThread after fix for 7017193
dsamersoff
parents:
diff
changeset
|
70 |
} |