From de8f07e247e44f7235495be14641185f6720ef57 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 12 May 2024 22:52:42 -0500 Subject: [PATCH] fix Indy arg calls to modify. --- .../downgradetest/TestException.java | 8 +++ .../jvmdg/coverage/ApiCoverageChecker.java | 2 +- .../j10/stub/java_base/J_I_PrintWriter.java | 2 +- .../jvmdg/j10/stub/java_base/J_U_Scanner.java | 12 +--- .../java_base/J_U_NoSuchElementException.java | 7 +-- .../J_L_IndexOutOfBoundsException.java | 2 +- .../stub/java_base/J_L_R_ObjectMethods.java | 6 +- .../java_base/J_I_InvalidClassException.java | 4 +- .../java_base/J_I_InvalidObjectException.java | 2 +- .../java_base/J_I_ObjectStreamException.java | 4 +- .../J_N_S_SSLHandshakeException.java | 2 +- .../stub/java_base/J_N_S_SSLKeyException.java | 2 +- .../stub/java_base/J_N_SocketException.java | 4 +- .../J_S_InvalidParameterException.java | 4 +- .../java_base/J_L_I_StringConcatFactory.java | 2 +- .../J_L_IndexOutOfBoundsException.java | 2 +- .../jvmdg/j9/stub/java_base/J_L_Thread.java | 5 +- .../j9/stub/java_base/J_M_BigInteger.java | 4 +- .../jvmdg/providers/Java11Downgrader.java | 10 +-- .../jvmdg/providers/Java16Downgrader.java | 2 +- .../jvmdg/providers/Java17Downgrader.java | 2 +- .../java/xyz/wagyourtail/jvmdg/Constants.java | 5 -- .../xyz/wagyourtail/jvmdg/asm/ASMUtils.java | 5 ++ .../jvmdg/compile/shade/ReferenceGraph.java | 12 ++-- .../jvmdg/version/VersionProvider.java | 62 ++++++++++++++++++- .../jvmdg/version/map/ClassMapping.java | 36 ++++++++++- .../map/FullyQualifiedMemberNameAndDesc.java | 9 ++- 27 files changed, 154 insertions(+), 63 deletions(-) diff --git a/downgradetest/src/main/java/xyz/wagyourtail/downgradetest/TestException.java b/downgradetest/src/main/java/xyz/wagyourtail/downgradetest/TestException.java index d509a898..fe9e358a 100644 --- a/downgradetest/src/main/java/xyz/wagyourtail/downgradetest/TestException.java +++ b/downgradetest/src/main/java/xyz/wagyourtail/downgradetest/TestException.java @@ -1,5 +1,8 @@ package xyz.wagyourtail.downgradetest; +import java.util.function.Function; +import java.util.function.Supplier; + public class TestException { public static void main(String[] args) { @@ -20,12 +23,17 @@ public static void main(String[] args) { } new InternalError("test", new IndexOutOfBoundsException(1L)); + + Function IOOBE = IndexOutOfBoundsException::new; + IOOBE.apply(0L); + try { throw new InternalError("test", new IndexOutOfBoundsException(1L)); } catch (InternalError e) { System.out.println(e); } + } } diff --git a/java-api/src/coverage/java/xyz/wagyourtail/jvmdg/coverage/ApiCoverageChecker.java b/java-api/src/coverage/java/xyz/wagyourtail/jvmdg/coverage/ApiCoverageChecker.java index 9ee06359..df3146cf 100644 --- a/java-api/src/coverage/java/xyz/wagyourtail/jvmdg/coverage/ApiCoverageChecker.java +++ b/java-api/src/coverage/java/xyz/wagyourtail/jvmdg/coverage/ApiCoverageChecker.java @@ -219,7 +219,7 @@ public static void main(String[] args) throws IOException, URISyntaxException { } if (!unmatchedStubs.isEmpty()) { var unmatched = Path.of("./coverage/" + stubVersion + "/unmatched.txt"); - writeList(unmatchedStubs.stream().map(methodStubPair -> new MemberInfo("unknown", FullyQualifiedMemberNameAndDesc.fromMethod(methodStubPair), false, false)).collect(Collectors.toList()), unmatched); + writeList(unmatchedStubs.stream().map(methodStubPair -> new MemberInfo("unknown", FullyQualifiedMemberNameAndDesc.of(methodStubPair), false, false)).collect(Collectors.toList()), unmatched); } } catch (IOException e) { diff --git a/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_I_PrintWriter.java b/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_I_PrintWriter.java index 27d7bd06..e0d6b1a8 100644 --- a/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_I_PrintWriter.java +++ b/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_I_PrintWriter.java @@ -10,7 +10,7 @@ public class J_I_PrintWriter { @Modify(ref = @Ref(value = "Ljava/io/PrintWriter;", member = "", desc = "(Ljava/io/OutputStream;ZLjava/nio/charset/Charset;)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: PrintWriter, OutputStream, boolean, Charset list.add(new InsnNode(Opcodes.DUP2_X1)); diff --git a/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_U_Scanner.java b/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_U_Scanner.java index f4cb9f05..4884f775 100644 --- a/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_U_Scanner.java +++ b/java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_U_Scanner.java @@ -6,22 +6,12 @@ import org.objectweb.asm.tree.*; import xyz.wagyourtail.jvmdg.version.Modify; import xyz.wagyourtail.jvmdg.version.Ref; -import xyz.wagyourtail.jvmdg.version.Stub; - -import java.nio.channels.ReadableByteChannel; -import java.nio.charset.Charset; -import java.util.Scanner; public class J_U_Scanner { -// @Stub(ref = @Ref(value = "Ljava/util/Scanner;", member = "")) -// public static Scanner init(ReadableByteChannel source, Charset charset) { -// return new Scanner(source, charset.name()); -// } - @Modify(ref = @Ref(value = "Ljava/util/Scanner;", member = "", desc = "(Ljava/nio/channels/ReadableByteChannel;Ljava/nio/charset/Charset;)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: Scanner, ReadableByteChannel, Charset // call:J_N_C_Channels.newReader(ReadableByteChannel, Charset) diff --git a/java-api/src/java15/java/xyz/wagyourtail/jvmdg/j15/stub/java_base/J_U_NoSuchElementException.java b/java-api/src/java15/java/xyz/wagyourtail/jvmdg/j15/stub/java_base/J_U_NoSuchElementException.java index 3e07fc2e..bb0dc734 100644 --- a/java-api/src/java15/java/xyz/wagyourtail/jvmdg/j15/stub/java_base/J_U_NoSuchElementException.java +++ b/java-api/src/java15/java/xyz/wagyourtail/jvmdg/j15/stub/java_base/J_U_NoSuchElementException.java @@ -5,15 +5,12 @@ import org.objectweb.asm.tree.*; import xyz.wagyourtail.jvmdg.version.Modify; import xyz.wagyourtail.jvmdg.version.Ref; -import xyz.wagyourtail.jvmdg.version.Stub; - -import java.util.NoSuchElementException; public class J_U_NoSuchElementException { @Modify(ref = @Ref(value = "Ljava/util/NoSuchElementException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: NoSuchElementException, String, Throwable list.add(new InsnNode(Opcodes.DUP_X2)); @@ -40,7 +37,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "java/util/NoSuchElementException", member = "", desc = "(Ljava/lang/Throwable;)V")) public static void init2(MethodNode mNode, int i) { - AbstractInsnNode node = mNode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mNode.instructions.get(i); InsnList list = new InsnList(); // stack: NoSuchElementException, Throwable list.add(new InsnNode(Opcodes.DUP2)); diff --git a/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_IndexOutOfBoundsException.java b/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_IndexOutOfBoundsException.java index 1187d027..8dcb32ac 100644 --- a/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_IndexOutOfBoundsException.java +++ b/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_IndexOutOfBoundsException.java @@ -12,7 +12,7 @@ public class J_L_IndexOutOfBoundsException { @Modify(ref = @Ref(value = "java/lang/IndexOutOfBoundsException", member = "", desc = "(J)V")) public static void init(MethodNode mNode, int i) { - AbstractInsnNode node = mNode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mNode.instructions.get(i); InsnList list = new InsnList(); // string concat factory, "Index out of range: \u0001" list.add(new InvokeDynamicInsnNode( diff --git a/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_R_ObjectMethods.java b/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_R_ObjectMethods.java index c3085ab9..d0ede7a9 100644 --- a/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_R_ObjectMethods.java +++ b/java-api/src/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_R_ObjectMethods.java @@ -46,7 +46,7 @@ public static void bootstrap(MethodNode mnode, int i, ClassNode cnode) { } private static void makeEquals(ClassNode cnode, String mname, String desc, Type recordClass, ArrayList getters) { - var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null); + var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null); visitor.visitCode(); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 1); @@ -117,7 +117,7 @@ private static void makeEquals(ClassNode cnode, String mname, String desc, Type } private static void makeHashCode(ClassNode cnode, String mname, String desc, Type recordClass, ArrayList getters) { - var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null); + var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null); visitor.visitCode(); visitor.visitLdcInsn(getters.size()); visitor.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); @@ -224,7 +224,7 @@ private static void makeHashCode(ClassNode cnode, String mname, String desc, Typ } private static void makeToString(ClassNode cnode, String mname, String desc, Type recordClass, String fieldNames, List getters) { - var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null); + var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null); visitor.visitCode(); visitor.visitVarInsn(Opcodes.ALOAD, 0); String last = recordClass.getInternalName(); diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidClassException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidClassException.java index e909c0d5..f28a0db0 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidClassException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidClassException.java @@ -9,7 +9,7 @@ public class J_I_InvalidClassException { @Modify(ref = @Ref(value = "Ljava/io/InvalidClassException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: InvalidClassException, String (cname), String (reason), Throwable list.add(new InsnNode(Opcodes.DUP2_X2)); @@ -51,7 +51,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "Ljava/io/InvalidClassException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init2(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: InvalidClassException, String (reason), Throwable list.add(new InsnNode(Opcodes.DUP_X2)); diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidObjectException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidObjectException.java index 6b08cf76..cfe7abfc 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidObjectException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_InvalidObjectException.java @@ -9,7 +9,7 @@ public class J_I_InvalidObjectException { @Modify(ref = @Ref(value = "Ljava/io/InvalidObjectException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: InvalidObjectException, String, Throwable list.add(new InsnNode(Opcodes.DUP_X2)); diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_ObjectStreamException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_ObjectStreamException.java index a27ef8c2..e7a46837 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_ObjectStreamException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_I_ObjectStreamException.java @@ -9,7 +9,7 @@ public class J_I_ObjectStreamException { @Modify(ref = @Ref(value = "Ljava/io/ObjectStreamException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: ObjectStreamException, String, Throwable list.add(new InsnNode(Opcodes.DUP_X2)); @@ -36,7 +36,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "Ljava/io/ObjectStreamException;", member = "", desc = "(Ljava/lang/Throwable;)V;")) public static void init2(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: ObjectStreamException, Throwable list.add(new InsnNode(Opcodes.DUP2)); diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLHandshakeException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLHandshakeException.java index 671c9476..af220515 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLHandshakeException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLHandshakeException.java @@ -9,7 +9,7 @@ public class J_N_S_SSLHandshakeException { @Modify(ref = @Ref(value = "Ljavax/net/ssl/SSLHandshakeException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: SSLHandshakeException, String (reason), Throwable diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLKeyException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLKeyException.java index 50c9ad3d..90bc19ab 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLKeyException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_S_SSLKeyException.java @@ -9,7 +9,7 @@ public class J_N_S_SSLKeyException { @Modify(ref = @Ref(value = "Ljavax/net/ssl/SSLKeyException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: SSLKeyException, String (reason), Throwable diff --git a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_SocketException.java b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_SocketException.java index 84bf872e..9647afb5 100644 --- a/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_SocketException.java +++ b/java-api/src/java19/java/xyz/wagyourtail/jvmdg/j19/stub/java_base/J_N_SocketException.java @@ -9,7 +9,7 @@ public class J_N_SocketException { @Modify(ref = @Ref(value = "Ljava/net/SocketException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: SocketException, String, Throwable list.add(new InsnNode(Opcodes.DUP_X2)); @@ -36,7 +36,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "Ljava/net/SocketException;", member = "", desc = "(Ljava/lang/Throwable;)V;")) public static void init2(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: SocketException, Throwable list.add(new InsnNode(Opcodes.DUP2)); diff --git a/java-api/src/java20/java/xyz/wagyourtail/jvmdg/j20/stub/java_base/J_S_InvalidParameterException.java b/java-api/src/java20/java/xyz/wagyourtail/jvmdg/j20/stub/java_base/J_S_InvalidParameterException.java index 34ada3ed..412693b5 100644 --- a/java-api/src/java20/java/xyz/wagyourtail/jvmdg/j20/stub/java_base/J_S_InvalidParameterException.java +++ b/java-api/src/java20/java/xyz/wagyourtail/jvmdg/j20/stub/java_base/J_S_InvalidParameterException.java @@ -9,7 +9,7 @@ public class J_S_InvalidParameterException { @Modify(ref = @Ref(value = "Ljava/security/InvalidParameterException;", member = "", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: InvalidParameterException, String, Throwable list.add(new InsnNode(Opcodes.DUP_X2)); @@ -34,7 +34,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "Ljava/security/InvalidParameterException;", member = "", desc = "(Ljava/lang/Throwable;)V;")) public static void init1(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: InvalidParameterException, Throwable list.add(new InsnNode(Opcodes.DUP_X1)); diff --git a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_I_StringConcatFactory.java b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_I_StringConcatFactory.java index ab490227..03d93e0a 100644 --- a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_I_StringConcatFactory.java +++ b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_I_StringConcatFactory.java @@ -496,7 +496,7 @@ public StringConcatMethodNode(String args, Deque types, int index) { if (index > 0) { this.name += index; } - this.access = Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC); + this.access = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC; this.desc = Type.getMethodDescriptor(Type.getType(String.class), types.toArray(new Type[0])); init(args, types); } diff --git a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IndexOutOfBoundsException.java b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IndexOutOfBoundsException.java index b8a40525..6e9e94ca 100644 --- a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IndexOutOfBoundsException.java +++ b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IndexOutOfBoundsException.java @@ -11,7 +11,7 @@ public class J_L_IndexOutOfBoundsException { @Modify(ref = @Ref(value = "java/lang/IndexOutOfBoundsException", member = "", desc = "(I)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: IndexOutOfBoundsException, int diff --git a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Thread.java b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Thread.java index 71d70ebf..cc5ed148 100644 --- a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Thread.java +++ b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Thread.java @@ -18,6 +18,7 @@ public class J_L_Thread { private static final ThreadLocal old = new ThreadLocal<>(); + private static final MethodHandles.Lookup impl_lookup = Utils.getImplLookup(); @Stub(ref = @Ref("Ljava/lang/Thread;")) public static void onSpinWait() { @@ -26,7 +27,7 @@ public static void onSpinWait() { @Modify(ref = @Ref(value = "java/lang/Thread", member = "", desc = "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;JZ)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: Thread, ThreadGroup, Runnable, String, long, boolean @@ -46,7 +47,6 @@ public static void preInit(boolean inheritThreadLocals) { if (!inheritThreadLocals) { Thread current = Thread.currentThread(); try { - MethodHandles.Lookup impl_lookup = Utils.getImplLookup(); Class map = Class.forName("java.lang.ThreadLocal$ThreadLocalMap"); MethodHandle setter = impl_lookup.findSetter(Thread.class, "inheritableThreadLocals", map); MethodHandle getter = impl_lookup.findGetter(Thread.class, "inheritableThreadLocals", map); @@ -65,7 +65,6 @@ public static void postInit() { if (o != null) { Thread current = Thread.currentThread(); try { - MethodHandles.Lookup impl_lookup = Utils.getImplLookup(); Class map = Class.forName("java.lang.ThreadLocal$ThreadLocalMap"); MethodHandle setter = impl_lookup.findSetter(Thread.class, "inheritableThreadLocals", map); setter.invoke(current, o); diff --git a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_M_BigInteger.java b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_M_BigInteger.java index 6f2bd2e4..308effc4 100644 --- a/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_M_BigInteger.java +++ b/java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_M_BigInteger.java @@ -20,7 +20,7 @@ public class J_M_BigInteger { @Modify(ref = @Ref(value = "Ljava/math/BigInteger;", member = "", desc = "([BII)V")) public static void init(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: BigInteger, byte[], (start) int, (len) int @@ -42,7 +42,7 @@ public static void init(MethodNode mnode, int i) { @Modify(ref = @Ref(value = "Ljava/math/BigInteger;", member = "", desc = "(I[BII)V")) public static void init2(MethodNode mnode, int i) { - AbstractInsnNode node = mnode.instructions.get(i); + MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); InsnList list = new InsnList(); // stack: BigInteger, int, byte[], (start) int, (len) int diff --git a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java11Downgrader.java b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java11Downgrader.java index ab27e5a3..aa30ffdf 100644 --- a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java11Downgrader.java +++ b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java11Downgrader.java @@ -395,7 +395,7 @@ private void createAccessors(ClassNode clazz, Map fields) { } else { // create new package-private method to call private method - MethodVisitor mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$" + name, desc, null, null); + MethodVisitor mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$" + name, desc, null, null); mv.visitCode(); if (!isStatic) { mv.visitVarInsn(Opcodes.ALOAD, 0); @@ -430,7 +430,7 @@ private void createAccessors(ClassNode clazz, Map fields) { } // create new package-private method to get field - MethodVisitor mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$get$" + field, "()" + desc, null, null); + MethodVisitor mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$get$" + field, "()" + desc, null, null); mv.visitCode(); if (!isStatic) { mv.visitVarInsn(Opcodes.ALOAD, 0); @@ -440,7 +440,7 @@ private void createAccessors(ClassNode clazz, Map fields) { mv.visitEnd(); // create new package-private method to set field - mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$set$" + field, "(" + desc + ")V", null, null); + mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$set$" + field, "(" + desc + ")V", null, null); mv.visitCode(); if (!isStatic) { mv.visitVarInsn(Opcodes.ALOAD, 0); @@ -467,7 +467,7 @@ public void fixNestsForParent(ClassNode clazz, Function getRe sb.deleteCharAt(sb.length() - 1); clazz.visitField( - Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL), + Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "jvmdowngrader$nestMembers", "Ljava/lang/String;", null, @@ -494,7 +494,7 @@ public void fixNestsForChild(ClassNode clazz, Function getRea // create nest members synthetic class clazz.visitField( - Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL), + Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "jvmdowngrader$nestHost", "Ljava/lang/String;", null, diff --git a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java16Downgrader.java b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java16Downgrader.java index 99d94d8d..a6592cd8 100644 --- a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java16Downgrader.java +++ b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java16Downgrader.java @@ -104,7 +104,7 @@ public void recordRemover(ClassNode node) { // value.deleteCharAt(value.length() - 1); // node.recordComponents = null; // node.visitField( -// Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL), +// Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, // "jvmdowngrader$recordComponents", // "Ljava/lang/String;", // null, diff --git a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java17Downgrader.java b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java17Downgrader.java index 6fda1858..1281b877 100644 --- a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java17Downgrader.java +++ b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java17Downgrader.java @@ -91,7 +91,7 @@ public void unseal(ClassNode node) { sb.deleteCharAt(sb.length() - 1); node.permittedSubclasses = null; node.visitField( - Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL), + Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "jvmdowngrader$permittedSubclasses", "Ljava/lang/String;", null, diff --git a/src/main/java/xyz/wagyourtail/jvmdg/Constants.java b/src/main/java/xyz/wagyourtail/jvmdg/Constants.java index f47db7f1..1a3e146d 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/Constants.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/Constants.java @@ -12,9 +12,4 @@ public class Constants { public static final File DIR = new File(".jvmdg"); public static final File DEBUG_DIR = new File(DIR, "debug"); - - public static int synthetic(int access) { - if (DEBUG) return access; - return access | Opcodes.ACC_SYNTHETIC; - } } diff --git a/src/main/java/xyz/wagyourtail/jvmdg/asm/ASMUtils.java b/src/main/java/xyz/wagyourtail/jvmdg/asm/ASMUtils.java index 522b5134..dfd58c58 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/asm/ASMUtils.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/asm/ASMUtils.java @@ -1,7 +1,12 @@ package xyz.wagyourtail.jvmdg.asm; import org.objectweb.asm.ClassReader; +import org.objectweb.asm.Handle; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InvokeDynamicInsnNode; +import xyz.wagyourtail.jvmdg.version.map.FullyQualifiedMemberNameAndDesc; public class ASMUtils { diff --git a/src/main/java/xyz/wagyourtail/jvmdg/compile/shade/ReferenceGraph.java b/src/main/java/xyz/wagyourtail/jvmdg/compile/shade/ReferenceGraph.java index 539c39f7..1caf16ce 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/compile/shade/ReferenceGraph.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/compile/shade/ReferenceGraph.java @@ -86,7 +86,7 @@ public Set getAllRefs() { Set refs = new HashSet<>(); for (References value : references.values()) { for (Type requiredInstance : value.requiredInstances) { - refs.add(FullyQualifiedMemberNameAndDesc.ofType(requiredInstance)); + refs.add(FullyQualifiedMemberNameAndDesc.of(requiredInstance)); } for (List requiredForMembers : value.requiredForMembers.values()) { refs.addAll(requiredForMembers); @@ -111,7 +111,7 @@ public Pair, Set> recursiveResolveF } } for (Type t : refer.requiredInstances) { - FullyQualifiedMemberNameAndDesc f = FullyQualifiedMemberNameAndDesc.ofType(t); + FullyQualifiedMemberNameAndDesc f = FullyQualifiedMemberNameAndDesc.of(t); if (refs.add(f)) { toAdd.add(f); } @@ -154,13 +154,13 @@ public void scan(ClassNode classNode, Filter filter) { Type currentType = Type.getObjectType(classNode.name); // super Type superType = Type.getObjectType(classNode.superName); - if (filter.shouldInclude(FullyQualifiedMemberNameAndDesc.ofType(superType))) { + if (filter.shouldInclude(FullyQualifiedMemberNameAndDesc.of(superType))) { requiredInstances.add(superType); } // interfaces for (String s : classNode.interfaces) { Type interfaceType = Type.getObjectType(s); - if (filter.shouldInclude(FullyQualifiedMemberNameAndDesc.ofType(interfaceType))) { + if (filter.shouldInclude(FullyQualifiedMemberNameAndDesc.of(interfaceType))) { requiredInstances.add(interfaceType); } } @@ -287,7 +287,7 @@ private void requiresInstance(MemberNameAndDesc member, Type required, Filter fi FullyQualifiedMemberNameAndDesc type; switch (required.getSort()) { case Type.ARRAY: - type = FullyQualifiedMemberNameAndDesc.ofType(required.getElementType()); + type = FullyQualifiedMemberNameAndDesc.of(required.getElementType()); if (filter.shouldInclude(type)) { if (list == null) { list = new ArrayList<>(); @@ -297,7 +297,7 @@ private void requiresInstance(MemberNameAndDesc member, Type required, Filter fi } break; case Type.OBJECT: - type = FullyQualifiedMemberNameAndDesc.ofType(required); + type = FullyQualifiedMemberNameAndDesc.of(required); if (filter.shouldInclude(type)) { if (list == null) { list = new ArrayList<>(); diff --git a/src/main/java/xyz/wagyourtail/jvmdg/version/VersionProvider.java b/src/main/java/xyz/wagyourtail/jvmdg/version/VersionProvider.java index fb18b5c6..d1d6c419 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/version/VersionProvider.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/version/VersionProvider.java @@ -516,7 +516,7 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set } // else if (!found) { - MethodVisitor mv = owner.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), name, hStaticDesc.getDescriptor(), null, null); + MethodVisitor mv = owner.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, name, hStaticDesc.getDescriptor(), null, null); mv.visitCode(); Type returnType = hStaticDesc.getReturnType(); Type[] arguments = hStaticDesc.getArgumentTypes(); @@ -544,6 +544,64 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set false ); } + } else { + Pair mod = stubMapper.getModifyFor(member, isStatic); + if (mod != null) { + if (handle.getTag() != Opcodes.H_NEWINVOKESPECIAL) { + System.err.println("Invalid modify for indy handle: " + handle.getOwner() + "." + handle.getName() + handle.getDesc()); + } else { + Type returnType = Type.getObjectType(handle.getOwner()); + Type[] arguments = hDesc.getArgumentTypes(); + + String name = "jvmdowngrader$construct"; + String desc = Type.getMethodDescriptor(returnType, arguments); + + boolean found = false; + for (MethodNode mn : owner.methods) { + if (mn.name.equals(name) && mn.desc.equals(desc)) { + found = true; + break; + } + } + + if (!found) { + + // construct wrapper + MethodNode mn = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, name, desc, null, null); + mn.visitCode(); + mn.visitTypeInsn(Opcodes.NEW, returnType.getInternalName()); + mn.visitInsn(Opcodes.DUP); + int k = 0; + for (Type argument : arguments) { + mn.visitVarInsn(argument.getOpcode(Opcodes.ILOAD), k); + k += argument.getSize(); + } + mn.visitMethodInsn(Opcodes.INVOKESPECIAL, returnType.getInternalName(), "", Type.getMethodDescriptor(Type.VOID_TYPE, arguments), false); + mn.visitInsn(Opcodes.ARETURN); + mn.visitMaxs(0, 0); + mn.visitEnd(); + owner.methods.add(mn); + + // invoke modify + try { + List modifyArgs = Arrays.asList(mn, mn.instructions.size() - 2, owner, extra); + mod.getFirst().invoke(null, modifyArgs.subList(0, mod.getFirst().getParameterTypes().length).toArray()); + } catch (Throwable e) { + throw new RuntimeException(e); + } + + } + + indy.bsmArgs[j] = new Handle( + Opcodes.H_INVOKESTATIC, + owner.name, + name, + desc, + false + ); + + } + } } break; } @@ -725,7 +783,7 @@ public ClassNode stubClasses(ClassNode clazz, boolean enableRuntime) { for (String removedInterface : removedInterfaces) { sb.append(removedInterface).append(";"); } - clazz.visitField(Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL), "jvmdg$removedInterfaces", "Ljava/lang/String;", null, sb.toString()).visitEnd(); + clazz.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "jvmdg$removedInterfaces", "Ljava/lang/String;", null, sb.toString()).visitEnd(); } // signature diff --git a/src/main/java/xyz/wagyourtail/jvmdg/version/map/ClassMapping.java b/src/main/java/xyz/wagyourtail/jvmdg/version/map/ClassMapping.java index 56a6673f..22de78f0 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/version/map/ClassMapping.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/version/map/ClassMapping.java @@ -165,7 +165,7 @@ public Pair getStubFor(MemberNameAndDesc member, boolean invoke_st try { Pair pair = methodStub.get(member); if (pair == null) { - if (!invoke_static) { + if (!invoke_static && !member.getName().equals("")) { Set members = this.members.get(); if (members != null && members.contains(member)) { // if (parentStub != null) { @@ -194,6 +194,40 @@ public Pair getStubFor(MemberNameAndDesc member, boolean invoke_st } } + public Pair getParentModifyFor(MemberNameAndDesc member) { + for (ClassMapping parent : parents.get()) { + Pair node = parent.getModifyFor(member, false); + if (node != null) { + return node; + } + } + return null; + } + + public Pair getModifyFor(MemberNameAndDesc member, boolean invoke_static) { + try { + Pair pair = methodModify.get(member); + if (pair == null) { + if (!invoke_static && !member.getName().equals("")) { + Set members = this.members.get(); + if (members != null && members.contains(member)) { + return null; + } + return getParentModifyFor(member); + } + return null; + } + Method m = pair.getFirst(); + int modifiers = m.getModifiers(); + if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { + throw new RuntimeException("modify method must be public static"); + } + return pair; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public Map> getMethodStubMap() { return methodStub; } diff --git a/src/main/java/xyz/wagyourtail/jvmdg/version/map/FullyQualifiedMemberNameAndDesc.java b/src/main/java/xyz/wagyourtail/jvmdg/version/map/FullyQualifiedMemberNameAndDesc.java index 195e1ba6..f612d57d 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/version/map/FullyQualifiedMemberNameAndDesc.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/version/map/FullyQualifiedMemberNameAndDesc.java @@ -1,5 +1,6 @@ package xyz.wagyourtail.jvmdg.version.map; +import org.objectweb.asm.Handle; import org.objectweb.asm.Type; import java.lang.reflect.Method; @@ -16,14 +17,18 @@ public FullyQualifiedMemberNameAndDesc(Type owner, String name, Type desc) { this.desc = desc; } - public static FullyQualifiedMemberNameAndDesc fromMethod(Method method) { + public static FullyQualifiedMemberNameAndDesc of(Method method) { return new FullyQualifiedMemberNameAndDesc(Type.getType(method.getDeclaringClass()), method.getName(), Type.getType(method)); } - public static FullyQualifiedMemberNameAndDesc ofType(Type type) { + public static FullyQualifiedMemberNameAndDesc of(Type type) { return new FullyQualifiedMemberNameAndDesc(type, null, null); } + public static FullyQualifiedMemberNameAndDesc of(Handle handle) { + return new FullyQualifiedMemberNameAndDesc(Type.getObjectType(handle.getOwner()), handle.getName(), Type.getType(handle.getDesc())); + } + public Type getOwner() { return owner; }