Skip to content

Instantly share code, notes, and snippets.

View rednaxelafx's full-sized avatar

Kris Mok rednaxelafx

View GitHub Profile
@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 / spark-shell-session
Created July 30, 2019 06:26
Apache Spark master running on OpenJDK11u
$ bin/spark-shell
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/home/krismok/code/work/oss-spark-readonly/assembly/target/scala-2.12/jars/spark-unsafe_2.12-3.0.0-SNAPSHOT.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
19/07/30 06:03:19 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
@rednaxelafx
rednaxelafx / TestSIMD.java
Last active July 31, 2019 16:41
HotSpot C2 SIMD vectorization demo
import java.util.Arrays;
public class TestSIMD {
public static void doCompute(int[] a, int[] x, int[] y, int[] z) {
for (int i = 0; i < a.length; i++) {
a[i] = a[i] + x[i] * y[i] * z[i];
}
}
@rednaxelafx
rednaxelafx / command_prompt
Last active April 10, 2018 07:09
demo C# and Scala's lazy val and lambda capturing
$ csc test.cs
Microsoft (R) Visual C# Compiler version 2.0.0.61404
Copyright (C) Microsoft Corporation. All rights reserved.
$ mono test.exe eager
MainThread
$ mono test.exe
NewTestThread
$ scalac test.scala
$ java -cp $SCALA_HOME/lib/*:. TestLazy eager
@rednaxelafx
rednaxelafx / clhsdb_session
Created April 17, 2017 17:37
Figuring out what bytecode scala.Predef$.augmentString corresponded to
$ sudo $JAVA_HOME/bin/java -cp $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB
Password:
hsdb> attach 15168
Attaching to process 15168, please wait...
hsdb> class scala.Predef$
scala/Predef$ @0x00000007c003eb60
hsdb> print 0x00000007c003eb60
public final class scala.Predef$ @0x00000007c003eb60
@rednaxelafx
rednaxelafx / Fib.java
Created March 7, 2017 01:07
Yet another naive Fibonacci example
import java.util.*;
public class Fib {
static int o = 0;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long start = System.currentTimeMillis();
int answer = fib(n);
@rednaxelafx
rednaxelafx / SynchSB.java
Last active April 17, 2018 12:44
Demo JDK8 HotSpot C2's escape analysis + lock elision
public class SynchSB {
StringBuilder sb = new StringBuilder();
public synchronized int length() {
return sb.length();
}
public synchronized StringBuilder append(String str) {
return sb.append(str);
}
@rednaxelafx
rednaxelafx / notes.md
Created January 10, 2017 05:54
A partial patch to make CRuby 2.3.3 compile with OPT_STACK_CACHING on. Note that this doesn't fully work yet.

This patch fixes issues with building CRuby 2.3.3 with OPT_STACK_CACHING turned on.

Note that it doesn't fully work yet. This patch does allow the core VM to build, producing the miniruby binary. But as soon as it runs any substantial Ruby code, e.g. building the cgi library, it ends up crashing. The implementation in compile.c around iseq_set_sequence_stackcaching() / REPLACE_ELEM and friends is probably where the remaining bug is. It'd be nice to know what caused nobu-san to comment out REPLACE_ELEM in the first place.

$ make install
...
@rednaxelafx
rednaxelafx / .jrubyrc
Last active April 10, 2018 08:12
JRuby 9.1.6.0 example of massign (paralle assignment) optimized
jit.dumping=true
jit.logging=true
jit.logging.verbose=true
jit.threshold=500
@rednaxelafx
rednaxelafx / A.java
Last active April 10, 2018 08:55 — forked from anonymous/A.java
An example of vtable initialization and package access override, run on Oracle JDK8
package pkga;
public class A {
/* packcage access */ void fun() {
System.out.println("A::fun()");
}
}