Skip to content

Commit 5d8ae9a

Browse files
committed
Added a spawn option to run JVM out of process
1 parent 22a2d28 commit 5d8ae9a

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

bintest/mjruby.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
assert_true status.success?, "Process did not exit cleanly"
2424
assert_include output, "Hello World"
2525

26+
output, status = Open3.capture2(
27+
"#{BIN_PATH} --spawn --dev -rwebrick -J-Dsome.prop=foobar -J-Xmx256m -e \"puts 'Hello World'\"")
28+
assert_true status.success?, "Process did not exit cleanly"
29+
assert_include output, "Hello World"
30+
2631
output, error, status = Open3.capture3(
2732
"#{BIN_PATH} -rwebrick -e 'puts WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd)'")
2833
assert_true status.success?, "Process did not exit cleanly"
@@ -45,6 +50,11 @@
4550
"#{BIN_PATH} -J-ea -e \"puts 'Hello World'\"")
4651
assert_true status.success?, "Process did not exit cleanly"
4752
assert_include output, "Hello World"
53+
54+
output, status = Open3.capture2(
55+
"#{BIN_PATH} -S gem install bundler")
56+
assert_true status.success?, "Process did not exit cleanly"
57+
assert_include output, "1 gem installed"
4858
end
4959
end
5060
end

mrblib/jruby_opts_parser.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def valid?
2626
@valid
2727
end
2828

29+
def spawn?
30+
@spawn == true
31+
end
32+
2933
def java_mem
3034
@java_mem || '-Xmx500m'
3135
end
@@ -109,6 +113,8 @@ def parse(opts)
109113
@java_opts << "-Djruby.compile.invokedynamic=false"
110114
elsif opt == "--sample"
111115
@java_opts << "-Xprof"
116+
elsif opt == "--spawn"
117+
@spawn = true
112118
elsif opt == "--1.8"
113119
puts "warning: --1.8 ignored"
114120
elsif opt == "--1.9"

mrblib/jruby_support.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def resolve_jruby_classpath
6969
jruby_already_added = true
7070
end
7171
end
72-
# FIXME this doesn't work on windows. org/jruby/Main isn't found.
73-
# cp_ary << File.join(jruby_home, "lib", "jruby-truffle.jar")
7472
raise "No JRuby JAR found in lib directory!" if cp_ary.empty?
73+
# FIXME this doesn't work on windows. org/jruby/Main isn't found.
74+
#cp_ary << File.join(jruby_home, "lib", "jruby-truffle.jar")
7575
cp_ary.join(JavaSupport.cp_delim)
7676
end
7777

mrblib/mjruby.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ def __main__(argv)
3030
"-Djruby.shell=#{JRubySupport::SYSTEM_SHELL}"]
3131

3232
debug "java #{all_java_opts} #{java_class} #{cli_opts.ruby_opts}"
33-
JavaSupport.exec_java(java_class, all_java_opts, cli_opts.ruby_opts)
33+
if cli_opts.spawn?
34+
JavaSupport.system_java(all_java_opts, java_class, cli_opts.ruby_opts)
35+
else
36+
JavaSupport.exec_java(java_class, all_java_opts, cli_opts.ruby_opts)
37+
end
3438
end

0 commit comments

Comments
 (0)