Skip to content

Commit

Permalink
Move call info setup into indy sites
Browse files Browse the repository at this point in the history
This moves the update of call info state into the indy call site
for all normal and super invocations. The call info update happens
in a method handle "fold" combiner just prior to calling the
target method body.
  • Loading branch information
headius committed Mar 15, 2023
1 parent 1b46921 commit e2ba184
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 84 deletions.
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
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ public void invokeOther(String file, String scopeFieldName, CallBase call, int a
return;
}

int flags = call.getFlags();

IRBytecodeAdapter.BlockPassType blockPassType = IRBytecodeAdapter.BlockPassType.fromIR(call);
if (blockPassType.given()) {
if (arity == -1) {
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), CodegenUtils.sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT_ARRAY, Block.class)), NormalInvokeSite.BOOTSTRAP, blockPassType.literal(), file, compiler.getLastLine());
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), CodegenUtils.sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT_ARRAY, Block.class)), NormalInvokeSite.BOOTSTRAP, blockPassType.literal(), flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, arity + 2, Block.class)), NormalInvokeSite.BOOTSTRAP, blockPassType.literal(), file, compiler.getLastLine());
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, arity + 2, Block.class)), NormalInvokeSite.BOOTSTRAP, blockPassType.literal(), flags, file, compiler.getLastLine());
}
} else {
if (arity == -1) {
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT_ARRAY)), NormalInvokeSite.BOOTSTRAP, false, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT_ARRAY)), NormalInvokeSite.BOOTSTRAP, false, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT, arity)), NormalInvokeSite.BOOTSTRAP, false, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invoke:" + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, JVM.OBJECT, arity)), NormalInvokeSite.BOOTSTRAP, false, flags, file, compiler.getLastLine());
}
}
}
Expand Down Expand Up @@ -94,8 +96,6 @@ public void invokeOtherOneFloat(String file, CallBase call, double flote) {

String signature = sig(IRubyObject.class, params(ThreadContext.class, IRubyObject.class, IRubyObject.class));

setCallInfo(call.getFlags());

compiler.adapter.invokedynamic(
"floatOperator:" + JavaNameMangler.mangleMethodName(id),
signature,
Expand Down Expand Up @@ -124,21 +124,21 @@ public void invokeSelf(String file, String scopeFieldName, CallBase call, int ar
return;
}

setCallInfo(call.getFlags());
int flags = call.getFlags();

String action = call.getCallType() == CallType.FUNCTIONAL ? "callFunctional" : "callVariable";
IRBytecodeAdapter.BlockPassType blockPassType = IRBytecodeAdapter.BlockPassType.fromIR(call);
if (blockPassType != IRBytecodeAdapter.BlockPassType.NONE) {
if (arity == -1) {
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT_ARRAY, Block.class)), SelfInvokeSite.BOOTSTRAP, blockPassType.literal(), file, compiler.getLastLine());
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT_ARRAY, Block.class)), SelfInvokeSite.BOOTSTRAP, blockPassType.literal(), flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, arity + 1, Block.class)), SelfInvokeSite.BOOTSTRAP, blockPassType.literal(), file, compiler.getLastLine());
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, arity + 1, Block.class)), SelfInvokeSite.BOOTSTRAP, blockPassType.literal(), flags, file, compiler.getLastLine());
}
} else {
if (arity == -1) {
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT_ARRAY)), SelfInvokeSite.BOOTSTRAP, false, file, compiler.getLastLine());
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT_ARRAY)), SelfInvokeSite.BOOTSTRAP, false, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, arity)), SelfInvokeSite.BOOTSTRAP, false, file, compiler.getLastLine());
compiler.adapter.invokedynamic(action + ':' + JavaNameMangler.mangleMethodName(id), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, arity)), SelfInvokeSite.BOOTSTRAP, false, flags, file, compiler.getLastLine());
}
}
}
Expand All @@ -147,58 +147,50 @@ public void invokeInstanceSuper(String file, String name, int arity, boolean has
if (arity > IRBytecodeAdapter.MAX_ARGUMENTS)
throw new NotCompilableException("call to instance super has more than " + IRBytecodeAdapter.MAX_ARGUMENTS + " arguments");

setCallInfo(flags);

String splatmapString = IRRuntimeHelpers.encodeSplatmap(splatmap);
if (hasClosure) {
String operation = literalClosure ? "invokeInstanceSuperIter" : "invokeInstanceSuper";
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invokeInstanceSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invokeInstanceSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
}
}

public void invokeClassSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags) {
if (arity > IRBytecodeAdapter.MAX_ARGUMENTS)
throw new NotCompilableException("call to class super has more than " + IRBytecodeAdapter.MAX_ARGUMENTS + " arguments");

setCallInfo(flags);

String splatmapString = IRRuntimeHelpers.encodeSplatmap(splatmap);
if (hasClosure) {
String operation = literalClosure ? "invokeClassSuperIter" : "invokeClassSuper";
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invokeClassSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invokeClassSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
}
}

public void invokeUnresolvedSuper(String file, String name, int arity, boolean hasClosure, boolean literalClosure, boolean[] splatmap, int flags) {
if (arity > IRBytecodeAdapter.MAX_ARGUMENTS)
throw new NotCompilableException("call to unresolved super has more than " + IRBytecodeAdapter.MAX_ARGUMENTS + " arguments");

setCallInfo(flags);

String splatmapString = IRRuntimeHelpers.encodeSplatmap(splatmap);
if (hasClosure) {
String operation = literalClosure ? "invokeUnresolvedSuperIter" : "invokeUnresolvedSuper";
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic(operation + ":" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invokeUnresolvedSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invokeUnresolvedSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
}
}

public void invokeZSuper(String file, String name, int arity, boolean hasClosure, boolean[] splatmap, int flags) {
if (arity > IRBytecodeAdapter.MAX_ARGUMENTS)
throw new NotCompilableException("call to zsuper has more than " + IRBytecodeAdapter.MAX_ARGUMENTS + " arguments");

setCallInfo(flags);

String splatmapString = IRRuntimeHelpers.encodeSplatmap(splatmap);
if (hasClosure) {
compiler.adapter.invokedynamic("invokeZSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invokeZSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity, Block.class)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
} else {
compiler.adapter.invokedynamic("invokeZSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, file, compiler.getLastLine());
compiler.adapter.invokedynamic("invokeZSuper:" + JavaNameMangler.mangleMethodName(name), sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, JVM.OBJECT, RubyClass.class, JVM.OBJECT, arity)), Bootstrap.invokeSuper(), splatmapString, flags, file, compiler.getLastLine());
}
}

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 InstanceSuperInvokeSite extends ResolvedSuperInvokeSite {
public InstanceSuperInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
super(type, name, splatmapString, file, line);
public InstanceSuperInvokeSite(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.instanceSuperSplatArgs(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 InstanceSuperIterInvokeSite extends ResolvedSuperInvokeSite {
public InstanceSuperIterInvokeSite(MethodType type, String name, String splatmapString, String file, int line) {
super(type, name, splatmapString, file, line);
public InstanceSuperIterInvokeSite(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.instanceSuperIterSplatArgs(context, self, superName, definingModule, args, block, splatMap);
}
}
Loading

0 comments on commit e2ba184

Please sign in to comment.