Skip to content

Commit

Permalink
Merge pull request #7720 from headius/more_indy_call_optz
Browse files Browse the repository at this point in the history
More indy call optz
  • Loading branch information
headius committed Mar 20, 2023
2 parents ec5bf9b + 48ef556 commit f1ce425
Show file tree
Hide file tree
Showing 31 changed files with 453 additions and 511 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ jobs:

strategy:
matrix:
target: ['test:jruby', 'spec:compiler']
java-version: ['8', '17']
target: ['test:jruby:jit', 'spec:compiler', 'spec:ruby:fast:jit']
java-version: ['17']
fail-fast: false

name: rake ${{ matrix.target }} (Java ${{ matrix.java-version }} +indy)
Expand Down
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
jar 'org.jruby.jcodings:jcodings:1.0.58'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.12'
jar 'com.headius:invokebinder:1.13'
jar 'com.headius:options:1.6'

jar 'com.jcraft:jzlib:1.1.3'
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ DO NOT MODIFY - GENERATED CODE
<dependency>
<groupId>com.headius</groupId>
<artifactId>invokebinder</artifactId>
<version>1.12</version>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,8 @@ private IRubyObject genericKill(Ruby runtime, RubyThread currentThread) {
private void pendingInterruptEnqueue(IRubyObject v) {
pendingInterruptQueue.add(v);
pendingInterruptQueueChecked = false;

getRuntime().getCheckpointInvalidator().invalidate();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ public static void resetCallInfo(ThreadContext context) {
context.resetCallInfo();
}

@JIT
public static void clearCallInfo(ThreadContext context) {
context.clearCallInfo();
}

public static void checkForExtraUnwantedKeywordArgs(ThreadContext context, final StaticScope scope, RubyHash keywordArgs) {
// we do an inexpensive non-gathering scan first to see if there's a bad keyword
try {
Expand Down
69 changes: 42 additions & 27 deletions core/src/main/java/org/jruby/ir/targets/InvocationCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,54 +51,62 @@ public interface InvocationCompiler {

/**
* Invoke a superclass method from an instance context.
*
* <p>
* Stack required: context, caller, self, start class, arguments[, block]
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
*
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
* @param literalClosure whether the block passed is a literal closure
* @param splatmap a map of arguments to be splatted back into arg list
* @param splatmap a map of arguments to be splatted back into arg list
* @param flags
*/
void invokeInstanceSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
void invokeInstanceSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);

/**
* Invoke a superclass method from a class context.
*
* <p>
* Stack required: context, caller, self, start class, arguments[, block]
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
*
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
* @param literalClosure whether the block passed is a literal closure
* @param splatmap a map of arguments to be splatted back into arg list
* @param splatmap a map of arguments to be splatted back into arg list
* @param flags
*/
void invokeClassSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
void invokeClassSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);

/**
* Invoke a superclass method from an unresolved context.
*
* <p>
* Stack required: context, caller, self, arguments[, block]
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
*
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
* @param literalClosure whether the block passed is a literal closure
* @param splatmap a map of arguments to be splatted back into arg list
* @param splatmap a map of arguments to be splatted back into arg list
* @param flags
*/
void invokeUnresolvedSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
void invokeUnresolvedSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);

/**
* Invoke a superclass method from a zsuper in a block.
*
* <p>
* Stack required: context, caller, self, arguments[, block]
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
*
* @param file the filename of the script making this call
* @param name name of the method to invoke
* @param arity arity of the arguments on the stack
* @param hasClosure whether a block is passed
* @param splatmap a map of arguments to be splatted back into arg list
* @param splatmap a map of arguments to be splatted back into arg list
* @param flags
*/
void invokeZSuper(String file, String name, int arity, boolean hasClosure, boolean[] splatmap);
void invokeZSuper(String file, String name, int arity, boolean hasClosure, boolean[] splatmap, int flags);

/**
* Perform a === call appropriate for a case/when statement.
Expand All @@ -113,4 +121,11 @@ public interface InvocationCompiler {
* Stack required: context, caller, receiver
*/
void asString(AsStringInstr call, String scopeFieldName, String file);

/**
* Sets the current callInfo, when it cannot be passed other ways
*
* Stack required: none
*/
void setCallInfo(int flags);
}
16 changes: 5 additions & 11 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,6 @@ private void compileCallCommon(IRBytecodeAdapter m, CallBase call) {
}
}

setupCallInfo(call.getFlags());

switch (call.getCallType()) {
case FUNCTIONAL:
case VARIABLE:
Expand Down Expand Up @@ -1690,20 +1688,18 @@ private void superCommon(String name, CallInstr instr, Operand[] args, Operand d
}
}

setupCallInfo(instr.getFlags());

