Skip to content

Commit a552ede

Browse files
committed
avoid doing unnecessary work for non-instrumented classes
1 parent cc55144 commit a552ede

17 files changed

Lines changed: 271 additions & 212 deletions

benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ questions.
5858
<dependency>
5959
<groupId>com.sun.tools.btrace</groupId>
6060
<artifactId>btrace-agent</artifactId>
61-
<version>1.3.7</version>
61+
<version>1.3.8.2</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>com.sun.tools.btrace</groupId>

src/share/classes/com/sun/btrace/SharedSettings.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,19 @@ public void from(Map<String, Object> params) {
102102
}
103103

104104
public void from(SharedSettings other) {
105+
clientName = other.clientName;
105106
debug = other.debug;
106107
dumpDir = other.dumpDir;
107-
trackRetransforms = other.trackRetransforms;
108-
unsafe = other.unsafe;
109-
probeDescPath = other.probeDescPath;
110-
statsdHost = other.statsdHost;
111-
statsdPort = other.statsdPort;
112108
fileRollMilliseconds = other.fileRollMilliseconds;
113109
fileRollMaxRolls = other.fileRollMaxRolls;
114110
outputFile = other.outputFile;
115111
outputDir = other.outputDir;
116-
clientName = other.clientName;
112+
probeDescPath = other.probeDescPath;
113+
retransformStartup = other.retransformStartup;
114+
statsdHost = other.statsdHost;
115+
statsdPort = other.statsdPort;
116+
trackRetransforms = other.trackRetransforms;
117+
unsafe = other.unsafe;
117118
}
118119

