Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.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"25#include "nsk_tools.h"2627extern "C" {2829static const char *Stest_cn="nsk/stress/strace/strace005";30static jclass stackOverflowErrorClass;3132JNIEXPORT jint JNICALL33JNI_OnLoad(JavaVM *vm, void *reserved)34{35JNIEnv *env;3637if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {38printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);39return 0;40}4142FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError");43stackOverflowErrorClass = (jclass) env->NewGlobalRef(stackOverflowErrorClass);44if (stackOverflowErrorClass == NULL) {45printf("Can't create global ref for stack overflow class\n");46return 0;47}4849return JNI_VERSION;50}5152JNIEXPORT void JNICALL53JNI_OnUnload(JavaVM *vm, void *reserved)54{55JNIEnv *env;5657if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {58if (stackOverflowErrorClass != NULL) {59env->DeleteGlobalRef(stackOverflowErrorClass);60}61} else {62printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);63}6465}6667JNIEXPORT void JNICALL68Java_nsk_stress_strace_strace005Thread_recursiveMethod2(JNIEnv *env, jobject obj)69{70jfieldID field;71jmethodID method;72jint currDepth;73jclass testClass, threadClass;74jint maxDepth;7576FIND_CLASS(testClass, Stest_cn);77GET_OBJECT_CLASS(threadClass, obj);7879GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH");8081/* currDepth++ */82GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth");83currDepth++;84SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);858687if (maxDepth - currDepth > 0)88{89GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V");90env->CallStaticVoidMethod(threadClass, method);91EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);9293GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V");94env->CallVoidMethod(obj, method);95EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);96}9798currDepth--;99GET_OBJECT_CLASS(threadClass, obj);100SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);101}102103}104105106