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

Commits on Aug 29, 2017

  1. Copy the full SHA
    c2dcfed View commit details
  2. Copy the full SHA
    e94eb2b View commit details

Commits on Aug 30, 2017

  1. Merge pull request #4762 from original-brownbear/cache-req-count

    MINOR: Cache required arg count in CompiledMethodIR
    enebo authored Aug 30, 2017
    Copy the full SHA
    b025bd1 View commit details
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
package org.jruby.internal.runtime;

import org.jruby.Ruby;
import java.util.ArrayList;
import java.util.List;
import org.jruby.RubyModule;
import org.jruby.anno.MethodDescriptor;
import org.jruby.compiler.Compilable;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.Interp;
import org.jruby.ir.instructions.GetFieldInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.PutFieldInstr;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ivars.MethodData;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractIRMethod extends DynamicMethod implements IRMethodArgs, PositionAware, Cloneable {

private Signature signature;
protected final Signature signature;
protected final IRScope method;
protected final StaticScope staticScope;
protected InterpreterContext interpreterContext = null;
@@ -78,7 +65,7 @@ public ArgumentDescriptor[] getArgumentDescriptors() {

public abstract InterpreterContext ensureInstrsReady();

public Signature getSignature() {
public final Signature getSignature() {
return signature;
}

Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package org.jruby.internal.runtime.methods;

import java.lang.invoke.MethodHandle;
import org.jruby.RubyModule;
import org.jruby.internal.runtime.AbstractIRMethod;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Block;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

import java.lang.invoke.MethodHandle;

public class CompiledIRMethod extends AbstractIRMethod {
protected final MethodHandle variable;
public final class CompiledIRMethod extends AbstractIRMethod {
private final MethodHandle variable;

protected final MethodHandle specific;
protected final int specificArity;
private final MethodHandle specific;
private final int specificArity;

private final boolean hasKwargs;

@@ -71,7 +69,7 @@ public InterpreterContext ensureInstrsReady() {

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
if (hasKwargs) args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, getSignature().required());
if (hasKwargs) args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, signature);

try {
return (IRubyObject) this.variable.invokeExact(context, staticScope, self, args, block, implementationClass, name);
@@ -136,7 +134,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
if (hasKwargs) args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, getSignature().required());
if (hasKwargs) args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, signature);

try {
return (IRubyObject) this.variable.invokeExact(context, staticScope, self, args, Block.NULL_BLOCK, implementationClass, name);
63 changes: 48 additions & 15 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,70 @@
package org.jruby.ir.runtime;

import com.headius.invokebinder.Signature;
import jnr.ffi.annotations.In;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.util.ArrayList;
import java.util.Map;
import org.jcodings.Encoding;
import org.jruby.*;
import org.jruby.EvalType;
import org.jruby.MetaClass;
import org.jruby.NativeException;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyBasicObject;
import org.jruby.RubyBoolean;
import org.jruby.RubyClass;
import org.jruby.RubyEncoding;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
import org.jruby.RubyHash;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyLocalJumpError;
import org.jruby.RubyMatchData;
import org.jruby.RubyMethod;
import org.jruby.RubyModule;
import org.jruby.RubyNil;
import org.jruby.RubyProc;
import org.jruby.RubyRegexp;
import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.common.IRubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.exceptions.Unrescuable;
import org.jruby.internal.runtime.methods.CompiledIRNoProtocolMethod;
import org.jruby.internal.runtime.methods.CompiledIRMethod;
import org.jruby.internal.runtime.methods.CompiledIRNoProtocolMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.InterpretedIRBodyMethod;
import org.jruby.internal.runtime.methods.InterpretedIRMetaClassBody;
import org.jruby.internal.runtime.methods.InterpretedIRMethod;
import org.jruby.internal.runtime.methods.MixedModeIRMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.ir.IRMetaClassBody;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMetaClassBody;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Interp;
import org.jruby.ir.JIT;
import org.jruby.ir.Tuple;
import org.jruby.ir.operands.IRException;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Splat;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.persistence.IRReader;
import org.jruby.ir.persistence.IRReaderStream;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.CallType;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaSites.IRRuntimeHelpersSites;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CachingCallSite;
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
@@ -47,12 +80,6 @@
import org.jruby.util.log.LoggerFactory;
import org.objectweb.asm.Type;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.util.ArrayList;
import java.util.Map;

public class IRRuntimeHelpers {
private static final Logger LOG = LoggerFactory.getLogger(IRRuntimeHelpers.class);

@@ -493,11 +520,18 @@ public static void checkArity(ThreadContext context, StaticScope scope, Object[]
}
}

public static IRubyObject[] frobnicateKwargsArgument(ThreadContext context, IRubyObject[] args,
org.jruby.runtime.Signature signature) {
return frobnicateKwargsArgument(context, args, signature.required());
}

public static IRubyObject[] frobnicateKwargsArgument(ThreadContext context, IRubyObject[] args, int requiredArgsCount) {
if (args.length <= requiredArgsCount) return args; // No kwarg because required args slurp them up.
// No kwarg because required args slurp them up.
return args.length <= requiredArgsCount ? args : frobnicateKwargsArgument(context, args);
}

private static IRubyObject[] frobnicateKwargsArgument(final ThreadContext context, IRubyObject[] args) {
final IRubyObject kwargs = toHash(args[args.length - 1], context);

if (kwargs != null) {
if (kwargs.isNil()) { // nil on to_hash is supposed to keep itself as real value so we need to make kwargs hash
return ArraySupport.newCopy(args, RubyHash.newSmallHash(context.runtime));
@@ -520,7 +554,6 @@ public static IRubyObject[] frobnicateKwargsArgument(ThreadContext context, IRub
}
args[args.length - 1] = visitor.syms; // kwargs hash
}

return args;
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Signature.java
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
/**
* A representation of a Ruby method signature (argument layout, min/max, keyword layout, rest args).
*/
public class Signature {
public final class Signature {
public enum Rest {
NONE, NORM, ANON, STAR;