src/share/vm/runtime/task.cpp

Wed, 18 Sep 2013 07:02:10 -0700

author
dcubed
date
Wed, 18 Sep 2013 07:02:10 -0700
changeset 5743
63147986a428
parent 5237
f2110083203d
child 6429
606acabe7b5c
permissions
-rw-r--r--

8019835: Strings interned in different threads equal but does not ==
Summary: Add -XX:+VerifyStringTableAtExit option and code to verify StringTable invariants.
Reviewed-by: rdurbin, sspitsyn, coleenp

duke@435 1 /*
sla@5237 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "memory/allocation.hpp"
stefank@2314 27 #include "runtime/init.hpp"
stefank@2314 28 #include "runtime/task.hpp"
stefank@4299 29 #include "runtime/thread.inline.hpp"
stefank@2314 30 #include "runtime/timer.hpp"
stefank@2314 31 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 32 # include "os_linux.inline.hpp"
stefank@2314 33 #endif
stefank@2314 34 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 35 # include "os_solaris.inline.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 38 # include "os_windows.inline.hpp"
stefank@2314 39 #endif
never@3156 40 #ifdef TARGET_OS_FAMILY_bsd
never@3156 41 # include "os_bsd.inline.hpp"
never@3156 42 #endif
duke@435 43
duke@435 44 int PeriodicTask::_num_tasks = 0;
duke@435 45 PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks];
duke@435 46 #ifndef PRODUCT
duke@435 47 elapsedTimer PeriodicTask::_timer;
duke@435 48 int PeriodicTask::_intervalHistogram[PeriodicTask::max_interval];
duke@435 49 int PeriodicTask::_ticks;
duke@435 50
duke@435 51 void PeriodicTask::print_intervals() {
duke@435 52 if (ProfilerCheckIntervals) {
duke@435 53 for (int i = 0; i < PeriodicTask::max_interval; i++) {
duke@435 54 int n = _intervalHistogram[i];
duke@435 55 if (n > 0) tty->print_cr("%3d: %5d (%4.1f%%)", i, n, 100.0 * n / _ticks);
duke@435 56 }
duke@435 57 }
duke@435 58 }
duke@435 59 #endif
duke@435 60
rbackman@4250 61 void PeriodicTask::real_time_tick(int delay_time) {
duke@435 62 #ifndef PRODUCT
duke@435 63 if (ProfilerCheckIntervals) {
duke@435 64 _ticks++;
duke@435 65 _timer.stop();
duke@435 66 int ms = (int)(_timer.seconds() * 1000.0);
duke@435 67 _timer.reset();
duke@435 68 _timer.start();
duke@435 69 if (ms >= PeriodicTask::max_interval) ms = PeriodicTask::max_interval - 1;
duke@435 70 _intervalHistogram[ms]++;
duke@435 71 }
duke@435 72 #endif
rbackman@4250 73
rbackman@4250 74 {
rbackman@4250 75 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
rbackman@4250 76 int orig_num_tasks = _num_tasks;
rbackman@4250 77
rbackman@4250 78 for(int index = 0; index < _num_tasks; index++) {
rbackman@4250 79 _tasks[index]->execute_if_pending(delay_time);
rbackman@4250 80 if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself
rbackman@4250 81 index--; // re-do current slot as it has changed
rbackman@4250 82 orig_num_tasks = _num_tasks;
rbackman@4250 83 }
duke@435 84 }
duke@435 85 }
duke@435 86 }
duke@435 87
rbackman@4250 88 int PeriodicTask::time_to_wait() {
rbackman@4250 89 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
rbackman@4250 90 NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
rbackman@4250 91
rbackman@4250 92 if (_num_tasks == 0) {
rbackman@4250 93 return 0; // sleep until shutdown or a task is enrolled
rbackman@4250 94 }
rbackman@4250 95
rbackman@4250 96 int delay = _tasks[0]->time_to_next_interval();
rbackman@4250 97 for (int index = 1; index < _num_tasks; index++) {
rbackman@4250 98 delay = MIN2(delay, _tasks[index]->time_to_next_interval());
rbackman@4250 99 }
rbackman@4250 100 return delay;
rbackman@4250 101 }
rbackman@4250 102
duke@435 103
duke@435 104 PeriodicTask::PeriodicTask(size_t interval_time) :
rbackman@4250 105 _counter(0), _interval((int) interval_time) {
duke@435 106 // Sanity check the interval time
duke@435 107 assert(_interval >= PeriodicTask::min_interval &&
duke@435 108 _interval <= PeriodicTask::max_interval &&
duke@435 109 _interval % PeriodicTask::interval_gran == 0,
duke@435 110 "improper PeriodicTask interval time");
duke@435 111 }
duke@435 112
duke@435 113 PeriodicTask::~PeriodicTask() {
rbackman@4250 114 disenroll();
duke@435 115 }
duke@435 116
sla@5237 117 /* enroll could be called from a JavaThread, so we have to check for
sla@5237 118 * safepoint when taking the lock to avoid deadlocking */
duke@435 119 void PeriodicTask::enroll() {
rbackman@4250 120 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
sla@5237 121 NULL : PeriodicTask_lock);
duke@435 122
rbackman@4250 123 if (_num_tasks == PeriodicTask::max_tasks) {
duke@435 124 fatal("Overflow in PeriodicTask table");
rbackman@4250 125 }
duke@435 126 _tasks[_num_tasks++] = this;
rbackman@4250 127
rbackman@4250 128 WatcherThread* thread = WatcherThread::watcher_thread();
rbackman@4250 129 if (thread) {
rbackman@4250 130 thread->unpark();
rbackman@4250 131 } else {
rbackman@4250 132 WatcherThread::start();
rbackman@4250 133 }
duke@435 134 }
duke@435 135
sla@5237 136 /* disenroll could be called from a JavaThread, so we have to check for
sla@5237 137 * safepoint when taking the lock to avoid deadlocking */
duke@435 138 void PeriodicTask::disenroll() {
rbackman@4250 139 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
sla@5237 140 NULL : PeriodicTask_lock);
duke@435 141
duke@435 142 int index;
rbackman@4250 143 for(index = 0; index < _num_tasks && _tasks[index] != this; index++)
rbackman@4250 144 ;
rbackman@4250 145
rbackman@4250 146 if (index == _num_tasks) {
rbackman@4250 147 return;
rbackman@4250 148 }
rbackman@4250 149
duke@435 150 _num_tasks--;
rbackman@4250 151
duke@435 152 for (; index < _num_tasks; index++) {
duke@435 153 _tasks[index] = _tasks[index+1];
duke@435 154 }
duke@435 155 }

mercurial