Skip to content

Instantly share code, notes, and snippets.

View mcimadamore's full-sized avatar

Maurizio Cimadamore mcimadamore

View GitHub Profile
@mcimadamore
mcimadamore / Test.java
Created June 3, 2022 21:49
Example of struct access with layouts and heap segments
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SequenceLayout;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;
public class Test {
static final ValueLayout.OfChar JAVA_CHAR_UNALIGNED = ValueLayout.JAVA_CHAR.withBitAlignment(8);
static final ValueLayout.OfInt JAVA_INT_UNALIGNED = ValueLayout.JAVA_INT.withBitAlignment(8);
@mcimadamore
mcimadamore / 01_jdk18_no_workarounds.json
Last active January 5, 2022 22:09
JDK 18 no workarounds
[
{
"jmhVersion" : "1.22",
"benchmark" : "org.openjdk.bench.jdk.incubator.foreign.LoopOverConstant.BB_get",
"mode" : "avgt",
"threads" : 1,
"forks" : 3,
"jvm" : "/w/lt/jdk/dev-18/build/linux-x86_64-server-release/images/jdk/bin/java",
"jvmArgs" : [
"-Djava.library.path=/w/lt/jdk/dev-18/build/linux-x86_64-server-release/images/test/micro/native",
[
{
"jmhVersion" : "1.22",
"benchmark" : "org.openjdk.bench.jdk.incubator.foreign.LoopOverConstant.BB_get",
"mode" : "avgt",
"threads" : 1,
"forks" : 3,
"jvm" : "/w/lt/jdk/dev-18/build/linux-x86_64-server-release/images/jdk/bin/java",
"jvmArgs" : [
"-Djava.library.path=/w/lt/jdk/dev-18/build/linux-x86_64-server-release/images/test/micro/native",
[
{
"jmhVersion" : "1.22",
"benchmark" : "org.openjdk.bench.jdk.incubator.foreign.LoopOverConstant.BB_get",
"mode" : "avgt",
"threads" : 1,
"forks" : 3,
"jvm" : "/w/lt/jdk/dev/build/linux-x86_64-server-release/images/jdk/bin/java",
"jvmArgs" : [
"-Djava.library.path=/w/lt/jdk/dev/build/linux-x86_64-server-release/images/test/micro/native",
@mcimadamore
mcimadamore / 01_no_workarounds.json
Created December 9, 2021 14:55
Panama JMH benchmark w/o long loop workarounds
[
{
"jmhVersion" : "1.22",
"benchmark" : "org.openjdk.bench.jdk.incubator.foreign.LoopOverConstant.BB_get",
"mode" : "avgt",
"threads" : 1,
"forks" : 3,
"jvm" : "/w/lt/jdk/dev/build/linux-x86_64-server-release/images/jdk/bin/java",
"jvmArgs" : [
"-Djava.library.path=/w/lt/jdk/dev/build/linux-x86_64-server-release/images/test/micro/native",
@mcimadamore
mcimadamore / 00_baseline.json
Created December 9, 2021 14:54
panama JMH baseline
[
{
"jmhVersion" : "1.22",
"benchmark" : "org.openjdk.bench.jdk.incubator.foreign.LoopOverConstant.BB_get",
"mode" : "avgt",
"threads" : 1,
"forks" : 3,
"jvm" : "/w/lt/jdk/dev/build/linux-x86_64-server-release/images/jdk/bin/java",
"jvmArgs" : [
"-Djava.library.path=/w/lt/jdk/dev/build/linux-x86_64-server-release/images/test/micro/native",
@mcimadamore
mcimadamore / Malloc.java
Created October 13, 2021 11:13
A malloc allocator which doesn't zero memory
import jdk.incubator.foreign.Addressable;
import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.FunctionDescriptor;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import jdk.incubator.foreign.SegmentAllocator;
import jdk.incubator.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
@mcimadamore
mcimadamore / DlOpen.java
Created May 22, 2021 21:51
DlOpen implementation using the Foreign Linker API
/*
* Copyright (c) 2021, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
/*
* Copyright (c) 2020, 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.
*
@mcimadamore
mcimadamore / JStruct.java
Created May 7, 2020 15:47
A simple jextract API plugin to generate all struct layouts in a given header file.
import jdk.incubator.foreign.GroupLayout;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.SequenceLayout;
import jdk.incubator.foreign.ValueLayout;
import jdk.incubator.jextract.Declaration;
import jdk.incubator.jextract.JextractTask;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;