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

The following examples show how to use org.objectweb.asm.Opcodes#H_NEWINVOKESPECIAL . 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: CheckMethodAdapter.java    From Concurnas with MIT License 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(
    final String name,
    final String descriptor,
    final Handle bootstrapMethodHandle,
    final Object... bootstrapMethodArguments) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  checkMethodIdentifier(version, name, "name");
  checkMethodDescriptor(version, descriptor);
  if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC
      && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
    throw new IllegalArgumentException("invalid handle tag " + bootstrapMethodHandle.getTag());
  }
  for (Object bootstrapMethodArgument : bootstrapMethodArguments) {
    checkLdcConstant(bootstrapMethodArgument);
  }
  super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
  ++insnCount;
}
 
Example 2
Source File: DalvikStatsTool.java    From buck with Apache License 2.0 6 votes vote down vote up
private void registerMethodHandleType(Handle handle) {
  switch (handle.getTag()) {
    case Opcodes.H_GETFIELD:
    case Opcodes.H_GETSTATIC:
    case Opcodes.H_PUTFIELD:
    case Opcodes.H_PUTSTATIC:
      visitFieldInsn(Opcodes.GETFIELD, handle.getOwner(), handle.getName(), handle.getDesc());
      break;
    case Opcodes.H_INVOKEVIRTUAL:
    case Opcodes.H_INVOKEINTERFACE:
    case Opcodes.H_INVOKESPECIAL:
    case Opcodes.H_INVOKESTATIC:
    case Opcodes.H_NEWINVOKESPECIAL:
      visitMethodInsn(
          Opcodes.H_INVOKEVIRTUAL,
          handle.getOwner(),
          handle.getName(),
          handle.getDesc(),
          false);
      createAdditionalMethodsForDesugar(handle);
      break;
    default:
      throw new IllegalStateException(
          "MethodHandle tag is not supported: " + handle.getTag());
  }
}
 
Example 3
Source File: LambdaDesugaring.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Produces a {@link MethodHandle} using either the context or {@link #targetLoader} class
 * loader, depending on {@code target}.
 */
private MethodHandle toMethodHandle(Lookup lookup, Handle asmHandle, boolean target)
    throws ReflectiveOperationException {
  Class<?> owner = loadFromInternal(asmHandle.getOwner());
  MethodType signature =
      MethodType.fromMethodDescriptorString(
          asmHandle.getDesc(),
          target ? targetLoader : Thread.currentThread().getContextClassLoader());
  switch (asmHandle.getTag()) {
    case Opcodes.H_INVOKESTATIC:
      return lookup.findStatic(owner, asmHandle.getName(), signature);
    case Opcodes.H_INVOKEVIRTUAL:
    case Opcodes.H_INVOKEINTERFACE:
      return lookup.findVirtual(owner, asmHandle.getName(), signature);
    case Opcodes.H_INVOKESPECIAL: // we end up calling these using invokevirtual
      return lookup.findSpecial(owner, asmHandle.getName(), signature, owner);
    case Opcodes.H_NEWINVOKESPECIAL:
      return lookup.findConstructor(owner, signature);
    default:
      throw new UnsupportedOperationException("Cannot resolve " + asmHandle);
  }
}
 
Example 4
Source File: LambdaDesugaring.java    From bazel with Apache License 2.0 6 votes vote down vote up
private Executable findTargetMethod(Handle invokedMethod) throws ClassNotFoundException {
  Type descriptor = Type.getMethodType(invokedMethod.getDesc());
  Class<?> owner = loadFromInternal(invokedMethod.getOwner());
  if (invokedMethod.getTag() == Opcodes.H_NEWINVOKESPECIAL) {
    for (Constructor<?> c : owner.getDeclaredConstructors()) {
      if (Type.getType(c).equals(descriptor)) {
        return c;
      }
    }
  } else {
    for (Method m : owner.getDeclaredMethods()) {
      if (m.getName().equals(invokedMethod.getName()) && Type.getType(m).equals(descriptor)) {
        return m;
      }
    }
  }
  throw new IllegalArgumentException("Referenced method not found: " + invokedMethod);
}
 
Example 5
Source File: MemberRef.java    From Mixin with MIT License 6 votes vote down vote up
@Override
public boolean isField() {
    switch (this.handle.getTag()) {
        case Opcodes.H_INVOKEVIRTUAL:
        case Opcodes.H_INVOKESTATIC:
        case Opcodes.H_INVOKEINTERFACE:
        case Opcodes.H_INVOKESPECIAL:
        case Opcodes.H_NEWINVOKESPECIAL:
            return false;
        case Opcodes.H_GETFIELD:
        case Opcodes.H_GETSTATIC:
        case Opcodes.H_PUTFIELD:
        case Opcodes.H_PUTSTATIC:
            return true;
        default:
            throw new MixinTransformerError("Invalid tag " + this.handle.getTag() + " for method handle " + this.handle + ".");
    }
}
 
Example 6
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(
    final String name,
    final String descriptor,
    final Handle bootstrapMethodHandle,
    final Object... bootstrapMethodArguments) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  checkMethodIdentifier(version, name, "name");
  checkMethodDescriptor(version, descriptor);
  if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC
      && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
    throw new IllegalArgumentException("invalid handle tag " + bootstrapMethodHandle.getTag());
  }
  for (Object bootstrapMethodArgument : bootstrapMethodArguments) {
    checkLdcConstant(bootstrapMethodArgument);
  }
  super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
  ++insnCount;
}
 
Example 7
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(
    final String name,
    final String descriptor,
    final Handle bootstrapMethodHandle,
    final Object... bootstrapMethodArguments) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  checkMethodIdentifier(version, name, "name");
  checkMethodDescriptor(version, descriptor);
  if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC
      && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
    throw new IllegalArgumentException("invalid handle tag " + bootstrapMethodHandle.getTag());
  }
  for (Object bootstrapMethodArgument : bootstrapMethodArguments) {
    checkLdcConstant(bootstrapMethodArgument);
  }
  super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
  ++insnCount;
}
 
Example 8
Source File: InvokedynamicShadower.java    From AVM with MIT License 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String origMethodName, String methodDescriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
    String methodOwner = bootstrapMethodHandle.getOwner();
    if (isStringConcatIndy(methodOwner, origMethodName)) {
        handleStringConcatIndy(origMethodName, methodDescriptor, bootstrapMethodHandle, bootstrapMethodArguments);
    } else if (isLambdaIndy(methodOwner)) {
        // AKI-130: The bootstrap methodDescriptor to this metafactory must NOT require additional arguments (since that would require dynamic class generation for each callsite - potential attack vector).
        if (!methodDescriptor.startsWith("()")) {
            throw RejectedClassException.invokeDynamicBootstrapMethodArguments(methodDescriptor);
        }
        // This is really just a specialization of the above call to check the return type (this would need to be changed if we accepted arguments).
        if (!RUNNABLE_DESCRIPTOR.equals(methodDescriptor) && !FUNCTION_DESCRIPTOR.equals(methodDescriptor)) {
            throw RejectedClassException.invokeDynamicLambdaType(methodDescriptor);
        }
        if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKEVIRTUAL && bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC
                && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL && bootstrapMethodHandle.getTag() != Opcodes.H_INVOKEINTERFACE) {
            throw RejectedClassException.invokeDynamicHandleType(bootstrapMethodHandle.getTag(), methodDescriptor);
        }

        handleLambdaIndy(origMethodName, methodDescriptor, bootstrapMethodHandle, bootstrapMethodArguments);
    } else {
        throw RejectedClassException.invokeDynamicUnsupportedMethodOwner(origMethodName, methodOwner);
    }
}
 
Example 9
Source File: CheckMethodAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
  checkStartCode();
  checkEndCode();
  checkMethodIdentifier(version, name, "name");
  checkMethodDesc(desc);
  if (bsm.getTag() != Opcodes.H_INVOKESTATIC && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
    throw new IllegalArgumentException("invalid handle tag " + bsm.getTag());
  }
  for (int i = 0; i < bsmArgs.length; i++) {
    checkLDCConstant(bsmArgs[i]);
  }
  super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
  ++insnCount;
}
 
Example 10
Source File: LambdaClassFixer.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
  if (!name.equals(lambdaInfo.methodReference().getName())
      || !desc.equals(lambdaInfo.methodReference().getDesc())) {
    super.visitMethodInsn(opcode, owner, name, desc, itf);
    return;
  }

  boolean useBridgeMethod = false;
  if (owner.equals(lambdaInfo.methodReference().getOwner())) {
    if (lambdaInfo.methodReference().getTag() == Opcodes.H_NEWINVOKESPECIAL
        && lambdaInfo.bridgeMethod().getTag() != Opcodes.H_NEWINVOKESPECIAL) {
      // We're changing a constructor call to a factory method call, so we unfortunately need
      // to go find the NEW/DUP pair preceding the constructor call and remove it
      removeLastAllocation();
    }
    useBridgeMethod = true;
  } else if ((lambdaInfo.methodReference().getTag() == Opcodes.H_INVOKEVIRTUAL
          || lambdaInfo.methodReference().getTag() == Opcodes.H_INVOKESPECIAL)
      && hasAssignableRelation(owner, lambdaInfo.methodReference().getOwner())) {
    // For rewriting instance methods calls, we consider the class hierarchy.
    // This is for JDK 9: (b/62218600).
    // TODO(cnsun): revisit this to make sure Desugar is fully compatible with this change
    // in JDK: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/a3b3c7b6464d
    useBridgeMethod = true;
  }
  if (useBridgeMethod) {
    super.visitMethodInsn(
        LambdaDesugaring.invokeOpcode(lambdaInfo.bridgeMethod()),
        lambdaInfo.bridgeMethod().getOwner(),
        lambdaInfo.bridgeMethod().getName(),
        lambdaInfo.bridgeMethod().getDesc(),
        lambdaInfo.bridgeMethod().isInterface());
  } else {
    super.visitMethodInsn(opcode, owner, name, desc, itf);
  }
}
 
