Skip to content

Instantly share code, notes, and snippets.

View kaspernielsen's full-sized avatar

Kasper Nielsen kaspernielsen

View GitHub Profile
public class LookupUsage {
public static void main(String[] args) throws IOException {
record Entry(ClassModel cm, MethodModel mm) {}
Map<Integer, List<Entry>> hits = new HashMap<>();
Path javaBasePath = FileSystems.getFileSystem(java.net.URI.create("jrt:/")).getPath("/modules/java.base/java/");
Files.walk(javaBasePath).filter(path -> path.toString().endsWith(".class")).forEach(classFile -> {
try {
ClassModel cm = ClassFile.of().parse(classFile);
if (cm.flags().has(AccessFlag.PUBLIC)) {
import static org.objectweb.asm.Opcodes.ACC_BRIDGE;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ACC_SUPER;
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
public class StaticJava {
// Can only be created at build-time for static java
sealed interface RuntimeLocal<T> permits InternalRuntimeLocal {
// VM could knwo about this and optimize invocations
T get();
static <T> RuntimeLocal<T> of(Supplier<T> supplier) {}
static <T> RuntimeLocal<T> ofLazy(Supplier<T> supplier) {}
}
public class FooBar {
static Boolean tmpVal;
public static void main(String[] args) {
tmpVal = true; // readFromConfig
// Assuming config is initialized before method is called
foo();
}
werwrwerwerwerertertertsdfsdfsdf232423
public class TestClass {
// So assumming internal classes are closed of with Java 16
// For Java [9;15]
// This will work because all packages are open to the unnamed module (stuff on the classpath)
// It will print a warning because you use method.setAccessible on a class in a package that will
// be closed of in Java 16
public static void main1(String[] args) throws Exception {
Module unnamed = TestClass.class.getModule();
public class FilterMapToDoubleSortedSum extends Processor {
public Object process(int[] arr, TerminalQueryOperationNode node) {
// Original Query: C_FILTER->C_MAP_TO_DOUBLE->C_SORTED_NATURAL->CT_MATH_SUM
// Simplified : C_FILTER->C_MAP_TO_DOUBLE->CT_MATH_SUM
// Extract all functions from a linked list of query objects
SI_MapToDouble on = (SI_MapToDouble) node.previous().previous();
IntToDoubleFunction mapper = on.getMapper();
/**
* Lazily associate a computed value with a lookup object much like {@link ClassValue} but for {@link Lookup} objects.
*/
public abstract class LookupValue<T> {
/** The cache of values. */
private final ClassValue<ConcurrentHashMap<Integer, T>> LOOKUP_CACHE = new ClassValue<>() {
/** {@inheritDoc} */
@Override
public static String toString(int[] a) {
int iMax = a.length - 1;
if (iMax == -1)
return "[]";
int size = 2 * a.length;
for (int j = 0; j < a.length; j++) {
size += stringSize(a[j]);
}

Keybase proof

I hereby claim:

  • I am kaspernielsen on github.
  • I am kasperni (https://keybase.io/kasperni) on keybase.
  • I have a public key ASCULnwiofvbZK-cx5ChdWzpmzkmtqaoWNv9HZLchkuIxgo

To claim this, I am signing this object: