summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2009-10-20 02:09:31 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2009-10-20 02:09:31 +0000
commit5de87156f94849f27baf77740d76adfb9ada2a07 (patch)
treec5c06550c54838d4f0b129a68ac1c86e025108b2
parent57fb7c93b2b5f41e5bfd82ec754a6c06b39c1080 (diff)
downloadjavassist-5de87156f94849f27baf77740d76adfb9ada2a07.tar.gz
javassist-5de87156f94849f27baf77740d76adfb9ada2a07.zip
for JIRA-95
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@500 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r--src/main/javassist/bytecode/ClassFileWriter.java5
-rw-r--r--src/main/javassist/bytecode/StackMap.java47
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java
index 816ab824..2dcbfc1c 100644
--- a/src/main/javassist/bytecode/ClassFileWriter.java
+++ b/src/main/javassist/bytecode/ClassFileWriter.java
@@ -113,6 +113,11 @@ public class ClassFileWriter {
StackMapTable.Printer.print((StackMapTable)ai, out);
out.println("<stack map table end>");
}
+ else if (ai instanceof StackMap) {
+ out.println("<stack map begin>");
+ StackMap.Printer.print((StackMap)ai, out);
+ out.println("<stack map end>");
+ }
else if (ai instanceof SignatureAttribute) {
SignatureAttribute sa = (SignatureAttribute)ai;
String sig = sa.getSignature();
diff --git a/src/main/javassist/bytecode/StackMap.java b/src/main/javassist/bytecode/StackMap.java
index caef3d80..06b637ee 100644
--- a/src/main/javassist/bytecode/StackMap.java
+++ b/src/main/javassist/bytecode/StackMap.java
@@ -157,6 +157,53 @@ public class StackMap extends AttributeInfo {
}
/**
+ * Printer
+ */
+ public static class Printer {
+ /**
+ * Prints a <code>StackMap</code> attribute.
+ *
+ * @param sm the <code>StackMap</code> attribute.
+ * @param cp the <code>ConstPool</code> of the class file
+ * containing the <code>StackMap</code> attribute.
+ */
+ public static void print(StackMap sm, java.io.PrintWriter out) {
+ int num = sm.numOfEntries();
+ out.println(num + " entries");
+ byte[] srcInfo = sm.get();
+ int pos = 2;
+ for (int i = 0; i < num; i++) {
+ int offset = ByteArray.readU16bit(srcInfo, pos);
+ out.println(" * offset " + offset);
+ pos += 2;
+ int numLoc = ByteArray.readU16bit(srcInfo, pos);
+ pos = printFrames(srcInfo, pos + 2, numLoc);
+ int numStack = ByteArray.readU16bit(srcInfo, pos);
+ pos = printFrames(srcInfo, pos + 2, numStack);
+ }
+ }
+
+ private static int printFrames(byte[] srcInfo, int pos,
+ int numFrames) {
+ for (int k = 0; k < numFrames; k++) {
+ byte tag = srcInfo[pos];
+ if (tag == OBJECT) {
+ ByteArray.readU16bit(srcInfo, pos + 1);
+ pos += 3;
+ }
+ else if (tag == UNINIT) {
+ ByteArray.readU16bit(srcInfo, pos + 1);
+ pos += 3;
+ }
+ else
+ pos++;
+ }
+
+ return pos;
+ }
+ }
+
+ /**
* Internal use only.
*/
public static class Writer {