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: c2349581905a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 158574d9b1b3
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 15, 2017

  1. Copy the full SHA
    63d8bbc View commit details
  2. Copy the full SHA
    1733278 View commit details
  3. Copy the full SHA
    158574d View commit details
Showing with 55 additions and 43 deletions.
  1. +39 −11 core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
  2. +16 −32 core/src/main/ruby/jruby/jruby.rb
50 changes: 39 additions & 11 deletions core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
import org.jruby.javasupport.Java;
import org.jruby.javasupport.JavaObject;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
@@ -109,21 +110,48 @@ public static IRubyObject runtime(ThreadContext context, IRubyObject recv) {
*/
@JRubyMethod(module = true)
public static IRubyObject dereference(ThreadContext context, IRubyObject recv, IRubyObject obj) {
Object unwrapped;

if (obj instanceof JavaProxy) {
unwrapped = ((JavaProxy)obj).getObject();
} else if (obj.dataGetStruct() instanceof JavaObject) {
unwrapped = JavaUtil.unwrapJavaObject(obj);
} else {
throw context.runtime.newTypeError("got " + obj + ", expected wrapped Java object");
Object unwrapped = JavaUtil.unwrapIfJavaObject(obj);
if (unwrapped == obj) {
throw context.runtime.newTypeError("got " + obj.inspect() + ", expected wrapped Java object");
}

if (!(unwrapped instanceof IRubyObject)) {
throw context.runtime.newTypeError("got " + obj + ", expected Java-wrapped Ruby object");
throw context.runtime.newTypeError("got " + obj.inspect() + ", expected Java-wrapped Ruby object");
}
return (IRubyObject) unwrapped;
}

return (IRubyObject)unwrapped;
/**
* Run the provided (required) block with the "global runtime" set to the current runtime,
* for libraries that expect to operate against the global runtime.
*/
@JRubyMethod(module = true)
public static IRubyObject with_current_runtime_as_global(ThreadContext context, IRubyObject recv, Block block) {
final Ruby current = context.runtime;
final Ruby global = Ruby.getGlobalRuntime();
try {
if (current != global) {
current.useAsGlobalRuntime();
}
return block.yield(context, runtime(context, recv)); // previously yield (without an argument)
}
finally {
if (Ruby.getGlobalRuntime() != global) {
global.useAsGlobalRuntime();
}
}
}

@JRubyMethod(module = true, rest = true, optional = 1) // (loader = JRuby.runtime.jruby_class_loader)
public static IRubyObject set_context_class_loader(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
final ClassLoader loader;
if (args.length == 0 || args[0] == context.nil) {
loader = context.runtime.getJRubyClassLoader();
}
else {
loader = JavaUtil.unwrapJavaObject(args[0]);
}
java.lang.Thread.currentThread().setContextClassLoader(loader);
return Java.wrapJavaObject(context.runtime, loader); // reference0
}

/**
48 changes: 16 additions & 32 deletions core/src/main/ruby/jruby/jruby.rb
Original file line number Diff line number Diff line change
@@ -2,40 +2,25 @@ module JRuby
class << self
# Get a Java integration reference to the given (Ruby) object.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def reference(obj); end
def reference(obj); end if false

# Turn a Java integration reference (to a Ruby object) back into a normal Ruby object reference.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def dereference(obj); end
def dereference(obj); end if false

# Get the current JRuby runtime.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def runtime; end

# Run the provided (required) block with the "global runtime" set to the
# current runtime, for libraries that expect to operate against the global
# runtime.
def with_current_runtime_as_global
current = JRuby.runtime
global = org.jruby.Ruby.global_runtime

begin
if current != global
current.use_as_global_runtime
end
yield
ensure
if org.jruby.Ruby.global_runtime != global
global.use_as_global_runtime
end
end
end
def runtime; end if false

# Change the current threads context classloader. By, default call
# with no arguments to replace it with JRuby's class loader.
def set_context_class_loader(loader = JRuby.runtime.jruby_class_loader)
java.lang.Thread.currentThread.setContextClassLoader loader
end
# Run the provided (required) block with the "global runtime" set to the current runtime,
# for libraries that expect to operate against the global runtime.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def with_current_runtime_as_global; end if false

# Change the current threads context classloader.
# By, default call with no arguments to replace it with JRuby's class loader.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def set_context_class_loader(loader = nil); end if false

DEFAULT_FILENAME = '-'.dup; private_constant :DEFAULT_FILENAME
class org::jruby::Ruby
@@ -45,8 +30,7 @@ class org::jruby::Ruby
# Parse the given block or the provided content, returning a JRuby AST node.
def parse(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, lineno = 0, &block)
if block
block_r = reference0(block)
body = block_r.body
body = reference0(block).body

if org.jruby.runtime.CompiledBlock === body
raise ArgumentError, "cannot get parse tree from compiled block"
@@ -68,7 +52,6 @@ def parse(content = nil, filename = DEFAULT_FILENAME, extra_position_info = fals
alias ast_for parse

def compile_ir(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, &block)
runtime = JRuby.runtime
manager = org.jruby.ir.IRManager.new(runtime.instance_config)
manager.dry_run = true
if filename.equal?(DEFAULT_FILENAME)
@@ -99,8 +82,8 @@ def compile(content = nil, filename = DEFAULT_FILENAME, extra_position_info = fa
end
end

# NOTE: This is not a public API and is subject to change at our whim
# @private
# NOTE: This is not a public API and is subject to change at our whim.
# @private no longer used - to be removed
module IR
def self.debug=(value)
org.jruby.RubyInstanceConfig.IR_DEBUG = !!value
@@ -126,6 +109,7 @@ def self.visualize
org.jruby.RubyInstanceConfig.IR_VISUALIZER
end
end
deprecate_constant :IR

class CompiledScript