/** * Check if we can instrument the given class * * @param className * a {@link java.lang.String} object. * @return a boolean. */ public static boolean checkIfCanInstrument(String className) { return RuntimeInstrumentation.checkIfCanInstrument(className); }
/** {@inheritDoc} */ @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { if ((opcode == Opcodes.PUTSTATIC || opcode == Opcodes.GETSTATIC) && !(className.equals(owner) && methodName.equals("<clinit>")) && !(className.equals(owner) && methodName.equals(ClassResetter.STATIC_RESET))) { String classNameWithDots = owner.replace('/', '.'); if (RuntimeInstrumentation.checkIfCanInstrument(classNameWithDots)) { String executionTracerClassName = ExecutionTracer.class.getName().replace('.', '/'); String executionTracerDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class), Type.getType(String.class)); super.visitLdcInsn(classNameWithDots); super.visitLdcInsn(name); if (opcode == Opcodes.PUTSTATIC) super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, PASSED_PUT_STATIC, executionTracerDescriptor, false); else super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, PASSED_GET_STATIC, executionTracerDescriptor, false); } } super.visitFieldInsn(opcode, owner, name, desc); } }
/** {@inheritDoc} */ @Override public Class<?> loadClass(String name) throws ClassNotFoundException { if (!RuntimeInstrumentation.checkIfCanInstrument(name)) { Class<?> result = findLoadedClass(name); if (result != null) { return result; } result = classLoader.loadClass(name); return result; } Class<?> result = classes.get(name); if (result != null) { return result; } else { logger.info("Seeing class for first time: " + name); Class<?> instrumentedClass = instrumentClass(name); return instrumentedClass; } }
/** * {@inheritDoc} */ @Override public Class<?> loadClass(String name) throws ClassNotFoundException { if ("<evosuite>".equals(name)) throw new ClassNotFoundException(); //first check if already loaded if (!RuntimeInstrumentation.checkIfCanInstrument(name)) { Class<?> result = findLoadedClass(name); if (result != null) { return result; } result = classLoader.loadClass(name); return result; } Class<?> result = classes.get(name); if (result != null) { return result; } else { logger.info("Seeing class for first time: " + name); Class<?> instrumentedClass = instrumentClass(name); return instrumentedClass; } }
@Override public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { String classWithDots = className.replace('/', '.'); if(!active || !RuntimeInstrumentation.checkIfCanInstrument(classWithDots) || classWithDots.startsWith(PackageInfo.getEvoSuitePackage())){ return classfileBuffer; } else { //ClassResetter.getInstance().setClassLoader(loader); ClassReader reader = new ClassReader(classfileBuffer); synchronized(instrumentedClasses){ instrumentedClasses.add(classWithDots); } logger.debug("Going to instrument: "+classWithDots); if(instrumenter.isAlreadyInstrumented(new ClassReader(classfileBuffer))) { logger.debug("Skipping transformation of {} as it is already instrumented", classWithDots); return classfileBuffer; } return instrumenter.transformBytes(loader, className, reader, false); // TODO: Need to set skip instrumentation for test class } }
if (!RuntimeInstrumentation.checkIfCanInstrument(name)) { Class<?> result = findLoadedClass(name); if (result != null) {
if (!checkIfCanInstrument(classNameWithDots)) { throw new IllegalArgumentException("Should not transform a shared class (" + classNameWithDots + ")! Load by parent (JVM) classloader.");