[PATCH] 8147527: Non-optimal code generated for postfix unary operators

bsrbnd bsrbnd at gmail.com
Mon Nov 14 10:48:32 UTC 2016


Hi,

2016-11-03 14:45 GMT+01:00 Jan Lahoda <jan.lahoda at oracle.com>:
> Hi Bernard,
>
> Thanks for looking at this. For the avoidance of the modification of
> tree.selected in Lower.visitSelect, what I meant was more that we would
> create a new instance of JCFieldAccess, to carry the new select. Might be
> easier that trying to work with the existing select.
>
> I think it might be useful to have a set of tests covering the usecases, so
> that we can more easily test patches (we will need tests eventually anyway).
> I can look at that, unless you want to.
>
Here is a test that verifies the runtime behavior of the "super",
"this" and "this$n" optimization. It failed previous to issue 8143388
changeset and still have to succeed after the optimization.

Bernard

diff --git a/test/tools/javac/boxing/BoxedPostOpOpti3.java
b/test/tools/javac/boxing/BoxedPostOpOpti3.java
new file mode 100644
--- /dev/null
+++ b/test/tools/javac/boxing/BoxedPostOpOpti3.java
@@ -0,0 +1,51 @@
+/*
+ * @test
+ * @bug 8147527
+ * @summary Verifies the runtime behavior of "super", "this" and
"this$n" optimization for boxed unary post-operations.
+ */
+public class BoxedPostOpOpti3 extends p.Parent {
+    public static void main(String[] args) {
+        new BoxedPostOpOpti3().testAll();
+    }
+
+    private void testAll() {
+        equals(test(), 1);
+        equals(i, 2);
+
+        Inner in = new Inner();
+        equals(in.test(), 3);
+        equals(i, 4);
+
+        equals(testParent(), 21);
+        equals(super.j, 22);
+
+        equals(in.testParent(), 23);
+        equals(super.j, 24);
+    }
+
+    private void equals(int a, int b) {
+        if (a != b) throw new Error();
+    }
+
+    Integer i=0;
+
+    private Integer test() {
+        i++;
+        return this.i++;
+    }
+    private Integer testParent() {
+        j++;
+        return super.j++;
+    }
+
+    class Inner {
+        private Integer test() {
+            i++;
+            return BoxedPostOpOpti3.this.i++;
+        }
+        private Integer testParent() {
+            j++;
+            return BoxedPostOpOpti3.super.j++;
+        }
+    }
+}
diff --git a/test/tools/javac/boxing/p/Parent.java
b/test/tools/javac/boxing/p/Parent.java
new file mode 100644
--- /dev/null
+++ b/test/tools/javac/boxing/p/Parent.java
@@ -0,0 +1,5 @@
+package p;
+
+public class Parent {
+    protected Integer j=20;
+}


More information about the compiler-dev mailing list