1 /*
2 * Copyright (c) 2018, 2019, Red Hat, Inc. 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_SHENANDOAH_SHENANDOAHPACER_INLINE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHPACER_INLINE_HPP
27
28 #include "gc/shenandoah/shenandoahPacer.hpp"
29
30 #include "runtime/atomic.hpp"
31
32 inline void ShenandoahPacer::report_mark(size_t words) {
33 report_internal(words);
34 report_progress_internal(words);
35 }
36
37 inline void ShenandoahPacer::report_evac(size_t words) {
38 report_internal(words);
39 }
40
41 inline void ShenandoahPacer::report_update_refs(size_t words) {
42 report_internal(words);
43 }
44
45 inline void ShenandoahPacer::report_alloc(size_t words) {
46 report_internal(words);
47 }
48
49 inline void ShenandoahPacer::report_internal(size_t words) {
50 assert(ShenandoahPacing, "Only be here when pacing is enabled");
51 add_budget(words);
52 }
53
54 inline void ShenandoahPacer::report_progress_internal(size_t words) {
55 assert(ShenandoahPacing, "Only be here when pacing is enabled");
56 STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
57 Atomic::add(&_progress, (intptr_t)words, memory_order_relaxed);
58 }
59
60 inline void ShenandoahPacer::add_budget(size_t words) {
61 STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
62 intptr_t inc = (intptr_t) words;
63 intptr_t new_budget = Atomic::add(&_budget, inc, memory_order_relaxed);
64
65 // Was the budget replenished beyond zero? Then all pacing claims
66 // are satisfied, notify the waiters. Avoid taking any locks here,
67 // as it can be called from hot paths and/or while holding other locks.
68 if (new_budget >= 0 && (new_budget - inc) < 0) {
69 _need_notify_waiters.try_set();
70 }
71 }
72
73 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPACER_INLINE_HPP