Skip to content

Commit

Permalink
Mild refactoring of invokers code (came from bytelist_love work). As …
Browse files Browse the repository at this point in the history
…I need

to make changes to generated code I am trying to comment/document some portions
and reduce some duplication when possible.
enebo committed Jan 17, 2018
1 parent 8723a89 commit 4a34053
Showing 3 changed files with 28 additions and 31 deletions.
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/anno/IndyBinder.java
Original file line number Diff line number Diff line change
@@ -362,16 +362,7 @@ public void processMethodDeclarationMulti(List<ExecutableElement> methods) {

meta |= anno.meta();

int specificArity = -1;
if (desc.optional == 0 && !desc.rest) {
if (desc.required == 0) {
if (desc.actualRequired <= 3) {
specificArity = desc.actualRequired;
}
} else if (desc.required >= 0 && desc.required <= 3) {
specificArity = desc.required;
}
}
int specificArity = desc.calculateSpecificCallArity();

if (specificArity != -1) {
if (specificArity < min) min = specificArity;
22 changes: 22 additions & 0 deletions core/src/main/java/org/jruby/anno/MethodDescriptor.java
Original file line number Diff line number Diff line change
@@ -145,4 +145,26 @@ public MethodDescriptor(T methodObject) {
int arityRequired = Math.max(required, actualRequired);
arity = (optional > 0 || rest) ? -(arityRequired + 1) : arityRequired;
}

public final static int MAX_REQUIRED_UNBOXED_ARITY = 3;

/**
* Returns a value useful for number of arguments we need for arity when generating call methods used by
* invokers and the JIT. Note: MAX_REQUIRED_UNBOXED_ARITY looks like some tweakable setting but it is merely
* for documentation. All our non-generated internal code is also locked to the same specific arities so we
* cannot just change this value and be happy.
*
* @return arity value of specific required arity which can be used as an unboxed call or -1 for all other cases.
*/
public int calculateSpecificCallArity() {
if (optional == 0 && !rest) {
if (required == 0) {
if (actualRequired <= MAX_REQUIRED_UNBOXED_ARITY) return actualRequired;
} else if (required >= 0 && required <= MAX_REQUIRED_UNBOXED_ARITY) {
return required;
}
}

return -1;
}
}
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ public Class getAnnotatedMethodClass(List<JavaMethodDescriptor> descs) {

ClassWriter cw = createJavaMethodCtor(generatedClassPath, superClassString, info.getParameterDesc());

addAnnotatedMethodInvoker(cw, "call", superClassString, descs);
addAnnotatedMethodInvoker(cw, superClassString, descs);

c = endClass(cw, generatedClassName);
}
@@ -675,29 +675,13 @@ private SkinnyMethodAdapter beginMethod(ClassWriter cw, String methodName, int s
}
}

private void addAnnotatedMethodInvoker(ClassWriter cw, String callName, String superClass, List<JavaMethodDescriptor> descs) {
private void addAnnotatedMethodInvoker(ClassWriter cw, String superClass, List<JavaMethodDescriptor> descs) {
for (JavaMethodDescriptor desc: descs) {
int specificArity = -1;
if (desc.optional == 0 && !desc.rest) {
if (desc.required == 0) {
if (desc.actualRequired <= 3) {
specificArity = desc.actualRequired;
} else {
specificArity = -1;
}
} else if (desc.required >= 0 && desc.required <= 3) {
specificArity = desc.required;
}
}

boolean hasBlock = desc.hasBlock;
SkinnyMethodAdapter mv;
int specificArity = desc.calculateSpecificCallArity();

mv = beginMethod(cw, callName, specificArity, hasBlock);
SkinnyMethodAdapter mv = beginMethod(cw, "call", specificArity, desc.hasBlock);
mv.visitCode();

createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, hasBlock);

createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, desc.hasBlock);
mv.end();
}
}

0 comments on commit 4a34053

Please sign in to comment.