This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeapIterator { | |
static { | |
System.loadLibrary("heapIterator"); | |
} | |
private static native void printStrings(); | |
public static void main(String[] args) throws Exception { | |
printStrings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_hashCode java/lang/Object.hashCode()I | |
_getClass java/lang/Object.getClass()Ljava/lang/Class; | |
_clone java/lang/Object.clone()Ljava/lang/Object; | |
_notify java/lang/Object.notify()V | |
_notifyAll java/lang/Object.notifyAll()V | |
_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
// See https://twitter.com/tagir_valeev/status/1402089474805354499 | |
public class StringBuilderHash { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public abstract class PowerAlgorithm { | |
public abstract long power(int x, int y); | |
static class NaivePower extends PowerAlgorithm { | |
@Override | |
public long power(int x, int y) { | |
long result = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method; | |
import java.util.Arrays; | |
public class Bytecodes { | |
static { | |
System.loadLibrary("bytecodes"); | |
} | |
private static native byte[] getBytecodes(Method method); |
NewerOlder