1 /*
2 * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHPACER_HPP
25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHPACER_HPP
26
27 #include "memory/allocation.hpp"
28 #include "utilities/numberSeq.hpp"
29
30 class ShenandoahHeap;
31
32 #define PACING_PROGRESS_UNINIT (-1)
33 #define PACING_PROGRESS_ZERO ( 0)
34
35 /**
36 * ShenandoahPacer provides allocation pacing mechanism.
37 *
38 * Currently it implements simple tax-and-spend pacing policy: GC threads provide
39 * credit, allocating thread spend the credit, or stall when credit is not available.
40 */
41 class ShenandoahPacer : public CHeapObj<mtGC> {
42 private:
43 ShenandoahHeap* _heap;
44 volatile intptr_t _budget;
45 volatile jdouble _tax_rate;
46 BinaryMagnitudeSeq _delays;
47
48 volatile intptr_t _progress;
49 TruncatedSeq* _progress_history;
50 volatile intptr_t _epoch;
51
52 public:
53 ShenandoahPacer(ShenandoahHeap* heap) :
54 _heap(heap), _budget(0), _tax_rate(1),
55 _progress(PACING_PROGRESS_UNINIT),
56 _progress_history(new TruncatedSeq(5)),
57 _epoch(0) {
58 }
59
60 void setup_for_idle();
61 void setup_for_mark();
62 void setup_for_evac();
63 void setup_for_updaterefs();
64
65 inline void report_mark(size_t words);
66 inline void report_evac(size_t words);
67 inline void report_updaterefs(size_t words);
68
69 inline void report_alloc(size_t words);
70
71 bool claim_for_alloc(size_t words, bool force);
72 void pace_for_alloc(size_t words);
73 void unpace_for_alloc(intptr_t epoch, size_t words);
74
75 intptr_t epoch();
76
77 void print_on(outputStream* out) const;
|
1 /*
2 * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHPACER_HPP
25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHPACER_HPP
26
27 #include "gc_implementation/shenandoah/shenandoahNumberSeq.hpp"
28 #include "memory/allocation.hpp"
29
30 class ShenandoahHeap;
31
32 #define PACING_PROGRESS_UNINIT (-1)
33 #define PACING_PROGRESS_ZERO ( 0)
34
35 /**
36 * ShenandoahPacer provides allocation pacing mechanism.
37 *
38 * Currently it implements simple tax-and-spend pacing policy: GC threads provide
39 * credit, allocating thread spend the credit, or stall when credit is not available.
40 */
41 class ShenandoahPacer : public CHeapObj<mtGC> {
42 private:
43 ShenandoahHeap* _heap;
44 BinaryMagnitudeSeq _delays;
45 TruncatedSeq* _progress_history;
46
47 volatile intptr_t _epoch;
48 volatile jdouble _tax_rate;
49
50 char _pad0[DEFAULT_CACHE_LINE_SIZE];
51 volatile intptr_t _budget;
52 char _pad1[DEFAULT_CACHE_LINE_SIZE];
53 volatile intptr_t _progress;
54 char _pad2[DEFAULT_CACHE_LINE_SIZE];
55
56 public:
57 ShenandoahPacer(ShenandoahHeap* heap) :
58 _heap(heap),
59 _progress_history(new TruncatedSeq(5)),
60 _epoch(0),
61 _tax_rate(1),
62 _budget(0),
63 _progress(PACING_PROGRESS_UNINIT) {
64 }
65
66 void setup_for_idle();
67 void setup_for_mark();
68 void setup_for_evac();
69 void setup_for_updaterefs();
70
71 inline void report_mark(size_t words);
72 inline void report_evac(size_t words);
73 inline void report_updaterefs(size_t words);
74
75 inline void report_alloc(size_t words);
76
77 bool claim_for_alloc(size_t words, bool force);
78 void pace_for_alloc(size_t words);
79 void unpace_for_alloc(intptr_t epoch, size_t words);
80
81 intptr_t epoch();
82
83 void print_on(outputStream* out) const;
|