Skip to content

Instantly share code, notes, and snippets.


Kris Mok rednaxelafx

View GitHub Profile
rednaxelafx / hsdis-ubuntu.patch
Created Nov 12, 2010
A quick-and-dirty patch to build hsdis ( on 32-bit Ubuntu 10.04. Do `make ARCH=i386 all` on Ubuntu 64-bit to build hsdis-i386
View hsdis-ubuntu.patch
diff -rupN original/hsdis.c hsdis.c
--- original/hsdis.c 2010-11-12 11:39:59.617873967 +0800
+++ hsdis.c 2010-11-12 11:42:00.566353179 +0800
@@ -29,7 +29,11 @@
#include "hsdis.h"
-#include <sysdep.h>
+#if 0
+ #include <sysdep.h>
rednaxelafx / mrp-url-change.patch
Created Nov 12, 2010
A patch to reflect URL changes in Harmony that are depended on by MRP. This patch should apply to MRP branch a4170d982dd2319c4fd0a8a3fea1dda408eb71ec Applying this patch will fix build problems but not runtime problems. Still got more work to do.
View mrp-url-change.patch
diff --git a/build/components/harmony.xml b/build/components/harmony.xml
index 7ba9405..2e0ed25 100755
--- a/build/components/harmony.xml
+++ b/build/components/harmony.xml
@@ -18,6 +18,7 @@
<property name="harmony.version" value="5.0M10"/>
<property name="harmony.description" value="Apache Harmony class libraries"/>
<property name="harmony.svn.revision" value="782693"/>
+ <property name="harmony.base.url" value=""/>
<property name="harmony.patchlevel" value="0"/>
rednaxelafx / mrp_gnu_source.patch
Created Nov 16, 2010
Fix MRP build problem on Ubuntu 10.10 x64, GCC 4.4.4-14ubuntu5. Defining __USE_GNU directly in source code apparently didn't work in this configuration.
View mrp_gnu_source.patch
diff --git a/tools/bootloader/sysSignal_Intel.c b/tools/bootloader/sysSignal_Intel.c
index c283e96..d7d04fa 100755
--- a/tools/bootloader/sysSignal_Intel.c
+++ b/tools/bootloader/sysSignal_Intel.c
@@ -14,6 +14,14 @@
+ * Define the _GNU_SOURCE macro before first include header,
+ * instead of defining glibc's internal macro __USE_GNU.
rednaxelafx /
Created Nov 18, 2010
Generate DOT graphs to visualize a Velocity template's AST. To run this program, the following dependencies are needed: velocity-1.6.4.jar/commons-collections-3.2.1.jar/commons-lang-2.5.jar
import static org.apache.commons.lang.StringEscapeUtils.escapeJava;
import static org.apache.commons.lang.StringUtils.isEmpty;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.runtime.parser.node.ASTAddNode;
import org.apache.velocity.runtime.parser.node.ASTAndNode;
import org.apache.velocity.runtime.parser.node.ASTAssignment;
import org.apache.velocity.runtime.parser.node.ASTBlock;
rednaxelafx /
Created Nov 20, 2010
Find out what's going on in Velocity, the interaction during rendering between a template and the context passed in. Bad news though, side-effects can happen which really forbids caching the variables locally.
import java.util.Arrays;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
* Demonstrate interaction between a template and its context.
rednaxelafx / check_jar.rb
Created Nov 25, 2010
A script to verify classes within a JAR file. Depends on the ASM, specifically asm-all-<ver>.jar. Edit the ASM_PATH constant to match your installation. Requires Ruby 1.9+
View check_jar.rb
#!/usr/bin/env ruby
ASM_PATH = "asm-all-3.3.jar"
jar_file, additional_classpath = ARGV
raise "usage: check_jar <jar_file> <additional_classpath>" unless jar_file
`jar tf #{jar_file}`.lines.grep(/\.class$/i).
map {|s| s.chomp[0..-7].gsub '/', '.'}.
rednaxelafx / gist:759495
Created Dec 30, 2010
A code snippet to show some relationship between JVM/HotSpot's and Dalvik's interpreter.
View gist:759495
Java source code:
k = i + j;
May compile to Java bytecode:
And may turn into Dalvik VM code:
rednaxelafx / prettyprint.js
Created Jan 20, 2011
Pretty print JavaScript objects (does not conform to JSON, because we don't want escape sequences in string literals)
View prettyprint.js
function isPlainObject(o) {
return o && === '[object Object]' && 'isPrototypeOf' in o;
function isArray(o) {
return == '[object Array]';
function objectToString(val) {
var INDENT = '&nbsp;&nbsp;';
rednaxelafx / gist:825394
Created Feb 14, 2011
a few examples of the implicit null check generated by HotSpot's opto compiler
View gist:825394
// java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=compileonly,TestC2NullCheck.getValue -XX:-UseFastAccessorMethods -XX:+PrintAssembly TestC2NullCheck
public class TestC2NullCheck {
public static int getValue(Foo foo) {
return foo.value;
public static void main(String[] args) throws Exception {
for (int i = 0; i < 120000; i++) {
getValue(new Foo());
rednaxelafx / VM arguments
Created Feb 14, 2011
A strange GC log that I'm investigating.
View VM arguments
-Xmx1024m -Xms1024m -Xmn512m -Xss512k -XX:PermSize=256m -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC -XX:MaxGCPauseMillis=100 -XX:+UseAdaptiveSizePolicy -XX:+DisableExplicitGC -verbose:gc -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps