Module: JRuby::Startup::AppCDS

Defined in:
lib/jruby/startup/appcds.rb

Class Method Summary collapse

Class Method Details

.regenerate_archive(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jruby/startup/appcds.rb', line 2

def self.regenerate_archive(argv)
  # Sanity check a few things
  java_version = ENV_JAVA['java.specification.version']

  if java_version < '11'
    puts "*** Warning: this feature is only supported on Java 11 or higher"
  end

  if JRUBY_VERSION < '9.2.1.0'
    puts "*** JRuby 9.2.1 or higher recommended"
  end

  # Go for it
  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_list}\n\n"

  fail unless system "VERIFY_JRUBY=1 JAVA_OPTS='-XX:DumpLoadedClassList=#{jruby_list}' #{jruby_exe} #{command_line}"

  # Use class list to generate AppCDS archive
  puts "\n*** Generating shared AppCDS archive at #{jruby_jsa}\n\n"

  fail unless system "VERIFY_JRUBY=1 JAVA_OPTS='-Xshare:dump -XX:G1HeapRegionSize=2m -XX:+UnlockDiagnosticVMOptions -XX:SharedClassListFile=#{jruby_list} -XX:SharedArchiveFile=#{jruby_jsa}' #{jruby_exe} #{command_line}"

  # Display env vars to use for the new archive
  puts "\n  *** Success!\n  \n  JRuby versions 9.2.1 or higher should detect \#{jruby_jsa} and use it automatically.\n  For versions of JRuby 9.2 or earlier, set the following environment variables:\n\n  VERIFY_JRUBY=1\n  JAVA_OPTS=\"-XX:G1HeapRegionSize=2m -XX:SharedArchiveFile=\#{jruby_jsa}\"\n  END\nend\n"