Repository navigation
Fix class initialization and bytecode edge cases #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| public class BooleanStore { | ||
| public static class Stores { | ||
| public static int store(boolean[] values) { | ||
| values[0] = true; | ||
| return values[0] ? 1 : 0; | ||
| } | ||
| } | ||
|
|
||
| static class Loader extends ClassLoader { | ||
| Class<?> define(byte[] bytes) { return defineClass(null, bytes, 0, bytes.length); } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| try { | ||
| Stores.store(null); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } catch (NullPointerException e) { | ||
| System.out.println("null store: " + e.getClass().getName()); | ||
| } | ||
| byte[] bytes; | ||
| try (var in = BooleanStore.class.getResourceAsStream("BooleanStore$Stores.class")) { | ||
| bytes = in.readAllBytes(); | ||
| } | ||
| int changes = 0; | ||
| for (int i = 0; i < bytes.length - 1; i++) { | ||
| if (bytes[i] == 4 && bytes[i + 1] == 0x54) { | ||
| bytes[i] = 5; | ||
| changes++; | ||
| } | ||
| } | ||
| if (changes != 1) throw new AssertionError(changes); | ||
| var method = new Loader().define(bytes).getMethod("store", boolean[].class); | ||
| for (int i = 0; i < 1000; i++) { | ||
| int value = (int) method.invoke(null, new boolean[] { true }); | ||
| if (i == 0 || i == 999) System.out.println(value); | ||
| } | ||
| try { | ||
| method.invoke(null, (Object) null); | ||
| } catch (java.lang.reflect.InvocationTargetException e) { | ||
| System.out.println("hot null store: " + e.getCause().getClass().getName()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,44 @@ | ||
| public class InterfaceInitialization { | ||
| static String mark(String name) { | ||
| System.out.println(name); | ||
| return name; | ||
| } | ||
|
|
||
| interface Root { | ||
| String VALUE = mark("root"); | ||
| default void root() {} | ||
| } | ||
| interface Middle extends Root {} | ||
| interface Left extends Middle { | ||
| String VALUE = mark("left"); | ||
| default void left() {} | ||
| } | ||
| interface Right extends Root { | ||
| String VALUE = mark("right"); | ||
| default void right() {} | ||
| } | ||
| static class Impl implements Left, Right { | ||
| static String VALUE = mark("class"); | ||
| } | ||
|
|
||
| interface Parent { | ||
| String VALUE = mark("parent"); | ||
| default void parent() {} | ||
| } | ||
| interface Child extends Parent { | ||
| String VALUE = mark("child"); | ||
| } | ||
| interface PrivateOnly { | ||
| String VALUE = mark("private interface"); | ||
| private void helper() {} | ||
| } | ||
| static class PrivateImpl implements PrivateOnly { | ||
| static String VALUE = mark("private class"); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println(Child.VALUE); | ||
| System.out.println(Impl.VALUE); | ||
| System.out.println(PrivateImpl.VALUE); | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| public class LongToFloat { | ||
| static float convert(long value) { return (float) value; } | ||
|
|
||
| public static void main(String[] args) { | ||
| long midpoint = (1L << 62) + (1L << 38); | ||
| long[] values = {0, 1, -1, midpoint - 1, midpoint, midpoint + 1, | ||
| -midpoint - 1, -midpoint, -midpoint + 1, Long.MIN_VALUE, Long.MAX_VALUE}; | ||
| for (int run = 0; run < 1000; run++) { | ||
| for (long value : values) { | ||
| int bits = Float.floatToRawIntBits(convert(value)); | ||
| if (run == 0 || run == 999) System.out.println(bits); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.