Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.Code


    Attribute[] attributes = m.getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      Attribute a = attributes[i];

      if (a instanceof Code) {
        Code code = (Code) a;
        setMaxStack(code.getMaxStack());
        setMaxLocals(code.getMaxLocals());

        CodeException[] ces = code.getExceptionTable();

        InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray();

        // process the exception table
        // -
        if (ces != null) {
          for (CodeException ce : ces) {
            int type = ce.getCatchType();
            ObjectType catchType = null;

            if (type > 0) {
              String cen = m.getConstantPool().getConstantString_CONSTANTClass(type);
              catchType = new ObjectType(cen);
            }

            int end_pc = ce.getEndPC();
            int length = m.getCode().getCode().length;

            InstructionHandle end;

            if (length == end_pc) { // May happen, because end_pc is exclusive
              end = il.getEnd();
            } else {
              end = il.findHandle(end_pc, arrayOfInstructions);// il.findHandle(end_pc);
              end = end.getPrev(); // Make it inclusive
            }

            addExceptionHandler(il.findHandle(ce.getStartPC(), arrayOfInstructions), end, il.findHandle(ce
                .getHandlerPC(), arrayOfInstructions), catchType);
          }
        }

        Attribute[] codeAttrs = code.getAttributes();
        for (int j = 0; j < codeAttrs.length; j++) {
          a = codeAttrs[j];

          if (a instanceof LineNumberTable) {
            LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
View Full Code Here


    }

    CodeException[] c_exc = getCodeExceptions();
    int exc_len = c_exc.length * 8; // Every entry takes 8 bytes

    Code code = null;

    if ((il != null) && !isAbstract()) {
      // Remove any stale code attribute
      List<Attribute> attributes = getAttributes();
      for (int i = 0; i < attributes.size(); i++) {
        Attribute a = attributes.get(i);
        if (a instanceof Code) {
          removeAttribute(a);
        }
      }

      code = new Code(cp.addUtf8("Code"), 8 + byte_code.length + // prologue byte code
          2 + exc_len + // exceptions
          2 + attrs_len, // attributes
          maxStack, maxLocals, byte_code, c_exc, code_attrs, cp);

      addAttribute(code);
View Full Code Here

    Attribute[] attributes = m.getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      Attribute a = attributes[i];

      if (a instanceof Code) {
        Code code = (Code) a;
        setMaxStack(code.getMaxStack());
        setMaxLocals(code.getMaxLocals());

        CodeException[] ces = code.getExceptionTable();

        InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray();

        // process the exception table
        // -
        if (ces != null) {
          for (CodeException ce : ces) {
            int type = ce.getCatchType();
            ObjectType catchType = null;

            if (type > 0) {
              String cen = m.getConstantPool().getConstantString_CONSTANTClass(type);
              catchType = new ObjectType(cen);
            }

            int end_pc = ce.getEndPC();
            int length = m.getCode().getCode().length;

            InstructionHandle end;

            if (length == end_pc) { // May happen, because end_pc is exclusive
              end = il.getEnd();
            } else {
              end = il.findHandle(end_pc, arrayOfInstructions);// il.findHandle(end_pc);
              end = end.getPrev(); // Make it inclusive
            }

            addExceptionHandler(il.findHandle(ce.getStartPC(), arrayOfInstructions), end, il.findHandle(ce
                .getHandlerPC(), arrayOfInstructions), catchType);
          }
        }

        Attribute[] codeAttrs = code.getAttributes();
        for (int j = 0; j < codeAttrs.length; j++) {
          a = codeAttrs[j];

          if (a instanceof LineNumberTable) {
            LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
View Full Code Here

    }

    CodeException[] c_exc = getCodeExceptions();
    int exc_len = c_exc.length * 8; // Every entry takes 8 bytes

    Code code = null;

    if ((il != null) && !isAbstract()) {
      // Remove any stale code attribute
      List<Attribute> attributes = getAttributes();
      for (int i = 0; i < attributes.size(); i++) {
        Attribute a = attributes.get(i);
        if (a instanceof Code) {
          removeAttribute(a);
        }
      }

      code = new Code(cp.addUtf8("Code"), 8 + byte_code.length + // prologue byte code
          2 + exc_len + // exceptions
          2 + attrs_len, // attributes
          maxStack, maxLocals, byte_code, c_exc, code_attrs, cp);

      addAttribute(code);
View Full Code Here

  file.print(",&nbsp;");
    }

    file.println(")</B></P>");
   
    Code c=null;
    byte[] code=null;

    if(attributes.length > 0) {
      file.print("<H4>Attributes</H4><UL>\n");
      for(int i=0; i < attributes.length; i++) {
  byte tag = attributes[i].getTag();

  if(tag != ATTR_UNKNOWN)
    file.print("<LI><A HREF=\"" + class_name + "_attributes.html#method" + method_number + "@" + i +
         "\" TARGET=Attributes>" + ATTRIBUTE_NAMES[tag] + "</A></LI>\n");
  else
    file.print("<LI>" + attributes[i] + "</LI>");

  if(tag == ATTR_CODE) {
    c = (Code)attributes[i];
    Attribute[] attributes2 = c.getAttributes();
    code                 = c.getCode();
         
    file.print("<UL>");
    for(int j=0; j < attributes2.length; j++) {
      tag = attributes2[j].getTag();
      file.print("<LI><A HREF=\"" + class_name + "_attributes.html#" +
View Full Code Here

          String lvtname = ((ConstantUtf8) cp.getConstant(lvt.getNameIndex())).getBytes();
          if (! lvtname.equals("LocalVariableTable")){
            throw new ClassConstraintException("The LocalVariableTable attribute '"+tostring(lvt)+"' is not correctly named 'LocalVariableTable' but '"+lvtname+"'.");
          }

          Code code = obj;

          //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
          LocalVariable[] localvariables = lvt.getLocalVariableTable();

          for (int i=0; i<localvariables.length; i++){
            checkIndex(lvt, localvariables[i].getNameIndex(), CONST_Utf8);
            String localname = ((ConstantUtf8) cp.getConstant(localvariables[i].getNameIndex())).getBytes();
            if (!validJavaIdentifier(localname)){
              throw new ClassConstraintException("LocalVariableTable '"+tostring(lvt)+"' references a local variable by the name '"+localname+"' which is not a legal Java simple name.");
            }

            checkIndex(lvt, localvariables[i].getSignatureIndex(), CONST_Utf8);
            String localsig  = ((ConstantUtf8) (cp.getConstant(localvariables[i].getSignatureIndex()))).getBytes(); // Local signature(=descriptor)
            Type t;
            try{
              t = Type.getType(localsig);
            }
            catch (ClassFormatError cfe){ // sometimes BCEL is a little harsh describing exceptional situations.
              throw new ClassConstraintException("Illegal descriptor (==signature) '"+localsig+"' used by LocalVariable '"+tostring(localvariables[i])+"' referenced by '"+tostring(lvt)+"'.");
            }
            int localindex = localvariables[i].getIndex();
            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()+"'.");
            }

            try{
              localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t);
            }
View Full Code Here

    /* Handle different attributes
     */
    switch(tag) {
    case ATTR_CODE:
      Code        c          = (Code)attribute;

      // Some directly printable values
      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");

      // Get handled exceptions and list them
      CodeException[] ce  = c.getExceptionTable();
      int             len = ce.length;

      if(len > 0) {
  file.print("<P><B>Exceptions handled</B><UL>");

View Full Code Here

    Attribute[] attributes = m.getAttributes();
    for(int i=0; i < attributes.length; i++) {
      Attribute a = attributes[i];

      if(a instanceof Code) {
  Code c = (Code)a;
  setMaxStack(c.getMaxStack());
  setMaxLocals(c.getMaxLocals());
 
  CodeException[] ces = c.getExceptionTable();
 
  if(ces != null) {
    for(int j=0; j < ces.length; j++) {
            CodeException ce     = ces[j];
            int           type   = ce.getCatchType();
            ObjectType    c_type = null;

      if(type > 0) {
        String cen = m.getConstantPool().getConstantString(type, Constants.CONSTANT_Class);
        c_type = new ObjectType(cen);
      }

      int end_pc = ce.getEndPC();
      int length = m.getCode().getCode().length;
     
      InstructionHandle end;

      if(length == end_pc) { // May happen, because end_pc is exclusive
        end = il.getEnd();
      } else {
        end = il.findHandle(end_pc);
        end = end.getPrev(); // Make it inclusive
      }

      addExceptionHandler(il.findHandle(ce.getStartPC()), end,
        il.findHandle(ce.getHandlerPC()), c_type);
    }
  }

  Attribute[] c_attributes = c.getAttributes();
  for(int j=0; j < c_attributes.length; j++) {
    a = c_attributes[j];

    if(a instanceof LineNumberTable) {
      LineNumber[] ln = ((LineNumberTable)a).getLineNumberTable();
View Full Code Here

      attrs_len += (code_attrs[i].getLength() + 6);

    CodeException[] c_exc   = getCodeExceptions();
    int             exc_len = c_exc.length * 8; // Every entry takes 8 bytes

    Code code = null;

    if((il != null) && !isAbstract()) {
      // Remove any stale code attribute
      Attribute[] attributes = getAttributes();
      for(int i=0; i < attributes.length; i++) {
      Attribute a = attributes[i];
      if(a instanceof Code)
        removeAttribute(a);
      }

      code = new Code(cp.addUtf8("Code"),
          8 + byte_code.length + // prologue byte code
          2 + exc_len +          // exceptions
          2 + attrs_len,         // attributes
          max_stack, max_locals,
          byte_code, c_exc,
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.Code

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.