Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace006.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/strace006";2930static jclass testClass, threadClass;31static jint DEPTH;32static jclass stackOverflowErrorClass;3334JNIEXPORT jint JNICALL35JNI_OnLoad(JavaVM *vm, void *reserved)36{37JNIEnv *env;3839if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {40printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);41return 0;42}4344FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError");45stackOverflowErrorClass = (jclass) env->NewGlobalRef(stackOverflowErrorClass);46if (stackOverflowErrorClass == NULL) {47printf("Can't create global ref for stack overflow class\n");48return 0;49}5051return JNI_VERSION;52}5354JNIEXPORT void JNICALL55JNI_OnUnload(JavaVM *vm, void *reserved)56{57JNIEnv *env;5859if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {60if (stackOverflowErrorClass != NULL) {61env->DeleteGlobalRef(stackOverflowErrorClass);62}63} else {64printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);65}6667}6869JNIEXPORT void JNICALL70Java_nsk_stress_strace_strace006Thread_recursiveMethod2(JNIEnv *env, jobject obj)71{72jfieldID field;73jmethodID method;74jint currDepth;75jclass testClass, threadClass;76jint maxDepth;7778FIND_CLASS(testClass, Stest_cn);79GET_OBJECT_CLASS(threadClass, obj);8081GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH");8283/* currDepth++ */84GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth");85currDepth++;86SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);8788if (maxDepth - currDepth > 0)89{90GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V");91env->CallStaticVoidMethod(threadClass, method);92EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);9394GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V");95env->CallVoidMethod(obj, method);96EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);97}9899currDepth--;100GET_OBJECT_CLASS(threadClass, obj);101SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);102}103104}105106107