author | iignatyev |
Tue, 28 Aug 2018 14:37:34 -0700 | |
changeset 51551 | e409244ce72e |
parent 49934 | test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c@44839fbb20db |
child 51634 | 3f189f451ff1 |
permissions | -rw-r--r-- |
49934
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
1 |
/* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
4 |
* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
8 |
* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
13 |
* accompanied this code). |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
14 |
* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
18 |
* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
21 |
* questions. |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
22 |
*/ |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
23 |
#include "jni.h" |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
24 |
#include "nsk_tools.h" |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
25 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
26 |
#ifdef __cplusplus |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
27 |
extern "C" { |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
28 |
#endif |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
29 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
30 |
#ifndef JNI_ENV_PTR |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
31 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
32 |
#ifdef __cplusplus |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
33 |
#define JNI_ENV_ARG_2(x, y) y |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
34 |
#define JNI_ENV_ARG_3(x, y, z) y, z |
51551 | 35 |
#define JNI_ENV_ARG_4(x, y, z, a) y, z, a |
49934
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
36 |
#define JNI_ENV_PTR(x) x |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
37 |
#else |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
38 |
#define JNI_ENV_ARG_2(x,y) x, y |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
39 |
#define JNI_ENV_ARG_3(x, y, z) x, y, z |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
40 |
#define JNI_ENV_ARG_4(x, y, z, a) x, y, z, a |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
41 |
#define JNI_ENV_PTR(x) (*x) |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
42 |
#endif |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
43 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
44 |
#endif |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
45 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
46 |
JNIEXPORT void JNICALL |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
47 |
Java_nsk_share_locks_JNIMonitorLocker_doLock(JNIEnv *env, jobject thisObject) |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
48 |
{ |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
49 |
/* |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
50 |
This method executes JNI analog for following Java code: |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
51 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
52 |
JNI_MonitorEnter(this); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
53 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
54 |
step1.unlockAll(); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
55 |
step2.waitFor(); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
56 |
readyWicket.unlock(); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
57 |
inner.lock(); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
58 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
59 |
JNI_MonitorExit(this); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
60 |
*/ |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
61 |
jint success; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
62 |
jfieldID field; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
63 |
jclass thisObjectClass; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
64 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
65 |
// fields 'step1' and 'step2' |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
66 |
jobject wicketObject; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
67 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
68 |
// class for fields 'step1', 'step2', 'readyWicket' |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
69 |
jclass wicketClass; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
70 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
71 |
// field 'inner' |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
72 |
jobject innerObject; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
73 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
74 |
// class for field 'inner' |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
75 |
jclass deadlockLockerClass; |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
76 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
77 |
success = JNI_ENV_PTR(env)->MonitorEnter(JNI_ENV_ARG_2(env, thisObject)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
78 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
79 |
if(success != 0) |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
80 |
{ |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
81 |
NSK_COMPLAIN1("MonitorEnter return non-zero: %d\n", success); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
82 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
83 |
JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorEnter return non-zero")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
84 |
} |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
85 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
86 |
thisObjectClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, thisObject)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
87 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
88 |
// step1.unlockAll() |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
89 |
field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step1", "Lnsk/share/Wicket;")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
90 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
91 |
wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
92 |
wicketClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, wicketObject)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
93 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
94 |
JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlockAll", "()V")))); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
95 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
96 |
// step2.waitFor() |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
97 |
field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "step2", "Lnsk/share/Wicket;")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
98 |
wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
99 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
100 |
JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "waitFor", "()V")))); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
101 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
102 |
// readyWicket.unlock() |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
103 |
field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "readyWicket", "Lnsk/share/Wicket;")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
104 |
wicketObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
105 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
106 |
JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, wicketObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, wicketClass, "unlock", "()V")))); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
107 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
108 |
// inner.lock() |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
109 |
field = JNI_ENV_PTR(env)->GetFieldID(JNI_ENV_ARG_4(env, thisObjectClass, "inner", "Lnsk/share/locks/DeadlockLocker;")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
110 |
innerObject = JNI_ENV_PTR(env)->GetObjectField(JNI_ENV_ARG_3(env, thisObject, field)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
111 |
deadlockLockerClass = JNI_ENV_PTR(env)->GetObjectClass(JNI_ENV_ARG_2(env, innerObject)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
112 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
113 |
JNI_ENV_PTR(env)->CallVoidMethod(JNI_ENV_ARG_3(env, innerObject, JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG_4(env, deadlockLockerClass, "lock", "()V")))); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
114 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
115 |
success = JNI_ENV_PTR(env)->MonitorExit(JNI_ENV_ARG_2(env, thisObject)); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
116 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
117 |
if(success != 0) |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
118 |
{ |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
119 |
NSK_COMPLAIN1("MonitorExit return non-zero: %d\n", success); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
120 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
121 |
JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG_3(env, JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG_2(env, "nsk/share/TestJNIError")), "MonitorExit return non-zero")); |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
122 |
} |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
123 |
} |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
124 |
|
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
125 |
#ifdef __cplusplus |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
126 |
} |
44839fbb20db
8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff
changeset
|
127 |
#endif |