org.objectweb.asm.ConstantDynamic Java Examples
The following examples show how to use
org.objectweb.asm.ConstantDynamic.
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: JavaConstant.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Resolves this {@link Dynamic} constant to resolve the returned instance to the supplied type. The type must be a subtype of the * bootstrap method's return type. Constructors cannot be resolved to a different type. * * @param typeDescription The type to resolve the bootstrapped value to. * @return This dynamic constant but resolved to the supplied type. */ public JavaConstant withType(TypeDescription typeDescription) { if (typeDescription.represents(void.class)) { throw new IllegalArgumentException("Constant value cannot represent void"); } else if (value.getBootstrapMethod().getName().equals(MethodDescription.CONSTRUCTOR_INTERNAL_NAME) ? !this.typeDescription.isAssignableTo(typeDescription) : (!typeDescription.asBoxed().isInHierarchyWith(this.typeDescription.asBoxed()))) { throw new IllegalArgumentException(typeDescription + " is not compatible with bootstrapped type " + this.typeDescription); } Object[] bootstrapMethodArgument = new Object[value.getBootstrapMethodArgumentCount()]; for (int index = 0; index < value.getBootstrapMethodArgumentCount(); index++) { bootstrapMethodArgument[index] = value.getBootstrapMethodArgument(index); } return new Dynamic(new ConstantDynamic(value.getName(), typeDescription.getDescriptor(), value.getBootstrapMethod(), bootstrapMethodArgument), typeDescription); }
Example #2
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Returns a {@code static}, {@code final} field constant. * * @param fieldDescription The field to represent a value of. * @return A dynamically resolved field value constant. */ public static Dynamic ofField(FieldDescription.InDefinedShape fieldDescription) { if (!fieldDescription.isStatic() || !fieldDescription.isFinal()) { throw new IllegalArgumentException("Field must be static and final: " + fieldDescription); } boolean selfDeclared = fieldDescription.getType().isPrimitive() ? fieldDescription.getType().asErasure().asBoxed().equals(fieldDescription.getType().asErasure()) : fieldDescription.getDeclaringType().equals(fieldDescription.getType().asErasure()); return new Dynamic(new ConstantDynamic(fieldDescription.getInternalName(), fieldDescription.getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "getStaticFinal", selfDeclared ? "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;" : "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;", false), selfDeclared ? new Object[0] : new Object[]{Type.getType(fieldDescription.getDeclaringType().getDescriptor())}), fieldDescription.getType().asErasure()); }
Example #3
Source File: CodeSizeEvaluator.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (value instanceof Long || value instanceof Double || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { minSize += 3; maxSize += 3; } else { minSize += 2; maxSize += 3; } super.visitLdcInsn(value); }
Example #4
Source File: GeneratorAdapter.java From JReFrameworker with MIT License | 5 votes |
/** * Generates the instruction to push a constant dynamic on the stack. * * @param constantDynamic the constant dynamic to be pushed on the stack. */ public void push(final ConstantDynamic constantDynamic) { if (constantDynamic == null) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.visitLdcInsn(constantDynamic); } }
Example #5
Source File: AdviceAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (isConstructor && !superClassConstructorCalled) { pushValue(OTHER); if (value instanceof Double || value instanceof Long || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { pushValue(OTHER); } } }
Example #6
Source File: AdviceAdapter.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (stackFrameTracking) { pushValue(OTHER); if (value instanceof Double || value instanceof Long || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { pushValue(SECOND_WORD); } } }
Example #7
Source File: InstructionAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } }
Example #8
Source File: AnalyzerAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (this.locals == null) { labels = null; return; } if (value instanceof Integer) { push(Opcodes.INTEGER); } else if (value instanceof Long) { push(Opcodes.LONG); push(Opcodes.TOP); } else if (value instanceof Float) { push(Opcodes.FLOAT); } else if (value instanceof Double) { push(Opcodes.DOUBLE); push(Opcodes.TOP); } else if (value instanceof String) { push("java/lang/String"); } else if (value instanceof Type) { int sort = ((Type) value).getSort(); if (sort == Type.OBJECT || sort == Type.ARRAY) { push("java/lang/Class"); } else if (sort == Type.METHOD) { push("java/lang/invoke/MethodType"); } else { throw new IllegalArgumentException(); } } else if (value instanceof Handle) { push("java/lang/invoke/MethodHandle"); } else if (value instanceof ConstantDynamic) { pushDescriptor(((ConstantDynamic) value).getDescriptor()); } else { throw new IllegalArgumentException(); } labels = null; }
Example #9
Source File: CodeSizeEvaluator.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (value instanceof Long || value instanceof Double || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { minSize += 3; maxSize += 3; } else { minSize += 2; maxSize += 3; } super.visitLdcInsn(value); }
Example #10
Source File: Remapper.java From JReFrameworker with MIT License | 5 votes |
/** * Returns the given value, remapped with this remapper. Possible values are {@link Boolean}, * {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double}, * {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays * of primitive types . * * @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values * are remapped. * @return the given value, remapped with this remapper. */ public Object mapValue(final Object value) { if (value instanceof Type) { return mapType((Type) value); } if (value instanceof Handle) { Handle handle = (Handle) value; return new Handle( handle.getTag(), mapType(handle.getOwner()), mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()), handle.getTag() <= Opcodes.H_PUTSTATIC ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()), handle.isInterface()); } if (value instanceof ConstantDynamic) { ConstantDynamic constantDynamic = (ConstantDynamic) value; int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount(); Object[] remappedBootstrapMethodArguments = new Object[bootstrapMethodArgumentCount]; for (int i = 0; i < bootstrapMethodArgumentCount; ++i) { remappedBootstrapMethodArguments[i] = mapValue(constantDynamic.getBootstrapMethodArgument(i)); } String descriptor = constantDynamic.getDescriptor(); return new ConstantDynamic( mapInvokeDynamicMethodName(constantDynamic.getName(), descriptor), mapDesc(descriptor), (Handle) mapValue(constantDynamic.getBootstrapMethod()), remappedBootstrapMethodArguments); } return value; }
Example #11
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Returns a constant {@code null} value of type {@link Object}. * * @return A dynamically resolved null constant. */ public static Dynamic ofNullConstant() { return new Dynamic(new ConstantDynamic("nullConstant", TypeDescription.OBJECT.getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "nullConstant", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;", false)), TypeDescription.OBJECT); }
Example #12
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Returns a {@link Class} constant for a primitive type. * * @param typeDescription The primitive type to represent. * @return A dynamically resolved primitive type constant. */ public static JavaConstant ofPrimitiveType(TypeDescription typeDescription) { if (!typeDescription.isPrimitive()) { throw new IllegalArgumentException("Not a primitive type: " + typeDescription); } return new Dynamic(new ConstantDynamic(typeDescription.getDescriptor(), TypeDescription.CLASS.getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "primitiveClass", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;", false)), TypeDescription.CLASS); }
Example #13
Source File: GeneratorAdapter.java From JReFrameworker with MIT License | 5 votes |
/** * Generates the instruction to push a constant dynamic on the stack. * * @param constantDynamic the constant dynamic to be pushed on the stack. */ public void push(final ConstantDynamic constantDynamic) { if (constantDynamic == null) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.visitLdcInsn(constantDynamic); } }
Example #14
Source File: AdviceAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (isConstructor && !superClassConstructorCalled) { pushValue(OTHER); if (value instanceof Double || value instanceof Long || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { pushValue(OTHER); } } }
Example #15
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Returns a {@link Enum} value constant. * * @param enumerationDescription The enumeration value to represent. * @return A dynamically resolved enumeration constant. */ public static JavaConstant ofEnumeration(EnumerationDescription enumerationDescription) { return new Dynamic(new ConstantDynamic(enumerationDescription.getValue(), enumerationDescription.getEnumerationType().getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "enumConstant", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Enum;", false)), enumerationDescription.getEnumerationType()); }
Example #16
Source File: InstructionAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } }
Example #17
Source File: AnalyzerAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (this.locals == null) { labels = null; return; } if (value instanceof Integer) { push(Opcodes.INTEGER); } else if (value instanceof Long) { push(Opcodes.LONG); push(Opcodes.TOP); } else if (value instanceof Float) { push(Opcodes.FLOAT); } else if (value instanceof Double) { push(Opcodes.DOUBLE); push(Opcodes.TOP); } else if (value instanceof String) { push("java/lang/String"); } else if (value instanceof Type) { int sort = ((Type) value).getSort(); if (sort == Type.OBJECT || sort == Type.ARRAY) { push("java/lang/Class"); } else if (sort == Type.METHOD) { push("java/lang/invoke/MethodType"); } else { throw new IllegalArgumentException(); } } else if (value instanceof Handle) { push("java/lang/invoke/MethodHandle"); } else if (value instanceof ConstantDynamic) { pushDescriptor(((ConstantDynamic) value).getDescriptor()); } else { throw new IllegalArgumentException(); } labels = null; }
Example #18
Source File: Remapper.java From JReFrameworker with MIT License | 5 votes |
/** * Returns the given value, remapped with this remapper. Possible values are {@link Boolean}, * {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double}, * {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays * of primitive types . * * @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values * are remapped. * @return the given value, remapped with this remapper. */ public Object mapValue(final Object value) { if (value instanceof Type) { return mapType((Type) value); } if (value instanceof Handle) { Handle handle = (Handle) value; return new Handle( handle.getTag(), mapType(handle.getOwner()), mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()), handle.getTag() <= Opcodes.H_PUTSTATIC ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()), handle.isInterface()); } if (value instanceof ConstantDynamic) { ConstantDynamic constantDynamic = (ConstantDynamic) value; int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount(); Object[] remappedBootstrapMethodArguments = new Object[bootstrapMethodArgumentCount]; for (int i = 0; i < bootstrapMethodArgumentCount; ++i) { remappedBootstrapMethodArguments[i] = mapValue(constantDynamic.getBootstrapMethodArgument(i)); } String descriptor = constantDynamic.getDescriptor(); return new ConstantDynamic( mapInvokeDynamicMethodName(constantDynamic.getName(), descriptor), mapDesc(descriptor), (Handle) mapValue(constantDynamic.getBootstrapMethod()), remappedBootstrapMethodArguments); } return value; }
Example #19
Source File: InstructionAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException(); } if (api != Opcodes.ASM7_EXPERIMENTAL && value instanceof ConstantDynamic) { throw new UnsupportedOperationException(); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } }
Example #20
Source File: AnalyzerAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (this.locals == null) { labels = null; return; } if (value instanceof Integer) { push(Opcodes.INTEGER); } else if (value instanceof Long) { push(Opcodes.LONG); push(Opcodes.TOP); } else if (value instanceof Float) { push(Opcodes.FLOAT); } else if (value instanceof Double) { push(Opcodes.DOUBLE); push(Opcodes.TOP); } else if (value instanceof String) { push("java/lang/String"); } else if (value instanceof Type) { int sort = ((Type) value).getSort(); if (sort == Type.OBJECT || sort == Type.ARRAY) { push("java/lang/Class"); } else if (sort == Type.METHOD) { push("java/lang/invoke/MethodType"); } else { throw new IllegalArgumentException(); } } else if (value instanceof Handle) { push("java/lang/invoke/MethodHandle"); } else if (value instanceof ConstantDynamic) { pushDescriptor(((ConstantDynamic) value).getDescriptor()); } else { throw new IllegalArgumentException(); } labels = null; }
Example #21
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Resolves a var handle constant for a field. * * @param fieldDescription The field to represent a var handle for. * @return A dynamic constant that represents the created var handle constant. */ public static JavaConstant ofVarHandle(FieldDescription.InDefinedShape fieldDescription) { return new Dynamic(new ConstantDynamic(fieldDescription.getInternalName(), JavaType.VAR_HANDLE.getTypeStub().getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, fieldDescription.isStatic() ? "staticFieldVarHandle" : "fieldVarHandle", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/invoke/VarHandle;", false), Type.getType(fieldDescription.getDeclaringType().getDescriptor()), Type.getType(fieldDescription.getType().asErasure().getDescriptor())), JavaType.VAR_HANDLE.getTypeStub()); }
Example #22
Source File: GeneratorAdapter.java From Concurnas with MIT License | 5 votes |
/** * Generates the instruction to push a constant dynamic on the stack. * * @param constantDynamic the constant dynamic to be pushed on the stack. */ public void push(final ConstantDynamic constantDynamic) { if (constantDynamic == null) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.visitLdcInsn(constantDynamic); } }
Example #23
Source File: AdviceAdapter.java From Concurnas with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (isConstructor && !superClassConstructorCalled) { pushValue(OTHER); if (value instanceof Double || value instanceof Long || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { pushValue(OTHER); } } }
Example #24
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Resolves a var handle constant for an array. * * @param typeDescription The array type for which the var handle is resolved. * @return A dynamic constant that represents the created var handle constant. */ public static JavaConstant ofArrayVarHandle(TypeDescription typeDescription) { if (!typeDescription.isArray()) { throw new IllegalArgumentException("Not an array type: " + typeDescription); } return new Dynamic(new ConstantDynamic("arrayVarHandle", JavaType.VAR_HANDLE.getTypeStub().getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "arrayVarHandle", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/invoke/VarHandle;", false), Type.getType(typeDescription.getDescriptor())), JavaType.VAR_HANDLE.getTypeStub()); }
Example #25
Source File: InstructionAdapter.java From Concurnas with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } }
Example #26
Source File: AnalyzerAdapter.java From Concurnas with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { super.visitLdcInsn(value); if (this.locals == null) { labels = null; return; } if (value instanceof Integer) { push(Opcodes.INTEGER); } else if (value instanceof Long) { push(Opcodes.LONG); push(Opcodes.TOP); } else if (value instanceof Float) { push(Opcodes.FLOAT); } else if (value instanceof Double) { push(Opcodes.DOUBLE); push(Opcodes.TOP); } else if (value instanceof String) { push("java/lang/String"); } else if (value instanceof Type) { int sort = ((Type) value).getSort(); if (sort == Type.OBJECT || sort == Type.ARRAY) { push("java/lang/Class"); } else if (sort == Type.METHOD) { push("java/lang/invoke/MethodType"); } else { throw new IllegalArgumentException(); } } else if (value instanceof Handle) { push("java/lang/invoke/MethodHandle"); } else if (value instanceof ConstantDynamic) { pushDescriptor(((ConstantDynamic) value).getDescriptor()); } else { throw new IllegalArgumentException(); } labels = null; }
Example #27
Source File: CodeSizeEvaluator.java From Concurnas with MIT License | 5 votes |
@Override public void visitLdcInsn(final Object value) { if (value instanceof Long || value instanceof Double || (value instanceof ConstantDynamic && ((ConstantDynamic) value).getSize() == 2)) { minSize += 3; maxSize += 3; } else { minSize += 2; maxSize += 3; } super.visitLdcInsn(value); }
Example #28
Source File: Remapper.java From Concurnas with MIT License | 5 votes |
/** * Returns the given value, remapped with this remapper. Possible values are {@link Boolean}, * {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double}, * {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays * of primitive types . * * @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values * are remapped. * @return the given value, remapped with this remapper. */ public Object mapValue(final Object value) { if (value instanceof Type) { return mapType((Type) value); } if (value instanceof Handle) { Handle handle = (Handle) value; return new Handle( handle.getTag(), mapType(handle.getOwner()), mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()), handle.getTag() <= Opcodes.H_PUTSTATIC ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()), handle.isInterface()); } if (value instanceof ConstantDynamic) { ConstantDynamic constantDynamic = (ConstantDynamic) value; int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount(); Object[] remappedBootstrapMethodArguments = new Object[bootstrapMethodArgumentCount]; for (int i = 0; i < bootstrapMethodArgumentCount; ++i) { remappedBootstrapMethodArguments[i] = mapValue(constantDynamic.getBootstrapMethodArgument(i)); } String descriptor = constantDynamic.getDescriptor(); return new ConstantDynamic( mapInvokeDynamicMethodName(constantDynamic.getName(), descriptor), mapDesc(descriptor), (Handle) mapValue(constantDynamic.getBootstrapMethod()), remappedBootstrapMethodArguments); } return value; }
Example #29
Source File: BasicInterpreter.java From JReFrameworker with MIT License | 4 votes |
@Override public BasicValue newOperation(final AbstractInsnNode insn) throws AnalyzerException { switch (insn.getOpcode()) { case ACONST_NULL: return newValue(NULL_TYPE); case ICONST_M1: case ICONST_0: case ICONST_1: case ICONST_2: case ICONST_3: case ICONST_4: case ICONST_5: return BasicValue.INT_VALUE; case LCONST_0: case LCONST_1: return BasicValue.LONG_VALUE; case FCONST_0: case FCONST_1: case FCONST_2: return BasicValue.FLOAT_VALUE; case DCONST_0: case DCONST_1: return BasicValue.DOUBLE_VALUE; case BIPUSH: case SIPUSH: return BasicValue.INT_VALUE; case LDC: Object value = ((LdcInsnNode) insn).cst; if (value instanceof Integer) { return BasicValue.INT_VALUE; } else if (value instanceof Float) { return BasicValue.FLOAT_VALUE; } else if (value instanceof Long) { return BasicValue.LONG_VALUE; } else if (value instanceof Double) { return BasicValue.DOUBLE_VALUE; } else if (value instanceof String) { return newValue(Type.getObjectType("java/lang/String")); } else if (value instanceof Type) { int sort = ((Type) value).getSort(); if (sort == Type.OBJECT || sort == Type.ARRAY) { return newValue(Type.getObjectType("java/lang/Class")); } else if (sort == Type.METHOD) { return newValue(Type.getObjectType("java/lang/invoke/MethodType")); } else { throw new AnalyzerException(insn, "Illegal LDC value " + value); } } else if (value instanceof Handle) { return newValue(Type.getObjectType("java/lang/invoke/MethodHandle")); } else if (value instanceof ConstantDynamic) { return newValue(Type.getType(((ConstantDynamic) value).getDescriptor())); } else { throw new AnalyzerException(insn, "Illegal LDC value " + value); } case JSR: return BasicValue.RETURNADDRESS_VALUE; case GETSTATIC: return newValue(Type.getType(((FieldInsnNode) insn).desc)); case NEW: return newValue(Type.getObjectType(((TypeInsnNode) insn).desc)); default: throw new AssertionError(); } }
Example #30
Source File: JavaConstant.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * Represents a constant that is resolved by invoking a {@code static} factory method or a constructor. * * @param methodDescription The method or constructor to invoke to create the represented constant value. * @param constants The constant values passed to the bootstrap method. Values can be represented either * as {@link TypeDescription}, as {@link JavaConstant}, as {@link String} or a primitive * {@code int}, {@code long}, {@code float} or {@code double} represented as wrapper type. * @return A dynamic constant that is resolved by the supplied factory method or constructor. */ public static Dynamic ofInvocation(MethodDescription.InDefinedShape methodDescription, List<?> constants) { if (!methodDescription.isConstructor() && methodDescription.getReturnType().represents(void.class)) { throw new IllegalArgumentException("Bootstrap method is no constructor or non-void static factory: " + methodDescription); } else if (methodDescription.getParameters().size() + (methodDescription.isStatic() || methodDescription.isConstructor() ? 0 : 1) != constants.size()) { throw new IllegalArgumentException("Cannot assign " + constants + " to " + methodDescription); } List<Object> arguments = new ArrayList<Object>(constants.size()); arguments.add(new Handle(methodDescription.isConstructor() ? Opcodes.H_NEWINVOKESPECIAL : Opcodes.H_INVOKESTATIC, methodDescription.getDeclaringType().getInternalName(), methodDescription.getInternalName(), methodDescription.getDescriptor(), false)); Iterator<TypeDescription> iterator = (methodDescription.isStatic() || methodDescription.isConstructor() ? methodDescription.getParameters().asTypeList().asErasures() : CompoundList.of(methodDescription.getDeclaringType(), methodDescription.getParameters().asTypeList().asErasures())).iterator(); for (Object constant : constants) { TypeDescription typeDescription; if (constant instanceof JavaConstant) { arguments.add(((JavaConstant) constant).asConstantPoolValue()); typeDescription = ((JavaConstant) constant).getType(); } else if (constant instanceof TypeDescription) { arguments.add(Type.getType(((TypeDescription) constant).getDescriptor())); typeDescription = TypeDescription.CLASS; } else { arguments.add(constant); typeDescription = TypeDescription.ForLoadedType.of(constant.getClass()).asUnboxed(); if (JavaType.METHOD_TYPE.isInstance(constant) || JavaType.METHOD_HANDLE.isInstance(constant)) { throw new IllegalArgumentException("Must be represented as a JavaConstant instance: " + constant); } else if (constant instanceof Class<?>) { throw new IllegalArgumentException("Must be represented as a TypeDescription instance: " + constant); } else if (!typeDescription.isCompileTimeConstant()) { throw new IllegalArgumentException("Not a compile-time constant: " + constant); } } if (!typeDescription.isAssignableTo(iterator.next())) { throw new IllegalArgumentException("Cannot assign " + constants + " to " + methodDescription); } } return new Dynamic(new ConstantDynamic("invoke", (methodDescription.isConstructor() ? methodDescription.getDeclaringType() : methodDescription.getReturnType().asErasure()).getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "invoke", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/invoke/MethodHandle;[Ljava/lang/Object;)Ljava/lang/Object;", false), arguments.toArray()), methodDescription.isConstructor() ? methodDescription.getDeclaringType() : methodDescription.getReturnType().asErasure()); }