Skip to content

Commit 204feb2

Browse files
committed
shorter code, also working. pretty good improvement!
1 parent 2d1935c commit 204feb2

File tree

1 file changed

+8
-55
lines changed

1 file changed

+8
-55
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ private static class InteropInfo {
7474
}
7575
};
7676

77-
private int getInheritanceDepth(Class<?> klass) {
78-
if (klass.getName().equals("java.lang.Object")) {
79-
return 1;
80-
} else {
81-
return 1 + getInheritanceDepth(klass.getSuperclass());
82-
}
83-
}
84-
8577
/**
8678
* Override this to define per-class STables.
8779
*/
@@ -332,9 +324,6 @@ protected ClassContext createAdaptor(Class<?> target) {
332324
cc.cv = cw;
333325
cc.className = className;
334326
cc.target = target;
335-
cc.inheritanceHiding = new HashMap<String, HidingInformation>();
336-
337-
for (Method m : target.getMethods()) analyzeMethodHiding(cc, m);
338327

339328
for (Method m : target.getMethods()) createAdaptorMethod(cc, m);
340329
for (Field f : target.getFields()) createAdaptorField(cc, f);
@@ -347,32 +336,6 @@ protected ClassContext createAdaptor(Class<?> target) {
347336
return cc;
348337
}
349338

350-
protected void analyzeMethodHiding(ClassContext cc, Method m) {
351-
String desc = Type.getMethodDescriptor(m);
352-
String name = m.getName();
353-
354-
int s2 = desc.indexOf(')');
355-
String fragment = name + "/" + desc.substring(0, s2);
356-
357-
Integer derivationDepth = getInheritanceDepth(m.getDeclaringClass());
358-
359-
if (cc.inheritanceHiding.containsKey(fragment)) {
360-
HidingInformation info = cc.inheritanceHiding.get(fragment);
361-
362-
if (derivationDepth > info.inheritanceDepth) {
363-
info.inheritanceDepth = derivationDepth;
364-
info.mostSpecificSignature = desc;
365-
}
366-
} else {
367-
HidingInformation info = new HidingInformation();
368-
369-
info.inheritanceDepth = derivationDepth;
370-
info.mostSpecificSignature = desc;
371-
372-
cc.inheritanceHiding.put(fragment, info);
373-
}
374-
}
375-
376339
protected void createShorthandDispatchers(ClassContext c) {
377340
for (Iterator<Map.Entry<String, HashMap<Integer, List<String>>>> it = c.arities.entrySet().iterator(); it.hasNext();) {
378341
Map.Entry<String, HashMap<Integer, List<String>>> ent = it.next();
@@ -543,16 +506,16 @@ protected void createAdaptorMethod(ClassContext c, Method tobind) {
543506
String name = tobind.getName();
544507
Integer arity = ptype.length;
545508

546-
int returnPos = desc.indexOf(')');
547-
String fragment = name + "/" + desc.substring(0, returnPos);
548-
549-
if (c.inheritanceHiding.containsKey(fragment)) {
550-
if (!c.inheritanceHiding.get(fragment).equals(desc)) {
551-
// this method is actually hidden by a more derived class
552-
System.out.println("hiding the method " + name + " " + desc + " from the fragment " + fragment);
509+
try {
510+
if (!c.target.getMethod(name, ptype).equals(tobind)) {
511+
System.out.println("hiding the method " + name + " " + desc);
553512
return;
554513
}
555514
}
515+
catch (NoSuchMethodException ex) {
516+
System.err.println("WTF, the method " + name + " magically disappeared?!");
517+
return;
518+
}
556519

557520
if (!c.arities.containsKey(name)) {
558521
c.arities.put(name, new HashMap<Integer, List<String>>());
@@ -563,7 +526,7 @@ protected void createAdaptorMethod(ClassContext c, Method tobind) {
563526
c.arities.get(name).get(arity).add(desc);
564527
// stash the method away for later generation of shorthand methods.
565528
c.methods.put(name + "/" + desc, tobind);
566-
MethodContext cc = startCallout(c, arity + 1, "method/" + tobind.getName() + "/" + desc);
529+
MethodContext cc = startCallout(c, arity + 1, "method/" + name + "/" + desc);
567530

568531
int parix = 1;
569532
preMarshalIn(cc, tobind.getReturnType(), 0);
@@ -863,13 +826,6 @@ else if (what == ThreadContext.class) {
863826
/** Type name of {@link ThreadContext}. */
864827
protected static final Type TYPE_TC = Type.getType(ThreadContext.class);
865828

866-
/** Store information needed to figure out which methods are hidden */
867-
protected class HidingInformation {
868-
/** How far away from java.lang.object are we? */
869-
public Integer inheritanceDepth;
870-
/** Which signature has been the most derived version so far? */
871-
public String mostSpecificSignature;
872-
}
873829
/** Stores working information while building a class. */
874830
protected static class ClassContext {
875831
/** The ASM class writer. */
@@ -890,9 +846,6 @@ protected static class ClassContext {
890846
public HashMap<String, AccessibleObject> methods = new HashMap< >();
891847
/** The next qb_NNN index to use. */
892848
public int nextCallout;
893-
/** The signature of the method with the return type cut off points
894-
* to a record stating which specific override is the real one */
895-
public HashMap<String, HidingInformation> inheritanceHiding;
896849
}
897850

898851
/** Start an adaptor method and generate standard prologue. */

0 commit comments

Comments
 (0)