test/compiler/c1/TestPinnedIntrinsics.java

Thu, 10 Aug 2017 12:08:50 +0530

author
thartmann
date
Thu, 10 Aug 2017 12:08:50 +0530
changeset 8884
35fe0be5277b
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, iveresov

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

mercurial