< prev index next >

src/share/vm/gc/shared/taskqueue.cpp

Print this page




   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 "runtime/atomic.inline.hpp"
  29 #include "runtime/os.hpp"
  30 #include "runtime/thread.inline.hpp"
  31 #include "utilities/debug.hpp"
  32 #include "utilities/stack.inline.hpp"
  33 
  34 #ifdef TRACESPINNING
  35 uint ParallelTaskTerminator::_total_yields = 0;
  36 uint ParallelTaskTerminator::_total_spins = 0;
  37 uint ParallelTaskTerminator::_total_peeks = 0;
  38 #endif
  39 
  40 #if TASKQUEUE_STATS
  41 const char * const TaskQueueStats::_names[last_stat_id] = {
  42   "qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax"
  43 };
  44 
  45 TaskQueueStats & TaskQueueStats::operator +=(const TaskQueueStats & addend)
  46 {
  47   for (unsigned int i = 0; i < last_stat_id; ++i) {


 195           yield();
 196           hard_spin_count = 0;
 197           hard_spin_limit = hard_spin_start;
 198 #ifdef TRACESPINNING
 199           _total_yields++;
 200 #endif
 201         } else {
 202           // Hard spin this time
 203           // Increase the hard spinning period but only up to a limit.
 204           hard_spin_limit = MIN2(2*hard_spin_limit,
 205                                  (uint) WorkStealingHardSpins);
 206           for (uint j = 0; j < hard_spin_limit; j++) {
 207             SpinPause();
 208           }
 209           hard_spin_count++;
 210 #ifdef TRACESPINNING
 211           _total_spins++;
 212 #endif
 213         }
 214       } else {
 215         if (PrintGCDetails && Verbose) {
 216          gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() "
 217            "thread " PTR_FORMAT " sleeps after %u yields",
 218            p2i(Thread::current()), yield_count);
 219         }
 220         yield_count = 0;
 221         // A sleep will cause this processor to seek work on another processor's
 222         // runqueue, if it has nothing else to run (as opposed to the yield
 223         // which may only move the thread to the end of the this processor's
 224         // runqueue).
 225         sleep(WorkStealingSleepMillis);
 226       }
 227 
 228 #ifdef TRACESPINNING
 229       _total_peeks++;
 230 #endif
 231       if (peek_in_queue_set() ||
 232           (terminator != NULL && terminator->should_exit_termination())) {
 233         Atomic::dec((int *)&_offered_termination);
 234         assert(_offered_termination < _n_threads, "Invariant");
 235         return false;
 236       }
 237     }
 238   }
 239 }
 240 
 241 #ifdef TRACESPINNING
 242 void ParallelTaskTerminator::print_termination_counts() {
 243   gclog_or_tty->print_cr("ParallelTaskTerminator Total yields: %u"
 244     " Total spins: %u Total peeks: %u",
 245     total_yields(),
 246     total_spins(),
 247     total_peeks());
 248 }
 249 #endif
 250 
 251 void ParallelTaskTerminator::reset_for_reuse() {
 252   if (_offered_termination != 0) {
 253     assert(_offered_termination == _n_threads,
 254            "Terminator may still be in use");
 255     _offered_termination = 0;
 256   }
 257 }
 258 
 259 #ifdef ASSERT
 260 bool ObjArrayTask::is_valid() const {
 261   return _obj != NULL && _obj->is_objArray() && _index >= 0 &&
 262       _index < objArrayOop(_obj)->length();
 263 }


   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.inline.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 #ifdef TRACESPINNING
  36 uint ParallelTaskTerminator::_total_yields = 0;
  37 uint ParallelTaskTerminator::_total_spins = 0;
  38 uint ParallelTaskTerminator::_total_peeks = 0;
  39 #endif
  40 
  41 #if TASKQUEUE_STATS
  42 const char * const TaskQueueStats::_names[last_stat_id] = {
  43   "qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax"
  44 };
  45 
  46 TaskQueueStats & TaskQueueStats::operator +=(const TaskQueueStats & addend)
  47 {
  48   for (unsigned int i = 0; i < last_stat_id; ++i) {


 196           yield();
 197           hard_spin_count = 0;
 198           hard_spin_limit = hard_spin_start;
 199 #ifdef TRACESPINNING
 200           _total_yields++;
 201 #endif
 202         } else {
 203           // Hard spin this time
 204           // Increase the hard spinning period but only up to a limit.
 205           hard_spin_limit = MIN2(2*hard_spin_limit,
 206                                  (uint) WorkStealingHardSpins);
 207           for (uint j = 0; j < hard_spin_limit; j++) {
 208             SpinPause();
 209           }
 210           hard_spin_count++;
 211 #ifdef TRACESPINNING
 212           _total_spins++;
 213 #endif
 214         }
 215       } else {
 216         log_develop(gc, task)("ParallelTaskTerminator::offer_termination() thread " PTR_FORMAT " sleeps after %u yields",


 217                               p2i(Thread::current()), yield_count);

 218         yield_count = 0;
 219         // A sleep will cause this processor to seek work on another processor's
 220         // runqueue, if it has nothing else to run (as opposed to the yield
 221         // which may only move the thread to the end of the this processor's
 222         // runqueue).
 223         sleep(WorkStealingSleepMillis);
 224       }
 225 
 226 #ifdef TRACESPINNING
 227       _total_peeks++;
 228 #endif
 229       if (peek_in_queue_set() ||
 230           (terminator != NULL && terminator->should_exit_termination())) {
 231         Atomic::dec((int *)&_offered_termination);
 232         assert(_offered_termination < _n_threads, "Invariant");
 233         return false;
 234       }
 235     }
 236   }
 237 }
 238 
 239 #ifdef TRACESPINNING
 240 void ParallelTaskTerminator::print_termination_counts() {
 241   log_trace(gc, task)("ParallelTaskTerminator Total yields: %u"
 242     " Total spins: %u Total peeks: %u",
 243     total_yields(),
 244     total_spins(),
 245     total_peeks());
 246 }
 247 #endif
 248 
 249 void ParallelTaskTerminator::reset_for_reuse() {
 250   if (_offered_termination != 0) {
 251     assert(_offered_termination == _n_threads,
 252            "Terminator may still be in use");
 253     _offered_termination = 0;
 254   }
 255 }
 256 
 257 #ifdef ASSERT
 258 bool ObjArrayTask::is_valid() const {
 259   return _obj != NULL && _obj->is_objArray() && _index >= 0 &&
 260       _index < objArrayOop(_obj)->length();
 261 }
< prev index next >