test/jdk/java/nio/Buffer/SwapMicroBenchmark.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 37913 jdk/test/java/nio/Buffer/SwapMicroBenchmark.java@3cc95b690353
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37913
3cc95b690353 8156931: java.nio.Buffer tests cleanup
prappo
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * This is not a regression test, but a micro-benchmark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * To exercise swap, run with filter=LITTLE_ENDIAN on sparc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * filter=BIG_ENDIAN on x86.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * I have run this as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * for f in -client -server; do mergeBench dolphin . jr -dsa -da $f SwapMicroBenchmark.java filter=LITTLE_ENDIAN; done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class SwapMicroBenchmark {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    abstract static class Job {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        public Job(String name) { this.name = name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        public String name() { return name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        public abstract void work() throws Throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static void collectAllGarbage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        final java.util.concurrent.CountDownLatch drained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            = new java.util.concurrent.CountDownLatch(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            System.gc();        // enqueue finalizable objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            new Object() { protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                drained.countDown(); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            System.gc();        // enqueue detector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            drained.await();    // wait for finalizer queue to drain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            System.gc();        // cleanup finalized objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        } catch (InterruptedException e) { throw new Error(e); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Runs each job for long enough that all the runtime compilers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * have had plenty of time to warm up, i.e. get around to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * compiling everything worth compiling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Returns array of average times per job per run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static long[] time0(Job ... jobs) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        final long warmupNanos = 10L * 1000L * 1000L * 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        long[] nanoss = new long[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        for (int i = 0; i < jobs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            collectAllGarbage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            long t0 = System.nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            long t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            do { jobs[i].work(); j++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            while ((t = System.nanoTime() - t0) < warmupNanos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            nanoss[i] = t/j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return nanoss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static void time(Job ... jobs) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        long[] warmup = time0(jobs); // Warm up run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        long[] nanoss = time0(jobs); // Real timing run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        long[] milliss = new long[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        double[] ratios = new double[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        final String nameHeader   = "Method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        final String millisHeader = "Millis";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        final String ratioHeader  = "Ratio";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int nameWidth   = nameHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        int millisWidth = millisHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        int ratioWidth  = ratioHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        for (int i = 0; i < jobs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            nameWidth = Math.max(nameWidth, jobs[i].name().length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            milliss[i] = nanoss[i]/(1000L * 1000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            millisWidth = Math.max(millisWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                   String.format("%d", milliss[i]).length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            ratios[i] = (double) nanoss[i] / (double) nanoss[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            ratioWidth = Math.max(ratioWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                  String.format("%.3f", ratios[i]).length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                      nameWidth, millisWidth, ratioWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                            nameWidth, millisWidth, ratioWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        System.out.printf(headerFormat, "Method", "Millis", "Ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // Print out absolute and relative times, calibrated against first job
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        for (int i = 0; i < jobs.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static String keywordValue(String[] args, String keyword) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        for (String arg : args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (arg.startsWith(keyword))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                return arg.substring(keyword.length() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static int intArg(String[] args, String keyword, int defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        String val = keywordValue(args, keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return val == null ? defaultValue : Integer.parseInt(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static Pattern patternArg(String[] args, String keyword) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        String val = keywordValue(args, keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return val == null ? null : Pattern.compile(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static Job[] filter(Pattern filter, Job[] jobs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (filter == null) return jobs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Job[] newJobs = new Job[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        for (Job job : jobs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (filter.matcher(job.name()).find())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                newJobs[n++] = job;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // Arrays.copyOf not available in JDK 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Job[] ret = new Job[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        System.arraycopy(newJobs, 0, ret, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private static void deoptimize(int sum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (sum == 42)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            System.out.println("the answer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Usage: [iterations=N] [size=N] [filter=REGEXP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        final int iterations = intArg(args, "iterations", 10000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        final int size       = intArg(args, "size", 1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        final Pattern filter = patternArg(args, "filter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        final Random rnd = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        final ByteBuffer b = ByteBuffer.allocateDirect(8*size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (int i = 0; i < b.limit(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            b.put(i, (byte) rnd.nextInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Job[] jobs = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            new Job("swap char BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    CharBuffer x = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            new Job("swap char LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    CharBuffer x = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            new Job("swap short BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    ShortBuffer x = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            new Job("swap short LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    ShortBuffer x = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            new Job("swap int BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    IntBuffer x = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            new Job("swap int LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    IntBuffer x = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            new Job("swap long BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    LongBuffer x = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            new Job("swap long LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    LongBuffer x = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        deoptimize(sum);}}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        time(filter(filter, jobs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}