jdk/test/java/nio/Buffer/SwapMicroBenchmark.java
author alanb
Wed, 15 Apr 2009 14:53:34 +0100
changeset 2593 76032557be03
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer Reviewed-by: sherman, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class SwapMicroBenchmark {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    abstract static class Job {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        public Job(String name) { this.name = name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        public String name() { return name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        public abstract void work() throws Throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static void collectAllGarbage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        final java.util.concurrent.CountDownLatch drained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            = new java.util.concurrent.CountDownLatch(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            System.gc();        // enqueue finalizable objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            new Object() { protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                drained.countDown(); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            System.gc();        // enqueue detector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            drained.await();    // wait for finalizer queue to drain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            System.gc();        // cleanup finalized objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        } catch (InterruptedException e) { throw new Error(e); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Runs each job for long enough that all the runtime compilers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * have had plenty of time to warm up, i.e. get around to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * compiling everything worth compiling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Returns array of average times per job per run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static long[] time0(Job ... jobs) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        final long warmupNanos = 10L * 1000L * 1000L * 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        long[] nanoss = new long[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        for (int i = 0; i < jobs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            collectAllGarbage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            long t0 = System.nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            long t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            do { jobs[i].work(); j++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            while ((t = System.nanoTime() - t0) < warmupNanos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            nanoss[i] = t/j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return nanoss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static void time(Job ... jobs) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        long[] warmup = time0(jobs); // Warm up run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        long[] nanoss = time0(jobs); // Real timing run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        long[] milliss = new long[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        double[] ratios = new double[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        final String nameHeader   = "Method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        final String millisHeader = "Millis";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        final String ratioHeader  = "Ratio";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        int nameWidth   = nameHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        int millisWidth = millisHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        int ratioWidth  = ratioHeader.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        for (int i = 0; i < jobs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            nameWidth = Math.max(nameWidth, jobs[i].name().length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            milliss[i] = nanoss[i]/(1000L * 1000L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            millisWidth = Math.max(millisWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                   String.format("%d", milliss[i]).length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            ratios[i] = (double) nanoss[i] / (double) nanoss[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            ratioWidth = Math.max(ratioWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                  String.format("%.3f", ratios[i]).length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                      nameWidth, millisWidth, ratioWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                            nameWidth, millisWidth, ratioWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        System.out.printf(headerFormat, "Method", "Millis", "Ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // Print out absolute and relative times, calibrated against first job
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        for (int i = 0; i < jobs.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static String keywordValue(String[] args, String keyword) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        for (String arg : args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (arg.startsWith(keyword))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                return arg.substring(keyword.length() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static int intArg(String[] args, String keyword, int defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        String val = keywordValue(args, keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return val == null ? defaultValue : Integer.parseInt(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private static Pattern patternArg(String[] args, String keyword) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        String val = keywordValue(args, keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return val == null ? null : Pattern.compile(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static Job[] filter(Pattern filter, Job[] jobs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (filter == null) return jobs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Job[] newJobs = new Job[jobs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (Job job : jobs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (filter.matcher(job.name()).find())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                newJobs[n++] = job;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // Arrays.copyOf not available in JDK 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Job[] ret = new Job[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        System.arraycopy(newJobs, 0, ret, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static void deoptimize(int sum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (sum == 42)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.out.println("the answer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Usage: [iterations=N] [size=N] [filter=REGEXP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        final int iterations = intArg(args, "iterations", 10000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        final int size       = intArg(args, "size", 1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        final Pattern filter = patternArg(args, "filter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        final Random rnd = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        final ByteBuffer b = ByteBuffer.allocateDirect(8*size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        for (int i = 0; i < b.limit(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            b.put(i, (byte) rnd.nextInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Job[] jobs = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            new Job("swap char BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    CharBuffer x = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            new Job("swap char LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    CharBuffer x = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            new Job("swap short BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    ShortBuffer x = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            new Job("swap short LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    ShortBuffer x = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            new Job("swap int BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    IntBuffer x = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            new Job("swap int LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    IntBuffer x = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            new Job("swap long BIG_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    LongBuffer x = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        deoptimize(sum);}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            new Job("swap long LITTLE_ENDIAN") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                public void work() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    LongBuffer x = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    for (int i = 0; i < iterations; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        int sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        for (int j = 0, end = x.limit(); j < end; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            sum += x.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        deoptimize(sum);}}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        time(filter(filter, jobs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}