diff --git a/src/main/java/fr/inria/align/treediff/FastRemoteReader.java b/src/main/java/fr/inria/align/treediff/FastRemoteReader.java index 707632c..8a34f2a 100644 --- a/src/main/java/fr/inria/align/treediff/FastRemoteReader.java +++ b/src/main/java/fr/inria/align/treediff/FastRemoteReader.java @@ -10,16 +10,6 @@ public class FastRemoteReader { - /*public static void main(String arg[]) throws InterruptedException { - FastRemoteReader r = new FastRemoteReader(); - r.logger = FastLogger.getInstance(); - File dd = new File("/home/nharrand/Documents/helloworld"); - r.dir = new File(dd,"d2"); - r.logger.setLogFile(new File("out.json")); - r.read(); - r.logger.flush(); - }*/ - public FastRemoteReader(FastTracking logger, File inTraceDir) { this.logger = logger; this.dir= inTraceDir; diff --git a/src/main/java/fr/inria/yajta/api/AbstractTracer.java b/src/main/java/fr/inria/yajta/api/AbstractTracer.java new file mode 100644 index 0000000..7ac9f0f --- /dev/null +++ b/src/main/java/fr/inria/yajta/api/AbstractTracer.java @@ -0,0 +1,71 @@ +package fr.inria.yajta.api; + +import javassist.CannotCompileException; +import javassist.ClassPool; +import javassist.CtBehavior; +import javassist.CtClass; +import javassist.NotFoundException; + +import java.net.URL; + +public abstract class AbstractTracer { + + public boolean verbose = false; + ClassList cl; + ClassPool pool = ClassPool.getDefault(); + + public byte[] transform( final ClassLoader loader, final String className, final Class clazz, + final java.security.ProtectionDomain domain, final byte[] bytes ) { + //if(verbose) System.out.println("className: " + className + " ? "); + URL classURL = loader.getResource(className + ".class"); + String classFilePath = classURL == null ? null : classURL.getFile().replace("file:",""); + if(classFilePath == null || !cl.isInJars(classFilePath)) return bytes; + if(verbose) System.out.println("className: " + className + " -> " + cl.isToBeProcessed(className)); + if( cl.isToBeProcessed(className) ) { + return doClass( className, clazz, bytes ); + } else { + return bytes; + } + } + + public byte[] doClass( final String name, final Class clazz, byte[] b ) { + CtClass cl = null; + try { + cl = pool.makeClass( new java.io.ByteArrayInputStream( b ) ); + if( cl.isInterface() == false ) { + + doClass(cl,name); + + b = cl.toBytecode(); + + if(verbose) System.err.println( "-> Instrument " + name); + } + } catch( Exception e ) { + if(verbose) System.err.println( "Could not instrument " + name + ", exception : " + e.getMessage() ); + } finally { + + if( cl != null ) { + cl.detach(); + } + } + + return b; + } + + public void doClass(CtClass cl, String name) throws NotFoundException, CannotCompileException { + CtBehavior[] methods = cl.getDeclaredBehaviors(); + + for( int i = 0; i < methods.length; i++ ) { + + if( methods[i].isEmpty() == false ) { + doMethod( methods[i] , name); + } + } + } + + private void doMethod( final CtBehavior method , String className) throws NotFoundException, CannotCompileException { + doMethod(method,className,false,null); + } + + abstract void doMethod( final CtBehavior method , String className, boolean isIsotope, String isotope) throws NotFoundException, CannotCompileException; +} diff --git a/src/main/java/fr/inria/yajta/api/FastTracer.java b/src/main/java/fr/inria/yajta/api/FastTracer.java index 32953cd..a9d9905 100644 --- a/src/main/java/fr/inria/yajta/api/FastTracer.java +++ b/src/main/java/fr/inria/yajta/api/FastTracer.java @@ -23,17 +23,14 @@ import java.lang.reflect.Method; import java.net.URL; -public class FastTracer implements TracerI { +public class FastTracer extends AbstractTracer implements TracerI { - public boolean verbose = false; public boolean strictIncludes = false; - ClassList cl; String loggerInstance; FastTracking realLoggerInstance; boolean logValue = false; boolean logBranch = false; - ClassPool pool = ClassPool.getDefault(); public FastTracer (ClassList cl) { @@ -70,44 +67,6 @@ public boolean implementsInterface(Class cl, Class interf) { return false; } - public byte[] transform( final ClassLoader loader, final String className, final Class clazz, - final java.security.ProtectionDomain domain, final byte[] bytes ) { - //if(verbose) System.out.println("className: " + className + " ? "); - URL classURL = loader.getResource(className + ".class"); - String classFilePath = classURL == null ? null : classURL.getFile().replace("file:",""); - if(classFilePath == null || !cl.isInJars(classFilePath)) return bytes; - if(verbose) System.out.println("className: " + className + " -> " + cl.isToBeProcessed(className)); - if( cl.isToBeProcessed(className) ) { - return doClass( className, clazz, bytes ); - } else { - return bytes; - } - } - - public byte[] doClass( final String name, final Class clazz, byte[] b ) { - CtClass cl = null; - try { - cl = pool.makeClass( new java.io.ByteArrayInputStream( b ) ); - if( cl.isInterface() == false ) { - - doClass(cl,name); - - b = cl.toBytecode(); - - if(verbose) System.err.println( "-> Instrument " + name); - } - } catch( Exception e ) { - if(verbose) System.err.println( "Could not instrument " + name + ", exception : " + e.getMessage() ); - } finally { - - if( cl != null ) { - cl.detach(); - } - } - - return b; - } - @Override public void setTrackingClass(Class trackingClass) throws MalformedTrackingClassException { throw new UnsupportedOperationException("FastTracer only supports TracingInstance that implements FastTracking"); @@ -154,21 +113,6 @@ public void setTrackingClass(Class trackingClass, FastTr this.realLoggerInstance = realLoggerInstance; } - public void doClass(CtClass cl, String name) throws NotFoundException, CannotCompileException { - CtBehavior[] methods = cl.getDeclaredBehaviors(); - - for( int i = 0; i < methods.length; i++ ) { - - if( methods[i].isEmpty() == false ) { - doMethod( methods[i] , name); - } - } - } - - private void doMethod( final CtBehavior method , String className) throws NotFoundException, CannotCompileException { - doMethod(method,className,false,null); - } - private Bytecode getBytecode(String print, CtClass cc) throws CompileError { Javac jv = new Javac(cc); jv.compileStmnt(print); @@ -209,7 +153,7 @@ private boolean isBlockEmpty(CodeIterator iterator, int begin, int end) { return true; } - private void doMethod( final CtBehavior method , String className, boolean isIsotope, String isotope) throws NotFoundException, CannotCompileException { + protected void doMethod( final CtBehavior method , String className, boolean isIsotope, String isotope) throws NotFoundException, CannotCompileException { if(!Modifier.isNative(method.getModifiers())) { if(verbose) System.err.println("[Vanilla] " + className + " " + method.getName()); String params = "("; diff --git a/src/main/java/fr/inria/yajta/api/FastTracking.java b/src/main/java/fr/inria/yajta/api/FastTracking.java index af62e43..3f662f6 100644 --- a/src/main/java/fr/inria/yajta/api/FastTracking.java +++ b/src/main/java/fr/inria/yajta/api/FastTracking.java @@ -1,6 +1,7 @@ package fr.inria.yajta.api; import java.io.File; +import java.lang.invoke.MethodHandles; /** * This interface can be extended by the user to create new logging structure. diff --git a/src/main/java/fr/inria/yajta/api/SimpleTracer.java b/src/main/java/fr/inria/yajta/api/SimpleTracer.java index bc81e88..8bb0543 100644 --- a/src/main/java/fr/inria/yajta/api/SimpleTracer.java +++ b/src/main/java/fr/inria/yajta/api/SimpleTracer.java @@ -26,17 +26,13 @@ import java.net.URL; import java.util.Arrays; -//public class SimpleTracer implements ClassFileTransformer { -public class SimpleTracer implements TracerI { +public class SimpleTracer extends AbstractTracer implements TracerI { - public boolean verbose = true; public boolean strictIncludes = false; - ClassList cl; String loggerInstance; boolean logValue = false; boolean logBranch = false; - ClassPool pool = ClassPool.getDefault(); public SimpleTracer (ClassList cl) { @@ -121,59 +117,6 @@ public void setFastTrackingClass(Class trackingClass) th throw new UnsupportedOperationException("SimpleTracer only supports TracingInstance that implements ValueTracking or Tracking"); } - public byte[] transform( final ClassLoader loader, final String className, final Class clazz, - final java.security.ProtectionDomain domain, final byte[] bytes ) { - if(verbose) System.out.println("className: " + className + " ? "); - URL classURL = loader.getResource(className + ".class"); - String classFilePath = classURL == null ? null : classURL.getFile().replace("file:",""); - if(classFilePath == null || !cl.isInJars(classFilePath)) return bytes; - if(verbose) System.out.println("className: " + className + " -> " + cl.isToBeProcessed(className)); - if( cl.isToBeProcessed(className) ) { - return doClass( className, clazz, bytes ); - } else { - return bytes; - } - } - - public byte[] doClass( final String name, final Class clazz, byte[] b ) { - CtClass cl = null; - try { - cl = pool.makeClass( new java.io.ByteArrayInputStream( b ) ); - if( cl.isInterface() == false ) { - - doClass(cl,name); - - b = cl.toBytecode(); - - if(verbose) System.err.println( "-> Instrument " + name); - } - } catch( Exception e ) { - if(verbose) System.err.println( "Could not instrument " + name + ", exception : " + e.getMessage() ); - } finally { - - if( cl != null ) { - cl.detach(); - } - } - - return b; - } - - public void doClass(CtClass cl, String name) throws NotFoundException, CannotCompileException { - CtBehavior[] methods = cl.getDeclaredBehaviors(); - - for( int i = 0; i < methods.length; i++ ) { - - if( methods[i].isEmpty() == false ) { - doMethod( methods[i] , name); - } - } - } - - private void doMethod( final CtBehavior method , String className) throws NotFoundException, CannotCompileException { - doMethod(method,className,false,null); - } - private Bytecode getBytecode(String print, CtClass cc) throws CompileError { Javac jv = new Javac(cc); jv.compileStmnt(print); @@ -214,7 +157,7 @@ private boolean isBlockEmpty(CodeIterator iterator, int begin, int end) { return true; } - private void doMethod( final CtBehavior method , String className, boolean isIsotope, String isotope) throws NotFoundException, CannotCompileException { + protected void doMethod( final CtBehavior method , String className, boolean isIsotope, String isotope) throws NotFoundException, CannotCompileException { //System.out.println("\t\tMethod: " + method.getLongName() + " -> " + !Modifier.isNative(method.getModifiers())); if(!Modifier.isNative(method.getModifiers())) { if(verbose) System.err.println("[Vanilla] " + className + " " + method.getName());