Skip to content

Instantly share code, notes, and snippets.

Avatar

Kris Mok rednaxelafx

View GitHub Profile
@rednaxelafx
rednaxelafx / TrapDemo.java
Created Oct 22, 2016
Java implicit null check example. Run on Oracle JDK8u101
View TrapDemo.java
public class TrapDemo {
public static void demo(IntBox p) {
int dead = p.value;
if (p == null) return;
p.value = 42;
}
public static void main(String[] args) throws Exception {
demo(null);
}
View Demo$$Lambda$1.javap
$ javap -verbose -c -s -l -private Demo\$\$Lambda\$1
Classfile /private/tmp/Demo$$Lambda$1.class
Last modified Oct 12, 2016; size 754 bytes
MD5 checksum 81ce9dafbca34417b2dfa94f596a85a1
final class Demo$$Lambda$1 implements org.apache.spark.api.java.function.VoidFunction
minor version: 0
major version: 52
flags: ACC_FINAL, ACC_SUPER, ACC_SYNTHETIC
Constant pool:
#1 = Utf8 Demo$$Lambda$1
@rednaxelafx
rednaxelafx / Demo.j
Created Jun 8, 2016
HotSpot C1 doesn't compile this "monitorenter with Phi input", fails with "invalid parsing"
View Demo.j
.class public Demo
.super java/lang/Object
.field public static dummy I
.method public static foo(Ljava/lang/Object;Ljava/lang/Object;Z)V
.limit stack 2
.limit locals 3
iload_2
@rednaxelafx
rednaxelafx / HashMapStackOverflow.java
Last active Jul 2, 2018
JDK8: StackOverflowError of HashMap due to self reference
View HashMapStackOverflow.java
import java.util.*;
public class HashMapStackOverflow {
public static void main(String[] args) throws Exception {
HashMap<String, Object> map = new HashMap<>();
map.put("self", map);
System.out.println(map.hashCode());
}
}
@rednaxelafx
rednaxelafx / command_prompt
Created Jul 16, 2015
Demo of Clang++'s implementation of C++ static local variable
View command_prompt
$ clang++ -S -emit-llvm yy.cc
@rednaxelafx
rednaxelafx / test_libjit.cc
Last active Aug 16, 2022
Comparing different JIT libraries via contrived simple examples
View test_libjit.cc
#include <iostream>
// #include <jit/jit-dump.h>
#include <jit/jit-plus.h>
// Create an example function equivalent to:
// int foo(int x, int y, int z) {
// return x + y * z;
// }
jit_function create_example_foo(jit_context& context, int opt_level) {
jit_type_t signature = jit_function::signature_helper(
@rednaxelafx
rednaxelafx / TestVec.java
Created Feb 9, 2015
Simple demo of autovectorization in Oracle JDK8u25 on Linux/x64 with AVX
View TestVec.java
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 / .hotspot_compiler
Created Mar 22, 2014
Demo of HotSpot C2 optimizing consecutive instanceof's. Run on JDK8 (b132). C2 missed an optimization for CmpP(LoadKlass(AddP(DecodeNKlass(LoadNKlass(...)))), ConP), should use CmpN(LoadNKlass(), ConNKlass), probably due to NPG changes.
View .hotspot_compiler
exclude SubtypeTest main
dontinline SubtypeTest *
compileonly SubtypeTest driver
compileonly SubtypeTest getObject
@rednaxelafx
rednaxelafx / range_check.patch
Last active Apr 8, 2018
A quick-n-dirty patch to implement JDK-8003585: strength reduce or eliminate range checks for power-of-two sized arrays
View range_check.patch
diff -r 9d39e8a8ff61 src/share/vm/opto/subnode.cpp
--- a/src/share/vm/opto/subnode.cpp Fri Dec 27 07:51:07 2013 -0800
+++ b/src/share/vm/opto/subnode.cpp Wed Feb 12 14:59:00 2014 -0800
@@ -1206,6 +1206,40 @@
Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2));
return new (phase->C) BoolNode( ncmp, _test.commute() );
}
+
+ // Change ((x & m) <= m) into (m >= 0)
+ // Integer expressions which perform bitwise and can be proven to
@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();