use of org.objectweb.asm.Type in project robolectric by robolectric.
the class SandboxClassLoader method box.
public static void box(final Type type, ListIterator<AbstractInsnNode> instructions) {
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
return;
}
if (type == Type.VOID_TYPE) {
instructions.add(new InsnNode(ACONST_NULL));
} else {
Type boxed = getBoxedType(type);
instructions.add(new TypeInsnNode(NEW, boxed.getInternalName()));
if (type.getSize() == 2) {
// Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o
instructions.add(new InsnNode(DUP_X2));
instructions.add(new InsnNode(DUP_X2));
instructions.add(new InsnNode(POP));
} else {
// p -> po -> opo -> oop -> o
instructions.add(new InsnNode(DUP_X1));
instructions.add(new InsnNode(SWAP));
}
instructions.add(new MethodInsnNode(INVOKESPECIAL, boxed.getInternalName(), "<init>", "(" + type.getDescriptor() + ")V"));
}
}
use of org.objectweb.asm.Type in project elasticsearch by elastic.
the class EFunctionRef method write.
@Override
void write(MethodWriter writer, Globals globals) {
if (ref != null) {
writer.writeDebugInfo(location);
// convert MethodTypes to asm Type for the constant pool.
String invokedType = ref.invokedType.toMethodDescriptorString();
Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString());
Type interfaceType = Type.getMethodType(ref.interfaceMethodType.toMethodDescriptorString());
if (ref.needsBridges()) {
writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType, ref.implMethodASM, samMethodType, LambdaMetafactory.FLAG_BRIDGES, 1, interfaceType);
} else {
writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType, ref.implMethodASM, samMethodType, 0);
}
} else {
// TODO: don't do this: its just to cutover :)
writer.push((String) null);
}
}
use of org.objectweb.asm.Type in project elasticsearch by elastic.
the class PSubDefCall method write.
@Override
void write(MethodWriter writer, Globals globals) {
writer.writeDebugInfo(location);
List<Type> parameterTypes = new ArrayList<>();
// first parameter is the receiver, we never know its type: always Object
parameterTypes.add(Definition.DEF_TYPE.type);
// append each argument
for (AExpression argument : arguments) {
parameterTypes.add(argument.actual.type);
if (argument instanceof ILambda) {
ILambda lambda = (ILambda) argument;
for (Type capture : lambda.getCaptures()) {
parameterTypes.add(capture);
}
}
argument.write(writer, globals);
}
// create method type from return value and arguments
Type methodType = Type.getMethodType(actual.type, parameterTypes.toArray(new Type[0]));
List<Object> args = new ArrayList<>();
args.add(recipe.toString());
args.addAll(pointers);
writer.invokeDefCall(name, methodType, DefBootstrap.METHOD_CALL, args.toArray());
}
use of org.objectweb.asm.Type in project cglib by cglib.
the class EmitUtils method process_arrays.
/**
* Process two arrays on the stack in parallel. Assumes the top two items on the stack
* are arrays of the specified class. The arrays must be the same length. For each pair
* of elements in the arrays, puts the pair on the stack and triggers the callback.
* @param type the type of the arrays (type.isArray() must be true)
* @param callback the callback triggered for each pair of elements
*/
public static void process_arrays(CodeEmitter e, Type type, ProcessArrayCallback callback) {
Type componentType = TypeUtils.getComponentType(type);
Local array1 = e.make_local();
Local array2 = e.make_local();
Local loopvar = e.make_local(Type.INT_TYPE);
Label loopbody = e.make_label();
Label checkloop = e.make_label();
e.store_local(array1);
e.store_local(array2);
e.push(0);
e.store_local(loopvar);
e.goTo(checkloop);
e.mark(loopbody);
e.load_local(array1);
e.load_local(loopvar);
e.array_load(componentType);
e.load_local(array2);
e.load_local(loopvar);
e.array_load(componentType);
callback.processElement(componentType);
e.iinc(loopvar, 1);
e.mark(checkloop);
e.load_local(loopvar);
e.load_local(array1);
e.arraylength();
e.if_icmp(e.LT, loopbody);
}
use of org.objectweb.asm.Type in project cglib by cglib.
the class ReflectUtils method getClassInfo.
public static ClassInfo getClassInfo(final Class clazz) {
final Type type = Type.getType(clazz);
final Type sc = (clazz.getSuperclass() == null) ? null : Type.getType(clazz.getSuperclass());
return new ClassInfo() {
public Type getType() {
return type;
}
public Type getSuperType() {
return sc;
}
public Type[] getInterfaces() {
return TypeUtils.getTypes(clazz.getInterfaces());
}
public int getModifiers() {
return clazz.getModifiers();
}
};
}
Aggregations