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 / c2_pea_details.md
Created March 3, 2023 00:35
Allocation State and Materialization in C2 PEA

Allocation State and Materialization in C2 PEA

Introduction

Partial Escape Analysis (PEA) is a flow sensitive analysis. It eagerly defers an object to the point where its object identity is required. This optimization avoids allocating the object on the paths where the object identity is not required.

Previously, we proposed to implement Stadler’s PEA algorithm [^1] in OpenJDK HotSpot C2 [^2]. We still stick with the algorithm and our high-level design. We are going to describes how we track allocation state and conduct materialization in C2 parser. The contribution of this paper is that we put forward piggybacking PEA on the parsing phase which lowers program from high-level IR to low-level IR. No extra pass is required in this approach.

@navyxliu
navyxliu / Example3_3.java
Created January 30, 2023 23:04
Example3_3.java
// java -ea -Xms16m -Xmx16M -XX:+UnlockExperimentalVMOptions -XX:-UseOnStackReplacement -XX:+PrintEscapeAnalysis -XX:+PrintEliminateAllocations -XX:+UseEpsilonGC -XX:-UseTLAB -XX:+DoPartialEscapeAnalysis -XX:CompileCommand=compileonly,Example3_3::foo -XX:CompileCommand=dontinline,Example3_3::blackhole -XX:CompileCommand=quiet -Xbatch Example3_3
class Example3_3 {
// use volatile to force c2 to load it again
volatile int value;
Example3_3(int value) {
this.value = value;
}
void blackhole(int field) {
@navyxliu
navyxliu / Example3.java
Created January 18, 2023 01:00
Example3.java
// from ResourceScopeCloseMin.java
// https://bugs.openjdk.org/browse/JDK-8267532
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Example3 {
Runnable dummy = () -> {};
@navyxliu
navyxliu / Example3_2.java
Created December 14, 2022 22:01
Example3_2.java
import java.util.*;
class Example3_2 {
void bar(boolean cond, ArrayList<Integer> L) {
if(cond) {
L.add(1); // can't inline java.util.ArrayList::add (23 bytes) low call site frequency
}
}
@navyxliu
navyxliu / Example3_1.java
Last active December 13, 2022 22:48
Example3_1.java
// java -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:-UseTLAB -XX:CompileOnly='Example3_1.foo' -XX:+DoPartialEscapeAnalysis Example3_1
import java.util.ArrayList;
class Example3_1 {
public ArrayList<Integer> _cache;
public void foo(boolean cond) {
ArrayList<Integer> x = new ArrayList<Integer>();
if (cond) {
_cache = x;
@navyxliu
navyxliu / Example2.java
Last active December 15, 2022 00:06
Example2.java
// -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example2.foo' -XX:CompileCommand=dontinline,Example2.blackhole
class Example2 {
private Object _cache;
public Object foo(boolean cond) {
Object x = new Object();
blackhole();
if (cond) {
_cache = x;
@navyxliu
navyxliu / Example1.java
Created October 19, 2022 21:24
PEA_C2_Example1
// -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example1.ivanov' -XX:CompileCommand=dontinline,Example1.blackhole
class Example1 {
private Object _cache;
public void foo(boolean cond) {
Object x = new Object();
if (cond) {
_cache = x;
}
}
@navyxliu
navyxliu / PEA_C2.md
Last active January 22, 2023 17:09
RFC: Partial Escape Analysis in HotSpot C2

RFC: Partial Escape Analysis in HotSpot C2

Summary

Reduce object-oriented overhead of a method compiled by C2 compiler. The C2 parser delays heap allocation and initialization to the place from which the object is about to escape. The optimization reduces allocation and initialization cost of an object on the paths of flowgraph where it is not escaped.

Goals

  • Perform flow-sensitive escape analysis
  • Delay heap allocation and initialization of an object until it is about to escape.
@navyxliu
navyxliu / PartialEATest.java
Created September 23, 2022 19:50
PartialEATest.java
package com.amazon.jdkteam;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
@navyxliu
navyxliu / scores.rb
Last active July 21, 2022 00:47
scores.rb
#!/usr/bin/env ruby
# do the statistics of renaissance results
#
# probably should choose gem 'enumerable-statistics' in the future.
# so far, we only need simple procedures.
#
def median(a)
copy = a.sort
return copy[a.size / 2]