Skip to content

Instantly share code, notes, and snippets.

View rednaxelafx's full-sized avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / .hotspot_compiler
Created March 6, 2012 13:18
Example (XS) of adding an intrinsic method to HotSpot C2. Patch against HS20-b12
exclude Main main
dontinline Main doTest
compileonly Main doTest
compileonly FxIntrinsics *
@rednaxelafx
rednaxelafx / HelloWorld.java
Created May 16, 2012 14:15
Print the list of invoked methods
public class HelloWorld {
private static int foo() {
return 42;
}
private static void bar() {
}
public static void main(String[] args) throws Exception {
foo();
@rednaxelafx
rednaxelafx / Bar$$$Lambda$101.class.javap
Last active June 11, 2020 07:35
Example comparison of inner-class anonfunc in Scala 2.11 vs indylambda in Scala 2.12, and how that affects Apache Spark's ClosureCleaner
# LMF class generated at runtime, dumped via
# <Scala 2.12.2>/bin/scala -cp . -Djdk.internal.lambda.dumpProxyClasses=dumpclasses Bar
$ javap -verbose -private -c -s -l 'Bar$$$Lambda$101.class'
Classfile /private/tmp/dumpclasses/Bar$$$Lambda$101.class
Last modified Apr 30, 2020; size 695 bytes
MD5 checksum 419f2634b1acdf7f40ba0bb7c22eabf4
final class Bar$$$Lambda$101 implements scala.runtime.java8.JFunction0$mcV$sp,scala.Serializable
minor version: 0
major version: 52
@rednaxelafx
rednaxelafx / TestVec.java
Created February 9, 2015 23:32
Simple demo of autovectorization in Oracle JDK8u25 on Linux/x64 with AVX
import java.util.*;
public class TestVec {
public static int[] doTest(int[] xs, int[] ys) {
if (xs.length != ys.length) return null;
int[] zs = new int[xs.length];
for (int i = 0; i < xs.length; i++) {
zs[i] = xs[i] * ys[i];
}
return zs;
@rednaxelafx
rednaxelafx / gist:998018
Created May 29, 2011 18:31
Example of /proc/{pid}/maps and pmap -x of a groovysh process on Ubuntu 10.10 x64
rednaxelafx@fx-laptop:~$ jps
7013 Jps
6946 GroovyStarter
rednaxelafx@fx-laptop:~$ cd /proc/6946
rednaxelafx@fx-laptop:/proc/6946$ ls
attr cpuset latency mountstats root statm
auxv cwd limits net sched status
cgroup environ loginuid numa_maps schedstat syscall
clear_refs exe maps oom_adj sessionid task
cmdline fd mem oom_score smaps wchan
@rednaxelafx
rednaxelafx / command_prompt
Created December 23, 2011 03:43
get class histogram in GC log on OutOfMemoryError
$ cat > OOM.java
import java.util.*;
public class OOM {
public static void main(String[] args) throws Exception {
ArrayList list = new ArrayList();
while (true) { list.add(new byte[20000]); }
}
}
@rednaxelafx
rednaxelafx / c1_isInstance.patch
Created May 29, 2012 19:28
First cut: C1 Class.isInstance intrinsic
diff -r 4d8787136e08 src/share/vm/c1/c1_Canonicalizer.cpp
--- a/src/share/vm/c1/c1_Canonicalizer.cpp Fri May 25 11:39:13 2012 -0700
+++ b/src/share/vm/c1/c1_Canonicalizer.cpp Wed May 30 03:21:56 2012 +0800
@@ -451,6 +451,28 @@
}
break;
}
+ case vmIntrinsics::_isInstance : {
+ assert(x->number_of_arguments() == 2, "wrong type");
+
@rednaxelafx
rednaxelafx / A.java
Created June 21, 2011 16:01
Trying out clhsdb to examine object layout in HotSpot
class A {
Object aObj;
int aInt;
}
class B extends A {
Object bObj;
int bInt;
float fFloat;
}
@rednaxelafx
rednaxelafx / Notes.md
Created December 12, 2011 15:47
Notes on JVM TI's GC start event

There's a GC start/end event in JVM TI: http://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html#GarbageCollectionStart It's been around for quite a while. Can be used in JDK 6. Can't execute Java code in the callback. The VM is in its stop-the-world phase when the event is sent.

From the document:

This event is sent while the VM is still stopped, thus the event handler must not use JNI functions and must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions).

The places that issue this event:

@rednaxelafx
rednaxelafx / gist:759495
Created December 30, 2010 05:21
A code snippet to show some relationship between JVM/HotSpot's and Dalvik's interpreter.
Java source code:
k = i + j;
May compile to Java bytecode:
iload_0
iload_1
iadd
istore_2
And may turn into Dalvik VM code: