|
1 /* |
|
2 * Copyright (c) 2016, 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 #include "precompiled.hpp" |
|
25 |
|
26 #include "gc/shenandoah/shenandoahHeap.hpp" |
|
27 #include "gc/shenandoah/shenandoahTaskqueue.hpp" |
|
28 #include "logging/log.hpp" |
|
29 #include "logging/logStream.hpp" |
|
30 |
|
31 void ShenandoahObjToScanQueueSet::clear() { |
|
32 uint size = GenericTaskQueueSet<ShenandoahObjToScanQueue, mtGC>::size(); |
|
33 for (uint index = 0; index < size; index ++) { |
|
34 ShenandoahObjToScanQueue* q = queue(index); |
|
35 assert(q != NULL, "Sanity"); |
|
36 q->clear(); |
|
37 } |
|
38 } |
|
39 |
|
40 bool ShenandoahObjToScanQueueSet::is_empty() { |
|
41 uint size = GenericTaskQueueSet<ShenandoahObjToScanQueue, mtGC>::size(); |
|
42 for (uint index = 0; index < size; index ++) { |
|
43 ShenandoahObjToScanQueue* q = queue(index); |
|
44 assert(q != NULL, "Sanity"); |
|
45 if (!q->is_empty()) { |
|
46 return false; |
|
47 } |
|
48 } |
|
49 return true; |
|
50 } |
|
51 |
|
52 class ShenandoahOWSTTerminator: public OWSTTaskTerminator { |
|
53 public: |
|
54 ShenandoahOWSTTerminator(uint n_threads, TaskQueueSetSuper* queue_set) : |
|
55 OWSTTaskTerminator(n_threads, queue_set){ } |
|
56 |
|
57 protected: |
|
58 bool exit_termination(size_t tasks, TerminatorTerminator* terminator); |
|
59 }; |
|
60 |
|
61 bool ShenandoahOWSTTerminator::exit_termination(size_t tasks, TerminatorTerminator* terminator) { |
|
62 ShenandoahTerminatorTerminator* t = (ShenandoahTerminatorTerminator*)terminator; |
|
63 bool force = (t != NULL) && t->should_force_termination(); |
|
64 if (force) { |
|
65 // Force termination : continue termination, even there are remaining tasks. |
|
66 return false; |
|
67 } else { |
|
68 return OWSTTaskTerminator::exit_termination(tasks, terminator); |
|
69 } |
|
70 } |
|
71 |
|
72 ShenandoahTaskTerminator::ShenandoahTaskTerminator(uint n_threads, TaskQueueSetSuper* queue_set) : |
|
73 _terminator(new ShenandoahOWSTTerminator(n_threads, queue_set)) { } |
|
74 |
|
75 ShenandoahTaskTerminator::~ShenandoahTaskTerminator() { |
|
76 assert(_terminator != NULL, "Invariant"); |
|
77 delete _terminator; |
|
78 } |
|
79 |
|
80 #if TASKQUEUE_STATS |
|
81 void ShenandoahObjToScanQueueSet::print_taskqueue_stats_hdr(outputStream* const st) { |
|
82 st->print_raw_cr("GC Task Stats"); |
|
83 st->print_raw("thr "); TaskQueueStats::print_header(1, st); st->cr(); |
|
84 st->print_raw("--- "); TaskQueueStats::print_header(2, st); st->cr(); |
|
85 } |
|
86 |
|
87 void ShenandoahObjToScanQueueSet::print_taskqueue_stats() const { |
|
88 if (!log_develop_is_enabled(Trace, gc, task, stats)) { |
|
89 return; |
|
90 } |
|
91 Log(gc, task, stats) log; |
|
92 ResourceMark rm; |
|
93 LogStream ls(log.trace()); |
|
94 outputStream* st = &ls; |
|
95 print_taskqueue_stats_hdr(st); |
|
96 |
|
97 ShenandoahObjToScanQueueSet* queues = const_cast<ShenandoahObjToScanQueueSet*>(this); |
|
98 TaskQueueStats totals; |
|
99 const uint n = size(); |
|
100 for (uint i = 0; i < n; ++i) { |
|
101 st->print(UINT32_FORMAT_W(3), i); |
|
102 queues->queue(i)->stats.print(st); |
|
103 st->cr(); |
|
104 totals += queues->queue(i)->stats; |
|
105 } |
|
106 st->print("tot "); totals.print(st); st->cr(); |
|
107 DEBUG_ONLY(totals.verify()); |
|
108 |
|
109 } |
|
110 |
|
111 void ShenandoahObjToScanQueueSet::reset_taskqueue_stats() { |
|
112 const uint n = size(); |
|
113 for (uint i = 0; i < n; ++i) { |
|
114 queue(i)->stats.reset(); |
|
115 } |
|
116 } |
|
117 #endif // TASKQUEUE_STATS |