Wed, 13 Jan 2010 23:05:52 -0800
6912065: final fields in objects need to support inlining optimizations for JSR 292
Reviewed-by: twisti, kvn
1 /*
2 * Copyright 1997-2008 Sun Microsystems, 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 # include "incls/_precompiled.incl"
26 # include "incls/_task.cpp.incl"
28 int PeriodicTask::_num_tasks = 0;
29 PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks];
30 #ifndef PRODUCT
31 elapsedTimer PeriodicTask::_timer;
32 int PeriodicTask::_intervalHistogram[PeriodicTask::max_interval];
33 int PeriodicTask::_ticks;
35 void PeriodicTask::print_intervals() {
36 if (ProfilerCheckIntervals) {
37 for (int i = 0; i < PeriodicTask::max_interval; i++) {
38 int n = _intervalHistogram[i];
39 if (n > 0) tty->print_cr("%3d: %5d (%4.1f%%)", i, n, 100.0 * n / _ticks);
40 }
41 }
42 }
43 #endif
45 void PeriodicTask::real_time_tick(size_t delay_time) {
46 #ifndef PRODUCT
47 if (ProfilerCheckIntervals) {
48 _ticks++;
49 _timer.stop();
50 int ms = (int)(_timer.seconds() * 1000.0);
51 _timer.reset();
52 _timer.start();
53 if (ms >= PeriodicTask::max_interval) ms = PeriodicTask::max_interval - 1;
54 _intervalHistogram[ms]++;
55 }
56 #endif
57 int orig_num_tasks = _num_tasks;
58 for(int index = 0; index < _num_tasks; index++) {
59 _tasks[index]->execute_if_pending(delay_time);
60 if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself
61 index--; // re-do current slot as it has changed
62 orig_num_tasks = _num_tasks;
63 }
64 }
65 }
68 PeriodicTask::PeriodicTask(size_t interval_time) :
69 _counter(0), _interval(interval_time) {
70 // Sanity check the interval time
71 assert(_interval >= PeriodicTask::min_interval &&
72 _interval <= PeriodicTask::max_interval &&
73 _interval % PeriodicTask::interval_gran == 0,
74 "improper PeriodicTask interval time");
75 }
77 PeriodicTask::~PeriodicTask() {
78 if (is_enrolled())
79 disenroll();
80 }
82 bool PeriodicTask::is_enrolled() const {
83 for(int index = 0; index < _num_tasks; index++)
84 if (_tasks[index] == this) return true;
85 return false;
86 }
88 void PeriodicTask::enroll() {
89 assert(WatcherThread::watcher_thread() == NULL, "dynamic enrollment of tasks not yet supported");
91 if (_num_tasks == PeriodicTask::max_tasks)
92 fatal("Overflow in PeriodicTask table");
93 _tasks[_num_tasks++] = this;
94 }
96 void PeriodicTask::disenroll() {
97 assert(WatcherThread::watcher_thread() == NULL ||
98 Thread::current() == WatcherThread::watcher_thread(),
99 "dynamic disenrollment currently only handled from WatcherThread from within task() method");
101 int index;
102 for(index = 0; index < _num_tasks && _tasks[index] != this; index++);
103 if (index == _num_tasks) return;
104 _num_tasks--;
105 for (; index < _num_tasks; index++) {
106 _tasks[index] = _tasks[index+1];
107 }
108 }