htmlunit-core-js-2.7

16:36:32.295 INFO  jd.cli.Main - Decompiling htmlunit-core-js-2.7.jar
package net.sourceforge.htmlunit.corejs.classfile;

public class ByteCode
{
  public static final int NOP = 0;
  public static final int ACONST_NULL = 1;
  public static final int ICONST_M1 = 2;
  public static final int ICONST_0 = 3;
  public static final int ICONST_1 = 4;
  public static final int ICONST_2 = 5;
  public static final int ICONST_3 = 6;
  public static final int ICONST_4 = 7;
  public static final int ICONST_5 = 8;
  public static final int LCONST_0 = 9;
  public static final int LCONST_1 = 10;
  public static final int FCONST_0 = 11;
  public static final int FCONST_1 = 12;
  public static final int FCONST_2 = 13;
  public static final int DCONST_0 = 14;
  public static final int DCONST_1 = 15;
  public static final int BIPUSH = 16;
  public static final int SIPUSH = 17;
  public static final int LDC = 18;
  public static final int LDC_W = 19;
  public static final int LDC2_W = 20;
  public static final int ILOAD = 21;
  public static final int LLOAD = 22;
  public static final int FLOAD = 23;
  public static final int DLOAD = 24;
  public static final int ALOAD = 25;
  public static final int ILOAD_0 = 26;
  public static final int ILOAD_1 = 27;
  public static final int ILOAD_2 = 28;
  public static final int ILOAD_3 = 29;
  public static final int LLOAD_0 = 30;
  public static final int LLOAD_1 = 31;
  public static final int LLOAD_2 = 32;
  public static final int LLOAD_3 = 33;
  public static final int FLOAD_0 = 34;
  public static final int FLOAD_1 = 35;
  public static final int FLOAD_2 = 36;
  public static final int FLOAD_3 = 37;
  public static final int DLOAD_0 = 38;
  public static final int DLOAD_1 = 39;
  public static final int DLOAD_2 = 40;
  public static final int DLOAD_3 = 41;
  public static final int ALOAD_0 = 42;
  public static final int ALOAD_1 = 43;
  public static final int ALOAD_2 = 44;
  public static final int ALOAD_3 = 45;
  public static final int IALOAD = 46;
  public static final int LALOAD = 47;
  public static final int FALOAD = 48;
  public static final int DALOAD = 49;
  public static final int AALOAD = 50;
  public static final int BALOAD = 51;
  public static final int CALOAD = 52;
  public static final int SALOAD = 53;
  public static final int ISTORE = 54;
  public static final int LSTORE = 55;
  public static final int FSTORE = 56;
  public static final int DSTORE = 57;
  public static final int ASTORE = 58;
  public static final int ISTORE_0 = 59;
  public static final int ISTORE_1 = 60;
  public static final int ISTORE_2 = 61;
  public static final int ISTORE_3 = 62;
  public static final int LSTORE_0 = 63;
  public static final int LSTORE_1 = 64;
  public static final int LSTORE_2 = 65;
  public static final int LSTORE_3 = 66;
  public static final int FSTORE_0 = 67;
  public static final int FSTORE_1 = 68;
  public static final int FSTORE_2 = 69;
  public static final int FSTORE_3 = 70;
  public static final int DSTORE_0 = 71;
  public static final int DSTORE_1 = 72;
  public static final int DSTORE_2 = 73;
  public static final int DSTORE_3 = 74;
  public static final int ASTORE_0 = 75;
  public static final int ASTORE_1 = 76;
  public static final int ASTORE_2 = 77;
  public static final int ASTORE_3 = 78;
  public static final int IASTORE = 79;
  public static final int LASTORE = 80;
  public static final int FASTORE = 81;
  public static final int DASTORE = 82;
  public static final int AASTORE = 83;
  public static final int BASTORE = 84;
  public static final int CASTORE = 85;
  public static final int SASTORE = 86;
  public static final int POP = 87;
  public static final int POP2 = 88;
  public static final int DUP = 89;
  public static final int DUP_X1 = 90;
  public static final int DUP_X2 = 91;
  public static final int DUP2 = 92;
  public static final int DUP2_X1 = 93;
  public static final int DUP2_X2 = 94;
  public static final int SWAP = 95;
  public static final int IADD = 96;
  public static final int LADD = 97;
  public static final int FADD = 98;
  public static final int DADD = 99;
  public static final int ISUB = 100;
  public static final int LSUB = 101;
  public static final int FSUB = 102;
  public static final int DSUB = 103;
  public static final int IMUL = 104;
  public static final int LMUL = 105;
  public static final int FMUL = 106;
  public static final int DMUL = 107;
  public static final int IDIV = 108;
  public static final int LDIV = 109;
  public static final int FDIV = 110;
  public static final int DDIV = 111;
  public static final int IREM = 112;
  public static final int LREM = 113;
  public static final int FREM = 114;
  public static final int DREM = 115;
  public static final int INEG = 116;
  public static final int LNEG = 117;
  public static final int FNEG = 118;
  public static final int DNEG = 119;
  public static final int ISHL = 120;
  public static final int LSHL = 121;
  public static final int ISHR = 122;
  public static final int LSHR = 123;
  public static final int IUSHR = 124;
  public static final int LUSHR = 125;
  public static final int IAND = 126;
  public static final int LAND = 127;
  public static final int IOR = 128;
  public static final int LOR = 129;
  public static final int IXOR = 130;
  public static final int LXOR = 131;
  public static final int IINC = 132;
  public static final int I2L = 133;
  public static final int I2F = 134;
  public static final int I2D = 135;
  public static final int L2I = 136;
  public static final int L2F = 137;
  public static final int L2D = 138;
  public static final int F2I = 139;
  public static final int F2L = 140;
  public static final int F2D = 141;
  public static final int D2I = 142;
  public static final int D2L = 143;
  public static final int D2F = 144;
  public static final int I2B = 145;
  public static final int I2C = 146;
  public static final int I2S = 147;
  public static final int LCMP = 148;
  public static final int FCMPL = 149;
  public static final int FCMPG = 150;
  public static final int DCMPL = 151;
  public static final int DCMPG = 152;
  public static final int IFEQ = 153;
  public static final int IFNE = 154;
  public static final int IFLT = 155;
  public static final int IFGE = 156;
  public static final int IFGT = 157;
  public static final int IFLE = 158;
  public static final int IF_ICMPEQ = 159;
  public static final int IF_ICMPNE = 160;
  public static final int IF_ICMPLT = 161;
  public static final int IF_ICMPGE = 162;
  public static final int IF_ICMPGT = 163;
  public static final int IF_ICMPLE = 164;
  public static final int IF_ACMPEQ = 165;
  public static final int IF_ACMPNE = 166;
  public static final int GOTO = 167;
  public static final int JSR = 168;
  public static final int RET = 169;
  public static final int TABLESWITCH = 170;
  public static final int LOOKUPSWITCH = 171;
  public static final int IRETURN = 172;
  public static final int LRETURN = 173;
  public static final int FRETURN = 174;
  public static final int DRETURN = 175;
  public static final int ARETURN = 176;
  public static final int RETURN = 177;
  public static final int GETSTATIC = 178;
  public static final int PUTSTATIC = 179;
  public static final int GETFIELD = 180;
  public static final int PUTFIELD = 181;
  public static final int INVOKEVIRTUAL = 182;
  public static final int INVOKESPECIAL = 183;
  public static final int INVOKESTATIC = 184;
  public static final int INVOKEINTERFACE = 185;
  public static final int NEW = 187;
  public static final int NEWARRAY = 188;
  public static final int ANEWARRAY = 189;
  public static final int ARRAYLENGTH = 190;
  public static final int ATHROW = 191;
  public static final int CHECKCAST = 192;
  public static final int INSTANCEOF = 193;
  public static final int MONITORENTER = 194;
  public static final int MONITOREXIT = 195;
  public static final int WIDE = 196;
  public static final int MULTIANEWARRAY = 197;
  public static final int IFNULL = 198;
  public static final int IFNONNULL = 199;
  public static final int GOTO_W = 200;
  public static final int JSR_W = 201;
  public static final int BREAKPOINT = 202;
  public static final int IMPDEP1 = 254;
  public static final int IMPDEP2 = 255;
  public static final byte T_BOOLEAN = 4;
  public static final byte T_CHAR = 5;
  public static final byte T_FLOAT = 6;
  public static final byte T_DOUBLE = 7;
  public static final byte T_BYTE = 8;
  public static final byte T_SHORT = 9;
  public static final byte T_INT = 10;
  public static final byte T_LONG = 11;
}

