1 30 31 package oracle.toplink.libraries.asm.attrs; 32 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Set ; 37 38 import oracle.toplink.libraries.asm.ByteVector; 39 import oracle.toplink.libraries.asm.ClassReader; 40 import oracle.toplink.libraries.asm.ClassWriter; 41 import oracle.toplink.libraries.asm.Label; 42 43 44 56 57 public class StackMapFrame { 58 59 public Label label; 60 61 public List locals = new ArrayList (); 62 63 public List stack = new ArrayList (); 64 65 public int read (ClassReader cr, 66 int off, char[] buf, int codeOff, Label[] labels) { 67 int n = cr.readUnsignedShort(off); 68 off += 2; 69 if (labels[n] == null) { 70 labels[n] = new Label(); 71 } 72 label = labels[n]; 73 off = readTypeInfo(cr, off, locals, labels, buf, 74 cr.readUnsignedShort(codeOff + 2)); off = readTypeInfo(cr, off, stack, labels, buf, 76 cr.readUnsignedShort(codeOff)); return off; 78 } 79 80 public void write (ClassWriter cw, 81 int maxStack, int maxLocals, ByteVector bv) { 82 bv.putShort(label.getOffset()); 83 writeTypeInfo(bv, cw, locals, maxLocals); 84 writeTypeInfo(bv, cw, stack, maxStack); 85 } 86 87 public void getLabels (Set labels) { 88 labels.add(label); 89 getTypeInfoLabels(labels, locals); 90 getTypeInfoLabels(labels, stack); 91 } 92 93 private void getTypeInfoLabels (Set labels, List info) { 94 for (Iterator it = info.iterator(); it.hasNext();) { 95 StackMapType typeInfo = (StackMapType)it.next(); 96 if (typeInfo.getType() == StackMapType.ITEM_Uninitialized) { 97 labels.add(typeInfo.getLabel()); 98 } 99 } 100 } 101 102 private int readTypeInfo (ClassReader cr, int off, 103 List info, Label[] labels, char[] buf, int max) { 104 int n = 0; 105 if (max > StackMapAttribute.MAX_SIZE) { 106 n = cr.readInt(off); 107 off += 4; 108 } else { 109 n = cr.readUnsignedShort(off); 110 off += 2; 111 } 112 for (int j = 0; j < n; j++) { 113 int itemType = cr.readByte(off++); 114 StackMapType typeInfo = StackMapType.getTypeInfo(itemType); 115 info.add(typeInfo); 116 switch (itemType) { 117 122 case StackMapType.ITEM_Object: typeInfo.setObject(cr.readClass(off, buf)); 124 off += 2; 125 break; 126 127 case StackMapType.ITEM_Uninitialized: int o = cr.readUnsignedShort(off); 129 off += 2; 130 if (labels[o] == null) { 131 labels[o] = new Label(); 132 } 133 typeInfo.setLabel(labels[o]); 134 break; 135 } 136 } 137 return off; 138 } 139 140 private void writeTypeInfo (ByteVector bv, 141 ClassWriter cw, List info, int max) { 142 if (max > StackMapAttribute.MAX_SIZE) { 143 bv.putInt(info.size()); 144 } else { 145 bv.putShort(info.size()); 146 } 147 for (int j = 0; j < info.size(); j++) { 148 StackMapType typeInfo = (StackMapType)info.get(j); 149 bv.putByte(typeInfo.getType()); 150 switch (typeInfo.getType()) { 151 case StackMapType.ITEM_Object: bv.putShort(cw.newClass(typeInfo.getObject())); 153 break; 154 155 case StackMapType.ITEM_Uninitialized: bv.putShort(typeInfo.getLabel().getOffset()); 157 break; 158 159 } 160 } 161 } 162 163 public String toString () { 164 StringBuffer sb = new StringBuffer ("Frame:L"); 165 sb.append(System.identityHashCode(label)); 166 sb.append(" locals").append(locals); 167 sb.append(" stack").append(stack); 168 return sb.toString(); 169 } 170 } 171 | Popular Tags |