/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @key stress
*
* @summary converted from VM testbase nsk/stress/strace/strace006.
* VM testbase keywords: [stress, strace]
* VM testbase readme:
* DESCRIPTION
* The test checks up java.lang.Thread.getAllStackTraces() method for many
* threads, that recursively invoke pure java and native methods by turns
* in running mode ("alive" stack).
* The test fails if:
* - amount of stack trace elements is more than depth of recursion plus
* four elements corresponding to invocations of Thread.run(), Thread.wait(),
* Thread.exit(), Thread.yield() and ThreadGroup.remove() methods;
* - there is at least one element corresponding to invocation of unexpected
* method.
* This test is almost the same as nsk.stress.strace.strace005 except for
* checking is performed for java.lang.Thread.getAllStackTraces() method.
* COMMENTS
* Similar assertion is thrown (see strace005.README).
*
* @library /vmTestbase
* /test/lib
* @run driver jdk.test.lib.FileInstaller . .
* @run main/othervm/native nsk.stress.strace.strace006
*/
package nsk.stress.strace;
import nsk.share.ArgumentParser;
import nsk.share.Failure;
import nsk.share.Log;
import java.io.PrintStream;
import java.util.Map;
/**
* The test check up java.lang.Thread.getStackTrace()
method for the pure
* java recursion.
*
The test creates THRD_COUNT
instances of strace006Thread
* class, tries to get their stack traces and checks up that returned array contains
* correct stack frames. Each stack frame must be corresponded to one of the following
* methods defined by the expectedMethod
array.
These checking are performed REPEAT_COUNT
times.
strace006Thread
class and tries
* to get their stack traces.
*/
class strace006Thread extends Thread {
private int currentDepth = 0;
public boolean isNativeResolved = false;
strace006 test;
static {
try {
System.loadLibrary("strace006");
} catch (UnsatisfiedLinkError e) {
System.err.println("Could not load strace006 library");
System.err.println("java.library.path:"
+ System.getProperty("java.library.path"));
throw e;
}
}
strace006Thread(strace006 test, String name) {
this.test = test;
setName(name);
}
public void run() {
recursiveMethod1();
}
void recursiveMethod1() {
currentDepth++;
if (currentDepth == 1) {
synchronized (test) {
test.achivedCount++;
}
int alltime = 0;
while (!strace006.isLocked) {
synchronized (test) {
try {
test.wait(1);
alltime++;
} catch (InterruptedException e) {
strace006.complain("" + e);
}
if (alltime > strace006.waitTime) {
throw new Failure("out of wait time");
}
}
}
} else if (currentDepth > 1 && !isNativeResolved)
isNativeResolved = true;
if (strace006.DEPTH - currentDepth > 0) {
try {
Thread.yield();
recursiveMethod2();
} catch (StackOverflowError e) {
// ignore this exception
}
}
currentDepth--;
}
native void recursiveMethod2();
}