-
Notifications
You must be signed in to change notification settings - Fork 273
Introduce temporary stack variables for getfield/-static and ?load #931
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
Closed
mgudemann
wants to merge
11
commits into
diffblue:master
from
mgudemann:fix/bytecode_args_push_on_stack
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2e4e0b5
Introduce temporary stack variables for ?load / ?aload
d9e3bbc
Introduce temporary stack variables for `dup`, `dup_x1`, `dup_x2`
319ff01
Introduce temporary stack variable for `getfield`
75b770b
Introduce temporary stack variable for `getstatic`
3569806
Introduce temporary stack variables for `dup_2`, `dup2_x1`, `dup2_x2`
74ac6e1
Adapt existing regression tests
3f5dac8
Add regression tests for `iload`, `dup`, `dup_x1`, `dup_x2`
0aec9b1
Add regression tests for `dup2`, `dup2_x1` and `dup2_x2`
8cacd7d
Add regression test for `getfield`, `getstatic`
52f522d
Add README to tests pointing to jasmin bytecode assembler
fc1a852
Do not duplicate constant value as temporary variables
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ Break.class | |
^SIGNAL=0$ | ||
dead i; | ||
-- | ||
GOTO 10 | ||
GOTO 11 |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var1 s = new stack_var1(); | ||
int n = s.f(1); | ||
assert(n==0); | ||
} | ||
} |
Binary file not shown.
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,22 @@ | ||
.class public stack_var1 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f(I)I | ||
.limit stack 2 | ||
.limit locals 2 | ||
|
||
;; copy of arg on stack | ||
iload_1 | ||
;; increment arg | ||
iinc 1 1 | ||
;; incremented copy on stack | ||
iload_1 | ||
isub | ||
ireturn | ||
.end method |
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,9 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var2 s = new stack_var2(); | ||
int n = s.f(1); | ||
assert(n==0); | ||
} | ||
} |
Binary file not shown.
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,25 @@ | ||
.class public stack_var2 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f(I)I | ||
.limit stack 3 | ||
.limit locals 2 | ||
|
||
;; push local var1 | ||
iload_1 | ||
;; duplicate | ||
dup | ||
;; increment local var1 | ||
iinc 1 1 | ||
;; push local var1 | ||
iload_1 | ||
isub | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,9 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var3 s = new stack_var3(); | ||
int n = s.f(); | ||
assert(n==0); | ||
} | ||
} |
Binary file not shown.
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,33 @@ | ||
.class public stack_var3 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f()I | ||
.limit stack 5 | ||
.limit locals 3 | ||
|
||
;; 1->var1 | ||
;; 0->var2 | ||
iconst_1 | ||
istore_1 | ||
iconst_0 | ||
istore_2 | ||
;; push local var2 / var1 | ||
iload_2 | ||
iload_1 | ||
;; dup var1 | ||
dup_x1 | ||
;; sub one from var1 | ||
iinc 1 -1 | ||
;; pop first var1 | ||
pop | ||
;; sub | ||
isub | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,9 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var4 s = new stack_var4(); | ||
int n = s.f(); | ||
assert(n==0); | ||
} | ||
} |
Binary file not shown.
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,37 @@ | ||
.class public stack_var4 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f()I | ||
.limit stack 5 | ||
.limit locals 4 | ||
|
||
;; 0->var1 | ||
;; 1->var2 | ||
;; 2->var3 | ||
iconst_0 | ||
istore_1 | ||
iconst_1 | ||
istore_2 | ||
iconst_2 | ||
istore_3 | ||
|
||
;; push local var3 / var2 / var1 | ||
iload_3 | ||
iload_2 | ||
iload_1 | ||
;; push var1 in front of var3 | ||
dup_x2 | ||
;; add one to local var 1 | ||
iinc 1 1 | ||
pop | ||
pop | ||
pop | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,10 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: SUCCESS | ||
$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var5 s = new stack_var5(); | ||
int n = s.f(); | ||
assert(n==1); | ||
} | ||
} |
Binary file not shown.
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,33 @@ | ||
.class public stack_var5 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f()I | ||
.limit stack 4 | ||
.limit locals 4 | ||
|
||
;; 1->var1 | ||
;; 2->var2 | ||
iconst_1 | ||
istore_1 | ||
iconst_2 | ||
istore_2 | ||
|
||
;; push local var2 / var1 | ||
iload_2 | ||
iload_1 | ||
|
||
;; duplicate var2 / var1 | ||
dup2 | ||
;; add one to local var 1 | ||
iinc 1 1 | ||
;; sub | ||
isub | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,10 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: SUCCESS | ||
$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var6 s = new stack_var6(); | ||
int n = s.f(1,2,4); | ||
assert(n==-2); | ||
} | ||
} |
Binary file not shown.
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,25 @@ | ||
.class public stack_var6 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f(III)I | ||
.limit stack 8 | ||
.limit locals 5 | ||
|
||
;; push local var3 / var2 / var1 | ||
iload_1 | ||
iload_2 | ||
iload_3 | ||
dup2_x1 | ||
;; add one to local var 2 | ||
iinc 2 1 | ||
;; sub | ||
isub | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,10 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: SUCCESS | ||
$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var7 s = new stack_var7(); | ||
int n = s.f(); | ||
assert(n==1); | ||
} | ||
} |
Binary file not shown.
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,43 @@ | ||
.class public stack_var7 | ||
.super java/lang/Object | ||
|
||
.method public <init>()V | ||
aload_0 | ||
invokenonvirtual java/lang/Object/<init>()V | ||
return | ||
.end method | ||
|
||
.method public f()I | ||
.limit stack 8 | ||
.limit locals 5 | ||
|
||
;; 1->var1 | ||
;; 2->var2 | ||
;; 4->var3 | ||
;; 8->var4 | ||
iconst_1 | ||
istore_1 | ||
iconst_2 | ||
istore_2 | ||
iconst_4 | ||
istore_3 | ||
bipush 8 | ||
istore 4 | ||
;; push local var4 / var3 / var2 / var1 | ||
iload 4 | ||
iload_3 | ||
iload_2 | ||
iload 1 | ||
;; push var2 / var1 in on head | ||
dup2_x2 | ||
;; add one to local var 1 | ||
iinc 1 1 | ||
pop | ||
pop | ||
pop | ||
pop | ||
;; sub | ||
isub | ||
;; incremented copy on stack | ||
ireturn | ||
.end method |
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,10 @@ | ||
CORE | ||
stack_test.class | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: SUCCESS | ||
$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Binary file not shown.
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,7 @@ | ||
public class stack_test { | ||
public static void main(String[] args) { | ||
stack_var8 s = new stack_var8(); | ||
int n = s.f(); | ||
assert(n==0); | ||
} | ||
} |
Binary file not shown.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this file (and the other .j files) included?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the source files I used to create the classes. This is very bytecode specific, in particular the
dup2_x?
are very rare, so I used the jasmin assembler to create the regression tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool. Would you mind adding information in either the commit message or some extra readme file so that these steps become reproducible? I had naively thought that the .class files had been produced from the accompanying .java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do, the
stack_test.java
is always the entry point and creates an object instance of the class created via jasmin.