mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-20 07:15:31 +00:00
8243455: Many SA tests can fail due to trying to get the stack trace of an active method
Reviewed-by: lmesnik, ysuenaga, sspitsyn
This commit is contained in:
parent
e834f99d1d
commit
43524cc41a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2021, 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
|
||||
@ -84,7 +84,7 @@ public class ClhsdbCDSJstackPrintAll {
|
||||
"Common-Cleaner",
|
||||
"Signal Dispatcher",
|
||||
"Method*",
|
||||
"LingeredApp.main"));
|
||||
"LingeredApp.steadyState"));
|
||||
unExpStrMap.put("jstack -v", List.of(
|
||||
"sun.jvm.hotspot.types.WrongTypeException",
|
||||
"No suitable match for type of address"));
|
||||
@ -105,8 +105,8 @@ public class ClhsdbCDSJstackPrintAll {
|
||||
"illegal code",
|
||||
"Failure occurred at bci"));
|
||||
expStrMap.put("where -a", List.of(
|
||||
"Java Stack Trace for main",
|
||||
"public static void main"));
|
||||
"Java Stack Trace for SteadyStateThread",
|
||||
"private static void steadyState"));
|
||||
unExpStrMap.put("where -a", List.of(
|
||||
"illegal code",
|
||||
"Failure occurred at bci"));
|
||||
|
||||
@ -53,8 +53,8 @@ public class ClhsdbDumpheap {
|
||||
try {
|
||||
System.out.println("HprofReader.getStack() output:");
|
||||
String output = HprofReader.getStack(file, 0);
|
||||
if (!output.contains("LingeredApp.main")) {
|
||||
throw new RuntimeException("'LingeredApp.main' missing from stdout/stderr");
|
||||
if (!output.contains("LingeredApp.steadyState")) {
|
||||
throw new RuntimeException("'LingeredApp.steadyState' missing from stdout/stderr");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Test ERROR " + ex, ex);
|
||||
|
||||
@ -90,7 +90,7 @@ public class ClhsdbFindPC {
|
||||
|
||||
test = new ClhsdbLauncher();
|
||||
|
||||
theApp = new LingeredAppWithTrivialMain();
|
||||
theApp = new LingeredApp();
|
||||
theApp.setForceCrash(withCore);
|
||||
if (withXcomp) {
|
||||
LingeredApp.startApp(theApp, "-Xcomp");
|
||||
@ -134,9 +134,9 @@ public class ClhsdbFindPC {
|
||||
String jStackOutput = runTest(withCore, cmds, null);
|
||||
|
||||
// Extract pc address from the following line:
|
||||
// - LingeredAppWithTrivialMain.main(java.lang.String[]) @bci=1, line=33, pc=0x00007ff18ff519f0, ...
|
||||
// - LingeredApp.steadyState(java.lang.Object) @bci=1, line=33, pc=0x00007ff18ff519f0, ...
|
||||
String pcAddress = null;
|
||||
String[] parts = jStackOutput.split("LingeredAppWithTrivialMain.main");
|
||||
String[] parts = jStackOutput.split("LingeredApp.steadyState");
|
||||
String[] tokens = parts[1].split(" ");
|
||||
for (String token : tokens) {
|
||||
if (token.contains("pc")) {
|
||||
@ -147,7 +147,7 @@ public class ClhsdbFindPC {
|
||||
}
|
||||
}
|
||||
if (pcAddress == null) {
|
||||
throw new RuntimeException("Cannot find LingeredAppWithTrivialMain.main pc in output");
|
||||
throw new RuntimeException("Cannot find LingeredApp.steadyState pc in output");
|
||||
}
|
||||
|
||||
// Test the 'findpc' command passing in the pc obtained from jstack above
|
||||
@ -157,7 +157,7 @@ public class ClhsdbFindPC {
|
||||
expStrMap = new HashMap<>();
|
||||
if (withXcomp) {
|
||||
expStrMap.put(cmdStr, List.of(
|
||||
"In code in NMethod for LingeredAppWithTrivialMain.main",
|
||||
"In code in NMethod for jdk/test/lib/apps/LingeredApp.steadyState",
|
||||
"content:",
|
||||
"oops:",
|
||||
"frame size:"));
|
||||
@ -168,9 +168,9 @@ public class ClhsdbFindPC {
|
||||
runTest(withCore, cmds, expStrMap);
|
||||
|
||||
// Run findpc on a Method*. We can find one in the jstack output. For example:
|
||||
// - LingeredAppWithTrivialMain.main(java.lang.String[]) @bci=1, line=33, pc=..., Method*=0x0000008041000208 ...
|
||||
// - LingeredApp.steadyState(java.lang.Object) @bci=1, line=33, pc=..., Method*=0x0000008041000208 ...
|
||||
// This is testing the PointerFinder support for C++ MetaData types.
|
||||
parts = jStackOutput.split("LingeredAppWithTrivialMain.main");
|
||||
parts = jStackOutput.split("LingeredApp.steadyState");
|
||||
parts = parts[1].split("Method\\*=");
|
||||
parts = parts[1].split(" ");
|
||||
String methodAddr = parts[0];
|
||||
@ -178,7 +178,7 @@ public class ClhsdbFindPC {
|
||||
cmds = List.of(cmdStr);
|
||||
expStrMap = new HashMap<>();
|
||||
expStrMap.put(cmdStr, List.of("Method ",
|
||||
"LingeredAppWithTrivialMain.main",
|
||||
"LingeredApp.steadyState",
|
||||
methodAddr));
|
||||
runTest(withCore, cmds, expStrMap);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -58,7 +58,7 @@ public class ClhsdbJdis {
|
||||
cmds = new ArrayList<String>();
|
||||
|
||||
String cmdStr = null;
|
||||
String[] parts = output.split("LingeredApp.main");
|
||||
String[] parts = output.split("LingeredApp.steadyState");
|
||||
String[] tokens = parts[1].split(" ");
|
||||
for (String token : tokens) {
|
||||
if (token.contains("Method")) {
|
||||
@ -72,7 +72,7 @@ public class ClhsdbJdis {
|
||||
|
||||
Map<String, List<String>> expStrMap = new HashMap<>();
|
||||
expStrMap.put(cmdStr, List.of(
|
||||
"public static void main\\(java\\.lang\\.String\\[\\]\\)",
|
||||
"private static void steadyState\\(java\\.lang\\.Object\\)",
|
||||
"Holder Class",
|
||||
"public class jdk.test.lib.apps.LingeredApp @",
|
||||
"public class jdk\\.test\\.lib\\.apps\\.LingeredApp @",
|
||||
@ -93,4 +93,3 @@ public class ClhsdbJdis {
|
||||
System.out.println("Test PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -71,7 +71,7 @@ public class ClhsdbJstack {
|
||||
"java.lang.ref.Finalizer\\$FinalizerThread.run",
|
||||
"java.lang.ref.Reference",
|
||||
"Method\\*",
|
||||
"LingeredApp.main"));
|
||||
"LingeredApp.steadyState"));
|
||||
|
||||
test.run(theApp.getPid(), cmds, expStrMap, null);
|
||||
} catch (SkippedException se) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -49,13 +49,13 @@ public class ClhsdbPrintAs {
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
|
||||
// Run the 'jstack -v' command to get the address of a the Method*
|
||||
// representing LingeredApp.main
|
||||
// representing LingeredApp.steadyState
|
||||
List<String> cmds = List.of("jstack -v");
|
||||
Map<String, List<String>> expStrMap;
|
||||
|
||||
String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
|
||||
|
||||
String[] snippets = jstackOutput.split("LingeredApp.main");
|
||||
String[] snippets = jstackOutput.split("LingeredApp.steadyState");
|
||||
String addressString = null;
|
||||
|
||||
String[] tokens = snippets[1].split("Method\\*=");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -63,7 +63,7 @@ public class ClhsdbSource {
|
||||
"java.lang.ref.Finalizer\\$FinalizerThread.run",
|
||||
"java.lang.ref.Reference",
|
||||
"Method\\*",
|
||||
"LingeredApp.main",
|
||||
"LingeredApp.steadyState",
|
||||
"Available commands:",
|
||||
"attach pid \\| exec core",
|
||||
"intConstant \\[ name \\[ value \\] \\]",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -59,8 +59,8 @@ public class ClhsdbWhere {
|
||||
"Java Stack Trace for Finalizer",
|
||||
"Java Stack Trace for Signal Dispatcher",
|
||||
"Java Stack Trace for Reference Handler",
|
||||
"Java Stack Trace for main",
|
||||
"public static void main"));
|
||||
"Java Stack Trace for SteadyStateThread",
|
||||
"private static void steadyState"));
|
||||
|
||||
test.run(theApp.getPid(), cmds, expStrMap, null);
|
||||
} catch (SkippedException se) {
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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.
|
||||
*/
|
||||
|
||||
import jdk.test.lib.apps.LingeredApp;
|
||||
|
||||
/**
|
||||
* This is a wrapper around LingeredApp.main to ensure we reliably get a
|
||||
* compiled main nmethod in the stack trace on all platforms when using
|
||||
* -Xcomp.
|
||||
*/
|
||||
public class LingeredAppWithTrivialMain extends LingeredApp {
|
||||
public static void main(String args[]) {
|
||||
LingeredApp.main(args);
|
||||
}
|
||||
}
|
||||
@ -102,8 +102,8 @@ public class HeapDumpTest {
|
||||
public static void printStackTraces(String file) throws IOException {
|
||||
try {
|
||||
String output = HprofReader.getStack(file, 0);
|
||||
if (!output.contains("LingeredAppWithExtendedChars.main")) {
|
||||
throw new RuntimeException("'LingeredAppWithExtendedChars.main' missing from stdout/stderr");
|
||||
if (!output.contains("LingeredApp.steadyState")) {
|
||||
throw new RuntimeException("'LingeredApp.steadyState' missing from stdout/stderr");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Test ERROR " + ex, ex);
|
||||
|
||||
@ -496,6 +496,43 @@ public class LingeredApp {
|
||||
return sane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support for creating a thread whose stack trace is always readable. There are
|
||||
* occassional isues trying to get the stack trace for LingeredApp.main() since
|
||||
* it sometimes wakes up from sleep and may breifly have an unreadable thread
|
||||
* stack trace. The code below is used to create "SteadyStateThread" whose
|
||||
* stack trace is always readable.
|
||||
*/
|
||||
|
||||
private static volatile boolean steadyStateReached = false;
|
||||
|
||||
private static void steadyState(Object steadyStateObj) {
|
||||
steadyStateReached = true;
|
||||
synchronized(steadyStateObj) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void startSteadyStateThread(Object steadyStateObj) {
|
||||
Thread steadyStateThread = new Thread() {
|
||||
public void run() {
|
||||
steadyState(steadyStateObj);
|
||||
}
|
||||
};
|
||||
steadyStateThread.setName("SteadyStateThread");
|
||||
steadyStateThread.start();
|
||||
|
||||
// Wait until the thread has started running.
|
||||
while (!steadyStateReached) {
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
|
||||
// Now wait until we get into the synchronized block.
|
||||
while (steadyStateThread.getState() != Thread.State.BLOCKED) {
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This part is the application itself. First arg is optional "forceCrash".
|
||||
* Following arg is the lock file name.
|
||||
@ -524,14 +561,18 @@ public class LingeredApp {
|
||||
Path path = Paths.get(theLockFileName);
|
||||
|
||||
try {
|
||||
if (forceCrash) {
|
||||
System.loadLibrary("LingeredApp"); // location of native crash() method
|
||||
crash();
|
||||
}
|
||||
while (Files.exists(path)) {
|
||||
// Touch the lock to indicate our readiness
|
||||
setLastModified(theLockFileName, epoch());
|
||||
Thread.sleep(spinDelay);
|
||||
Object steadyStateObj = new Object();
|
||||
synchronized(steadyStateObj) {
|
||||
startSteadyStateThread(steadyStateObj);
|
||||
if (forceCrash) {
|
||||
System.loadLibrary("LingeredApp"); // location of native crash() method
|
||||
crash();
|
||||
}
|
||||
while (Files.exists(path)) {
|
||||
// Touch the lock to indicate our readiness
|
||||
setLastModified(theLockFileName, epoch());
|
||||
Thread.sleep(spinDelay);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// Lock deleted while we are setting last modified time.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user