Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ab235e268bbb
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 49623910464b
Choose a head ref
Loading
Showing with 1,885 additions and 1,129 deletions.
  1. +3 −3 core/src/main/java/org/jruby/Ruby.java
  2. +3 −1 core/src/main/java/org/jruby/RubyDir.java
  3. +7 −4 core/src/main/java/org/jruby/RubyFile.java
  4. +1 −6 core/src/main/java/org/jruby/RubyInstanceConfig.java
  5. +10 −17 core/src/main/java/org/jruby/RubyThread.java
  6. +14 −14 core/src/main/java/org/jruby/compiler/JITCompiler.java
  7. +23 −10 core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
  8. +6 −13 core/src/main/java/org/jruby/embed/ScriptingContainer.java
  9. +4 −4 core/src/main/java/org/jruby/internal/runtime/methods/JavaMethod.java
  10. +18 −0 core/src/main/java/org/jruby/ir/dataflow/analyses/LiveVariableNode.java
  11. +1 −30 core/src/main/java/org/jruby/ir/dataflow/analyses/LiveVariablesProblem.java
  12. +2 −2 core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
  13. +1 −1 core/src/main/java/org/jruby/ir/instructions/BacktickInstr.java
  14. +4 −2 core/src/main/java/org/jruby/ir/instructions/BlockGivenInstr.java
  15. +1 −1 core/src/main/java/org/jruby/ir/instructions/BranchInstr.java
  16. +5 −2 core/src/main/java/org/jruby/ir/instructions/BreakInstr.java
  17. +4 −2 core/src/main/java/org/jruby/ir/instructions/BuildCompoundArrayInstr.java
  18. +1 −1 core/src/main/java/org/jruby/ir/instructions/BuildCompoundStringInstr.java
  19. +3 −3 core/src/main/java/org/jruby/ir/instructions/BuildDynRegExpInstr.java
  20. +3 −3 core/src/main/java/org/jruby/ir/instructions/BuildLambdaInstr.java
  21. +2 −2 core/src/main/java/org/jruby/ir/instructions/BuildRangeInstr.java
  22. +2 −2 core/src/main/java/org/jruby/ir/instructions/BuildSplatInstr.java
  23. +9 −9 core/src/main/java/org/jruby/ir/instructions/CallBase.java
  24. +2 −2 core/src/main/java/org/jruby/ir/instructions/CheckArgsArrayArityInstr.java
  25. +2 −2 core/src/main/java/org/jruby/ir/instructions/CopyInstr.java
  26. +2 −2 core/src/main/java/org/jruby/ir/instructions/DefineClassInstr.java
  27. +2 −2 core/src/main/java/org/jruby/ir/instructions/DefineClassMethodInstr.java
  28. +2 −2 core/src/main/java/org/jruby/ir/instructions/DefineMetaClassInstr.java
  29. +2 −2 core/src/main/java/org/jruby/ir/instructions/DefineModuleInstr.java
  30. +2 −2 core/src/main/java/org/jruby/ir/instructions/EQQInstr.java
  31. +3 −3 core/src/main/java/org/jruby/ir/instructions/ExceptionRegionStartMarkerInstr.java
  32. +2 −2 core/src/main/java/org/jruby/ir/instructions/GVarAliasInstr.java
  33. +2 −2 core/src/main/java/org/jruby/ir/instructions/GetClassVarContainerModuleInstr.java
  34. +2 −2 core/src/main/java/org/jruby/ir/instructions/GetGlobalVariableInstr.java
  35. +2 −2 core/src/main/java/org/jruby/ir/instructions/GetInstr.java
  36. +2 −2 core/src/main/java/org/jruby/ir/instructions/InheritanceSearchConstInstr.java
  37. +1 −26 core/src/main/java/org/jruby/ir/instructions/Instr.java
  38. +2 −2 core/src/main/java/org/jruby/ir/instructions/JumpInstr.java
  39. +2 −2 core/src/main/java/org/jruby/ir/instructions/LabelInstr.java
  40. +2 −2 core/src/main/java/org/jruby/ir/instructions/LexicalSearchConstInstr.java
  41. +3 −3 core/src/main/java/org/jruby/ir/instructions/LoadLocalVarInstr.java
  42. +2 −2 core/src/main/java/org/jruby/ir/instructions/ModuleVersionGuardInstr.java
  43. +2 −2 core/src/main/java/org/jruby/ir/instructions/MultipleAsgnBase.java
  44. +3 −1 core/src/main/java/org/jruby/ir/instructions/OneOperandBranchInstr.java
  45. +2 −2 core/src/main/java/org/jruby/ir/instructions/ProcessModuleBodyInstr.java
  46. +2 −2 core/src/main/java/org/jruby/ir/instructions/PutGlobalVarInstr.java
  47. +2 −2 core/src/main/java/org/jruby/ir/instructions/PutInstr.java
  48. +2 −2 core/src/main/java/org/jruby/ir/instructions/RecordEndBlockInstr.java
  49. +2 −2 core/src/main/java/org/jruby/ir/instructions/ReifyClosureInstr.java
  50. +2 −2 core/src/main/java/org/jruby/ir/instructions/RescueEQQInstr.java
  51. +0 −6 core/src/main/java/org/jruby/ir/instructions/ResultBaseInstr.java
  52. +3 −3 core/src/main/java/org/jruby/ir/instructions/ReturnBase.java
  53. +10 −10 core/src/main/java/org/jruby/ir/instructions/RuntimeHelperCall.java
  54. +4 −2 core/src/main/java/org/jruby/ir/instructions/SearchConstInstr.java
  55. +2 −2 core/src/main/java/org/jruby/ir/instructions/SetCapturedVarInstr.java
  56. +4 −4 core/src/main/java/org/jruby/ir/instructions/StoreLocalVarInstr.java
  57. +2 −2 core/src/main/java/org/jruby/ir/instructions/ThrowExceptionInstr.java
  58. +2 −2 core/src/main/java/org/jruby/ir/instructions/ToAryInstr.java
  59. +2 −2 core/src/main/java/org/jruby/ir/instructions/TwoOperandBranchInstr.java
  60. +2 −2 core/src/main/java/org/jruby/ir/instructions/UndefMethodInstr.java
  61. +2 −2 core/src/main/java/org/jruby/ir/instructions/YieldInstr.java
  62. +2 −2 core/src/main/java/org/jruby/ir/instructions/boxing/AluInstr.java
  63. +2 −2 core/src/main/java/org/jruby/ir/instructions/boxing/BoxInstr.java
  64. +2 −2 core/src/main/java/org/jruby/ir/instructions/boxing/UnboxInstr.java
  65. +2 −2 core/src/main/java/org/jruby/ir/instructions/defined/RestoreErrorInfoInstr.java
  66. +1 −1 core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
  67. +116 −65 core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
  68. +11 −1 core/src/main/java/org/jruby/javasupport/JavaEmbedUtils.java
  69. +2 −7 core/src/main/java/org/jruby/javasupport/JavaMethod.java
  70. +0 −3 core/src/main/java/org/jruby/util/ClassDefiningJRubyClassLoader.java
  71. +19 −5 core/src/main/java/org/jruby/util/JRubyClassLoader.java
  72. +62 −0 core/src/main/java/org/jruby/util/UriLikePathHelper.java
  73. +14 −13 core/src/main/java/org/jruby/util/cli/Options.java
  74. +77 −28 core/src/main/java/org/jruby/util/collections/WeakHashSet.java
  75. +3 −4 core/src/main/java/org/jruby/util/collections/WeakValuedIdentityMap.java
  76. +20 −22 core/src/main/java/org/jruby/util/collections/WeakValuedMap.java
  77. +4 −15 core/src/main/ruby/jruby/kernel/kernel.rb
  78. +182 −0 core/src/test/java/org/jruby/java/dispatch/CallableSelectorTest.java
  79. +66 −0 core/src/test/java/org/jruby/javasupport/JavaEmbedUtilsTest.java
  80. 0 core/src/test/resources/java_embed_utils/.jrubydir
  81. +1 −0 core/src/test/resources/java_embed_utils/test_me.rb
  82. +4 −6 lib/ruby/stdlib/rubygems/defaults/jruby.rb
  83. +141 −120 maven/jruby-complete/src/it/integrity/pom.xml
  84. +1 −1 ...y_bundles_with_embedded_gems/test/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
  85. +7 −4 maven/jruby/src/it/runnable/Mavenfile
  86. +14 −0 maven/jruby/src/it/runnable/nested.rb
  87. +21 −6 maven/jruby/src/it/runnable/pom.xml
  88. +1 −1 maven/jruby/src/it/runnable/spec/one_spec.rb
  89. +25 −0 maven/jruby/src/it/runnable/test.rb
  90. +29 −0 maven/jruby/src/it/runnable/test_other.rb
  91. +13 −1 maven/jruby/src/it/runnable/verify.bsh
  92. +1 −1 .../src/templates/osgi_all_inclusive/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
  93. +36 −0 spec/java_integration/interfaces/implementation_spec.rb
  94. +3 −0 spec/ruby/.travis.yml
  95. +2 −5 spec/ruby/core/array/eql_spec.rb
  96. +3 −9 spec/ruby/core/array/equal_value_spec.rb
  97. +3 −6 spec/ruby/core/array/hash_spec.rb
  98. +16 −6 spec/ruby/core/array/intersection_spec.rb
  99. +1 −1 spec/ruby/core/array/minus_spec.rb
  100. +16 −6 spec/ruby/core/array/union_spec.rb
  101. +59 −15 spec/ruby/core/array/uniq_spec.rb
  102. +5 −3 spec/ruby/core/bignum/bit_or_spec.rb
  103. +5 −3 spec/ruby/core/bignum/bit_xor_spec.rb
  104. +6 −3 spec/ruby/core/bignum/div_spec.rb
  105. +4 −1 spec/ruby/core/bignum/divide_spec.rb
  106. +8 −3 spec/ruby/core/bignum/divmod_spec.rb
  107. +1 −0 spec/ruby/core/bignum/multiply_spec.rb
  108. +9 −7 spec/ruby/core/binding/local_variable_set_spec.rb
  109. +3 −13 spec/ruby/core/fixnum/multiply_spec.rb
  110. +1 −1 spec/ruby/core/hash/element_reference_spec.rb
  111. +0 −3 spec/ruby/core/hash/eql_spec.rb
  112. +1 −1 spec/ruby/core/hash/fetch_values_spec.rb
  113. +16 −9 spec/ruby/core/hash/shared/eql.rb
  114. +1 −1 spec/ruby/core/module/prepend_spec.rb
  115. +8 −0 spec/ruby/core/module/private_constant_spec.rb
  116. +10 −0 spec/ruby/core/module/public_constant_spec.rb
  117. +1 −1 spec/ruby/core/process/waitpid_spec.rb
  118. +5 −0 spec/ruby/core/range/bsearch_spec.rb
  119. +3 −4 spec/ruby/core/string/slice_spec.rb
  120. +6 −0 spec/ruby/core/thread/priority_spec.rb
  121. +1 −2 spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb
  122. +4 −5 spec/ruby/shared/process/exit.rb
  123. +1 −0 spec/tags/ruby/core/array/equal_value_tags.txt
  124. +1 −0 spec/tags/ruby/core/string/slice_tags.txt
  125. +1 −0 spec/tags/ruby/core/thread/priority_tags.txt
  126. +1 −0 spec/truffle/tags/core/range/bsearch_tags.txt
  127. +1 −0 spec/truffle/tags/core/string/slice_tags.txt
  128. +0 −5 spec/truffle/tags/core/thread/priority_tags.txt
  129. +0 −3 spec/truffle/tags/language/super_tags.txt
  130. +0 −3 spec/truffle/tags/library/timeout/timeout_tags.txt
  131. +17 −2 test/jruby/test_file.rb
  132. +10 −1 test/jruby/test_load.rb
  133. +0 −10 test/mri/excludes_truffle/TestSuper.rb
  134. +0 −4 test/mri/excludes_truffle/TestTimeout.rb
  135. +10 −0 test/mri/ruby/test_proc.rb
  136. +1 −1 test/pom.rb
  137. +18 −18 tool/jruby_eclipse
  138. +14 −43 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  139. +54 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/QueueNodes.java
  140. +5 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/ThreadNodes.java
  141. +9 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayBuilderNode.java
  142. +66 −90 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java
  143. +4 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/hash/HashNodes.java
  144. +39 −0 truffle/src/main/java/org/jruby/truffle/nodes/exceptions/ClearExceptionVariableNode.java
  145. +8 −15 truffle/src/main/java/org/jruby/truffle/nodes/exceptions/TryNode.java
  146. +0 −33 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/ChannelPrimitiveNodes.java
  147. +27 −6 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/EncodingConverterPrimitiveNodes.java
  148. +0 −1 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/RubiniusPrimitiveManager.java
  149. +50 −6 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/ThreadPrimitiveNodes.java
  150. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/TimePrimitiveNodes.java
  151. +25 −30 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/VMPrimitiveNodes.java
  152. +6 −6 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperCallNode.java
  153. +32 −36 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperReCallNode.java
  154. +61 −0 truffle/src/main/java/org/jruby/truffle/nodes/supercall/ZSuperOutsideMethodNode.java
  155. +10 −0 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  156. +1 −0 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyThread.java
  157. +1 −0 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  158. +1 −1 truffle/src/main/java/org/jruby/truffle/translator/LoadArgumentsTranslator.java
  159. +17 −3 truffle/src/main/java/org/jruby/truffle/translator/MethodTranslator.java
  160. +39 −32 truffle/src/main/java/org/jruby/truffle/translator/ReloadArgumentsTranslator.java
  161. +2 −1 truffle/src/main/ruby/core.rb
  162. +39 −0 truffle/src/main/ruby/core/rubinius/api/shims/channel.rb
  163. +0 −7 truffle/src/main/ruby/core/rubinius/api/shims/thread_common.rb
  164. +0 −101 truffle/src/main/ruby/core/rubinius/bootstrap/channel.rb
  165. +17 −0 truffle/src/main/ruby/core/rubinius/bootstrap/thread.rb
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3307,7 +3307,7 @@ public void tearDown(boolean systemExit) {

getSelectorPool().cleanup();

tearDownClassLoader();
releaseClassLoader();

if (config.isProfilingEntireRun()) {
// not using logging because it's formatted
@@ -3332,9 +3332,9 @@ public void tearDown(boolean systemExit) {
}
}

private void tearDownClassLoader() {
private void releaseClassLoader() {
if (getJRubyClassLoader() != null) {
getJRubyClassLoader().tearDown(isDebug());
getJRubyClassLoader().close();
}
}

4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -84,6 +84,8 @@ public class RubyDir extends RubyObject {

private final static Encoding UTF8 = UTF8Encoding.INSTANCE;

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");

public RubyDir(Ruby runtime, RubyClass type) {
super(runtime, type);
}
@@ -308,7 +310,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
if (PROTOCOL_PATTERN.matcher(adjustedPath).matches()) {
realPath = adjustedPath;
}
else {
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -1540,16 +1540,18 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// argument is relative.
if (args.length == 2 && !args[1].isNil()) {
// TODO maybe combine this with get_path method
if ((args[1] instanceof RubyString) && args[1].asJavaString().startsWith("uri:")) {
cwd = args[1].asJavaString();
String path = args[1].toString();
if (path.startsWith("uri:")) {
cwd = path;
} else {
cwd = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[1])).getUnicodeValue();

// Handle ~user paths.
if (expandUser) {
cwd = expandUserPath(context, cwd, true);
}


// TODO try to treat all uri-like paths alike
String[] cwdURIParts = splitURI(cwd);
if (uriParts == null && cwdURIParts != null) {
uriParts = cwdURIParts;
@@ -1566,7 +1568,8 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// If the path isn't absolute, then prepend the current working
// directory to the path.
if (!startsWithSlashNotOnWindows && !startsWithDriveLetterOnWindows(cwd)) {
cwd = new File(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
if ("".equals(cwd)) cwd = ".";
cwd = JRubyFile.create(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
}
}
} else {
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -53,9 +53,7 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -70,8 +68,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;

/**
@@ -1756,8 +1752,6 @@ public boolean shouldPrecompileAll() {

public static final boolean JIT_CACHE_ENABLED = Options.JIT_CACHE.load();

public static final String JIT_CODE_CACHE = Options.JIT_CODECACHE.load();

public static final boolean REFLECTED_HANDLES = Options.REFLECTED_HANDLES.load();

public static final boolean NO_UNWRAP_PROCESS_STREAMS = Options.PROCESS_NOUNWRAP.load();
@@ -1947,4 +1941,5 @@ public boolean isCextEnabled() {
return false;
}

@Deprecated public static final String JIT_CODE_CACHE = "";
}
27 changes: 10 additions & 17 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -148,8 +148,8 @@ public class RubyThread extends RubyObject implements ExecutionContext {
private final SleepTask2 sleepTask = new SleepTask2();

private static final boolean DEBUG = false;
private static final int RUBY_MIN_THREAD_PRIORITY = -3;
private static final int RUBY_MAX_THREAD_PRIORITY = 3;
public static final int RUBY_MIN_THREAD_PRIORITY = -3;
public static final int RUBY_MAX_THREAD_PRIORITY = 3;

/** Thread statuses */
public static enum Status {
@@ -1106,26 +1106,19 @@ public IRubyObject priority_set(IRubyObject priority) {
return RubyFixnum.newFixnum(getRuntime(), iPriority);
}

/* helper methods to translate java thread priority (1-10) to
* Ruby thread priority (-3 to 3) using a quadratic polynoimal ant its
* inverse
/* helper methods to translate Java thread priority (1-10) to
* Ruby thread priority (-3 to 3) using a quadratic polynomial ant its
* inverse passing by (Ruby,Java): (-3,1), (0,5) and (3,10)
* i.e., j = r^2/18 + 3*r/2 + 5
* r = 3/2*sqrt(8*j + 41) - 27/2
*/
private int javaPriorityToRubyPriority(int javaPriority) {
double d; // intermediate value
d = 1.5 * Math.sqrt(8.0*javaPriority + 41) - 13.5;
public static int javaPriorityToRubyPriority(int javaPriority) {
double d = 1.5 * Math.sqrt(8.0 * javaPriority + 41) - 13.5;
return Math.round((float) d);
}

private int rubyPriorityToJavaPriority(int rubyPriority) {
double d;
if (rubyPriority < RUBY_MIN_THREAD_PRIORITY) {
rubyPriority = RUBY_MIN_THREAD_PRIORITY;
} else if (rubyPriority > RUBY_MAX_THREAD_PRIORITY) {
rubyPriority = RUBY_MAX_THREAD_PRIORITY;
}
d = Math.pow(rubyPriority, 2.0)/18.0 + 1.5 * rubyPriority + 5;

public static int rubyPriorityToJavaPriority(int rubyPriority) {
double d = (rubyPriority * rubyPriority) / 18.0 + 1.5 * rubyPriority + 5;
return Math.round((float) d);
}

28 changes: 14 additions & 14 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
*
* Copyright (C) 2006-2008 Charles O Nutter <headius@headius.com>
* Copyright (C) 2008 Thomas E Enebo <enebo@acm.org>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -84,10 +84,10 @@ public static class JITCounts {

private final JITCounts counts = new JITCounts();
private final ExecutorService executor;

private final Ruby runtime;
private final RubyInstanceConfig config;

public JITCompiler(Ruby runtime) {
this.runtime = runtime;
this.config = runtime.getInstanceConfig();
@@ -120,19 +120,19 @@ public long getCompileTime() {
public long getAbandonCount() {
return counts.abandonCount.get();
}

public long getCodeSize() {
return counts.codeSize.get();
}

public long getAverageCodeSize() {
return counts.averageCodeSize.get();
}

public long getAverageCompileTime() {
return counts.averageCompileTime.get() / 1000;
}

public long getLargestCodeSize() {
return counts.largestCodeSize.get();
}
@@ -334,7 +334,7 @@ public static String getHashForBytes(byte[] bytes) {
throw new RuntimeException(nsae);
}
}

public static class JITClassGenerator {
public JITClassGenerator(String className, String methodName, String key, Ruby ruby, MixedModeIRMethod method, JVMVisitor visitor) {
this.packageName = JITCompiler.RUBY_JIT_PREFIX;
@@ -345,7 +345,7 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
// Also, invokedynamic forces us to make jitted bytecode unique to each runtime, since the call sites cache
// at class level rather than at our runtime level. This makes it impossible to share jitted bytecode
// across runtimes.

digestString = key + Math.abs(ruby.hashCode());
} else {
digestString = key;
@@ -356,11 +356,11 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
this.method = method;
this.visitor = visitor;
}

@SuppressWarnings("unchecked")
protected void compile() {
if (bytecode != null) return;

// Time the compilation
long start = System.nanoTime();

@@ -395,7 +395,7 @@ void updateCounters(JITCounts counts) {
public void generate() {
compile();
}

public byte[] bytecode() {
return bytecode;
}
@@ -429,15 +429,15 @@ static void log(RubyModule implementationClass, String file, int line, String na
name = isBlock ? "" : "." + name;

StringBuilder builder = new StringBuilder(message + ":" + className + name + " at " + file + ":" + line);

if (reason.length > 0) {
builder.append(" because of: \"");
for (int i = 0; i < reason.length; i++) {
builder.append(reason[i]);
}
builder.append('"');
}

LOG.info(builder.toString());
}
}
33 changes: 23 additions & 10 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -4,22 +4,26 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.LinkedList;

import org.jruby.util.UriLikePathHelper;

/**
* the IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* in such a way that it uses only resources which can be reached with classloader.
*
*
* GEM_HOME is uri:classloader://META-INF/jruby.home/lib/ruby/gems/shared
* GEM_PATH is uri:classloader://
* JARS_HOME is uri:classloader://jars
*
*
* but whenever you want to set them via {@link #setEnvironment(Map)} this will be honored.
*
*
* it also comes with OSGi support which allows to add a bundle to LOAD_PATH or GEM_PATH.
*/
public class IsolatedScriptingContainer extends ScriptingContainer {

private static final String JRUBY_HOME = "/META-INF/jruby.home";
private static final String URI_CLASSLOADER = "uri:classloader:/";

public IsolatedScriptingContainer()
{
@@ -48,20 +52,29 @@ public IsolatedScriptingContainer( LocalContextScope scope,
{
super(scope, behavior, lazy);

setLoadPaths( Arrays.asList( "uri:classloader:" ) );
List<String> loadPaths = new LinkedList<String>();
loadPaths.add(URI_CLASSLOADER);
setLoadPaths(loadPaths);

// set the right jruby home
UriLikePathHelper uriPath = new UriLikePathHelper(getClassLoader());
URL url = uriPath.getResource("/.jrubydir");
if (url != null){
setCurrentDirectory( URI_CLASSLOADER );
}

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
setEnvironment(null);
}

@Override
public void setEnvironment(Map environment) {
if (environment == null || !environment.containsKey("GEM_PATH")
|| !environment.containsKey("GEM_HOME")|| !environment.containsKey("JARS_HOME")) {
if (environment == null || !environment.containsKey("GEM_PATH")
|| !environment.containsKey("GEM_HOME") || !environment.containsKey("JARS_HOME")) {
Map<String,String> env = environment == null ? new HashMap<String,String>() : new HashMap<String,String>(environment);
if (!env.containsKey("GEM_PATH")) env.put("GEM_PATH", "uri:classloader://");
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", "uri:classloader://");
if (!env.containsKey("JARS_HOME")) env.put("JARS_HOME", "uri:classloader://jars");
if (!env.containsKey("GEM_PATH")) env.put("GEM_PATH", URI_CLASSLOADER);
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", URI_CLASSLOADER);
if (!env.containsKey("JARS_HOME")) env.put("JARS_HOME", URI_CLASSLOADER + "jars");
super.setEnvironment(env);
}
else {
19 changes: 6 additions & 13 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -29,16 +29,11 @@
*/
package org.jruby.embed;

import java.io.UnsupportedEncodingException;

import org.jruby.embed.internal.LocalContextProvider;

import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
@@ -267,7 +262,7 @@ static LocalContextProvider getProviderInstance(LocalContextScope scope, LocalVa
return SingletonLocalContextProvider.getProvider(behavior, lazy);
}
}

private void initRubyInstanceConfig() throws RaiseException {
String home = SystemPropertyCatcher.findJRubyHome(this);
if (home != null) {
@@ -1856,14 +1851,11 @@ public PrintStream getErr() {
* @since JRuby 1.5.0
*/
public void terminate() {
if (getProvider().isRuntimeInitialized()) {
getProvider().getRuntime().tearDown(false);
try {
getProvider().getRuntime().getJRubyClassLoader().close();
}
catch(IOException weTriedIt){}
LocalContextProvider provider = getProvider();
if (provider.isRuntimeInitialized()) {
provider.getRuntime().tearDown(false);
}
getProvider().terminate();
provider.terminate();
}

/**
@@ -1876,6 +1868,7 @@ public void terminate() {
*
* @since JRuby 1.6.0
*/
@Override
public void finalize() throws Throwable {
super.finalize();
// singleton containers share global runtime, and should not tear it down
Original file line number Diff line number Diff line change
@@ -44,9 +44,9 @@ public abstract class JavaMethod extends DynamicMethod implements Cloneable, Met
private String parameterDesc;
private String[] parameterList;

private static String[] ONE_REQ = new String[] { "q" };
private static String[] TWO_REQ = new String[] { "q", "q" };
private static String[] THREE_REQ = new String[] { "q", "q", "q" };
private static final String[] ONE_REQ = new String[] { "q" };
private static final String[] TWO_REQ = new String[] { "q", "q" };
private static final String[] THREE_REQ = new String[] { "q", "q", "q" };

public static final Class[][] METHODS = {
{JavaMethodZero.class, JavaMethodZeroOrOne.class, JavaMethodZeroOrOneOrTwo.class, JavaMethodZeroOrOneOrTwoOrThree.class},
@@ -89,7 +89,7 @@ protected JavaMethod() {}

public void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope) {
this.staticScope = staticScope;
this.arity = arity;
setArity(arity);
super.init(implementationClass, visibility);
}

Loading