Skip to content

Commit

Permalink
First version of appcds generation script.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 9, 2018
0 parents commit de2d08e
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in jruby-startup.gemspec
gemspec
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Jruby::Startup

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jruby/startup`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'jruby-startup'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install jruby-startup

## Usage

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/headius/jruby-startup.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"
task :default => :spec
40 changes: 40 additions & 0 deletions jruby-startup.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "jruby/startup/version"

Gem::Specification.new do |spec|
spec.name = "jruby-startup"
spec.version = Jruby::Startup::VERSION
spec.authors = ["Charles Oliver Nutter"]
spec.email = ["headius@headius.com"]

spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
end
2 changes: 2 additions & 0 deletions lib/jruby/startup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "jruby/startup/version"
require "jruby/startup/appcds"
42 changes: 42 additions & 0 deletions lib/jruby/startup/appcds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module JRuby::Startup::AppCDS
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

# 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_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
end
end
5 changes: 5 additions & 0 deletions lib/jruby/startup/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module JRuby
module Startup
VERSION = "0.1.0"
end
end

0 comments on commit de2d08e

Please sign in to comment.