|
1 | 1 | #!/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" |
2 | 30 |
|
3 | 31 | # PGO seems to have problems with incremental compilation or something else similar. |
4 | 32 | # PGO build might fail with error messages such as |
5 | 33 | # error: file `/tmp/$USER/pgo-data/merged.profdata` passed to `-C profile-use` does not exist. |
6 | 34 | # when the file clearly exists on disk. |
7 | 35 | # 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. |
8 | 36 | # 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 |
12 | 44 |
|
13 | 45 | # 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 |
15 | 48 |
|
16 | 49 | # Remove extraneous profiling data |
17 | | -rm -rf /tmp/$USER/pgo-data/* |
| 50 | +rm -rf $PROFILE_DATA_DIR/* |
18 | 51 |
|
19 | 52 | # 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 |
21 | 54 |
|
22 | 55 | # 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 |
24 | 57 |
|
25 | | -pushd ../mmtk-openjdk/mmtk |
26 | | -cargo clean |
27 | | -popd |
| 58 | +clean_binding_mmtk |
28 | 59 |
|
29 | 60 | # 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