Java Code Examples for org.objectweb.asm.Opcodes#V11

The following examples show how to use org.objectweb.asm.Opcodes#V11 . 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: SourceVersionUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Gets the class file version corresponding to the given source version constant. */
public static int sourceVersionToClassFileVersion(SourceVersion version) {
  switch (version) {
    case RELEASE_0:
      return Opcodes.V1_1; // JVMS8 4.1: 1.0 and 1.1 both support version 45.3 (Opcodes.V1_1)
    case RELEASE_1:
      return Opcodes.V1_1;
    case RELEASE_2:
      return Opcodes.V1_2;
    case RELEASE_3:
      return Opcodes.V1_3;
    case RELEASE_4:
      return Opcodes.V1_4;
    case RELEASE_5:
      return Opcodes.V1_5;
    case RELEASE_6:
      return Opcodes.V1_6;
    case RELEASE_7:
      return Opcodes.V1_7;
    case RELEASE_8:
      return Opcodes.V1_8;
    case RELEASE_9:
      return Opcodes.V9;
    case RELEASE_10:
      return Opcodes.V10;
    case RELEASE_11:
      return Opcodes.V11;
    default:
      throw new IllegalArgumentException(String.format("Unexpected source version: %s", version));
  }
}
 
Example 2
Source File: CheckMethodAdapter.java    From Concurnas with MIT License 4 votes vote down vote up
/**
 * Checks that the given value is a valid operand for the LDC instruction.
 *
 * @param value the value to be checked.
 */
private void checkLdcConstant(final Object value) {
  if (value instanceof Type) {
    int sort = ((Type) value).getSort();
    if (sort != Type.OBJECT && sort != Type.ARRAY && sort != Type.METHOD) {
      throw new IllegalArgumentException("Illegal LDC constant value");
    }
    if (sort != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
      throw new IllegalArgumentException("ldc of a constant class requires at least version 1.5");
    }
    if (sort == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a method type requires at least version 1.7");
    }
  } else if (value instanceof Handle) {
    if ((version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a Handle requires at least version 1.7");
    }
    Handle handle = (Handle) value;
    int tag = handle.getTag();
    if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
      throw new IllegalArgumentException("invalid handle tag " + tag);
    }
    checkInternalName(this.version, handle.getOwner(), "handle owner");
    if (tag <= Opcodes.H_PUTSTATIC) {
      checkDescriptor(this.version, handle.getDesc(), false);
    } else {
      checkMethodDescriptor(this.version, handle.getDesc());
    }
    String handleName = handle.getName();
    if (!("<init>".equals(handleName) && tag == Opcodes.H_NEWINVOKESPECIAL)) {
      checkMethodIdentifier(this.version, handleName, "handle name");
    }
  } else if (value instanceof ConstantDynamic) {
    if ((version & 0xFFFF) < Opcodes.V11) {
      throw new IllegalArgumentException("ldc of a ConstantDynamic requires at least version 11");
    }
    ConstantDynamic constantDynamic = (ConstantDynamic) value;
    checkMethodIdentifier(this.version, constantDynamic.getName(), "constant dynamic name");
    checkDescriptor(this.version, constantDynamic.getDescriptor(), false);
    checkLdcConstant(constantDynamic.getBootstrapMethod());
    int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
    for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
      checkLdcConstant(constantDynamic.getBootstrapMethodArgument(i));
    }
  } else {
    checkConstant(value);
  }
}
 
Example 3
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 4 votes vote down vote up
/**
 * Checks that the given value is a valid operand for the LDC instruction.
 *
 * @param value the value to be checked.
 */
private void checkLdcConstant(final Object value) {
  if (value instanceof Type) {
    int sort = ((Type) value).getSort();
    if (sort != Type.OBJECT && sort != Type.ARRAY && sort != Type.METHOD) {
      throw new IllegalArgumentException("Illegal LDC constant value");
    }
    if (sort != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
      throw new IllegalArgumentException("ldc of a constant class requires at least version 1.5");
    }
    if (sort == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a method type requires at least version 1.7");
    }
  } else if (value instanceof Handle) {
    if ((version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a Handle requires at least version 1.7");
    }
    Handle handle = (Handle) value;
    int tag = handle.getTag();
    if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
      throw new IllegalArgumentException("invalid handle tag " + tag);
    }
    checkInternalName(this.version, handle.getOwner(), "handle owner");
    if (tag <= Opcodes.H_PUTSTATIC) {
      checkDescriptor(this.version, handle.getDesc(), false);
    } else {
      checkMethodDescriptor(this.version, handle.getDesc());
    }
    String handleName = handle.getName();
    if (!("<init>".equals(handleName) && tag == Opcodes.H_NEWINVOKESPECIAL)) {
      checkMethodIdentifier(this.version, handleName, "handle name");
    }
  } else if (value instanceof ConstantDynamic) {
    if ((version & 0xFFFF) < Opcodes.V11) {
      throw new IllegalArgumentException("ldc of a ConstantDynamic requires at least version 11");
    }
    ConstantDynamic constantDynamic = (ConstantDynamic) value;
    checkMethodIdentifier(this.version, constantDynamic.getName(), "constant dynamic name");
    checkDescriptor(this.version, constantDynamic.getDescriptor(), false);
    checkLdcConstant(constantDynamic.getBootstrapMethod());
    int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
    for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
      checkLdcConstant(constantDynamic.getBootstrapMethodArgument(i));
    }
  } else {
    checkConstant(value);
  }
}
 
