Skip to content

Commit f88d184

Browse files
committed
Improve pgo-build.sh
1 parent 45d6657 commit f88d184

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

.github/scripts/pgo-build.sh

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,61 @@
11
#!/bin/bash
2+
set -e
3+
4+
# This script should be run from the OpenJDK source directory. This is a quick check.
5+
if [ "$(basename "$PWD")" != "openjdk" ] || [ ! -f "configure" ] || [ ! -d "src" ] || [ ! -d "test" ]; then
6+
echo "Error: Please run this script from the OpenJDK source directory."
7+
exit 1
8+
fi
9+
10+
# The directory of this script
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
# The directory of the binding
13+
BINDING_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
14+
BINDING_MMTK_DIR="$BINDING_DIR/mmtk"
15+
BINDING_OPENJDK_DIR="$BINDING_DIR/openjdk"
16+
# Rust version
17+
RUST_VERSION=$(tr -d '[:space:]' < "$BINDING_MMTK_DIR/rust-toolchain")
18+
19+
# llvm-profdata: we need to use the same version as the Rust compiler to avoid compatibility issues.
20+
LLVM_PROFDATA="$(dirname "$(rustc +"$RUST_VERSION" --print target-libdir)")/bin/llvm-profdata"
21+
# The dacapo jar used to profile.
22+
DACAPO_JAR=/usr/share/benchmarks/dacapo/dacapo-23.11-MR2-chopin.jar
23+
24+
# OpenJDK config name
25+
OPENJDK_DEBUG_LEVEL=release
26+
OPENJDK_CONFIG=linux-x86_64-server-$OPENJDK_DEBUG_LEVEL
27+
28+
# Rust profile data directory
29+
PROFILE_DATA_DIR="/tmp/$USER/pgo-data"
230

331
# PGO seems to have problems with incremental compilation or something else similar.
432
# PGO build might fail with error messages such as
533
# error: file `/tmp/$USER/pgo-data/merged.profdata` passed to `-C profile-use` does not exist.
634
# when the file clearly exists on disk.
735
# This happens on both 1.71.1 and 1.66.1, and running cargo clean prior to building seems to reliably work around the problem.
836
# We can remove this once the compiler bug is fixed.
9-
pushd ../mmtk-openjdk/mmtk
10-
cargo clean
11-
popd
37+
clean_binding_mmtk() {
38+
pushd "$BINDING_MMTK_DIR"
39+
cargo clean
40+
popd
41+
}
42+
43+
clean_binding_mmtk
1244

1345
# Compile with profiling support
14-
RUSTFLAGS="-Cprofile-generate=/tmp/$USER/pgo-data" make CONF=linux-x86_64-server-release THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk images
46+
sh configure --disable-warnings-as-errors --with-debug-level=$OPENJDK_DEBUG_LEVEL
47+
RUSTFLAGS="-Cprofile-generate=$PROFILE_DATA_DIR" make CONF=$OPENJDK_CONFIG THIRD_PARTY_HEAP=$BINDING_OPENJDK_DIR images
1548

1649
# Remove extraneous profiling data
17-
rm -rf /tmp/$USER/pgo-data/*
50+
rm -rf $PROFILE_DATA_DIR/*
1851

1952
# Profile using fop
20-
MMTK_PLAN=GenImmix MMTK_STRESS_FACTOR=4194304 MMTK_PRECISE_STRESS=false ./build/linux-x86_64-server-release/images/jdk/bin/java -XX:MetaspaceSize=500M -XX:+DisableExplicitGC -XX:-TieredCompilation -Xcomp -XX:+UseThirdPartyHeap -Xms60M -Xmx60M -jar /usr/share/benchmarks/dacapo/dacapo-23.11-MR2-chopin.jar -n 5 fop
53+
MMTK_PLAN=GenImmix MMTK_STRESS_FACTOR=16777216 MMTK_PRECISE_STRESS=false ./build/$OPENJDK_CONFIG/images/jdk/bin/java -XX:MetaspaceSize=500M -XX:+DisableExplicitGC -XX:-TieredCompilation -Xcomp -XX:+UseThirdPartyHeap -Xms60M -Xmx60M -jar $DACAPO_JAR -n 5 fop
2154

2255
# Merge profiling data
23-
/opt/rust/toolchains/1.83.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o /tmp/$USER/pgo-data/merged.profdata /tmp/$USER/pgo-data
56+
"$LLVM_PROFDATA" merge -o $PROFILE_DATA_DIR/merged.profdata $PROFILE_DATA_DIR
2457

25-
pushd ../mmtk-openjdk/mmtk
26-
cargo clean
27-
popd
58+
clean_binding_mmtk
2859

2960
# Compile using profiling data
30-
RUSTFLAGS="-Cprofile-use=/tmp/$USER/pgo-data/merged.profdata -Cllvm-args=-pgo-warn-missing-function" make CONF=linux-x86_64-server-release THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk images
61+
RUSTFLAGS="-Cprofile-use=$PROFILE_DATA_DIR/merged.profdata -Cllvm-args=-pgo-warn-missing-function" make CONF=$OPENJDK_CONFIG THIRD_PARTY_HEAP=$BINDING_OPENJDK_DIR images

0 commit comments

Comments
 (0)