1 /*
2  * Copyright (c) 2020, 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_GC_G1_G1CONCURRENTREFINESTATS_HPP
26 #define SHARE_GC_G1_G1CONCURRENTREFINESTATS_HPP
27 
28 #include "memory/allocation.hpp"
29 #include "utilities/globalDefinitions.hpp"
30 #include "utilities/ticks.hpp"
31 
32 // Collection of statistics for concurrent refinement processing.
33 // Used for collecting per-thread statistics and for summaries over a
34 // collection of threads.
35 class G1ConcurrentRefineStats : public CHeapObj<mtGC> {
36   Tickspan _refinement_time;
37   size_t _refined_cards;
38   size_t _precleaned_cards;
39   size_t _dirtied_cards;
40 
41 public:
42   G1ConcurrentRefineStats();
43 
44   // Time spent performing concurrent refinement.
refinement_time() const45   Tickspan refinement_time() const { return _refinement_time; }
46 
47   // Number of refined cards.
refined_cards() const48   size_t refined_cards() const { return _refined_cards; }
49 
50   // Number of cards for which refinement was skipped because some other
51   // thread had already refined them.
precleaned_cards() const52   size_t precleaned_cards() const { return _precleaned_cards; }
53 
54   // Number of cards marked dirty and in need of refinement.
dirtied_cards() const55   size_t dirtied_cards() const { return _dirtied_cards; }
56 
inc_refinement_time(Tickspan t)57   void inc_refinement_time(Tickspan t) { _refinement_time += t; }
inc_refined_cards(size_t cards)58   void inc_refined_cards(size_t cards) { _refined_cards += cards; }
inc_precleaned_cards(size_t cards)59   void inc_precleaned_cards(size_t cards) { _precleaned_cards += cards; }
inc_dirtied_cards(size_t cards)60   void inc_dirtied_cards(size_t cards) { _dirtied_cards += cards; }
61 
62   G1ConcurrentRefineStats& operator+=(const G1ConcurrentRefineStats& other);
63   G1ConcurrentRefineStats& operator-=(const G1ConcurrentRefineStats& other);
64 
operator +(G1ConcurrentRefineStats x,const G1ConcurrentRefineStats & y)65   friend G1ConcurrentRefineStats operator+(G1ConcurrentRefineStats x,
66                                            const G1ConcurrentRefineStats& y) {
67     return x += y;
68   }
69 
operator -(G1ConcurrentRefineStats x,const G1ConcurrentRefineStats & y)70   friend G1ConcurrentRefineStats operator-(G1ConcurrentRefineStats x,
71                                            const G1ConcurrentRefineStats& y) {
72     return x -= y;
73   }
74 
75   void reset();
76 };
77 
78 #endif // SHARE_GC_G1_G1CONCURRENTREFINESTATS_HPP
79