Skip to content

Commit

Permalink
#376 Implement more efficient Class Hierarchy Analysis for method de-…
Browse files Browse the repository at this point in the history
…virtualization
  • Loading branch information
mirkosertic committed Apr 12, 2020
1 parent d341863 commit c77b2cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,20 @@ public String methodHandleDelegateFor(final MethodHandleExpression e) {
theWriter.tab().text("};").newLine();
}

if (aEntry.getProvidingClass().getClassName().equals(BytecodeObjectTypeRef.fromRuntimeClass(Class.class))
&& theMethod.getName().stringValue().equals("getClassLoader")
&& theMethod.getSignature().matchesExactlyTo(BytecodeLinkedClass.GET_CLASSLOADER_SIGNATURE)) {

// Special method: we resolve a runtime class by name here
theWriter.tab().text("C.");

final String theJSMethodName = theMinifier.toMethodName(theMethod.getName().stringValue(), theCurrentMethodSignature);

theWriter.text(theJSMethodName).assign().text("function()").space().text("{").newLine();
theWriter.tab(2).text("return null;").newLine();
theWriter.tab().text("};").newLine();
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import de.mirkosertic.bytecoder.core.BytecodeTypeRef;
import de.mirkosertic.bytecoder.graph.Edge;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class ClassHierarchyAnalysis {

Expand All @@ -49,17 +50,26 @@ public List<BytecodeLinkedClass> classesProvidingInvocableMethod(final String aM
theInvocationTarget = linkerContext.resolveClass((BytecodeObjectTypeRef) aInvocationTarget);
}

return linkerContext.linkedClasses()
final Set<BytecodeLinkedClass> theResult = new HashSet<>();
linkerContext.linkedClasses()
.map(Edge::targetNode)
.filter(aClassFilter)
.filter(t -> {
final Set<BytecodeLinkedClass> theImplementingTypes = t.getImplementingTypes();
return theImplementingTypes.contains(theInvocationTarget);
})
.filter(t -> {
final BytecodeMethod m = t.getBytecodeClass().methodByNameAndSignatureOrNull(aMethodName, aSignature);
return m != null && aMethodFilter.test(m);
})
.collect(Collectors.toList());
.forEach(clz -> {
BytecodeLinkedClass theCurrent = clz;
test: while(theCurrent != null) {
final BytecodeMethod m = theCurrent.getBytecodeClass().methodByNameAndSignatureOrNull(aMethodName, aSignature);
if (m != null && aMethodFilter.test(m)) {
theResult.add(theCurrent);
break test;
}
theCurrent = theCurrent.getSuperClass();
}
});

return new ArrayList<>(theResult);
}
}

0 comments on commit c77b2cd

Please sign in to comment.