Fri, 05 Oct 2012 18:57:10 -0700
7177003: C1: LogCompilation support
Summary: add LogCompilation support in C1 - both client and tiered mode.
Reviewed-by: twisti, kvn
duke@435 | 1 | /* |
ysr@2192 | 2 | * Copyright (c) 2005, 2010, 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_UTILITIES_YIELDINGWORKGROUP_HPP |
stefank@2314 | 26 | #define SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #ifndef SERIALGC |
stefank@2314 | 29 | #include "utilities/workgroup.hpp" |
stefank@2314 | 30 | #endif |
stefank@2314 | 31 | |
duke@435 | 32 | |
duke@435 | 33 | // Forward declarations |
duke@435 | 34 | class YieldingFlexibleWorkGang; |
duke@435 | 35 | |
duke@435 | 36 | // Status of tasks |
duke@435 | 37 | enum Status { |
duke@435 | 38 | INACTIVE, |
duke@435 | 39 | ACTIVE, |
duke@435 | 40 | YIELDING, |
duke@435 | 41 | YIELDED, |
duke@435 | 42 | ABORTING, |
duke@435 | 43 | ABORTED, |
duke@435 | 44 | COMPLETING, |
duke@435 | 45 | COMPLETED |
duke@435 | 46 | }; |
duke@435 | 47 | |
duke@435 | 48 | // Class YieldingFlexibleGangWorker: |
duke@435 | 49 | // Several instances of this class run in parallel as workers for a gang. |
duke@435 | 50 | class YieldingFlexibleGangWorker: public GangWorker { |
duke@435 | 51 | public: |
duke@435 | 52 | // Ctor |
duke@435 | 53 | YieldingFlexibleGangWorker(AbstractWorkGang* gang, int id) : |
duke@435 | 54 | GangWorker(gang, id) { } |
duke@435 | 55 | |
duke@435 | 56 | public: |
duke@435 | 57 | YieldingFlexibleWorkGang* yf_gang() const |
duke@435 | 58 | { return (YieldingFlexibleWorkGang*)gang(); } |
duke@435 | 59 | |
duke@435 | 60 | protected: // Override from parent class |
duke@435 | 61 | virtual void loop(); |
duke@435 | 62 | }; |
duke@435 | 63 | |
jmasa@2188 | 64 | class FlexibleGangTask: public AbstractGangTask { |
jmasa@2188 | 65 | int _actual_size; // size of gang obtained |
jmasa@2188 | 66 | protected: |
jmasa@2188 | 67 | int _requested_size; // size of gang requested |
jmasa@2188 | 68 | public: |
jmasa@2188 | 69 | FlexibleGangTask(const char* name): AbstractGangTask(name), |
jmasa@2188 | 70 | _requested_size(0) {} |
jmasa@2188 | 71 | |
jmasa@2188 | 72 | // The abstract work method. |
jmasa@2188 | 73 | // The argument tells you which member of the gang you are. |
jmasa@3357 | 74 | virtual void work(uint worker_id) = 0; |
jmasa@2188 | 75 | |
jmasa@2188 | 76 | int requested_size() const { return _requested_size; } |
jmasa@2188 | 77 | int actual_size() const { return _actual_size; } |
jmasa@2188 | 78 | |
jmasa@2188 | 79 | void set_requested_size(int sz) { _requested_size = sz; } |
jmasa@2188 | 80 | void set_actual_size(int sz) { _actual_size = sz; } |
jmasa@2188 | 81 | }; |
jmasa@2188 | 82 | |
duke@435 | 83 | // An abstract task to be worked on by a flexible work gang, |
duke@435 | 84 | // and where the workers will periodically yield, usually |
duke@435 | 85 | // in response to some condition that is signalled by means |
duke@435 | 86 | // that are specific to the task at hand. |
duke@435 | 87 | // You subclass this to supply your own work() method. |
duke@435 | 88 | // A second feature of this kind of work gang is that |
duke@435 | 89 | // it allows for the signalling of certain exceptional |
duke@435 | 90 | // conditions that may be encountered during the performance |
duke@435 | 91 | // of the task and that may require the task at hand to be |
duke@435 | 92 | // `aborted' forthwith. Finally, these gangs are `flexible' |
duke@435 | 93 | // in that they can operate at partial capacity with some |
duke@435 | 94 | // gang workers waiting on the bench; in other words, the |
duke@435 | 95 | // size of the active worker pool can flex (up to an apriori |
duke@435 | 96 | // maximum) in response to task requests at certain points. |
duke@435 | 97 | // The last part (the flexible part) has not yet been fully |
duke@435 | 98 | // fleshed out and is a work in progress. |
jmasa@2188 | 99 | class YieldingFlexibleGangTask: public FlexibleGangTask { |
duke@435 | 100 | Status _status; |
duke@435 | 101 | YieldingFlexibleWorkGang* _gang; |
duke@435 | 102 | |
duke@435 | 103 | protected: |
duke@435 | 104 | // Constructor and desctructor: only construct subclasses. |
jmasa@2188 | 105 | YieldingFlexibleGangTask(const char* name): FlexibleGangTask(name), |
duke@435 | 106 | _status(INACTIVE), |
jmasa@2188 | 107 | _gang(NULL) { } |
duke@435 | 108 | |
duke@435 | 109 | virtual ~YieldingFlexibleGangTask() { } |
duke@435 | 110 | |
duke@435 | 111 | friend class YieldingFlexibleWorkGang; |
duke@435 | 112 | friend class YieldingFlexibleGangWorker; |
duke@435 | 113 | NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const { |
duke@435 | 114 | return true; |
duke@435 | 115 | }) |
duke@435 | 116 | |
duke@435 | 117 | void set_status(Status s) { |
duke@435 | 118 | _status = s; |
duke@435 | 119 | } |
duke@435 | 120 | YieldingFlexibleWorkGang* gang() { |
duke@435 | 121 | return _gang; |
duke@435 | 122 | } |
duke@435 | 123 | void set_gang(YieldingFlexibleWorkGang* gang) { |
duke@435 | 124 | assert(_gang == NULL || gang == NULL, "Clobber without intermediate reset?"); |
duke@435 | 125 | _gang = gang; |
duke@435 | 126 | } |
duke@435 | 127 | |
duke@435 | 128 | public: |
duke@435 | 129 | // The abstract work method. |
duke@435 | 130 | // The argument tells you which member of the gang you are. |
jmasa@3357 | 131 | virtual void work(uint worker_id) = 0; |
duke@435 | 132 | |
duke@435 | 133 | // Subclasses should call the parent's yield() method |
duke@435 | 134 | // after having done any work specific to the subclass. |
duke@435 | 135 | virtual void yield(); |
duke@435 | 136 | |
duke@435 | 137 | // An abstract method supplied by |
duke@435 | 138 | // a concrete sub-class which is used by the coordinator |
duke@435 | 139 | // to do any "central yielding" work. |
duke@435 | 140 | virtual void coordinator_yield() = 0; |
duke@435 | 141 | |
duke@435 | 142 | // Subclasses should call the parent's abort() method |
duke@435 | 143 | // after having done any work specific to the sunbclass. |
duke@435 | 144 | virtual void abort(); |
duke@435 | 145 | |
duke@435 | 146 | Status status() const { return _status; } |
ysr@2192 | 147 | bool yielding() const { return _status == YIELDING; } |
duke@435 | 148 | bool yielded() const { return _status == YIELDED; } |
duke@435 | 149 | bool completed() const { return _status == COMPLETED; } |
duke@435 | 150 | bool aborted() const { return _status == ABORTED; } |
duke@435 | 151 | bool active() const { return _status == ACTIVE; } |
duke@435 | 152 | }; |
duke@435 | 153 | // Class YieldingWorkGang: A subclass of WorkGang. |
duke@435 | 154 | // In particular, a YieldingWorkGang is made up of |
duke@435 | 155 | // YieldingGangWorkers, and provides infrastructure |
duke@435 | 156 | // supporting yielding to the "GangOverseer", |
duke@435 | 157 | // being the thread that orchestrates the WorkGang via run_task(). |
jmasa@2188 | 158 | class YieldingFlexibleWorkGang: public FlexibleWorkGang { |
duke@435 | 159 | // Here's the public interface to this class. |
duke@435 | 160 | public: |
duke@435 | 161 | // Constructor and destructor. |
jmasa@3357 | 162 | YieldingFlexibleWorkGang(const char* name, uint workers, |
ysr@777 | 163 | bool are_GC_task_threads); |
duke@435 | 164 | |
duke@435 | 165 | YieldingFlexibleGangTask* yielding_task() const { |
duke@435 | 166 | assert(task() == NULL || task()->is_YieldingFlexibleGang_task(), |
duke@435 | 167 | "Incorrect cast"); |
duke@435 | 168 | return (YieldingFlexibleGangTask*)task(); |
duke@435 | 169 | } |
jmasa@2188 | 170 | // Allocate a worker and return a pointer to it. |
jmasa@3357 | 171 | GangWorker* allocate_worker(uint which); |
jmasa@2188 | 172 | |
duke@435 | 173 | // Run a task; returns when the task is done, or the workers yield, |
duke@435 | 174 | // or the task is aborted, or the work gang is terminated via stop(). |
duke@435 | 175 | // A task that has been yielded can be continued via this same interface |
duke@435 | 176 | // by using the same task repeatedly as the argument to the call. |
duke@435 | 177 | // It is expected that the YieldingFlexibleGangTask carries the appropriate |
duke@435 | 178 | // continuation information used by workers to continue the task |
duke@435 | 179 | // from its last yield point. Thus, a completed task will return |
duke@435 | 180 | // immediately with no actual work having been done by the workers. |
duke@435 | 181 | void run_task(AbstractGangTask* task) { |
duke@435 | 182 | guarantee(false, "Use start_task instead"); |
duke@435 | 183 | } |
duke@435 | 184 | void start_task(YieldingFlexibleGangTask* new_task); |
duke@435 | 185 | void continue_task(YieldingFlexibleGangTask* gang_task); |
duke@435 | 186 | |
duke@435 | 187 | // Abort a currently running task, if any; returns when all the workers |
duke@435 | 188 | // have stopped working on the current task and have returned to their |
duke@435 | 189 | // waiting stations. |
duke@435 | 190 | void abort_task(); |
duke@435 | 191 | |
duke@435 | 192 | // Yield: workers wait at their current working stations |
duke@435 | 193 | // until signalled to proceed by the overseer. |
duke@435 | 194 | void yield(); |
duke@435 | 195 | |
duke@435 | 196 | // Abort: workers are expected to return to their waiting |
duke@435 | 197 | // stations, whence they are ready for the next task dispatched |
duke@435 | 198 | // by the overseer. |
duke@435 | 199 | void abort(); |
duke@435 | 200 | |
duke@435 | 201 | private: |
jmasa@3357 | 202 | uint _yielded_workers; |
duke@435 | 203 | void wait_for_gang(); |
duke@435 | 204 | |
duke@435 | 205 | public: |
duke@435 | 206 | // Accessors for fields |
jmasa@3357 | 207 | uint yielded_workers() const { |
duke@435 | 208 | return _yielded_workers; |
duke@435 | 209 | } |
duke@435 | 210 | |
duke@435 | 211 | private: |
duke@435 | 212 | friend class YieldingFlexibleGangWorker; |
duke@435 | 213 | void reset(); // NYI |
duke@435 | 214 | }; |
stefank@2314 | 215 | |
stefank@2314 | 216 | #endif // SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |