Skip to content

Instantly share code, notes, and snippets.

View navyxliu's full-sized avatar
🍉
watermelon

xin liu navyxliu

🍉
watermelon
  • Amazon.com
  • Seattle
View GitHub Profile
@navyxliu
navyxliu / EmptyString.md
Created March 28, 2024 05:10
EmptyString Example
// ./build/linux-x86_64-server-fastdebug/jdk/bin/java -XX:+PrintCompilation -XX:CompileCommand=compileonly,EmptyString::main  -XX:CompileCommand=quiet -Xbatch -XX:+PrintOptoAssembly -XX:CompileCommand=IGVPrintLevel,EmptyString::main,3 EmptyString
class EmptyString {
  public static void main(String[] args) {
        String msg = "";
        int x = 0;

        for (int i = 0; i < 300_000; ++i)  {
          if (msg.length() > 0) {
            x++;
@navyxliu
navyxliu / async_log_dropped.rb
Created March 19, 2024 04:21
A scripp to count how many messages are dropped.
#!/usr/bin/env ruby
lines = ARGF.readlines
total = 0
lines.each do |line|
if line =~ /(\d+)\smessages dropped due to async logging/
num = $1.to_i
total = total + num
#print line
end
end
@navyxliu
navyxliu / UnderProfiledSubprocedure.java
Created February 10, 2024 06:11
C2 inliner rejects a callee because of under-profiled subprocedure.
// java -XX:CompileOnly='UnderProfiledSubprocedure.foo' -XX:+PrintInlining -XX:+PrintCompilation -XX:CompileCommand=quiet -Xbatch UnderProfiledSubprocedure
import java.util.ArrayList;
class UnderProfiledSubprocedure {
private static int ODD = 100;
public void foo(boolean cond) {
var x = new ArrayList<Integer>();
if (cond) { // the branch is only taken by ODD
x.add(0); // ArrayList::add(E) is the subprocedure. it will call ArrayList::add(E, Object[], int)
@navyxliu
navyxliu / .zshrc
Created February 6, 2024 22:07
handy scripts on macOS
; my handy scripts on MacOS
function realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
function jdk_select() {
if [ -e $1/bin/java ]; then
P=$(realpath $1)
export JAVA_HOME=$P
export PATH=$JAVA_HOME/bin:$PATH
@navyxliu
navyxliu / jsc.md
Last active October 31, 2023 20:51
Building your own jsc

troubleshooting

➜  WebKit git:(main) ./WebKitBuild/Debug/jsc
dyld[8692]: Symbol not found: __ZN3JSC27retrieveTypeImportAttributeEPNS_14JSGlobalObjectERKN3WTF7HashMapINS2_6RefPtrINS2_17UniquedStringImplENS2_12RawPtrTraitsIS5_EENS2_21DefaultRefDerefTraitsIS5_EEEENS2_6StringENS2_11DefaultHashISA_EENS2_10HashTraitsISA_EENSE_ISB_EENS2_15HashTableTraitsEEE
  Referenced from: <BD3D10DA-F74B-3755-8B54-29D1F10163E5> /Users/xxinliu/Devel/WebKit/WebKitBuild/Debug/jsc (built for macOS 14.0 which is newer than running OS)
  Expected in:     <957522FA-9B44-3C8F-9BD4-A209C728B133> /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore
[1]    8692 abort      ./WebKitBuild/Debug/jsc

The problem here is JSC depends on WTF(who would name its library that? it seems the acronym of webkit's template framework). Dynamic loader has difficulty to resolve this symbol in WTF. we need to teach dynamic laoder to get from what you built

@navyxliu
navyxliu / RelockInDeopt.java
Created October 24, 2023 21:49
RelockInDeopt.java
// java -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,RelockInDeopt::snippet2 -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:+PrintCompilation -XX:+TraceDeoptimization -XX:+PrintEliminateLocks -XX:+PrintDeoptimizationDetails -XX:-PrintInlining -Xbatch -XX:+PrintEliminateAllocations RelockInDeopt
class RelockInDeopt {
static int staticInt = 0;
static Object staticObj = null;
public static void snippet2() {
Object escaped = new Object();
Object nonEscaped = new Object();
synchronized (nonEscaped) {
@navyxliu
navyxliu / unstable_if.md
Last active October 19, 2023 19:32
Aggressive liveness for unstable_if traps

Aggressive liveness for unstable_if traps

Background:

C2 is a speculative compiler. When it encounters a conditional branch and profiling data suggest that the control is highly likely to take one path, parser intends to prune the other path and leave a runtime stub uncommon_trap. We refer to it as “unstable_if trap” because the reason of this stub is unstable_if. If the rare case does happen, the trap triggers deoptimization. HotSpot realizes that current profiling data do not hold up and destroys this compilation. The execution returns to interpreter. Presumably, the upcoming compilation of this method will correct itself with updated profiling data.

Bci(byte code index) in JVM is analogous to the PC(program counter) of a physical processor. It points to the current bytecode in interpreter. Because an uncommon_trap stub punts to interpreter, it must restore the interpreter state in JVM. Restoring the interpreter state means that all variables live at the current bci must have cor

@navyxliu
navyxliu / passive_materialization.md
Last active October 6, 2023 19:21
Passive materialization in C2 Partial Escape Analysis

Passive materialization in C2 Partial Escape Analysis

Problem Statement

Besides escaping points, C2 Partial Escape Analysis(PEA) can optionally materialize the object at the convergence block when any of its predecessors has already materialized it. It is referred to as passive materialization. It is optional because C2 currently skips it and programs are still correct. Here is an example. Object pt is escaped at line 6.

  1  public double test(boolean cond, double x, double y) {
  2      Point pt = new Point(x, y);
 3 pt.x = 3.0d;
@navyxliu
navyxliu / gist:3463c98f12b97d6614167f0cc48375a8
Created October 2, 2023 03:32
My build script of llvm
#/bin/bash
#
# 1.after check out llvm repo, create a directory 'llvm-build' nearby.I prefer out-of-tree-build.
# 2.configure
# execute 'sh ./mybuild.sh RelWithDebInfo'
#
# the only argument is CMAKE_BUILD_TYPE. options: Release, Debug, RelWithDebInfo etc. ref: https://llvm.org/docs/CMake.html
# Debug build is desireable for development, but be mindful that it requires a lot of memory in linkage stage. Curb the number of parallel jobs.
# I configure mlir,clang and lld(llvm will be built as the dependency). I only select x86 and amdgpu.
#
@navyxliu
navyxliu / Example1_Point.java
Created March 29, 2023 22:39
Passive Materialization
import java.lang.Math;
class Example1_Point {
static class Point {
double x;
double y;
public Point(double x, double y) {
this.x = x;
this.y = y;