Skip to content

Commit f1ce425

Browse files
authored
Merge pull request #7720 from headius/more_indy_call_optz
More indy call optz
2 parents ec5bf9b + 48ef556 commit f1ce425

31 files changed

+453
-511
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ jobs:
123123

124124
strategy:
125125
matrix:
126-
target: ['test:jruby', 'spec:compiler']
127-
java-version: ['8', '17']
126+
target: ['test:jruby:jit', 'spec:compiler', 'spec:ruby:fast:jit']
127+
java-version: ['17']
128128
fail-fast: false
129129

130130
name: rake ${{ matrix.target }} (Java ${{ matrix.java-version }} +indy)

core/pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
jar 'org.jruby.jcodings:jcodings:1.0.58'
5656
jar 'org.jruby:dirgra:0.3'
5757

58-
jar 'com.headius:invokebinder:1.12'
58+
jar 'com.headius:invokebinder:1.13'
5959
jar 'com.headius:options:1.6'
6060

6161
jar 'com.jcraft:jzlib:1.1.3'

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ DO NOT MODIFY - GENERATED CODE
164164
<dependency>
165165
<groupId>com.headius</groupId>
166166
<artifactId>invokebinder</artifactId>
167-
<version>1.12</version>
167+
<version>1.13</version>
168168
</dependency>
169169
<dependency>
170170
<groupId>com.headius</groupId>

core/src/main/java/org/jruby/RubyThread.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,8 @@ private IRubyObject genericKill(Ruby runtime, RubyThread currentThread) {
18591859
private void pendingInterruptEnqueue(IRubyObject v) {
18601860
pendingInterruptQueue.add(v);
18611861
pendingInterruptQueueChecked = false;
1862+
1863+
getRuntime().getCheckpointInvalidator().invalidate();
18621864
}
18631865

18641866
/**

core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,11 @@ public static void resetCallInfo(ThreadContext context) {
837837
context.resetCallInfo();
838838
}
839839

840+
@JIT
841+
public static void clearCallInfo(ThreadContext context) {
842+
context.clearCallInfo();
843+
}
844+
840845
public static void checkForExtraUnwantedKeywordArgs(ThreadContext context, final StaticScope scope, RubyHash keywordArgs) {
841846
// we do an inexpensive non-gathering scan first to see if there's a bad keyword
842847
try {

core/src/main/java/org/jruby/ir/targets/InvocationCompiler.java

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,54 +51,62 @@ public interface InvocationCompiler {
5151

5252
/**
5353
* Invoke a superclass method from an instance context.
54-
*
54+
* <p>
5555
* Stack required: context, caller, self, start class, arguments[, block]
56-
* @param file the filename of the script making this call
57-
* @param name name of the method to invoke
58-
* @param arity arity of the arguments on the stack
59-
* @param hasClosure whether a block is passed
56+
*
57+
* @param file the filename of the script making this call
58+
* @param name name of the method to invoke
59+
* @param arity arity of the arguments on the stack
60+
* @param hasClosure whether a block is passed
6061
* @param literalClosure whether the block passed is a literal closure
61-
* @param splatmap a map of arguments to be splatted back into arg list
62+
* @param splatmap a map of arguments to be splatted back into arg list
63+
* @param flags
6264
*/
63-
void invokeInstanceSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
65+
void invokeInstanceSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);
6466

6567
/**
6668
* Invoke a superclass method from a class context.
67-
*
69+
* <p>
6870
* Stack required: context, caller, self, start class, arguments[, block]
69-
* @param file the filename of the script making this call
70-
* @param name name of the method to invoke
71-
* @param arity arity of the arguments on the stack
72-
* @param hasClosure whether a block is passed
71+
*
72+
* @param file the filename of the script making this call
73+
* @param name name of the method to invoke
74+
* @param arity arity of the arguments on the stack
75+
* @param hasClosure whether a block is passed
7376
* @param literalClosure whether the block passed is a literal closure
74-
* @param splatmap a map of arguments to be splatted back into arg list
77+
* @param splatmap a map of arguments to be splatted back into arg list
78+
* @param flags
7579
*/
76-
void invokeClassSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
80+
void invokeClassSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);
7781

