Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1752173

Summary: jstack -F hits NPE during some application pattern calls
Product: Red Hat Enterprise Linux 7 Reporter: Aaron Ogburn <aogburn>
Component: java-1.8.0-openjdkAssignee: Severin Gehwolf <sgehwolf>
Status: CLOSED ERRATA QA Contact: OpenJDK QA <java-qa>
Severity: high Docs Contact:
Priority: high    
Version: 7.7CC: ahughes, aph, dbhole, fdemeloj, jandrlik, jvanek, loskutov, pmikova, sgehwolf, simeon.andreev
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: java-1.8.0-openjdk-1.8.0.262.b04-0.1.ea.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-09-29 19:54:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
bz1752173repro.zip none

Description Aaron Ogburn 2019-09-14 00:07:34 UTC
Description of problem:

When using jstack -F, not all thread stacks are listed. Instead, an error is listed for a thread which is in an endless loop due to Java pattern processing.

Thread 12105: (state = IN_JAVA)
Error occurred during stack walking:
java.lang.NullPointerException
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:88)
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)

Version-Release number of selected component (if applicable):

java-1.8.0-openjdk-1.8.0.222.b10-4


How reproducible:

Very

Steps to Reproduce:
1. java TestPattern (attached)
2. Find the process PID of the running Java application 
3. Call jstack -F <PID>.
4. Observe that often, the above error is seen

Actual results:

Frequent NPE

Expected results:

No NPE

Comment 2 Aaron Ogburn 2019-09-14 00:09:28 UTC
Created attachment 1615044 [details]
bz1752173repro.zip

Comment 3 Severin Gehwolf 2019-09-17 08:12:07 UTC
*** Bug 1750768 has been marked as a duplicate of this bug. ***

Comment 4 Severin Gehwolf 2019-09-17 17:08:42 UTC
This reproduces with JDK 11 and JDK head (JDK 14) as well and is related to compiled frames being on the stack.

The command for JDK 11+ is "jhsdb jstack --mixed --pid <PID>" over "jstack -F <PID>".

Stack trace for JDK 11 looks like this:

Attaching to process ID 383780, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 11.0.4+11
sun.jvm.hotspot.utilities.AssertionFailure: must be a valid non-zero index
	at jdk.hotspot.agent/sun.jvm.hotspot.utilities.Assert.that(Assert.java:32)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.NMethod.getMetadataAt(NMethod.java:204)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.NMethod.getMethodAt(NMethod.java:210)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.DebugInfoReadStream.readMethod(DebugInfoReadStream.java:58)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.ScopeDesc.<init>(ScopeDesc.java:64)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.ScopeDesc.sender(ScopeDesc.java:121)
	at jdk.hotspot.agent/sun.jvm.hotspot.runtime.CompiledVFrame.sender(CompiledVFrame.java:187)
	at jdk.hotspot.agent/sun.jvm.hotspot.runtime.VFrame.javaSender(VFrame.java:143)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.initJFrameCache(PStack.java:207)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:71)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.run(JStack.java:67)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.runWithArgs(JStack.java:90)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJSTACK(SALauncher.java:251)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:472)
Deadlock Detection:

For JDK 14 it looks similar:

Attaching to process ID 384120, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14-internal+0-adhoc.sgehwolf.openjdk-head
sun.jvm.hotspot.utilities.AssertionFailure: must be a valid non-zero index
	at jdk.hotspot.agent/sun.jvm.hotspot.utilities.Assert.that(Assert.java:32)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.NMethod.getMetadataAt(NMethod.java:200)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.NMethod.getMethodAt(NMethod.java:206)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.DebugInfoReadStream.readMethod(DebugInfoReadStream.java:58)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.ScopeDesc.<init>(ScopeDesc.java:64)
	at jdk.hotspot.agent/sun.jvm.hotspot.code.ScopeDesc.sender(ScopeDesc.java:121)
	at jdk.hotspot.agent/sun.jvm.hotspot.runtime.CompiledVFrame.sender(CompiledVFrame.java:187)
	at jdk.hotspot.agent/sun.jvm.hotspot.runtime.VFrame.javaSender(VFrame.java:143)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.initJFrameCache(PStack.java:208)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:71)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.run(JStack.java:67)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.runWithArgs(JStack.java:90)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJSTACK(SALauncher.java:290)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:406)
Deadlock Detection:

Comment 5 Severin Gehwolf 2019-09-17 17:17:06 UTC
So far I haven't reproduced this with -Xint being passed to the java command for Testpattern. Similarly excluding java.util.regex.Pattern from JIT compiling. Excluding just java.util.regex.Pattern$Branch.match() and java.util.regex.Pattern$NotBehind.match() from JIT compilation seems to reduce the frequency of this occurring somewhat:

