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: 8d95baf63e27
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 639ac5fb29ed
Choose a head ref
  • 5 commits
  • 7 files changed
  • 1 contributor

Commits on Aug 25, 2017

  1. Copy the full SHA
    8d714f5 View commit details
  2. revert JRuby.config helper for now, this needs to be re-disagned to fit

    ... with some existing functionality available JRuby::CONFIG, JRuby::Util
    kares committed Aug 25, 2017
    Copy the full SHA
    f739da5 View commit details
  3. Copy the full SHA
    9db8858 View commit details
  4. Copy the full SHA
    15d56cd View commit details
  5. Copy the full SHA
    639ac5f View commit details
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Original file line number Diff line number Diff line change
@@ -122,7 +122,8 @@ public static IRubyObject runtime(ThreadContext context, IRubyObject recv) {
* @return a wrapped RubyInstanceConfig
* @since 9.2
*/
@JRubyMethod(module = true)
// TODO needs to get fine tuned considering there's a CONFIG constant already
// @JRubyMethod(module = true)
public static IRubyObject config(ThreadContext context, IRubyObject recv) {
return Java.wrapJavaObject(context.runtime, context.runtime.getInstanceConfig());
}
38 changes: 23 additions & 15 deletions core/src/main/java/org/jruby/ir/targets/InvokeSite.java
Original file line number Diff line number Diff line change
@@ -44,13 +44,21 @@
* Created by headius on 10/23/14.
*/
public abstract class InvokeSite extends MutableCallSite {

private static final Logger LOG = LoggerFactory.getLogger(InvokeSite.class);
static { // enable DEBUG output
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.setDebugEnable(true);
}
private static final boolean LOG_BINDING = LOG.isDebugEnabled();

private static final AtomicLong SITE_ID = new AtomicLong(1);

final Signature signature;
final Signature fullSignature;
final int arity;
protected final String methodName;
final MethodHandle fallback;
private final SiteTracker tracker = new SiteTracker();
private static final AtomicLong SITE_ID = new AtomicLong(1);
private final long siteID = SITE_ID.getAndIncrement();
private final int argOffset;
protected final String file;
@@ -59,8 +67,6 @@ public abstract class InvokeSite extends MutableCallSite {
private boolean literalClosure;
CacheEntry cache = CacheEntry.NULL_CACHE;

private static final Logger LOG = LoggerFactory.getLogger(InvokeSite.class);

public String name() {
return methodName;
}
@@ -425,22 +431,25 @@ MethodHandle updateInvocationTarget(MethodHandle target, IRubyObject self, RubyM
}

private void logMethodMissing() {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load())
LOG.info(methodName + "\ttriggered site #" + siteID + " method_missing (" + file + ":" + line + ")");
if (LOG_BINDING) {
LOG.debug(methodName + "\ttriggered site #" + siteID + " method_missing (" + file + ":" + line + ")");
}
}

private void logBind(CacheAction action) {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load())
LOG.info(methodName + "\ttriggered site #" + siteID + " " + action + " (" + file + ":" + line + ")");
if (LOG_BINDING) {
LOG.debug(methodName + "\ttriggered site #" + siteID + " " + action + " (" + file + ":" + line + ")");
}
}

private void logPic(DynamicMethod method) {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load())
LOG.info(methodName + "\tadded to PIC " + logMethod(method));
if (LOG_BINDING) {
LOG.debug(methodName + "\tadded to PIC " + logMethod(method));
}
}

