Skip to content

Commit

Permalink
Merge in release/1.3.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Dec 2, 2018
2 parents 6844d2c + 60c0554 commit 0f37ca3
Show file tree
Hide file tree
Showing 17 changed files with 735 additions and 255 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A safe, dynamic tracing tool for the Java platform

## Version
1.3.11.1 ([Release Page](https://github.com/jbachorik/btrace/releases/latest))
1.3.11.2 ([Release Page](https://github.com/btraceio/btrace/releases/latest))

_! NOTE: For the latest develop changes head to ['develop' branch](https://github.com/btraceio/btrace/tree/develop)_

Expand Down
2 changes: 1 addition & 1 deletion benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ questions.
<dependency>
<groupId>com.sun.tools.btrace</groupId>
<artifactId>btrace-client</artifactId>
<version>1.3.11.1</version>
<version>1.3.11.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.tools.btrace</groupId>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (!currentJvm.toString().startsWith("1.7")) {
}

group 'com.sun.tools.btrace'
version = '1.3.11.1'
version = '1.3.11.2'
description = 'BTrace - a safe, dynamic tracing tool for the Java platform'

sourceCompatibility = 7
Expand Down
2 changes: 1 addition & 1 deletion make/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ docs.dir=${project.dir}/docs
samples.dir=${project.dir}/samples
dist.dir=${project.dir}/dist
junit.jar=${test.lib.dir}/junit-4.6.jar
release.version=1.3.11.1
release.version=1.3.11.2
asm.version=5.2
maven.repo.local=../build/maven
15 changes: 13 additions & 2 deletions src/share/classes/com/sun/btrace/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,18 @@ public void attach(String pid, String agentPath, String sysCp, String bootCp) th
* to the command listener provided.
*/
public void submit(String fileName, byte[] code, String[] args,
CommandListener listener) throws IOException {
CommandListener listener) throws IOException {
submit("localhost", fileName,code, args, listener);
}

/**
* Submits the compiled BTrace .class to the VM
* attached and passes given command line arguments.
* Receives commands from the traced JVM and sends those
* to the command listener provided.
*/
public void submit(String host, String fileName, byte[] code, String[] args,
CommandListener listener) throws IOException {
if (sock != null) {
throw new IllegalStateException();
}
Expand All @@ -360,7 +371,7 @@ public void submit(String fileName, byte[] code, String[] args,
long timeout = System.currentTimeMillis() + 5000;
while (sock == null && System.currentTimeMillis() <= timeout) {
try {
sock = new Socket("localhost", port);
sock = new Socket(host, port);
} catch (ConnectException e) {
if (debug) {
debugPrint("server not yet available; retrying ...");
Expand Down
14 changes: 10 additions & 4 deletions src/share/classes/com/sun/btrace/client/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ public final class Main {
public static volatile boolean exiting;
private static boolean DEBUG;
private static boolean TRUSTED;
private static boolean DUMP_CLASSES;
private static boolean DUMP_CLASSES;
private static String OUTPUT_FILE;
private static String DUMP_DIR;
private static String PROBE_DESC_PATH;
public static final boolean TRACK_RETRANSFORM;
public static final int BTRACE_DEFAULT_PORT = 2020;
public static final String BTRACE_DEFAULT_HOST = "localhost";

private static final Console con;
private static final PrintWriter out;
Expand Down Expand Up @@ -84,10 +85,12 @@ private static PrintWriter getOutWriter(Console con) {

public static void main(String[] args) {
int port = BTRACE_DEFAULT_PORT;
String host = BTRACE_DEFAULT_HOST;
String classPath = ".";
String includePath = null;

int count = 0;
boolean hostDefined = false;
boolean portDefined = false;
boolean classpathDefined = false;
boolean includePathDefined = false;
Expand Down Expand Up @@ -149,6 +152,9 @@ public static void main(String[] args) {
statsdDef = args[++count];
} else if (args[count].equals("-v")) {
// already processed
} else if (args[count].equals("-host") && !hostDefined) {
host = args[++count];
hostDefined = true;
} else {
usage();
}
Expand Down Expand Up @@ -190,14 +196,14 @@ public static void main(String[] args) {
if (code == null) {
errorExit("BTrace compilation failed", 1);
}
client.attach(pid, null, classPath);
if (!hostDefined)
client.attach(pid, null, classPath);
registerExitHook(client);
if (con != null) {
registerSignalHandler(client);
}
if (isDebug()) debugPrint("submitting the BTrace program");
client.submit(fileName, code, btraceArgs,
createCommandListener(client));
client.submit(host, fileName, code, btraceArgs, createCommandListener(client));
} catch (IOException exp) {
errorExit(exp.getMessage(), 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ btrace.usage =\
-cp <path> Specify where to find user class files and annotation processors\n \
-I <path> Specify where to find include files\n \
-p <port> Specify port to which the btrace agent listens for clients\n \
-host <host> Specify host to which btrace client's socket connect \n \
-statsd <host[:port]> Specify the statsd server, if any

btrace.agent.usage =\
Expand Down
107 changes: 62 additions & 45 deletions src/share/classes/com/sun/btrace/runtime/BTraceTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -130,24 +131,35 @@ public Result matchClass(String className) {
}
}
private final DebugSupport debug;
private final ReentrantReadWriteLock setupLock = new ReentrantReadWriteLock();
private final Collection<BTraceProbe> probes = new ArrayList<>(3);
private final Filter filter = new Filter();

public BTraceTransformer(DebugSupport d) {
debug = d;
}

public final synchronized void register(BTraceProbe p) {
probes.add(p);
for(OnMethod om : p.onmethods()) {
filter.add(om);
public final void register(BTraceProbe p) {
try {
setupLock.writeLock().lock();
probes.add(p);
for(OnMethod om : p.onmethods()) {
filter.add(om);
}
} finally {
setupLock.writeLock().unlock();
}
}

public final synchronized void unregister(BTraceProbe p) {
probes.remove(p);
for(OnMethod om : p.onmethods()) {
filter.remove(om);
public final void unregister(BTraceProbe p) {
try {
setupLock.writeLock().lock();
probes.remove(p);
for(OnMethod om : p.onmethods()) {
filter.remove(om);
}
} finally {
setupLock.writeLock().unlock();
}
}

Expand All @@ -156,54 +168,59 @@ Filter getFilter() {
}

@Override
public synchronized byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (probes.isEmpty()) return null;
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
try {
setupLock.readLock().lock();
if (probes.isEmpty()) return null;

className = className != null ? className : "<anonymous>";
className = className != null ? className : "<anonymous>";

if ((loader == null || loader.equals(ClassLoader.getSystemClassLoader())) && isSensitiveClass(className)) {
if (isDebug()) {
debugPrint("skipping transform for BTrace class " + className); // NOI18N
if ((loader == null || loader.equals(ClassLoader.getSystemClassLoader())) && isSensitiveClass(className)) {
if (isDebug()) {
debugPrint("skipping transform for BTrace class " + className); // NOI18N
}
return null;
}
return null;
}

if (filter.matchClass(className) == Filter.Result.FALSE) return null;
if (filter.matchClass(className) == Filter.Result.FALSE) return null;

boolean entered = BTraceRuntime.enter();
try {
if (isDebug()) {
debug.dumpClass(className.replace('.', '/') + "_orig", classfileBuffer);
}
BTraceClassReader cr = InstrumentUtils.newClassReader(loader, classfileBuffer);
BTraceClassWriter cw = InstrumentUtils.newClassWriter(cr);
for(BTraceProbe p : probes) {
p.notifyTransform(className);
cw.addInstrumentor(p, loader);
}
byte[] transformed = cw.instrument();
if (transformed == null) {
// no instrumentation necessary
boolean entered = BTraceRuntime.enter();
try {
if (isDebug()) {
debugPrint("skipping class " + cr.getJavaClassName());
debug.dumpClass(className.replace('.', '/') + "_orig", classfileBuffer);
}
return classfileBuffer;
} else {
if (isDebug()) {
debugPrint("transformed class " + cr.getJavaClassName());
BTraceClassReader cr = InstrumentUtils.newClassReader(loader, classfileBuffer);
BTraceClassWriter cw = InstrumentUtils.newClassWriter(cr);
for(BTraceProbe p : probes) {
p.notifyTransform(className);
cw.addInstrumentor(p, loader);
}
byte[] transformed = cw.instrument();
if (transformed == null) {
// no instrumentation necessary
if (isDebug()) {
debugPrint("skipping class " + cr.getJavaClassName());
}
return classfileBuffer;
} else {
if (isDebug()) {
debugPrint("transformed class " + cr.getJavaClassName());
}
if (debug.isDumpClasses()) {
debug.dumpClass(className.replace('.', '/'), transformed);
}
}
if (debug.isDumpClasses()) {
debug.dumpClass(className.replace('.', '/'), transformed);
return transformed;
} catch (Throwable th) {
debugPrint(th);
throw th;
} finally {
if (entered) {
BTraceRuntime.leave();
}
}
return transformed;
} catch (Throwable th) {
debugPrint(th);
throw th;
} finally {
if (entered) {
BTraceRuntime.leave();
}
setupLock.readLock().unlock();
}
}

Expand Down
Loading

0 comments on commit 0f37ca3

Please sign in to comment.