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 * 23 */ 24 25 #ifndef SHARE_VM_UTILITIES_TICKS_HPP 26 #define SHARE_VM_UTILITIES_TICKS_HPP 27 28 #include "memory/allocation.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 31 class Ticks; 32 33 class Tickspan { 34 friend class Ticks; 35 friend Tickspan operator-(const Ticks& end, const Ticks& start); 36 37 private: 38 jlong _span_ticks; 39 40 Tickspan(const Ticks& end, const Ticks& start); 41 42 public: 43 Tickspan() : _span_ticks(0) {} 44 45 Tickspan& operator+=(const Tickspan& rhs) { 46 _span_ticks += rhs._span_ticks; 47 return *this; 48 } 49 50 Tickspan& operator-=(const Tickspan& rhs) { 51 _span_ticks -= rhs._span_ticks; 52 return *this; 53 } 54 55 jlong value() const { 56 return _span_ticks; 57 } 58 59 }; 60 61 class Ticks { 62 private: 63 jlong _stamp_ticks; 64 65 public: 66 Ticks() : _stamp_ticks(0) { 67 assert((_stamp_ticks = invalid_time_stamp) == invalid_time_stamp, 68 "initial unstamped time value assignment"); 69 } 70 71 Ticks& operator+=(const Tickspan& span) { 72 _stamp_ticks += span.value(); 73 return *this; 74 } 75 76 Ticks& operator-=(const Tickspan& span) { 77 _stamp_ticks -= span.value(); 78 return *this; 79 } 80 81 void stamp(); 82 83 jlong value() const { 84 return _stamp_ticks; 85 } 86 87 static const Ticks now(); 88 89 #ifdef ASSERT 90 static const jlong invalid_time_stamp; 91 #endif 92 93 #ifndef PRODUCT 94 // only for internal use by GC VM tests 95 friend class TimePartitionPhasesIteratorTest; 96 friend class GCTimerTest; 97 98 private: 99 // implicit type conversion 100 Ticks(int ticks) : _stamp_ticks(ticks) {} 101 102 #endif // !PRODUCT 103 104 }; 105 106 class TicksToTimeHelper : public AllStatic { 107 public: 108 enum Unit { 109 SECONDS = 1, 110 MILLISECONDS = 1000 111 }; 112 static double seconds(const Tickspan& span); 113 static jlong milliseconds(const Tickspan& span); 114 }; 115 116 #endif // SHARE_VM_UTILITIES_TICKS_HPP