Skip to content

Instantly share code, notes, and snippets.

View apangin's full-sized avatar

Andrei Pangin apangin

View GitHub Profile
@apangin
apangin / NpsConverter.java
Created June 6, 2020 18:08
Converts .collapsed output produced by async-profiler to VisualVM format
/*
* Copyright 2020 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
/*
* Copyright 2018 Andrei Pangin
*
* This is a specialized Java port of the FlameGraph script available at
* https://github.com/brendangregg/FlameGraph/blob/master/flamegraph.pl
*
* Copyright 2016 Netflix, Inc.
* Copyright 2011 Joyent, Inc. All rights reserved.
* Copyright 2011 Brendan Gregg. All rights reserved.
*
// Compile:
// gcc -shared -fPIC -olibsighandle.so sighandle.c
//
// Run:
// java -agentpath:/path/to/libsighandle.so ...
// kill -37 <pid>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
package bench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
@apangin
apangin / patcher.cpp
Created July 2, 2019 16:03
Example for the presentation about JVM TI
#include <jvmti.h>
#include <stdio.h>
static jvmtiIterationControl JNICALL
heap_callback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) {
*tag_ptr = 1;
return JVMTI_ITERATION_CONTINUE;
}
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
@apangin
apangin / MapGenerator.java
Created October 23, 2018 11:19
GC off-heap overhead
package map;
import java.io.PrintStream;
import java.util.Base64;
import java.util.concurrent.ThreadLocalRandom;
public class MapGenerator {
public static void main(String[] args) throws Exception {
try (PrintStream out = new PrintStream("in.txt")) {
@apangin
apangin / proccount.c
Last active March 14, 2023 23:46
Fool JVM about the number of available processors according to /sys/devices/system/cpu/online
// Compile: gcc -O2 -fPIC -shared -o libproccount.so proccount.c
// Run: LD_PRELOAD=/path/to/libproccount.so java args
#define _GNU_SOURCE
#include <sched.h>
#include <unistd.h>
static int online_cpus;
__attribute__((constructor))
#include <jvmti.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define INSIDE_MAIN 0x10000000
static volatile int max_depth = INSIDE_MAIN;
static intptr_t get_current_stack_depth(jvmtiEnv *jvmti) {
intptr_t depth = 0;
@apangin
apangin / rawdata.txt
Created February 15, 2018 05:03
Shenandoah GC vs. CMS GC: 99.9% response time
Time Shenandoah CMS
0:00 2457603 5213181
0:05 2267273 57975399
0:10 2352205 4507923
0:15 2528657 4868730
0:20 2251922 4356681
0:25 2270476 50325870
0:30 2205635 4559177
0:35 2529011 73313110
0:40 2199077 4155792
#include <sched.h>
#include <stdio.h>
#include <time.h>
static long nanotime() {
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
return tp.tv_sec * 1000000000L + tp.tv_nsec;
}