-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 45 additions & 2 deletions
47
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_ClassLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_N_URLClassLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package xyz.wagyourtail.jvmdg.j9.stub.java_base; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.Type; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
import xyz.wagyourtail.jvmdg.version.Modify; | ||
import xyz.wagyourtail.jvmdg.version.Ref; | ||
|
||
public class J_N_URLClassLoader { | ||
|
||
@Modify(ref = @Ref(value = "java/net/URLClassLoader", member = "<init>", desc = "(Ljava/lang/String;[Ljava/net/URL;Ljava/lang/ClassLoader;)V")) | ||
public static void init1(MethodNode mnode, int i) { | ||
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
// stack: URLClassLoader (U), String, URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.DUP2_X1)); | ||
// stack: URLClassLoader (U), URL[], ClassLoader, String, URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.POP2)); | ||
// stack: URLClassLoader (U), URL[], ClassLoader, String | ||
list.add(new InsnNode(Opcodes.DUP2_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader, String | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.DUP2_X1)); | ||
// stack: ClassLoader, String, URL[], ClassLoader, URLClassLoader (U), URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.POP2)); | ||
// stack: ClassLoader, String, URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URLClassLoader (U), URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URLClassLoader (U), URL[], ClassLoader | ||
// init | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/net/URLClassLoader", "<init>", "([Ljava/net/URL;Ljava/lang/ClassLoader;)V", false)); | ||
// stack: ClassLoader, String, URLClassLoader | ||
// call setName | ||
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(J_L_ClassLoader.class), "setClassloaderName", "(Ljava/lang/String;Ljava/lang/ClassLoader;)V", false)); | ||
// stack: ClassLoader | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: | ||
|
||
mnode.instructions.insert(node, list); | ||
mnode.instructions.remove(node); | ||
} | ||
|
||
@Modify(ref = @Ref(value = "java/net/URLClassLoader", member = "<init>", desc = "(Ljava/lang/String;[Ljava/net/URL;Ljava/lang/ClassLoader;Ljava/net/URLStreamHandlerFactory;)V")) | ||
public static void init2(MethodNode mnode, int i) { | ||
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
// stack: URLClassLoader (U), String, URL[], ClassLoader, URLStreamHandlerFactory | ||
|
||
int var = mnode.maxLocals++; | ||
list.add(new VarInsnNode(Opcodes.ASTORE, var)); | ||
|
||
// stack: URLClassLoader (U), String, URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.DUP2_X1)); | ||
// stack: URLClassLoader (U), URL[], ClassLoader, String, URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.POP2)); | ||
// stack: URLClassLoader (U), URL[], ClassLoader, String | ||
list.add(new InsnNode(Opcodes.DUP2_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader, String | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.DUP2_X1)); | ||
// stack: ClassLoader, String, URL[], ClassLoader, URLClassLoader (U), URL[], ClassLoader | ||
list.add(new InsnNode(Opcodes.POP2)); | ||
// stack: ClassLoader, String, URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URLClassLoader (U), URL[], ClassLoader, URLClassLoader (U) | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URLClassLoader (U), URL[], ClassLoader | ||
list.add(new VarInsnNode(Opcodes.ALOAD, var)); | ||
// stack: ClassLoader, String, URLClassLoader (U), URLClassLoader (U), URL[], ClassLoader, URLStreamHandlerFactory | ||
// init | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/net/URLClassLoader", "<init>", "([Ljava/net/URL;Ljava/lang/ClassLoader;Ljava/net/URLStreamHandlerFactory;)V", false)); | ||
// stack: ClassLoader, String, URLClassLoader | ||
// call setName | ||
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(J_L_ClassLoader.class), "setClassloaderName", "(Ljava/lang/String;Ljava/lang/ClassLoader;)V", false)); | ||
// stack: ClassLoader | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: | ||
|
||
mnode.instructions.insert(node, list); | ||
mnode.instructions.remove(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
testing/downgrade/src/main/java/xyz/wagyourtail/downgradetest/TestClassloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package xyz.wagyourtail.downgradetest; | ||
|
||
import java.net.URLClassLoader; | ||
|
||
public class TestClassloader { | ||
|
||
public static void main(String[] args) { | ||
URLClassLoader cl = new URLClassLoader("name1", new java.net.URL[0], TestClassloader.class.getClassLoader()); | ||
System.out.println(cl.getName()); | ||
|
||
URLClassLoader cl2 = new URLClassLoader("name2", new java.net.URL[0], TestClassloader.class.getClassLoader(), null); | ||
System.out.println(cl2.getName()); | ||
|
||
CLExt cl3 = new CLExt(TestClassloader.class.getClassLoader()); | ||
System.out.println(cl3.getName()); | ||
|
||
} | ||
|
||
private static class CLExt extends ClassLoader { | ||
|
||
public CLExt(ClassLoader parent) { | ||
super("name3", parent); | ||
} | ||
|
||
} | ||
|
||
} |