7882
/**
7983
* Invoke a superclass method from an unresolved context.
80-
*
84+
* <p>
8185
* Stack required: context, caller, self, arguments[, block]
82-
* @param file the filename of the script making this call
83-
* @param name name of the method to invoke
84-
* @param arity arity of the arguments on the stack
85-
* @param hasClosure whether a block is passed
86+
*
87+
* @param file the filename of the script making this call
88+
* @param name name of the method to invoke
89+
* @param arity arity of the arguments on the stack
90+
* @param hasClosure whether a block is passed
8691
* @param literalClosure whether the block passed is a literal closure
87-
* @param splatmap a map of arguments to be splatted back into arg list
92+
* @param splatmap a map of arguments to be splatted back into arg list
93+
* @param flags
8894
*/
89-
void invokeUnresolvedSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap);
95+
void invokeUnresolvedSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags);
9096

9197
/**
9298
* Invoke a superclass method from a zsuper in a block.
93-
*
99+
* <p>
94100
* Stack required: context, caller, self, arguments[, block]
95-
* @param file the filename of the script making this call
96-
* @param name name of the method to invoke
97-
* @param arity arity of the arguments on the stack
101+
*
102+
* @param file the filename of the script making this call
103+
* @param name name of the method to invoke
104+
* @param arity arity of the arguments on the stack
98105
* @param hasClosure whether a block is passed
99-
* @param splatmap a map of arguments to be splatted back into arg list
106+
* @param splatmap a map of arguments to be splatted back into arg list
107+
* @param flags
100108
*/
101-
void invokeZSuper(String file, String name, int arity, boolean hasClosure, boolean[] splatmap);
109+
void invokeZSuper(String file, String name, int arity, boolean hasClosure, boolean[] splatmap, int flags);
102110

103111
/**
104112
* Perform a === call appropriate for a case/when statement.
@@ -113,4 +121,11 @@ public interface InvocationCompiler {
113121
* Stack required: context, caller, receiver
114122
*/
115123
void asString(AsStringInstr call, String scopeFieldName, String file);
124+
125+
/**
126+
* Sets the current callInfo, when it cannot be passed other ways
127+
*
128+
* Stack required: none
129+
*/
130+
void setCallInfo(int flags);
116131
}

core/src/main/java/org/jruby/ir/targets/JVMVisitor.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,6 @@ private void compileCallCommon(IRBytecodeAdapter m, CallBase call) {
12581258
}
12591259
}
12601260

1261-
setupCallInfo(call.getFlags());
1262-
12631261
switch (call.getCallType()) {
12641262
case FUNCTIONAL:
12651263
case VARIABLE:
@@ -1690,20 +1688,18 @@ private void superCommon(String name, CallInstr instr, Operand[] args, Operand d
16901688
}
16911689
}
16921690

