hotspot/test/compiler/c1/TestPinnedIntrinsics.java
author thartmann
Fri, 14 Jul 2017 11:55:58 +0200
changeset 46663 715d5f268f62
permissions -rw-r--r--
8184271: Time related C1 intrinsics produce inconsistent results when floating around Summary: C1 intrinsics for System.nanoTime(), System.currentTimeMillis() and JVM.counterTime() should be pinned. Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46663
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     1
/*
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     4
 *
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     8
 *
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    13
 * accompanied this code).
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    14
 *
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    18
 *
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    21
 * questions.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    22
 */
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    23
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    24
/*
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    25
 * @test
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    26
 * @bug 8184271
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    27
 * @summary Test correct scheduling of System.nanoTime and System.currentTimeMillis C1 intrinsics.
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    28
 * @run main/othervm -XX:TieredStopAtLevel=1 -Xbatch
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    29
 *                   -XX:CompileCommand=dontinline,compiler.c1.TestPinnedIntrinsics::checkNanoTime
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    30
 *                   -XX:CompileCommand=dontinline,compiler.c1.TestPinnedIntrinsics::checkCurrentTimeMillis
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    31
 *                   compiler.c1.TestPinnedIntrinsics
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    32
 */
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    33
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    34
package compiler.c1;
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    35
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    36
public class TestPinnedIntrinsics {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    37
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    38
    private static void testNanoTime() {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    39
        long start = System.nanoTime();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    40
        long end = System.nanoTime();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    41
        checkNanoTime(end - start);
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    42
    }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    43
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    44
    private static void checkNanoTime(long diff) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    45
        if (diff < 0) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    46
            throw new RuntimeException("testNanoTime failed with " + diff);
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    47
        }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    48
    }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    49
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    50
    private static void testCurrentTimeMillis() {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    51
        long start = System.currentTimeMillis();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    52
        long end = System.currentTimeMillis();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    53
        checkCurrentTimeMillis(end - start);
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    54
    }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    55
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    56
    private static void checkCurrentTimeMillis(long diff) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    57
        if (diff < 0) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    58
            throw new RuntimeException("testCurrentTimeMillis failed with " + diff);
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    59
        }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    60
    }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    61
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    62
    public static void main(String[] args) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    63
        for (int i = 0; i < 100_000; ++i) {
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    64
            testNanoTime();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    65
            testCurrentTimeMillis();
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    66
        }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    67
    }
715d5f268f62 8184271: Time related C1 intrinsics produce inconsistent results when floating around
thartmann
parents:
diff changeset
    68
}