Skip to content

Instantly share code, notes, and snippets.

View franz1981's full-sized avatar
🏠
Working from home

Francesco Nigro franz1981

🏠
Working from home
View GitHub Profile
import java.io.Serializable;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class InstanceOfScalability {
private static Object intNum = Integer.valueOf(42);
private static Object longNum = Long.valueOf(42L);
public static void main(String[] args) throws InterruptedException, BrokenBarrierException, ExecutionException {
public class JCTools {
private volatile Thread sleeping;
<T> void add(Queue<? super T> q, T e) {
while (!q.offer(e)) {
// TODO: FIXME - cannot happen in production (even if is what some does!)
LockSupport.parkNanos(1L);
}
LockSupport.unpark(sleeping);
/**
run it with
$ java --source 19 --enable-preview --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED LoomDeadlockMain.java
**/
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.CompletableFuture;
import java.io.*;
import java.net.*;
import java.util.*;
public class VirtualThreadExample {
public static void main(String[] args) throws Exception {
// Create a virtual executor for running virtual threads
VirtualThreadExecutor executor = VirtualThreadExecutor.newSingleVirtualThreadExecutor();
// javac Main.java
// java -XX:-Inline -XX:-TieredCompilation Main 36 8000000
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
interface I1 {}
interface I2 {}
interface I3 extends I1, I2 {}
class B implements I3 {}
....[Hottest Region 2]..............................................................................
interpreter, io/netty/handler/codec/http/HttpObjectEncoder.encode(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Object;Ljava/util/List;)V
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵ 0x00007f1b24bea3dd: movb $0x0,(%r11,%r10,1) ;*invokestatic copyMemory {reexecute=0 rethrow=0 return_oop=0}
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵ ; - io.netty.buffer.UnsafeByteBufUtil::setBytes@69 (line 543)
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵ ; - io.netty.buffer.PooledUnsafeDirectByteBuf::setBytes@11 (line 199)
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵ ; - io.netty.buffer.AbstractByteBuf::writeBytes@14 (line 1074)
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵ ; - io.netty.buffer.AbstractByteBuf::writeBytes@5 (line 1081)
╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵╵
private static final long DOLLAR_PATTERN = '$' * 0x0001_0001_0001_0001L;
private static int firstAnyPattern(long fourChars, long charPattern) {
long input = fourChars ^ charPattern;
long tmp = (input & 0x7FFF_7FFF_7FFF_7FFFL) + 0x7FFF_7FFF_7FFF_7FFFL;
tmp = ~(tmp | input | 0x7FFF_7FFF_7FFF_7FFFL);
final int binaryPosition = Long.numberOfLeadingZeros(tmp);
return binaryPosition >>> 4;
}
@franz1981
franz1981 / Startup.md
Last active November 28, 2024 07:43
Results from native startup tests with different compilation levels
//DEPS org.openjdk.jmh:jmh-generator-annprocess:1.36
// to run with javagagent add the following:
// `--javaagent=ap-loader@maxandersen=start,event=cpu,file=profile.html`
package red.hat.puzzles;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
package red.hat.puzzles.loom;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;