Skip to content

Commit

Permalink
[GR-45890] Use G1 by default on Native EE on Linux
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3939
  • Loading branch information
eregon committed Aug 17, 2023
2 parents f5c5c19 + 41c2f89 commit b2cec7c
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
New features:

* Updated to Ruby 3.2.2 (#3039, @eregon, @andrykonchin).
* TruffleRuby Native on Oracle GraalVM on Linux now uses the G1 garbage collector which is much faster.

Bug fixes:

Expand Down
4 changes: 4 additions & 0 deletions ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ local part_definitions = {
HOST_VM_CONFIG: "graal-enterprise",
},
},
native_ee_aux: {
mx_env:: "native-ee-aux",
},
host_inlining_log: {
# Same as in mx.truffleruby/native-host-inlining
mx_options+:: [
Expand Down Expand Up @@ -551,6 +554,7 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
"ruby-test-svm-ce-darwin-aarch64-new": $.platform.darwin_aarch64 + $.jdk.new + $.env.native + gate + native_tests,
"ruby-test-svm-ee-linux-amd64": $.platform.linux + $.jdk.lts + $.env.native_ee + $.env.gdb_svm + gate + native_tests + $.env.host_inlining_log + { timelimit: "01:30:00" },
"ruby-test-svm-ee-darwin-aarch64": $.platform.darwin_aarch64 + $.jdk.lts + $.env.native_ee + gate + native_tests,
"ruby-test-svm-ee-aux-linux-amd64": $.platform.linux + $.jdk.lts + $.env.native_ee_aux + $.env.gdb_svm + gate + native_tests + { timelimit: "01:30:00" },
},

local other_rubies = {
Expand Down
4 changes: 2 additions & 2 deletions mx.truffleruby/env_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Here is how the various env files relate to each other:
* `jvm-ee`: + Oracle GraalVM Compiler + `Truffle enterprise`
* `jvm-ee-ntl`: + native toolchain launchers
* `jvm-ee-libgraal`: + libgraal
* `native-ee`: + librubyvm + `Truffle Macro Enterprise`
* `native-ee-g1`: + Native Image G1
* `native-ee`: + librubyvm + `Truffle Macro Enterprise` + Native Image G1
* `native-ee-aux`: + `AuxiliaryEngineCache`, - Native Image G1 (currently incompatible)
* `jvm-gu`: + Graal Updater
* `jvm-js`: + Graal.js
* `jvm-py`: + GraalPython
2 changes: 1 addition & 1 deletion mx.truffleruby/jvm-ee
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GRAALVM_SKIP_ARCHIVE=true
DYNAMIC_IMPORTS=/tools,/graal-enterprise
DYNAMIC_IMPORTS=/tools,/truffleruby-enterprise,/graal-enterprise
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise
2 changes: 1 addition & 1 deletion mx.truffleruby/jvm-ee-libgraal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GRAALVM_SKIP_ARCHIVE=true
DYNAMIC_IMPORTS=/tools,/graal-enterprise,/substratevm-enterprise
DYNAMIC_IMPORTS=/tools,/truffleruby-enterprise,/graal-enterprise,/substratevm-enterprise
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise,LibGraal Enterprise
NATIVE_IMAGES=suite:sulong,lib:jvmcicompiler
2 changes: 1 addition & 1 deletion mx.truffleruby/jvm-ee-ntl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GRAALVM_SKIP_ARCHIVE=true
DYNAMIC_IMPORTS=/tools,/graal-enterprise,/substratevm-enterprise
DYNAMIC_IMPORTS=/tools,/truffleruby-enterprise,/graal-enterprise,/substratevm-enterprise
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise
NATIVE_IMAGES=suite:sulong
2 changes: 1 addition & 1 deletion mx.truffleruby/mx_truffleruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def verify_ci(args):
],
build_args_enterprise=[
'-J-Xmx7g', # Set Xmx to use a reliable amount of memory
],
] + (['--gc=G1', '-H:-ProtectionKeys'] if (mx.get_os() == 'linux' and 'NATIVE_IMAGE_AUXILIARY_ENGINE_CACHE' not in os.environ) else []), # G1 is only supported on linux currently
language='ruby',
option_vars=[
'RUBYOPT',
Expand Down
8 changes: 4 additions & 4 deletions mx.truffleruby/native-ee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GRAALVM_SKIP_ARCHIVE=true
DYNAMIC_IMPORTS=/tools,/graal-enterprise,/substratevm-enterprise
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise,Truffle Macro Enterprise
DYNAMIC_IMPORTS=/tools,/truffleruby-enterprise,/graal-enterprise,/substratevm-enterprise,substratevm-enterprise-gcs
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise,Truffle Macro Enterprise,suite:substratevm-enterprise-gcs
NATIVE_IMAGES=suite:sulong,lib:rubyvm
EXTRA_IMAGE_BUILDER_ARGUMENTS=rubyvm:-H:BuildOutputJSONFile=native-image-build-rubyvm.json rubyvm:-H:+AuxiliaryEngineCache rubyvm:-H:ReservedAuxiliaryImageBytes=1073741824
EXTRA_IMAGE_BUILDER_ARGUMENTS=rubyvm:-H:BuildOutputJSONFile=native-image-build-rubyvm.json
# To also create the standalone
INSTALLABLES=TruffleRuby
INSTALLABLES=TruffleRuby
7 changes: 4 additions & 3 deletions mx.truffleruby/native-ee-g1 → mx.truffleruby/native-ee-aux
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GRAALVM_SKIP_ARCHIVE=true
DYNAMIC_IMPORTS=/tools,/graal-enterprise,/substratevm-enterprise,substratevm-enterprise-gcs
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise,Truffle Macro Enterprise,SubstrateVM Enterprise GC
DYNAMIC_IMPORTS=/tools,/truffleruby-enterprise,/graal-enterprise,/substratevm-enterprise
COMPONENTS=TruffleRuby,suite:tools,GraalVM enterprise compiler,Truffle enterprise,SubstrateVM Enterprise,Truffle Macro Enterprise
NATIVE_IMAGES=suite:sulong,lib:rubyvm
EXTRA_IMAGE_BUILDER_ARGUMENTS=rubyvm:-H:BuildOutputJSONFile=native-image-build-rubyvm.json rubyvm:-H:+UseG1GC
EXTRA_IMAGE_BUILDER_ARGUMENTS=rubyvm:-H:BuildOutputJSONFile=native-image-build-rubyvm.json rubyvm:-H:+AuxiliaryEngineCache rubyvm:-H:ReservedAuxiliaryImageBytes=1073741824
NATIVE_IMAGE_AUXILIARY_ENGINE_CACHE=true
# To also create the standalone
INSTALLABLES=TruffleRuby
1 change: 1 addition & 0 deletions spec/tags/core/gc/count_tags.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
slow:GC.count increases as collections are run
native-g1:GC.count increases as collections are run
2 changes: 2 additions & 0 deletions spec/tags/core/gc/stat_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
slow:GC.stat increases count after GC is run
slow:GC.stat increases major_gc_count after GC is run
fails:GC.stat raises an error if an unknown key is given
native-g1:GC.stat increases count after GC is run
native-g1:GC.stat increases major_gc_count after GC is run
1 change: 1 addition & 0 deletions spec/tags/optional/capi/gc_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ slow:CApiGCSpecs rb_gc increases gc count
fails:CApiGCSpecs rb_gc_adjust_memory_usage adjusts the amount of registered external memory
slow:CApiGCSpecs rb_gc_register_address keeps the value alive even if the value is assigned after rb_gc_register_address() is called
slow:CApiGCSpecs rb_global_variable keeps the value alive even if the value is assigned after rb_global_variable() is called
native-g1:CApiGCSpecs rb_gc increases gc count
5 changes: 4 additions & 1 deletion spec/truffleruby.mspec
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ class MSpecScript

if defined?(::TruffleRuby)
if TruffleRuby.native?
excludes << 'aot'
excludes << 'native'
if GC.heap_stats.values.none?(Hash)
excludes << 'native-g1'
end
else
excludes << 'jvm'
end
Expand Down
11 changes: 10 additions & 1 deletion test/truffle/compiler/engine-caching.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ source test/truffle/common.sh.inc
ruby_version=$(jt ruby -v)

if [[ ! $ruby_version =~ "Oracle GraalVM Native" ]]; then
echo Oracle GraalVM Native not detected, no tests to run.
echo Oracle GraalVM Native not detected, skipping test
exit 0
fi

set +x
output=$(jt ruby --experimental-options --engine.CacheLoad=does-not-exist.image -e0 2>&1 || true)

if [[ $output =~ "AuxiliaryEngineCache at image build time" ]]; then
echo Oracle GraalVM Native without AuxiliaryEngineCache, skipping test
exit 0
fi
set -x

# Store the image
jt ruby --experimental-options --engine.TraceCache --engine.CacheCompile=executed --engine.CacheStore=core.image test/truffle/compiler/engine_caching/engine_caching.rb

Expand Down
26 changes: 20 additions & 6 deletions tool/jt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,21 @@ def rebuild(*options)
vm_args << "--core-load-path=#{TRUFFLERUBY_DIR}/src/main/ruby/truffleruby"
end

if ci? and truffleruby_jvm?
vm_args << '--vm.Xlog:os+thread=off' # GR-23507: prevent thread warnings on stdout to break specs/tests
if ci?
# GR-23507: prevent thread warnings on stdout to break specs/tests/programs using execve().
# The problem happens if one thread is calling execve() and the other about the same time is calling pthread_create().
# In such case, pthread_create() can return EAGAIN "just because there is a concurrent execve()".
# See https://bugs.openjdk.org/browse/JDK-8268605?focusedCommentId=14473665#comment-14473665
# To solve this we move VM warnings to stderr instead of stdout to avoid breaking specs, and logging should be on stderr anyway.
# '--vm.Xlog:os+thread=off' '--vm.Xlog:gc+task=off' would also be a possibility, but unfortunately
# these flags don't seem to combine with moving all warnings to stderr so we have to pick one approach.
# Example warnings:
# JVM:
# [11.028s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 2048k, guardsize: 0k, detached.
# SVM with G1:
# [0.094s][warning][os,thread] Failed to start thread "GC Thread#1" - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 4k, detached.
# [0.094s][error ][gc,task ] GC(0) Failed to create worker thread
vm_args << '--vm.Xlog:all=warning:stderr'
end

[vm_args, ruby_args + args, options]
Expand Down Expand Up @@ -1630,20 +1643,21 @@ def mspec(*args)
private def test_specs(command, *args)
env_vars = {}
options = []
tag = ENV['TAG'] || 'fails'

case command
when 'run'
options += %w[--excl-tag fails]
when 'tag'
options += %w[--add fails --fail --excl-tag fails]
options += %W[--add #{tag} --fail --excl-tag fails]
when 'untag'
options += %w[--del fails --pass]
options += %W[--del #{tag} --pass]
command = 'tag'
when 'purge'
options += %w[--purge]
command = 'tag'
when 'tag_all'
options += %w[--unguarded --all --dry-run --add fails]
options += %W[--unguarded --all --dry-run --add #{tag}]
command = 'tag'
else
raise command
Expand Down Expand Up @@ -2234,7 +2248,7 @@ def graph(*args)
# See org.graalvm.compiler.debug.StandardPathUtilitiesProvider#sanitizeFileName
method_glob_pattern = method.gsub(/[ \/\p{Cntrl}]/, '_')
if truffleruby_native?
method_glob_pattern = "Isolated:_#{method_glob_pattern}"
method_glob_pattern = "{Isolated:_,}#{method_glob_pattern}"
end

dumps = Dir.glob('graal_dumps/*').select { |path| File.directory?(path) }.sort.last
Expand Down

0 comments on commit b2cec7c

Please sign in to comment.