home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / Code.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  18.5 KB  |  710 lines

  1. /*
  2.  *
  3.  * @(#) Code.java 1.4@(#)
  4.  *
  5.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  6.  * 
  7.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  8.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  9.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  10.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  11.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  12.  * THIS SOFTWARE OR ITS DERIVATIVES.
  13.  * 
  14.  */
  15.  
  16. /**
  17.  * <p>
  18.  * sunw.demo.classfile.Code
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25.  
  26. package sunw.demo.classfile;
  27.  
  28.  
  29. import java.io.DataOutputStream;
  30. import java.io.IOException;
  31.  
  32. import java.util.Vector;
  33.  
  34. import sunw.demo.classfile.Attribute;
  35. import sunw.demo.classfile.ClassConstant;
  36.  
  37. /**
  38.  * <p>
  39.  * The Code attribute is defined to describe the implementation for each
  40.  * Method Implementation in a class. In particular it contains the byte
  41.  * codes and exception information.
  42.  * </p>
  43.  */
  44.  
  45. final class Code extends Attribute {
  46.  
  47.     final static byte    OP_NOP            = (byte) 0x00;
  48.     final static byte    OP_ACONST_NULL        = (byte) 0x01;
  49.  
  50.     // int consts
  51.  
  52.     final static byte    OP_ICONST_m1        = (byte) 0x02;
  53.     final static byte    OP_ICONST_0        = (byte) 0x03;
  54.     final static byte    OP_ICONST_1        = (byte) 0x04;
  55.     final static byte    OP_ICONST_2        = (byte) 0x05;
  56.     final static byte    OP_ICONST_3        = (byte) 0x06;
  57.     final static byte    OP_ICONST_4        = (byte) 0x07;
  58.     final static byte    OP_ICONST_5        = (byte) 0x08;
  59.  
  60.     // long consts
  61.  
  62.     final static byte    OP_LCONST_0        = (byte) 0x09;
  63.     final static byte    OP_LCONST_1        = (byte) 0x0A;
  64.  
  65.     // float consts
  66.  
  67.     final static byte    OP_FCONST_0        = (byte) 0x0B;
  68.     final static byte    OP_FCONST_1        = (byte) 0x0C;
  69.     final static byte    OP_FCONST_2        = (byte) 0x0D;
  70.  
  71.     // double consts
  72.  
  73.     final static byte    OP_DCONST_0        = (byte) 0x0E;
  74.     final static byte    OP_DCONST_1        = (byte) 0x0F;
  75.  
  76.     final static byte    OP_BIPUSH        = (byte) 0x10;
  77.     final static byte    OP_SIPUSH        = (byte) 0x11;
  78.  
  79.     final static byte    OP_LDC            = (byte) 0x12;
  80.     final static byte    OP_LDC_WIDE        = (byte) 0x13;
  81.     final static byte    OP_LDC2_WIDE        = (byte) 0x14;
  82.  
  83.  
  84.     // typed loads local
  85.  
  86.     final static byte    OP_ILOAD        = (byte) 0x15;
  87.     final static byte    OP_LLOAD        = (byte) 0x16;
  88.     final static byte    OP_FLOAD        = (byte) 0x17;
  89.     final static byte    OP_DLOAD        = (byte) 0x18;
  90.     final static byte    OP_ALOAD        = (byte) 0x19;
  91.  
  92.     // int loads
  93.  
  94.     final static byte    OP_ILOAD_0        = (byte) 0x1A;
  95.     final static byte    OP_ILOAD_1        = (byte) 0x1B;
  96.     final static byte    OP_ILOAD_2        = (byte) 0x1C;
  97.     final static byte    OP_ILOAD_3        = (byte) 0x1D;
  98.  
  99.     // long loads
  100.  
  101.     final static byte    OP_LLOAD_0        = (byte) 0x1E;
  102.     final static byte    OP_LLOAD_1        = (byte) 0x1F;
  103.     final static byte    OP_LLOAD_2        = (byte) 0x20;
  104.     final static byte    OP_LLOAD_3        = (byte) 0x21;
  105.  
  106.     // float loads
  107.  
  108.     final static byte    OP_FLOAD_0        = (byte) 0x22;
  109.     final static byte    OP_FLOAD_1        = (byte) 0x23;
  110.     final static byte    OP_FLOAD_2        = (byte) 0x24;
  111.     final static byte    OP_FLOAD_3        = (byte) 0x25;
  112.  
  113.     // double loads
  114.  
  115.     final static byte    OP_DLOAD_0        = (byte) 0x26;
  116.     final static byte    OP_DLOAD_1        = (byte) 0x27;
  117.     final static byte    OP_DLOAD_2        = (byte) 0x28;
  118.     final static byte    OP_DLOAD_3        = (byte) 0x29;
  119.  
  120.     // ref loads
  121.  
  122.     final static byte    OP_ALOAD_0        = (byte) 0x2A;
  123.     final static byte    OP_ALOAD_1        = (byte) 0x2B;
  124.     final static byte    OP_ALOAD_2        = (byte) 0x2C;
  125.     final static byte    OP_ALOAD_3        = (byte) 0x2D;
  126.  
  127.     final static byte    OP_IALOAD        = (byte) 0x2E;
  128.     final static byte    OP_LALOAD        = (byte) 0x2F;
  129.  
  130.     // array loads 
  131.  
  132.     final static byte    OP_FALOAD        = (byte) 0x30;
  133.     final static byte    OP_DALOAD        = (byte) 0x31;
  134.     final static byte    OP_AALOAD        = (byte) 0x32;
  135.     final static byte    OP_BALOAD        = (byte) 0x33;
  136.     final static byte    OP_CALOAD        = (byte) 0x34;
  137.     final static byte    OP_SALOAD        = (byte) 0x35;
  138.  
  139.     final static byte    OP_ISTORE        = (byte) 0x36;
  140.     final static byte    OP_LSTORE        = (byte) 0x37;
  141.     final static byte    OP_FSTORE        = (byte) 0x38;
  142.     final static byte    OP_DSTORE        = (byte) 0x39;
  143.     final static byte    OP_ASTORE        = (byte) 0x3A;
  144.  
  145.     // int stores
  146.  
  147.     final static byte    OP_ISTORE_0        = (byte) 0x3B;
  148.     final static byte    OP_ISTORE_1        = (byte) 0x3C;
  149.     final static byte    OP_ISTORE_2        = (byte) 0x3D;
  150.     final static byte    OP_ISTORE_3        = (byte) 0x3E;
  151.  
  152.     // long stores 
  153.  
  154.     final static byte    OP_LSTORE_0        = (byte) 0x3F;
  155.     final static byte    OP_LSTORE_1        = (byte) 0x40;
  156.     final static byte    OP_LSTORE_2        = (byte) 0x41;
  157.     final static byte    OP_LSTORE_3        = (byte) 0x42;
  158.  
  159.     // float stores
  160.  
  161.     final static byte    OP_FSTORE_0        = (byte) 0x43;
  162.     final static byte    OP_FSTORE_1        = (byte) 0x44;
  163.     final static byte    OP_FSTORE_2        = (byte) 0x45;
  164.     final static byte    OP_FSTORE_3        = (byte) 0x46;
  165.  
  166.     // double stores
  167.  
  168.     final static byte    OP_DSTORE_0        = (byte) 0x47;
  169.     final static byte    OP_DSTORE_1        = (byte) 0x48;
  170.     final static byte    OP_DSTORE_2        = (byte) 0x49;
  171.     final static byte    OP_DSTORE_3        = (byte) 0x4A;
  172.  
  173.     // ref stores
  174.  
  175.     final static byte    OP_ASTORE_0        = (byte) 0x4B;
  176.     final static byte    OP_ASTORE_1        = (byte) 0x4C;
  177.     final static byte    OP_ASTORE_2        = (byte) 0x4D;
  178.     final static byte    OP_ASTORE_3        = (byte) 0x4E;
  179.  
  180.     final static byte    OP_IASTORE        = (byte) 0x4F;
  181.  
  182.     // array stores
  183.  
  184.     final static byte    OP_LASTORE        = (byte) 0x50;
  185.     final static byte    OP_FASTORE        = (byte) 0x51;
  186.     final static byte    OP_DASTORE        = (byte) 0x52;
  187.     final static byte    OP_AASTORE        = (byte) 0x53;
  188.     final static byte    OP_BASTORE        = (byte) 0x54;
  189.     final static byte    OP_CASTORE        = (byte) 0x55;
  190.     final static byte    OP_SASTORE        = (byte) 0x56;
  191.  
  192.     final static byte    OP_POP            = (byte) 0x57;
  193.     final static byte    OP_POP2            = (byte) 0x58;
  194.  
  195.     // dup's
  196.  
  197.     final static byte    OP_DUP            = (byte) 0x59;
  198.     final static byte    OP_DUP_X1        = (byte) 0x5A;
  199.     final static byte    OP_DUP_X2        = (byte) 0x5B;
  200.     final static byte    OP_DUP2            = (byte) 0x5C;
  201.     final static byte    OP_DUP2_X1        = (byte) 0x5D;
  202.     final static byte    OP_DUP2_X2        = (byte) 0x5E;
  203.     final static byte    OP_SWAP            = (byte) 0x5F;
  204.  
  205.     // arith
  206.  
  207.     final static byte    OP_IADD            = (byte) 0x60;
  208.     final static byte    OP_LADD            = (byte) 0x61;
  209.     final static byte    OP_FADD            = (byte) 0x62;
  210.     final static byte    OP_DADD            = (byte) 0x63;
  211.  
  212.     final static byte    OP_ISUB            = (byte) 0x64;
  213.     final static byte    OP_LSUB            = (byte) 0x65;
  214.     final static byte    OP_FSUB            = (byte) 0x66;
  215.     final static byte    OP_DSUB            = (byte) 0x67;
  216.  
  217.     final static byte    OP_IMUL            = (byte) 0x68;
  218.     final static byte    OP_LMUL            = (byte) 0x69;
  219.     final static byte    OP_FMUL            = (byte) 0x6A;
  220.     final static byte    OP_DMUL            = (byte) 0x6B;
  221.  
  222.     final static byte    OP_IDIV            = (byte) 0x6C;
  223.     final static byte    OP_FDIV            = (byte) 0x6E;
  224.     final static byte    OP_LDIV            = (byte) 0x6D;
  225.     final static byte    OP_DDIV            = (byte) 0x6F;
  226.  
  227.     // arith misc
  228.  
  229.     final static byte    OP_IREM            = (byte) 0x70;
  230.     final static byte    OP_LREM            = (byte) 0x71;
  231.     final static byte    OP_FREM            = (byte) 0x72;
  232.     final static byte    OP_DREM            = (byte) 0x73;
  233.  
  234.     final static byte    OP_INEG            = (byte) 0x74;
  235.     final static byte    OP_LNEG            = (byte) 0x75;
  236.     final static byte    OP_FNEG            = (byte) 0x76;
  237.     final static byte    OP_DNEG            = (byte) 0x77;
  238.  
  239.     final static byte    OP_ISHL            = (byte) 0x78;
  240.     final static byte    OP_LSHL            = (byte) 0x79;
  241.  
  242.     final static byte    OP_ISHR            = (byte) 0x7A;
  243.     final static byte    OP_LSHR            = (byte) 0x7B;
  244.  
  245.     final static byte    OP_IUSHR        = (byte) 0x7C;
  246.     final static byte    OP_LUSHR        = (byte) 0x7D;
  247.  
  248.     final static byte    OP_IAND            = (byte) 0x7E;
  249.     final static byte    OP_LAND            = (byte) 0x7F;
  250.  
  251.     final static byte    OP_IOR            = (byte) 0x80;
  252.     final static byte    OP_LOR            = (byte) 0x81;
  253.  
  254.     final static byte    OP_IXOR            = (byte) 0x82;
  255.     final static byte    OP_LXOR            = (byte) 0x83;
  256.     
  257.     // local int += const
  258.  
  259.     final static byte    OP_IINC            = (byte) 0x84;
  260.  
  261.     // int conversions
  262.  
  263.     final static byte    OP_I2L            = (byte) 0x85;
  264.     final static byte    OP_I2F            = (byte) 0x86;
  265.     final static byte    OP_I2D            = (byte) 0x87;
  266.  
  267.     // long conversions
  268.  
  269.     final static byte    OP_L2I            = (byte) 0x88;
  270.     final static byte    OP_L2F            = (byte) 0x89;
  271.     final static byte    OP_L2D            = (byte) 0x8A;
  272.  
  273.     // float conversions
  274.  
  275.     final static byte    OP_F2I            = (byte) 0x8B;
  276.     final static byte    OP_F2L            = (byte) 0x8C;
  277.     final static byte    OP_F2D            = (byte) 0x8D;
  278.  
  279.     // double conversions
  280.  
  281.     final static byte    OP_D2I            = (byte) 0x8E;
  282.     final static byte    OP_D2L            = (byte) 0x8F;
  283.     final static byte    OP_D2F            = (byte) 0x90;
  284.  
  285.     // int conversions
  286.  
  287.     final static byte    OP_I2B            = (byte) 0x91;
  288.     final static byte    OP_I2C            = (byte) 0x92;
  289.     final static byte    OP_I2S            = (byte) 0x93;
  290.  
  291.     // long comparision's
  292.  
  293.     final static byte    OP_LCMP            = (byte) 0x94;
  294.     
  295.     // float comparision's
  296.  
  297.     final static byte    OP_FCMPL        = (byte) 0x95;
  298.     final static byte    OP_FCMPG        = (byte) 0x96;
  299.  
  300.     // double comparision's
  301.  
  302.     final static byte    OP_DCMPL        = (byte) 0x97;
  303.     final static byte    OP_DCMPG        = (byte) 0x98;
  304.  
  305.     // int to zero comparisions
  306.  
  307.     final static byte    OP_IFEQ            = (byte) 0x99;
  308.     final static byte    OP_IFNE            = (byte) 0x9A;
  309.     final static byte    OP_IFLT            = (byte) 0x9B;
  310.     final static byte    OP_IFGE            = (byte) 0x9C;
  311.     final static byte    OP_IFGT            = (byte) 0x9D;
  312.     final static byte    OP_IFLE            = (byte) 0x9E;
  313.  
  314.     // int to int comparision's
  315.  
  316.     final static byte    OP_IFICMPEQ        = (byte) 0x9F;
  317.     final static byte    OP_IFICMPNE        = (byte) 0xA0;
  318.     final static byte    OP_IFICMPLT        = (byte) 0xA1;
  319.     final static byte    OP_IFICMPGE        = (byte) 0xA2;
  320.     final static byte    OP_IFICMPGT        = (byte) 0xA3;
  321.     final static byte    OP_IFICMPLE        = (byte) 0xA4;
  322.  
  323.     // ref comparisions
  324.  
  325.     final static byte    OP_IFACMPEQ        = (byte) 0xA5;
  326.     final static byte    OP_IFACMPNE        = (byte) 0xA6;
  327.  
  328.     // goto
  329.  
  330.     final static byte    OP_GOTO            = (byte) 0xA7;
  331.  
  332.     final static byte    OP_JSR            = (byte) 0xA8;
  333.  
  334.     final static byte    OP_RET            = (byte) 0xA9;
  335.  
  336.     final static byte    OP_TABLESWITCH        = (byte) 0xAA;
  337.  
  338.     final static byte    OP_LOOKUP_SWITCH    = (byte) 0xAB;
  339.  
  340.  
  341.     // return's
  342.  
  343.     final static byte    OP_IRETURN        = (byte) 0xAC;
  344.     final static byte    OP_LRETURN        = (byte) 0xAD;
  345.     final static byte    OP_FRETURN        = (byte) 0xAE;
  346.     final static byte    OP_DRETURN        = (byte) 0xAF;
  347.     final static byte    OP_ARETURN        = (byte) 0xB0;
  348.     final static byte    OP_RETURN        = (byte) 0xB1;
  349.  
  350.  
  351.     // getfield's
  352.  
  353.     final static byte    OP_GETSTATIC        = (byte) 0xB2;
  354.     final static byte    OP_GETFIELD        = (byte) 0xB4;
  355.  
  356.     // invoke virtual
  357.  
  358.     final static byte    OP_INVOKE_VIRTUAL    = (byte) 0xB6;
  359.  
  360.     // invoke static
  361.  
  362.     final static byte    OP_INVOKE_STATIC    = (byte) 0xB8;
  363.  
  364.     // method invocation
  365.  
  366.     final static byte    OP_INVOKE_SPECIAL    = (byte) 0xB7;
  367.  
  368.     // invoke interface
  369.  
  370.     final static byte    OP_INVOKE_INTERFACE    = (byte) 0xB9;
  371.  
  372.     // new
  373.  
  374.     final static byte    OP_NEW            = (byte) 0xBB;
  375.  
  376.     // array misc
  377.  
  378.     final static byte    OP_NEWARRAY        = (byte) 0xBD;
  379.  
  380.     final static byte    ARRAY_T_BOOLEAN        = (byte) 0x4;
  381.     final static byte    ARRAY_T_CHAR        = (byte) 0x5;
  382.     final static byte    ARRAY_T_FLOAT        = (byte) 0x6;
  383.     final static byte    ARRAY_T_DOUBLE        = (byte) 0x7;
  384.     final static byte    ARRAY_T_BYTE        = (byte) 0x8;
  385.     final static byte    ARRAY_T_SHORT        = (byte) 0x9;
  386.     final static byte    ARRAY_T_INT        = (byte) 0xA;
  387.     final static byte    ARRAY_T_LONG        = (byte) 0xB;
  388.     
  389.     // putfield's
  390.  
  391.     final static byte    OP_PUTSTATIC        = (byte) 0xB3;
  392.     final static byte    OP_PUTFIELD        = (byte) 0xB5;
  393.  
  394.     // array's
  395.  
  396.     final static byte    OP_ANEWARRAY        = (byte) 0xBD;
  397.     final static byte    OP_ARRAYLENGTH        = (byte) 0xBE;
  398.  
  399.     // exceptions
  400.  
  401.     final static byte    OP_ATHROW        = (byte) 0xBF;
  402.  
  403.     // cast
  404.  
  405.     final static byte    OP_CHECKCAST        = (byte) 0xC0;
  406.  
  407.     // instanceof
  408.  
  409.     final static byte    OP_INSTANCEOF        = (byte) 0xC1;
  410.  
  411.     // monitor
  412.  
  413.     final static byte    OP_MONITOR_ENTER    = (byte) 0xC2;
  414.     final static byte    OP_MONITOR_EXIT        = (byte) 0xC3;
  415.  
  416.     // wide
  417.  
  418.     final static byte    OP_WIDE            = (byte) 0xC4;
  419.  
  420.     // arrays
  421.  
  422.     final static byte    OP_MULTI_NEW_ARRAY     = (byte) 0xC5;
  423.  
  424.     // compare to null
  425.  
  426.     final static byte    OP_IFNULL        = (byte) 0xc6;
  427.     final static byte    OP_IFNONNULL        = (byte) 0xc7;
  428.  
  429.     // goto wide
  430.  
  431.     final static byte    OP_GOTO_WIDE        = (byte) 0xc8;
  432.  
  433.     final static byte    OP_JSR_WIDE        = (byte) 0xc9;
  434.  
  435.  
  436.     /*
  437.      * inst vars
  438.      */
  439.  
  440.     private Vector        attributes;
  441.  
  442.     private int            length = 12;    // starting value
  443.  
  444.     private short        currentPC;
  445.  
  446.     private short        maxLocals;
  447.     
  448.     private short        maxStack;
  449.  
  450.     private Vector        byteCodes = new Vector(1);
  451.  
  452.     private Vector        exceptions;
  453.  
  454.     /**
  455.      * <p> construct a Code Attribute </p>
  456.      *
  457.      * @param locals    number of words used to describe local vars
  458.      * @param maxstack    max number of stack words used.
  459.      *
  460.      */
  461.  
  462.     Code(ClassFile cf, short locals, short stack) {
  463.         super(CODE, cf);
  464.  
  465.         maxLocals = (locals >= 0 ? locals : 0);
  466.         maxStack  = (stack  >  2 ? stack  : 2);
  467.     }
  468.     
  469.     /**
  470.      * <p> write the code attribute to the stream </p>
  471.      *
  472.      * @param dos the output stream
  473.      *
  474.      * @throws IOException
  475.      */
  476.     
  477.     void write(DataOutputStream dos) throws IOException {
  478.         int i;
  479.  
  480.         dos.writeShort(getNameConstantPoolIndex());
  481.         dos.writeInt(getLength());
  482.         dos.writeShort(maxStack);
  483.         dos.writeShort(maxLocals);
  484.  
  485.         // write the code ...
  486.  
  487.         dos.writeInt(byteCodes.size());
  488.  
  489.         for (i = 0; i < byteCodes.size(); i++) {
  490.             dos.writeByte(((Byte)byteCodes.elementAt(i)).byteValue());
  491.         }
  492.  
  493.         // write exceptions (if any)
  494.  
  495.         if (exceptions != null) {
  496.             dos.writeShort(exceptions.size());
  497.  
  498.             for (i = 0; i < exceptions.size(); i++) {
  499.                 ((ExceptionTableEntry)exceptions.elementAt(i)).write(dos);
  500.             }
  501.         } else dos.writeShort(0);
  502.  
  503.         // write attributes (if any)
  504.  
  505.         if (attributes != null) {
  506.             dos.writeShort(attributes.size());
  507.  
  508.             for (i = 0; i < attributes.size(); i ++) {
  509.                 ((Attribute)attributes.elementAt(i)).write(dos);
  510.             }
  511.         } else dos.writeShort(0);
  512.     }
  513.  
  514.     /**
  515.      * <p> returns the length of the Code attribute in bytes </p>
  516.      *
  517.      * @return the length of the attribute.
  518.      */
  519.  
  520.     int getLength() { return length; }
  521.  
  522.     /**
  523.      * @return object equality.
  524.      */
  525.  
  526.     public boolean equals(Object o) {
  527.         return false;
  528.     }
  529.  
  530.     /**
  531.      * @return a hashcode for the object.
  532.      */
  533.     public int hashCode() {
  534.     return length;
  535.     }
  536.  
  537.     /**
  538.      * @return the current PC offset from the start of the method.
  539.      */
  540.  
  541.     short getCurrentPC() { return currentPC; }
  542.  
  543.     /**
  544.      * <p>
  545.      * adds per Code attribute, can be used for SourceFile, LocalVariable,
  546.      * and LineNumberTable attributes etc.
  547.      * </p>
  548.      *
  549.      * @param attr Attribte to be added.
  550.      */
  551.  
  552.     void addAttribute(Attribute attr) {
  553.         if (attributes == null) attributes = new Vector(1);
  554.  
  555.         attributes.addElement(attr);
  556.         length += attr.getLength() + 6; // sizeof(Attribute)
  557.     }
  558.  
  559.     /**
  560.      * <p>
  561.      * Adds an entry to the Exception handler table for this Code attribute.
  562.      * An entry describes the start and stop pc offset within the Code fragment
  563.      * for which an exception handler is provided, the start pc of the handler
  564.      * code within the fragment itself, and the class of the exception type
  565.      * for this handler.
  566.      * </p>
  567.      *
  568.      * @param start    start pc offset for this exception handler range
  569.      * @param stop    stop pc offset for this exception handler range
  570.      * @param handler    handler pc start offset for this exception
  571.      * @param ct    CONSTANT_CLASS describing the exception class handled
  572.      */
  573.  
  574.     void addExceptionTableEntry(short start,   short         stop,
  575.                             short handler, ClassConstant ct) {
  576.         exceptions.addElement(
  577.             new ExceptionTableEntry(start, stop, handler, ct)
  578.         );
  579.  
  580.         length += 8; // sizeof(ExceptionTableEntry)
  581.     }
  582.  
  583.     /**
  584.      * <p> add an opcode to the implementation </p>
  585.      */
  586.  
  587.     void addOp(byte opCode) {
  588.         byteCodes.addElement(new Byte(opCode));
  589.         currentPC++;
  590.         length++;
  591.     }
  592.  
  593.     /**
  594.      * <p> add an opcode and a 1 byte operand </p>
  595.      */
  596.  
  597.     void addOp1(byte opCode, byte op1) {
  598.         byteCodes.addElement(new Byte(opCode));
  599.         byteCodes.addElement(new Byte(op1));
  600.         currentPC += 2;
  601.         length    += 2;
  602.     }
  603.  
  604.     /**
  605.      * <p> add an opcode and 2, 1 byte operands </p>
  606.      */
  607.  
  608.     void addOp2(byte opCode, byte op1, byte op2) {
  609.         byteCodes.addElement(new Byte(opCode));
  610.         byteCodes.addElement(new Byte(op1));
  611.         byteCodes.addElement(new Byte(op2));
  612.         currentPC += 3;
  613.         length    += 3;
  614.     }
  615.  
  616.     /**
  617.      * <p> add an opcode and 4, 1 byte operands </p>
  618.      */
  619.  
  620.     void addOp4(byte opCode, byte op1, byte op2, byte op3, byte op4) {
  621.         byteCodes.addElement(new Byte(opCode));
  622.         byteCodes.addElement(new Byte(op1));
  623.         byteCodes.addElement(new Byte(op2));
  624.         byteCodes.addElement(new Byte(op3));
  625.         byteCodes.addElement(new Byte(op4));
  626.         currentPC += 5;
  627.         length    += 5;
  628.  
  629.     }
  630.  
  631.     /**
  632.      * <p> add an opcode and a 2 byte operand </p>
  633.      */
  634.  
  635.     void addOpShort(byte opCode,short op) {
  636.         addOp2(opCode,
  637.                (byte)((op >>> 8) & 0xff),
  638.                (byte)( op        & 0xff)
  639.         );
  640.     }
  641.  
  642.     /**
  643.      * <p> add an opcode and a 4 byte operand </p>
  644.      */
  645.  
  646.     void addOpInt(byte opCode,int op) {
  647.         addOp4(opCode,    
  648.                (byte)((op >>> 24) & 0xff),
  649.                (byte)((op >>> 16) & 0xff),
  650.                (byte)((op >>>  8) & 0xff),
  651.                (byte)( op         & 0xff)
  652.         );
  653.     }
  654.  
  655.     /**
  656.      * <p> increment the local word count </p>
  657.      *
  658.      * @param n the number of local words to increment by.
  659.      */
  660.  
  661.     void incrLocals(short n) { maxLocals += n; }
  662.  
  663.     /**
  664.      * <p> increment the max operand stack word count </p>
  665.      *
  666.      * @param n the number of words to increment the max stack count by
  667.      */
  668.  
  669.     void incrMaxStack(short n) { maxStack += n; }
  670. }
  671.  
  672. /*
  673.  * private implementation class to represent exception table entries.
  674.  */
  675.  
  676. final class ExceptionTableEntry {
  677.     private short        startPC;
  678.     private short        stopPC;
  679.     private short        handlerPC;
  680.     private ClassConstant    exceptionType;
  681.  
  682.     /*
  683.      * construct and Exception Table Entry
  684.      */
  685.  
  686.     ExceptionTableEntry(short start, short       stop,
  687.                 short handler,   ClassConstant eType) {
  688.         super();
  689.  
  690.         startPC       = start;
  691.         stopPC        = stop;
  692.         handlerPC     = handler;
  693.         exceptionType = eType;
  694.     }
  695.  
  696.     /*
  697.      * wrote the exception table entry to the stream
  698.      */
  699.  
  700.     void write(DataOutputStream dos) throws IOException {
  701.         dos.writeShort(startPC);
  702.         dos.writeShort(stopPC);
  703.         dos.writeShort(handlerPC);
  704.         if (exceptionType != null)
  705.             dos.writeShort(exceptionType.getConstantPoolIndex());
  706.         else
  707.             dos.writeShort(0);
  708.     }
  709. }
  710.