4bac2b27b64ff71deb19eaed631ee1b521e1191f
[jpf-core.git] / src / main / gov / nasa / jpf / jvm / ClassFile.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package gov.nasa.jpf.jvm;
20
21 import java.io.File;
22
23 import gov.nasa.jpf.JPFException;
24 import gov.nasa.jpf.util.BailOut;
25 import gov.nasa.jpf.util.BinaryClassSource;
26 import gov.nasa.jpf.vm.ClassParseException;
27
28 /**
29  * class to read and dissect Java classfile contents (as specified by the Java VM
30  * spec  http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#16628
31  */
32 public class ClassFile extends BinaryClassSource {
33
34   public static final int CONSTANT_UTF8 = 1;
35   public static final int CONSTANT_INTEGER = 3;
36   public static final int CONSTANT_FLOAT = 4;
37   public static final int CONSTANT_LONG = 5;
38   public static final int CONSTANT_DOUBLE = 6;
39   public static final int CONSTANT_CLASS = 7;
40   public static final int CONSTANT_STRING = 8;
41   public static final int FIELD_REF = 9;
42   public static final int METHOD_REF = 10;
43   public static final int INTERFACE_METHOD_REF = 11;
44   public static final int NAME_AND_TYPE = 12;
45   public static final int METHOD_HANDLE = 15;
46   public static final int METHOD_TYPE = 16;
47   public static final int INVOKE_DYNAMIC = 18;
48
49   public static final int REF_GETFIELD = 1;
50   public static final int REF_GETSTATIC = 2;
51   public static final int REF_PUTFIELD = 3;
52   public static final int REF_PUTSTATIC = 4;
53   public static final int REF_INVOKEVIRTUAL = 5;
54   public static final int REF_INVOKESTATIC = 6;
55   public static final int REF_INVOKESPECIAL = 7;
56   public static final int REF_NEW_INVOKESPECIAL = 8;
57   public static final int REF_INVOKEINTERFACE = 9;
58
59   // used to store types in cpValue[]
60   public static enum CpInfo {
61     Unused_0,                 // 0
62     ConstantUtf8,             // 1
63     Unused_2,                 // 2
64     ConstantInteger,          // 3
65     ConstantFloat,            // 4
66     ConstantLong,             // 5
67     ConstantDouble,           // 6
68     ConstantClass,            // 7
69     ConstantString,           // 8
70     FieldRef,                 // 9
71     MethodRef,                // 10
72     InterfaceMethodRef,       // 11
73     NameAndType,              // 12
74     Unused_13,
75     Unused_14,
76     MethodHandle,             // 15
77     MethodType,               // 16
78     Unused_17,
79     InvokeDynamic             // 18
80   }
81
82   // <2do> this is going away
83   String requestedTypeName; // the type name that caused this classfile to be loaded
84
85   // the const pool
86   int[] cpPos;     // cpPos[i] holds data start index for cp_entry i (0 is unused)
87   Object[] cpValue; // cpValue[i] hold the String/Integer/Float/Double associated with corresponding cp_entries
88   
89   //--- ctors
90   public ClassFile (byte[] data, int offset){
91     super(data,offset);
92   }
93
94   public ClassFile (byte[] data){
95     super(data,0);
96   }
97
98   public ClassFile (String typeName, byte[] data){
99     super(data,0);
100     
101     this.requestedTypeName = typeName;
102   }
103   
104   public ClassFile (String typeName, byte[] data, int offset){
105     super(data, offset);
106     
107     this.requestedTypeName = typeName;
108   }
109
110   public ClassFile (File file) throws ClassParseException {
111     super(file);
112   }
113
114   public ClassFile (String pathName)  throws ClassParseException {
115     super( new File(pathName));
116   }
117
118
119
120   
121   /**
122    * set classfile data.  This is mainly provided to allow
123    * on-the-fly classfile instrumentation with 3rd party libraries
124    * 
125    * BEWARE - like getData(), this method can cause parsing to fail if the
126    * provided data does not conform to the VM specs. In particular, this
127    * method should ONLY be called before executing parse(ClassFileReader) and
128    * will otherwise throw a JPFException
129    */
130   public void setData(byte[] newData){
131     if (cpPos != null){
132       throw new JPFException("concurrent modification of ClassFile data");
133     }
134     
135     data = newData;
136   }
137   
138   /**
139    * return the typename this classfile gets loaded for
140    * <2do> this is going away
141    */
142   public String getRequestedTypeName(){
143     return requestedTypeName;
144   }
145
146
147   //--- general attributes
148   public static final String SYNTHETIC_ATTR = "Synthetic";
149   public static final String DEPRECATED_ATTR = "Deprecated";
150   public static final String SIGNATURE_ATTR = "Signature";
151   public static final String RUNTIME_INVISIBLE_ANNOTATIONS_ATTR = "RuntimeInvisibleAnnotations";
152   public static final String RUNTIME_VISIBLE_ANNOTATIONS_ATTR = "RuntimeVisibleAnnotations";
153   public static final String RUNTIME_VISIBLE_TYPE_ANNOTATIONS_ATTR = "RuntimeVisibleTypeAnnotations";
154
155   //--- standard field attributes
156   public static final String CONST_VALUE_ATTR = "ConstantValue";
157
158   protected final static String[] stdFieldAttrs = {
159     CONST_VALUE_ATTR, SYNTHETIC_ATTR, DEPRECATED_ATTR, SIGNATURE_ATTR,
160     RUNTIME_INVISIBLE_ANNOTATIONS_ATTR, RUNTIME_VISIBLE_ANNOTATIONS_ATTR, RUNTIME_VISIBLE_TYPE_ANNOTATIONS_ATTR };
161
162
163   //--- standard method attributes
164   public static final String CODE_ATTR = "Code";
165   public static final String EXCEPTIONS_ATTR = "Exceptions";
166   public static final String RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS_ATTR = "RuntimeInvisibleParameterAnnotations";
167   public static final String RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS_ATTR = "RuntimeVisibleParameterAnnotations";
168   public static final String ANNOTATIONDEFAULT_ATTR = "AnnotationDefault";
169
170   protected final static String[] stdMethodAttrs = { 
171     CODE_ATTR, EXCEPTIONS_ATTR, SYNTHETIC_ATTR, DEPRECATED_ATTR, SIGNATURE_ATTR,
172     RUNTIME_INVISIBLE_ANNOTATIONS_ATTR, RUNTIME_VISIBLE_ANNOTATIONS_ATTR,
173     RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS_ATTR,
174     RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS_ATTR,
175     RUNTIME_VISIBLE_TYPE_ANNOTATIONS_ATTR,
176     ANNOTATIONDEFAULT_ATTR
177   };
178
179
180   //--- standard code attributes
181   public static final String LINE_NUMBER_TABLE_ATTR = "LineNumberTable";
182   public static final String LOCAL_VAR_TABLE_ATTR = "LocalVariableTable";
183
184   protected final static String[] stdCodeAttrs = { LINE_NUMBER_TABLE_ATTR, LOCAL_VAR_TABLE_ATTR, RUNTIME_VISIBLE_TYPE_ANNOTATIONS_ATTR };
185
186
187   //--- standard class attributes
188   public static final String  SOURCE_FILE_ATTR = "SourceFile";
189   public static final String  INNER_CLASSES_ATTR = "InnerClasses";
190   public static final String  ENCLOSING_METHOD_ATTR = "EnclosingMethod";
191   public static final String  BOOTSTRAP_METHOD_ATTR = "BootstrapMethods";
192   
193   protected final static String[] stdClassAttrs = {
194     SOURCE_FILE_ATTR, DEPRECATED_ATTR, INNER_CLASSES_ATTR, DEPRECATED_ATTR, SIGNATURE_ATTR,
195     RUNTIME_INVISIBLE_ANNOTATIONS_ATTR, RUNTIME_VISIBLE_ANNOTATIONS_ATTR, RUNTIME_VISIBLE_TYPE_ANNOTATIONS_ATTR,
196     ENCLOSING_METHOD_ATTR, BOOTSTRAP_METHOD_ATTR };
197
198
199   protected String internStdAttrName(int cpIdx, String name, String[] stdNames){
200     for (int i=0; i<stdNames.length; i++){
201       if (stdNames[i] == name) return name;
202     }
203     for (int i=0; i<stdNames.length; i++){
204       String stdName = stdNames[i];
205       if (stdName.equals(name)){
206         cpValue[cpIdx] = stdName;
207         return stdName;
208       }
209     }
210     return name;
211   }
212
213
214   //--- constpool access
215
216   //--- the primitive info cpValue
217   public String utf8At(int utf8InfoIdx){
218     //assert data[cpPos[utf8InfoIdx]] == 1 : "not a utf8_info tag";
219     return (String) cpValue[utf8InfoIdx];
220   }
221
222   public int intAt(int intInfoIdx){
223     //assert data[cpPos[intInfoIdx]] == 3 : "not a int_info tag";
224     return (Integer) cpValue[intInfoIdx];
225   }
226
227   public float floatAt(int floatInfoIdx){
228     //assert data[cpPos[floatInfoIdx]] == 4 : "not a float_info tag";
229     return (Float) cpValue[floatInfoIdx];
230   }
231
232   public long longAt(int longInfoIdx){
233     //assert data[cpPos[longInfoIdx]] == 5 : "not a long_info tag";
234     return (Long) cpValue[longInfoIdx];
235   }
236
237   public double doubleAt(int doubleInfoIdx){
238     //assert data[cpPos[doubleInfoIdx]] == 6 : "not a double_info tag";
239     return (Double) cpValue[doubleInfoIdx];
240   }
241
242   //--- those two are delegated but resolved
243   public String classNameAt(int classInfoIdx){
244     //assert data[cpPos[classInfoIdx]] == 7 : "not a Class_info tag";
245     return (String) cpValue[classInfoIdx];
246   }
247
248   public String stringAt(int stringInfoIdx){
249     //assert data[cpPos[stringInfoIdx]] == 8 : "not a String_info tag";
250     return (String) cpValue[stringInfoIdx];
251   }
252
253   //--- composite infos
254
255   // the generic ones (if we don't care what kind of reference type this is)
256   public String refClassNameAt(int cpIdx){
257     return (String) cpValue[ u2(cpPos[cpIdx]+1)];
258   }
259   public String refNameAt(int cpIdx){
260     return utf8At( u2( cpPos[ u2(cpPos[cpIdx]+3)]+1));
261   }
262   public String refDescriptorAt(int cpIdx){
263     return utf8At( u2( cpPos[ u2(cpPos[cpIdx]+3)]+3));
264   }
265
266   public int mhRefTypeAt (int methodHandleInfoIdx){
267     return u1(cpPos[methodHandleInfoIdx]+1);
268   }
269   public int mhMethodRefIndexAt  (int methodHandleInfoIdx){
270     return u2(cpPos[methodHandleInfoIdx]+2);
271   }
272   
273   // those could check ref types
274   public String fieldClassNameAt(int fieldRefInfoIdx){
275     //assert data[cpPos[fieldRefInfoIdx]] == 9 : "not a Fieldref_info tag";
276     return (String) cpValue[ u2(cpPos[fieldRefInfoIdx]+1)];
277   }
278   public String fieldNameAt(int fieldRefInfoIdx){
279     return utf8At( u2( cpPos[ u2(cpPos[fieldRefInfoIdx]+3)]+1));
280   }
281   public String fieldDescriptorAt(int fieldRefInfoIdx){
282     return utf8At( u2( cpPos[ u2(cpPos[fieldRefInfoIdx]+3)]+3));
283   }
284
285   public String methodClassNameAt(int methodRefInfoIdx){
286     return (String) cpValue[ u2(cpPos[methodRefInfoIdx]+1)];
287   }
288   public String methodNameAt(int methodRefInfoIdx){
289     return utf8At( u2( cpPos[ u2(cpPos[methodRefInfoIdx]+3)]+1));
290   }
291   public String methodDescriptorAt(int methodRefInfoIdx){
292     return utf8At( u2( cpPos[ u2(cpPos[methodRefInfoIdx]+3)]+3));
293   }
294
295   public String methodTypeDescriptorAt (int methodTypeInfoIdx){
296     return utf8At( u2(cpPos[methodTypeInfoIdx]+1));
297   }
298   
299   public String interfaceMethodClassNameAt(int ifcMethodRefInfoIdx){
300     return (String) cpValue[ u2(cpPos[ifcMethodRefInfoIdx]+1)];
301   }
302   public String interfaceMethodNameAt(int ifcMethodRefInfoIdx){
303     return utf8At( u2( cpPos[ u2(cpPos[ifcMethodRefInfoIdx]+3)]+1));
304   }
305   public String interfaceMethodDescriptorAt(int ifcMethodRefInfoIdx){
306     return utf8At( u2( cpPos[ u2(cpPos[ifcMethodRefInfoIdx]+3)]+3));
307   }
308   
309   public int bootstrapMethodIndex (int cpInvokeDynamicIndex){
310     return u2(cpPos[cpInvokeDynamicIndex]+1);
311   }
312   public String samMethodNameAt(int cpInvokeDynamicIndex) {
313     return utf8At( u2( cpPos[ u2(cpPos[cpInvokeDynamicIndex]+3)]+1)); 
314   }
315   public String callSiteDescriptor(int cpInvokeDynamicIndex) {
316     return utf8At( u2( cpPos[ u2(cpPos[cpInvokeDynamicIndex]+3)]+3)); 
317   }
318   
319   public String getRefTypeName (int refCode){
320     switch (refCode){
321       case REF_GETFIELD:      return "getfield";
322       case REF_GETSTATIC:     return "getstatic";
323       case REF_PUTFIELD:      return "putfield";
324       case REF_PUTSTATIC:     return "putstatic";
325       case REF_INVOKEVIRTUAL: return "invokevirtual";
326       case REF_INVOKESTATIC:  return "invokestatic";
327       case REF_INVOKESPECIAL: return "invokespecial";
328       case REF_NEW_INVOKESPECIAL: return "new-invokespecial";
329       case REF_INVOKEINTERFACE: return "invokeinterface";
330       default:
331         return "<unknown>";
332     }
333   }
334   
335   public String getTypeName (int typeCode){
336     switch(typeCode){
337       case 4: return "boolean";
338       case 5: return "char";
339       case 6: return "float";
340       case 7: return "double";
341       case 8: return "byte";
342       case 9: return "short";
343       case 10: return "int";
344       case 11: return "long";
345       default:
346         return "<unknown>";
347     }
348   }
349
350   @Override
351   public int getPos(){
352     return pos;
353   }
354
355   public int getPc(){
356     return pc;
357   }
358
359   //--- traverse/analyze the const pool (this is rather exotic)
360
361   public int getNumberOfCpEntries(){
362     return cpValue.length;
363   }
364
365   public Object getCpValue (int i){
366     return cpValue[i];
367   }
368
369   public int getCpTag (int i){
370     return data[cpPos[i]];
371   }
372
373   /**
374    * the result can be used as input for u2(dataIndex)
375    *
376    * NOTE - this returns -1 for the dreaded unused extra entries associated
377    * with ConstantDouble and ConstantLong
378    */
379   public int getDataPosOfCpEntry (int i){
380     return cpPos[i];
381   }
382
383   //--- standard attributes
384
385   public Object getConstValueAttribute(int dataPos){
386     int cpIdx = u2(dataPos);
387     Object v = cpValue[cpIdx];
388     return v;
389   }
390
391   public String getSourceFileAttribute(int dataPos){
392     // SourceFile_attribute { u2 attr_name_idx; u4 attr_length; u2 sourcefile_idx<utf8>; }
393
394     int cpIdx = u2(dataPos + 6);
395     Object v = cpValue[cpIdx];
396     return (String)v;
397   }
398
399   
400   //--- low level readers
401
402   public final int u1(int dataIdx){
403     return data[dataIdx] & 0xff;
404   }
405
406   public final int u2(int dataIdx){
407     return ((data[dataIdx]&0xff) << 8) | (data[dataIdx+1]&0xff);
408   }
409
410   public final int i1(int dataIdx) {
411     return data[dataIdx++];
412   }
413
414   public final int i2(int dataIdx) {
415     int idx = dataIdx;
416     return (data[idx++] << 8) | (data[idx]&0xff);
417   }
418
419   public final int readU2(){
420     int idx = pos;
421     pos += 2;
422     return ((data[idx++]&0xff) << 8) | (data[idx]&0xff);
423   }
424
425   public final int readI2() {
426     int idx = pos;
427     pos += 2;
428     return (data[idx++] << 8) | (data[idx]&0xff);
429   }
430
431   public final int readI4(){
432     int idx = pos;
433     pos += 4;
434     byte[] data = this.data;
435
436     return (data[idx++] <<24) | ((data[idx++]&0xff) << 16) | ((data[idx++]&0xff) << 8) | (data[idx]&0xff);
437   }
438
439   
440   //--- reader notifications
441   private void setClass(ClassFileReader reader, String clsName, String superClsName, int flags, int cpCount) throws ClassParseException {
442     int p = pos;
443     reader.setClass( this, clsName, superClsName, flags, cpCount);
444     pos = p;
445   }
446
447   private void setInterfaceCount(ClassFileReader reader, int ifcCount){
448     int p = pos;
449     reader.setInterfaceCount( this, ifcCount);
450     pos = p;
451   }
452   private void setInterface(ClassFileReader reader, int ifcIndex, String ifcName){
453     int p = pos;
454     reader.setInterface( this, ifcIndex, ifcName);
455     pos = p;
456   }
457   private void setInterfacesDone(ClassFileReader reader){
458     int p = pos;
459     reader.setInterfacesDone( this);
460     pos = p;
461   }
462
463
464   private void setFieldCount(ClassFileReader reader, int fieldCount){
465     int p = pos;
466     reader.setFieldCount( this, fieldCount);
467     pos = p;
468
469   }
470   private void setField(ClassFileReader reader, int fieldIndex, int accessFlags, String name, String descriptor){
471     int p = pos;
472     reader.setField( this, fieldIndex, accessFlags, name, descriptor);
473     pos = p;
474   }
475   private void setFieldAttributeCount(ClassFileReader reader, int fieldIndex, int attrCount){
476     int p = pos;
477     reader.setFieldAttributeCount( this, fieldIndex, attrCount);
478     pos = p;
479   }
480   private void setFieldAttribute(ClassFileReader reader, int fieldIndex, int attrIndex, String name, int attrLength){
481     int p = pos + attrLength;
482     reader.setFieldAttribute( this, fieldIndex, attrIndex, name, attrLength);
483     pos = p;
484   }
485   private void setFieldAttributesDone(ClassFileReader reader, int fieldIndex){
486     int p = pos;
487     reader.setFieldAttributesDone( this, fieldIndex);
488     pos = p;
489   }
490   private void setFieldDone(ClassFileReader reader, int fieldIndex){
491     int p = pos;
492     reader.setFieldDone( this, fieldIndex);
493     pos = p;
494   }
495   private void setFieldsDone(ClassFileReader reader){
496     int p = pos;
497     reader.setFieldsDone( this);
498     pos = p;
499   }
500   private void setConstantValue(ClassFileReader reader, Object tag, Object value){
501     int p = pos;
502     reader.setConstantValue( this, tag, value);
503     pos = p;
504   }
505
506   private void setMethodCount(ClassFileReader reader, int methodCount){
507     int p = pos;
508     reader.setMethodCount( this, methodCount);
509     pos = p;
510   }
511   private void setMethod(ClassFileReader reader, int methodIndex, int accessFlags, String name, String descriptor){
512     int p = pos;
513     reader.setMethod( this, methodIndex, accessFlags, name, descriptor);
514     pos = p;
515   }
516   private void setMethodAttributeCount(ClassFileReader reader, int methodIndex, int attrCount){
517     int p = pos;
518     reader.setMethodAttributeCount( this, methodIndex, attrCount);
519     pos = p;
520   }
521   private void setMethodAttribute(ClassFileReader reader, int methodIndex, int attrIndex, String name, int attrLength){
522     int p = pos + attrLength;
523     reader.setMethodAttribute( this, methodIndex, attrIndex, name, attrLength);
524     pos = p;
525   }
526   private void setMethodAttributesDone(ClassFileReader reader, int methodIndex){
527     int p = pos;
528     reader.setMethodAttributesDone( this, methodIndex);
529     pos = p;
530   }
531   private void setMethodDone(ClassFileReader reader, int methodIndex){
532     int p = pos;
533     reader.setMethodDone( this, methodIndex);
534     pos = p;
535   }
536   private void setMethodsDone(ClassFileReader reader){
537     int p = pos;
538     reader.setMethodsDone( this);
539     pos = p;
540   }
541   private void setExceptionCount(ClassFileReader reader, Object tag, int exceptionCount){
542     int p = pos;
543     reader.setExceptionCount( this, tag, exceptionCount);
544     pos = p;
545   }
546   private void setExceptionsDone(ClassFileReader reader, Object tag){
547     int p = pos;
548     reader.setExceptionsDone( this, tag);
549     pos = p;
550   }
551   private void setException(ClassFileReader reader, Object tag, int exceptionIndex, String exceptionType){
552     int p = pos;
553     reader.setException( this, tag, exceptionIndex, exceptionType);
554     pos = p;
555   }
556   private void setCode(ClassFileReader reader, Object tag, int maxStack, int maxLocals, int codeLength){
557     int p = pos + codeLength;
558     reader.setCode( this, tag, maxStack, maxLocals, codeLength);
559     pos = p;
560   }
561   private void setExceptionTableCount(ClassFileReader reader, Object tag, int exceptionTableCount){
562     int p = pos;
563     reader.setExceptionHandlerTableCount( this, tag, exceptionTableCount);
564     pos = p;
565   }
566   private void setExceptionTableEntry(ClassFileReader reader, Object tag, int exceptionIndex,
567           int startPc, int endPc, int handlerPc, String catchType){
568     int p = pos;
569     reader.setExceptionHandler( this, tag, exceptionIndex, startPc, endPc, handlerPc, catchType);
570     pos = p;
571   }
572   private void setExceptionTableDone(ClassFileReader reader, Object tag){
573     int p = pos;
574     reader.setExceptionHandlerTableDone( this, tag);
575     pos = p;
576   }
577
578   private void setCodeAttributeCount(ClassFileReader reader, Object tag, int attrCount){
579     int p = pos;
580     reader.setCodeAttributeCount( this, tag, attrCount);
581     pos = p;
582   }
583   private void setCodeAttribute(ClassFileReader reader, Object tag, int attrIndex, String name, int attrLength){
584     int p = pos + attrLength;
585     reader.setCodeAttribute( this, tag, attrIndex, name, attrLength);
586     pos = p;
587   }
588   private void setCodeAttributesDone(ClassFileReader reader, Object tag){
589     int p = pos;
590     reader.setCodeAttributesDone( this, tag);
591     pos = p;
592   }
593           
594   private void setLineNumberTableCount(ClassFileReader reader, Object tag, int lineNumberCount){
595     int p = pos;
596     reader.setLineNumberTableCount( this, tag, lineNumberCount);
597     pos = p;
598   }
599   private void setLineNumber(ClassFileReader reader, Object tag, int lineIndex, int lineNumber, int startPc){
600     int p = pos;
601     reader.setLineNumber( this, tag, lineIndex, lineNumber, startPc);
602     pos = p;
603   }
604   private void setLineNumberTableDone(ClassFileReader reader, Object tag){
605     int p = pos;
606     reader.setLineNumberTableDone( this, tag);
607     pos = p;
608   }
609
610   private void setLocalVarTableCount(ClassFileReader reader, Object tag, int localVarCount){
611     int p = pos;
612     reader.setLocalVarTableCount( this, tag, localVarCount);
613     pos = p;
614   }
615   private void setLocalVar(ClassFileReader reader, Object tag, int localVarIndex, String varName, String descriptor,
616                       int scopeStartPc, int scopeEndPc, int slotIndex){
617     int p = pos;
618     reader.setLocalVar( this, tag, localVarIndex, varName, descriptor, scopeStartPc, scopeEndPc, slotIndex);
619     pos = p;
620   }
621   private void setLocalVarTableDone(ClassFileReader reader, Object tag){
622     int p = pos;
623     reader.setLocalVarTableDone( this, tag);
624     pos = p;
625   }
626
627
628   private void setClassAttributeCount(ClassFileReader reader, int attrCount){
629     int p = pos;
630     reader.setClassAttributeCount( this, attrCount);
631     pos = p;
632   }
633   private void setClassAttribute(ClassFileReader reader, int attrIndex, String name, int attrLength){
634     int p = pos + attrLength;
635     reader.setClassAttribute( this, attrIndex, name, attrLength);
636     pos = p;
637   }
638   private void setClassAttributesDone(ClassFileReader reader){
639     int p = pos;
640     reader.setClassAttributesDone(this);
641     pos = p;
642   }
643
644   private void setSourceFile(ClassFileReader reader, Object tag, String pathName){
645     int p = pos;
646     reader.setSourceFile( this, tag, pathName);
647     pos = p;
648   }
649   
650   private void setBootstrapMethodCount (ClassFileReader reader, Object tag, int bootstrapMethodCount){
651     int p = pos;
652     reader.setBootstrapMethodCount( this, tag, bootstrapMethodCount);
653     pos = p;    
654   }
655   private void setBootstrapMethod (ClassFileReader reader, Object tag, int idx, 
656                                    int refKind, String cls, String mth, String descriptor, int[] cpArgs){
657     int p = pos;
658     reader.setBootstrapMethod( this, tag, idx, refKind, cls, mth, descriptor, cpArgs);
659     pos = p;    
660   }
661   private void setBootstrapMethodsDone (ClassFileReader reader, Object tag){
662     int p = pos;
663     reader.setBootstrapMethodsDone( this, tag);
664     pos = p;    
665   }
666   
667   private void setInnerClassCount(ClassFileReader reader, Object tag, int innerClsCount){
668     int p = pos;
669     reader.setInnerClassCount( this, tag, innerClsCount);
670     pos = p;
671   }
672   private void setInnerClass(ClassFileReader reader, Object tag, int innerClsIndex, String outerName, String innerName,
673           String innerSimpleName, int accessFlags){
674     int p = pos;
675     reader.setInnerClass( this, tag, innerClsIndex, outerName, innerName, innerSimpleName, accessFlags);
676     pos = p;
677   }
678   private void setEnclosingMethod(ClassFileReader reader, Object tag, String enclosingClass, String enclosedMethod, String descriptor){
679     int p = pos;
680           reader.setEnclosingMethod( this, tag, enclosingClass, enclosedMethod, descriptor);
681           pos = p;
682   }
683   private void setInnerClassesDone(ClassFileReader reader, Object tag){
684     int p = pos;
685     reader.setInnerClassesDone(this, tag);
686     pos = p;
687   }
688
689   private void setAnnotationCount(ClassFileReader reader, Object tag, int annotationCount){
690     int p = pos;
691     reader.setAnnotationCount( this, tag, annotationCount);
692     pos = p;
693   }
694   private boolean setAnnotation(ClassFileReader reader, Object tag, int annotationIndex, String annotationType){
695     int p = pos;
696     try {
697       reader.setAnnotation( this, tag, annotationIndex, annotationType);
698       pos = p;
699       return true;
700     } catch (SkipAnnotation sa) {
701       this.skipAnnotation(false);
702       return false;
703     }
704   }
705   
706   /*
707    * This is largely lifted from AnnotationParser.java
708    *   annotation {
709    *     u2 type_index;
710    *     u2 num_element_value_pairs;
711    *     {
712    *       u2 element_name_index;
713    *       element_value value;
714    *     } element_value_pairs[num_element_value_pairs]
715    *   }
716    */
717   private void skipAnnotation(boolean skipTypeIndex) {
718     if(skipTypeIndex) { // we may want to skip after reading the type name
719       readU2();
720     }
721     int numKV = readU2();
722     for(int i = 0; i < numKV; i++) {
723       readU2(); // skip name
724       skipMemberValue();
725     }
726   }
727
728   /*
729    * Skips an element_value
730    */
731   private void skipMemberValue() {
732     int tag = readUByte();
733     switch(tag) {
734     case 'e': // Enum value
735       pos += 4; // an enum value is a struct of two shorts, for 4 bytes total
736       break;
737     case '@':
738       skipAnnotation(true);
739       break;
740     case '[':
741       skipArray();
742       break;
743     default:
744       pos += 2; // either two bye const val index or two byte class info index
745     }
746   }
747
748   private void skipArray() {
749     int len = readU2();
750     for(int i = 0; i < len; i++) {
751       skipMemberValue();
752     }
753   }
754
755   private void setAnnotationsDone(ClassFileReader reader, Object tag){
756     int p = pos;
757     reader.setAnnotationsDone(this, tag);
758     pos = p;
759   }
760
761   private void setTypeAnnotationCount(ClassFileReader reader, Object tag, int annotationCount){
762     int p = pos;
763     reader.setTypeAnnotationCount( this, tag, annotationCount);
764     pos = p;
765   }
766   private void setTypeAnnotationsDone(ClassFileReader reader, Object tag){
767     int p = pos;
768     reader.setTypeAnnotationsDone(this, tag);
769     pos = p;
770   }
771
772   
773   private void setAnnotationValueCount(ClassFileReader reader, Object tag, int annotationIndex, int nValuePairs){
774     int p = pos;
775     reader.setAnnotationValueCount( this, tag, annotationIndex, nValuePairs);
776     pos = p;
777   }
778   private void setPrimitiveAnnotationValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
779           String elementName, int arrayIndex, Object val){
780     int p = pos;
781     reader.setPrimitiveAnnotationValue( this, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
782     pos = p;
783   }
784   private void setStringAnnotationValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
785           String elementName, int arrayIndex, String s){
786     int p = pos;
787     reader.setStringAnnotationValue( this, tag, annotationIndex, valueIndex, elementName, arrayIndex, s);
788     pos = p;
789   }
790   private void setClassAnnotationValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
791           String elementName, int arrayIndex, String typeName){
792     int p = pos;
793     reader.setClassAnnotationValue( this, tag, annotationIndex, valueIndex, elementName, arrayIndex, typeName);
794     pos = p;
795   }
796   
797   private void setAnnotationFieldValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex, String elementName, int arrayIndex) {
798     int p = pos;
799     reader.setAnnotationFieldValue( this, tag, annotationIndex, valueIndex, elementName, arrayIndex);
800     pos = p;
801   }
802   
803   private void setEnumAnnotationValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
804           String elementName, int arrayIndex, String enumType, String enumValue){
805     int p = pos;
806     reader.setEnumAnnotationValue( this, tag, annotationIndex, valueIndex, elementName, arrayIndex, enumType, enumValue);
807     pos = p;
808   }
809
810   private void setAnnotationValueElementCount(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
811           String elementName, int elementCount){
812     int p = pos;
813     reader.setAnnotationValueElementCount(this, tag, annotationIndex, valueIndex, elementName, elementCount);
814     pos = p;
815   }
816   private void setAnnotationValueElementsDone(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex,
817           String elementName){
818     int p = pos;
819     reader.setAnnotationValueElementsDone(this, tag, annotationIndex, valueIndex, elementName);
820     pos = p;
821   }
822
823   public void setAnnotationValuesDone(ClassFileReader reader, Object tag, int annotationIndex){
824     int p = pos;
825     reader.setAnnotationValuesDone(this, tag, annotationIndex);
826     pos = p;
827   }
828
829   private void setParameterCount(ClassFileReader reader, Object tag, int parameterCount){
830     int p = pos;
831     reader.setParameterCount(this, tag, parameterCount);
832     pos = p;
833   }
834   private void setParameterAnnotationCount(ClassFileReader reader, Object tag, int paramIndex, int annotationCount){
835     int p = pos;
836     reader.setParameterAnnotationCount(this, tag, paramIndex, annotationCount);
837     pos = p;
838   }
839
840   private boolean setParameterAnnotation(ClassFileReader reader, Object tag, int annotationIndex, String annotationType){
841     int p = pos;
842     try {
843       reader.setParameterAnnotation( this, tag, annotationIndex, annotationType);
844       pos = p;
845       return true;
846     } catch(SkipAnnotation s) {
847       this.skipAnnotation(false);
848       return false;
849     }
850   }
851   private void setParameterAnnotationsDone(ClassFileReader reader, Object tag, int paramIndex){
852     int p = pos;
853     reader.setParameterAnnotationsDone(this, tag, paramIndex);
854     pos = p;
855   }
856   private void setParametersDone(ClassFileReader reader, Object tag){
857     int p = pos;
858     reader.setParametersDone(this, tag);
859     pos = p;
860   }
861
862   public void setSignature(ClassFileReader reader, Object tag, String signature){
863     int p = pos;
864     reader.setSignature(this, tag, signature);
865     pos = p;
866   }
867
868   //--- parsing
869
870   /**
871    * this is the main parsing routine that uses the ClassFileReader interface
872    * to tell clients about the classfile contents
873    *
874    * ClassFile structure: http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#74353
875    *   u4 magic;  // 0xcafebabe
876    *   u2 minor_version;
877    *   u2 major_version;
878    *
879    *   u2 constant_pool_count;
880    *   cp_entry constant_pool[constant_pool_count-1];
881    *   u2 access_flags;
882    *
883    *   u2 this_class;
884    *   u2 super_class;
885    *
886    *   u2 interfaces_count;
887    *   u2 interfaces[interfaces_count];
888    *
889    *   u2 fields_count;
890    *   field_info fields[fields_count];
891    *
892    *   u2 methods_count;
893    *   method_info methods[methods_count];
894    *
895    *   u2 attributes_count;
896    *   attribute_info attributes[attributes_count];
897    */
898   public void parse( ClassFileReader reader)  throws ClassParseException {
899     int cpIdx;
900
901     try {
902       // yeah, cafebabe
903       int magic = readI4();
904       if (magic != 0xCAFEBABE) {
905         error("wrong magic: " + Integer.toHexString(magic));
906       }
907
908       // we don't do much with the version numbers yet
909       int minor = readU2();
910       int major = readU2();
911
912       // get the const pool
913       int cpCount = readU2();
914       cpPos = new int[cpCount];
915       cpValue = new Object[cpCount];
916       parseCp(cpCount);
917
918       // the class essentials
919       int accessFlags = readU2();
920
921       cpIdx = readU2();
922       String clsName = (String) cpValue[cpIdx];
923
924       cpIdx = readU2();
925       String superClsName = (String) cpValue[cpIdx];
926
927
928       setClass(reader, clsName, superClsName, accessFlags, cpCount);
929
930       // interfaces
931       int ifcCount = readU2();
932       parseInterfaces(reader, ifcCount);
933
934       // fields
935       int fieldCount = readU2();
936       parseFields(reader, fieldCount);
937
938       // methods
939       int methodCount = readU2();
940       parseMethods(reader, methodCount);
941
942       // class attributes
943       int classAttrCount = readU2();
944       parseClassAttributes(reader, classAttrCount);
945
946     } catch (BailOut x){
947       // nothing, just a control exception to shortcut the classfile parsing
948     }
949   }
950
951
952   //--- constpool parsing
953
954   public static String readModifiedUTF8String( byte[] data, int pos, int len) throws ClassParseException {
955     
956     int n = 0; // the number of chars in buf
957     char[] buf = new char[len]; // it can't be more, but it can be less chars
958     
959     // \u0001 - \u007f             : single byte chars:  0xxxxxxx
960     // \u0000 and \u0080 - \u07ff  : double byte chars:  110xxxxx, 10xxxxxx
961     // \u0800 - \uffff             : tripple byte chars: 1110xxxx, 10xxxxxx, 10xxxxxx
962     
963     int max = pos+len;
964     for (int i=pos; i<max; i++){
965       int c = data[i] & 0xff;
966       if ((c & 0x80) == 0){ // single byte char  0xxxxxxx
967         buf[n++] = (char)c;
968         
969       } else {
970         if ((c & 0x40) != 0){      // 11xxxxxx
971           
972           // for the sake of efficiency, we don't check for the trailing zero bit in the marker,
973           // we just mask it out
974           if ((c & 0x20) == 0) {   // 110xxxxx - double byte char
975             buf[n++] = (char) (((c & 0x1f) << 6) | (data[++i] & 0x3f));
976             
977           } else {                 // 1110xxxx - tripple byte char
978             buf[n++] = (char) (((c & 0x0f) << 12) | ((data[++i] & 0x3f) << 6) | (data[++i] & 0x3f));
979           }
980           
981         } else {
982           throw new ClassParseException("malformed modified UTF-8 input: ");
983         }
984       }
985     }
986     
987     return new String(buf, 0, n);
988   }
989
990   
991   // the protected methods are called automatically, the public parse..Attr() methods
992   // are called optionally from the corresponding ClassFileReader.set..Attribute() method.
993   // Note that these calls have to provide the ClassFileReader as an argument because
994   // we might actually switch to another reader (e.g. MethodInfos for parseCodeAttr)
995
996   protected void parseCp(int cpCount)  throws ClassParseException {
997     int j = pos;
998
999     byte[] data = this.data;
1000     int[] dataIdx = this.cpPos;
1001     Object[] values = this.cpValue;
1002
1003     //--- first pass: store data index values and convert non-delegating constant values
1004     // cp_entry[0] is traditionally unused
1005     for (int i=1; i<cpCount; i++) {
1006       switch (data[j]){
1007         case 0:
1008           error("illegal constpool tag");
1009
1010         case CONSTANT_UTF8:  // utf8_info { u1 tag; u2 length; u1 bytes[length]; }
1011           dataIdx[i] = j++;
1012           int len = ((data[j++]&0xff) <<8) | (data[j++]&0xff);
1013
1014           String s = readModifiedUTF8String( data, j, len);
1015           values[i] = s;
1016
1017           j += len;
1018           break;
1019
1020         case 2:
1021           error("illegal constpool tag");
1022
1023         case CONSTANT_INTEGER:  // Integer_info { u1 tag; u4 bytes; }
1024           dataIdx[i] = j++;
1025
1026           int iVal = (data[j++]&0xff)<<24 | (data[j++]&0xff)<<16 | (data[j++]&0xff)<<8 | (data[j++]&0xff);
1027           values[i] = new Integer(iVal);
1028           break;
1029
1030         case CONSTANT_FLOAT:  // Float_info  { u1 tag; u4 bytes; }
1031           dataIdx[i] = j++;
1032
1033           int iBits = (data[j++]&0xff)<<24 | (data[j++]&0xff)<<16 | (data[j++]&0xff)<<8 | (data[j++]&0xff);
1034           float fVal = Float.intBitsToFloat(iBits);
1035           values[i] = new Float(fVal);
1036           break;
1037
1038         case CONSTANT_LONG:  // Long_info { u1 tag; u4 high_bytes; u4 low_bytes; }
1039           dataIdx[i] = j++;
1040           long lVal =  (data[j++]&0xffL)<<56 | (data[j++]&0xffL)<<48 | (data[j++]&0xffL)<<40 | (data[j++]&0xffL)<<32
1041                     | (data[j++]&0xffL)<<24 | (data[j++]&0xffL)<<16 | (data[j++]&0xffL)<<8 | (data[j++]&0xffL);
1042           values[i] = new Long(lVal);
1043
1044           dataIdx[++i] = -1;  // 8 byte cpValue occupy 2 index slots
1045           break;
1046
1047         case CONSTANT_DOUBLE:  // Double_info  { u1 tag; u4 high_bytes; u4 low_bytes; }
1048           dataIdx[i] = j++;
1049
1050           long lBits = (data[j++]&0xffL)<<56 | (data[j++]&0xffL)<<48 | (data[j++]&0xffL)<<40 | (data[j++]&0xffL)<<32
1051                     | (data[j++]&0xffL)<<24 | (data[j++]&0xffL)<<16 | (data[j++]&0xffL)<<8 | (data[j++]&0xffL);
1052           double dVal = Double.longBitsToDouble(lBits);
1053           values[i] = new Double(dVal);
1054
1055           dataIdx[++i] = -1;  // 8 byte cpValue occupy 2 index slots
1056           break;
1057
1058         case CONSTANT_CLASS:  // Class_info { u1 tag; u2 name_index<utf8>; }
1059           dataIdx[i] = j;
1060           values[i] = CpInfo.ConstantClass;
1061
1062           j += 3;
1063           break;
1064
1065         case CONSTANT_STRING:  // String_info { u1 tag; u2 string_index<utf8>; }
1066           dataIdx[i] = j;
1067           values[i] = CpInfo.ConstantString;
1068
1069           j += 3;
1070           break;
1071
1072         case FIELD_REF:  // Fieldref_info { u1 tag; u2 class_index; u2 name_and_type_index; }
1073           dataIdx[i] = j;
1074           values[i] = CpInfo.FieldRef;
1075           j += 5;
1076           break;
1077
1078         case METHOD_REF: // Methodref_info  { u1 tag; u2 class_index; u2 name_and_type_index; }
1079           dataIdx[i] = j;
1080           values[i] = CpInfo.MethodRef;
1081           j += 5;
1082           break;
1083
1084         case INTERFACE_METHOD_REF: // InterfaceMethodref_info { u1 tag; u2 class_index; u2 name_and_type_index; }
1085           dataIdx[i] = j;
1086           values[i] = CpInfo.InterfaceMethodRef;
1087           j += 5;
1088           break;
1089
1090         case NAME_AND_TYPE: // NameAndType_info { u1 tag; u2 name_index<utf8>; u2 descriptor_index<utf8>; }
1091           dataIdx[i] = j;
1092           values[i] = CpInfo.NameAndType;
1093
1094           j += 5;
1095           break;
1096
1097         //--- the Java 8 ones
1098           
1099         case METHOD_HANDLE: // MethodHandle_info { u1 tag; u1 reference_kind; u2 reference_index<mthref>; }
1100           dataIdx[i] = j;
1101           values[i] = CpInfo.MethodHandle;
1102           j += 4;
1103           break;
1104           
1105         case METHOD_TYPE:  // MethodType_info { u1 tag;  u2 descriptor_index<utf8>; }
1106           dataIdx[i] = j;
1107           values[i] = CpInfo.MethodType;
1108           j += 3;
1109           break;
1110
1111         case INVOKE_DYNAMIC: //  InvokeDynamic_info { u1 tag; u2 bootstrap_method_attr_index; u2 name_and_type_index; }
1112           dataIdx[i] = j;
1113           values[i] = CpInfo.InvokeDynamic;
1114           j += 5;
1115           break;
1116           
1117         default:
1118           error("illegal constpool tag: " + data[j]);
1119       }
1120     }
1121
1122     pos = j;
1123
1124     //--- second pass: store values of delegating constant values
1125     for (int i=1; i<cpCount; i++){
1126       Object v = cpValue[i];
1127
1128       // we store string and class constants as their utf8 string values
1129       if (v == CpInfo.ConstantClass || v == CpInfo.ConstantString){
1130          cpValue[i] = cpValue[u2(cpPos[i]+1)];
1131       }
1132     }
1133   }
1134
1135   protected void parseInterfaces(ClassFileReader reader, int ifcCount){
1136
1137     setInterfaceCount(reader, ifcCount);
1138
1139     for (int i=0; i<ifcCount; i++){
1140       int cpIdx = readU2();
1141       setInterface(reader, i, classNameAt(cpIdx));
1142     }
1143
1144     setInterfacesDone(reader);
1145   }
1146
1147   //--- fields
1148   protected void parseFields(ClassFileReader reader, int fieldCount) {
1149
1150     setFieldCount(reader, fieldCount);
1151
1152     for (int i=0; i<fieldCount; i++){
1153       int accessFlags = readU2();
1154
1155       int cpIdx = readU2();
1156       String name = utf8At(cpIdx);
1157
1158       cpIdx = readU2();
1159       String descriptor = utf8At(cpIdx);
1160
1161       setField(reader, i, accessFlags, name, descriptor);
1162
1163       int attrCount = readU2();
1164       parseFieldAttributes(reader, i, attrCount);
1165
1166       setFieldDone(reader, i);
1167     }
1168
1169     setFieldsDone(reader);
1170   }
1171
1172   protected void parseFieldAttributes(ClassFileReader reader, int fieldIdx, int attrCount){
1173     setFieldAttributeCount(reader, fieldIdx, attrCount);
1174
1175     for (int i=0; i<attrCount; i++){
1176       int cpIdx = readU2();
1177       String name = utf8At(cpIdx);
1178
1179       name = internStdAttrName(cpIdx, name, stdFieldAttrs);
1180
1181       int attrLength = readI4(); // actually U4, but we don't support 2GB attributes
1182       setFieldAttribute(reader, fieldIdx, i, name, attrLength);
1183     }
1184
1185     setFieldAttributesDone(reader, fieldIdx);
1186   }
1187
1188   /**
1189    * optionally called by reader to obtain a ConstantValue field attribute
1190    * 
1191    *   ConstantValue {u2 attrName<utf8>; u4 attrLength; u2 constIndex<class|string|int|float|long|double> }
1192    * 
1193    * pos is at constIndex
1194    */
1195   public void parseConstValueAttr(ClassFileReader reader, Object tag){
1196     int cpIdx = readU2();
1197     setConstantValue(reader, tag, cpValue[cpIdx]);
1198   }
1199
1200
1201   //--- methods
1202   protected void parseMethods(ClassFileReader reader, int methodCount) {
1203
1204     setMethodCount(reader, methodCount);
1205
1206     for (int i=0; i<methodCount; i++){
1207       int accessFlags = readU2();
1208
1209       int cpIdx = readU2();
1210       String name = utf8At(cpIdx);
1211
1212       cpIdx = readU2();
1213       String descriptor = utf8At(cpIdx);
1214
1215       setMethod(reader, i, accessFlags, name, descriptor);
1216
1217       int attrCount = readU2();
1218       parseMethodAttributes(reader, i, attrCount);
1219
1220       setMethodDone(reader, i);
1221     }
1222
1223     setMethodsDone(reader);
1224   }
1225
1226   protected void parseMethodAttributes(ClassFileReader reader, int methodIdx, int attrCount){
1227     setMethodAttributeCount(reader, methodIdx, attrCount);
1228
1229     for (int i=0; i<attrCount; i++){
1230       int cpIdx = readU2();
1231       String name = utf8At(cpIdx);
1232
1233       name = internStdAttrName(cpIdx, name, stdMethodAttrs);
1234
1235       int attrLength = readI4(); // actually U4, but we don't support 2GB attributes
1236       setMethodAttribute(reader, methodIdx, i, name, attrLength);
1237     }
1238
1239     setMethodAttributesDone(reader, methodIdx);
1240   }
1241
1242   public void parseExceptionAttr (ClassFileReader reader, Object tag){
1243     int exceptionCount = readU2();
1244     setExceptionCount(reader, tag, exceptionCount);
1245
1246     for (int i=0; i<exceptionCount; i++){
1247       int cpIdx = readU2();
1248       String exceptionType = classNameAt(cpIdx);
1249       setException(reader, tag, i, exceptionType);
1250     }
1251
1252     setExceptionsDone(reader, tag);
1253   }
1254
1255   /**
1256    * (optionally) called by reader from within the setMethodAttribute() notification
1257    * This means we have recursive notification since this is a variable length
1258    * attribute that has variable length attributes
1259    *
1260    * Code_attribute { u2 attr_name_index<utf8>; u4 attr_length;
1261    *                  u2 max_stack; u2 max_locals;
1262    *                  u4 code_length; u1 code[code_length];
1263    *                  u2 exception_table_length;
1264    *                  { u2 start_pc; u2 end_pc; u2  handler_pc; u2  catch_type<class_entry>;
1265    *                  } exception_table[exception_table_length];
1266    *                  u2 attributes_count;
1267    *                  attribute_info attributes[attributes_count];  }
1268    *
1269    * pos is at max_stack
1270    */
1271   public void parseCodeAttr (ClassFileReader reader, Object tag){
1272     int maxStack = readU2();
1273     int maxLocals = readU2();
1274     int codeLength = readI4();  // no code length > 2GB supported
1275     int codeStartPos = pos;
1276
1277     setCode(reader, tag, maxStack, maxLocals, codeLength);
1278
1279     int exceptionCount = readU2();
1280     setExceptionTableCount(reader, tag, exceptionCount);
1281
1282     for (int i = 0; i < exceptionCount; i++) {
1283       int startPc = readU2();
1284       int endPc = readU2();
1285       int handlerPc = readU2();
1286
1287       int cpIdx = readU2();
1288       String catchType = (String) cpValue[cpIdx]; // a Constant_class
1289
1290       setExceptionTableEntry(reader, tag, i, startPc, endPc, handlerPc, catchType);
1291     }
1292     setExceptionTableDone(reader, tag);
1293
1294     int attrCount = readU2();
1295     parseCodeAttrAttributes(reader, tag, attrCount);
1296   }
1297
1298
1299   protected void parseCodeAttrAttributes(ClassFileReader reader, Object tag, int attrCount){
1300
1301     setCodeAttributeCount(reader, tag, attrCount);
1302
1303     for (int i=0; i<attrCount; i++){
1304       int cpIdx = readU2();
1305       String name = utf8At(cpIdx);
1306
1307       name = internStdAttrName(cpIdx, name, stdCodeAttrs);
1308
1309       int attrLength = readI4(); // actually U4, but we don't support 2GB attributes
1310       setCodeAttribute(reader, tag, i, name, attrLength);
1311     }
1312
1313     setCodeAttributesDone(reader, tag);
1314   }
1315
1316   /**
1317    * optionally called from ClassFileReader.setCodeAttribute() to parse LineNumberTables
1318    *   LineNumberTable { u2 attrName; u4 attrLength;
1319    *                     u2 lineCount;
1320    *                     { u2 startPc; u2 lineNumber; } [lineCount] };
1321    * pos is at lineCount
1322    */
1323   public void parseLineNumberTableAttr(ClassFileReader reader, Object tag){
1324     int lineCount = readU2();
1325     setLineNumberTableCount(reader, tag, lineCount);
1326     
1327     for (int i=0; i<lineCount; i++){
1328       int startPc = readU2();
1329       int lineNumber = readU2();
1330       setLineNumber(reader, tag, i, lineNumber, startPc);
1331     }
1332
1333     setLineNumberTableDone(reader, tag);
1334   }
1335
1336   
1337   /**
1338    * optionally called from ClassFileReader.setCodeAttribute() to parse LocalVarTables
1339    *   LocalVarTableTable { u2 attrName; u4 attrLength;
1340    *                        u2 localVarCount;
1341    *                        { u2 startPc; u2 lineNumber; } [lineCount] };
1342    * pos is at localVarCount
1343    */
1344   public void parseLocalVarTableAttr(ClassFileReader reader, Object tag){
1345     int localVarCount = readU2();
1346     setLocalVarTableCount(reader, tag, localVarCount);
1347     
1348     for (int i=0; i<localVarCount; i++){
1349       int startPc = readU2();
1350       int length = readU2();
1351       int cpIdx = readU2();
1352       String varName = (String) cpValue[cpIdx];
1353       cpIdx = readU2();
1354       String descriptor = (String)  cpValue[cpIdx];
1355       int slotIndex = readU2();
1356       
1357       setLocalVar(reader, tag, i, varName, descriptor, startPc, startPc+length-1, slotIndex );
1358     }
1359
1360     setLocalVarTableDone(reader, tag);
1361   }
1362
1363   //--- class
1364   protected void parseClassAttributes(ClassFileReader reader, int attrCount){
1365
1366     setClassAttributeCount(reader, attrCount);
1367
1368     for (int i=0; i<attrCount; i++){
1369       int cpIdx = readU2();
1370       String name = utf8At(cpIdx);
1371
1372       name = internStdAttrName(cpIdx, name, stdClassAttrs);
1373
1374       int attrLength = readI4(); // actually U4, but we don't support 2GB attributes
1375       setClassAttribute(reader, i, name, attrLength);
1376     }
1377
1378     setClassAttributesDone(reader);
1379   }
1380
1381
1382   /**
1383    * (optionally) called by ClassFileReader from within setClassAttribute() notification
1384    *
1385    * InnerClass { u2 nameIdx<utf8>; u4 length; u2 sourceFile<utf8>; }
1386    */
1387   public void parseSourceFileAttr(ClassFileReader reader, Object tag){
1388     int cpIdx = readU2();
1389     String pathName = utf8At(cpIdx);
1390     setSourceFile(reader, tag, pathName);
1391   }
1392
1393   /**
1394    * (optionally) called by ClassFileReader from within setClassAttribute() notification
1395    *
1396    * InnerClass { 
1397    *    u2 nameIdx<utf8>; 
1398    *    u4 length;
1399    *    u2 classCount;
1400    *    { u2 innerCls<cls>;
1401    *      u2 outerCls<cls>;
1402    *      u2 innerName<utf8>; 
1403    *      u2 innerAccessFlags;
1404    *    } classes[classCount] }
1405    * }
1406    * 
1407    * pos is at classCount
1408    */
1409   public void parseInnerClassesAttr(ClassFileReader reader, Object tag){
1410     int innerClsCount = readU2();    
1411     setInnerClassCount(reader, tag, innerClsCount);
1412
1413     for (int i = 0; i < innerClsCount; i++) {
1414       int cpIdx = readU2();
1415       String innerClsName = (cpIdx != 0) ? (String) cpValue[cpIdx] : null;
1416       cpIdx = readU2();
1417       String outerClsName = (cpIdx != 0) ? (String) cpValue[cpIdx] : null;
1418       cpIdx = readU2();
1419       String innerSimpleName = (cpIdx != 0) ? (String) cpValue[cpIdx] : null;
1420       int accessFlags = readU2();
1421
1422       setInnerClass(reader, tag, i, outerClsName, innerClsName, innerSimpleName, accessFlags);
1423     }
1424
1425     setInnerClassesDone(reader, tag);
1426   }
1427   
1428   /**
1429    * EnclosingMethod_attribute {
1430    *   u2 attribute_name_index;
1431    *   u4 attribute_length;
1432    *   u2 class_index     -> Class_info { u1 tag; u2 name_index->utf8 }
1433    *   u2 method_index    -> NameAndType_info { u1 tag; u2 name_index->utf8; u2 descriptor_index->utf8 }
1434    * }
1435    */
1436   public void parseEnclosingMethodAttr(ClassFileReader reader, Object tag){
1437     String enclosedMethod = null;
1438     String descriptor = null;
1439     
1440     int cpIdx = readU2(); // start of Class_info
1441     String enclosingClass =  nameAt(cpIdx);
1442     
1443     cpIdx = readU2(); // start of NameAndType_info
1444     
1445     // check if this is inside a method - we also get EnclosingMethod_infos for
1446     // classes that are not immediately enclosed
1447     if (cpIdx != 0){
1448       enclosedMethod = nameAt(cpIdx);    
1449       descriptor = descriptorAt(cpIdx);
1450     }
1451     
1452     setEnclosingMethod(reader, tag, enclosingClass, enclosedMethod, descriptor);
1453   }
1454   
1455   /**
1456    * BootstrapMethods_attribute {
1457    *     u2 attribute_name_index;
1458    *     u4 attribute_length;
1459    *     u2 num_bootstrap_methods;
1460    *     {   u2 bootstrap_method_ref; -> MethodHandle
1461    *         u2 num_bootstrap_arguments;
1462    *         u2 bootstrap_arguments[num_bootstrap_arguments];
1463    *     } bootstrap_methods[num_bootstrap_methods];
1464    * }
1465    * 
1466    * pos is at num_bootstrap_methods
1467   */
1468   public void parseBootstrapMethodAttr (ClassFileReader reader, Object tag){
1469     int nBootstrapMethods = readU2();
1470     
1471     setBootstrapMethodCount(reader, tag, nBootstrapMethods);
1472     
1473     for (int i=0; i<nBootstrapMethods; i++){
1474       int cpMhIdx = readU2();
1475       int nArgs = readU2();
1476       int[] bmArgs = new int[nArgs];
1477       for (int j=0; j<nArgs; j++){
1478         bmArgs[j] = readU2();
1479       }
1480       
1481       // kind of this method handle
1482       int refKind = mhRefTypeAt(cpMhIdx);
1483       
1484       // CONSTANT_Methodref_info structure
1485       int mrefIdx = mhMethodRefIndexAt(cpMhIdx);
1486       
1487       String clsName = methodClassNameAt(mrefIdx);
1488       String mthName = methodNameAt(mrefIdx);
1489       String descriptor = methodDescriptorAt(mrefIdx);
1490       
1491       setBootstrapMethod(reader, tag, i, refKind, clsName, mthName, descriptor, bmArgs);
1492     }
1493     
1494     setBootstrapMethodsDone( reader, tag);
1495   }
1496   
1497   String nameAt(int nameTypeInfoIdx) {
1498     return utf8At(u2(cpPos[nameTypeInfoIdx] + 1));
1499   }
1500   
1501   String descriptorAt (int nameTypeInfoIdx){
1502     return utf8At( u2( cpPos[nameTypeInfoIdx]+3));
1503   }
1504
1505 // those are as per http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf
1506
1507   /*
1508    *   element_value {
1509    *     u1 tag;
1510    *     union {
1511    *       u2 const_value_index;
1512    *       { u2 type_name_index; u2 const_name_index; } enum_const_value;
1513    *       u2 class_info_index;
1514    *       annotation annotation_value;
1515    *       { u2 num_values; element_value values[num_values]; } array_value;
1516    *     } value;
1517    *   }
1518    *   valid tags are primitve type codes B,C,D,F,I,J,S,Z
1519    *   plus:   's'=String, 'e'=enum, 'c'=class, '@'=annotation, '['=array
1520    */
1521   void parseAnnotationValue(ClassFileReader reader, Object tag, int annotationIndex, int valueIndex, String elementName, int arrayIndex){
1522     int cpIdx;
1523     Object val;
1524
1525     int t = readUByte();
1526     switch (t){
1527       case 'Z':
1528         // booleans have to be treated differently since there is no CONSTANT_Boolean, i.e. values are
1529         // stored as CONSTANT_Integer in the constpool, i.e. the cpValue doesn't have the right type
1530         cpIdx = readU2();
1531         val = cpValue[cpIdx];
1532         val = Boolean.valueOf((Integer)val == 1);
1533         setPrimitiveAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
1534         break;        
1535
1536       case 'B':
1537         cpIdx = readU2();
1538         val = cpValue[cpIdx];
1539         val = Byte.valueOf(((Integer)val).byteValue());
1540         setPrimitiveAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
1541         break;
1542         
1543       case 'C':
1544         cpIdx = readU2();
1545         val = cpValue[cpIdx];
1546         val = Character.valueOf((char)((Integer)val).shortValue());
1547         setPrimitiveAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
1548         break;
1549         
1550       case 'S':
1551         cpIdx = readU2();
1552         val = cpValue[cpIdx];
1553         val = Short.valueOf(((Integer)val).shortValue());
1554         setPrimitiveAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
1555         break;
1556
1557       case 'I':
1558       case 'F':
1559       case 'D':
1560       case 'J':
1561         cpIdx = readU2();
1562         val = cpValue[cpIdx];
1563         setPrimitiveAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, val);
1564         break;
1565
1566       case 's':
1567         cpIdx = readU2();
1568         String s = (String) cpValue[cpIdx];
1569         setStringAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, s);
1570         break;
1571
1572       case 'e':
1573         cpIdx = readU2();
1574         String enumTypeName = (String)cpValue[cpIdx];
1575         cpIdx = readU2();
1576         String enumConstName = (String)cpValue[cpIdx];
1577         setEnumAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, enumTypeName, enumConstName);
1578         break;
1579
1580       case 'c':
1581         cpIdx = readU2();
1582         String className = (String)cpValue[cpIdx];
1583         setClassAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex, className);
1584         break;
1585
1586       case '@':
1587         parseAnnotation(reader, tag, -1, false);  // getting recursive here
1588         setAnnotationFieldValue(reader, tag, annotationIndex, valueIndex, elementName, arrayIndex);
1589         break;
1590
1591       case '[':
1592         int arrayLen = readU2();
1593         setAnnotationValueElementCount(reader, tag, annotationIndex, valueIndex, elementName, arrayLen);
1594         for (int i=0; i<arrayLen; i++){
1595           parseAnnotationValue(reader, tag, annotationIndex, valueIndex, elementName, i);
1596         }
1597         setAnnotationValueElementsDone(reader, tag, annotationIndex, valueIndex, elementName);
1598         break;
1599     }
1600   }
1601
1602   /*
1603    *   annotation {
1604    *     u2 type_index;
1605    *     u2 num_element_value_pairs;
1606    *     {
1607    *       u2 element_name_index;
1608    *       element_value value;
1609    *     } element_value_pairs[num_element_value_pairs]
1610    *   }
1611    */
1612   void parseAnnotation (ClassFileReader reader, Object tag, int annotationIndex, boolean isParameterAnnotation){
1613     int cpIdx = readU2();
1614     String annotationType = (String)cpValue[cpIdx];
1615     boolean parseValues;
1616     if (isParameterAnnotation){
1617       parseValues = setParameterAnnotation(reader, tag, annotationIndex, annotationType);
1618     } else {
1619       parseValues = setAnnotation(reader, tag, annotationIndex, annotationType);
1620     }
1621     if(parseValues) {
1622       parseAnnotationValues(reader, tag, annotationIndex);
1623     }
1624   }
1625
1626   void parseAnnotationValues (ClassFileReader reader, Object tag, int annotationIndex){
1627     int nValuePairs = readU2();
1628     setAnnotationValueCount(reader, tag, annotationIndex, nValuePairs);
1629
1630     for (int i=0; i<nValuePairs; i++){
1631       int cpIdx = readU2();
1632       String elementName = (String)cpValue[cpIdx];
1633       parseAnnotationValue(reader, tag, annotationIndex, i, elementName, -1);
1634     }
1635
1636     setAnnotationValuesDone(reader, tag, annotationIndex);
1637   }
1638   
1639   /*
1640    * class, field, method annotation attributes (only one per target)
1641    *
1642    *  Runtime[In]VisibleAnnotations_attribute {
1643    *     u2 attribute_name_index;
1644    *     u4 attribute_length;
1645    *     u2 num_annotations;        << pos
1646    *     annotation annotations[num_annotations];
1647    *   }
1648    */
1649   public void parseAnnotationsAttr (ClassFileReader reader, Object tag){
1650     int numAnnotations = readU2();
1651     setAnnotationCount(reader, tag, numAnnotations);
1652
1653     for (int i=0; i<numAnnotations; i++){
1654       parseAnnotation(reader, tag, i, false);
1655     }
1656
1657     setAnnotationsDone(reader, tag);
1658   }
1659
1660   
1661   // JSR 308 type annotation target types
1662   public static final int CLASS_TYPE_PARAMETER                 = 0x00;
1663   public static final int METHOD_TYPE_PARAMETER                = 0x01;
1664   public static final int CLASS_EXTENDS                        = 0x10;
1665   public static final int CLASS_TYPE_PARAMETER_BOUND           = 0x11;
1666   public static final int METHOD_TYPE_PARAMETER_BOUND          = 0x12;
1667   public static final int FIELD                                = 0x13;
1668   public static final int METHOD_RETURN                        = 0x14;
1669   public static final int METHOD_RECEIVER                      = 0x15;
1670   public static final int METHOD_FORMAL_PARAMETER              = 0x16;
1671   public static final int THROWS                               = 0x17;
1672   public static final int LOCAL_VARIABLE                       = 0x40;
1673   public static final int RESOURCE_VARIABLE                    = 0x41;
1674   public static final int EXCEPTION_PARAMETER                  = 0x42;
1675   public static final int INSTANCEOF                           = 0x43;
1676   public static final int NEW                                  = 0x44;
1677   public static final int CONSTRUCTOR_REFERENCE                = 0x45;
1678   public static final int METHOD_REFERENCE                     = 0x46;
1679   public static final int CAST                                 = 0x47;
1680   public static final int CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT = 0x48;
1681   public static final int METHOD_INVOCATION_TYPE_ARGUMENT      = 0x49;
1682   public static final int CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT  = 0x4a;
1683   public static final int METHOD_REFERENCE_TYPE_ARGUMENT       = 0x4b;  
1684   
1685   public static String getTargetTypeName (int targetType){
1686     switch (targetType){
1687       case CLASS_TYPE_PARAMETER: return "class type parameter";
1688       case METHOD_TYPE_PARAMETER: return "method type parameter";
1689       case CLASS_EXTENDS: return "super class";
1690       case CLASS_TYPE_PARAMETER_BOUND: return "class type parameter bound";
1691       case METHOD_TYPE_PARAMETER_BOUND: return "method type parameter bound";
1692       case FIELD: return "field";
1693       case METHOD_RETURN: return "method return";
1694       case METHOD_RECEIVER: return "method receiver";
1695       case METHOD_FORMAL_PARAMETER: return "method formal parameter";
1696       case THROWS: return "throws";
1697       case LOCAL_VARIABLE: return "local variable";
1698       case RESOURCE_VARIABLE: return "resource variable";
1699       case EXCEPTION_PARAMETER: return "exception parameter";
1700       case INSTANCEOF: return "instanceof";
1701       case NEW: return "new";
1702       case CONSTRUCTOR_REFERENCE: return "ctor reference";
1703       case METHOD_REFERENCE: return "method reference";
1704       case CAST: return "case";
1705       case METHOD_INVOCATION_TYPE_ARGUMENT: return "method invocation type argument";
1706       case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: return "ctor reference type argument";
1707       case METHOD_REFERENCE_TYPE_ARGUMENT: return "method reference type argument";
1708       default:
1709         return "<unknown target type 0x" + Integer.toHexString(targetType);
1710     }
1711   }
1712   
1713   public static String getTypePathEncoding (short[] typePath){
1714     if (typePath == null){
1715       return "()";
1716     }
1717     
1718     StringBuffer sb = new StringBuffer();
1719     for (int i=0; i<typePath.length;i++){
1720       int e = typePath[i];
1721       sb.append('(');
1722       sb.append( Integer.toString((e>>8) & 0xff));
1723       sb.append( Integer.toString(e & 0xff));
1724       sb.append(')');
1725     }
1726     
1727     return sb.toString();
1728   }
1729   
1730   public static String getScopeEncoding (long[] scopeEntries){
1731     StringBuffer sb = new StringBuffer();
1732     for (int i=0; i<scopeEntries.length;i++){
1733       long e = scopeEntries[i];
1734       int slotIndex = (int)(e & 0xffff);
1735       int length = (int)((e >> 16) & 0xffff);
1736       int startPc = (int)((e >> 32) & 0xffff);
1737       
1738       if (i>0){
1739         sb.append(',');
1740       }
1741       
1742       sb.append('[');
1743       sb.append( Integer.toString(startPc));
1744       sb.append("..");
1745       sb.append( Integer.toString(startPc + length-1));
1746       sb.append("]#");
1747       sb.append(slotIndex);
1748     }
1749     
1750     return sb.toString();
1751   }
1752   
1753   // JSR 308 type annotation, which adds 3 fields to the old annotation structure
1754   //
1755   //  type_annotation {
1756   //      u1 target_type;        // targeted program element (sec 3.2)
1757   //      union {                // ?? this is probably packed - variable size unions make no sense
1758   //          type_parameter_target;
1759   //          supertype_target;
1760   //          type_parameter_bound_target;
1761   //          empty_target;
1762   //          method_formal_parameter_target;
1763   //          throws_target;
1764   //          localvar_target;
1765   //          catch_target;
1766   //          offset_target;
1767   //          type_argument_target;
1768   //      } target_info;         // targeted program element (sec 3.3)
1769   //
1770   //      type_path target_path; // encoding of annotation position in compound type (array, generic, etc., sec 3.4)
1771   //
1772   //                             // standard annotation fields
1773   //      u2 type_index;         // the annotation type
1774   //      u2 num_element_value_pairs;
1775   //      {
1776   //          u2 element_name_index;
1777   //          element_value value;
1778   //      } element_value_pairs[num_element_value_pairs];
1779   //  }
1780   //
1781   //  struct type_path {
1782   //    u1              path_length;
1783   //    type_path_entry path[path_length];
1784   //  }
1785   //
1786   //  struct type_path_entry {
1787   //    u1 type_path_kind;
1788   //        // 0: deeper in array type
1789   //        // 1: deeper in nested type
1790   //        // 2: bound of wildcard typearg
1791   //        // 3: type argument of parameterized type
1792   //    u1 type_argument_index;
1793   //        // 0, if type_path_kind == 0,1,2
1794   //        // 0-based index of type arg in parameterized type if type_path_kind i== 3
1795   //  }
1796   
1797   int getTargetInfoSize (int targetType){
1798     int len = 3; // max static length are xx_TYPE_ARGUMENTs
1799     if (targetType == LOCAL_VARIABLE || targetType == RESOURCE_VARIABLE){
1800       len = Math.max( len, u2(pos) * 6); // three u2 values per entry
1801     }
1802     
1803     return len;
1804   }
1805
1806   int getTypePathSize (short[] typePath){
1807     int typePathSize = 1;
1808     if (typePath != null) {
1809       typePathSize += typePath.length * 2;
1810     }
1811     return typePathSize;
1812   }
1813   
1814   
1815   short[] readTypePath (){
1816     short[] typePath = null;
1817     
1818     int pathLength = readUByte();
1819     if (pathLength > 0){
1820       typePath = new short[pathLength];
1821       for (int i=0; i<pathLength; i++){
1822         int pathKind = (short)readUByte();
1823         int argIdx = (short)readUByte();
1824         typePath[i]= (short)((pathKind << 8) | argIdx);
1825       }
1826     }
1827     
1828     return typePath;
1829   }
1830
1831   String readAnnotationType (){
1832     int cpIdx = readU2();
1833     String annotationType = (String)cpValue[cpIdx];
1834     return annotationType;
1835   }
1836
1837   void setTypeAnnotation (ClassFileReader reader, Object tag, int annotationIndex) {
1838     int targetType = readUByte();
1839     
1840     switch (targetType){
1841       case CLASS_TYPE_PARAMETER:
1842       case METHOD_TYPE_PARAMETER: {
1843         // type_parameter_target { u1 type_parameter_index; }
1844         int typeParamIdx = readUByte();
1845         reader.setTypeParameterAnnotation( this, tag, annotationIndex, targetType, typeParamIdx, readTypePath(), readAnnotationType());
1846         break;
1847       } 
1848       case CLASS_EXTENDS: {
1849         // supertype_target { u2 supertype_index; }
1850         int superTypeIdx = readU2();
1851         reader.setSuperTypeAnnotation( this, tag, annotationIndex, targetType, superTypeIdx, readTypePath(), readAnnotationType());
1852         break;
1853       }
1854       case CLASS_TYPE_PARAMETER_BOUND:
1855       case METHOD_TYPE_PARAMETER_BOUND: {
1856         // type_parameter_bound_target { u1 type_parameter_index; u1 bound_index; }
1857         int typeParamIdx = readUByte();
1858         int boundIdx = readUByte();
1859         reader.setTypeParameterBoundAnnotation(this, tag, annotationIndex, targetType, typeParamIdx, boundIdx, readTypePath(), readAnnotationType());
1860         break;
1861       }
1862       case METHOD_RETURN:
1863       case METHOD_RECEIVER:
1864       case FIELD:
1865         // empty_target {}
1866         reader.setTypeAnnotation( this, tag, annotationIndex, targetType, readTypePath(), readAnnotationType());
1867         break;
1868         
1869       case METHOD_FORMAL_PARAMETER: {
1870         // method_formal_parameter_target { u1 method_formal_parameter_index; }
1871         int formalParamIdx = readUByte();
1872         reader.setFormalParameterAnnotation( this, tag, annotationIndex, targetType, formalParamIdx, readTypePath(), readAnnotationType());
1873         break;
1874       }
1875       case THROWS: {
1876         // throws_target { u2 throws_type_index; }
1877         int throwsTypeIdx = readU2();
1878         reader.setThrowsAnnotation( this, tag, annotationIndex, targetType, throwsTypeIdx, readTypePath(), readAnnotationType());        
1879         break;
1880       } 
1881       case LOCAL_VARIABLE:
1882       case RESOURCE_VARIABLE: {
1883         // this can't just refer to a LocalVarInfo since those depend on debug compile options
1884         //
1885         //  localvar_target {
1886         //      u2 table_length;  // number of entries, not bytes
1887         //      {
1888         //          u2 start_pc;
1889         //          u2 length; // bytecode offset length
1890         //          u2 index;  // local var idx
1891         //      } table[table_length];
1892         //  }
1893         int tableLength = readU2();
1894         long[] scopeEntries = new long[tableLength];
1895         for (int i=0; i<tableLength; i++){
1896           int startPc = readU2();
1897           int length = readU2();
1898           int slotIdx = readU2();
1899           scopeEntries[i] = ((long)startPc << 32) | ((long)length << 16) | slotIdx;
1900         }
1901         reader.setVariableAnnotation( this, tag, annotationIndex, targetType, scopeEntries, readTypePath(), readAnnotationType());
1902         break;
1903       }
1904       case EXCEPTION_PARAMETER: {
1905         // catch_target { u2 exception_table_index; }
1906         int exceptionIdx = readU2();
1907         reader.setExceptionParameterAnnotation( this, tag, annotationIndex, targetType, exceptionIdx, readTypePath(), readAnnotationType());        
1908         break;
1909       }
1910       case INSTANCEOF:
1911       case METHOD_REFERENCE:
1912       case CONSTRUCTOR_REFERENCE:
1913       case NEW: {
1914         // offset_target { u2 offset; }   // insn offset within bytecode
1915         int offset = readU2();
1916         reader.setBytecodeAnnotation(this, tag, annotationIndex, targetType, offset, readTypePath(), readAnnotationType());
1917         break;
1918       }
1919       case CAST:
1920       case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
1921       case METHOD_INVOCATION_TYPE_ARGUMENT:
1922       case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
1923       case METHOD_REFERENCE_TYPE_ARGUMENT: {
1924         //  type_argument_target {
1925         //      u2 offset;
1926         //      u1 type_argument_index;
1927         //  }
1928         int offset = readU2();
1929         int typeArgIdx = readUByte();
1930         reader.setBytecodeTypeParameterAnnotation(this, tag, annotationIndex, targetType, offset, typeArgIdx, readTypePath(), readAnnotationType());
1931         break;
1932       }
1933       
1934       default:
1935         // <2do - report this to the reader
1936         throw new RuntimeException("unknown type annotation target: 0x" + Integer.toHexString(targetType));
1937     }
1938   }
1939
1940   
1941   void parseTypeAnnotation (ClassFileReader reader, Object tag, int annotationIndex) {
1942    
1943     // this does the respective setXTypeAnnotation() reader callback
1944     //dumpData(pos, 16);
1945     setTypeAnnotation(reader, tag, annotationIndex);
1946     
1947     // now set the annotation value pairs
1948     parseAnnotationValues( reader, tag, annotationIndex);
1949   }
1950   
1951   /*
1952    * Runtime[In]VisibleTypeAnnotations_attribute {
1953    *    u2 attribute_name_index;
1954    *    u4 attribute_length;
1955    *    u2 num_annotations;
1956    *    type_annotation annotations[num_annotations];
1957    * }
1958    */
1959   public void parseTypeAnnotationsAttr (ClassFileReader reader, Object tag) {
1960     int numAnnotations = readU2();
1961     setTypeAnnotationCount(reader, tag, numAnnotations);
1962
1963     for (int i=0; i<numAnnotations; i++){
1964       parseTypeAnnotation(reader, tag, i);
1965     }
1966
1967     setTypeAnnotationsDone(reader, tag);
1968   }
1969   
1970   /*
1971    *   RuntimeInvisibleParameterAnnotations_attribute {
1972    *     u2 attribute_name_index;
1973    *     u4 attribute_length;
1974    *     u1 num_parameters; << pos
1975    *     {
1976    *       u2 num_annotations;
1977    *       annotation annotations[num_annotations];
1978    *     } parameter_annotations[num_parameters];
1979    *   }
1980    */
1981    public void parseParameterAnnotationsAttr(ClassFileReader reader, Object tag){
1982      int numParameters = readUByte();
1983      setParameterCount(reader, tag, numParameters);
1984      for (int i=0; i<numParameters; i++){
1985        int numAnnotations = readU2();
1986
1987        setParameterAnnotationCount(reader, tag, i, numAnnotations);
1988        for (int j=0; j<numAnnotations; j++){
1989          parseAnnotation(reader, tag, j, true);
1990        }
1991        setParameterAnnotationsDone(reader, tag, i);
1992      }
1993      setParametersDone(reader, tag);
1994    }
1995
1996   /**
1997    *  Signature_attribute {
1998    *    u2 attribute_name_index;
1999    *    u4 attr-length;
2000    *    u2 signature-index << pos
2001    *  }
2002    */
2003    public void parseSignatureAttr(ClassFileReader reader, Object tag){
2004      int cpIdx = readU2();
2005      setSignature(reader, tag, utf8At(cpIdx));
2006    }
2007
2008
2009   /**
2010    *    AnnotationDefault_attribute {
2011    *      u2 attribute_name_index;
2012    *      u4 attribute_length;
2013    *      element_value default_value; << pos
2014    *    }
2015    */
2016    public void parseAnnotationDefaultAttr(ClassFileReader reader, Object tag){
2017      parseAnnotationValue(reader, tag, -1, -1, null, -1);
2018    }
2019
2020
2021 //   EnclosingMethod_attribute {
2022 //     u2 attribute_name_index;
2023 //     u4 attribute_length;
2024 //     u2 class_index
2025 //     u2 method_index;
2026 //   }
2027
2028 //   LocalVariableTypeTable_attribute {  // Code attr
2029 //     u2 attribute_name_index;
2030 //     u4 attribute_length;
2031 //     u2 local_variable_type_table_length;
2032 //     {
2033 //       u2 start_pc;
2034 //       u2 length;
2035 //       u2 name_index;
2036 //       u2 signature_index;
2037 //       u2 index;
2038 //     } local_variable_type_table[local_variable_type_table_length];
2039 //   }
2040
2041
2042
2043
2044   public void parseBytecode(JVMByteCodeReader reader, Object tag, int codeLength){
2045     int localVarIndex;
2046     int cpIdx;
2047     int constVal;
2048     int offset;
2049     int defaultOffset;
2050
2051     boolean isWide = false; // modifier for Xload,Xstore,ret and iinc
2052
2053     int startPos = pos;
2054     int endPos = pos+codeLength;
2055     int nextPos;
2056
2057
2058     while (pos < endPos){
2059       pc = pos - startPos;
2060
2061       int opcode = readUByte();
2062       switch (opcode){
2063         case 0: // nop
2064           reader.nop();
2065           break;
2066         case 1:  // aconst_null
2067           reader.aconst_null();
2068           break;
2069         case 2: // iconst_m1
2070           reader.iconst_m1();
2071           break;
2072         case 3: // iconst_0
2073           reader.iconst_0();
2074           break;
2075         case 4: // iconst_1
2076           reader.iconst_1();
2077           break;
2078         case 5: // iconst_2
2079           reader.iconst_2();
2080           break;
2081         case 6: // iconst_3
2082           reader.iconst_3();
2083           break;
2084         case 7: // iconst_4
2085           reader.iconst_4();
2086           break;
2087         case 8: // iconst_5
2088           reader.iconst_5();
2089           break;
2090         case 9: // lconst_0
2091           reader.lconst_0();
2092           break;
2093         case 10: // lconst_1
2094           reader.lconst_1();
2095           break;
2096         case 11: // fconst_0
2097           reader.fconst_0();
2098           break;
2099         case 12: // fconst_1
2100           reader.fconst_1();
2101           break;
2102         case 13: // fconst_2
2103           reader.fconst_2();
2104           break;
2105         case 14: // dconst_0
2106           reader.dconst_0();
2107           break;
2108         case 15: // dconst_1
2109           reader.dconst_1();
2110           break;
2111         case 16: // bipush
2112           constVal = readByte();
2113           reader.bipush(constVal);
2114           break;
2115         case 17: // sipush
2116           constVal = readI2();
2117           reader.sipush(constVal);
2118           break;
2119         case 18: // ldc
2120           cpIdx = readUByte();
2121           reader.ldc_(cpIdx);
2122           break;
2123         case 19: // ldc_w
2124           cpIdx = readU2();
2125           reader.ldc_w_(cpIdx);
2126           break;
2127         case 20: // ldc2_w
2128           cpIdx = readU2();
2129           reader.ldc2_w(cpIdx);
2130           break;
2131         case 21: // iload
2132           localVarIndex = isWide ? readU2() : readUByte();
2133           reader.iload(localVarIndex);
2134           break;
2135         case 22: // lload
2136           localVarIndex = isWide ? readU2() : readUByte();
2137           reader.lload(localVarIndex);
2138           break;
2139         case 23: // fload
2140           localVarIndex = isWide ? readU2() : readUByte();
2141           reader.fload(localVarIndex);
2142           break;
2143         case 24: // dload
2144           localVarIndex = isWide ? readU2() : readUByte();
2145           reader.dload(localVarIndex);
2146           break;
2147         case 25: // aload
2148           localVarIndex = isWide ? readU2() : readUByte();
2149           reader.aload(localVarIndex);
2150           break;
2151         case 26: // iload_0
2152           reader.iload_0();
2153           break;
2154         case 27: // iload_1
2155           reader.iload_1();
2156           break;
2157         case 28: // iload_2
2158           reader.iload_2();
2159           break;
2160         case 29: // iload_3
2161           reader.iload_3();
2162           break;
2163         case 30: // lload_0
2164           reader.lload_0();
2165           break;
2166         case 31: // lload_1
2167           reader.lload_1();
2168           break;
2169         case 32: // lload_2
2170           reader.lload_2();
2171           break;
2172         case 33: // lload_3
2173           reader.lload_3();
2174           break;
2175         case 34: // fload_0
2176           reader.fload_0();
2177           break;
2178         case 35: // fload_1
2179           reader.fload_1();
2180           break;
2181         case 36: // fload_2
2182           reader.fload_2();
2183           break;
2184         case 37: // fload_3
2185           reader.fload_3();
2186           break;
2187         case 38: // dload_0
2188           reader.dload_0();
2189           break;
2190         case 39: // dload_1
2191           reader.dload_1();
2192           break;
2193         case 40: // dload_2
2194           reader.dload_2();
2195           break;
2196         case 41: // dload_3
2197           reader.dload_3();
2198           break;
2199         case 42: // aload_0
2200           reader.aload_0();
2201           break;
2202         case 43: // aload_1
2203           reader.aload_1();
2204           break;
2205         case 44: // aload_2
2206           reader.aload_2();
2207           break;
2208         case 45: // aload_3
2209           reader.aload_3();
2210           break;
2211         case 46: // iaload
2212           reader.iaload();
2213           break;
2214         case 47: // laload
2215           reader.laload();
2216           break;
2217         case 48: // faload
2218           reader.faload();
2219           break;
2220         case 49: // daload
2221           reader.daload();
2222           break;
2223         case 50: // aaload
2224           reader.aaload();
2225           break;
2226         case 51: // baload
2227           reader.baload();
2228           break;
2229         case 52: // caload
2230           reader.caload();
2231           break;
2232         case 53: // saload
2233           reader.saload();
2234           break;
2235         case 54: // istore
2236           localVarIndex = isWide ? readU2() : readUByte();
2237           reader.istore(localVarIndex);
2238           break;
2239         case 55: // lstore
2240           localVarIndex = isWide ? readU2() : readUByte();
2241           reader.lstore(localVarIndex);
2242           break;
2243         case 56: // fstore
2244           localVarIndex = isWide ? readU2() : readUByte();
2245           reader.fstore(localVarIndex);
2246           break;
2247         case 57: // dstore
2248           localVarIndex = isWide ? readU2() : readUByte();
2249           reader.dstore(localVarIndex);
2250           break;
2251         case 58: // astore
2252           localVarIndex = isWide ? readU2() : readUByte();
2253           reader.astore(localVarIndex);
2254           break;
2255         case 59: // istore_0
2256           reader.istore_0();
2257           break;
2258         case 60: // istore_1
2259           reader.istore_1();
2260           break;
2261         case 61: // istore_2
2262           reader.istore_2();
2263           break;
2264         case 62: // istore_3
2265           reader.istore_3();
2266           break;
2267         case 63: // lstore_0
2268           reader.lstore_0();
2269           break;
2270         case 64: // lstore_1
2271           reader.lstore_1();
2272           break;
2273         case 65: // lstore_2
2274           reader.lstore_2();
2275           break;
2276         case 66: // lstore_3
2277           reader.lstore_3();
2278           break;
2279         case 67: // fstore_0
2280           reader.fstore_0();
2281           break;
2282         case 68: // fstore_1
2283           reader.fstore_1();
2284           break;
2285         case 69: // fstore_2
2286           reader.fstore_2();
2287           break;
2288         case 70: // fstore_3
2289           reader.fstore_3();
2290           break;
2291         case 71: //dstore_0
2292           reader.dstore_0();
2293           break;
2294         case 72: //dstore_1
2295           reader.dstore_1();
2296           break;
2297         case 73: //dstore_2
2298           reader.dstore_2();
2299           break;
2300         case 74: //dstore_3
2301           reader.dstore_3();
2302           break;
2303         case 75: // astore_0
2304           reader.astore_0();
2305           break;
2306         case 76: // astore_1
2307           reader.astore_1();
2308           break;
2309         case 77: // astore_2
2310           reader.astore_2();
2311           break;
2312         case 78: // astore_3
2313           reader.astore_3();
2314           break;
2315         case 79: // iastore
2316           reader.iastore();
2317           break;
2318         case 80: // lastore
2319           reader.lastore();
2320           break;
2321         case 81: // fastore
2322           reader.fastore();
2323           break;
2324         case 82: // dastore
2325           reader.dastore();
2326           break;
2327         case 83: // aastore
2328           reader.aastore();
2329           break;
2330         case 84: // bastore
2331           reader.bastore();
2332           break;
2333         case 85: // castore
2334           reader.castore();
2335           break;
2336         case 86: // sastore
2337           reader.sastore();
2338           break;
2339         case 87: // pop
2340           reader.pop();
2341           break;
2342         case 88: // pop2
2343           reader.pop2();
2344           break;
2345         case 89: // dup
2346           reader.dup();
2347           break;
2348         case 90: // dup_x1
2349           reader.dup_x1();
2350           break;
2351         case 91: // dup_x2
2352           reader.dup_x2();
2353           break;
2354         case 92: // dup2
2355           reader.dup2();
2356           break;
2357         case 93: // dup2_x1
2358           reader.dup2_x1();
2359           break;
2360         case 94: // dup2_x2
2361           reader.dup2_x2();
2362           break;
2363         case 95: // swap
2364           reader.swap();
2365           break;
2366         case 96: // iadd
2367           reader.iadd();
2368           break;
2369         case 97: // ladd
2370           reader.ladd();
2371           break;
2372         case 98: // fadd
2373           reader.fadd();
2374           break;
2375         case 99: // dadd
2376           reader.dadd();
2377           break;
2378         case 100: // isub
2379           reader.isub();
2380           break;
2381         case 101: // lsub
2382           reader.lsub();
2383           break;
2384         case 102: // fsub
2385           reader.fsub();
2386           break;
2387         case 103: // dsub
2388           reader.dsub();
2389           break;
2390         case 104: // imul
2391           reader.imul();
2392           break;
2393         case 105: // lmul
2394           reader.lmul();
2395           break;
2396         case 106: // fmul
2397           reader.fmul();
2398           break;
2399         case 107: // dmul
2400           reader.dmul();
2401           break;
2402         case 108: // idiv
2403           reader.idiv();
2404           break;
2405         case 109: // ldiv
2406           reader.ldiv();
2407           break;
2408         case 110: // fdiv
2409           reader.fdiv();
2410           break;
2411         case 111: //ddiv
2412           reader.ddiv();
2413           break;
2414         case 112: // irem
2415           reader.irem();
2416           break;
2417         case 113: // lrem
2418           reader.lrem();
2419           break;
2420         case 114: // frem
2421           reader.frem();
2422           break;
2423         case 115: // drem
2424           reader.drem();
2425           break;
2426         case 116: // ineg
2427           reader.ineg();
2428           break;
2429         case 117: // lneg
2430           reader.lneg();
2431           break;
2432         case 118: // fneg
2433           reader.fneg();
2434           break;
2435         case 119: // dneg
2436           reader.dneg();
2437           break;
2438         case 120: // ishl
2439           reader.ishl();
2440           break;
2441         case 121: // lshl
2442           reader.lshl();
2443           break;
2444         case 122: // ishr
2445           reader.ishr();
2446           break;
2447         case 123: // lshr
2448           reader.lshr();
2449           break;
2450         case 124: // iushr
2451           reader.iushr();
2452           break;
2453         case 125: // lushr
2454           reader.lushr();
2455           break;
2456         case 126: // iand
2457           reader.iand();
2458           break;
2459         case 127: // land
2460           reader.land();
2461           break;
2462         case 128: // ior
2463           reader.ior();
2464           break;
2465         case 129: // lor
2466           reader.lor();
2467           break;
2468         case 130: // ixor
2469           reader.ixor();
2470           break;
2471         case 131: // lxor
2472           reader.lxor();
2473           break;
2474         case 132: // iinc
2475           if (isWide){
2476             localVarIndex = readU2();
2477             constVal = readI2();
2478           } else {
2479             localVarIndex = readUByte();
2480             constVal = readByte();
2481           }
2482           reader.iinc(localVarIndex, constVal);
2483           break;
2484         case 133: // i2l
2485           reader.i2l();
2486           break;
2487         case 134: // i2f
2488           reader.i2f();
2489           break;
2490         case 135: // i2d
2491           reader.i2d();
2492           break;
2493         case 136: // l2i
2494           reader.l2i();
2495           break;
2496         case 137: // l2f
2497           reader.l2f();
2498           break;
2499         case 138: // l2d
2500           reader.l2d();
2501           break;
2502         case 139: // f2i
2503           reader.f2i();
2504           break;
2505         case 140: // f2l
2506           reader.f2l();
2507           break;
2508         case 141: // f2d
2509           reader.f2d();
2510           break;
2511         case 142: // d2i
2512           reader.d2i();
2513           break;
2514         case 143: // d2l
2515           reader.d2l();
2516           break;
2517         case 144: // d2f
2518           reader.d2f();
2519           break;
2520         case 145: // i2b
2521           reader.i2b();
2522           break;
2523         case 146: // i2c
2524           reader.i2c();
2525           break;
2526         case 147: // i2s
2527           reader.i2s();
2528           break;
2529         case 148: // lcmp
2530           reader.lcmp();
2531           break;
2532         case 149: // fcmpl
2533           reader.fcmpl();
2534           break;
2535         case 150: // fcmpg
2536           reader.fcmpg();
2537           break;
2538         case 151: // dcmpl
2539           reader.dcmpl();
2540           break;
2541         case 152: // dcmpg
2542           reader.dcmpg();
2543           break;
2544         case 153: // ifeq
2545           offset = readI2();
2546           reader.ifeq(offset);
2547           break;
2548         case 154: // ifne
2549           offset = readI2();
2550           reader.ifne(offset);
2551           break;
2552         case 155: // iflt
2553           offset = readI2();
2554           reader.iflt(offset);
2555           break;
2556         case 156: // ifge
2557           offset = readI2();
2558           reader.ifge(offset);
2559           break;
2560         case 157: // ifgt
2561           offset = readI2();
2562           reader.ifgt(offset);
2563           break;
2564         case 158: // ifle
2565           offset = readI2();
2566           reader.ifle(offset);
2567           break;
2568         case 159: // if_icmpeq
2569           offset = readI2();
2570           reader.if_icmpeq(offset);
2571           break;
2572         case 160: // if_icmpne
2573           offset = readI2();
2574           reader.if_icmpne(offset);
2575           break;
2576         case 161: // if_icmplt
2577           offset = readI2();
2578           reader.if_icmplt(offset);
2579           break;
2580         case 162: // if_icmpge
2581           offset = readI2();
2582           reader.if_icmpge(offset);
2583           break;
2584         case 163: // if_icmpgt
2585           offset = readI2();
2586           reader.if_icmpgt(offset);
2587           break;
2588         case 164: // if_icmple
2589           offset = readI2();
2590           reader.if_icmple(offset);
2591           break;
2592         case 165: // if_acmpeq
2593           offset = readI2();
2594           reader.if_acmpeq(offset);
2595           break;
2596         case 166: // if_acmpne
2597           offset = readI2();
2598           reader.if_acmpne(offset);
2599           break;
2600         case 167: // goto
2601           offset = readI2();
2602           reader.goto_(offset);
2603           break;
2604         case 168: // jsr
2605           offset = readI2();
2606           reader.jsr(offset);
2607           break;
2608         case 169: // ret
2609           localVarIndex = isWide ? readU2() : readUByte();
2610           reader.ret(localVarIndex);
2611           break;
2612         case 170: // tableswitch
2613           pos = (((pc+4)>>2)<<2)+startPos; // skip over padding
2614
2615           defaultOffset = readI4();
2616           int low = readI4();
2617           int high = readI4();
2618
2619           int len = high-low+1;
2620           nextPos = pos + len*4;
2621           reader.tableswitch(defaultOffset, low, high);
2622           pos = nextPos;
2623           break;
2624         case 171: // lookupswitch
2625           pos = (((pc+4)>>2)<<2)+startPos; // skip over padding
2626
2627           defaultOffset = readI4();
2628           int nPairs = readI4();
2629
2630           nextPos = pos + (nPairs*8);
2631           reader.lookupswitch(defaultOffset, nPairs);
2632           pos = nextPos;
2633           break;
2634         case 172: // ireturn
2635           reader.ireturn();
2636           break;
2637         case 173: // lreturn
2638           reader.lreturn();
2639           break;
2640         case 174: // freturn
2641           reader.freturn();
2642           break;
2643         case 175: // dreturn
2644           reader.dreturn();
2645           break;
2646         case 176: // areturn
2647           reader.areturn();
2648           break;
2649         case 177: // return
2650           reader.return_();
2651           break;
2652         case 178: // getstatic
2653           cpIdx = readU2(); // CP index of fieldRef
2654           reader.getstatic(cpIdx);
2655           break;
2656         case 179: // putstatic
2657           cpIdx = readU2(); // CP index of fieldRef
2658           reader.putstatic(cpIdx);
2659           break;
2660         case 180: // getfield
2661           cpIdx = readU2(); // CP index of fieldRef
2662           reader.getfield(cpIdx);
2663           break;
2664         case 181: // putfield
2665           cpIdx = readU2(); // CP index of fieldRef
2666           reader.putfield(cpIdx);
2667           break;
2668         case 182: // invokevirtual
2669           cpIdx = readU2(); // CP index of methodRef
2670           reader.invokevirtual(cpIdx);
2671           break;
2672         case 183: // invokespecial
2673           cpIdx = readU2(); // CP index of methodRef
2674           reader.invokespecial(cpIdx);
2675           break;
2676         case 184: // invokestatic
2677           cpIdx = readU2(); // CP index of methodRef
2678           reader.invokestatic(cpIdx);
2679           break;
2680         case 185: // invokeinterface
2681           cpIdx = readU2(); // CP index of methodRef
2682           int count = readUByte();
2683           int zero = readUByte(); // must be 0
2684           reader.invokeinterface(cpIdx, count, zero);
2685           break;
2686         case 186: // invokedynamic
2687           cpIdx = readU2(); // CP index of bootstrap method
2688           readUByte();  // 0
2689           readUByte(); //  0
2690           reader.invokedynamic(cpIdx);
2691           break;
2692         case 187: // new
2693           cpIdx = readU2();
2694           reader.new_(cpIdx);
2695           break;
2696         case 188: // newarray
2697           int aType = readUByte();
2698           reader.newarray(aType);
2699           break;
2700         case 189: // anewarray
2701           cpIdx = readU2(); // CP index of component type
2702           reader.anewarray(cpIdx);
2703           break;
2704         case 190: // arraylength
2705           reader.arraylength();
2706           break;
2707         case 191: // athrow
2708           reader.athrow();
2709           break;
2710         case 192: // checkcast
2711           cpIdx = readU2(); // cast type cp index
2712           reader.checkcast(cpIdx);
2713           break;
2714         case 193: // instanceof
2715           cpIdx = readU2(); // check type cp index
2716           reader.instanceof_(cpIdx);
2717           break;
2718         case 194: // monitorenter
2719           reader.monitorenter();
2720           break;
2721         case 195: // monitorexit
2722           reader.monitorexit();
2723           break;
2724         case 196: // wide
2725           isWide = true;
2726           // affects immediate operand width if next bytecode is:
2727           //  iload,fload,aload,lload,dload,
2728           //  istore,fstore,astore,lstore,dstore
2729           //  ret
2730           reader.wide();
2731           continue;
2732         case 197: // multianewarray
2733           cpIdx = readU2();
2734           int dimensions = readUByte();
2735           reader.multianewarray(cpIdx, dimensions);
2736           break;
2737         case 198: // ifnull
2738           offset = readI2();
2739           reader.ifnull(offset);
2740           break;
2741         case 199: // ifnonnull
2742           offset = readI2();
2743           reader.ifnonnull(offset);
2744           break;
2745         case 200: // goto_w
2746           offset = readI4();
2747           reader.goto_w(offset);
2748           break;
2749         case 201: // jsr_w
2750           offset = readI4();
2751           reader.jsr_w(offset);
2752           break;
2753           
2754           
2755         default:
2756           reader.unknown(opcode);
2757       }
2758
2759       isWide = false; // reset wide modifier
2760     }
2761
2762   }
2763
2764   //--- those can only be called from within a JVMByteCodeReader.tableswitch() notification
2765   public void parseTableSwitchEntries(JVMByteCodeReader reader, int low, int high){
2766     for (int val=low; val<=high; val++){
2767       int offset = readI4();
2768       reader.tableswitchEntry(val, offset);
2769     }
2770   }
2771   public int getTableSwitchOffset(int low, int high, int defaultOffset, int val){
2772     if (val < low || val > high){
2773       return defaultOffset;
2774     }
2775
2776     int n = Math.abs(val - low);
2777     pos += n*4;
2778     int pcOffset = readI4();
2779
2780     return pcOffset;
2781   }
2782
2783   //--- those can only be called from within a JVMByteCodeReader.lookupswitch() notification
2784   public void parseLookupSwitchEntries(JVMByteCodeReader reader, int nEntries){
2785     for (int i=0; i<nEntries; i++){
2786       int value = readI4();
2787       int offset = readI4();
2788       reader.lookupswitchEntry(i, value, offset);
2789     }
2790   }
2791   public int getLookupSwitchOffset(int nEntries, int defaultOffset, int val){
2792     for (int i=0; i<nEntries; i++){
2793       int match = readI4();
2794       if (val > match){
2795         pos +=4;
2796       } else if (val == match) {
2797         int offset = readI4();
2798         return offset;
2799       } else {
2800         break;
2801       }
2802     }
2803     return defaultOffset;
2804   }
2805
2806 }