src/share/vm/runtime/task.hpp

Thu, 21 Nov 2013 12:30:35 -0800

author
kvn
date
Thu, 21 Nov 2013 12:30:35 -0800
changeset 6485
da862781b584
parent 4250
c284cf4781f0
child 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

duke@435 1 /*
mikael@4153 2 * Copyright (c) 1997, 2012, 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 #ifndef SHARE_VM_RUNTIME_TASK_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_TASK_HPP
stefank@2314 27
stefank@2314 28 #include "utilities/top.hpp"
stefank@2314 29
duke@435 30 // A PeriodicTask has the sole purpose of executing its task
duke@435 31 // function with regular intervals.
duke@435 32 // Usage:
duke@435 33 // PeriodicTask pf(10);
duke@435 34 // pf.enroll();
duke@435 35 // ...
duke@435 36 // pf.disenroll();
duke@435 37
zgu@3900 38 class PeriodicTask: public CHeapObj<mtInternal> {
duke@435 39 public:
duke@435 40 // Useful constants.
duke@435 41 // The interval constants are used to ensure the declared interval
duke@435 42 // is appropriate; it must be between min_interval and max_interval,
duke@435 43 // and have a granularity of interval_gran (all in millis).
duke@435 44 enum { max_tasks = 10, // Max number of periodic tasks in system
duke@435 45 interval_gran = 10,
duke@435 46 min_interval = 10,
duke@435 47 max_interval = 10000 };
duke@435 48
duke@435 49 static int num_tasks() { return _num_tasks; }
duke@435 50
duke@435 51 private:
rbackman@4250 52 int _counter;
rbackman@4250 53 const int _interval;
duke@435 54
duke@435 55 static int _num_tasks;
duke@435 56 static PeriodicTask* _tasks[PeriodicTask::max_tasks];
rbackman@4250 57 static void real_time_tick(int delay_time);
duke@435 58
duke@435 59 #ifndef PRODUCT
duke@435 60 static elapsedTimer _timer; // measures time between ticks
duke@435 61 static int _ticks; // total number of ticks
duke@435 62 static int _intervalHistogram[max_interval]; // to check spacing of timer interrupts
duke@435 63 public:
duke@435 64 static void print_intervals();
duke@435 65 #endif
duke@435 66 // Only the WatcherThread can cause us to execute PeriodicTasks
duke@435 67 friend class WatcherThread;
duke@435 68 public:
duke@435 69 PeriodicTask(size_t interval_time); // interval is in milliseconds of elapsed time
duke@435 70 ~PeriodicTask();
duke@435 71
duke@435 72 // Make the task active
rbackman@4250 73 // For dynamic enrollment at the time T, the task will execute somewhere
rbackman@4250 74 // between T and T + interval_time.
duke@435 75 void enroll();
duke@435 76
duke@435 77 // Make the task deactive
duke@435 78 void disenroll();
duke@435 79
rbackman@4250 80 void execute_if_pending(int delay_time) {
rbackman@4250 81 // make sure we don't overflow
rbackman@4250 82 jlong tmp = (jlong) _counter + (jlong) delay_time;
rbackman@4250 83
rbackman@4250 84 if (tmp >= (jlong) _interval) {
duke@435 85 _counter = 0;
duke@435 86 task();
rbackman@4250 87 } else {
rbackman@4250 88 _counter += delay_time;
duke@435 89 }
duke@435 90 }
duke@435 91
duke@435 92 // Returns how long (time in milliseconds) before the next time we should
duke@435 93 // execute this task.
rbackman@4250 94 int time_to_next_interval() const {
duke@435 95 assert(_interval > _counter, "task counter greater than interval?");
duke@435 96 return _interval - _counter;
duke@435 97 }
duke@435 98
duke@435 99 // Calculate when the next periodic task will fire.
duke@435 100 // Called by the WatcherThread's run method.
rbackman@4250 101 static int time_to_wait();
duke@435 102
duke@435 103 // The task to perform at each period
duke@435 104 virtual void task() = 0;
duke@435 105 };
stefank@2314 106
stefank@2314 107 #endif // SHARE_VM_RUNTIME_TASK_HPP

mercurial