Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace004.java
41155 views
/*1* Copyright (c) 2003, 2020, 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/*24* @test25* @key stress26*27* @summary converted from VM testbase nsk/stress/strace/strace004.28* VM testbase keywords: [stress, strace]29* VM testbase readme:30* DESCRIPTION31* The test checks up java.lang.Thread.getAllStackTraces() method for many32* threads, that recursively invoke a native method in running mode33* ("alive" stack).34* The test fails if:35* - amount of stack trace elements is more than depth of recursion plus36* four elements corresponding to invocations of Thread.run(), Thread.wait(),37* Thread.exit(), Thread.yield() and ThreadGroup.remove() methods;38* - there is at least one element corresponding to invocation of unexpected39* method.40* This test is almost the same as nsk.stress.strace.strace003 except for41* checking is performed for java.lang.Thread.getAllStackTraces() method.42* COMMENTS43* java.lang.Thread.getAllStackTraces() is too slow method. So it is not successed44* to catch an alive thread during execution of this method for the first snapshot45* and it is needed to check on a promoted build due to the below assertion.46* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~47* waiting for all threads started ...48* >>> snapshot 149* waiting for threads finished50* # To suppress the following error report, specify this argument51* # after -XX: or in .hotspotrc: SuppressErrorAt=/jniHandles.hpp:15752* #53* # HotSpot Virtual Machine Error, assertion failure54* # Please report this error at55* # http://java.sun.com/cgi-bin/bugreport.cgi56* #57* # Java VM: Java HotSpot(TM) Client VM (1.4.1-internal-debug mixed mode)58* #59* # assert(result != ((oop)::badJNIHandleVal), "Pointing to zapped jni handle area")60* #61* # Error ID: src/share/vm/runtime/jniHandles.hpp, 157 [ Patched ]62* #63* # Problematic Thread: prio=5 tid=0x001976e0 nid=0x96 runnable64* #65* Heap at VM Abort:66* Heap67* def new generation total 2112K, used 455K [0xf1800000, 0xf1a20000, 0xf1f10000)68* eden space 2048K, 22% used [0xf1800000, 0xf1871f60, 0xf1a00000)69* from space 64K, 0% used [0xf1a00000, 0xf1a00000, 0xf1a10000)70* to space 64K, 0% used [0xf1a10000, 0xf1a10000, 0xf1a20000)71* tenured generation total 1408K, used 0K [0xf1f10000, 0xf2070000, 0xf5800000)72* the space 1408K, 0% used [0xf1f10000, 0xf1f10000, 0xf1f10200, 0xf2070000)73* compacting perm gen total 4096K, used 1025K [0xf5800000, 0xf5c00000, 0xf9800000)74* the space 4096K, 25% used [0xf5800000, 0xf5900660, 0xf5900800, 0xf5c00000)75* Dumping core....76* Abort77* Finished at: Fri Apr 25 18:01:37 NSK 200378*79* @library /vmTestbase80* /test/lib81* @run main/othervm/native nsk.stress.strace.strace00482*/8384package nsk.stress.strace;8586import nsk.share.ArgumentParser;87import nsk.share.Log;8889import java.io.PrintStream;90import java.util.Map;9192/**93* The test check up <code>java.lang.Thread.getAllStackTraces()</code> method for many94* threads, that recursively invoke a native method in running mode ("alive" stack).95* <p>96* <p>The test creates <code>THRD_COUNT</code> instances of <code>strace004Thread</code>97* class, tries to get their stack traces and checks up that returned array contains98* correct stack frames. Each stack frame must be corresponded to one of the following99* methods defined by the <code>EXPECTED_METHODS</code> array.</p>100* <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>101*/102public class strace004 {103104static final int DEPTH = 100;105static final int THRD_COUNT = 100;106static final int REPEAT_COUNT = 10;107static final String[] EXPECTED_METHODS = {108"java.lang.System.arraycopy",109"java.lang.Object.wait",110"java.lang.Thread.exit",111"java.lang.Thread.yield",112"java.lang.ThreadGroup.remove",113"java.lang.ThreadGroup.threadTerminated",114"nsk.stress.strace.strace004Thread.run",115"nsk.stress.strace.strace004Thread.recursiveMethod"116};117118119static volatile boolean isLocked = false;120static PrintStream out;121static long waitTime = 2;122123static Object waitStart = new Object();124125static strace004Thread[] threads;126static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];127static Log log;128129volatile int achivedCount = 0;130131public static void main(String[] args) {132out = System.out;133int exitCode = run(args);134System.exit(exitCode + 95);135}136137public static int run(String[] args) {138ArgumentParser argHandler = new ArgumentParser(args);139log = new Log(out, argHandler);140waitTime = argHandler.getWaitTime() * 60000;141142strace004 test = new strace004();143boolean res = true;144145for (int j = 0; j < REPEAT_COUNT; j++) {146test.startThreads();147148if (!test.makeSnapshot(j + 1)) res = false;149150display("waiting for threads finished\n");151test.finishThreads();152}153154if (!res) {155complain("***>>>Test failed<<<***");156return 2;157}158159return 0;160}161162void startThreads() {163threads = new strace004Thread[THRD_COUNT];164achivedCount = 0;165166String tmp_name;167for (int i = 0; i < THRD_COUNT; i++) {168tmp_name = "strace004Thread" + Integer.toString(i);169threads[i] = new strace004Thread(this, tmp_name);170}171172for (int i = 0; i < THRD_COUNT; i++) {173threads[i].start();174}175176waitFor("all threads started ...");177synchronized (waitStart) {178isLocked = true;179waitStart.notifyAll();180}181try {182Thread.yield();183Thread.sleep(1);184} catch (InterruptedException e) {185complain("" + e);186}187}188189void waitFor(String msg) {190if (msg.length() > 0)191display("waiting for " + msg);192193while (achivedCount < THRD_COUNT) {194try {195Thread.sleep(1);196} catch (InterruptedException e) {197complain("" + e);198}199}200achivedCount = 0;201}202203boolean makeSnapshot(int repeat_number) {204205Map traces = Thread.getAllStackTraces();206for (int i = 0; i < threads.length; i++) {207snapshots[i] = (StackTraceElement[]) traces.get(threads[i]);208}209210return checkTraces(repeat_number);211}212213boolean checkTraces(int repeat_number) {214StackTraceElement[] elements;215216boolean res = true;217display(">>> snapshot " + repeat_number);218int expectedCount = DEPTH + 1;219220for (int i = 0; i < threads.length; i++) {221elements = snapshots[i];222223if (elements == null)224continue;225226if (elements.length == 0)227continue;228229if (elements.length > 3) {230display("\tchecking " + threads[i].getName()231+ "(trace elements: " + elements.length + ")");232}233234if (elements.length > expectedCount) {235complain(threads[i].getName() + ">Contains more then " +236+expectedCount + " elements");237}238239for (int j = 0; j < elements.length; j++) {240if (!checkElement(elements[j])) {241complain(threads[i].getName() + ">Unexpected method name: "242+ elements[j].getMethodName());243complain("\tat " + j + " position");244if (elements[j].isNativeMethod()) {245complain("\tline number: (native method)");246complain("\tclass name: " + elements[j].getClassName());247} else {248complain("\tline number: " + elements[j].getLineNumber());249complain("\tclass name: " + elements[j].getClassName());250complain("\tfile name: " + elements[j].getFileName());251}252res = false;253}254}255}256return res;257}258259boolean checkElement(StackTraceElement element) {260String name = element.getClassName() + "." + element.getMethodName();261for (int i = 0; i < EXPECTED_METHODS.length; i++) {262if (EXPECTED_METHODS[i].compareTo(name) == 0)263return true;264}265return false;266}267268void finishThreads() {269try {270for (int i = 0; i < threads.length; i++) {271if (threads[i].isAlive())272threads[i].join(waitTime / THRD_COUNT);273}274} catch (InterruptedException e) {275complain("" + e);276}277isLocked = false;278}279280static void display(String message) {281log.display(message);282}283284static void complain(String message) {285log.complain(message);286}287288}289290class strace004Thread extends Thread {291292private int currentDepth = 0;293294strace004 test;295296static {297try {298System.loadLibrary("strace004");299} catch (UnsatisfiedLinkError e) {300System.err.println("Could not load strace004 library");301System.err.println("java.library.path:"302+ System.getProperty("java.library.path"));303throw e;304}305}306307strace004Thread(strace004 test, String name) {308this.test = test;309setName(name);310}311312public void run() {313314recursiveMethod();315316}317318native void recursiveMethod();319}320321322