Example 11
Source File: LambdaDesugaring.java    From bazel with Apache License 2.0 5 votes vote down vote up
static int invokeOpcode(Handle invokedMethod) {
  switch (invokedMethod.getTag()) {
    case Opcodes.H_INVOKESTATIC:
      return Opcodes.INVOKESTATIC;
    case Opcodes.H_INVOKEVIRTUAL:
      return Opcodes.INVOKEVIRTUAL;
    case Opcodes.H_INVOKESPECIAL:
    case Opcodes.H_NEWINVOKESPECIAL: // Must be preceded by NEW
      return Opcodes.INVOKESPECIAL;
    case Opcodes.H_INVOKEINTERFACE:
      return Opcodes.INVOKEINTERFACE;
    default:
      throw new UnsupportedOperationException("Don't know how to call " + invokedMethod);
  }
}
 
Example 12
Source File: Textifier.java    From JReFrameworker with MIT License 4 votes vote down vote up
/**
 * Appends a string representation of the given handle to {@link #stringBuilder}.
 *
 * @param handle a handle.
 */
protected void appendHandle(final Handle handle) {
  int tag = handle.getTag();
  stringBuilder.append("// handle kind 0x").append(Integer.toHexString(tag)).append(" : ");
  boolean isMethodHandle = false;
  switch (tag) {
    case Opcodes.H_GETFIELD:
      stringBuilder.append("GETFIELD");
      break;
    case Opcodes.H_GETSTATIC:
      stringBuilder.append("GETSTATIC");
      break;
    case Opcodes.H_PUTFIELD:
      stringBuilder.append("PUTFIELD");
      break;
    case Opcodes.H_PUTSTATIC:
      stringBuilder.append("PUTSTATIC");
      break;
    case Opcodes.H_INVOKEINTERFACE:
      stringBuilder.append("INVOKEINTERFACE");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESPECIAL:
      stringBuilder.append("INVOKESPECIAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESTATIC:
      stringBuilder.append("INVOKESTATIC");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKEVIRTUAL:
      stringBuilder.append("INVOKEVIRTUAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_NEWINVOKESPECIAL:
      stringBuilder.append("NEWINVOKESPECIAL");
      isMethodHandle = true;
      break;
    default:
      throw new IllegalArgumentException();
  }
  stringBuilder.append('\n');
  stringBuilder.append(tab3);
  appendDescriptor(INTERNAL_NAME, handle.getOwner());
  stringBuilder.append('.');
  stringBuilder.append(handle.getName());
  if (!isMethodHandle) {
    stringBuilder.append('(');
  }
  appendDescriptor(HANDLE_DESCRIPTOR, handle.getDesc());
  if (!isMethodHandle) {
    stringBuilder.append(')');
  }
  if (handle.isInterface()) {
    stringBuilder.append(" itf");
  }
}
 
Example 13
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 14
Source File: Textifier.java    From JReFrameworker with MIT License 4 votes vote down vote up
/**
 * Appends a string representation of the given handle to {@link #stringBuilder}.
 *
 * @param handle a handle.
 */
protected void appendHandle(final Handle handle) {
  int tag = handle.getTag();
  stringBuilder.append("// handle kind 0x").append(Integer.toHexString(tag)).append(" : ");
  boolean isMethodHandle = false;
  switch (tag) {
    case Opcodes.H_GETFIELD:
      stringBuilder.append("GETFIELD");
      break;
    case Opcodes.H_GETSTATIC:
      stringBuilder.append("GETSTATIC");
      break;
    case Opcodes.H_PUTFIELD:
      stringBuilder.append("PUTFIELD");
      break;
    case Opcodes.H_PUTSTATIC:
      stringBuilder.append("PUTSTATIC");
      break;
    case Opcodes.H_INVOKEINTERFACE:
      stringBuilder.append("INVOKEINTERFACE");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESPECIAL:
      stringBuilder.append("INVOKESPECIAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESTATIC:
      stringBuilder.append("INVOKESTATIC");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKEVIRTUAL:
      stringBuilder.append("INVOKEVIRTUAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_NEWINVOKESPECIAL:
      stringBuilder.append("NEWINVOKESPECIAL");
      isMethodHandle = true;
      break;
    default:
      throw new IllegalArgumentException();
  }
  stringBuilder.append('\n');
  stringBuilder.append(tab3);
  appendDescriptor(INTERNAL_NAME, handle.getOwner());
  stringBuilder.append('.');
  stringBuilder.append(handle.getName());
  if (!isMethodHandle) {
    stringBuilder.append('(');
  }
  appendDescriptor(HANDLE_DESCRIPTOR, handle.getDesc());
  if (!isMethodHandle) {
    stringBuilder.append(')');
  }
  if (handle.isInterface()) {
    stringBuilder.append(" itf");
  }
}
 
Example 15
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 16
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Appends the information about the given handle to {@link #buf buf}.
 *
 * @param h
 *          a handle, non null.
 */
protected void appendHandle(final Handle h) {
  int tag = h.getTag();
  buf.append("// handle kind 0x").append(Integer.toHexString(tag)).append(" : ");
  boolean isMethodHandle = false;
  switch (tag) {
  case Opcodes.H_GETFIELD:
    buf.append("GETFIELD");
    break;
  case Opcodes.H_GETSTATIC:
    buf.append("GETSTATIC");
    break;
  case Opcodes.H_PUTFIELD:
    buf.append("PUTFIELD");
    break;
  case Opcodes.H_PUTSTATIC:
    buf.append("PUTSTATIC");
    break;
  case Opcodes.H_INVOKEINTERFACE:
    buf.append("INVOKEINTERFACE");
    isMethodHandle = true;
    break;
  case Opcodes.H_INVOKESPECIAL:
    buf.append("INVOKESPECIAL");
    isMethodHandle = true;
    break;
  case Opcodes.H_INVOKESTATIC:
    buf.append("INVOKESTATIC");
    isMethodHandle = true;
    break;
  case Opcodes.H_INVOKEVIRTUAL:
    buf.append("INVOKEVIRTUAL");
    isMethodHandle = true;
    break;
  case Opcodes.H_NEWINVOKESPECIAL:
    buf.append("NEWINVOKESPECIAL");
    isMethodHandle = true;
    break;
  }
  buf.append('\n');
  buf.append(tab3);
  appendDescriptor(INTERNAL_NAME, h.getOwner());
  buf.append('.');
  buf.append(h.getName());
  if (!isMethodHandle) {
    buf.append('(');
  }
  appendDescriptor(HANDLE_DESCRIPTOR, h.getDesc());
  if (!isMethodHandle) {
    buf.append(')');
  }
  if (h.isInterface()) {
    buf.append(" itf");
  }
}
 
Example 17
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 18
Source File: Textifier.java    From Concurnas with MIT License 4 votes vote down vote up
/**
 * Appends a string representation of the given handle to {@link #stringBuilder}.
 *
 * @param handle a handle.
 */
protected void appendHandle(final Handle handle) {
  int tag = handle.getTag();
  stringBuilder.append("// handle kind 0x").append(Integer.toHexString(tag)).append(" : ");
  boolean isMethodHandle = false;
  switch (tag) {
    case Opcodes.H_GETFIELD:
      stringBuilder.append("GETFIELD");
      break;
    case Opcodes.H_GETSTATIC:
      stringBuilder.append("GETSTATIC");
      break;
    case Opcodes.H_PUTFIELD:
      stringBuilder.append("PUTFIELD");
      break;
    case Opcodes.H_PUTSTATIC:
      stringBuilder.append("PUTSTATIC");
      break;
    case Opcodes.H_INVOKEINTERFACE:
      stringBuilder.append("INVOKEINTERFACE");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESPECIAL:
      stringBuilder.append("INVOKESPECIAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKESTATIC:
      stringBuilder.append("INVOKESTATIC");
      isMethodHandle = true;
      break;
    case Opcodes.H_INVOKEVIRTUAL:
      stringBuilder.append("INVOKEVIRTUAL");
      isMethodHandle = true;
      break;
    case Opcodes.H_NEWINVOKESPECIAL:
      stringBuilder.append("NEWINVOKESPECIAL");
      isMethodHandle = true;
      break;
    default:
      throw new IllegalArgumentException();
  }
  stringBuilder.append('\n');
  stringBuilder.append(tab3);
  appendDescriptor(INTERNAL_NAME, handle.getOwner());
  stringBuilder.append('.');
  stringBuilder.append(handle.getName());
  if (!isMethodHandle) {
    stringBuilder.append('(');
  }
  appendDescriptor(HANDLE_DESCRIPTOR, handle.getDesc());
  if (!isMethodHandle) {
    stringBuilder.append(')');
  }
  if (handle.isInterface()) {
    stringBuilder.append(" itf");
  }
}