1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
45 static void do_time_measurements(volatile jlong& time_base,
46 volatile jlong& time_fast,
47 volatile jlong& time_base_elapsed,
48 volatile jlong& time_fast_elapsed) {
49 static const unsigned int FT_SLEEP_MILLISECS = 1;
50 const unsigned int loopcount = 3;
51
52 volatile jlong start = 0;
53 volatile jlong fstart = 0;
54 volatile jlong end = 0;
55 volatile jlong fend = 0;
56
57 // Figure out the difference between rdtsc and os provided timer.
58 // base algorithm adopted from JRockit.
59 for (unsigned int times = 0; times < loopcount; times++) {
60 start = os::elapsed_counter();
61 OrderAccess::fence();
62 fstart = os::rdtsc();
63
64 // use sleep to prevent compiler from optimizing
65 os::sleep(Thread::current(), FT_SLEEP_MILLISECS, true);
66
67 end = os::elapsed_counter();
68 OrderAccess::fence();
69 fend = os::rdtsc();
70
71 time_base += end - start;
72 time_fast += fend - fstart;
73
74 // basis for calculating the os tick start
75 // to fast time tick start offset
76 time_base_elapsed += end;
77 time_fast_elapsed += (fend - _epoch);
78 }
79
80 time_base /= loopcount;
81 time_fast /= loopcount;
82 time_base_elapsed /= loopcount;
83 time_fast_elapsed /= loopcount;
84 }
85
|
1 /*
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
45 static void do_time_measurements(volatile jlong& time_base,
46 volatile jlong& time_fast,
47 volatile jlong& time_base_elapsed,
48 volatile jlong& time_fast_elapsed) {
49 static const unsigned int FT_SLEEP_MILLISECS = 1;
50 const unsigned int loopcount = 3;
51
52 volatile jlong start = 0;
53 volatile jlong fstart = 0;
54 volatile jlong end = 0;
55 volatile jlong fend = 0;
56
57 // Figure out the difference between rdtsc and os provided timer.
58 // base algorithm adopted from JRockit.
59 for (unsigned int times = 0; times < loopcount; times++) {
60 start = os::elapsed_counter();
61 OrderAccess::fence();
62 fstart = os::rdtsc();
63
64 // use sleep to prevent compiler from optimizing
65 os::sleep(JavaThread::current(), FT_SLEEP_MILLISECS);
66
67 end = os::elapsed_counter();
68 OrderAccess::fence();
69 fend = os::rdtsc();
70
71 time_base += end - start;
72 time_fast += fend - fstart;
73
74 // basis for calculating the os tick start
75 // to fast time tick start offset
76 time_base_elapsed += end;
77 time_fast_elapsed += (fend - _epoch);
78 }
79
80 time_base /= loopcount;
81 time_fast /= loopcount;
82 time_base_elapsed /= loopcount;
83 time_fast_elapsed /= loopcount;
84 }
85
|