Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.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/strace005.28* VM testbase keywords: [stress, strace]29* VM testbase readme:30* DESCRIPTION31* The test checks up java.lang.Thread.getStackTrace() method for many threads,32* that recursively invoke pure java and native methods by turns in running33* 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 and41* nsk.stress.strace.strace003 except for the recursive methods are42* pure java and native one.43* COMMENTS44* Below assertion is revealed on engineer's build. It is needed to check45* on a promoted build.46* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~47* waiting for all threads started ...48* Unexpected Signal : 11 occurred at PC=0xFDBB782049* Function=[Unknown. Nearest: SUNWprivate_1.1+0x3B7820]50* Library=java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/client/libjvm.so51* Current Java thread:52* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)53* at nsk.stress.strace.strace005Thread.recursiveMethod1(strace005.java:285)54* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)56* at nsk.stress.strace.strace005Thread.recursiveMethod1(strace005.java:285)57* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)58* Dynamic libraries:59* 0x10000 jdk/4593133/solaris-sparc/bin/java60* 0xff350000 /usr/lib/libthread.so.161* 0xff390000 /usr/lib/libdl.so.162* 0xff200000 /usr/lib/libc.so.163* 0xff330000 /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.164* 0xfd800000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/client/libjvm.so65* 0xff2d0000 /usr/lib/libCrun.so.166* 0xff1d0000 /usr/lib/libsocket.so.167* 0xff100000 /usr/lib/libnsl.so.168* 0xff0d0000 /usr/lib/libm.so.169* 0xff0b0000 /usr/lib/libsched.so.170* 0xff300000 /usr/lib/libw.so.171* 0xff090000 /usr/lib/libmp.so.272* 0xff050000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/native_threads/libhpi.so73* 0xfd7d0000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libverify.so74* 0xfd790000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libjava.so75* 0xfe7e0000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libzip.so76* 0xfc6e0000 java/vitp/tests/4593133/src/libstrace005.so77* Heap at VM Abort:78* Heap79* def new generation total 2112K, used 336K [0xf1800000, 0xf1a20000, 0xf1f10000)80* eden space 2048K, 16% used [0xf1800000, 0xf1854300, 0xf1a00000)81* from space 64K, 0% used [0xf1a00000, 0xf1a00000, 0xf1a10000)82* to space 64K, 0% used [0xf1a10000, 0xf1a10000, 0xf1a20000)83* tenured generation total 1408K, used 0K [0xf1f10000, 0xf2070000, 0xf5800000)84* the space 1408K, 0% used [0xf1f10000, 0xf1f10000, 0xf1f10200, 0xf2070000)85* compacting perm gen total 4096K, used 1020K [0xf5800000, 0xf5c00000, 0xf9800000)86* the space 4096K, 24% used [0xf5800000, 0xf58ff028, 0xf58ff200, 0xf5c00000)87* Local Time = Fri Apr 25 18:09:16 200388* Elapsed Time = 1389* #90* # HotSpot Virtual Machine Error : 1191* # Error ID : src/share/vm/runtime/os.cpp, 753 [ Patched ]92* # Please report this error at93* # http://java.sun.com/cgi-bin/bugreport.cgi94* #95* # Java VM: Java HotSpot(TM) Client VM (1.4.1-internal-debug mixed mode)96* #97* # An error report file has been saved as hs_err_pid16847.log.98* # Please refer to the file for further information.99* #100* Dumping core....101* Abort102* Finished at: Fri Apr 25 18:09:17 NSK 2003103*104* @library /vmTestbase105* /test/lib106* @run main/othervm/native nsk.stress.strace.strace005107*/108109package nsk.stress.strace;110111import nsk.share.ArgumentParser;112import nsk.share.Failure;113import nsk.share.Log;114115import java.io.PrintStream;116117/**118* The test checks up <code>java.lang.Thread.getStackTrace()</code> method for many threads,119* that recursively invoke pure java and native methods by turns in running mode120* ("alive" stack).121* <p>122* <p>The test creates <code>THRD_COUNT</code> instances of <code>strace005Thread</code>123* class, tries to get their stack traces and checks up that returned array contains124* correct stack frames. Each stack frame must be corresponded to one of the following125* methods defined by the <code>EXPECTED_METHODS</code> array.</p>126* <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>127*/128public class strace005 {129130static final int DEPTH = 500;131static final int THRD_COUNT = 100;132static final int REPEAT_COUNT = 10;133static final String[] EXPECTED_METHODS = {134"java.lang.System.arraycopy",135"java.lang.Object.wait",136"java.lang.Thread.exit",137"java.lang.Thread.yield",138"java.lang.ThreadGroup.remove",139"java.lang.ThreadGroup.threadTerminated",140"nsk.stress.strace.strace005Thread.run",141"nsk.stress.strace.strace005Thread.recursiveMethod1",142"nsk.stress.strace.strace005Thread.recursiveMethod2"143};144145146static volatile boolean isLocked = false;147static PrintStream out;148static long waitTime = 2;149150static Object waitStart = new Object();151152static strace005Thread[] threads;153static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];154static Log log;155156volatile int achivedCount = 0;157158public static void main(String[] args) {159out = System.out;160int exitCode = run(args);161System.exit(exitCode + 95);162}163164public static int run(String[] args) {165ArgumentParser argHandler = new ArgumentParser(args);166log = new Log(out, argHandler);167waitTime = argHandler.getWaitTime() * 60000;168169strace005 test = new strace005();170boolean res = true;171172for (int j = 0; j < REPEAT_COUNT; j++) {173test.startThreads();174175if (!test.makeSnapshot(j + 1)) res = false;176177display("waiting for threads finished\n");178test.finishThreads();179}180181if (!res) {182complain("***>>>Test failed<<<***");183return 2;184}185186return 0;187}188189void startThreads() {190threads = new strace005Thread[THRD_COUNT];191achivedCount = 0;192193String tmp_name;194for (int i = 0; i < THRD_COUNT; i++) {195tmp_name = "strace005Thread" + Integer.toString(i);196threads[i] = new strace005Thread(this, tmp_name);197// threads[i].setPriority(Thread.MIN_PRIORITY);198}199200for (int i = 0; i < THRD_COUNT; i++) {201threads[i].start();202}203204waitFor("all threads started ...");205synchronized (waitStart) {206isLocked = true;207waitStart.notifyAll();208}209try {210Thread.yield();211Thread.sleep(1);212} catch (InterruptedException e) {213complain("" + e);214}215}216217void waitFor(String msg) {218if (msg.length() > 0)219display("waiting for " + msg);220221while (achivedCount < THRD_COUNT) {222try {223Thread.sleep(1);224} catch (InterruptedException e) {225complain("" + e);226}227}228achivedCount = 0;229}230231boolean makeSnapshot(int repeat_number) {232// wait for native resolution completed (all threads have finished recursiveMethod2)233boolean isNativeResolved = false;234while (!isNativeResolved) {235try {236isNativeResolved = true;237for (int i = 0; i < threads.length; ++i)238if (!threads[i].isNativeResolved)239isNativeResolved = false;240Thread.sleep(20);241} catch (InterruptedException e) {242throw new Error(e);243}244}245246for (int i = 0; i < threads.length; i++) {247snapshots[i] = threads[i].getStackTrace();248}249250return checkTraces(repeat_number);251}252253boolean checkTraces(int repeat_number) {254StackTraceElement[] elements;255256boolean res = true;257display(">>> snapshot " + repeat_number);258int expectedCount = DEPTH + 1;259260for (int i = 0; i < threads.length; i++) {261elements = snapshots[i];262263if (elements == null || elements.length == 0)264continue;265266if (elements.length > 0) {267display("\tchecking " + threads[i].getName()268+ "(trace elements: " + elements.length + ")");269}270271if (elements.length > expectedCount) {272complain(threads[i].getName() + ">Contains more then " +273+expectedCount + " elements");274}275276for (int j = 0; j < elements.length; j++) {277if (!checkElement(elements[j])) {278complain(threads[i].getName() + ">Unexpected method name: "279+ elements[j].getMethodName());280complain("\tat " + j + " position");281if (elements[j].isNativeMethod()) {282complain("\tline number: (native method)");283complain("\tclass name: " + elements[j].getClassName());284} else {285complain("\tline number: " + elements[j].getLineNumber());286complain("\tclass name: " + elements[j].getClassName());287complain("\tfile name: " + elements[j].getFileName());288}289res = false;290}291}292}293return res;294}295296boolean checkElement(StackTraceElement element) {297String name = element.getClassName() + "." + element.getMethodName();298for (int i = 0; i < EXPECTED_METHODS.length; i++) {299if (EXPECTED_METHODS[i].compareTo(name) == 0)300return true;301}302return false;303}304305void finishThreads() {306try {307for (int i = 0; i < threads.length; i++) {308if (threads[i].isAlive())309threads[i].join(waitTime / THRD_COUNT);310}311} catch (InterruptedException e) {312complain("" + e);313}314isLocked = false;315}316317static void display(String message) {318log.display(message);319}320321static void complain(String message) {322log.complain(message);323}324325}326327/**328* The test creates many instances of <code>strace005Thread</code> class and tries329* to get their stack traces.330*/331class strace005Thread extends Thread {332333private int currentDepth = 0;334public boolean isNativeResolved = false;335336strace005 test;337338static {339try {340System.loadLibrary("strace005");341} catch (UnsatisfiedLinkError e) {342System.err.println("Could not load strace005 library");343System.err.println("java.library.path:"344+ System.getProperty("java.library.path"));345throw e;346}347}348349strace005Thread(strace005 test, String name) {350this.test = test;351setName(name);352}353354public void run() {355356recursiveMethod1();357358}359360void recursiveMethod1() {361362currentDepth++;363364if (currentDepth == 1) {365synchronized (test) {366test.achivedCount++;367}368369int alltime = 0;370while (!strace005.isLocked) {371synchronized (test) {372try {373test.wait(1);374alltime++;375} catch (InterruptedException e) {376strace005.complain("" + e);377}378if (alltime > strace005.waitTime) {379throw new Failure("out of wait time");380}381}382}383} else if (currentDepth > 1 && !isNativeResolved)384isNativeResolved = true;385386if (strace005.DEPTH - currentDepth > 0) {387try {388Thread.yield();389recursiveMethod2();390} catch (StackOverflowError e) {391// ignore this exception392}393}394395currentDepth--;396}397398native void recursiveMethod2();399}400401402