Skip to content

Instantly share code, notes, and snippets.

View raphw's full-sized avatar

Rafael Winterhalter raphw

View GitHub Profile
@raphw
raphw / ReactiveMain.java
Created October 22, 2018 11:35
A reactive stream processor
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 June 2, 2018 11:07
Twist transformer order
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;
public class GenericNestedType {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface SampleTypeAnnotation { }
static class GenericNested<T> {
class Inner { }
}
@raphw
raphw / BugReportDeprecatedModifier.java
Last active April 17, 2018 22:02
Demonstrating loosing the deprecated modifier with retransformation when two transformers are registered using an old Log4j (Java 1.1).
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 19:07
Method handle invoke special
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 October 20, 2017 13:15
Approaches to stack extraction.
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 June 14, 2017 07:11
Inlining attempt with Byte Buddy
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 07:22
Overridding a package private package.
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 {
@raphw
raphw / Benchmark
Created March 5, 2017 20:50
XML/JSON benchmark
package test;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import foo.SampleBean;
import foo.SampleBeans;
@raphw
raphw / FileMonitor.java
Created February 13, 2017 00:34
Monitors folder and reads it upon discovery
import java.io.IOException;
import java.nio.file.*;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class FileMonitor implements Runnable {