/*
* Copyright (c) 2003, 2023, 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/strace011.
* VM testbase keywords: [stress, quick, strace]
* VM testbase readme:
* DESCRIPTION
* The test runs many threads, that recursively invoke a native method.
* After arriving at defined depth of recursion, each thread is blocked
* on entering 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.010 except for
* the recursive method is a native one.
*
* @library /vmTestbase
* /test/lib
* @run main/othervm/native nsk.stress.strace.strace011
*/
package nsk.stress.strace;
import java.util.Map;
/**
* The test runs THRD_COUNT
instances of strace011Thread
,
* that recursively invoke a native method. After arriving at defined depth
* DEPTH
of recursion, each thread is blocked on entering a monitor.
* Then the test calls java.lang.Thread.getStackTrace()
and
* java.lang.Thread.getAllStackTraces()
methods and checks their results.
*
*/
public class strace011 extends StraceBase {
static final int DEPTH = 100;
static final int THRD_COUNT = 50;
public static Object lockedObject = new Object();
static volatile boolean isLocked = false;
static volatile int achivedCount = 0;
strace011Thread[] threads;
public static void main(String[] args) {
strace011 test = new strace011();
test.startThreads();
boolean res = test.makeSnapshot();
test.finishThreads();
if (!res) {
new RuntimeException("***>>>Test failed<<<***");
}
display(">>>Test passed<<<");
}
void startThreads() {
threads = new strace011Thread[THRD_COUNT];
achivedCount = 0;
String tmp_name;
display("starting threads...");
for (int i = 0; i < THRD_COUNT; i++) {
tmp_name = "strace011Thread" + Integer.toString(i);
threads[i] = new strace011Thread(this, tmp_name);
threads[i].start();
}
waitFor("the defined recursion depth ...");
}
void waitFor(String msg) {
if (msg.length() > 0)
display("waiting for " + msg);
while (achivedCount < THRD_COUNT) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
complain("" + e);
}
}
achivedCount = 0;
}
boolean makeSnapshot() {
Map