Skip to content

Instantly share code, notes, and snippets.

View apangin's full-sized avatar

Andrei Pangin apangin

View GitHub Profile
@apangin
apangin / HotSpot JVM intrinsics
Last active May 11, 2023 18:32
HotSpot JVM intrinsics
_hashCode java/lang/Object.hashCode()I
_getClass java/lang/Object.getClass()Ljava/lang/Class;
_clone java/lang/Object.clone()Ljava/lang/Object;
_dabs java/lang/Math.abs(D)D
_dsin java/lang/Math.sin(D)D
_dcos java/lang/Math.cos(D)D
_dtan java/lang/Math.tan(D)D
_datan2 java/lang/Math.atan2(DD)D
_dsqrt java/lang/Math.sqrt(D)D
_dlog java/lang/Math.log(D)D
@apangin
apangin / Queue.java
Last active August 29, 2015 14:22
Capacity field vs. array length
package bench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import sun.misc.Unsafe;
@apangin
apangin / constants.txt
Created June 3, 2015 23:48
HotSpot VMStructs
const int ASSERT = 0
const int STACK_BIAS = 0
const int oopSize = 8
const int LogBytesPerWord = 3
const int BytesPerWord = 8
const int BytesPerLong = 8
const int LogKlassAlignmentInBytes = 3
const int ageTable::table_size = 16
const int BarrierSet::ModRef = 0
const int BarrierSet::CardTableModRef = 1
@apangin
apangin / StringHash.java
Created September 2, 2015 13:24
Compare xxHash with default String.hashCode
package bench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
@apangin
apangin / rafpatch.c
Last active March 14, 2023 23:46
Patch to enable O_SYNC on RandomAccessFile
/*
* Compile: gcc -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -shared -fPIC -O3 -olibrafpatch.so -Wl,-soname,librafpatch.so rafpatch.c $JAVA_HOME/lib/amd64/libjava.so
* Run: java -agentpath:/path/to/librafpatch.so MainClass
*/
#include <jvmti.h>
#include <jni.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
package bench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@State(Scope.Thread)
public class InliningBenchmark {
static volatile int value = 20;
@apangin
apangin / BenchBase.java
Created October 18, 2015 22:37
DB connection pool benchmark
/*
* Copyright (C) 2014 Brett Wooldridge, Andrei Pangin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@apangin
apangin / LZ4Array.java
Created January 14, 2016 13:54
Java LZ4 benchmark
package lz4;
import static lz4.LZ4Common.*;
public class LZ4Array {
private static long getLong(byte[] b, int p) {
return (b[p] & 0xffL)
| (b[p + 1] & 0xffL) << 8
| (b[p + 2] & 0xffL) << 16
package bench;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@State(Scope.Benchmark)
public class ListIndexOf {
private static final Random random = new Random(0);
import com.sun.tools.attach.VirtualMachine;
import java.nio.file.Paths;
public class InjectAgent {
public static void main(String[] args) throws Exception {
String PID = args[0];
String agentJar = Paths.get("retransformer.jar").toAbsolutePath().toString();