Skip to content

Instantly share code, notes, and snippets.

View raphw's full-sized avatar

Rafael Winterhalter raphw

View GitHub Profile
@raphw
raphw / Example.java
Last active August 29, 2015 14:26
Example for VerifierError when using method reference within a lambda before constructor is completed.
class Example {
Example(Function<Function<Function<Consumer<Void>, Void>, Void>, Void> innerClass) {
new InnerClass(innerClass);
}
void foo(Void v) { }
class InnerClass {
@raphw
raphw / Foo.java
Created August 3, 2015 08:30
FinalVisibilityBridge
package foo;
public class Foo extends Base {
}
class Base {
public final void foo() {
@raphw
raphw / GenericVisibilityBridge.java
Last active August 29, 2015 14:26
Visibility bridges
package pkg;
class GenericVisibilityBridge extends GenericVisibilityBridgeBase<Void> {
@Override
public void foo(Void aVoid) {
System.out.println("specialized");
}
}
@raphw
raphw / Foo.java
Last active August 29, 2015 14:25
Bridge method resolution.
public abstract class Foo<T> {
abstract void foo(T t);
abstract T bar();
public static void main(String[] args) {
Foo<?> quxFoo = new Qux();
Bar<?> quxBar = new Qux();
@raphw
raphw / MockBytecodeGenerator.java
Last active September 11, 2017 11:30
Constructor interception fix
package org.mockito.internal.creation.bytebuddy;
import java.util.Random;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
import org.mockito.internal.creation.bytebuddy.ByteBuddyCrossClassLoaderSerializationSupport.CrossClassLoaderSerializableMock;
import org.mockito.internal.creation.util.SearchingClassLoader;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
@raphw
raphw / EduAVLTree.java
Created March 13, 2015 08:26
Educational AVL tree in Java (from Google code)
/*
* EduAVLTree: An AVL tree implementation of educational intention.
*
* Copyright (C) 2011 Rafael W.
*
* EduAVLTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
@raphw
raphw / LogInterceptor.java
Created February 23, 2015 14:11
Byte Buddy agent: JDK 8
package introspect;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.AllArguments;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.Origin;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
public class LogInterceptor {
@raphw
raphw / FastListBenchmark.java
Last active August 29, 2015 14:11
Benchmark of FastList
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class FastListBenchmark {
private static final int LOAD = 10;
private ArrayList<Object> arrayList;
@raphw
raphw / agent.patch
Last active September 9, 2017 19:53
Self-attachment agent for JOL
Index: jol-core/src/main/java/org/openjdk/jol/util/VMSupport.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- jol-core/src/main/java/org/openjdk/jol/util/VMSupport.java (revision 31:9a546334aa57fa0e114db159b2a8a5345c249b3e)
+++ jol-core/src/main/java/org/openjdk/jol/util/VMSupport.java (revision 31+:9a546334aa57+)
@@ -35,13 +35,22 @@
import javax.management.openmbean.CompositeDataSupport;
import java.io.PrintWriter;
@raphw
raphw / ClassLayout.java
Last active August 29, 2015 14:11
Modified version of JOL's class layout
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*