Skip to content

Instantly share code, notes, and snippets.

Avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / DumpClassURL.java
Created Dec 7, 2011
Using the ProtectionDomain of an InstanceKlass to see where it was loaded from
View DumpClassURL.java
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
public class DumpClassURL extends Tool {
public void run() {
@rednaxelafx
rednaxelafx / Main.java
Last active Nov 26, 2021
Code and session notes for blog post: Exploring HotSpot runtime data with HSDB http://rednaxelafx.iteye.com/blog/1847971
View Main.java
public class Main {
public static void main(String[] args) {
Test test = new Test();
test.fn();
}
}
@rednaxelafx
rednaxelafx / command_prompt
Created Jan 2, 2012
quick-n-dirty modification to ObjectHistogram to get generational information
View command_prompt
$ export SAPATH=/home/sajia/taobao-jdk-repo/hotspot/make/linux/linux_amd64_compiler2/generated/
$ java -classpath .:$SAPATH/sa-jdi.jar sun.jvm.hotspot.tools.JMap -histo `pgrep java` > jmap_output.log
Attaching to process ID 1587, please wait...
WARNING: Hotspot VM version 20.5-b03 does not match with SA version 20.0-b12-internal. You may see unexpected results.
Debugger attached successfully.
Server compiler detected.
JVM version is 20.5-b03
Iterating over heap. This may take a while...
Heap traversal took 3.577 seconds.
$ java -version
@rednaxelafx
rednaxelafx / JDK5u22_client.log
Created Aug 23, 2011
PrintCompilation samples running Groovy shell 1.7.7 on different versions of HotSpot VM
View JDK5u22_client.log
1 b java.lang.String::charAt (33 bytes)
2 b java.lang.Math::max (11 bytes)
3 b java.util.jar.Manifest$FastInputStream::readLine (167 bytes)
4 b sun.nio.cs.UTF_8$Decoder::decodeArrayLoop (553 bytes)
5 b java.util.Properties$LineReader::readLine (383 bytes)
6 b java.lang.String::hashCode (60 bytes)
7 b java.lang.String::indexOf (151 bytes)
8 b sun.nio.cs.ext.DoubleByteDecoder::decodeSingle (10 bytes)
9 b java.lang.String::lastIndexOf (156 bytes)
10 b java.lang.String::replace (142 bytes)
@rednaxelafx
rednaxelafx / DirectMemorySize.java
Created Jan 11, 2012
An Serviceability-Agent based tool to see stats of NIO direct memory, as an alternative on JDK6 without JMX support for direct memory monitoring. Only works on JDK6; to work on JDK7 will need some tweaking because static variables are moved to Java mirror
View DirectMemorySize.java
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
public class DirectMemorySize extends Tool {
@rednaxelafx
rednaxelafx / JNILocalRefLeakDemo.h
Created Sep 1, 2011
demo of JNI local reference leak with JNI libraries, on HotSpot VM.
View JNILocalRefLeakDemo.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNILocalRefLeakDemo */
#ifndef _Included_JNILocalRefLeakDemo
#define _Included_JNILocalRefLeakDemo
#ifdef __cplusplus
extern "C" {
#endif
/*
@rednaxelafx
rednaxelafx / cheney.cpp
Last active Sep 29, 2021
Pseudo-code that implements Cheney's algorithm for copying GC
View cheney.cpp
// Pseudo-code that implements Cheney's algorithm
class Object {
// remains null for normal objects
// non-null for forwarded objects
Object* _forwardee;
public:
void forward_to(address new_addr);
Object* forwardee();
@rednaxelafx
rednaxelafx / gdb_session
Created Oct 31, 2013
explore memory layout of g++-4.4.5/libstdc++'s std::string
View gdb_session
rednaxelafx@fx-laptop:/tmp
$ gedit xx.cpp
rednaxelafx@fx-laptop:/tmp
$ g++ -g xx.cpp
rednaxelafx@fx-laptop:/tmp
$ g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
@rednaxelafx
rednaxelafx / log1
Created Jul 14, 2011
analyzing an endless loop problem caused by concurrent access to HashMap.get()
View log1
$ top -H
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19115 root 25 0 576m 217m 9432 R 99.7 5.3 1357:12 java
28347 root 25 0 576m 217m 9432 R 99.7 5.3 1191:05 java
26912 root 25 0 576m 217m 9432 R 99.3 5.3 114:58.57 java
5607 root 25 0 576m 217m 9432 R 99.0 5.3 54:49.02 java
@rednaxelafx
rednaxelafx / DumpClassURL.java
Created Dec 7, 2011
Using the ProtectionDomain of an InstanceKlass to see where it was loaded from, with Attach API this time
View DumpClassURL.java
import java.lang.instrument.Instrumentation;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Arrays;
import java.util.Comparator;
public class DumpClassURL {
public static void agentmain(String agentArgs, Instrumentation inst) {
Class<?>[] classes = inst.getAllLoadedClasses();