1 /* 2 * Copyright (c) 2001, 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 #include "precompiled.hpp" 26 #include "gc/shared/taskqueue.hpp" 27 #include "oops/oop.inline.hpp" 28 #include "logging/log.hpp" 29 #include "runtime/atomic.hpp" 30 #include "runtime/os.hpp" 31 #include "runtime/thread.inline.hpp" 32 #include "utilities/debug.hpp" 33 #include "utilities/stack.inline.hpp" 34 35 #if TASKQUEUE_STATS 36 const char * const TaskQueueStats::_names[last_stat_id] = { 37 "qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax" 38 }; 39 40 TaskQueueStats & TaskQueueStats::operator +=(const TaskQueueStats & addend) 41 { 42 for (unsigned int i = 0; i < last_stat_id; ++i) { 43 _stats[i] += addend._stats[i]; 44 } 45 return *this; 46 } 47 48 void TaskQueueStats::print_header(unsigned int line, outputStream* const stream, 49 unsigned int width) 50 { 51 // Use a width w: 1 <= w <= max_width 52 const unsigned int max_width = 40; 53 const unsigned int w = clamp(width, 1u, max_width); 54 55 if (line == 0) { // spaces equal in width to the header 56 const unsigned int hdr_width = w * last_stat_id + last_stat_id - 1; 57 stream->print("%*s", hdr_width, " "); 58 } else if (line == 1) { // labels 59 stream->print("%*s", w, _names[0]); 60 for (unsigned int i = 1; i < last_stat_id; ++i) { 61 stream->print(" %*s", w, _names[i]); 62 } 63 } else if (line == 2) { // dashed lines 64 char dashes[max_width + 1]; 65 memset(dashes, '-', w); 66 dashes[w] = '\0'; 67 stream->print("%s", dashes); 68 for (unsigned int i = 1; i < last_stat_id; ++i) { 69 stream->print(" %s", dashes); 70 } 71 } 72 } 73 74 void TaskQueueStats::print(outputStream* stream, unsigned int width) const 75 { 76 #define FMT SIZE_FORMAT_W(*) 77 stream->print(FMT, width, _stats[0]); 78 for (unsigned int i = 1; i < last_stat_id; ++i) { 79 stream->print(" " FMT, width, _stats[i]); 80 } 81 #undef FMT 82 } 83 84 #ifdef ASSERT 85 // Invariants which should hold after a TaskQueue has been emptied and is 86 // quiescent; they do not hold at arbitrary times. 87 void TaskQueueStats::verify() const 88 { 89 assert(get(push) == get(pop) + get(steal), 90 "push=" SIZE_FORMAT " pop=" SIZE_FORMAT " steal=" SIZE_FORMAT, 91 get(push), get(pop), get(steal)); 92 assert(get(pop_slow) <= get(pop), 93 "pop_slow=" SIZE_FORMAT " pop=" SIZE_FORMAT, 94 get(pop_slow), get(pop)); 95 assert(get(steal) <= get(steal_attempt), 96 "steal=" SIZE_FORMAT " steal_attempt=" SIZE_FORMAT, 97 get(steal), get(steal_attempt)); 98 assert(get(overflow) == 0 || get(push) != 0, 99 "overflow=" SIZE_FORMAT " push=" SIZE_FORMAT, 100 get(overflow), get(push)); 101 assert(get(overflow_max_len) == 0 || get(overflow) != 0, 102 "overflow_max_len=" SIZE_FORMAT " overflow=" SIZE_FORMAT, 103 get(overflow_max_len), get(overflow)); 104 } 105 #endif // ASSERT 106 #endif // TASKQUEUE_STATS 107 108 #ifdef ASSERT 109 bool ObjArrayTask::is_valid() const { 110 return _obj != NULL && _obj->is_objArray() && _index >= 0 && 111 _index < objArrayOop(_obj)->length(); 112 } 113 #endif // ASSERT