/* Location:
 * Qualified Name:     net.sourceforge.htmlunit.corejs.classfile.ByteCode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package net.sourceforge.htmlunit.corejs.classfile;

final class ClassFileField
{
  private short itsNameIndex;
  private short itsTypeIndex;
  private short itsFlags;
  private boolean itsHasAttributes;
  private short itsAttr1;
  private short itsAttr2;
  private short itsAttr3;
  private int itsIndex;
  
  ClassFileField(short nameIndex, short typeIndex, short flags)
  {
    itsNameIndex = nameIndex;
    itsTypeIndex = typeIndex;
    itsFlags = flags;
    itsHasAttributes = false;
  }
  
  void setAttributes(short attr1, short attr2, short attr3, int index)
  {
    itsHasAttributes = true;
    itsAttr1 = attr1;
    itsAttr2 = attr2;
    itsAttr3 = attr3;
    itsIndex = index;
  }
  
  int write(byte[] data, int offset)
  {
    offset = ClassFileWriter.putInt16(itsFlags, data, offset);
    offset = ClassFileWriter.putInt16(itsNameIndex, data, offset);
    offset = ClassFileWriter.putInt16(itsTypeIndex, data, offset);
    if (!itsHasAttributes)
    {
      offset = ClassFileWriter.putInt16(0, data, offset);
    }
    else
    {
      offset = ClassFileWriter.putInt16(1, data, offset);
      offset = ClassFileWriter.putInt16(itsAttr1, data, offset);
      offset = ClassFileWriter.putInt16(itsAttr2, data, offset);
      offset = ClassFileWriter.putInt16(itsAttr3, data, offset);
      offset = ClassFileWriter.putInt16(itsIndex, data, offset);
    }
    return offset;
  }
  
  int getWriteSize()
  {
    int size = 6;
    if (!itsHasAttributes) {
      size += 2;
    } else {
      size += 10;
    }
    return size;
  }
}

/* Location:
 * Qualified Name:     net.sourceforge.htmlunit.corejs.classfile.ClassFileField
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package net.sourceforge.htmlunit.corejs.classfile;

final class ClassFileMethod
{
  private short itsNameIndex;
  private short itsTypeIndex;
  private short itsFlags;
  private byte[] itsCodeAttribute;
  
  ClassFileMethod(short nameIndex, short typeIndex, short flags)
  {
    itsNameIndex = nameIndex;
    itsTypeIndex = typeIndex;
    itsFlags = flags;
  }
  
  void setCodeAttribute(byte[] codeAttribute)
  {
    itsCodeAttribute = codeAttribute;
  }
  
  int write(byte[] data, int offset)
  {
    offset = ClassFileWriter.putInt16(itsFlags, data, offset);
    offset = ClassFileWriter.putInt16(itsNameIndex, data, offset);
    offset = ClassFileWriter.putInt16(itsTypeIndex, data, offset);
    
    offset = ClassFileWriter.putInt16(1, data, offset);
    System.arraycopy(itsCodeAttribute, 0, data, offset, itsCodeAttribute.length);
    
    offset += itsCodeAttribute.length;
    return offset;
  }
  
  int getWriteSize()
  {
    return 8 + itsCodeAttribute.length;
  }
}

/* Location:
 * Qualified Name:     net.sourceforge.htmlunit.corejs.classfile.ClassFileMethod
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package net.sourceforge.htmlunit.corejs.classfile;

public class ClassFileWriter$ClassFileFormatException
  extends RuntimeException
{
  private static final long serialVersionUID = 1263998431033790599L;
  
  ClassFileWriter$ClassFileFormatException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     net.sourceforge.htmlunit.corejs.classfile.ClassFileWriter.ClassFileFormatException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package net.sourceforge.htmlunit.corejs.classfile;

import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.htmlunit.corejs.javascript.ObjArray;

public class ClassFileWriter
{
  public static final short ACC_PUBLIC = 1;
  public static final short ACC_PRIVATE = 2;
  public static final short ACC_PROTECTED = 4;
  public static final short ACC_STATIC = 8;
  public static final short ACC_FINAL = 16;
  public static final short ACC_SYNCHRONIZED = 32;
  public static final short ACC_VOLATILE = 64;
  public static final short ACC_TRANSIENT = 128;
  public static final short ACC_NATIVE = 256;
  public static final short ACC_ABSTRACT = 1024;
  private static final int LineNumberTableSize = 16;
  private static final int ExceptionTableSize = 4;
  private static final long FileHeaderConstant = -3819410108756852691L;
  private static final boolean DEBUGSTACK = false;
  private static final boolean DEBUGLABELS = false;
  private static final boolean DEBUGCODE = false;
  private String generatedClassName;
  private ExceptionTableEntry[] itsExceptionTable;
  private int itsExceptionTableTop;
  private int[] itsLineNumberTable;
  private int itsLineNumberTableTop;
  
  public static class ClassFileFormatException
    extends RuntimeException
  {
    private static final long serialVersionUID = 1263998431033790599L;
    
    ClassFileFormatException(String message)
    {
      super();
    }
  }
  
  public ClassFileWriter(String className, String superClassName, String sourceFileName)
  {
    generatedClassName = className;
    itsConstantPool = new ConstantPool(this);
    itsThisClassIndex = itsConstantPool.addClass(className);
    itsSuperClassIndex = itsConstantPool.addClass(superClassName);
    if (sourceFileName != null) {
      itsSourceFileNameIndex = itsConstantPool.addUtf8(sourceFileName);
    }
    itsFlags = 1;
  }
  
  public final String getClassName()
  {
    return generatedClassName;
  }
  
  public void addInterface(String interfaceName)
  {
    short interfaceIndex = itsConstantPool.addClass(interfaceName);
    itsInterfaces.add(Short.valueOf(interfaceIndex));
  }
  
  public void setFlags(short flags)
  {
    itsFlags = flags;
  }
  
  static String getSlashedForm(String name)
  {
    return name.replace('.', '/');
  }
  
  public static String classNameToSignature(String name)
  {
    int nameLength = name.length();
    int colonPos = 1 + nameLength;
    char[] buf = new char[colonPos + 1];
    buf[0] = 'L';
    buf[colonPos] = ';';
    name.getChars(0, nameLength, buf, 1);
    for (int i = 1; i != colonPos; i++) {
      if (buf[i] == '.') {
        buf[i] = '/';
      }
    }
    return new String(buf, 0, colonPos + 1);
  }
  
  public void addField(String fieldName, String type, short flags)
  {
    short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
    short typeIndex = itsConstantPool.addUtf8(type);
    itsFields.add(new ClassFileField(fieldNameIndex, typeIndex, flags));
  }
  
  public void addField(String fieldName, String type, short flags, int value)
  {
    short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
    short typeIndex = itsConstantPool.addUtf8(type);
    ClassFileField field = new ClassFileField(fieldNameIndex, typeIndex, flags);
    
    field.setAttributes(itsConstantPool.addUtf8("ConstantValue"), (short)0, (short)0, itsConstantPool.addConstant(value));
    
    itsFields.add(field);
  }
  
  public void addField(String fieldName, String type, short flags, long value)
  {
    short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
    short typeIndex = itsConstantPool.addUtf8(type);
    ClassFileField field = new ClassFileField(fieldNameIndex, typeIndex, flags);
    
    field.setAttributes(itsConstantPool.addUtf8("ConstantValue"), (short)0, (short)2, itsConstantPool.addConstant(value));
    
    itsFields.add(field);
  }
  
  public void addField(String fieldName, String type, short flags, double value)
  {
    short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
    short typeIndex = itsConstantPool.addUtf8(type);
    ClassFileField field = new ClassFileField(fieldNameIndex, typeIndex, flags);
    
    field.setAttributes(itsConstantPool.addUtf8("ConstantValue"), (short)0, (short)2, itsConstantPool.addConstant(value));
    
    itsFields.add(field);
  }
  
  public void addVariableDescriptor(String name, String type, int startPC, int register)
  {
    int nameIndex = itsConstantPool.addUtf8(name);
    int descriptorIndex = itsConstantPool.addUtf8(type);
    int[] chunk = { nameIndex, descriptorIndex, startPC, register };
    if (itsVarDescriptors == null) {
      itsVarDescriptors = new ObjArray();
    }
    itsVarDescriptors.add(chunk);
  }
  
  public void startMethod(String methodName, String type, short flags)
  {
    short methodNameIndex = itsConstantPool.addUtf8(methodName);
    short typeIndex = itsConstantPool.addUtf8(type);
    itsCurrentMethod = new ClassFileMethod(methodNameIndex, typeIndex, flags);
    
    itsMethods.add(itsCurrentMethod);
  }
  
  public void stopMethod(short maxLocals)
  {
    if (itsCurrentMethod == null) {
      throw new IllegalStateException("No method to stop");
    }
    fixLabelGotos();
    
    itsMaxLocals = maxLocals;
    
    int lineNumberTableLength = 0;
    if (itsLineNumberTable != null) {
      lineNumberTableLength = 8 + itsLineNumberTableTop * 4;
    }
    int variableTableLength = 0;
    if (itsVarDescriptors != null) {
      variableTableLength = 8 + itsVarDescriptors.size() * 10;
    }
    int attrLength = 14 + itsCodeBufferTop + 2 + itsExceptionTableTop * 8 + 2 + lineNumberTableLength + variableTableLength;
    if (attrLength > 65536) {
      throw new ClassFileFormatException("generated bytecode for method exceeds 64K limit.");
    }
    byte[] codeAttribute = new byte[attrLength];
    int index = 0;
    int codeAttrIndex = itsConstantPool.addUtf8("Code");
    index = putInt16(codeAttrIndex, codeAttribute, index);
    attrLength -= 6;
    index = putInt32(attrLength, codeAttribute, index);
    index = putInt16(itsMaxStack, codeAttribute, index);
    index = putInt16(itsMaxLocals, codeAttribute, index);
    index = putInt32(itsCodeBufferTop, codeAttribute, index);
    System.arraycopy(itsCodeBuffer, 0, codeAttribute, index, itsCodeBufferTop);
    
    index += itsCodeBufferTop;
    if (itsExceptionTableTop > 0)
    {
      index = putInt16(itsExceptionTableTop, codeAttribute, index);
      for (int i = 0; i < itsExceptionTableTop; i++)
      {
        ExceptionTableEntry ete = itsExceptionTable[i];
        short startPC = (short)getLabelPC(itsStartLabel);
        short endPC = (short)getLabelPC(itsEndLabel);
        short handlerPC = (short)getLabelPC(itsHandlerLabel);
        short catchType = itsCatchType;
        if (startPC == -1) {
          throw new IllegalStateException("start label not defined");
        }
        if (endPC == -1) {
          throw new IllegalStateException("end label not defined");
        }
        if (handlerPC == -1) {
          throw new IllegalStateException("handler label not defined");
        }
        index = putInt16(startPC, codeAttribute, index);
        index = putInt16(endPC, codeAttribute, index);
        index = putInt16(handlerPC, codeAttribute, index);
        index = putInt16(catchType, codeAttribute, index);
      }
    }
    else
    {
      index = putInt16(0, codeAttribute, index);
    }
    int attributeCount = 0;
    if (itsLineNumberTable != null) {
      attributeCount++;
    }
    if (itsVarDescriptors != null) {
      attributeCount++;
    }
    index = putInt16(attributeCount, codeAttribute, index);
    if (itsLineNumberTable != null)
    {
      int lineNumberTableAttrIndex = itsConstantPool.addUtf8("LineNumberTable");
      
      index = putInt16(lineNumberTableAttrIndex, codeAttribute, index);
      int tableAttrLength = 2 + itsLineNumberTableTop * 4;
      index = putInt32(tableAttrLength, codeAttribute, index);
      index = putInt16(itsLineNumberTableTop, codeAttribute, index);
      for (int i = 0; i < itsLineNumberTableTop; i++) {
        index = putInt32(itsLineNumberTable[i], codeAttribute, index);
      }
    }
    if (itsVarDescriptors != null)
    {
      int variableTableAttrIndex = itsConstantPool.addUtf8("LocalVariableTable");
      
      index = putInt16(variableTableAttrIndex, codeAttribute, index);
      int varCount = itsVarDescriptors.size();
      int tableAttrLength = 2 + varCount * 10;
      index = putInt32(tableAttrLength, codeAttribute, index);
      index = putInt16(varCount, codeAttribute, index);
      for (int i = 0; i < varCount; i++)
      {
        int[] chunk = (int[])itsVarDescriptors.get(i);
        int nameIndex = chunk[0];
        int descriptorIndex = chunk[1];
        int startPC = chunk[2];
        int register = chunk[3];
        int length = itsCodeBufferTop - startPC;
        
        index = putInt16(startPC, codeAttribute, index);
        index = putInt16(length, codeAttribute, index);
        index = putInt16(nameIndex, codeAttribute, index);
        index = putInt16(descriptorIndex, codeAttribute, index);
        index = putInt16(register, codeAttribute, index);
      }
    }
    itsCurrentMethod.setCodeAttribute(codeAttribute);
    
    itsExceptionTable = null;
    itsExceptionTableTop = 0;
    itsLineNumberTableTop = 0;
    itsCodeBufferTop = 0;
    itsCurrentMethod = null;
    itsMaxStack = 0;
    itsStackTop = 0;
    itsLabelTableTop = 0;
    itsFixupTableTop = 0;
    itsVarDescriptors = null;
  }
  
  public void add(int theOpCode)
  {
    if (opcodeCount(theOpCode) != 0) {
      throw new IllegalArgumentException("Unexpected operands");
    }
    int newStack = itsStackTop + stackChange(theOpCode);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    addToCodeBuffer(theOpCode);
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void add(int theOpCode, int theOperand)
  {
    int newStack = itsStackTop + stackChange(theOpCode);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    switch (theOpCode)
    {
    case 153: 
    case 154: 
    case 155: 
    case 156: 
    case 157: 
    case 158: 
    case 159: 
    case 160: 
    case 161: 
    case 162: 
    case 163: 
    case 164: 
    case 165: 
    case 166: 
    case 167: 
    case 168: 
    case 198: 
    case 199: 
      if (((theOperand & 0x80000000) != Integer.MIN_VALUE) && (
        (theOperand < 0) || (theOperand > 65535))) {
        throw new IllegalArgumentException("Bad label for branch");
      }
      int branchPC = itsCodeBufferTop;
      addToCodeBuffer(theOpCode);
      if ((theOperand & 0x80000000) != Integer.MIN_VALUE)
      {
        addToCodeInt16(theOperand);
      }
      else
      {
        int targetPC = getLabelPC(theOperand);
        if (targetPC != -1)
        {
          int offset = targetPC - branchPC;
          addToCodeInt16(offset);
        }
        else
        {
          addLabelFixup(theOperand, branchPC + 1);
          addToCodeInt16(0);
        }
      }
      break;
    case 16: 
      if ((byte)theOperand != theOperand) {
        throw new IllegalArgumentException("out of range byte");
      }
      addToCodeBuffer(theOpCode);
      addToCodeBuffer((byte)theOperand);
      break;
    case 17: 
      if ((short)theOperand != theOperand) {
        throw new IllegalArgumentException("out of range short");
      }
      addToCodeBuffer(theOpCode);
      addToCodeInt16(theOperand);
      break;
    case 188: 
      if ((0 > theOperand) || (theOperand >= 256)) {
        throw new IllegalArgumentException("out of range index");
      }
      addToCodeBuffer(theOpCode);
      addToCodeBuffer(theOperand);
      break;
    case 180: 
    case 181: 
      if ((0 > theOperand) || (theOperand >= 65536)) {
        throw new IllegalArgumentException("out of range field");
      }
      addToCodeBuffer(theOpCode);
      addToCodeInt16(theOperand);
      break;
    case 18: 
    case 19: 
    case 20: 
      if ((0 > theOperand) || (theOperand >= 65536)) {
        throw new IllegalArgumentException("out of range index");
      }
      if ((theOperand >= 256) || (theOpCode == 19) || (theOpCode == 20))
      {
        if (theOpCode == 18) {
          addToCodeBuffer(19);
        } else {
          addToCodeBuffer(theOpCode);
        }
        addToCodeInt16(theOperand);
      }
      else
      {
        addToCodeBuffer(theOpCode);
        addToCodeBuffer(theOperand);
      }
      break;
    case 21: 
    case 22: 
    case 23: 
    case 24: 
    case 25: 
    case 54: 
    case 55: 
    case 56: 
    case 57: 
    case 58: 
    case 169: 
      if ((0 > theOperand) || (theOperand >= 65536)) {
        throw new ClassFileFormatException("out of range variable");
      }
      if (theOperand >= 256)
      {
        addToCodeBuffer(196);
        addToCodeBuffer(theOpCode);
        addToCodeInt16(theOperand);
      }
      else
      {
        addToCodeBuffer(theOpCode);
        addToCodeBuffer(theOperand);
      }
      break;
    default: 
      throw new IllegalArgumentException("Unexpected opcode for 1 operand");
    }
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void addLoadConstant(int k)
  {
    switch (k)
    {
    case 0: 
      add(3); break;
    case 1: 
      add(4); break;
    case 2: 
      add(5); break;
    case 3: 
      add(6); break;
    case 4: 
      add(7); break;
    case 5: 
      add(8); break;
    default: 
      add(18, itsConstantPool.addConstant(k));
    }
  }
  
  public void addLoadConstant(long k)
  {
    add(20, itsConstantPool.addConstant(k));
  }
  
  public void addLoadConstant(float k)
  {
    add(18, itsConstantPool.addConstant(k));
  }
  
  public void addLoadConstant(double k)
  {
    add(20, itsConstantPool.addConstant(k));
  }
  
  public void addLoadConstant(String k)
  {
    add(18, itsConstantPool.addConstant(k));
  }
  
  public void add(int theOpCode, int theOperand1, int theOperand2)
  {
    int newStack = itsStackTop + stackChange(theOpCode);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    if (theOpCode == 132)
    {
      if ((0 > theOperand1) || (theOperand1 >= 65536)) {
        throw new ClassFileFormatException("out of range variable");
      }
      if ((0 > theOperand2) || (theOperand2 >= 65536)) {
        throw new ClassFileFormatException("out of range increment");
      }
      if ((theOperand1 > 255) || (theOperand2 < -128) || (theOperand2 > 127))
      {
        addToCodeBuffer(196);
        addToCodeBuffer(132);
        addToCodeInt16(theOperand1);
        addToCodeInt16(theOperand2);
      }
      else
      {
        addToCodeBuffer(132);
        addToCodeBuffer(theOperand1);
        addToCodeBuffer(theOperand2);
      }
    }
    else if (theOpCode == 197)
    {
      if ((0 > theOperand1) || (theOperand1 >= 65536)) {
        throw new IllegalArgumentException("out of range index");
      }
      if ((0 > theOperand2) || (theOperand2 >= 256)) {
        throw new IllegalArgumentException("out of range dimensions");
      }
      addToCodeBuffer(197);
      addToCodeInt16(theOperand1);
      addToCodeBuffer(theOperand2);
    }
    else
    {
      throw new IllegalArgumentException("Unexpected opcode for 2 operands");
    }
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void add(int theOpCode, String className)
  {
    int newStack = itsStackTop + stackChange(theOpCode);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    switch (theOpCode)
    {
    case 187: 
    case 189: 
    case 192: 
    case 193: 
      short classIndex = itsConstantPool.addClass(className);
      addToCodeBuffer(theOpCode);
      addToCodeInt16(classIndex);
      
      break;
    case 188: 
    case 190: 
    case 191: 
    default: 
      throw new IllegalArgumentException("bad opcode for class reference");
    }
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void add(int theOpCode, String className, String fieldName, String fieldType)
  {
    int newStack = itsStackTop + stackChange(theOpCode);
    char fieldTypeChar = fieldType.charAt(0);
    int fieldSize = (fieldTypeChar == 'J') || (fieldTypeChar == 'D') ? 2 : 1;
    switch (theOpCode)
    {
    case 178: 
    case 180: 
      newStack += fieldSize;
      break;
    case 179: 
    case 181: 
      newStack -= fieldSize;
      break;
    default: 
      throw new IllegalArgumentException("bad opcode for field reference");
    }
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    short fieldRefIndex = itsConstantPool.addFieldRef(className, fieldName, fieldType);
    
    addToCodeBuffer(theOpCode);
    addToCodeInt16(fieldRefIndex);
    
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void addInvoke(int theOpCode, String className, String methodName, String methodType)
  {
    int parameterInfo = sizeOfParameters(methodType);
    int parameterCount = parameterInfo >>> 16;
    int stackDiff = (short)parameterInfo;
    
    int newStack = itsStackTop + stackDiff;
    newStack += stackChange(theOpCode);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    switch (theOpCode)
    {
    case 182: 
    case 183: 
    case 184: 
    case 185: 
      addToCodeBuffer(theOpCode);
      if (theOpCode == 185)
      {
        short ifMethodRefIndex = itsConstantPool.addInterfaceMethodRef(className, methodName, methodType);
        
        addToCodeInt16(ifMethodRefIndex);
        addToCodeBuffer(parameterCount + 1);
        addToCodeBuffer(0);
      }
      else
      {
        short methodRefIndex = itsConstantPool.addMethodRef(className, methodName, methodType);
        
        addToCodeInt16(methodRefIndex);
      }
      break;
    default: 
      throw new IllegalArgumentException("bad opcode for method reference");
    }
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  public void addPush(int k)
  {
    if ((byte)k == k)
    {
      if (k == -1) {
        add(2);
      } else if ((0 <= k) && (k <= 5)) {
        add((byte)(3 + k));
      } else {
        add(16, (byte)k);
      }
    }
    else if ((short)k == k) {
      add(17, (short)k);
    } else {
      addLoadConstant(k);
    }
  }
  
  public void addPush(boolean k)
  {
    add(k ? 4 : 3);
  }
  
  public void addPush(long k)
  {
    int ik = (int)k;
    if (ik == k)
    {
      addPush(ik);
      add(133);
    }
    else
    {
      addLoadConstant(k);
    }
  }
  
  public void addPush(double k)
  {
    if (k == 0.0D)
    {
      add(14);
      if (1.0D / k < 0.0D) {
        add(119);
      }
    }
    else if ((k == 1.0D) || (k == -1.0D))
    {
      add(15);
      if (k < 0.0D) {
        add(119);
      }
    }
    else
    {
      addLoadConstant(k);
    }
  }
  
  public void addPush(String k)
  {
    int length = k.length();
    int limit = itsConstantPool.getUtfEncodingLimit(k, 0, length);
    if (limit == length)
    {
      addLoadConstant(k);
      return;
    }
    String SB = "java/lang/StringBuffer";
    add(187, "java/lang/StringBuffer");
    add(89);
    addPush(length);
    addInvoke(183, "java/lang/StringBuffer", "<init>", "(I)V");
    int cursor = 0;
    for (;;)
    {
      add(89);
      String s = k.substring(cursor, limit);
      addLoadConstant(s);
      addInvoke(182, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
      
      add(87);
      if (limit == length) {
        break;
      }
      cursor = limit;
      limit = itsConstantPool.getUtfEncodingLimit(k, limit, length);
    }
    addInvoke(182, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
  }
  
  public boolean isUnderStringSizeLimit(String k)
  {
    return itsConstantPool.isUnderUtfEncodingLimit(k);
  }
  
  public void addIStore(int local)
  {
    xop(59, 54, local);
  }
  
  public void addLStore(int local)
  {
    xop(63, 55, local);
  }
  
  public void addFStore(int local)
  {
    xop(67, 56, local);
  }
  
  public void addDStore(int local)
  {
    xop(71, 57, local);
  }
  
  public void addAStore(int local)
  {
    xop(75, 58, local);
  }
  
  public void addILoad(int local)
  {
    xop(26, 21, local);
  }
  
  public void addLLoad(int local)
  {
    xop(30, 22, local);
  }
  
  public void addFLoad(int local)
  {
    xop(34, 23, local);
  }
  
  public void addDLoad(int local)
  {
    xop(38, 24, local);
  }
  
  public void addALoad(int local)
  {
    xop(42, 25, local);
  }
  
  public void addLoadThis()
  {
    add(42);
  }
  
  private void xop(int shortOp, int op, int local)
  {
    switch (local)
    {
    case 0: 
      add(shortOp);
      break;
    case 1: 
      add(shortOp + 1);
      break;
    case 2: 
      add(shortOp + 2);
      break;
    case 3: 
      add(shortOp + 3);
      break;
    default: 
      add(op, local);
    }
  }
  
  public int addTableSwitch(int low, int high)
  {
    if (low > high) {
      throw new ClassFileFormatException("Bad bounds: " + low + ' ' + high);
    }
    int newStack = itsStackTop + stackChange(170);
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    int entryCount = high - low + 1;
    int padSize = 0x3 & (itsCodeBufferTop ^ 0xFFFFFFFF);
    
    int N = addReservedCodeSpace(1 + padSize + 4 * (3 + entryCount));
    int switchStart = N;
    itsCodeBuffer[(N++)] = -86;
    while (padSize != 0)
    {
      itsCodeBuffer[(N++)] = 0;
      padSize--;
    }
    N += 4;
    N = putInt32(low, itsCodeBuffer, N);
    putInt32(high, itsCodeBuffer, N);
    
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
    return switchStart;
  }
  
  public final void markTableSwitchDefault(int switchStart)
  {
    setTableSwitchJump(switchStart, -1, itsCodeBufferTop);
  }
  
  public final void markTableSwitchCase(int switchStart, int caseIndex)
  {
    setTableSwitchJump(switchStart, caseIndex, itsCodeBufferTop);
  }
  
  public final void markTableSwitchCase(int switchStart, int caseIndex, int stackTop)
  {
    if ((0 > stackTop) || (stackTop > itsMaxStack)) {
      throw new IllegalArgumentException("Bad stack index: " + stackTop);
    }
    itsStackTop = ((short)stackTop);
    setTableSwitchJump(switchStart, caseIndex, itsCodeBufferTop);
  }
  
  public void setTableSwitchJump(int switchStart, int caseIndex, int jumpTarget)
  {
    if ((0 > jumpTarget) || (jumpTarget > itsCodeBufferTop)) {
      throw new IllegalArgumentException("Bad jump target: " + jumpTarget);
    }
    if (caseIndex < -1) {
      throw new IllegalArgumentException("Bad case index: " + caseIndex);
    }
    int padSize = 0x3 & (switchStart ^ 0xFFFFFFFF);
    int caseOffset;
    int caseOffset;
    if (caseIndex < 0) {
      caseOffset = switchStart + 1 + padSize;
    } else {
      caseOffset = switchStart + 1 + padSize + 4 * (3 + caseIndex);
    }
    if ((0 > switchStart) || (switchStart > itsCodeBufferTop - 16 - padSize - 1)) {
      throw new IllegalArgumentException(switchStart + " is outside a possible range of tableswitch" + " in already generated code");
    }
    if ((0xFF & itsCodeBuffer[switchStart]) != 170) {
      throw new IllegalArgumentException(switchStart + " is not offset of tableswitch statement");
    }
    if ((0 > caseOffset) || (caseOffset + 4 > itsCodeBufferTop)) {
      throw new ClassFileFormatException("Too big case index: " + caseIndex);
    }
    putInt32(jumpTarget - switchStart, itsCodeBuffer, caseOffset);
  }
  
  public int acquireLabel()
  {
    int top = itsLabelTableTop;
    if ((itsLabelTable == null) || (top == itsLabelTable.length)) {
      if (itsLabelTable == null)
      {
        itsLabelTable = new int[32];
      }
      else
      {
        int[] tmp = new int[itsLabelTable.length * 2];
        System.arraycopy(itsLabelTable, 0, tmp, 0, top);
        itsLabelTable = tmp;
      }
    }
    itsLabelTableTop = (top + 1);
    itsLabelTable[top] = -1;
    return top | 0x80000000;
  }
  
  public void markLabel(int label)
  {
    if (label >= 0) {
      throw new IllegalArgumentException("Bad label, no biscuit");
    }
    label &= 0x7FFFFFFF;
    if (label > itsLabelTableTop) {
      throw new IllegalArgumentException("Bad label");
    }
    if (itsLabelTable[label] != -1) {
      throw new IllegalStateException("Can only mark label once");
    }
    itsLabelTable[label] = itsCodeBufferTop;
  }
  
  public void markLabel(int label, short stackTop)
  {
    markLabel(label);
    itsStackTop = stackTop;
  }
  
  public void markHandler(int theLabel)
  {
    itsStackTop = 1;
    markLabel(theLabel);
  }
  
  private int getLabelPC(int label)
  {
    if (label >= 0) {
      throw new IllegalArgumentException("Bad label, no biscuit");
    }
    label &= 0x7FFFFFFF;
    if (label >= itsLabelTableTop) {
      throw new IllegalArgumentException("Bad label");
    }
    return itsLabelTable[label];
  }
  
  private void addLabelFixup(int label, int fixupSite)
  {
    if (label >= 0) {
      throw new IllegalArgumentException("Bad label, no biscuit");
    }
    label &= 0x7FFFFFFF;
    if (label >= itsLabelTableTop) {
      throw new IllegalArgumentException("Bad label");
    }
    int top = itsFixupTableTop;
    if ((itsFixupTable == null) || (top == itsFixupTable.length)) {
      if (itsFixupTable == null)
      {
        itsFixupTable = new long[40];
      }
      else
      {
        long[] tmp = new long[itsFixupTable.length * 2];
        System.arraycopy(itsFixupTable, 0, tmp, 0, top);
        itsFixupTable = tmp;
      }
    }
    itsFixupTableTop = (top + 1);
    itsFixupTable[top] = (label << 32 | fixupSite);
  }
  
  private void fixLabelGotos()
  {
    byte[] codeBuffer = itsCodeBuffer;
    for (int i = 0; i < itsFixupTableTop; i++)
    {
      long fixup = itsFixupTable[i];
      int label = (int)(fixup >> 32);
      int fixupSite = (int)fixup;
      int pc = itsLabelTable[label];
      if (pc == -1) {
        throw new RuntimeException();
      }
      int offset = pc - (fixupSite - 1);
      if ((short)offset != offset) {
        throw new ClassFileFormatException("Program too complex: too big jump offset");
      }
      codeBuffer[fixupSite] = ((byte)(offset >> 8));
      codeBuffer[(fixupSite + 1)] = ((byte)offset);
    }
    itsFixupTableTop = 0;
  }
  
  public int getCurrentCodeOffset()
  {
    return itsCodeBufferTop;
  }
  
  public short getStackTop()
  {
    return itsStackTop;
  }
  
  public void setStackTop(short n)
  {
    itsStackTop = n;
  }
  
  public void adjustStackTop(int delta)
  {
    int newStack = itsStackTop + delta;
    if ((newStack < 0) || (32767 < newStack)) {
      badStack(newStack);
    }
    itsStackTop = ((short)newStack);
    if (newStack > itsMaxStack) {
      itsMaxStack = ((short)newStack);
    }
  }
  
  private void addToCodeBuffer(int b)
  {
    int N = addReservedCodeSpace(1);
    itsCodeBuffer[N] = ((byte)b);
  }
  
  private void addToCodeInt16(int value)
  {
    int N = addReservedCodeSpace(2);
    putInt16(value, itsCodeBuffer, N);
  }
  
  private int addReservedCodeSpace(int size)
  {
    if (itsCurrentMethod == null) {
      throw new IllegalArgumentException("No method to add to");
    }
    int oldTop = itsCodeBufferTop;
    int newTop = oldTop + size;
    if (newTop > itsCodeBuffer.length)
    {
      int newSize = itsCodeBuffer.length * 2;
      if (newTop > newSize) {
        newSize = newTop;
      }
      byte[] tmp = new byte[ne
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd