Skip to content

Commit 8e04702

Browse files
quadhierSerguei Spitsyn
authored andcommitted
8242152: SA does not include StackMapTables when dumping .class files
Reviewed-by: cjplummer, sspitsyn
1 parent 3bc475e commit 8e04702

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void update(Observable o, Object data) {
6262
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
6363
Type type = db.lookupType("ConstMethod");
6464
constants = new MetadataField(type.getAddressField("_constants"), 0);
65+
stackMapData = type.getAddressField("_stackmap_data");
6566
constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
6667
flags = new CIntField(type.getCIntegerField("_flags._flags"), 0);
6768

@@ -108,6 +109,7 @@ public ConstMethod(Address addr) {
108109

109110
// Fields
110111
private static MetadataField constants;
112+
private static AddressField stackMapData; // Raw stackmap data for the method (#entries + entries)
111113
private static CIntField constMethodSize;
112114
private static CIntField flags;
113115
private static CIntField codeSize;
@@ -136,6 +138,15 @@ public ConstantPool getConstants() {
136138
return (ConstantPool) constants.getValue(this);
137139
}
138140

141+
public boolean hasStackMapTable() {
142+
return stackMapData.getValue(getAddress()) != null;
143+
}
144+
145+
public U1Array getStackMapData() {
146+
Address addr = stackMapData.getValue(getAddress());
147+
return VMObjectFactory.newObject(U1Array.class, addr);
148+
}
149+
139150
public long getConstMethodSize() {
140151
return constMethodSize.getValue(this);
141152
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Method.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.PrintStream;
2828
import sun.jvm.hotspot.utilities.Observable;
2929
import sun.jvm.hotspot.utilities.Observer;
30+
import sun.jvm.hotspot.utilities.U1Array;
3031

3132
import sun.jvm.hotspot.code.NMethod;
3233
import sun.jvm.hotspot.debugger.Address;
@@ -118,6 +119,12 @@ public ConstMethod getConstMethod() {
118119
public ConstantPool getConstants() {
119120
return getConstMethod().getConstants();
120121
}
122+
public boolean hasStackMapTable() {
123+
return getConstMethod().hasStackMapTable();
124+
}
125+
public U1Array getStackMapData() {
126+
return getConstMethod().getStackMapData();
127+
}
121128
public MethodData getMethodData() {
122129
Address addr = methodData.getValue(getAddress());
123130
return VMObjectFactory.newObject(MethodData.class, addr);

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected void debugMessage(String message) {
5757
protected short _constantValueIndex;
5858
protected short _codeIndex;
5959
protected short _exceptionsIndex;
60+
protected short _stackMapTableIndex;
6061
protected short _lineNumberTableIndex;
6162
protected short _localVariableTableIndex;
6263
protected short _signatureIndex;
@@ -168,6 +169,11 @@ else if(cpConstType == JVM_CONSTANT_Long ||
168169
// Short deprecatedIndex = (Short) utf8ToIndex.get("Deprecated");
169170

170171
// Code attributes
172+
Short stackMapTableIndex = utf8ToIndex.get("StackMapTable");
173+
_stackMapTableIndex = (stackMapTableIndex != null) ?
174+
stackMapTableIndex.shortValue() : 0;
175+
if (DEBUG) debugMessage("StackMapTable index = " + _stackMapTableIndex);
176+
171177
Short lineNumberTableIndex = utf8ToIndex.get("LineNumberTable");
172178
_lineNumberTableIndex = (lineNumberTableIndex != null)?
173179
lineNumberTableIndex.shortValue() : 0;
@@ -515,6 +521,27 @@ protected void writeMethod(Method m) throws IOException {
515521
2 /* catch_type */);
516522
}
517523

524+
boolean hasStackMapTable = m.hasStackMapTable();
525+
U1Array stackMapData = null;
526+
int stackMapAttrLen = 0;
527+
528+
if (hasStackMapTable) {
529+
if (DEBUG) debugMessage("\tmethod has stack map table");
530+
stackMapData = m.getStackMapData();
531+
if (DEBUG) debugMessage("\t\tstack map table length = " + stackMapData.length());
532+
533+
stackMapAttrLen = stackMapData.length();
534+
535+
codeSize += 2 /* stack map table attr index */ +
536+
4 /* stack map table attr length */ +
537+
stackMapAttrLen;
538+
539+
if (DEBUG) debugMessage("\t\tstack map table attr size = " +
540+
stackMapAttrLen);
541+
542+
codeAttrCount++;
543+
}
544+
518545
boolean hasLineNumberTable = m.hasLineNumberTable();
519546
LineNumberTableElement[] lineNumberTable = null;
520547
int lineNumberAttrLen = 0;
@@ -601,6 +628,17 @@ protected void writeMethod(Method m) throws IOException {
601628
dos.writeShort(codeAttrCount);
602629
if (DEBUG) debugMessage("\tcode attribute count = " + codeAttrCount);
603630

631+
// write StackMapTable, if available
632+
if (hasStackMapTable) {
633+
writeIndex(_stackMapTableIndex);
634+
dos.writeInt(stackMapAttrLen);
635+
// We write bytes directly as stackMapData is
636+
// raw data (#entries + entries)
637+
for (int i = 0; i < stackMapData.length(); i++) {
638+
dos.writeByte(stackMapData.at(i));
639+
}
640+
}
641+
604642
// write LineNumberTable, if available.
605643
if (hasLineNumberTable) {
606644
writeIndex(_lineNumberTableIndex);

test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public static void main(String[] args) throws Exception {
8686
System.err.println(out.getStderr());
8787
out.shouldHaveExitValue(0);
8888
out.shouldMatch("public class " + APP_DOT_CLASSNAME);
89+
// StackMapTable might not be generated for a class
90+
// containing only methods with sequential control flows.
91+
// But the class used here (LingeredApp) is not such a case.
92+
out.shouldContain("StackMapTable:");
8993
out.shouldNotContain("Error:");
9094
} catch (SkippedException se) {
9195
throw se;

0 commit comments

Comments
 (0)