diff options
| author | 2019-05-18 11:13:24 +0200 | |
|---|---|---|
| committer | 2019-05-18 11:13:24 +0200 | |
| commit | 463aee1dfc1222e8f6f0312aa46fb9b9dcfa13a1 (patch) | |
| tree | 2f2503cabe79145799db5f5e63ee272cf695b72f /src/main/java/cuchaz/enigma/analysis | |
| parent | Feature/weave (#138) (diff) | |
| download | enigma-fork-463aee1dfc1222e8f6f0312aa46fb9b9dcfa13a1.tar.gz enigma-fork-463aee1dfc1222e8f6f0312aa46fb9b9dcfa13a1.tar.xz enigma-fork-463aee1dfc1222e8f6f0312aa46fb9b9dcfa13a1.zip | |
Method type reference corrections (#142)
* Add more specific returns for translatables
* Only index method descriptors for implemented methods and methods in generated lambda classes
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis')
4 files changed, 60 insertions, 31 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java b/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java index ba5d3b6..b730a8a 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java | |||
| @@ -1,16 +1,11 @@ | |||
| 1 | package cuchaz.enigma.analysis.index; | 1 | package cuchaz.enigma.analysis.index; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.translation.representation.AccessFlags; | 3 | import cuchaz.enigma.translation.representation.AccessFlags; |
| 4 | import cuchaz.enigma.translation.representation.Lambda; | ||
| 4 | import cuchaz.enigma.translation.representation.MethodDescriptor; | 5 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| 5 | import cuchaz.enigma.translation.representation.Signature; | 6 | import cuchaz.enigma.translation.representation.Signature; |
| 6 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 7 | import cuchaz.enigma.translation.representation.entry.*; |
| 7 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | 8 | import org.objectweb.asm.*; |
| 8 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | ||
| 9 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 10 | import org.objectweb.asm.ClassVisitor; | ||
| 11 | import org.objectweb.asm.Handle; | ||
| 12 | import org.objectweb.asm.MethodVisitor; | ||
| 13 | import org.objectweb.asm.Opcodes; | ||
| 14 | 9 | ||
| 15 | public class IndexReferenceVisitor extends ClassVisitor { | 10 | public class IndexReferenceVisitor extends ClassVisitor { |
| 16 | private final JarIndexer indexer; | 11 | private final JarIndexer indexer; |
| @@ -54,29 +49,37 @@ public class IndexReferenceVisitor extends ClassVisitor { | |||
| 54 | this.indexer.indexMethodReference(callerEntry, methodEntry); | 49 | this.indexer.indexMethodReference(callerEntry, methodEntry); |
| 55 | } | 50 | } |
| 56 | 51 | ||
| 52 | private static ParentedEntry<?> getHandleEntry(Handle handle) { | ||
| 53 | switch (handle.getTag()) { | ||
| 54 | case Opcodes.H_GETFIELD: | ||
| 55 | case Opcodes.H_GETSTATIC: | ||
| 56 | case Opcodes.H_PUTFIELD: | ||
| 57 | case Opcodes.H_PUTSTATIC: | ||
| 58 | return FieldEntry.parse(handle.getOwner(), handle.getName(), handle.getDesc()); | ||
| 59 | case Opcodes.H_INVOKEINTERFACE: | ||
| 60 | case Opcodes.H_INVOKESPECIAL: | ||
| 61 | case Opcodes.H_INVOKESTATIC: | ||
| 62 | case Opcodes.H_INVOKEVIRTUAL: | ||
| 63 | case Opcodes.H_NEWINVOKESPECIAL: | ||
| 64 | return MethodEntry.parse(handle.getOwner(), handle.getName(), handle.getDesc()); | ||
| 65 | } | ||
| 66 | throw new RuntimeException("Invalid handle tag " + handle.getTag()); | ||
| 67 | } | ||
| 68 | |||
| 57 | @Override | 69 | @Override |
| 58 | public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { | 70 | public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { |
| 59 | for (Object bsmArg : bsmArgs) { | 71 | if ("java/lang/invoke/LambdaMetafactory".equals(bsm.getOwner()) && "metafactory".equals(bsm.getName())) { |
| 60 | if (bsmArg instanceof Handle) { | 72 | Type samMethodType = (Type) bsmArgs[0]; |
| 61 | Handle handle = (Handle) bsmArg; | 73 | Handle implMethod = (Handle) bsmArgs[1]; |
| 62 | switch (handle.getTag()) { | 74 | Type instantiatedMethodType = (Type) bsmArgs[2]; |
| 63 | case Opcodes.H_GETFIELD: | 75 | |
| 64 | case Opcodes.H_GETSTATIC: | 76 | this.indexer.indexLambda(callerEntry, new Lambda( |
| 65 | case Opcodes.H_PUTFIELD: | 77 | name, |
| 66 | case Opcodes.H_PUTSTATIC: | 78 | new MethodDescriptor(desc), |
| 67 | FieldEntry fieldEntry = FieldEntry.parse(handle.getOwner(), handle.getName(), handle.getDesc()); | 79 | new MethodDescriptor(samMethodType.getDescriptor()), |
| 68 | this.indexer.indexFieldReference(callerEntry, fieldEntry); | 80 | getHandleEntry(implMethod), |
| 69 | break; | 81 | new MethodDescriptor(instantiatedMethodType.getDescriptor()) |
| 70 | case Opcodes.H_INVOKEINTERFACE: | 82 | )); |
| 71 | case Opcodes.H_INVOKESPECIAL: | ||
| 72 | case Opcodes.H_INVOKESTATIC: | ||
| 73 | case Opcodes.H_INVOKEVIRTUAL: | ||
| 74 | case Opcodes.H_NEWINVOKESPECIAL: | ||
| 75 | MethodEntry methodEntry = MethodEntry.parse(handle.getOwner(), handle.getName(), handle.getDesc()); | ||
| 76 | this.indexer.indexMethodReference(callerEntry, methodEntry); | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | 83 | } |
| 81 | } | 84 | } |
| 82 | } | 85 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java b/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java index ac907af..fd4e618 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java | |||
| @@ -16,6 +16,7 @@ import com.google.common.collect.Multimap; | |||
| 16 | import cuchaz.enigma.analysis.ParsedJar; | 16 | import cuchaz.enigma.analysis.ParsedJar; |
| 17 | import cuchaz.enigma.translation.mapping.EntryResolver; | 17 | import cuchaz.enigma.translation.mapping.EntryResolver; |
| 18 | import cuchaz.enigma.translation.mapping.IndexEntryResolver; | 18 | import cuchaz.enigma.translation.mapping.IndexEntryResolver; |
| 19 | import cuchaz.enigma.translation.representation.Lambda; | ||
| 19 | import cuchaz.enigma.translation.representation.entry.*; | 20 | import cuchaz.enigma.translation.representation.entry.*; |
| 20 | import org.objectweb.asm.ClassReader; | 21 | import org.objectweb.asm.ClassReader; |
| 21 | import org.objectweb.asm.Opcodes; | 22 | import org.objectweb.asm.Opcodes; |
| @@ -129,6 +130,15 @@ public class JarIndex implements JarIndexer { | |||
| 129 | indexers.forEach(indexer -> indexer.indexFieldReference(callerEntry, referencedEntry)); | 130 | indexers.forEach(indexer -> indexer.indexFieldReference(callerEntry, referencedEntry)); |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 133 | @Override | ||
| 134 | public void indexLambda(MethodDefEntry callerEntry, Lambda lambda) { | ||
| 135 | if (callerEntry.getParent().isJre()) { | ||
| 136 | return; | ||
| 137 | } | ||
| 138 | |||
| 139 | indexers.forEach(indexer -> indexer.indexLambda(callerEntry, lambda)); | ||
| 140 | } | ||
| 141 | |||
| 132 | public EntryIndex getEntryIndex() { | 142 | public EntryIndex getEntryIndex() { |
| 133 | return entryIndex; | 143 | return entryIndex; |
| 134 | } | 144 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/index/JarIndexer.java b/src/main/java/cuchaz/enigma/analysis/index/JarIndexer.java index 457c223..4f885b3 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/JarIndexer.java +++ b/src/main/java/cuchaz/enigma/analysis/index/JarIndexer.java | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | package cuchaz.enigma.analysis.index; | 1 | package cuchaz.enigma.analysis.index; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.translation.representation.Lambda; | ||
| 3 | import cuchaz.enigma.translation.representation.entry.*; | 4 | import cuchaz.enigma.translation.representation.entry.*; |
| 4 | 5 | ||
| 5 | public interface JarIndexer { | 6 | public interface JarIndexer { |
| @@ -18,6 +19,9 @@ public interface JarIndexer { | |||
| 18 | default void indexFieldReference(MethodDefEntry callerEntry, FieldEntry referencedEntry) { | 19 | default void indexFieldReference(MethodDefEntry callerEntry, FieldEntry referencedEntry) { |
| 19 | } | 20 | } |
| 20 | 21 | ||
| 22 | default void indexLambda(MethodDefEntry callerEntry, Lambda lambda) { | ||
| 23 | } | ||
| 24 | |||
| 21 | default void processIndex(JarIndex index) { | 25 | default void processIndex(JarIndex index) { |
| 22 | } | 26 | } |
| 23 | } | 27 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java b/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java index 04306bd..f54c90d 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java | |||
| @@ -4,6 +4,7 @@ import com.google.common.collect.HashMultimap; | |||
| 4 | import com.google.common.collect.Multimap; | 4 | import com.google.common.collect.Multimap; |
| 5 | import cuchaz.enigma.analysis.EntryReference; | 5 | import cuchaz.enigma.analysis.EntryReference; |
| 6 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | 6 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; |
| 7 | import cuchaz.enigma.translation.representation.Lambda; | ||
| 7 | import cuchaz.enigma.translation.representation.MethodDescriptor; | 8 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| 8 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 9 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 9 | import cuchaz.enigma.translation.representation.entry.*; | 10 | import cuchaz.enigma.translation.representation.entry.*; |
| @@ -64,8 +65,6 @@ public class ReferenceIndex implements JarIndexer { | |||
| 64 | ClassEntry referencedClass = referencedEntry.getParent(); | 65 | ClassEntry referencedClass = referencedEntry.getParent(); |
| 65 | referencesToClasses.put(referencedClass, new EntryReference<>(referencedClass, referencedEntry.getName(), callerEntry)); | 66 | referencesToClasses.put(referencedClass, new EntryReference<>(referencedClass, referencedEntry.getName(), callerEntry)); |
| 66 | } | 67 | } |
| 67 | |||
| 68 | indexMethodDescriptor(callerEntry, referencedEntry.getDesc()); | ||
| 69 | } | 68 | } |
| 70 | 69 | ||
| 71 | @Override | 70 | @Override |
| @@ -74,6 +73,19 @@ public class ReferenceIndex implements JarIndexer { | |||
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | @Override | 75 | @Override |
| 76 | public void indexLambda(MethodDefEntry callerEntry, Lambda lambda) { | ||
| 77 | if (lambda.getImplMethod() instanceof MethodEntry) { | ||
| 78 | indexMethodReference(callerEntry, (MethodEntry) lambda.getImplMethod()); | ||
| 79 | } else { | ||
| 80 | indexFieldReference(callerEntry, (FieldEntry) lambda.getImplMethod()); | ||
| 81 | } | ||
| 82 | |||
| 83 | indexMethodDescriptor(callerEntry, lambda.getInvokedType()); | ||
| 84 | indexMethodDescriptor(callerEntry, lambda.getSamMethodType()); | ||
| 85 | indexMethodDescriptor(callerEntry, lambda.getInstantiatedMethodType()); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Override | ||
| 77 | public void processIndex(JarIndex index) { | 89 | public void processIndex(JarIndex index) { |
| 78 | methodReferences = remapReferences(index, methodReferences); | 90 | methodReferences = remapReferences(index, methodReferences); |
| 79 | referencesToMethods = remapReferencesTo(index, referencesToMethods); | 91 | referencesToMethods = remapReferencesTo(index, referencesToMethods); |