Skip to content

Commit

Permalink
Added a spawn option to run JVM out of process
Browse files Browse the repository at this point in the history
  • Loading branch information
jkutner committed Sep 9, 2015
1 parent 22a2d28 commit 5d8ae9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions bintest/mjruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
assert_true status.success?, "Process did not exit cleanly"
assert_include output, "Hello World"

output, status = Open3.capture2(
"#{BIN_PATH} --spawn --dev -rwebrick -J-Dsome.prop=foobar -J-Xmx256m -e \"puts 'Hello World'\"")
assert_true status.success?, "Process did not exit cleanly"
assert_include output, "Hello World"

output, error, status = Open3.capture3(
"#{BIN_PATH} -rwebrick -e 'puts WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd)'")
assert_true status.success?, "Process did not exit cleanly"
Expand All @@ -45,6 +50,11 @@
"#{BIN_PATH} -J-ea -e \"puts 'Hello World'\"")
assert_true status.success?, "Process did not exit cleanly"
assert_include output, "Hello World"

output, status = Open3.capture2(
"#{BIN_PATH} -S gem install bundler")
assert_true status.success?, "Process did not exit cleanly"
assert_include output, "1 gem installed"
end
end
end
6 changes: 6 additions & 0 deletions mrblib/jruby_opts_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def valid?
@valid
end

def spawn?
@spawn == true
end

def java_mem
@java_mem || '-Xmx500m'
end
Expand Down Expand Up @@ -109,6 +113,8 @@ def parse(opts)
@java_opts << "-Djruby.compile.invokedynamic=false"
elsif opt == "--sample"
@java_opts << "-Xprof"
elsif opt == "--spawn"
@spawn = true
elsif opt == "--1.8"
puts "warning: --1.8 ignored"
elsif opt == "--1.9"
Expand Down
4 changes: 2 additions & 2 deletions mrblib/jruby_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def resolve_jruby_classpath
jruby_already_added = true
end
end
# FIXME this doesn't work on windows. org/jruby/Main isn't found.
# cp_ary << File.join(jruby_home, "lib", "jruby-truffle.jar")
raise "No JRuby JAR found in lib directory!" if cp_ary.empty?
# FIXME this doesn't work on windows. org/jruby/Main isn't found.
#cp_ary << File.join(jruby_home, "lib", "jruby-truffle.jar")
cp_ary.join(JavaSupport.cp_delim)
end

Expand Down
6 changes: 5 additions & 1 deletion mrblib/mjruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ def __main__(argv)
"-Djruby.shell=#{JRubySupport::SYSTEM_SHELL}"]

debug "java #{all_java_opts} #{java_class} #{cli_opts.ruby_opts}"
JavaSupport.exec_java(java_class, all_java_opts, cli_opts.ruby_opts)
if cli_opts.spawn?
JavaSupport.system_java(all_java_opts, java_class, cli_opts.ruby_opts)
else
JavaSupport.exec_java(java_class, all_java_opts, cli_opts.ruby_opts)
end
end

0 comments on commit 5d8ae9a

Please sign in to comment.