119120
public boolean isDebug() {

src/share/classes/com/sun/btrace/agent/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private Client(Instrumentation inst, SharedSettings s, BTraceTransformer t) {
121121

122122
protected final void setupWriter() {
123123
String outputFile = settings.getOutputFile();
124-
if (outputFile == null) return;
124+
if (outputFile == null || outputFile.equals("::null")) return;
125125

126126
if (!outputFile.equals("::stdout")) {
127127
String outputDir = settings.getOutputDir();

src/share/classes/com/sun/btrace/agent/FileClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static byte[] readAll(File file) throws IOException {
100100
private static byte[] readAll(InputStream is, int size) throws IOException {
101101
if (is == null) throw new NullPointerException();
102102

103-
byte[] buf = new byte[size != -1 ? size : 1024];
103+
byte[] buf = new byte[size != -1 ? size : 8192];
104104
int bufsize = buf.length;
105105
int off = 0;
106106
int read;

src/share/classes/com/sun/btrace/runtime/Assembler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public Assembler addLevelCheck(String clsName, Level level, Label jmp) {
532532
}
533533

534534
public Assembler addLevelCheck(String clsName, Interval itv, Label jmp) {
535-
getStatic(clsName, "$btrace$$level", Type.INT_TYPE.getDescriptor());
535+
getStatic(clsName, "$btrace$$level", INT_DESC);
536536
if (itv.getA() <= 0) {
537537
if (itv.getB() != Integer.MAX_VALUE) {
538538
ldc(itv.getB());
@@ -545,7 +545,7 @@ public Assembler addLevelCheck(String clsName, Interval itv, Label jmp) {
545545
} else {
546546
ldc(itv.getA());
547547
jump(Opcodes.IF_ICMPLT, jmp);
548-
getStatic(clsName, "$btrace$$level", Type.INT_TYPE.getDescriptor());
548+
getStatic(clsName, "$btrace$$level", INT_DESC);
549549
ldc(itv.getB());
550550
jump(Opcodes.IF_ICMPGT, jmp);
551551
}
@@ -568,20 +568,20 @@ public Assembler compareLevel(String clsName, Level level) {
568568
if (itv.getA() <= 0) {
569569
if (itv.getB() != Integer.MAX_VALUE) {
570570
ldc(itv.getB());
571-
getStatic(clsName, "$btrace$$level", Type.INT_TYPE.getDescriptor());
571+
getStatic(clsName, BTRACE_LEVEL_FLD, INT_DESC);
572572
sub(Type.INT_TYPE);
573573
}
574574
} else if (itv.getA() < itv.getB()) {
575575
if (itv.getB() == Integer.MAX_VALUE) {
576-
getStatic(clsName, "$btrace$$level", Type.INT_TYPE.getDescriptor());
576+
getStatic(clsName, BTRACE_LEVEL_FLD, INT_DESC);
577577
ldc(itv.getA());
578578
sub(Type.INT_TYPE);
579579
} else {
580580
Label l1 = new Label();
581581
Label l2 = new Label();
582582
ldc(itv.getA());
583583
jump(Opcodes.IF_ICMPLT, l1);
584-
getStatic(clsName, "$btrace$$level", Type.INT_TYPE.getDescriptor());
584+
getStatic(clsName, BTRACE_LEVEL_FLD, INT_DESC);
585585
ldc(itv.getB());
586586
jump(Opcodes.IF_ICMPGT, l1);
587587
ldc(0);

src/share/classes/com/sun/btrace/runtime/BTraceClassWriter.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.Deque;
3030
import java.util.Iterator;
3131
import java.util.LinkedHashSet;
32-
import java.util.concurrent.ConcurrentLinkedDeque;
32+
import java.util.LinkedList;
3333

3434
/**
3535
* A hacked version of <a href="http://asm.ow2.org/asm50/javadoc/user/org/objectweb/asm/ClassWriter.html">ClassWriter</a>
@@ -38,7 +38,7 @@
3838
* @author Jaroslav Bachorik
3939
*/
4040
final class BTraceClassWriter extends ClassWriter {
41-
private final Deque<Instrumentor> instrumentors = new ConcurrentLinkedDeque<>();
41+
private final Deque<Instrumentor> instrumentors = new LinkedList<>();
4242
private final ClassLoader targetCL;
4343
private final BTraceClassReader cr;
4444

@@ -56,23 +56,27 @@ final class BTraceClassWriter extends ClassWriter {
5656

5757
public void addInstrumentor(BTraceProbe bp) {
5858
if (cr != null && bp != null) {
59-
Instrumentor top = instrumentors.peekLast();
60-
ClassVisitor parent = top != null ? top : this;
61-
Instrumentor i = Instrumentor.create(cr, bp, parent);
62-
if (i != null) {
63-
instrumentors.add(i);
59+
synchronized(instrumentors) {
60+
Instrumentor top = instrumentors.peekLast();
61+
ClassVisitor parent = top != null ? top : this;
62+
Instrumentor i = Instrumentor.create(cr, bp, parent);
63+
if (i != null) {
64+
instrumentors.add(i);
65+
}
6466
}
6567
}
6668
}
6769

6870
public byte[] instrument() {
69-
if (instrumentors.isEmpty()) return null;
70-
71-
ClassVisitor top = instrumentors.peekLast();
72-
InstrumentUtils.accept(cr, top != null ? top : this);
7371
boolean hit = false;
74-
for(Instrumentor i : instrumentors) {
75-
hit |= i.hasMatch();
72+
synchronized(instrumentors) {
73+
if (instrumentors.isEmpty()) return null;
74+
75+
ClassVisitor top = instrumentors.peekLast();
76+
InstrumentUtils.accept(cr, top != null ? top : this);
77+
for(Instrumentor i : instrumentors) {
78+
hit |= i.hasMatch();
79+
}
7680
}
7781
return hit ? this.toByteArray() : null;
7882
}

src/share/classes/com/sun/btrace/runtime/BTraceMethodNode.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@
2929
import com.sun.btrace.annotations.Where;
3030
import com.sun.btrace.org.objectweb.asm.AnnotationVisitor;
3131
import com.sun.btrace.org.objectweb.asm.Opcodes;
32-
import com.sun.btrace.org.objectweb.asm.Type;
3332
import static com.sun.btrace.runtime.Constants.*;
3433

3534
import com.sun.btrace.org.objectweb.asm.tree.MethodNode;
36-
import static com.sun.btrace.runtime.Verifier.BTRACE_DURATION_DESC;
37-
import static com.sun.btrace.runtime.Verifier.BTRACE_RETURN_DESC;
38-
import static com.sun.btrace.runtime.Verifier.BTRACE_SELF_DESC;
39-
import static com.sun.btrace.runtime.Verifier.BTRACE_TARGETINSTANCE_DESC;
40-
import static com.sun.btrace.runtime.Verifier.BTRACE_TARGETMETHOD_DESC;
4135
import java.util.Comparator;
4236
import java.util.List;
4337
import java.util.Set;
@@ -198,7 +192,7 @@ public void visit(String name, Object value) {
198192
}
199193
}
200194
};
201-
} else if (type.equals(SAMPLER_DESC)) {
195+
} else if (type.equals(SAMPLED_DESC)) {
202196
if (om != null) {
203197
om.setSamplerKind(Sampled.Sampler.Adaptive);
204198
return new AnnotationVisitor(Opcodes.ASM5, av) {
@@ -217,7 +211,7 @@ public void visit(String name, Object value) {
217211
public void visitEnum(String name, String desc, String value) {
218212
super.visitEnum(name, desc, value);
219213

220-
if (name.equals("kind") && desc.equals(Type.getDescriptor(Sampled.Sampler.class))) {
214+
if (name.equals("kind") && desc.equals(SAMPLER_DESC)) {
221215
om.setSamplerKind(Sampled.Sampler.valueOf(value));
222216
}
223217
}
@@ -310,7 +304,7 @@ OnProbe getOnProbe() {
310304

311305
private AnnotationVisitor setSpecialParameters(final SpecialParameterHolder ph, final String desc, int parameter, AnnotationVisitor av) {
312306
// for OnProbe the 'loc' variable will be null; we will need to verfiy the placement later on
313-
if (desc.equals(BTRACE_SELF_DESC)) {
307+
if (desc.equals(SELF_DESC)) {
314308
ph.setSelfParameter(parameter);
315309
} else if (desc.equals(BTRACE_PROBECLASSNAME_DESC)) {
316310
ph.setClassNameParameter(parameter);
@@ -326,9 +320,9 @@ public void visit(String name, Object val) {
326320
}
327321

328322
};
329-
} else if (desc.equals(BTRACE_RETURN_DESC)) {
323+
} else if (desc.equals(RETURN_DESC)) {
330324
ph.setReturnParameter(parameter);
331-
} else if (desc.equals(BTRACE_TARGETMETHOD_DESC)) {
325+
} else if (desc.equals(TARGETMETHOD_DESC)) {
332326
ph.setTargetMethodOrFieldParameter(parameter);
333327

334328
av = new AnnotationVisitor(Opcodes.ASM5, av) {
@@ -341,9 +335,9 @@ public void visit(String name, Object val) {
341335
}
342336

343337
};
344-
} else if (desc.equals(BTRACE_TARGETINSTANCE_DESC)) {
338+
} else if (desc.equals(TARGETINSTANCE_DESC)) {
345339
ph.setTargetInstanceParameter(parameter);
346-
} else if (desc.equals(BTRACE_DURATION_DESC)) {
340+
} else if (desc.equals(DURATION_DESC)) {
347341
ph.setDurationParameter(parameter);
348342
}
349343
return av;
@@ -358,7 +352,7 @@ private void verifySpecialParameters(OnMethod om) {
358352
(loc.getValue() == Kind.FIELD_GET && loc.getWhere() == Where.AFTER) ||
359353
(loc.getValue() == Kind.NEW && loc.getWhere() == Where.AFTER) ||
360354
(loc.getValue() == Kind.NEWARRAY && loc.getWhere() == Where.AFTER))) {
361-
Verifier.reportError("return.desc.invalid", om.getTargetName() + om.getTargetDescriptor() + "(" + om.getReturnParameter() + ")");;
355+
Verifier.reportError("return.desc.invalid", om.getTargetName() + om.getTargetDescriptor() + "(" + om.getReturnParameter() + ")");
362356
}
363357
}
364358
if (om.getTargetMethodOrFieldParameter() != -1) {

src/share/classes/com/sun/btrace/runtime/BTraceProbe.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@
5151
import java.util.Collections;
5252
import java.util.Iterator;
5353
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
54+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
55+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
56+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
57+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
58+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
59+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
60+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
61+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
62+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
63+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
64+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
65+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
66+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
67+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
68+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
69+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
70+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
71+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
72+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
73+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
74+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
75+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
76+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
77+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
78+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
79+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
80+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
81+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
82+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
83+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
84+
import static com.sun.btrace.runtime.ClassFilter.isSubTypeOf;
5485

5586
/**
5687
*

0 commit comments

Comments
 (0)