Skip to content

Instantly share code, notes, and snippets.

View rednaxelafx's full-sized avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / TestThreadStackSize.java
Created July 6, 2011 08:01
Inconsistency of -Xss and -XX:ThreadStackSize in the java launcher
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class TestThreadStackSize {
private static void crashVM() {
try {
makeSegfault(getUnsafe());
} catch (Exception e) {
// swallow
}
@rednaxelafx
rednaxelafx / DirectMemoryCrashDemo.java
Created May 2, 2012 11:02
Demonstrate a 32-bit JVM crash when address space is used up
import java.nio.*;
import java.util.*;
public class DirectMemoryCrashDemo {
private static int BUFFER_COUNT = 82;
private static int K = 1024;
private static int M = K * K;
private static int PAGE_SIZE = 4*K;
public static void main(String[] args) {
@rednaxelafx
rednaxelafx / StackOverflowCrashDemo.h
Created May 2, 2012 06:27
demo of a Java-level stack overflow causing a native crash
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class StackOverflowCrashDemo */
#ifndef _Included_StackOverflowCrashDemo
#define _Included_StackOverflowCrashDemo
#ifdef __cplusplus
extern "C" {
#endif
/*
@rednaxelafx
rednaxelafx / Main.java
Last active November 26, 2021 14:23
Code and session notes for blog post: Exploring HotSpot runtime data with HSDB http://rednaxelafx.iteye.com/blog/1847971
public class Main {
public static void main(String[] args) {
Test test = new Test();
test.fn();
}
}
@rednaxelafx
rednaxelafx / JNILocalRefLeakDemo.h
Created September 1, 2011 11:33
demo of JNI local reference leak with JNI libraries, on HotSpot VM.
/* 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 September 29, 2021 14:00
Pseudo-code that implements Cheney's algorithm for copying GC
// 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 October 31, 2013 02:24
explore memory layout of g++-4.4.5/libstdc++'s std::string
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 July 14, 2011 03:49
analyzing an endless loop problem caused by concurrent access to HashMap.get()
$ 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 December 7, 2011 09:48
Using the ProtectionDomain of an InstanceKlass to see where it was loaded from, with Attach API this time
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();
@rednaxelafx
rednaxelafx / PrintThreadIds.java
Created February 25, 2011 10:31
find out the correspondence between the tid/nid of Java threads as shown from jstack/JMX, on HotSpot/Linux
package fx.jvm.hotspot.tools;
import java.util.List;
import sun.jvm.hotspot.tools.Tool;
public class PrintThreadIds extends Tool {
public static void main(String[] args) {
PrintThreadIds tool = new PrintThreadIds();
tool.start(args);