com.sun.org.apache.bcel.internal.Constants Java Examples
The following examples show how to use
com.sun.org.apache.bcel.internal.Constants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstructionFactory.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * @param index index of local variable */ public static LocalVariableInstruction createLoad(Type type, int index) { switch(type.getType()) { case Constants.T_BOOLEAN: case Constants.T_CHAR: case Constants.T_BYTE: case Constants.T_SHORT: case Constants.T_INT: return new ILOAD(index); case Constants.T_FLOAT: return new FLOAD(index); case Constants.T_DOUBLE: return new DLOAD(index); case Constants.T_LONG: return new LLOAD(index); case Constants.T_ARRAY: case Constants.T_OBJECT: return new ALOAD(index); default: throw new RuntimeException("Invalid type " + type); } }
Example #2
Source File: Utility.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Return type of signature as a byte value as defined in <em>Constants</em> * * @param signature in format described above * @return type of signature * @see Constants */ public static final byte typeOfSignature(String signature) throws ClassFormatException { try { switch(signature.charAt(0)) { case 'B' : return Constants.T_BYTE; case 'C' : return Constants.T_CHAR; case 'D' : return Constants.T_DOUBLE; case 'F' : return Constants.T_FLOAT; case 'I' : return Constants.T_INT; case 'J' : return Constants.T_LONG; case 'L' : return Constants.T_REFERENCE; case '[' : return Constants.T_ARRAY; case 'V' : return Constants.T_VOID; case 'Z' : return Constants.T_BOOLEAN; case 'S' : return Constants.T_SHORT; default: throw new ClassFormatException("Invalid method signature: " + signature); } } catch(StringIndexOutOfBoundsException e) { throw new ClassFormatException("Invalid method signature: " + signature); } }
Example #3
Source File: BCELifier.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static String printType(String signature) { Type type = Type.getType(signature); byte t = type.getType(); if(t <= Constants.T_VOID) { return "Type." + Constants.TYPE_NAMES[t].toUpperCase(); } else if(type.toString().equals("java.lang.String")) { return "Type.STRING"; } else if(type.toString().equals("java.lang.Object")) { return "Type.OBJECT"; } else if(type.toString().equals("java.lang.StringBuffer")) { return "Type.STRINGBUFFER"; } else if(type instanceof ArrayType) { ArrayType at = (ArrayType)type; return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions() + ")"; } else { return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")"; } }
Example #4
Source File: InstructionFactory.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * @param type type of elements of array, i.e., array.getElementType() */ public static ArrayInstruction createArrayStore(Type type) { switch(type.getType()) { case Constants.T_BOOLEAN: case Constants.T_BYTE: return BASTORE; case Constants.T_CHAR: return CASTORE; case Constants.T_SHORT: return SASTORE; case Constants.T_INT: return IASTORE; case Constants.T_FLOAT: return FASTORE; case Constants.T_DOUBLE: return DASTORE; case Constants.T_LONG: return LASTORE; case Constants.T_ARRAY: case Constants.T_OBJECT: return AASTORE; default: throw new RuntimeException("Invalid type " + type); } }
Example #5
Source File: ConstantPool.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Get constant from constant pool and check whether it has the * expected type. * * @param index Index in constant pool * @param tag Tag of expected constant, i.e., its type * @return Constant value * @see Constant * @throws ClassFormatException */ public Constant getConstant(int index, byte tag) throws ClassFormatException { Constant c; c = getConstant(index); if(c == null) throw new ClassFormatException("Constant pool at index " + index + " is null."); if(c.getTag() == tag) return c; else throw new ClassFormatException("Expected class `" + Constants.CONSTANT_NAMES[tag] + "' at index " + index + " and got " + c); }
Example #6
Source File: ConstantPool.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Read constants from given file stream. * * @param file Input stream * @throws IOException * @throws ClassFormatException */ ConstantPool(DataInputStream file) throws IOException, ClassFormatException { byte tag; constant_pool_count = file.readUnsignedShort(); constant_pool = new Constant[constant_pool_count]; /* constant_pool[0] is unused by the compiler and may be used freely * by the implementation. */ for(int i=1; i < constant_pool_count; i++) { constant_pool[i] = Constant.readConstant(file); /* Quote from the JVM specification: * "All eight byte constants take up two spots in the constant pool. * If this is the n'th byte in the constant pool, then the next item * will be numbered n+2" * * Thus we have to increment the index counter. */ tag = constant_pool[i].getTag(); if((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long)) i++; } }
Example #7
Source File: ConstantValue.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * @return String representation of constant value. */ public final String toString() { Constant c = constant_pool.getConstant(constantvalue_index); String buf; int i; // Print constant to string depending on its type switch(c.getTag()) { case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break; case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8); buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; break; default: throw new IllegalStateException("Type of ConstValue invalid: " + c); } return buf; }
Example #8
Source File: LocalVariableInstruction.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Returns the type associated with the instruction - * in case of ALOAD or ASTORE Type.OBJECT is returned. * This is just a bit incorrect, because ALOAD and ASTORE * may work on every ReferenceType (including Type.NULL) and * ASTORE may even work on a ReturnaddressType . * @return type associated with the instruction */ public Type getType(ConstantPoolGen cp) { switch(canon_tag) { case Constants.ILOAD: case Constants.ISTORE: return Type.INT; case Constants.LLOAD: case Constants.LSTORE: return Type.LONG; case Constants.DLOAD: case Constants.DSTORE: return Type.DOUBLE; case Constants.FLOAD: case Constants.FSTORE: return Type.FLOAT; case Constants.ALOAD: case Constants.ASTORE: return Type.OBJECT; default: throw new ClassGenException("Oops: unknown case in switch" + canon_tag); } }
Example #9
Source File: ConversionInstruction.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** @return type associated with the instruction */ public Type getType(ConstantPoolGen cp) { switch(opcode) { case Constants.D2I: case Constants.F2I: case Constants.L2I: return Type.INT; case Constants.D2F: case Constants.I2F: case Constants.L2F: return Type.FLOAT; case Constants.D2L: case Constants.F2L: case Constants.I2L: return Type.LONG; case Constants.F2D: case Constants.I2D: case Constants.L2D: return Type.DOUBLE; case Constants.I2B: return Type.BYTE; case Constants.I2C: return Type.CHAR; case Constants.I2S: return Type.SHORT; default: // Never reached throw new ClassGenException("Unknown type " + opcode); } }
Example #10
Source File: BasicType.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static final BasicType getType(byte type) { switch(type) { case Constants.T_VOID: return VOID; case Constants.T_BOOLEAN: return BOOLEAN; case Constants.T_BYTE: return BYTE; case Constants.T_SHORT: return SHORT; case Constants.T_CHAR: return CHAR; case Constants.T_INT: return INT; case Constants.T_LONG: return LONG; case Constants.T_DOUBLE: return DOUBLE; case Constants.T_FLOAT: return FLOAT; default: throw new ClassGenException("Invalid type: " + type); } }
Example #11
Source File: BCELifier.java From hottub with GNU General Public License v2.0 | 6 votes |
static String printType(String signature) { Type type = Type.getType(signature); byte t = type.getType(); if(t <= Constants.T_VOID) { return "Type." + Constants.TYPE_NAMES[t].toUpperCase(); } else if(type.toString().equals("java.lang.String")) { return "Type.STRING"; } else if(type.toString().equals("java.lang.Object")) { return "Type.OBJECT"; } else if(type.toString().equals("java.lang.StringBuffer")) { return "Type.STRINGBUFFER"; } else if(type instanceof ArrayType) { ArrayType at = (ArrayType)type; return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions() + ")"; } else { return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")"; } }
Example #12
Source File: InstructionFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. * For those you should use the SWITCH compound instruction. */ public static BranchInstruction createBranchInstruction(short opcode, InstructionHandle target) { switch(opcode) { case Constants.IFEQ: return new IFEQ(target); case Constants.IFNE: return new IFNE(target); case Constants.IFLT: return new IFLT(target); case Constants.IFGE: return new IFGE(target); case Constants.IFGT: return new IFGT(target); case Constants.IFLE: return new IFLE(target); case Constants.IF_ICMPEQ: return new IF_ICMPEQ(target); case Constants.IF_ICMPNE: return new IF_ICMPNE(target); case Constants.IF_ICMPLT: return new IF_ICMPLT(target); case Constants.IF_ICMPGE: return new IF_ICMPGE(target); case Constants.IF_ICMPGT: return new IF_ICMPGT(target); case Constants.IF_ICMPLE: return new IF_ICMPLE(target); case Constants.IF_ACMPEQ: return new IF_ACMPEQ(target); case Constants.IF_ACMPNE: return new IF_ACMPNE(target); case Constants.GOTO: return new GOTO(target); case Constants.JSR: return new JSR(target); case Constants.IFNULL: return new IFNULL(target); case Constants.IFNONNULL: return new IFNONNULL(target); case Constants.GOTO_W: return new GOTO_W(target); case Constants.JSR_W: return new JSR_W(target); default: throw new RuntimeException("Invalid opcode: " + opcode); } }
Example #13
Source File: ArithmeticInstruction.java From hottub with GNU General Public License v2.0 | 5 votes |
/** @return type associated with the instruction */ public Type getType(ConstantPoolGen cp) { switch(opcode) { case Constants.DADD: case Constants.DDIV: case Constants.DMUL: case Constants.DNEG: case Constants.DREM: case Constants.DSUB: return Type.DOUBLE; case Constants.FADD: case Constants.FDIV: case Constants.FMUL: case Constants.FNEG: case Constants.FREM: case Constants.FSUB: return Type.FLOAT; case Constants.IADD: case Constants.IAND: case Constants.IDIV: case Constants.IMUL: case Constants.INEG: case Constants.IOR: case Constants.IREM: case Constants.ISHL: case Constants.ISHR: case Constants.ISUB: case Constants.IUSHR: case Constants.IXOR: return Type.INT; case Constants.LADD: case Constants.LAND: case Constants.LDIV: case Constants.LMUL: case Constants.LNEG: case Constants.LOR: case Constants.LREM: case Constants.LSHL: case Constants.LSHR: case Constants.LSUB: case Constants.LUSHR: case Constants.LXOR: return Type.LONG; default: // Never reached throw new ClassGenException("Unknown type " + opcode); } }
Example #14
Source File: BCELFactory.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void visitArrayInstruction(ArrayInstruction i) { short opcode = i.getOpcode(); Type type = i.getType(_cp); String kind = (opcode < Constants.IASTORE)? "Load" : "Store"; _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type) + "));"); }
Example #15
Source File: ConstantUtf8.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * @param bytes Data */ public ConstantUtf8(String bytes) { super(Constants.CONSTANT_Utf8); if(bytes == null) throw new IllegalArgumentException("bytes must not be null!"); this.bytes = bytes; }
Example #16
Source File: StackMap.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) { super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool); setStackMap(map); }
Example #17
Source File: ConstantValue.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * @param name_index Name index in constant pool * @param length Content length in bytes * @param constantvalue_index Index in constant pool * @param constant_pool Array of constants */ public ConstantValue(int name_index, int length, int constantvalue_index, ConstantPool constant_pool) { super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool); this.constantvalue_index = constantvalue_index; }
Example #18
Source File: BCELFactory.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public void visitLocalVariableInstruction(LocalVariableInstruction i) { short opcode = i.getOpcode(); Type type = i.getType(_cp); if(opcode == Constants.IINC) { _out.println("il.append(new IINC(" + i.getIndex() + ", " + ((IINC)i).getIncrement() + "));"); } else { String kind = (opcode < Constants.ISTORE)? "Load" : "Store"; _out.println("il.append(_factory.create" + kind + "(" + BCELifier.printType(type) + ", " + i.getIndex() + "));"); } }
Example #19
Source File: InstructionFactory.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. * For those you should use the SWITCH compound instruction. */ public static BranchInstruction createBranchInstruction(short opcode, InstructionHandle target) { switch(opcode) { case Constants.IFEQ: return new IFEQ(target); case Constants.IFNE: return new IFNE(target); case Constants.IFLT: return new IFLT(target); case Constants.IFGE: return new IFGE(target); case Constants.IFGT: return new IFGT(target); case Constants.IFLE: return new IFLE(target); case Constants.IF_ICMPEQ: return new IF_ICMPEQ(target); case Constants.IF_ICMPNE: return new IF_ICMPNE(target); case Constants.IF_ICMPLT: return new IF_ICMPLT(target); case Constants.IF_ICMPGE: return new IF_ICMPGE(target); case Constants.IF_ICMPGT: return new IF_ICMPGT(target); case Constants.IF_ICMPLE: return new IF_ICMPLE(target); case Constants.IF_ACMPEQ: return new IF_ACMPEQ(target); case Constants.IF_ACMPNE: return new IF_ACMPNE(target); case Constants.GOTO: return new GOTO(target); case Constants.JSR: return new JSR(target); case Constants.IFNULL: return new IFNULL(target); case Constants.IFNONNULL: return new IFNONNULL(target); case Constants.GOTO_W: return new GOTO_W(target); case Constants.JSR_W: return new JSR_W(target); default: throw new RuntimeException("Invalid opcode: " + opcode); } }
Example #20
Source File: MethodGen.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Adds a local variable type to this method. * * @param name variable name * @param type variable type * @param slot the index of the local variable, if type is long or double, the next available * index is slot+2 * @param start from where the variable is valid * @param end until where the variable is valid * @return new local variable object * @see LocalVariable */ private LocalVariableGen addLocalVariableType(String name, Type type, int slot, InstructionHandle start, InstructionHandle end) { byte t = type.getType(); if(t != Constants.T_ADDRESS) { int add = type.getSize(); if(slot + add > max_locals) max_locals = slot + add; LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end); int i; if((i = type_vec.indexOf(l)) >= 0) // Overwrite if necessary type_vec.set(i, l); else type_vec.add(l); return l; } else { throw new IllegalArgumentException("Can not use " + type + " as type for local variable"); } }
Example #21
Source File: InstructionFinder.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Map symbolic instruction names like "getfield" to a single character. * * @param pattern instruction pattern in lower case * @return encoded string for a pattern such as "BranchInstruction". */ private static final String mapName(String pattern) { String result = (String)map.get(pattern); if(result != null) return result; for(short i=0; i < NO_OPCODES; i++) if(pattern.equals(Constants.OPCODE_NAMES[i])) return "" + makeChar(i); throw new RuntimeException("Instruction unknown: " + pattern); }
Example #22
Source File: ConstantUtf8.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Initialize instance from file data. * * @param file Input stream * @throws IOException */ ConstantUtf8(DataInputStream file) throws IOException { super(Constants.CONSTANT_Utf8); bytes = file.readUTF(); }
Example #23
Source File: LocalVariableInstruction.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Dump instruction as byte code to stream out. * @param out Output stream */ public void dump(DataOutputStream out) throws IOException { if(wide()) // Need WIDE prefix ? out.writeByte(Constants.WIDE); out.writeByte(opcode); if(length > 1) { // Otherwise ILOAD_n, instruction, e.g. if(wide()) out.writeShort(n); else out.writeByte(n); } }
Example #24
Source File: PMGClass.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * @param name_index Index in constant pool to CONSTANT_Utf8 * @param length Content length in bytes * @param constant_pool Array of constants * @param PMGClass_index Index in constant pool to CONSTANT_Utf8 */ public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, ConstantPool constant_pool) { super(Constants.ATTR_PMG, name_index, length, constant_pool); this.pmg_index = pmg_index; this.pmg_class_index = pmg_class_index; }
Example #25
Source File: BasicType.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Constructor for basic types such as int, long, `void' * * @param type one of T_INT, T_BOOLEAN, ..., T_VOID * @see com.sun.org.apache.bcel.internal.Constants */ BasicType(byte type) { super(type, Constants.SHORT_TYPE_NAMES[type]); if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) throw new ClassGenException("Invalid type: " + type); }
Example #26
Source File: Utility.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload" */ public static short searchOpcode(String name) { name = name.toLowerCase(); for(short i=0; i < Constants.OPCODE_NAMES.length; i++) if(Constants.OPCODE_NAMES[i].equals(name)) return i; return -1; }
Example #27
Source File: Unknown.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Create a non-standard attribute. * * @param name_index Index in constant pool * @param length Content length in bytes * @param bytes Attribute contents * @param constant_pool Array of constants */ public Unknown(int name_index, int length, byte[] bytes, ConstantPool constant_pool) { super(Constants.ATTR_UNKNOWN, name_index, length, constant_pool); this.bytes = bytes; name = ((ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8)).getBytes(); unknown_attributes.put(name, this); }
Example #28
Source File: Method.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Return string representation close to declaration format, * `public static void _main(String[] args) throws IOException', e.g. * * @return String representation of the method. */ public final String toString() { ConstantUtf8 c; String name, signature, access; // Short cuts to constant pool StringBuffer buf; access = Utility.accessToString(access_flags); // Get name and signature from constant pool c = (ConstantUtf8)constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8); signature = c.getBytes(); c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8); name = c.getBytes(); signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable()); buf = new StringBuffer(signature); for(int i=0; i < attributes_count; i++) { Attribute a = attributes[i]; if(!((a instanceof Code) || (a instanceof ExceptionTable))) buf.append(" [" + a.toString() + "]"); } ExceptionTable e = getExceptionTable(); if(e != null) { String str = e.toString(); if(!str.equals("")) buf.append("\n\t\tthrows " + str); } return buf.toString(); }
Example #29
Source File: PMGClass.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * @param name_index Index in constant pool to CONSTANT_Utf8 * @param length Content length in bytes * @param constant_pool Array of constants * @param PMGClass_index Index in constant pool to CONSTANT_Utf8 */ public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, ConstantPool constant_pool) { super(Constants.ATTR_PMG, name_index, length, constant_pool); this.pmg_index = pmg_index; this.pmg_class_index = pmg_class_index; }
Example #30
Source File: BasicType.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructor for basic types such as int, long, `void' * * @param type one of T_INT, T_BOOLEAN, ..., T_VOID * @see com.sun.org.apache.bcel.internal.Constants */ BasicType(byte type) { super(type, Constants.SHORT_TYPE_NAMES[type]); if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) throw new ClassGenException("Invalid type: " + type); }