Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.cpp
41155 views
/*1* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <stdio.h>24#include "nsk_strace.h"2526extern "C" {2728static const char *Stest_cn="nsk/stress/strace/strace003";29static const char *Slongparam="(J)V";3031JNIEXPORT void JNICALL32Java_nsk_stress_strace_strace003Thread_recursiveMethod(JNIEnv *env, jobject obj)33{34jfieldID field;35jmethodID method;36jint currDepth;37jclass testClass, threadClass, objClass;38jint maxDepth;39jboolean isLocked;40jint achivedCount;41jobject testField, waitStart;4243FIND_CLASS(testClass, Stest_cn);44FIND_CLASS(objClass, "java/lang/Object");45GET_OBJECT_CLASS(threadClass, obj);4647/* currDepth++ */48GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth");49currDepth++;50SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);5152if (currDepth == 1)53{54GET_OBJ_FIELD(testField, obj, threadClass, "test",55"Lnsk/stress/strace/strace003;");5657GET_STATIC_OBJ_FIELD(waitStart, testClass, "waitStart",58"Ljava/lang/Object;");5960MONITOR_ENTER(testField);61GET_INT_FIELD(achivedCount, testField, testClass, "achivedCount");62achivedCount++;63SET_INT_FIELD(testField, testClass, "achivedCount", achivedCount);64MONITOR_EXIT(testField);6566GET_STATIC_BOOL_FIELD(isLocked, testClass, "isLocked");67while (isLocked != JNI_TRUE)68{69MONITOR_ENTER(waitStart);70CALL_VOID(waitStart, objClass, "wait", Slongparam, 1LL);71MONITOR_EXIT(waitStart);72GET_STATIC_BOOL_FIELD(isLocked, testClass, "isLocked");73}74}7576GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH");7778if (maxDepth - currDepth > 0)79{80CALL_STATIC_VOID_NOPARAM(threadClass, "yield");81CALL_VOID_NOPARAM(obj, threadClass, "recursiveMethod");82}8384currDepth--;85GET_OBJECT_CLASS(threadClass, obj);86SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);87}8889}909192