예제 #1
0
  /** {@inheritDoc} */
  protected int placeItem(int offset) {
    offset += Leb128Utils.unsignedLeb128Size(staticFields.length);
    offset += Leb128Utils.unsignedLeb128Size(instanceFields.length);
    offset += Leb128Utils.unsignedLeb128Size(directMethods.length);
    offset += Leb128Utils.unsignedLeb128Size(virtualMethods.length);

    EncodedField previousEncodedField = null;
    for (EncodedField encodedField : staticFields) {
      offset = encodedField.place(offset, previousEncodedField);
      previousEncodedField = encodedField;
    }

    previousEncodedField = null;
    for (EncodedField encodedField : instanceFields) {
      offset = encodedField.place(offset, previousEncodedField);
      previousEncodedField = encodedField;
    }

    EncodedMethod previousEncodedMethod = null;
    for (EncodedMethod encodedMethod : directMethods) {
      offset = encodedMethod.place(offset, previousEncodedMethod);
      previousEncodedMethod = encodedMethod;
    }

    previousEncodedMethod = null;
    for (EncodedMethod encodedMethod : virtualMethods) {
      offset = encodedMethod.place(offset, previousEncodedMethod);
      previousEncodedMethod = encodedMethod;
    }

    return offset;
  }
예제 #2
0
 public void addField(EncodedField field) {
   if (field.isStatic()) {
     addStaticField(field);
     return;
   }
   addInstanceField(field);
 }
예제 #3
0
  /** {@inheritDoc} */
  protected void writeItem(AnnotatedOutput out) {
    if (out.annotates()) {
      out.annotate(
          "static_fields_size: 0x"
              + Integer.toHexString(staticFields.length)
              + " ("
              + staticFields.length
              + ")");
      out.writeUnsignedLeb128(staticFields.length);
      out.annotate(
          "instance_fields_size: 0x"
              + Integer.toHexString(instanceFields.length)
              + " ("
              + instanceFields.length
              + ")");
      out.writeUnsignedLeb128(instanceFields.length);
      out.annotate(
          "direct_methods_size: 0x"
              + Integer.toHexString(directMethods.length)
              + " ("
              + directMethods.length
              + ")");
      out.writeUnsignedLeb128(directMethods.length);
      out.annotate(
          "virtual_methods_size: 0x"
              + Integer.toHexString(virtualMethods.length)
              + " ("
              + virtualMethods.length
              + ")");
      out.writeUnsignedLeb128(virtualMethods.length);

      EncodedField[] staticFields = this.staticFields;

      int index = 0;
      EncodedField previousEncodedField = null;
      for (EncodedField encodedField : staticFields) {
        out.annotate("[" + index++ + "] static_field");
        out.indent();
        encodedField.writeTo(out, previousEncodedField);
        out.deindent();
        previousEncodedField = encodedField;
      }

      EncodedField[] instanceFields = this.instanceFields;
      index = 0;
      previousEncodedField = null;
      for (EncodedField encodedField : instanceFields) {
        out.annotate("[" + index++ + "] instance_field");
        out.indent();
        encodedField.writeTo(out, previousEncodedField);
        out.deindent();
        previousEncodedField = encodedField;
      }

      EncodedMethod[] directMethods = this.directMethods;
      index = 0;
      EncodedMethod previousEncodedMethod = null;
      for (EncodedMethod encodedMethod : directMethods) {
        out.annotate("[" + index++ + "] direct_method");
        out.indent();
        encodedMethod.writeTo(out, previousEncodedMethod);
        out.deindent();
        previousEncodedMethod = encodedMethod;
      }

      EncodedMethod[] virtualMethods = this.virtualMethods;
      index = 0;
      previousEncodedMethod = null;
      for (EncodedMethod encodedMethod : virtualMethods) {
        out.annotate("[" + index++ + "] virtual_method");
        out.indent();
        encodedMethod.writeTo(out, previousEncodedMethod);
        out.deindent();
        previousEncodedMethod = encodedMethod;
      }
    } else {
      out.writeUnsignedLeb128(staticFields.length);
      out.writeUnsignedLeb128(instanceFields.length);
      out.writeUnsignedLeb128(directMethods.length);
      out.writeUnsignedLeb128(virtualMethods.length);

      EncodedField[] staticFields = this.staticFields;
      EncodedField previousEncodedField = null;
      for (EncodedField encodedField : staticFields) {
        encodedField.writeTo(out, previousEncodedField);
        previousEncodedField = encodedField;
      }

      EncodedField[] instanceFields = this.instanceFields;
      previousEncodedField = null;
      for (EncodedField encodedField : instanceFields) {
        encodedField.writeTo(out, previousEncodedField);
        previousEncodedField = encodedField;
      }

      EncodedMethod[] directMethods = this.directMethods;
      EncodedMethod previousEncodedMethod = null;
      for (EncodedMethod encodedMethod : directMethods) {
        encodedMethod.writeTo(out, previousEncodedMethod);
        previousEncodedMethod = encodedMethod;
      }

      EncodedMethod[] virtualMethods = this.virtualMethods;
      previousEncodedMethod = null;
      for (EncodedMethod encodedMethod : virtualMethods) {
        encodedMethod.writeTo(out, previousEncodedMethod);
        previousEncodedMethod = encodedMethod;
      }
    }
  }