src/share/classes/sun/reflect/Label.java

Print this page




  31 
  32 /** Allows forward references in bytecode streams emitted by
  33     ClassFileAssembler. Assumes that the start of the method body is
  34     the first byte in the assembler's buffer. May be used at more than
  35     one branch site. */
  36 
  37 class Label {
  38     static class PatchInfo {
  39         PatchInfo(ClassFileAssembler asm,
  40                   short instrBCI,
  41                   short patchBCI,
  42                   int stackDepth)
  43         {
  44             this.asm = asm;
  45             this.instrBCI   = instrBCI;
  46             this.patchBCI   = patchBCI;
  47             this.stackDepth = stackDepth;
  48         }
  49         // This won't work for more than one assembler anyway, so this is
  50         // unnecessary
  51         ClassFileAssembler asm;
  52         short instrBCI;
  53         short patchBCI;
  54         int   stackDepth;
  55     }
  56     private List/*<PatchInfo>*/ patches = new ArrayList();
  57 
  58     public Label() {
  59     }
  60 
  61     void add(ClassFileAssembler asm,
  62              short instrBCI,
  63              short patchBCI,
  64              int stackDepth)
  65     {
  66         patches.add(new PatchInfo(asm, instrBCI, patchBCI, stackDepth));
  67     }
  68 
  69     public void bind() {
  70         for (Iterator iter = patches.iterator(); iter.hasNext(); ) {
  71             PatchInfo patch = (PatchInfo) iter.next();
  72             short curBCI = patch.asm.getLength();
  73             short offset = (short) (curBCI - patch.instrBCI);
  74             patch.asm.emitShort(patch.patchBCI, offset);


  31 
  32 /** Allows forward references in bytecode streams emitted by
  33     ClassFileAssembler. Assumes that the start of the method body is
  34     the first byte in the assembler's buffer. May be used at more than
  35     one branch site. */
  36 
  37 class Label {
  38     static class PatchInfo {
  39         PatchInfo(ClassFileAssembler asm,
  40                   short instrBCI,
  41                   short patchBCI,
  42                   int stackDepth)
  43         {
  44             this.asm = asm;
  45             this.instrBCI   = instrBCI;
  46             this.patchBCI   = patchBCI;
  47             this.stackDepth = stackDepth;
  48         }
  49         // This won't work for more than one assembler anyway, so this is
  50         // unnecessary
  51         final ClassFileAssembler asm;
  52         final short instrBCI;
  53         final short patchBCI;
  54         final int   stackDepth;
  55     }
  56     private List/*<PatchInfo>*/ patches = new ArrayList();
  57 
  58     public Label() {
  59     }
  60 
  61     void add(ClassFileAssembler asm,
  62              short instrBCI,
  63              short patchBCI,
  64              int stackDepth)
  65     {
  66         patches.add(new PatchInfo(asm, instrBCI, patchBCI, stackDepth));
  67     }
  68 
  69     public void bind() {
  70         for (Iterator iter = patches.iterator(); iter.hasNext(); ) {
  71             PatchInfo patch = (PatchInfo) iter.next();
  72             short curBCI = patch.asm.getLength();
  73             short offset = (short) (curBCI - patch.instrBCI);
  74             patch.asm.emitShort(patch.patchBCI, offset);