-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
btrace-compiler/src/test/java/org/openjdk/btrace/compiler/TypeErasureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.openjdk.btrace.compiler; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.util.CheckClassAdapter; | ||
import org.openjdk.btrace.core.SharedSettings; | ||
import org.openjdk.btrace.instr.BTraceProbe; | ||
import org.openjdk.btrace.instr.BTraceProbeFactory; | ||
|
||
import java.io.File; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TypeErasureTest { | ||
@Test | ||
void testTypeErasure() throws Exception { | ||
URL input = TypeErasureTest.class.getResource("/HistoProbe.java"); | ||
File inputFile = new File(input.toURI()); | ||
Map<String, byte[]> data = | ||
new Compiler(true) | ||
.compile( | ||
inputFile, | ||
new PrintWriter(System.err), | ||
null, | ||
System.getProperty("java.class.path")); | ||
BTraceProbeFactory factory = new BTraceProbeFactory(SharedSettings.GLOBAL); | ||
for (byte[] bytes : data.values()) { | ||
BTraceProbe probe = factory.createProbe(bytes); | ||
verifyCode(probe.getFullBytecode()); | ||
verifyCode(probe.getDataHolderBytecode()); | ||
} | ||
} | ||
|
||
private void verifyCode(byte[] code) { | ||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw); | ||
CheckClassAdapter.verify(new ClassReader(code), true, pw); | ||
if (sw.toString().contains("AnalyzerException")) { | ||
System.err.println(sw); | ||
fail(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package test; | ||
|
||
import static org.openjdk.btrace.core.BTraceUtils.*; | ||
import org.openjdk.btrace.core.annotations.*; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@BTrace public class HistoProbe { | ||
private static Map<String, AtomicInteger> histo = newHashMap(); | ||
@OnMethod(clazz = "javax.swing.JComponent", method = "<init>") | ||
public static void onMethod(@Self Object obj) { | ||
String cn = name(classOf(obj)); | ||
AtomicInteger ai = get((Map<String, AtomicInteger>)histo, cn); | ||
if (ai == null) { | ||
ai = newAtomicInteger(1); | ||
put(histo, cn, ai); | ||
} else { | ||
incrementAndGet(ai); // WORKS if commented out | ||
} | ||
} | ||
|
||
@OnTimer(1000) | ||
public static void print() { | ||
printNumberMap("Component Histogram", histo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters