Skip to content

Commit 69deec2

Browse files
committed
8378985: serviceability/sa/TestJhsdbJstackMixedWithXComp.java failed if sender frame is return barrier of Continuation
Reviewed-by: cjplummer, mdoerr, fyang
1 parent ceb109f commit 69deec2

15 files changed

Lines changed: 412 additions & 58 deletions

src/hotspot/share/runtime/vmStructs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@
475475
/***********************************/ \
476476
\
477477
static_field(StubRoutines, _call_stub_return_address, address) \
478+
static_field(StubRoutines, _cont_returnBarrier, address) \
478479
\
479480
/***************************************/ \
480481
/* PcDesc and other compiled code info */ \
@@ -786,6 +787,7 @@
786787
static_field(Mutex, _mutex_array, Mutex**) \
787788
static_field(Mutex, _num_mutex, int) \
788789
volatile_nonstatic_field(Mutex, _owner, Thread*) \
790+
nonstatic_field(ContinuationEntry, _parent, ContinuationEntry*) \
789791
static_field(ContinuationEntry, _return_pc, address)
790792

791793
//--------------------------------------------------------------------------------
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2026, NTT DATA.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package sun.jvm.hotspot.runtime;
26+
27+
import sun.jvm.hotspot.debugger.Address;
28+
29+
30+
public class Continuation {
31+
32+
public static boolean isReturnBarrierEntry(Address senderPC) {
33+
if (!Continuations.enabled()) {
34+
return false;
35+
}
36+
return VM.getVM().getStubRoutines().contReturnBarrier().equals(senderPC);
37+
}
38+
39+
public static boolean isSPInContinuation(ContinuationEntry entry, Address sp) {
40+
return entry.getEntrySP().greaterThan(sp);
41+
}
42+
43+
public static ContinuationEntry getContinuationEntryForSP(JavaThread thread, Address sp) {
44+
ContinuationEntry entry = thread.getContEntry();
45+
while (entry != null && !isSPInContinuation(entry, sp)) {
46+
entry = entry.getParent();
47+
}
48+
return entry;
49+
}
50+
51+
public static Frame continuationBottomSender(JavaThread thread, Frame callee, Address senderSP) {
52+
ContinuationEntry ce = getContinuationEntryForSP(thread, callee.getSP());
53+
Frame entry = ce.toFrame();
54+
if (callee.isInterpretedFrame()) {
55+
entry.setSP(senderSP); // sp != unextended_sp
56+
}
57+
return entry;
58+
}
59+
60+
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ContinuationEntry.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2025, NTT DATA.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2025, 2026, NTT DATA.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -26,12 +26,17 @@
2626
package sun.jvm.hotspot.runtime;
2727

2828
import sun.jvm.hotspot.debugger.*;
29-
import sun.jvm.hotspot.runtime.*;
29+
import sun.jvm.hotspot.runtime.aarch64.*;
30+
import sun.jvm.hotspot.runtime.amd64.*;
31+
import sun.jvm.hotspot.runtime.ppc64.*;
32+
import sun.jvm.hotspot.runtime.riscv64.*;
3033
import sun.jvm.hotspot.types.*;
34+
import sun.jvm.hotspot.utilities.*;
3135

3236

33-
public class ContinuationEntry extends VMObject {
37+
public abstract class ContinuationEntry extends VMObject {
3438
private static long size;
39+
private static AddressField parentField;
3540
private static Address returnPC;
3641

3742
static {
@@ -41,13 +46,28 @@ public class ContinuationEntry extends VMObject {
4146
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
4247
Type type = db.lookupType("ContinuationEntry");
4348
size = type.getSize();
49+
parentField = type.getAddressField("_parent");
4450
returnPC = type.getAddressField("_return_pc").getValue();
4551
}
4652

53+
public static ContinuationEntry create(Address addr) {
54+
return switch (VM.getVM().getDebugger().getCPU()) {
55+
case "amd64" -> VMObjectFactory.newObject(AMD64ContinuationEntry.class, addr);
56+
case "aarch64" -> VMObjectFactory.newObject(AARCH64ContinuationEntry.class, addr);
57+
case "riscv64" -> VMObjectFactory.newObject(RISCV64ContinuationEntry.class, addr);
58+
case "ppc64" -> VMObjectFactory.newObject(PPC64ContinuationEntry.class, addr);
59+
default -> throw new UnsupportedPlatformException("Continuation is not yet implemented.");
60+
};
61+
}
62+
4763
public ContinuationEntry(Address addr) {
4864
super(addr);
4965
}
5066

67+
public ContinuationEntry getParent() {
68+
return create(parentField.getValue(addr));
69+
}
70+
5171
public Address getEntryPC() {
5272
return returnPC;
5373
}
@@ -60,4 +80,6 @@ public Address getEntryFP(){
6080
return this.getAddress().addOffsetTo(size);
6181
}
6282

83+
public abstract Frame toFrame();
84+
6385
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2026, NTT DATA.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package sun.jvm.hotspot.runtime;
26+
27+
public class Continuations {
28+
29+
public static boolean enabled() {
30+
return VM.getVM().getCommandLineFlag("VMContinuations").getBool();
31+
}
32+
33+
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Frame.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -138,6 +138,7 @@ public CodeBlob cb() {
138138
}
139139

140140
public abstract Address getSP();
141+
public abstract void setSP(Address newSP);
141142
public abstract Address getID();
142143
public abstract Address getFP();
143144

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JavaThread.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -343,7 +343,7 @@ public int getTerminated() {
343343
}
344344

345345
public ContinuationEntry getContEntry() {
346-
return VMObjectFactory.newObject(ContinuationEntry.class, contEntryField.getValue(addr));
346+
return ContinuationEntry.create(contEntryField.getValue(addr));
347347
}
348348

349349
/** Gets the Java-side thread object for this JavaThread */

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StubRoutines.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
3434

3535
public class StubRoutines {
3636
private static AddressField callStubReturnAddressField;
37+
private static AddressField contReturnBarrierField;
3738

3839
static {
3940
VM.registerVMInitializedObserver(new Observer() {
@@ -46,6 +47,7 @@ public void update(Observable o, Object data) {
4647
private static synchronized void initialize(TypeDataBase db) {
4748
Type type = db.lookupType("StubRoutines");
4849
callStubReturnAddressField = type.getAddressField("_call_stub_return_address");
50+
contReturnBarrierField = type.getAddressField("_cont_returnBarrier");
4951
}
5052

5153
public StubRoutines() {
@@ -59,4 +61,9 @@ public boolean returnsToCallStub(Address returnPC) {
5961
return (addr.equals(returnPC));
6062
}
6163
}
64+
65+
public Address contReturnBarrier() {
66+
return contReturnBarrierField.getValue();
67+
}
68+
6269
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2026, NTT DATA.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package sun.jvm.hotspot.runtime.aarch64;
26+
27+
import sun.jvm.hotspot.debugger.Address;
28+
import sun.jvm.hotspot.runtime.ContinuationEntry;
29+
import sun.jvm.hotspot.runtime.Frame;
30+
31+
32+
public class AARCH64ContinuationEntry extends ContinuationEntry {
33+
34+
public AARCH64ContinuationEntry(Address addr) {
35+
super(addr);
36+
}
37+
38+
@Override
39+
public Frame toFrame() {
40+
return new AARCH64Frame(getEntrySP(), getEntrySP(), getEntryFP(), getEntryPC());
41+
}
42+
43+
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/aarch64/AARCH64Frame.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2015, 2019, Red Hat Inc.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -206,6 +206,11 @@ public String toString() {
206206
public Address getSP() { return raw_sp; }
207207
public Address getID() { return raw_sp; }
208208

209+
@Override
210+
public void setSP(Address newSP) {
211+
raw_sp = newSP;
212+
}
213+
209214
// FIXME: not implemented yet
210215
public boolean isSignalHandlerFrameDbg() { return false; }
211216
public int getSignalNumberDbg() { return 0; }
@@ -360,16 +365,6 @@ private void updateMapWithSavedLink(RegisterMap map, Address savedFPAddr) {
360365
map.setLocation(fp, savedFPAddr);
361366
}
362367

363-
private Frame senderForContinuationStub(AARCH64RegisterMap map, CodeBlob cb) {
364-
var contEntry = map.getThread().getContEntry();
365-
366-
Address senderSP = contEntry.getEntrySP();
367-
Address senderPC = contEntry.getEntryPC();
368-
Address senderFP = contEntry.getEntryFP();
369-
370-
return new AARCH64Frame(senderSP, senderFP, senderPC);
371-
}
372-
373368
private Frame senderForCompiledFrame(AARCH64RegisterMap map, CodeBlob cb) {
374369
if (DEBUG) {
375370
System.out.println("senderForCompiledFrame");
@@ -416,6 +411,22 @@ private Frame senderForCompiledFrame(AARCH64RegisterMap map, CodeBlob cb) {
416411
updateMapWithSavedLink(map, savedFPAddr);
417412
}
418413

414+
if (Continuation.isReturnBarrierEntry(senderPC)) {
415+
// We assume WalkContinuation is "WalkContinuation::skip".
416+
// It is same with c'tor arguments of RegisterMap in frame::next_frame().
417+
//
418+
// HotSpot code in cpu/aarch64/frame_aarch64.inline.hpp:
419+
//
420+
// if (Continuation::is_return_barrier_entry(sender_pc)) {
421+
// if (map->walk_cont()) { // about to walk into an h-stack
422+
// return Continuation::top_frame(*this, map);
423+
// } else {
424+
// return Continuation::continuation_bottom_sender(map->thread(), *this, l_sender_sp);
425+
// }
426+
// }
427+
return Continuation.continuationBottomSender(map.getThread(), this, senderSP);
428+
}
429+
419430
return new AARCH64Frame(senderSP, savedFPAddr.getAddressAt(0), senderPC);
420431
}
421432

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2026, NTT DATA.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package sun.jvm.hotspot.runtime.amd64;
26+
27+
import sun.jvm.hotspot.debugger.Address;
28+
import sun.jvm.hotspot.runtime.ContinuationEntry;
29+
import sun.jvm.hotspot.runtime.Frame;
30+
31+
32+
public class AMD64ContinuationEntry extends ContinuationEntry {
33+
34+
public AMD64ContinuationEntry(Address addr) {
35+
super(addr);
36+
}
37+
38+
@Override
39+
public Frame toFrame() {
40+
return new AMD64Frame(getEntrySP(), getEntrySP(), getEntryFP(), getEntryPC());
41+
}
42+
43+
}

0 commit comments

Comments
 (0)