changeset 92:d04b4bbbc39f

A few new WIPs
author shade
date Tue, 19 Dec 2017 18:49:03 +0100
parents e8e80f26edfb
children 6ec38e1bea7a
files src/main/java/org/openjdk/gcbench/wip/OISRead.java src/main/java/org/openjdk/gcbench/wip/WriteBarrierLoop.java src/main/java/org/openjdk/gcbench/wip/WriteBarrierTableSwitch.java src/main/java/org/openjdk/gcbench/wip/WriteBarrierUTF8Scan.java
diffstat 4 files changed, 344 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/openjdk/gcbench/wip/OISRead.java	Tue Dec 19 18:49:03 2017 +0100
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.gcbench.wip;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.io.*;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(1)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Threads(1)
+@State(Scope.Benchmark)
+public class OISRead {
+
+    @Param("1024")
+    int size;
+    private byte[] src;
+
+    @Setup
+    public void setup() throws IOException {
+        StringBuilder sb = new StringBuilder();
+        for (int c = 0; c < size; c++) {
+            sb.append('c' + c);
+        }
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(sb.toString());
+        oos.flush();
+        oos.close();
+        src = baos.toByteArray();
+    }
+
+    @Benchmark
+    public Object test() throws IOException, ClassNotFoundException {
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(src));
+        return ois.readObject();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/openjdk/gcbench/wip/WriteBarrierLoop.java	Tue Dec 19 18:49:03 2017 +0100
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.gcbench.wip;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.util.concurrent.TimeUnit;
+
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(1)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Threads(1)
+@State(Scope.Benchmark)
+public class WriteBarrierLoop {
+
+    @Param("1000")
+    int size;
+
+    byte[] target;
+
+    @Setup
+    public void setup() {
+        target = new byte[size];
+    }
+
+    @Benchmark
+    public void test() {
+        for (int c = 0; c < size; c++) {
+            target[c] = (byte) (c & 0xFF);
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/openjdk/gcbench/wip/WriteBarrierTableSwitch.java	Tue Dec 19 18:49:03 2017 +0100
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.gcbench.wip;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.io.UTFDataFormatException;
+import java.nio.charset.Charset;
+import java.util.concurrent.TimeUnit;
+
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(3)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Threads(1)
+@State(Scope.Benchmark)
+public class WriteBarrierTableSwitch {
+
+    @Param("1000")
+    int size;
+
+    byte[] buf;
+    char[] cbuf;
+
+    @Setup
+    public void setup() {
+        StringBuilder sb = new StringBuilder();
+        for (int c = 0; c < size; c++) {
+            sb.append('c' + c);
+        }
+
+        buf = new byte[size];
+        cbuf = new char[size];
+        Charset.forName("UTF-8").encode(sb.toString()).get(buf);
+    }
+
+    @Benchmark
+    public void separate() {
+        for (int pos = 0; pos < size; pos++) {
+            int b1 = buf[pos] & 0xFF;
+            switch (b1 >> 4) {
+                case 0:
+                case 1:
+                case 2:
+                case 3:
+                case 4:
+                case 5:
+                case 6:
+                case 7:
+                    cbuf[pos] = (char) b1;
+                    break;
+                case 12:
+                case 13:
+                case 14:
+                    cbuf[pos] = (char) b1;
+                    break;
+                default:
+                    throw new IllegalStateException();
+            }
+        }
+    }
+
+    @Benchmark
+    public void common() {
+        for (int pos = 0; pos < size; pos++) {
+            int b1 = buf[pos] & 0xFF;
+            switch (b1 >> 4) {
+                case 0:
+                case 1:
+                case 2:
+                case 3:
+                case 4:
+                case 5:
+                case 6:
+                case 7:
+                case 12:
+                case 13:
+                case 14:
+                    cbuf[pos] = (char) b1;
+                    break;
+                default:
+                    throw new IllegalStateException();
+            }
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/openjdk/gcbench/wip/WriteBarrierUTF8Scan.java	Tue Dec 19 18:49:03 2017 +0100
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.gcbench.wip;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.io.UTFDataFormatException;
+import java.nio.charset.Charset;
+import java.util.concurrent.TimeUnit;
+
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(1)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Threads(1)
+@State(Scope.Benchmark)
+public class WriteBarrierUTF8Scan {
+
+    @Param("1000")
+    int size;
+
+    byte[] buf;
+    char[] cbuf;
+
+    @Setup
+    public void setup() {
+        StringBuilder sb = new StringBuilder();
+        for (int c = 0; c < size; c++) {
+            sb.append('c' + c);
+        }
+
+        buf = new byte[size];
+        cbuf = new char[size];
+
+        Charset.forName("UTF-8").encode(sb.toString()).get(buf);
+    }
+
+    @Benchmark
+    public void test() {
+        int cpos = 0;
+        int pos = 0;
+        int stop = pos + size;
+
+        while (pos < stop) {
+            int b1, b2, b3;
+            b1 = buf[pos++] & 0xFF;
+            switch (b1 >> 4) {
+                case 0:
+                case 1:
+                case 2:
+                case 3:
+                case 4:
+                case 5:
+                case 6:
+                case 7:   // 1 byte format: 0xxxxxxx
+                    cbuf[cpos++] = (char) b1;
+                    break;
+
+                case 12:
+                case 13:  // 2 byte format: 110xxxxx 10xxxxxx
+                    b2 = buf[pos++];
+                    if ((b2 & 0xC0) != 0x80) {
+                        throw new IllegalStateException();
+                    }
+                    cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
+                            ((b2 & 0x3F) << 0));
+                    break;
+
+                case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
+                    b3 = buf[pos + 1];
+                    b2 = buf[pos + 0];
+                    pos += 2;
+                    if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
+                        throw new IllegalStateException();
+                    }
+                    cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
+                            ((b2 & 0x3F) << 6) |
+                            ((b3 & 0x3F) << 0));
+                    break;
+
+                default:  // 10xx xxxx, 1111 xxxx
+                    throw new IllegalStateException();
+            }
+        }
+    }
+
+}