Example 4
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 4 votes vote down vote up
/**
 * Checks that the given value is a valid operand for the LDC instruction.
 *
 * @param value the value to be checked.
 */
private void checkLdcConstant(final Object value) {
  if (value instanceof Type) {
    int sort = ((Type) value).getSort();
    if (sort != Type.OBJECT && sort != Type.ARRAY && sort != Type.METHOD) {
      throw new IllegalArgumentException("Illegal LDC constant value");
    }
    if (sort != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
      throw new IllegalArgumentException("ldc of a constant class requires at least version 1.5");
    }
    if (sort == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a method type requires at least version 1.7");
    }
  } else if (value instanceof Handle) {
    if ((version & 0xFFFF) < Opcodes.V1_7) {
      throw new IllegalArgumentException("ldc of a Handle requires at least version 1.7");
    }
    Handle handle = (Handle) value;
    int tag = handle.getTag();
    if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
      throw new IllegalArgumentException("invalid handle tag " + tag);
    }
    checkInternalName(this.version, handle.getOwner(), "handle owner");
    if (tag <= Opcodes.H_PUTSTATIC) {
      checkDescriptor(this.version, handle.getDesc(), false);
    } else {
      checkMethodDescriptor(this.version, handle.getDesc());
    }
    String handleName = handle.getName();
    if (!("<init>".equals(handleName) && tag == Opcodes.H_NEWINVOKESPECIAL)) {
      checkMethodIdentifier(this.version, handleName, "handle name");
    }
  } else if (value instanceof ConstantDynamic) {
    if ((version & 0xFFFF) < Opcodes.V11) {
      throw new IllegalArgumentException("ldc of a ConstantDynamic requires at least version 11");
    }
    ConstantDynamic constantDynamic = (ConstantDynamic) value;
    checkMethodIdentifier(this.version, constantDynamic.getName(), "constant dynamic name");
    checkDescriptor(this.version, constantDynamic.getDescriptor(), false);
    checkLdcConstant(constantDynamic.getBootstrapMethod());
    int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
    for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
      checkLdcConstant(constantDynamic.getBootstrapMethodArgument(i));
    }
  } else {
    checkConstant(value);
  }
}
 
Example 5
Source File: ClassVisitorDriverFromElement.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitType(TypeElement e, ClassVisitor visitor) {
  if (classVisitorStarted) {
    // We'll get inner class references later
    return null;
  }

  TypeMirror superclass = e.getSuperclass();
  if (superclass.getKind() == TypeKind.NONE) {
    superclass = Objects.requireNonNull(elements.getTypeElement("java.lang.Object")).asType();
  }

  int classFileVersion = SourceVersionUtils.sourceVersionToClassFileVersion(targetVersion);
  visitor.visit(
      classFileVersion,
      accessFlagsUtils.getAccessFlagsForClassNode(e),
      descriptorFactory.getInternalName(e),
      signatureFactory.getSignature(e),
      descriptorFactory.getInternalName(superclass),
      e.getInterfaces().stream()
          .map(descriptorFactory::getInternalName)
          .toArray(size -> new String[size]));
  classVisitorStarted = true;

  // Handle nests in Java 11+. See JEP 181 (https://openjdk.java.net/jeps/181) for details.
  if (classFileVersion >= Opcodes.V11) {
    if (e.getNestingKind().isNested()) {
      visitNestHost(e, visitor);
    } else {
      visitNestMembers(e, visitor);
    }
  }

  visitAnnotations(e, visitor::visitAnnotation);

  super.visitType(e, visitor);

  InnerClassesTable innerClassesTable =
      new InnerClassesTable(descriptorFactory, accessFlagsUtils, e);
  if (e.getKind().isClass() || classFileVersion >= Opcodes.V1_8) {
    try {
      generateBridges(e, visitor, innerClassesTable);
    } catch (UnsupportedOperationException | CannotInferException ex) { // NOPMD
      // Can't generate bridges in source-only mode
    }
  }

  innerClassesTable.reportInnerClassReferences(visitor);

  return null;
}