Type[] args = Type.getArgumentTypes(desc); for(int i=0;i<t.getSize();i++) { simulatedStack.poll(); if (!Type.getReturnType(desc).equals(Type.VOID_TYPE)) { simulatedStack.push(Boolean.FALSE);
if (left.equals(right)) { return true; } else if(isObjectOrAnyType(left)) { int sort2 = right.getSort(); return (sort2 == Type.OBJECT || sort2 == Type.ARRAY); } if (right.getSort() != Type.ARRAY) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { clzLeft = cl.loadClass(left.getClassName()); } catch (Throwable e) { System.err.println("btrace ERR"); clzRight = cl.loadClass(left.getClassName()); } catch (Throwable e) { System.err.println("btrace ERR");
switch (type.getSort()) { case Type.BOOLEAN: case Type.CHAR: break; case Type.ARRAY: t = type.getDescriptor(); break; t = type.getInternalName(); break; memento.nextLocal += type.getSize(); setLocalType(local, type); setFrameLocal(local, t); mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), local); newLocalIndices.add(local); return local;
public MethodInstrumentor(MethodVisitor mv, String parentClz, String superClz, int access, String name, String desc) { super(Opcodes.ASM4, mv); this.parentClz = parentClz; this.superClz = superClz; this.access = access; this.name = name; this.desc = desc; this.returnType = Type.getReturnType(desc); this.argumentTypes = Type.getArgumentTypes(desc); extraTypes = new HashMap<Integer, Type>(); }
/** * Creates a new {@link LocalVariablesSorter}. * * @param access access flags of the adapted method. * @param desc the method's descriptor (see {@link Type Type}). * @param mv the method visitor to which this adapter delegates calls. */ public LocalVariablesSorter( final int access, final String desc, final MethodVisitor mv, final Memento memento) { super(Opcodes.ASM4, mv); this.memento = memento; Type[] args = Type.getArgumentTypes(desc); memento.nextLocal = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0; for (int i = 0; i < args.length; i++) { memento.nextLocal += args[i].getSize(); } memento.firstLocal = memento.nextLocal; }
private int generateClinit(MethodVisitor mv) { Type clazz = Type.getType("L" + cname + ";"); // the client name (the BTrace script class name) mv.visitLdcInsn(runtime); // the name of the currently processed class mv.visitLdcInsn(clazz); // NOI18N // invocatio nof BTraceRuntime.retransform() method mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(BTraceRuntime.class), "retransform", "(Ljava/lang/String;Ljava/lang/Class;)V"); // NOI18N return clazz.getSize() + Type.getType(String.class).getSize(); } }
Type[] calledMethodArgs = Type.getArgumentTypes(desc); addExtraTypeInfo(om.getSelfParameter(), Type.getObjectType(className)); if (where == Where.AFTER) { addExtraTypeInfo(om.getReturnParameter(), Type.getReturnType(desc)); backupArgsIndexes = backupStack(lvs, Type.getArgumentTypes(desc), isStaticCall); if (where == Where.BEFORE) { injectBtrace(vr, method, Type.getArgumentTypes(desc), Type.getReturnType(desc)); restoreStack(backupArgsIndexes, Type.getArgumentTypes(desc), isStaticCall); } finally { lvs.unfreeze();
public static boolean isAnyTypeArray(Type t) { return t.equals(anyTypeArray); }
private void callAction() { if (isStatic() && om.getSelfParameter() > -1) { return; // invalid combination; a static method can not provide *this* } Type[] calledMethodArgs = Type.getArgumentTypes(getDescriptor()); addExtraTypeInfo(om.getSelfParameter(), Type.getObjectType(className)); ValidationResult vr = validateArguments(om, isStatic(), actionArgTypes, calledMethodArgs); if (vr.isValid()) { injectBtrace(vr); } }
@Override public void visitEnd() { if (isExtension) { MethodVisitor mv = visitMethod(Opcodes.ACC_STATIC, CLINIT, "()V", null, null); mv.visitCode(); for(InitializerBlock ib : initBlocks) { ib.apply(mv); } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(Type.getType(BTraceRuntimeBridge.class).getSize(), 0); mv.visitEnd(); } super.visitEnd(); } }
private void injectBtrace(ValidationResult vr) { lvs.freeze(); try { ArgumentProvider[] actionArgs = new ArgumentProvider[actionArgTypes.length + 3]; int ptr = isStatic() ? 0 : 1; for(int i=0;i<vr.getArgCnt();i++) { int index = vr.getArgIdx(i); Type t = actionArgTypes[index]; if (TypeUtils.isAnyTypeArray(t)) { actionArgs[i] = new AnyTypeArgProvider(index, ptr); ptr++; } else { actionArgs[i] = new LocalVarArgProvider(index, t, ptr); ptr += actionArgTypes[index].getSize(); } } actionArgs[actionArgTypes.length] = new ConstantArgProvider(om.getMethodParameter(), getName(om.isMethodFqn())); actionArgs[actionArgTypes.length + 1] = new ConstantArgProvider(om.getClassNameParameter(), className.replace("/", ".")); actionArgs[actionArgTypes.length + 2] = new LocalVarArgProvider(om.getSelfParameter(), Type.getObjectType(className), 0); loadArguments(actionArgs); invokeBTraceAction(this, om); } finally { lvs.unfreeze(); } }
protected int newLocalMapping(final Type type) { int local = getNextLocal(); memento.nextLocal += type.getSize(); return local; }
public void doProvide() { push(myArgTypes.length); visitTypeInsn(ANEWARRAY, TypeUtils.objectType.getInternalName()); for (int j = 0; j < myArgTypes.length; j++) { dup(); push(j); Type argType = myArgTypes[j]; loadLocal(argType, argPtr); box(argType); arrayStore(TypeUtils.objectType); argPtr += argType.getSize(); } }
inlineConcatLevel--; } else if (!Type.getInternalName(StringBuilder.class).equals(owner) || inlineConcatLevel == 0) { Type[] args = Type.getArgumentTypes(desc); switch (opcode) { case INVOKEVIRTUAL: if ((inlineConcatLevel == 0 || !Type.getInternalName(StringBuilder.class).equals(owner)) && !ctValidator.isCallTargetValid(owner, name, args.length)) { reportError("no.method.calls", owner + "." + name + desc);
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { className = name; this.superName = superName; classType = Type.getObjectType(className); classInitializerFound = false; super.visit(version, access, name, signature, superName, interfaces); }
@Override protected void onAfterPutField(int opcode, String owner, String name, String desc) { if (om.getTargetInstanceParameter() != -1 && isStaticAccess) { return; } if (where == Where.AFTER && matches(targetClassName, owner.replace('/', '.')) && matches(targetFieldName, name)) { Type fieldType = Type.getType(desc); addExtraTypeInfo(om.getSelfParameter(), Type.getObjectType(className)); ValidationResult vr = validateArguments(om, isStatic(), actionArgTypes, new Type[]{fieldType}); if (vr.isValid()) { lvs.freeze(); try { loadArguments( new LocalVarArgProvider(vr.getArgIdx(0), fieldType, fldValueIndex), new LocalVarArgProvider(om.getTargetInstanceParameter(), TypeUtils.objectType, calledInstanceIndex), new ConstantArgProvider(om.getTargetMethodOrFieldParameter(), targetFieldName), new ConstantArgProvider(om.getClassNameParameter(), className.replace("/", ".")), new ConstantArgProvider(om.getMethodParameter(), getName(om.isMethodFqn())), new LocalVarArgProvider(om.getSelfParameter(), Type.getObjectType(className), 0)); invokeBTraceAction(this, om); } finally { lvs.unfreeze(); } } } } };// </editor-fold>
private boolean typeMatches(String decl, String desc) { // empty type declaration matches any method signature if (decl.isEmpty()) { return true; } else { String d = TypeUtils.declarationToDescriptor(decl); Type[] args1 = Type.getArgumentTypes(d); Type[] args2 = Type.getArgumentTypes(desc); return TypeUtils.isCompatible(args1, args2); } }
@Override public void visitEnd() { if ((access & ACC_PUBLIC) == 0 && !methodName.equals(CLASS_INITIALIZER)) { if (asBTrace) { // only btrace handlers are enforced to be public reportError("method.should.be.public", methodName + methodDesc); } } if (Type.getReturnType(methodDesc) != Type.VOID_TYPE) { if (asBTrace) { reportError("return.type.should.be.void", methodName + methodDesc); } } super.visitEnd(); }
String annoName = Type.getType(desc).getClassName(); for (String name : annotationClasses) { if (annoName.equals(name)) {
public void visitLdcInsn(Object cst) { if (cst instanceof Type) { String name = ((Type)cst).getInternalName(); if (name.equals(oldName)) { cst = Type.getType(newNameDesc); } } super.visitLdcInsn(cst); }