1 30 31 package oracle.toplink.libraries.asm.attrs; 32 33 import java.util.ArrayList ; 34 import java.util.HashSet ; 35 36 import oracle.toplink.libraries.asm.Attribute; 37 import oracle.toplink.libraries.asm.ByteVector; 38 import oracle.toplink.libraries.asm.ClassReader; 39 import oracle.toplink.libraries.asm.ClassWriter; 40 import oracle.toplink.libraries.asm.Label; 41 42 141 142 public class StackMapAttribute extends Attribute { 143 144 static final int MAX_SIZE = 65535; 145 146 public ArrayList frames = new ArrayList (); 147 148 public StackMapAttribute () { 149 super("StackMap"); 150 } 151 152 public StackMapFrame getFrame (Label label) { 153 for (int i = 0; i < frames.size(); i++) { 154 StackMapFrame frame = (StackMapFrame)frames.get(i); 155 if (frame.label == label) { 156 return frame; 157 } 158 } 159 return null; 160 } 161 162 protected Attribute read (ClassReader cr, int off, int len, 163 char[] buf, int codeOff, Label[] labels) { 164 StackMapAttribute attr = new StackMapAttribute(); 165 int codeSize = cr.readInt(codeOff + 4); 167 int size = 0; 168 if (codeSize > MAX_SIZE) { 169 size = cr.readInt(off); 170 off += 4; 171 } else { 172 size = cr.readShort(off); 173 off += 2; 174 } 175 for (int i = 0; i < size; i++) { 176 StackMapFrame frame = new StackMapFrame(); 177 off = frame.read(cr, off, buf, codeOff, labels); 178 attr.frames.add(frame); 179 } 180 return attr; 181 } 182 183 protected ByteVector write (ClassWriter cw, byte[] code, 184 int len, int maxStack, int maxLocals) { 185 ByteVector bv = new ByteVector(); 186 if ( code!=null && code.length > MAX_SIZE) { 187 bv.putInt(frames.size()); 188 } else { 189 bv.putShort(frames.size()); 190 } 191 for (int i = 0; i < frames.size(); i++) { 192 ((StackMapFrame)frames.get(i)).write(cw, maxStack, maxLocals, bv); 193 } 194 return bv; 195 } 196 197 protected Label[] getLabels () { 198 HashSet labels = new HashSet (); 199 for (int i = 0; i < frames.size(); i++) { 200 ((StackMapFrame)frames.get(i)).getLabels(labels); 201 } 202 return (Label[])labels.toArray(new Label[labels.size()]); 203 } 204 205 public String toString () { 206 StringBuffer sb = new StringBuffer ("StackMap["); 207 for (int i = 0; i < frames.size(); i++) { 208 sb.append('\n').append('[').append(frames.get(i)).append(']'); 209 } 210 sb.append("\n]"); 211 return sb.toString(); 212 } 213 } 214 | Popular Tags |