switch (operation) {
case INSTANCE_SUPER:
m.getInvocationCompiler().invokeInstanceSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
m.getInvocationCompiler().invokeInstanceSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
break;
case CLASS_SUPER:
m.getInvocationCompiler().invokeClassSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
m.getInvocationCompiler().invokeClassSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
break;
case UNRESOLVED_SUPER:
m.getInvocationCompiler().invokeUnresolvedSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
m.getInvocationCompiler().invokeUnresolvedSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
break;
case ZSUPER:
m.getInvocationCompiler().invokeZSuper(file, name, args.length, hasClosure, splatMap);
m.getInvocationCompiler().invokeZSuper(file, name, args.length, hasClosure, splatMap, instr.getFlags());
break;
default:
throw new NotCompilableException("unknown super type " + operation + " in " + instr);
Expand Down Expand Up @@ -2553,9 +2549,7 @@ public void UpdateBlockExecutionStateInstr (UpdateBlockExecutionStateInstr instr
}

private void setupCallInfo(int flags) {
jvmMethod().loadContext();
jvmMethod().adapter.ldc(flags);
jvmMethod().invokeIRHelper("setCallInfo", sig(void.class, ThreadContext.class, int.class));
jvmMethod().getInvocationCompiler().setCallInfo(flags);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ArrayDerefInvokeSite extends NormalInvokeSite {
public ArrayDerefInvokeSite(MethodType type, String file, int line) {
super(type, "[]", false, file, line);
super(type, "[]", false, 0, file, line);
}

public static final Handle BOOTSTRAP = new Handle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class AsStringSite extends NormalInvokeSite {
public AsStringSite(MethodType type, String file, int line) {
super(type, "to_s", false, file, line);
super(type, "to_s", false, 0, file, line);
}

public static final Handle BOOTSTRAP = new Handle(
Expand All @@ -46,7 +46,7 @@ public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, Metho
}

public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) throws Throwable {
NormalInvokeSite toS = new NormalInvokeSite(type(), "to_s", false, file, line);
NormalInvokeSite toS = new NormalInvokeSite(type(), "to_s", false, 0, file, line);
MethodHandle toS_handle = toS.dynamicInvoker();

MethodHandle checkcast = Binder.from(type().changeReturnType(boolean.class))
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class Bootstrap {
public final static String BOOTSTRAP_LONG_STRING_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, long.class, int.class, String.class, int.class);
public final static String BOOTSTRAP_DOUBLE_STRING_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, double.class, int.class, String.class, int.class);
public final static String BOOTSTRAP_INT_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, int.class, int.class);
public final static String BOOTSTRAP_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, int.class);
private static final Logger LOG = LoggerFactory.getLogger(Bootstrap.class);
static final Lookup LOOKUP = MethodHandles.lookup();
public static final Handle EMPTY_STRING_BOOTSTRAP = new Handle(
Expand Down Expand Up @@ -1424,6 +1425,10 @@ public static Handle checkpointHandle() {
return getBootstrapHandle("checkpointBootstrap", BOOTSTRAP_BARE_SIG);
}

public static Handle callInfoHandle() {
return getBootstrapHandle("callInfoBootstrap", BOOTSTRAP_INT_SIG);
}

public static Handle coverLineHandle() {
return getBootstrapHandle("coverLineBootstrap", sig(CallSite.class, Lookup.class, String.class, MethodType.class, String.class, int.class, int.class));
}
Expand Down Expand Up @@ -1472,6 +1477,21 @@ public static void checkpointFallback(MutableCallSite site, ThreadContext contex
target = ((SwitchPoint)invalidator.getData()).guardWithTest(target, fallback);

site.setTarget(target);

// poll for events once since we've ended up back in fallback
context.pollThreadEvents();
}

public static CallSite callInfoBootstrap(Lookup lookup, String name, MethodType type, int callInfo) throws Throwable {
MethodHandle handle;
if (callInfo == 0) {
handle = lookup.findVirtual(ThreadContext.class, "clearCallInfo", methodType(void.class));
} else {
handle = lookup.findStatic(IRRuntimeHelpers.class, "setCallInfo", methodType(void.class, ThreadContext.class, int.class));
handle = insertArguments(handle, 1, callInfo);
}

return new ConstantCallSite(handle);
}

public static CallSite coverLineBootstrap(Lookup lookup, String name, MethodType type, String filename, int line, int oneshot) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Created by headius on 10/23/14.
*/
public class ClassSuperInvokeSite extends ResolvedSuperInvokeSite {
public ClassSuperInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
super(type, name, splatmapString, file, line);
public ClassSuperInvokeSite(MethodType type, String name, String splatmapString, int flags, String file, int line) {
super(type, name, splatmapString, flags, file, line);
}

@Override
Expand All @@ -26,6 +26,7 @@ protected RubyClass getSuperClass(RubyClass definingModule) {
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, RubyClass definingModule, IRubyObject[] args, Block block) throws Throwable {
// TODO: get rid of caller
// TODO: caching
IRRuntimeHelpers.setCallInfo(context, flags);
return IRRuntimeHelpers.classSuperSplatArgs(context, self, superName, definingModule, args, block, splatMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Created by headius on 10/23/14.
*/
public class ClassSuperIterInvokeSite extends ResolvedSuperInvokeSite {
public ClassSuperIterInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
super(type, name, splatmapString, file, line);
public ClassSuperIterInvokeSite(MethodType type, String name, String splatmapString, int flags, String file, int line) {
super(type, name, splatmapString, flags, file, line);
}

@Override
Expand All @@ -26,6 +26,7 @@ protected RubyClass getSuperClass(RubyClass definingModule) {
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, RubyClass definingModule, IRubyObject[] args, Block block) throws Throwable {
// TODO: get rid of caller
// TODO: caching
IRRuntimeHelpers.setCallInfo(context, flags);
return IRRuntimeHelpers.classSuperIterSplatArgs(context, self, superName, definingModule, args, block, splatMap);
}
}

0 comments on commit f1ce425

Please sign in to comment.