Skip to content

Instantly share code, notes, and snippets.

Rafael Winterhalter raphw

View GitHub Profile
@raphw
raphw / bridge_generic.sh
Last active Jan 22, 2019
Generation of a visibility bridge method.
View bridge_generic.sh
mkdir pkg1
echo "package pkg1; class SuperClass<X> { public X m() { return null; } }" > pkg1/SuperClass.java
echo "package pkg1; public class SubClass extends SuperClass<Void> { }" > pkg1/SubClass.java
${JAVA_HOME}/bin/javac pkg1/*.java
mkdir pkg2
echo "package pkg2; class Main { public static void main(String[] args) throws Exception { pkg1.SubClass.class.getMethod(\"m\").invoke(new pkg1.SubClass()); } }" > pkg2/Main.java
${JAVA_HOME}/bin/javac pkg2/*.java
${JAVA_HOME}/bin/java -cp . pkg2.Main
@raphw
raphw / bridge.sh
Created Jan 22, 2019
Generation of a visibility bridge method.
View bridge.sh
mkdir pkg1
echo "package pkg1; class SuperClass<X> { public X m() { return null; } }" > pkg1/SuperClass.java
echo "package pkg1; public class SubClass extends SuperClass<Void> { }" > pkg1/SubClass.java
${JAVA_HOME}/bin/javac pkg1/*.java
mkdir pkg2
echo "package pkg2; class Main { public static void main(String[] args) throws Exception { pkg1.SubClass.class.getMethod(\"m\").invoke(new pkg1.SubClass()); } }" > pkg2/Main.java
${JAVA_HOME}/bin/javac pkg2/*.java
${JAVA_HOME}/bin/java -cp . pkg2.Main
@raphw
raphw / ReactiveMain.java
Created Oct 22, 2018
A reactive stream processor
View ReactiveMain.java
import static org.asynchttpclient.Dsl.asyncHttpClient;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
@raphw
raphw / Experiment.class
Created Jun 2, 2018
Twist transformer order
View Experiment.class
package sun.instrument;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.StubMethod;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.utility.JavaModule;
View GenericNestedTypeDemo.java
public class GenericNestedType {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface SampleTypeAnnotation { }
static class GenericNested<T> {
class Inner { }
}
@raphw
raphw / BugReportDeprecatedModifier.java
Last active Apr 17, 2018
Demonstrating loosing the deprecated modifier with retransformation when two transformers are registered using an old Log4j (Java 1.1).
View BugReportDeprecatedModifier.java
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.TraceClassVisitor;
import java.io.PrintWriter;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
public class BugReportDeprecatedModifier {
@raphw
raphw / Main.java
Last active May 9, 2018
Method handle invoke special
View Main.java
package main;
import bar.Bar;
import qux.Qux;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Proxy;
import java.util.function.Consumer;
@raphw
raphw / StackWalkerExtraction.java
Created Oct 20, 2017
Approaches to stack extraction.
View StackWalkerExtraction.java
import org.openjdk.jmh.annotations.Benchmark;
public class StackWalkerExtraction {
private static Object call(int depth, Callable<?> result) throws Exception {
if (depth == 0) {
return result.call();
} else {
return call(depth - 1, result);
}
@raphw
raphw / Experiment.java
Created Jun 14, 2017
Inlining attempt with Byte Buddy
View Experiment.java
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
import net.bytebuddy.pool.TypePool;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.SimpleRemapper;
@raphw
raphw / PackageConfustion.java
Created May 11, 2017
Overridding a package private package.
View PackageConfustion.java
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.FixedValue;
import java.lang.reflect.Method;
import static net.bytebuddy.matcher.ElementMatchers.named;
public class PackageConfusion {
public static void main(String[] args) throws Exception {
You can’t perform that action at this time.