Skip to content

Instantly share code, notes, and snippets.

View parttimenerd's full-sized avatar

Johannes Bechberger parttimenerd

View GitHub Profile
@parttimenerd
parttimenerd / Task.md
Last active November 15, 2024 13:32
Code comprehension task

If any issues arise, please don't hesitate to ask.

Setup

Before diving into the code, please clone the OpenJDK JDK repository on a machine running Linux and build it according to the build instructions.

This should give you a running OpenJDK. Add it to your path and run a simple Java "Hello, World" program to confirm everything is set up correctly.

Testing

@parttimenerd
parttimenerd / CpuCoreHog.java
Created September 11, 2024 16:59
Java program that spins up 5*#cores CPU-bound threads
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CpuCoreHog {
public static void main(String[] args) {
// Get the number of available processors (cores)
int cores = Runtime.getRuntime().availableProcessors() * 5;
System.out.println("Running on " + cores + " cores.");
// Create a fixed thread pool with the number of available cores
ExecutorService executorService = Executors.newFixedThreadPool(cores);
import java.io.IOException;
import java.net.*;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
class HttpRequestsExample {
private static HttpServer server;
  • segment.setUtf8String(0, obj); -> segment.setString(0, obj);
  • same with getUtf8String
  • MemoryLayout.sequenceLayout(JAVA_BYTE) -> MemoryLayout.sequenceLayout(0, JAVA_BYTE)
  • arena.allocateUtf8String(string) -> allocateFrom(string)
  • var readers = arena.allocateArray(PanamaUtil.POINTER, perfBuffers.size()); -> var readers = arena.allocate(PanamaUtil.POINTER, perfBuffers.size());
  • jextract:
    • Callbacks: "X" -> "X.function"
    • bcc_symbol.module$get(sym) -> module(sym)
  • Lib.open(pathInC, O_RDONLY) (var args (?)) -> Lib.open.makeInvoker().apply(pathInC, O_RDONLY) (extern int open(const char *__file, int __oflag, ...))
@parttimenerd
parttimenerd / sample.py
Last active December 1, 2023 12:33
Collect all used classes, methods and functions
"""
Sample file to test the trace module.
This should print:
...
********** Trace Results **********
Used classes:
only static init:
not only static init:
@parttimenerd
parttimenerd / CustomEvents.java
Created November 20, 2023 11:38
Custom JFR events defined in Minecraft, obtained by using `jfr metadata` on a generated JFR file
@Name("minecraft.ChunkGeneration")
@Label("Chunk Generation")
@Category({"Minecraft", "World Generation"})
class ChunkGeneration extends jdk.jfr.Event {
@Label("Start Time")
@Timestamp("TICKS")
long startTime;
@Label("Duration")
@Timespan("TICKS")
@parttimenerd
parttimenerd / uBlock_Twitter
Last active November 21, 2023 07:33
uBlock Origin Twitter rules to hide the trends and statistics
! 2023-08-01 https://twitter.com
twitter.com##a.r-13qz1uu.r-rjfia.r-1ny4l3l.r-16y2uox.r-eqz5dr.r-6koalj.r-1loqt21.r-1habvwh.css-1dbjc4n.css-18t94o4.css-4rbku5:nth-of-type(7)
! 2023-09-10 https://twitter.com
twitter.com##a.r-13qz1uu.r-oyd9sg.r-1ny4l3l.r-eqz5dr.r-13awgt0.r-6koalj.r-1loqt21.r-1habvwh.css-1dbjc4n.css-18t94o4.css-4rbku5:nth-of-type(7)
! 2023-11-21 https://twitter.com
twitter.com###id__q3p36maqo9 > div.r-13awgt0.r-1h0z5md.r-18u37iz.css-175oi2r > .r-1ny4l3l.r-lrvibr.r-bztko3.r-bt1l66.r-1777fci.css-175oi2r > .r-3s2u2q.r-clp7b1.r-o7ynqc.r-1h0z5md.r-6koalj.r-1awozwy.r-16dba41.r-rjixqe.r-a023e6.r-37j5jr.r-qvutc0.r-bcqeeo.css-1rynq56 > .r-1udh08x.r-xoduu5.css-175oi2r > span
twitter.com###id__cglm8gn7hvg > div.r-13awgt0.r-1h0z5md.r-18u37iz.css-175oi2r > .r-1ny4l3l.r-lrvibr.r-bztko3.r-bt1l66.r-1777fci.css-175oi2r > .r-3s2u2q.r-clp7b1.r-o7ynqc.r-1h0z5md.r-6koalj.r-1awozwy.r-16dba41.r-rjixqe.r-a023e6.r-37j5jr.r-qvutc0.r-bcqeeo.css-1rynq56 > .r-1udh08x.r-xoduu5.css-175oi2r > span > .r-1pn2ns4.r-1k6nrdp.r-1c
@parttimenerd
parttimenerd / Main.java
Last active February 20, 2023 11:57
Tiny self-contained reproducer for https://bugs.openjdk.org/browse/JDK-8302320 (AsyncGetCallTrace obtains too few frames in sanity test)
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> klass = Main.class;
Method mainMethod = klass.getMethod("test");
mainMethod.invoke(null);
}
@parttimenerd
parttimenerd / SmallProgram.java
Created December 27, 2022 12:55
JDWP transcript for blog post
public class SmallProgram {
public static void main(String[] args) {
String name = args[0];
System.out.println("Hello, " + name + "!");
}
}