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: 38e32b003ce7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 96a38e8c080a
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 11, 2016

  1. can safe more allocations on type populate by delaying methods map al…

    …locations
    
    ... since most ext classes provide either instance xor static methods this is legit!
    kares committed Apr 11, 2016
    Copy the full SHA
    fbcc60d View commit details
  2. Copy the full SHA
    4d82ce2 View commit details
  3. Copy the full SHA
    96a38e8 View commit details
Showing with 24 additions and 24 deletions.
  1. +21 −20 core/src/main/java/org/jruby/RubyModule.java
  2. +3 −4 core/src/main/java/org/jruby/internal/runtime/methods/InvocationMethodFactory.java
41 changes: 21 additions & 20 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -884,25 +884,19 @@ public void defineAnnotatedMethod(Class clazz, String name) {
}
}

public void defineAnnotatedConstants(Class clazz) {
Field[] declaredFields = clazz.getDeclaredFields();
for (Field field : declaredFields) {
public final void defineAnnotatedConstants(Class clazz) {
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
defineAnnotatedConstant(field);
}
}
}

public boolean defineAnnotatedConstant(Field field) {
public final boolean defineAnnotatedConstant(Field field) {
JRubyConstant jrubyConstant = field.getAnnotation(JRubyConstant.class);

if (jrubyConstant == null) return false;

String[] names = jrubyConstant.value();
if(names.length == 0) {
names = new String[]{field.getName()};
}

Class tp = field.getType();
IRubyObject realVal;

@@ -918,9 +912,12 @@ public boolean defineAnnotatedConstant(Field field) {
realVal = getRuntime().getNil();
}


for(String name : names) {
this.setConstant(name, realVal);
String[] names = jrubyConstant.value();
if (names.length == 0) {
setConstant(field.getName(), realVal);
}
else {
for (String name : names) setConstant(name, realVal);
}

return true;
@@ -932,8 +929,8 @@ public void defineAnnotatedMethods(Class clazz) {
}

public static final class MethodClumper {
final HashMap<String, List<JavaMethodDescriptor>> annotatedMethods = new HashMap<>();
final HashMap<String, List<JavaMethodDescriptor>> staticAnnotatedMethods = new HashMap<>();
private HashMap<String, List<JavaMethodDescriptor>> annotatedMethods;
private HashMap<String, List<JavaMethodDescriptor>> staticAnnotatedMethods;
// final HashMap<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<>();

public void clump(final Class cls) {
@@ -953,9 +950,13 @@ public void clump(final Class cls) {
List<JavaMethodDescriptor> methodDescs;
Map<String, List<JavaMethodDescriptor>> methodsHash;
if (desc.isStatic) {
methodsHash = staticAnnotatedMethods;
if ( (methodsHash = staticAnnotatedMethods) == null ) {
methodsHash = staticAnnotatedMethods = new HashMap<>();
}
} else {
methodsHash = annotatedMethods;
if ( (methodsHash = annotatedMethods) == null ) {
methodsHash = annotatedMethods = new HashMap<>();
}
}

// add to specific
@@ -1003,12 +1004,12 @@ public Map<String, List<JavaMethodDescriptor>> getAllAnnotatedMethods() {
return null; // return allAnnotatedMethods;
}

public Map<String, List<JavaMethodDescriptor>> getAnnotatedMethods() {
return annotatedMethods;
public final Map<String, List<JavaMethodDescriptor>> getAnnotatedMethods() {
return annotatedMethods == null ? Collections.EMPTY_MAP : annotatedMethods;
}

public Map<String, List<JavaMethodDescriptor>> getStaticAnnotatedMethods() {
return staticAnnotatedMethods;
public final Map<String, List<JavaMethodDescriptor>> getStaticAnnotatedMethods() {
return staticAnnotatedMethods == null ? Collections.EMPTY_MAP : staticAnnotatedMethods;
}
}

Original file line number Diff line number Diff line change
@@ -350,9 +350,6 @@ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMeth
* @param method The code generator for the handle being created
*/
private static void checkArity(JRubyMethod jrubyMethod, SkinnyMethodAdapter method, int specificArity) {
Label arityError = new Label();
Label noArityError = new Label();

switch (specificArity) {
case 0:
case 1:
@@ -361,6 +358,8 @@ private static void checkArity(JRubyMethod jrubyMethod, SkinnyMethodAdapter meth
// for zero, one, two, three arities, JavaMethod.JavaMethod*.call(...IRubyObject[] args...) will check
return;
default:
final Label arityError = new Label();
final Label noArityError = new Label();
boolean checkArity = false;
if (jrubyMethod.rest()) {
if (jrubyMethod.required() > 0) {
@@ -692,7 +691,7 @@ private void addAnnotatedMethodInvoker(ClassWriter cw, String callName, String s
}

boolean hasBlock = desc.hasBlock;
SkinnyMethodAdapter mv = null;
SkinnyMethodAdapter mv;

mv = beginMethod(cw, callName, specificArity, hasBlock);
mv.visitCode();