1 /* 2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 #include <jni.h> 24 #include "jni_tools.h" 25 26 extern "C" { 27 28 #define FIND_CLASS(_class, _className)\ 29 if (!NSK_JNI_VERIFY(env, (_class = \ 30 NSK_CPP_STUB2(FindClass, env, _className)) != NULL))\ 31 return 32 33 #define GET_OBJECT_CLASS(_class, _obj)\ 34 if (!NSK_JNI_VERIFY(env, (_class = \ 35 NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\ 36 return 37 38 #define GET_OBJ_FIELD(_value, _obj, _class, _fieldName, _fieldSig)\ 39 GET_FIELD_ID(field, _class, _fieldName, _fieldSig);\ 40 _value = NSK_CPP_STUB3(GetObjectField, env, _obj, field) 41 42 #define GET_FIELD_ID(_fieldID, _class, _fieldName, _fieldSig)\ 43 if (!NSK_JNI_VERIFY(env, (_fieldID = \ 44 NSK_CPP_STUB4(GetFieldID, env, _class,\ 45 _fieldName, _fieldSig)) != NULL))\ 46 return 47 48 #define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\ 49 if (!NSK_JNI_VERIFY(env, (_methodID = \ 50 NSK_CPP_STUB4(GetMethodID, env, _class,\ 51 _methodName, _sig)) != NULL))\ 52 return 53 54 #define CALL_VOID_NOPARAM(_obj, _class, _methodName)\ 55 GET_METHOD_ID(method, _class, _methodName, "()V");\ 56 if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\ 57 method)))\ 58 return 59 /* 60 * Class: nsk_monitoring_share_thread_LockingThreads_Thread1 61 * Method: B 62 * Signature: ()V 63 */ 64 JNIEXPORT void JNICALL Java_nsk_monitoring_share_thread_LockingThreads_00024Thread1_B 65 (JNIEnv *env, jobject o) { 66 jclass testBugClass, threadClass; 67 jobject lock4, lock5; 68 jfieldID field; 69 jmethodID method; 70 71 GET_OBJECT_CLASS(threadClass, o); 72 FIND_CLASS(testBugClass, "nsk/share/TestBug"); 73 GET_OBJ_FIELD(lock4, o, threadClass, "lock4", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); 74 GET_OBJ_FIELD(lock5, o, threadClass, "lock5", "Lnsk/monitoring/share/thread/LockingThreads$CustomLock;"); 75 if (env->MonitorEnter(lock4) == JNI_OK) { 76 if (env->MonitorEnter(lock5) == JNI_OK) { 77 CALL_VOID_NOPARAM(o, threadClass, "C"); 78 env->MonitorExit(lock5); 79 } else 80 env->ThrowNew(testBugClass, "MonitorEnter(lock5) call failed"); 81 env->MonitorExit(lock4); 82 } else 83 env->ThrowNew(testBugClass, "MonitorEnter(lock4) call failed"); 84 } 85 86 }