/*
* 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/strace015.
* VM testbase keywords: [stress, strace, quarantine]
* VM testbase comments: 8199581
* VM testbase readme:
* DESCRIPTION
* The test runs many threads, that recursively invoke pure java and native
* method by turns. After arriving at defined depth of recursion, each thread
* is switched to waits for a monitor. Then the test calls
* java.lang.Thread.getStackTrace() and java.lang.Thread.getAllStackTraces()
* methods and checks their results.
* The test fails if:
* - amount of stack trace elements and stack trace elements themselves are
* the same for both methods;
* - there is at least one element corresponding to invocation of unexpected
* method. Expected methods are Thread.sleep(), Thread.run() and the
* recursive method.
* This test is almost the same as nsk.stress.strace.strace013 except for
* recursion is presented by pure java and native method invocation.
*
* @library /vmTestbase
* /test/lib
* @run driver jdk.test.lib.FileInstaller . .
* @run main/othervm/native nsk.stress.strace.strace015
*/
package nsk.stress.strace;
import nsk.share.ArgumentParser;
import nsk.share.Log;
import java.io.PrintStream;
import java.util.Map;
/**
* The test runs THRD_COUNT
instances of strace010Thread
,
* that recursively invoke pure java and native method by turns. After arriving at
* defined depth DEPTH
of recursion, each thread is switched to wait
* a monitor. Then the test calls java.lang.Thread.getStackTrace()
and
* java.lang.Thread.getAllStackTraces()
methods and checks their results.
*
*
It is expected that these methods return the same stack traces. Each stack frame
* for both stack traces must be corresponded to invocation of one of the methods
* defined by the EXPECTED_METHODS
array.
strace015Thread
class and tries
* to get their stack traces.
*/
class strace015Thread extends Thread {
private int currentDepth = 0;
strace015 test;
static {
try {
System.loadLibrary("strace015");
} catch (UnsatisfiedLinkError e) {
System.err.println("Could not load strace015 library");
System.err.println("java.library.path:"
+ System.getProperty("java.library.path"));
throw e;
}
}
strace015Thread(strace015 test, String name) {
this.test = test;
setName(name);
}
public void run() {
recursiveMethod1();
}
void recursiveMethod1() {
currentDepth++;
if (strace015.DEPTH - currentDepth > 0) {
recursiveMethod2();
}
if (strace015.DEPTH == currentDepth) {
strace015.display(getName() + ">waiting on a monitor");
synchronized (test) {
test.achivedCount++;
}
synchronized (strace015.lockedObject) {
try {
strace015.lockedObject.wait();
} catch (InterruptedException e) {
strace015.complain("" + e);
}
}
strace015.display(getName() + ">notified");
}
currentDepth--;
}
native void recursiveMethod2();
}