private void logFail() {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
if (LOG_BINDING) {
if (tracker.clearCount() > Options.INVOKEDYNAMIC_MAXFAIL.load()) {
LOG.info(methodName + "\tat site #" + siteID + " failed more than " + Options.INVOKEDYNAMIC_MAXFAIL.load() + " times; bailing out (" + file + ":" + line + ")");
} else if (tracker.seenTypesCount() + 1 > Options.INVOKEDYNAMIC_MAXPOLY.load()) {
@@ -480,8 +489,7 @@ CacheAction testThresholds(RubyModule testClass) {

public RubyClass pollAndGetClass(ThreadContext context, IRubyObject self) {
context.callThreadPoll();
RubyClass selfType = ((RubyBasicObject)self).getMetaClass();
return selfType;
return ((RubyBasicObject) self).getMetaClass();
}

@Override
@@ -527,12 +535,12 @@ public IRubyObject callMethodMissing(CacheEntry entry, CallType callType, Thread
}

private static String logMethod(DynamicMethod method) {
return "[#" + method.getSerialNumber() + " " + method.getImplementationClass() + "]";
return "[#" + method.getSerialNumber() + ' ' + method.getImplementationClass() + ']';
}

@JIT
public static boolean testMetaclass(RubyClass metaclass, IRubyObject self) {
return metaclass == ((RubyBasicObject)self).getMetaClass();
return metaclass == ((RubyBasicObject) self).getMetaClass();
}

@JIT
@@ -541,7 +549,7 @@ public static boolean testClass(Object object, Class clazz) {
}

public String toString() {
return "InvokeSite[name=" + name() + ",arity=" + arity + ",type=" + type() + ",file=" + file + ",line=" + line + "]";
return getClass().getName() + "[name=" + name() + ",arity=" + arity + ",type=" + type() + ",file=" + file + ",line=" + line + ']';
}

private static final MethodHandle TEST_CLASS = Binder
47 changes: 26 additions & 21 deletions core/src/main/java/org/jruby/runtime/invokedynamic/MathLinker.java
Original file line number Diff line number Diff line change
@@ -29,31 +29,35 @@

import java.lang.invoke.CallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.SwitchPoint;
import java.util.List;

import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;

import com.headius.invokebinder.Binder;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
import org.jruby.RubyInstanceConfig;
import org.jruby.management.Runtime;
import org.jruby.runtime.CallType;
import org.jruby.runtime.MethodIndex;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import java.lang.invoke.SwitchPoint;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.util.JavaNameMangler;
import org.jruby.util.StringSupport;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

public class MathLinker {

private static final Logger LOG = LoggerFactory.getLogger(MathLinker.class);
static { // enable DEBUG output
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.setDebugEnable(true);
}
private static final boolean LOG_BINDING = LOG.isDebugEnabled();

public static final MethodHandle FIXNUM_TEST =
Binder
@@ -83,8 +87,8 @@ public class MathLinker {
public static final MethodHandle FLOAT_OPERATOR = Binder.from(methodType(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, double.class)).invokeStaticQuiet(lookup(), MathLinker.class, "floatOperator");

public static CallSite fixnumOperatorBootstrap(Lookup lookup, String name, MethodType type, long value, int callType, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
List<String> names = StringSupport.split(name, ':');
String operator = JavaNameMangler.demangleMethodName(names.get(1));
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.values()[callType], file, line, operator, true);

MethodHandle target = FIXNUM_OPERATOR;
@@ -95,8 +99,8 @@ public static CallSite fixnumOperatorBootstrap(Lookup lookup, String name, Metho
}

public static CallSite fixnumBooleanBootstrap(Lookup lookup, String name, MethodType type, long value, int callType, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
List<String> names = StringSupport.split(name, ':');
String operator = JavaNameMangler.demangleMethodName(names.get(1));
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.values()[callType], file, line, operator, true);

MethodHandle target = FIXNUM_BOOLEAN;
@@ -107,8 +111,8 @@ public static CallSite fixnumBooleanBootstrap(Lookup lookup, String name, Method
}

public static CallSite floatOperatorBootstrap(Lookup lookup, String name, MethodType type, double value, int callType, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
List<String> names = StringSupport.split(name, ':');
String operator = JavaNameMangler.demangleMethodName(names.get(1));
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.values()[callType], file, line, operator, true);

MethodHandle target = FLOAT_OPERATOR;
@@ -147,8 +151,8 @@ public static IRubyObject fixnumOperator(ThreadContext context, IRubyObject call

MethodHandle test = FIXNUM_TEST;
test = permuteArguments(test, methodType(boolean.class, ThreadContext.class, IRubyObject.class, IRubyObject.class), new int[] {2});
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name + "\tFixnum operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

if (LOG_BINDING) LOG.debug(name + "\tFixnum operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

// confirm it's a Fixnum
target = guardWithTest(test, target, fallback);
@@ -180,8 +184,8 @@ public static boolean fixnumBoolean(ThreadContext context, IRubyObject caller, I

MethodHandle test = FIXNUM_TEST;
test = permuteArguments(test, methodType(boolean.class, ThreadContext.class, IRubyObject.class, IRubyObject.class), new int[] {2});
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name + "\tFixnum boolean operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

if (LOG_BINDING) LOG.debug(name + "\tFixnum boolean operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

// confirm it's a Fixnum
target = guardWithTest(test, target, fallback);
@@ -211,7 +215,7 @@ public static IRubyObject fixnumOperatorFail(ThreadContext context, IRubyObject
return entry.method.call(context, self, selfClass, operator, value);
}
}

public static boolean fixnumBooleanFail(ThreadContext context, IRubyObject caller, IRubyObject self, JRubyCallSite site, RubyFixnum value) throws Throwable {
return fixnumOperatorFail(context, caller, self, site, value).isTrue();
}
@@ -326,8 +330,9 @@ public static IRubyObject floatOperator(ThreadContext context, IRubyObject calle

MethodHandle test = FLOAT_TEST;
test = permuteArguments(test, methodType(boolean.class, ThreadContext.class, IRubyObject.class, IRubyObject.class), new int[] {2});

if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name + "\tFloat operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

if (LOG_BINDING) LOG.debug(name + "\tFloat operation at site #" + site.siteID() + " (" + site.file() + ":" + site.line() + ") bound directly");

site.setTarget(guardWithTest(test, target, fallback));

// confirm it's a Float
@@ -345,7 +350,7 @@ public static IRubyObject floatOperator(ThreadContext context, IRubyObject calle
public static boolean fixnumTest(IRubyObject self) {
return self instanceof RubyFixnum;
}

public static boolean floatTest(IRubyObject self) {
return self instanceof RubyFloat;
}
21 changes: 21 additions & 0 deletions core/src/main/ruby/jruby/asm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module JRuby
# Internal module which acts as a proxy for ASM class names.
# Auto loaded on demand (@see jruby.rb) when JRuby::ASM is accessed.
# @private
module ASM

begin
Opcodes = org.jruby.org.objectweb.asm.Opcodes
ClassReader = org.jruby.org.objectweb.asm.ClassReader
ClassWriter = org.jruby.org.objectweb.asm.ClassWriter
TraceClassVisitor = org.jruby.org.objectweb.asm.util.TraceClassVisitor
rescue
Opcodes = org.objectweb.asm.Opcodes
ClassReader = org.objectweb.asm.ClassReader
ClassWriter = org.objectweb.asm.ClassWriter
TraceClassVisitor = org.objectweb.asm.util.TraceClassVisitor
end

end
end
26 changes: 9 additions & 17 deletions core/src/main/ruby/jruby/jruby.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ def runtime; end if false
# Get the current runtime's config.
# Changes to the configuration won't be reflected in the runtime, meant to be read-only.
# @note implemented in *org.jruby.ext.jruby.JRubyLibrary*
def config; end if false
# def config; end if false

# Run the provided (required) block with the "global runtime" set to the current runtime,
# for libraries that expect to operate against the global runtime.
@@ -70,6 +70,8 @@ def self.visualize
end
deprecate_constant :IR

# Helper struct returned from `JRuby.compile`.
# @see JRuby#compile
class CompiledScript

attr_reader :name, :class_name, :original_script, :code
@@ -82,6 +84,7 @@ def initialize(filename, class_name, content, bytes)
@code = bytes
end

# Returns the original (.rb script content's
def to_s
@original_script
end
@@ -90,30 +93,19 @@ def inspect
"\#<#{self.class.name} #{@name}>"
end

# Inspects the compiled (Java) byte-code.
def inspect_bytecode
JRuby.init_asm

writer = java.io.StringWriter.new
reader = ClassReader.new(@code)
tracer = TraceClassVisitor.new(java.io.PrintWriter.new(writer))
reader = JRuby::ASM::ClassReader.new(@code)
tracer = JRuby::ASM::TraceClassVisitor.new(java.io.PrintWriter.new(writer))

reader.accept(tracer, ClassReader::SKIP_DEBUG)
reader.accept(tracer, JRuby::ASM::ClassReader::SKIP_DEBUG)

writer.to_s
end

end

# @private
def self.init_asm
return if const_defined? :TraceClassVisitor
begin
const_set(:TraceClassVisitor, org.jruby.org.objectweb.asm.util.TraceClassVisitor)
const_set(:ClassReader, org.jruby.org.objectweb.asm.ClassReader)
rescue
const_set(:TraceClassVisitor, org.objectweb.asm.util.TraceClassVisitor)
const_set(:ClassReader, org.objectweb.asm.ClassReader)
end
end
autoload :ASM, 'jruby/asm.rb'

end
Loading