-
-
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.
replace stub init with modify, rework try/catch logging
- Loading branch information
1 parent
3b6eea3
commit b37f1b8
Showing
13 changed files
with
315 additions
and
97 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
52 changes: 42 additions & 10 deletions
52
java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_I_PrintWriter.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 |
---|---|---|
@@ -1,20 +1,52 @@ | ||
package xyz.wagyourtail.jvmdg.j10.stub.java_base; | ||
|
||
|
||
import org.objectweb.asm.Opcodes; | ||
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.io.BufferedWriter; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.io.PrintWriter; | ||
import java.nio.charset.Charset; | ||
|
||
public class J_I_PrintWriter { | ||
|
||
@Stub(ref = @Ref(value = "Ljava/io/PrintWriter;", member = "<init>")) | ||
public static PrintWriter init(OutputStream out, boolean autoFlush, Charset encoding) { | ||
return new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, encoding)), autoFlush); | ||
@Modify(ref = @Ref(value = "Ljava/io/PrintWriter;", member = "<init>", desc = "(Ljava/io/OutputStream;ZLjava/nio/charset/Charset;)V")) | ||
public static void init(MethodNode mnode, int i) { | ||
AbstractInsnNode node = mnode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
// stack: PrintWriter, OutputStream, boolean, Charset | ||
list.add(new InsnNode(Opcodes.DUP2_X1)); | ||
// stack: PrintWriter, boolean, Charset, OutputStream, boolean, Charset | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: PrintWriter, boolean, Charset, OutputStream, Charset, boolean | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: PrintWriter, boolean, Charset, OutputStream, Charset | ||
list.add(new TypeInsnNode(Opcodes.NEW, "java/io/OutputStreamWriter")); | ||
// stack: PrintWriter, boolean, Charset, OutputStream, Charset, (U) OutputStreamWriter | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: PrintWriter, boolean, Charset, (U) OutputStreamWriter, OutputStream, Charset, (U) OutputStreamWriter | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: PrintWriter, boolean, Charset, (U) OutputStreamWriter, (U) OutputStreamWriter, OutputStream, Charset, (U) OutputStreamWriter | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: PrintWriter, boolean, Charset, (U) OutputStreamWriter, (U) OutputStreamWriter, OutputStream, Charset | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/OutputStreamWriter", "<init>", "(Ljava/io/OutputStream;Ljava/nio/charset/Charset;)V", false)); | ||
// stack: PrintWriter, boolean, Charset, OutputStreamWriter | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: PrintWriter, boolean, OutputStreamWriter, Charset | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: PrintWriter, boolean, OutputStreamWriter | ||
list.add(new TypeInsnNode(Opcodes.NEW, "java/io/BufferedWriter")); | ||
// stack: PrintWriter, boolean, OutputStreamWriter, (U) BufferedWriter | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: PrintWriter, boolean, (U) BufferedWriter, OutputStreamWriter, (U) BufferedWriter | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: PrintWriter, boolean, (U) BufferedWriter, (U) BufferedWriter, OutputStreamWriter | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/BufferedWriter", "<init>", "(Ljava/io/Writer;)V", false)); | ||
// stack: PrintWriter, boolean, BufferedWriter | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: PrintWriter, BufferedWriter, boolean | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/PrintWriter", "<init>", "(Ljava/io/Writer;Z)V", false)); | ||
|
||
mnode.instructions.insert(node, list); | ||
mnode.instructions.remove(node); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
java-api/src/java10/java/xyz/wagyourtail/jvmdg/j10/stub/java_base/J_N_C_Channels.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,28 @@ | ||
package xyz.wagyourtail.jvmdg.j10.stub.java_base; | ||
|
||
import xyz.wagyourtail.jvmdg.version.Ref; | ||
import xyz.wagyourtail.jvmdg.version.Stub; | ||
|
||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.nio.channels.WritableByteChannel; | ||
import java.nio.charset.Charset; | ||
import java.util.Objects; | ||
|
||
public class J_N_C_Channels { | ||
|
||
@Stub(ref = @Ref("java/nio/channels/Channels")) | ||
public static Reader newReader(ReadableByteChannel channel, Charset charset) { | ||
Objects.requireNonNull(charset, "charset"); | ||
return Channels.newReader(channel, charset.newDecoder(), -1); | ||
} | ||
|
||
@Stub(ref = @Ref("java/nio/channels/Channels")) | ||
public static Writer newWriter(WritableByteChannel channel, Charset charset) { | ||
Objects.requireNonNull(charset, "charset"); | ||
return Channels.newWriter(channel, charset.newEncoder(), -1); | ||
} | ||
|
||
} |
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
57 changes: 47 additions & 10 deletions
57
.../src/java15/java/xyz/wagyourtail/jvmdg/j15/stub/java_base/J_U_NoSuchElementException.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 |
---|---|---|
@@ -1,25 +1,62 @@ | ||
package xyz.wagyourtail.jvmdg.j15.stub.java_base; | ||
|
||
|
||
import org.objectweb.asm.Opcodes; | ||
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 { | ||
|
||
@Stub(ref = @Ref(value = "Ljava/util/NoSuchElementException;", member = "<init>")) | ||
public static NoSuchElementException create(String s, Throwable cause) throws NoSuchMethodException { | ||
var nse = new NoSuchElementException(s); | ||
nse.initCause(cause); | ||
return nse; | ||
@Modify(ref = @Ref(value = "Ljava/util/NoSuchElementException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V")) | ||
public static void init(MethodNode mnode, int i) { | ||
AbstractInsnNode node = mnode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
// stack: NoSuchElementException, String, Throwable | ||
list.add(new InsnNode(Opcodes.DUP_X2)); | ||
// stack: Throwable, NoSuchElementException, String, Throwable | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: Throwable, NoSuchElementException, String | ||
list.add(new InsnNode(Opcodes.DUP2)); | ||
// stack: Throwable, NoSuchElementException, String, NoSuchElementException, String | ||
// call init | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "(Ljava/lang/String;)V", false)); | ||
// stack: Throwable, NoSuchElementException, String | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: Throwable, NoSuchElementException | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: NoSuchElementException, Throwable | ||
// call initCause | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/NoSuchElementException", "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;", false)); | ||
// stack: NoSuchElementException | ||
list.add(new InsnNode(Opcodes.POP)); | ||
|
||
mnode.instructions.insert(node, list); | ||
mnode.instructions.remove(node); | ||
} | ||
|
||
@Stub(ref = @Ref(value = "Ljava/util/NoSuchElementException;", member = "<init>")) | ||
public static NoSuchElementException create(Throwable cause) throws NoSuchMethodException { | ||
var nse = new NoSuchElementException(cause == null ? null : cause.toString()); | ||
nse.initCause(cause); | ||
return nse; | ||
@Modify(ref = @Ref(value = "java/util/NoSuchElementException", member = "<init>", desc = "(Ljava/lang/Throwable;)V")) | ||
public static void init2(MethodNode mNode, int i) { | ||
AbstractInsnNode node = mNode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
// stack: NoSuchElementException, Throwable | ||
list.add(new InsnNode(Opcodes.DUP2)); | ||
// stack: NoSuchElementException, Throwable, NoSuchElementException, Throwable | ||
list.add(new InsnNode(Opcodes.POP)); | ||
// stack: NoSuchElementException, Throwable, NoSuchElementException | ||
// call init | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "()V", false)); | ||
// stack: NoSuchElementException, Throwable | ||
// call initCause | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/NoSuchElementException", "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;", false)); | ||
// stack: NoSuchElementException | ||
list.add(new InsnNode(Opcodes.POP)); | ||
|
||
mNode.instructions.insert(node, list); | ||
mNode.instructions.remove(node); | ||
} | ||
|
||
} |
29 changes: 26 additions & 3 deletions
29
...c/java16/java/xyz/wagyourtail/jvmdg/j16/stub/java_base/J_L_IndexOutOfBoundsException.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
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
29 changes: 26 additions & 3 deletions
29
...src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IndexOutOfBoundsException.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 |
---|---|---|
@@ -1,14 +1,37 @@ | ||
package xyz.wagyourtail.jvmdg.j9.stub.java_base; | ||
|
||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
import xyz.wagyourtail.jvmdg.version.Modify; | ||
import xyz.wagyourtail.jvmdg.version.Ref; | ||
import xyz.wagyourtail.jvmdg.version.Stub; | ||
|
||
public class J_L_IndexOutOfBoundsException { | ||
|
||
@Stub(ref = @Ref(value = "Ljava/lang/IndexOutOfBoundsException;", member = "<init>")) | ||
public static IndexOutOfBoundsException init(int index) { | ||
return new IndexOutOfBoundsException("Index out of range: " + index); | ||
@Modify(ref = @Ref(value = "java/lang/IndexOutOfBoundsException", member = "<init>", desc = "(I)V")) | ||
public static void init(MethodNode mnode, int i) { | ||
AbstractInsnNode node = mnode.instructions.get(i); | ||
InsnList list = new InsnList(); | ||
|
||
// stack: IndexOutOfBoundsException, int | ||
// new StringBuilder("Index out of range: ").append(index) | ||
list.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder")); | ||
list.add(new InsnNode(Opcodes.DUP)); | ||
list.add(new LdcInsnNode("Index out of range: ")); | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false)); | ||
// stack: IndexOutOfBoundsException, int, StringBuilder | ||
list.add(new InsnNode(Opcodes.SWAP)); | ||
// stack: IndexOutOfBoundsException, StringBuilder, int | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false)); | ||
// stack: IndexOutOfBoundsException, StringBuilder | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)); | ||
// stack: IndexOutOfBoundsException, String | ||
// call init | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/IndexOutOfBoundsException", "<init>", "(Ljava/lang/String;)V", false)); | ||
|
||
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
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
Oops, something went wrong.