Commit 8c7c5667 authored by Lukáš Marek's avatar Lukáš Marek

Moved dynamic bypass into separate directory

Dynamic bypass after bootstrap code in separate directory
Other improvements
parent ffa847a4
package ch.usi.dag.dynamicbypass;
public class DynamicBypassCheck {
// this version is executed after bootstrap phase
// and is it the replacement for version in src-dynbypass directory
public static boolean executeUninstrumente() {
return DynamicBypass.isActivated();
}
}
package ch.usi.dag.dynamicbypass;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.instrument.ClassDefinition;
import java.lang.instrument.Instrumentation;
public class Bootstrap {
public static void completed(Instrumentation instr) {
try {
// get class loader
ClassLoader cl = Bootstrap.class.getClassLoader();
// find our class in resources
InputStream dbcIS =
cl.getResourceAsStream("DynamicBypass-DynamicBypassCheck");
byte[] newDBCCode = loadAsBytes(dbcIS);
instr.redefineClasses(new ClassDefinition(DynamicBypassCheck.class, newDBCCode));
} catch (Exception e) {
e.printStackTrace();
}
}
// thx: http://www.java2s.com/Tutorial/Java/0180__File/Loadfiletobytearray.htm
public final static byte[] loadAsBytes(InputStream is) throws IOException {
byte readBuf[] = new byte[512 * 1024];
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readCnt = is.read(readBuf);
while (0 < readCnt) {
bout.write(readBuf, 0, readCnt);
readCnt = is.read(readBuf);
}
is.close();
return bout.toByteArray();
}
}
......@@ -3,12 +3,9 @@ package ch.usi.dag.dynamicbypass;
public class DynamicBypassCheck {
// this version is executed before bootstrap phase
// and will be replaced by ...AfterBootstrap() after bootstrap
// it will be after bootstrap replaced by with version in src-dynbypass-a
// directory
public static boolean executeUninstrumented() {
return true;
}
public static boolean executeUninstrumentedAfterBootstrap() {
return DynamicBypass.isActivated();
}
}
package ch.usi.dag.dynamicbypass;
public class Bootstrap {
public static void completed() {
// TODO jb ! redefinition of DynamicBypassCheck
}
}
......@@ -10,7 +10,7 @@ public class JavaAgent {
Instrumentation instrumentation) {
if (!Boolean.getBoolean("jborat.noBootstrap")) {
Bootstrap.completed();
Bootstrap.completed(instrumentation);
}
}
}
package ch.usi.dag.disl.testtools.onplace;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import org.objectweb.asm.ClassReader;
......@@ -36,12 +40,7 @@ public class OnPlaceTransformer {
}
// get code as bytes
byte[] origCode = null;
/* TODO java 7 only
Path cttPath = FileSystems.getDefault().getPath(classToTransform);
origCode = Files.readAllBytes(cttPath);
/**/
byte[] origCode = loadAsBytes(classToTransform);
// check class first
ClassReader cr = new ClassReader(origCode);
......@@ -58,4 +57,27 @@ public class OnPlaceTransformer {
fos.close();
}
}
// thx: http://www.java2s.com/Tutorial/Java/0180__File/Loadfiletobytearray.htm
public final static byte[] loadAsBytes(String file) throws IOException {
FileInputStream fin = new FileInputStream(file);
return loadAsBytes(fin);
}
public final static byte[] loadAsBytes(InputStream is) throws IOException {
byte readBuf[] = new byte[512 * 1024];
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readCnt = is.read(readBuf);
while (0 < readCnt) {
bout.write(readBuf, 0, readCnt);
readCnt = is.read(readBuf);
}
is.close();
return bout.toByteArray();
}
}
......@@ -408,4 +408,8 @@ public class DiSL {
instrCN.accept(cw);
return cw.toByteArray();
}
public void terminate() {
}
}
......@@ -106,7 +106,7 @@ public abstract class ClassByteLoader {
private static String getClassesListFromManifest(ClassLoader classLoader)
throws IOException {
// get all manifests...
// get all manifests...
Enumeration<URL> resources = classLoader.getResources(MANIFEST);
// and find ours...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment