Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.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*/222324/*25* @test26* @key stress27*28* @summary converted from VM testbase nsk/stress/strace/strace003.29* VM testbase keywords: [stress, strace]30* VM testbase readme:31* DESCRIPTION32* The test checks up java.lang.Thread.getStackTrace() method for many threads,33* that recursively invoke a native method in running mode ("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.strace001 except for41* the recursive method is a native one.42* COMMENTS43* Below assertion is revealed on engineer's build. It is needed to check44* on a promoted build.45* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~46* Started at: Fri Apr 25 15:47:13 NSK 200347* waiting for all threads started ...48* >>> snapshot 149* checking strace003Thread0(trace elements: 2)50* checking strace003Thread1(trace elements: 2)51* checking strace003Thread2(trace elements: 3)52* checking strace003Thread3(trace elements: 2)53* checking strace003Thread4(trace elements: 2)54* checking strace003Thread5(trace elements: 2)55* checking strace003Thread6(trace elements: 3)56* checking strace003Thread7(trace elements: 2)57* # To suppress the following error report, specify this argument58* # after -XX: or in .hotspotrc: SuppressErrorAt=/jniHandles.hpp:15759* #60* # HotSpot Virtual Machine Error, assertion failure61* # Please report this error at62* # http://java.sun.com/cgi-bin/bugreport.cgi63* #64* # Java VM: Java HotSpot(TM) Client VM (1.4.1-internal-debug mixed mode)65* #66* # assert(result != ((oop)::badJNIHandleVal), "Pointing to zapped jni handle area")67* #68* # Error ID: src/share/vm/runtime/jniHandles.hpp, 157 [ Patched ]69* #70* # Problematic Thread: prio=5 tid=0x001b99e8 nid=0xbf runnable71* #72* Heap at VM Abort:73* Heap74* def new generation total 2112K, used 300K [0xf1800000, 0xf1a20000, 0xf1f10000)75* eden space 2048K, 14% used [0xf1800000, 0xf184b358, 0xf1a00000)76* from space 64K, 0% used [0xf1a00000, 0xf1a00000, 0xf1a10000)77* to space 64K, 0% used [0xf1a10000, 0xf1a10000, 0xf1a20000)78* tenured generation total 1408K, used 0K [0xf1f10000, 0xf2070000, 0xf5800000)79* the space 1408K, 0% used [0xf1f10000, 0xf1f10000, 0xf1f10200, 0xf2070000)80* compacting perm gen total 4096K, used 1024K [0xf5800000, 0xf5c00000, 0xf9800000)81* the space 4096K, 25% used [0xf5800000, 0xf5900240, 0xf5900400, 0xf5c00000)82* Dumping core....83* Abort84* Finished at: Fri Apr 25 15:48:10 NSK 200385* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~86*87* @library /vmTestbase88* /test/lib89* @run main/othervm/native nsk.stress.strace.strace00390*/9192package nsk.stress.strace;9394import nsk.share.ArgumentParser;95import nsk.share.Log;9697import java.io.PrintStream;9899/**100* The test check up <code>java.lang.Thread.getStackTrace()</code> method for many threads,101* that recursively invoke a native method in running mode ("alive" stack).102* <p>103* <p>The test creates <code>THRD_COUNT</code> instances of <code>strace003Thread</code>104* class, tries to get their stack traces and checks up that returned array contains105* correct stack frames. Each stack frame must be corresponded to one of the following106* methods defined by the <code>EXPECTED_METHODS</code> array.</p>107* <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>108*/109public class strace003 {110111static final int DEPTH = 100;112static final int THRD_COUNT = 100;113static final int REPEAT_COUNT = 10;114static final String[] EXPECTED_METHODS = {115"java.lang.System.arraycopy",116"java.lang.Object.wait",117"java.lang.Thread.exit",118"java.lang.Thread.yield",119"java.lang.ThreadGroup.remove",120"java.lang.ThreadGroup.threadTerminated",121"nsk.stress.strace.strace003Thread.run",122"nsk.stress.strace.strace003Thread.recursiveMethod"123};124125126static volatile boolean isLocked = false;127static PrintStream out;128static long waitTime = 2;129130static Object waitStart = new Object();131132static strace003Thread[] threads;133static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];134static Log log;135136volatile int achivedCount = 0;137138public static void main(String[] args) {139out = System.out;140int exitCode = run(args);141System.exit(exitCode + 95);142}143144public static int run(String[] args) {145ArgumentParser argHandler = new ArgumentParser(args);146log = new Log(out, argHandler);147waitTime = argHandler.getWaitTime() * 60000;148149strace003 test = new strace003();150boolean res = true;151152for (int j = 0; j < REPEAT_COUNT; j++) {153test.startThreads();154155if (!test.makeSnapshot(j + 1)) res = false;156157display("waiting for threads finished\n");158test.finishThreads();159}160161if (!res) {162complain("***>>>Test failed<<<***");163return 2;164}165166return 0;167}168169void startThreads() {170threads = new strace003Thread[THRD_COUNT];171achivedCount = 0;172173String tmp_name;174for (int i = 0; i < THRD_COUNT; i++) {175tmp_name = "strace003Thread" + Integer.toString(i);176threads[i] = new strace003Thread(this, tmp_name);177}178179for (int i = 0; i < THRD_COUNT; i++) {180threads[i].start();181}182183waitFor("all threads started ...");184synchronized (waitStart) {185isLocked = true;186waitStart.notifyAll();187}188try {189Thread.yield();190Thread.sleep(1);191} catch (InterruptedException e) {192complain("" + e);193}194}195196void waitFor(String msg) {197if (msg.length() > 0)198display("waiting for " + msg);199200while (achivedCount < THRD_COUNT) {201try {202Thread.sleep(1);203} catch (InterruptedException e) {204complain("" + e);205}206}207achivedCount = 0;208}209210boolean makeSnapshot(int repeat_number) {211212for (int i = 0; i < threads.length; i++) {213snapshots[i] = threads[i].getStackTrace();214}215216return checkTraces(repeat_number);217}218219boolean checkTraces(int repeat_number) {220StackTraceElement[] elements;221222boolean res = true;223display(">>> snapshot " + repeat_number);224int expectedCount = DEPTH + 1;225226for (int i = 0; i < threads.length; i++) {227elements = snapshots[i];228229if (elements == null)230continue;231232if (elements.length == 0)233continue;234235if (elements.length > 0) {236display("\tchecking " + threads[i].getName()237+ "(trace elements: " + elements.length + ")");238}239240if (elements.length > expectedCount) {241complain(threads[i].getName() + ">Contains more then " +242+expectedCount + " elements");243}244245for (int j = 0; j < elements.length; j++) {246if (!checkElement(elements[j])) {247complain(threads[i].getName() + ">Unexpected method name: "248+ elements[j].getMethodName());249complain("\tat " + j + " position");250if (elements[j].isNativeMethod()) {251complain("\tline number: (native method)");252complain("\tclass name: " + elements[j].getClassName());253} else {254complain("\tline number: " + elements[j].getLineNumber());255complain("\tclass name: " + elements[j].getClassName());256complain("\tfile name: " + elements[j].getFileName());257}258res = false;259}260}261}262return res;263}264265boolean checkElement(StackTraceElement element) {266String name = element.getClassName() + "." + element.getMethodName();267for (int i = 0; i < EXPECTED_METHODS.length; i++) {268if (EXPECTED_METHODS[i].compareTo(name) == 0)269return true;270}271return false;272}273274void finishThreads() {275try {276for (int i = 0; i < threads.length; i++) {277if (threads[i].isAlive())278threads[i].join(waitTime / THRD_COUNT);279}280} catch (InterruptedException e) {281complain("" + e);282}283isLocked = false;284}285286static void display(String message) {287log.display(message);288}289290static void complain(String message) {291log.complain(message);292}293294}295296class strace003Thread extends Thread {297298private int currentDepth = 0;299300strace003 test;301302static {303try {304System.loadLibrary("strace003");305} catch (UnsatisfiedLinkError e) {306System.err.println("Could not load strace003 library");307System.err.println("java.library.path:"308+ System.getProperty("java.library.path"));309throw e;310}311}312313strace003Thread(strace003 test, String name) {314this.test = test;315setName(name);316}317318public void run() {319320recursiveMethod();321322}323324native void recursiveMethod();325}326327328