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

bsrbnd bsrbnd at gmail.com
Thu Nov 10 19:12:38 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 below is a test (derived from issue 8143388 test) for the
optimization of "this" and "this$n".

Bernard

diff --git a/test/tools/javac/boxing/BoxedPostOpOpti.java
b/test/tools/javac/boxing/BoxedPostOpOpti.java
new file mode 100644
--- /dev/null
+++ b/test/tools/javac/boxing/BoxedPostOpOpti.java
@@ -0,0 +1,77 @@
+/*
+ * @test
+ * @bug 8147527
+ * @summary "this" and "this$n" code optimization for boxed unary
post-operations.
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask
+ * @run main BoxedPostOpOpti
+ */
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+
+import toolbox.JavacTask;
+import toolbox.ToolBox;
+
+public class BoxedPostOpOpti {
+    public static void main(String... args) throws IOException {
+        new BoxedPostOpOpti().run();
+    }
+
+    void run() throws IOException {
+        ToolBox tb = new ToolBox();
+
+        Path expected = Paths.get("expected");
+        Files.createDirectories(expected);
+        tb.cleanDirectory(expected);
+        new JavacTask(tb).sources(
+                "class C {" +
+                "    Integer i=0;" +
+                "    private Integer test() {" +
+                "        return i++;" +
+                "    }" +
+                "    class Inner {" +
+                "        private Integer test() {" +
+                "            return i++;" +
+                "        }" +
+                "    }" +
+                "}"
+            ).outdir(expected).run();
+
+        Path actual = Paths.get("actual");
+        Files.createDirectories(actual);
+        tb.cleanDirectory(actual);
+        new JavacTask(tb).sources(
+                "class C {" +
+                "    Integer i=0;" +
+                "    private Integer test() {" +
+                "        return this.i++;" +
+                "    }" +
+                "    class Inner {" +
+                "        private Integer test() {" +
+                "            return C.this.i++;" +
+                "        }" +
+                "    }" +
+                "}"
+            ).outdir(actual).run();
+
+        String error = "", sep = "";
+        for (Path p1: tb.findFiles(".class", expected)) {
+            for (Path p2: tb.findFiles(p1.getFileName().toString(), actual)) {
+                byte[] b1 = Files.readAllBytes(p1);
+                byte[] b2 = Files.readAllBytes(p2);
+                if (!Arrays.equals(b1, b2)) {
+                    error += sep + p1 + " differs from " + p2;
+                    sep = ", ";
+                }
+            }
+        }
+        if (error.length() > 0) throw new Error(error);
+    }
+}


More information about the compiler-dev mailing list