Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting of threadInfo #4998

Merged
merged 1 commit into from
Mar 21, 2019
Merged

Conversation

pdbain-ibm
Copy link
Contributor

@pdbain-ibm pdbain-ibm commented Mar 5, 2019

Improve formatting of ThreadInfo and StackTraceElement

Move StackTraceElement toString implementation to a utility method to allow
more latitude in formatting. Make stack trace format match reference
implementation. Add module version to StackTraceElement's toString(). Add
locking information.

Fixes #4965
Fixes #5012

Signed-off-by: Peter Bain peter_bain@ca.ibm.com

@pdbain-ibm
Copy link
Contributor Author

Tested manually:

jshell> for (ThreadInfo t: b.dumpAllThreads(true, true)) System.out.println(t.toString());
"main" prio=5 Id=1 RUNNABLE
	at java.management/com.ibm.java.lang.management.internal.ThreadMXBeanImpl.dumpAllThreadsImpl(Native Method)
	at java.management/com.ibm.java.lang.management.internal.ThreadMXBeanImpl.dumpAllThreadsCommon(ThreadMXBeanImpl.java:653)
	at java.management/com.ibm.java.lang.management.internal.ThreadMXBeanImpl.dumpAllThreads(ThreadMXBeanImpl.java:636)
	at REPL.$JShell$17.do_it$($JShell$17.java:5)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at jdk.jshell/jdk.jshell.execution.DirectExecutionControl.invoke(DirectExecutionControl.java:209)
	at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.invoke(RemoteExecutionControl.java:116)
	at jdk.jshell/jdk.jshell.execution.DirectExecutionControl.invoke(DirectExecutionControl.java:119)
	at jdk.jshell/jdk.jshell.execution.ExecutionControlForwarder.processCommand(ExecutionControlForwarder.java:144)
	at jdk.jshell/jdk.jshell.execution.ExecutionControlForwarder.commandLoop(ExecutionControlForwarder.java:262)
	at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControl(Util.java:76)
	at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControlAndIO(Util.java:137)
	at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.main(RemoteExecutionControl.java:70)

"JIT Compilation Thread-0" prio=10 Id=3 RUNNABLE

"JIT Compilation Thread-1 Suspended" prio=10 Id=4 RUNNABLE

@pshipton
Copy link
Member

pshipton commented Mar 5, 2019

Note the missing module version should also be fixed.

@pdbain-ibm pdbain-ibm marked this pull request as ready for review March 6, 2019 18:28
@pdbain-ibm
Copy link
Contributor Author

Note the missing module version should also be fixed.

That's a bug in StackTraceElement. Will update.

@pdbain-ibm pdbain-ibm force-pushed the mxbean branch 2 times, most recently from 11e13fa to c9315c3 Compare March 6, 2019 18:52
@pshipton
Copy link
Member

pshipton commented Mar 6, 2019

jenkins test sanity plinux jdk11

@pshipton
Copy link
Member

pshipton commented Mar 6, 2019

jenkins test extended plinux jdk11

@@ -260,6 +260,8 @@ void appendTo(Appendable buf) {
/*[IF Sidecar19-SE]*/
if (null != moduleName) {
appendTo(buf, moduleName);
appendTo(buf, "@"); //$NON-NLS-1$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. Seems that printStackTrace() doesn't include the version, while the ThreadInfo printing does.

Copy link
Contributor Author

@pdbain-ibm pdbain-ibm Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the reference implementation StackTraceElement.toString() does not print the version or monitor information, nor do Thread.dumpStack() or Exception.printStackTrace(). It appears that only ThreadInfo.toString()` prints this extra information.

@pshipton
Copy link
Member

pshipton commented Mar 6, 2019

Please also check the output for non-modularied class.
i.e. I got this on the RI for a test class with no package app//Test1a.main(Test1a.java:37)

@pdbain-ibm
Copy link
Contributor Author

Please also check the output for non-modularied class.
i.e. I got this on the RI for a test class with no package app//Test1a.main(Test1a.java:37)

I got something similar from OpenJDK on my test case compiled with Java 8:

	at locker.printThreadInfo(locker.java:37)
	at locker.meth(locker.java:25)
	-  locked java.lang.Object@44c03695
	at locker.main(locker.java:49)
	at java.base@11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

OpenJ9 matches that, though the version information is formatted differently:

	at locker.printThreadInfo(locker.java:37)
	at locker.meth(locker.java:25)
	at locker.main(locker.java:49)
	at java.base@11.0.3-internal/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

The formatting code in StackTraceElement omits the module information if moduleName is null.

@pdbain-ibm pdbain-ibm changed the title Improve formatting of threadInfo WIP Improve formatting of threadInfo Mar 12, 2019
@pdbain-ibm pdbain-ibm force-pushed the mxbean branch 5 times, most recently from d5c7e3f to b11d1e4 Compare March 19, 2019 15:44
@pdbain-ibm pdbain-ibm changed the title WIP Improve formatting of threadInfo Improve formatting of threadInfo Mar 19, 2019
@pdbain-ibm
Copy link
Contributor Author

Updated and designer tested. Ready for review.

@pshipton
Copy link
Member

Note the following

import java.lang.management.*;

public class DumpThreads {
public static void main(String[] args) throws Throwable {
        ThreadMXBean tb = ManagementFactory.getThreadMXBean();
        ThreadInfo[] tis = tb.dumpAllThreads(true, true);
        for (ThreadInfo ti : tis) {
                System.out.println(ti);
        }
}
}

gives the following output for the main thread. The app//DumpThreads.main(DumpThreads.java:6) part isn't reflected by these changes.

"main" prio=5 Id=1 RUNNABLE
        at java.management@11.0.2/sun.management.ThreadImpl.dumpThreads0(Native Method)
        at java.management@11.0.2/sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:502)
        at java.management@11.0.2/sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:490)
        at app//DumpThreads.main(DumpThreads.java:6)

@pshipton
Copy link
Member

pshipton commented Mar 19, 2019

If I change the test case to a different package (test), then the output changes to

test.DumpThreads.main(DumpThreads2.java:8)

@pdbain-ibm
Copy link
Contributor Author

If I change the test case to a different package (test), then the output changes to

test.DumpThreads.main(DumpThreads2.java:8)

Odd. I did the same test (except with package foobar) and still got the leading app//.
However, running directly from the .java file, i.e. not compiling to a classfile beforehand, I don't get the app//. I assume app// represents the unnamed module?

@pdbain-ibm pdbain-ibm force-pushed the mxbean branch 2 times, most recently from 2e866a3 to c8a2233 Compare March 20, 2019 14:04
@pshipton
Copy link
Member

Please squash.

Move StackTraceElement toString implementation to a utility method to allow
more latitude in formatting.  Make stack trace format match reference
implementation.  Add module version to StackTraceElement's toString().  Add
locking information.  Refactor utility methods.

Fixes eclipse-openj9#4965
Fixes eclipse-openj9#5012

[ci skip]

Signed-off-by: Peter Bain <peter_bain@ca.ibm.com>
@pdbain-ibm
Copy link
Contributor Author

Squashed.

@pshipton
Copy link
Member

jenkins test sanity zlinux jdk8

@pshipton
Copy link
Member

jenkins test sanity zlinux jdk11

@pshipton
Copy link
Member

jenkins test extended plinux jdk8,jdk11

@pshipton pshipton merged commit 27eb090 into eclipse-openj9:master Mar 21, 2019
@pdbain-ibm pdbain-ibm deleted the mxbean branch March 28, 2019 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants