public void visitCode(Code code) { stack.push(code); code.accept(visitor); CodeException[] table = code.getExceptionTable(); for(int i=0; i < table.length; i++) table[i].accept(this); Attribute[] attributes = code.getAttributes(); for(int i=0; i < attributes.length; i++) attributes[i].accept(this); stack.pop(); }
/** * @param attributes. */ public final void setAttributes(Attribute[] attributes) { this.attributes = attributes; attributes_count = (attributes == null)? 0 : attributes.length; length = calculateLength(); // Adjust length }
/** * Initialize from another object. Note that both objects use the same * references (shallow copy). Use copy() for a physical copy. */ public Code(Code c) { this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), c.getCode(), c.getExceptionTable(), c.getAttributes(), c.getConstantPool()); }
new InstructionList(m.getCode().getCode()) : null, cp); setMaxStack(c.getMaxStack()); setMaxLocals(c.getMaxLocals()); CodeException[] ces = c.getExceptionTable(); int length = m.getCode().getCode().length; Attribute[] c_attributes = c.getAttributes(); for(int j=0; j < c_attributes.length; j++) { a = c_attributes[j];
int codeLength = code.getCode().length; LineNumberTable lnt = code.getLineNumberTable(); if (lnt != null){ LineNumber[] lineNumbers = lnt.getLineNumberTable(); if (instructionPositions[j] == offset){ if (offsets.contains(offset)){ addMessage("LineNumberTable attribute '"+code.getLineNumberTable()+"' refers to the same code offset ('"+offset+"') more than once which is violating the semantics [but is sometimes produced by IBM's 'jikes' compiler]."); throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist."); Attribute[] atts = code.getAttributes(); for (int a=0; a<atts.length; a++){ if (atts[a] instanceof LocalVariableTable){ throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset ('"+startpc+"') that does not exist."); throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset start_pc+length ('"+(startpc+length)+"') that does not exist."); CodeException[] exceptionTable = code.getExceptionTable(); for (int i=0; i<exceptionTable.length; i++){ int startpc = exceptionTable[i].getStartPC();
checkIndex(obj, obj.getNameIndex(), CONST_Utf8); String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); if (! name.equals("Code")){ throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'."); if (obj.getCode().length == 0){ throw new ClassConstraintException("Code array of Code attribute '"+tostring(obj)+"' (method '"+m+"') must not be empty."); CodeException[] exc_table = obj.getExceptionTable(); for (int i=0; i<exc_table.length; i++){ int exc_index = exc_table[i].getCatchType(); throw new AssertionViolatedException("Could not find a known BCEL Method object in the corresponding BCEL JavaClass object."); localVariablesInfos[method_number] = new LocalVariablesInfo(obj.getMaxLocals()); Attribute[] atts = obj.getAttributes(); for (int a=0; a<atts.length; a++){ if ((! (atts[a] instanceof LineNumberTable)) && if ( ( (t==Type.LONG || t==Type.DOUBLE)? localindex+1:localindex) >= code.getMaxLocals()){ throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'."); if (num_of_lvt_attribs > obj.getMaxLocals()){ throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.').");
file.print("<UL><LI>Maximum stack size = " + c.getMaxStack() + "</LI>\n<LI>Number of local variables = " + c.getMaxLocals() + "</LI>\n<LI><A HREF=\"" + class_name + "_code.html#method" + method_number + "\" TARGET=Code>Byte code</A></LI></UL>\n"); CodeException[] ce = c.getExceptionTable(); int len = ce.length;
Attribute[] attributes2 = c.getAttributes(); code = c.getCode();
CodeException[] ce = code.getExceptionTable(); int len = ce.length; Attribute[] attributes = code.getAttributes(); for(int i=0; i < attributes.length; i++) { if(attributes[i].getTag() == ATTR_LOCAL_VARIABLE_TABLE) {
if (! (code.getCode().length < 65536)){// contradicts vmspec2 page 152 ("Limitations"), but is on page 134. throw new StaticCodeInstructionConstraintException("Code array in code attribute '"+code+"' too big: must be smaller than 65536 bytes.");
return new Code(name_index, length, file, constant_pool);
/** * @return the full size of this code attribute, minus its first 6 bytes, * including the size of all its contained attributes */ private final int calculateLength() { int len = 0; for(int i=0; i < attributes_count; i++) len += attributes[i].length + 6 /*attribute header size*/; return len + getInternalLength(); }
/** * @return deep copy of this attribute */ public Attribute copy(ConstantPool constant_pool) { Code c = (Code)clone(); c.code = (byte[])code.clone(); c.constant_pool = constant_pool; c.exception_table = new CodeException[exception_table_length]; for(int i=0; i < exception_table_length; i++) c.exception_table[i] = exception_table[i].copy(); c.attributes = new Attribute[attributes_count]; for(int i=0; i < attributes_count; i++) c.attributes[i] = attributes[i].copy(constant_pool); return c; } }
Attribute[] c_a = ((Code)attributes[i]).getAttributes();
new InstructionList(m.getCode().getCode()) : null, cp); setMaxStack(c.getMaxStack()); setMaxLocals(c.getMaxLocals()); CodeException[] ces = c.getExceptionTable(); int length = m.getCode().getCode().length; Attribute[] c_attributes = c.getAttributes(); for(int j=0; j < c_attributes.length; j++) { a = c_attributes[j];
int codeLength = code.getCode().length; LineNumberTable lnt = code.getLineNumberTable(); if (lnt != null){ LineNumber[] lineNumbers = lnt.getLineNumberTable(); if (instructionPositions[j] == offset){ if (offsets.contains(offset)){ addMessage("LineNumberTable attribute '"+code.getLineNumberTable()+"' refers to the same code offset ('"+offset+"') more than once which is violating the semantics [but is sometimes produced by IBM's 'jikes' compiler]."); throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist."); Attribute[] atts = code.getAttributes(); for (int a=0; a<atts.length; a++){ if (atts[a] instanceof LocalVariableTable){ throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset ('"+startpc+"') that does not exist."); throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset start_pc+length ('"+(startpc+length)+"') that does not exist."); CodeException[] exceptionTable = code.getExceptionTable(); for (int i=0; i<exceptionTable.length; i++){ int startpc = exceptionTable[i].getStartPC();
checkIndex(obj, obj.getNameIndex(), CONST_Utf8); String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes(); if (! name.equals("Code")){ throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'."); if (obj.getCode().length == 0){ throw new ClassConstraintException("Code array of Code attribute '"+tostring(obj)+"' (method '"+m+"') must not be empty."); CodeException[] exc_table = obj.getExceptionTable(); for (int i=0; i<exc_table.length; i++){ int exc_index = exc_table[i].getCatchType(); throw new AssertionViolatedException("Could not find a known BCEL Method object in the corresponding BCEL JavaClass object."); localVariablesInfos[method_number] = new LocalVariablesInfo(obj.getMaxLocals()); Attribute[] atts = obj.getAttributes(); for (int a=0; a<atts.length; a++){ if ((! (atts[a] instanceof LineNumberTable)) && if ( ( (t==Type.LONG || t==Type.DOUBLE)? localindex+1:localindex) >= code.getMaxLocals()){ throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'."); if (num_of_lvt_attribs > obj.getMaxLocals()){ throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.').");
file.print("<UL><LI>Maximum stack size = " + c.getMaxStack() + "</LI>\n<LI>Number of local variables = " + c.getMaxLocals() + "</LI>\n<LI><A HREF=\"" + class_name + "_code.html#method" + method_number + "\" TARGET=Code>Byte code</A></LI></UL>\n"); CodeException[] ce = c.getExceptionTable(); int len = ce.length;
Attribute[] attributes2 = c.getAttributes(); code = c.getCode();
CodeException[] ce = code.getExceptionTable(); int len = ce.length; Attribute[] attributes = code.getAttributes(); for(int i=0; i < attributes.length; i++) { if(attributes[i].getTag() == ATTR_LOCAL_VARIABLE_TABLE) {