1693-
setupCallInfo(instr.getFlags());
1694-
16951691
switch (operation) {
16961692
case INSTANCE_SUPER:
1697-
m.getInvocationCompiler().invokeInstanceSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
1693+
m.getInvocationCompiler().invokeInstanceSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
16981694
break;
16991695
case CLASS_SUPER:
1700-
m.getInvocationCompiler().invokeClassSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
1696+
m.getInvocationCompiler().invokeClassSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
17011697
break;
17021698
case UNRESOLVED_SUPER:
1703-
m.getInvocationCompiler().invokeUnresolvedSuper(file, name, args.length, hasClosure, literalClosure, splatMap);
1699+
m.getInvocationCompiler().invokeUnresolvedSuper(file, name, args.length, hasClosure, literalClosure, splatMap, instr.getFlags());
17041700
break;
17051701
case ZSUPER:
1706-
m.getInvocationCompiler().invokeZSuper(file, name, args.length, hasClosure, splatMap);
1702+
m.getInvocationCompiler().invokeZSuper(file, name, args.length, hasClosure, splatMap, instr.getFlags());
17071703
break;
17081704
default:
17091705
throw new NotCompilableException("unknown super type " + operation + " in " + instr);
@@ -2553,9 +2549,7 @@ public void UpdateBlockExecutionStateInstr (UpdateBlockExecutionStateInstr instr
25532549
}
25542550

25552551
private void setupCallInfo(int flags) {
2556-
jvmMethod().loadContext();
2557-
jvmMethod().adapter.ldc(flags);
2558-
jvmMethod().invokeIRHelper("setCallInfo", sig(void.class, ThreadContext.class, int.class));
2552+
jvmMethod().getInvocationCompiler().setCallInfo(flags);
25592553
}
25602554

25612555
@Override

core/src/main/java/org/jruby/ir/targets/indy/ArrayDerefInvokeSite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class ArrayDerefInvokeSite extends NormalInvokeSite {
3333
public ArrayDerefInvokeSite(MethodType type, String file, int line) {
34-
super(type, "[]", false, file, line);
34+
super(type, "[]", false, 0, file, line);
3535
}
3636

3737
public static final Handle BOOTSTRAP = new Handle(

core/src/main/java/org/jruby/ir/targets/indy/AsStringSite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public class AsStringSite extends NormalInvokeSite {
3131
public AsStringSite(MethodType type, String file, int line) {
32-
super(type, "to_s", false, file, line);
32+
super(type, "to_s", false, 0, file, line);
3333
}
3434

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

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

5252
MethodHandle checkcast = Binder.from(type().changeReturnType(boolean.class))

core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class Bootstrap {
122122
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);
123123
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);
124124
public final static String BOOTSTRAP_INT_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, int.class, int.class);
125+
public final static String BOOTSTRAP_INT_SIG = sig(CallSite.class, Lookup.class, String.class, MethodType.class, int.class);
125126
private static final Logger LOG = LoggerFactory.getLogger(Bootstrap.class);
126127
static final Lookup LOOKUP = MethodHandles.lookup();
127128
public static final Handle EMPTY_STRING_BOOTSTRAP = new Handle(
@@ -1424,6 +1425,10 @@ public static Handle checkpointHandle() {
14241425
return getBootstrapHandle("checkpointBootstrap", BOOTSTRAP_BARE_SIG);
14251426
}
14261427

1428+
public static Handle callInfoHandle() {
1429+
return getBootstrapHandle("callInfoBootstrap", BOOTSTRAP_INT_SIG);
1430+
}
1431+
14271432
public static Handle coverLineHandle() {
14281433
return getBootstrapHandle("coverLineBootstrap", sig(CallSite.class, Lookup.class, String.class, MethodType.class, String.class, int.class, int.class));
14291434
}
@@ -1472,6 +1477,21 @@ public static void checkpointFallback(MutableCallSite site, ThreadContext contex
14721477
target = ((SwitchPoint)invalidator.getData()).guardWithTest(target, fallback);
14731478

14741479
site.setTarget(target);
1480+
1481+
// poll for events once since we've ended up back in fallback
1482+
context.pollThreadEvents();
1483+
}
1484+
1485+
public static CallSite callInfoBootstrap(Lookup lookup, String name, MethodType type, int callInfo) throws Throwable {
1486+
MethodHandle handle;
1487+
if (callInfo == 0) {
1488+
handle = lookup.findVirtual(ThreadContext.class, "clearCallInfo", methodType(void.class));
1489+
} else {
1490+
handle = lookup.findStatic(IRRuntimeHelpers.class, "setCallInfo", methodType(void.class, ThreadContext.class, int.class));
1491+
handle = insertArguments(handle, 1, callInfo);
1492+
}
1493+
1494+
return new ConstantCallSite(handle);
14751495
}
14761496

14771497
public static CallSite coverLineBootstrap(Lookup lookup, String name, MethodType type, String filename, int line, int oneshot) throws Throwable {

core/src/main/java/org/jruby/ir/targets/indy/ClassSuperInvokeSite.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* Created by headius on 10/23/14.
1313
*/
1414
public class ClassSuperInvokeSite extends ResolvedSuperInvokeSite {
15-
public ClassSuperInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
16-
super(type, name, splatmapString, file, line);
15+
public ClassSuperInvokeSite(MethodType type, String name, String splatmapString, int flags, String file, int line) {
16+
super(type, name, splatmapString, flags, file, line);
1717
}
1818

1919
@Override
@@ -26,6 +26,7 @@ protected RubyClass getSuperClass(RubyClass definingModule) {
2626
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, RubyClass definingModule, IRubyObject[] args, Block block) throws Throwable {
2727
// TODO: get rid of caller
2828
// TODO: caching
29+
IRRuntimeHelpers.setCallInfo(context, flags);
2930
return IRRuntimeHelpers.classSuperSplatArgs(context, self, superName, definingModule, args, block, splatMap);
3031
}
3132
}

core/src/main/java/org/jruby/ir/targets/indy/ClassSuperIterInvokeSite.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* Created by headius on 10/23/14.
1313
*/
1414
public class ClassSuperIterInvokeSite extends ResolvedSuperInvokeSite {
15-
public ClassSuperIterInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
16-
super(type, name, splatmapString, file, line);
15+
public ClassSuperIterInvokeSite(MethodType type, String name, String splatmapString, int flags, String file, int line) {
16+
super(type, name, splatmapString, flags, file, line);
1717
}
1818

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

0 commit comments

Comments
 (0)