Skip to content

Instantly share code, notes, and snippets.

@headius

headius/.rb Secret

Created October 9, 2018 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/ebe5dd9fc8cb809993e939a38399f029 to your computer and use it in GitHub Desktop.
Save headius/ebe5dd9fc8cb809993e939a38399f029 to your computer and use it in GitHub Desktop.
command_line = ARGV[0] || "-e 1"
jruby_home = ENV_JAVA['jruby.home']
jruby_bin = File.join(jruby_home, 'bin')
jruby_lib = File.join(jruby_home, 'lib')
jruby_exe = File.join(jruby_bin, 'jruby')
jruby_list = File.join(jruby_lib, 'jruby.list')
jruby_jsa = File.join(jruby_lib, 'jruby.jsa')
# Force JRuby to be verified so its classes are seen by AppCDS
ENV['VERIFY_JRUBY'] = '1'
# Dump list of classes for this command line
puts "Outputting list of classes at #{jruby_jsa}"
fail unless system "VERIFY_JRUBY=1 JAVA_OPTS='-XX:DumpLoadedClassList=#{jruby_list}' #{jruby_exe} #{command_line}"
# Use class list to generate AppCDS archive
puts "Generating shared AppCDS archive at #{jruby_jsa}"
fail unless system "VERIFY_JRUBY=1 JAVA_OPTS='-Xshare:dump -XX:+UnlockDiagnosticVMOptions -XX:SharedClassListFile=#{jruby_list} -XX:SharedArchiveFile=#{jruby_jsa}' #{jruby_exe} #{command_line}"
# Display env vars to use for the new archive
puts <<END
Success!
Set the following environment variables to use the shared archive:
VERIFY_JRUBY=1
JAVA_OPTS=-XX:SharedArchiveFile=#{jruby_jsa}
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment