Skip to content

Instantly share code, notes, and snippets.

@Maldivia
Maldivia / LayoutMaker.java
Created April 5, 2021 18:28
Java Record to MemorySegment mapper
package com.test;
import jdk.incubator.foreign.GroupLayout;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.MemoryLayouts;
import jdk.incubator.foreign.MemorySegment;
import java.lang.reflect.RecordComponent;
import java.util.Arrays;
@Maldivia
Maldivia / Lazy8.java
Created May 21, 2019 12:48
JDK8 vresion of Lazy initialization
package app1;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import sun.misc.Unsafe;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@Maldivia
Maldivia / Lazy.java
Last active May 21, 2019 12:19
Lazy init class using Unsafe anonymous class and Constant Dynamic from JDK11
package app1;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.util.function.Supplier;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.DoublePredicate;
import java.util.function.IntConsumer;
import java.util.function.IntPredicate;
import java.util.function.LongConsumer;
import java.util.function.LongPredicate;
import java.util.function.Predicate;