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
@xzer
xzer / RangeModule.java
Created September 17, 2023 05:31
LC-715
class RangeModule {
static class Range {
private static final boolean DEBUG = false;
private static final boolean BIASED_SPLIT = true;
private static final int MID_NON_MARKED = -1;
private static final int MID_ALL_MARKED = -2;
int startValue;
int endValue;

HotSpot Escape Analysis and Scalar Replacement Status

Introduction

Escape Analysis (EA) is a compiler analysis to answer the following questions for a given object O, method M, and thread T.

  • Escapes(O, M): Does object O outlive the execution of method M? This may happen for instance if a reference to O is assigned to a global variable.
  • Escapes(O, T): Does object O escape the current execution thread? This may happen for instance if a reference to O is copied to another thread.

Answers to these questions enable a compiler to perform a few highly effective optimizations, for instance, Stack Allocation (SA), Lock Elision (LE), and Scalar Replacement of Aggregates (SRA). Note that,

@GuillaumeDua
GuillaumeDua / Concept-based polymorphism in modern Cpp.md
Last active May 4, 2024 09:30
Concept-based polymorphism in modern C++

Concept-based polymorphism in modern C++

Date 05-05-2021 - 10-17-2023
Revision R3
Author Guillaume Dua
Reviewers Loïc Joly, Antoine Morrier
List of pre-defined events (to be used in -e):
branch-misses [Hardware event]
bus-cycles [Hardware event]
cache-misses [Hardware event]
cache-references [Hardware event]
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
stalled-cycles-backend OR idle-cycles-backend [Hardware event]
stalled-cycles-frontend OR idle-cycles-frontend [Hardware event]
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f1187ed709f, pid=124446, tid=0x00007f115b1a1700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_191-b12) (build 1.8.0_191-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V [libjvm.so+0x9c109f] SharedRuntime::resolve_sub_helper(JavaThread*, bool, bool, Thread*)+0x9bf
#
@hashbrowncipher
hashbrowncipher / coredump_uploader.sh
Created November 11, 2019 03:38
Example coredump uploader
#!/bin/bash
# Depends on zstd (>1.3.6) and aws-cli
set -o errexit
set -o nounset
set -o pipefail
# Set kernel.core_pattern = | coredump_uploader.sh %P %s %E
PID=$1
shift
SIGNAL=$1

Guava, Graal and Partial Escape Analysis

Recently java 10 release happened - in fact, Graal was available earlier, but now it is more easy to access and use it - Congratulations, you're running #Graal! - just add a couple options:

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

What does it can provide for us and what kind of enhancements we can expect to get, and more over - what dirty-hacks could be dropped ?

Let's explore an example - looks a bit synthetic but based on a real production code.

@graphitemaster
graphitemaster / WORKING_AROUND_OFFSETOF_LIMITATIONS.MD
Last active February 29, 2024 08:49
Working around offsetof limitations in C++

Working around offsetof limitations in C++:

There is sometimes a situation in which one needs to get the relative offset of a structure field, common examples of this include serialization frameworks which aid to serialize objects, vertex attributes for rendering (D3D, GL.), etc.

The most common technique for getting this information is through the offsetof macro defined in stddef.h. Unfortunately using the macro in C++ comes with a new set of restrictions that prevent some (subjectively valid) uses of it.

@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");
+
@ytoshima
ytoshima / sum.java
Created November 18, 2011 16:02
PrintOptoAssembly output example
// -XX::CompileOnly=sum::doit would narrow down the method to compile, but it
// is not used here.
$ ~/jdk1.7.0-b147/fastdebug/bin/java -XX:+PrintOptoAssembly sum
VM option '+PrintOptoAssembly'
{method}
- klass: {other class}
- this oop: 0x911f8110
- method holder: 'sum'
- constants: 0x911f7e10 constant pool [32] for 'sum' cache=0x911f86b0