$ java -XX:CompileCommand="exclude java/util/regex/Pattern\$Branch::match" -XX:CompileCommand="exclude java/util/regex/Pattern\$NotBehind::match" TestPattern
CompilerOracle: exclude java/util/regex/Pattern$Branch.match
CompilerOracle: exclude java/util/regex/Pattern$NotBehind.match
### Excluding compile: java.util.regex.Pattern$Branch::match
### Excluding compile: java.util.regex.Pattern$NotBehind::match

[...]

Comment 6 Severin Gehwolf 2019-09-19 15:34:48 UTC
(In reply to Severin Gehwolf from comment #4)
> This reproduces with JDK 11 and JDK head (JDK 14) as well and is related to
> compiled frames being on the stack.
> 
> The command for JDK 11+ is "jhsdb jstack --mixed --pid <PID>" over "jstack> -F <PID>".

Correction. In JDK 11+ the command is (no --mixed):

$ jhsdb jstack --pid <PID>

For JDK 14 the error looks like this:

Attaching to process ID 180596, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14-internal+0-adhoc.sgehwolf.openjdk-head-2
Deadlock Detection:

No deadlocks found.

"main" #1 prio=5 tid=0x00007efcec018000 nid=0x2c175 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_in_java
Error occurred during stack walking:
java.lang.NullPointerException
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:83)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.run(JStack.java:67)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JStack.runWithArgs(JStack.java:90)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJSTACK(SALauncher.java:290)
	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:406)

Comment 7 Severin Gehwolf 2019-09-19 15:40:41 UTC
This seems to be upstream bug JDK-8196969 and seems intermittent. The reproducer at hand seems to trigger it more often. I'll see if I can come up with a somewhat reliable jtreg test.

Comment 8 Simeon Andreev 2019-09-19 16:49:50 UTC
Hi Severin,

thanks for examining this bug. But is there any chance you or your colleagues can look into: https://bugzilla.redhat.com/show_bug.cgi?id=1751985

This is a RHEL bugzilla ticket for this OpenJDK bug: https://bugs.openjdk.java.net/browse/JDK-8227269

Our R&D would really like a fix in the next official OpenJDK release (and the code freeze for that according to the 1.8 schedule is nearing).

Sorry if this is not your area or your teams area, I thought I might ask seeing that there is no developer activity on the RHEL ticket (1751985). Unfortunately we have no contacts to OpenJDK developers and also no account at OpenJDK. If you or your colleagues are able to at least link the RHEL bugzilla ticket to the OpenJDK one (or mention it in the OpenJDK ticket), even that would probably be of great help.

Best regards and thanks,
Simeon

Comment 9 Severin Gehwolf 2019-09-27 12:18:03 UTC
Posted and RFR for this upstream:
http://mail.openjdk.java.net/pipermail/serviceability-dev/2019-September/029347.html

Comment 10 Francisco De Melo 2019-11-26 16:11:10 UTC
Hello, any update on this?

Comment 12 Severin Gehwolf 2019-11-26 16:29:13 UTC
(In reply to Francisco De Melo from comment #10)
> Hello, any update on this?

JDK-8196969 has been fixed upstream. I'll investigate possible avenues of getting a fix included in stable release trains.

Comment 13 Francisco De Melo 2019-11-26 19:10:49 UTC
Thank you very much! great!

Comment 18 Andrew John Hughes 2020-02-17 19:05:06 UTC
Moving to rhel-7.9.

Comment 19 Francisco De Melo 2020-02-19 17:47:03 UTC
Hello Severin, which OpenJDK version will have this fix? 
Sorry, it's not clear for me.

Comment 20 Severin Gehwolf 2020-02-19 19:12:07 UTC
(In reply to Francisco De Melo from comment #19)
> Hello Severin, which OpenJDK version will have this fix? 
> Sorry, it's not clear for me.

Right now, it's in 11.0.7. So any EA build from [1] should have it fixed. I don't have jdk8u approval yet, so it's not been pushed to JDK 8u upstream.

[1] https://adoptopenjdk.net/upstream.html?variant=openjdk11&ga=ea

Comment 24 Severin Gehwolf 2020-05-27 09:37:28 UTC
(In reply to Francisco De Melo from comment #19)
> Hello Severin, which OpenJDK version will have this fix? 
> Sorry, it's not clear for me.

This has been integrated into OpenJDK 8u262 now too. Any EA build better than -b04 should have the fix:
https://adoptopenjdk.net/upstream.html?variant=openjdk8&ga=ea

Comment 30 errata-xmlrpc 2020-09-29 19:54:11 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (java-1.8.0-openjdk bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:3920