Skip to content

Instantly share code, notes, and snippets.

View Glavo's full-sized avatar
😇

Glavo Glavo

😇
View GitHub Profile
import java.lang.foreign.*;
import java.lang.invoke.*;
import java.util.Arrays;
import static java.lang.foreign.ValueLayout.*;
public class Test {
@FunctionalInterface
public interface Callback {
int invoke(MemorySegment a, MemorySegment b);
@Glavo
Glavo / NoRepl.java
Created January 20, 2023 16:53
New NoRepl.java
package org.glavo.jmh;
import com.google.common.jimfs.Jimfs;
import org.openjdk.jmh.annotations.*;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import com.google.common.jimfs.Jimfs;
import org.openjdk.jmh.annotations.*;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
@Glavo
Glavo / PanamaJIT.java
Last active November 23, 2021 10:43
PanamaJIT Demo
import jdk.incubator.foreign.*;
import java.lang.invoke.*;
// Original code (C++): https://stackoverflow.com/a/40937610/7659948
public class PanamaJIT {
public static final int MEM_COMMIT = 0x00001000;
public static final int PAGE_READWRITE = 0x04;
public static final int PAGE_EXECUTE_READ = 0x20;
@Glavo
Glavo / TimingsListener.kts
Created October 15, 2021 05:44
Task TimingsListener Kotlin DSL
// Log timings per task.
class TimingsListener : TaskExecutionListener, BuildListener {
private var startTime: Long = 0L
private val timings = mutableListOf<Pair<Long, String>>()
@Override
override fun beforeExecute(task: Task) {
startTime = System.nanoTime()
}
@Glavo
Glavo / Clang.asm
Created March 18, 2021 20:44
DfsTest
; ModuleID = 'test2.cpp'
source_filename = "test2.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@_ZL3cnt = internal unnamed_addr global i32 0, align 4
@.str = private unnamed_addr constant [16 x i8] c"%d\0ATime: %ldms\0A\00", align 1
; Function Attrs: nofree nounwind uwtable
define dso_local void @_Z3Dfsiiii(i32 %0, i32 %1, i32 %2, i32 %3) local_unnamed_addr #0 {
@Glavo
Glavo / hmcl-exported-logs-2020-07-09T17-16-06.log
Last active July 9, 2020 09:18
hmcl-exported-logs-2020-07-09T17-16-06.log
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] *** HMCL 3.3.172 ***
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Operating System: Windows 10 10.0
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Java Version: 1.8.0_252, BellSoft
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), BellSoft
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Java Home: D:\Downloads\HMCL\jre-x64
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Current Directory: D:\Downloads\HMCL
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] HMCL Directory: C:\Users\Glavo\AppData\Roaming\.hmcl
[17:15:40] [org.jackhuang.hmcl.Launcher.main/INFO] Memory: 14553MB
[17:15:40] [org.jackhuang.hmcl.Launcher.lambda$main$2/INFO] Metaspace: 8MB
[17:15:40] [org.jackhuang.hmcl.Main.fixLetsEncrypt/INFO] Added Lets Encrypt root certificates as additional trust
@Glavo
Glavo / Scala
Created October 22, 2018 09:47
Type Error
scala> type T = (Int, Char, String)
// defined alias type T = (Int, Char, String)
scala> val get: (t: T, i: Int) => Tuple.Elem[T, i.type] = (t, i) => t(i)
1 |val get: (t: T, i: Int) => Tuple.Elem[T, i.type] = (t, i) => t(i)
| ^^^^
|found: Int(i) match {
| case Int(0) => Int
| case [n1 <: Int] => typelevel.S[n1] => scala.Tuple.Elem[(Char, String), n1]
|}
openjdk-jdk9-jdk9/
├── common
│ ├── autoconf
│ │ └── build-aux
│ ├── bin
│ ├── conf
│ ├── doc
│ ├── nb_native
│ │ └── nbproject
│ └── src
class C {
def fun23(f: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) => Int) = {}
}
object C {
def main(args: Array[String]): Unit = {
classOf[C].getMethod("fun23", classOf[FunctionXXL]).getGenericParameterTypes
}
}