< prev index next >

src/share/vm/gc/parallel/gcTaskThread.cpp

Print this page




   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/parallel/gcTaskManager.hpp"
  27 #include "gc/parallel/gcTaskThread.hpp"
  28 #include "gc/shared/gcId.hpp"

  29 #include "memory/allocation.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 #include "memory/resourceArea.hpp"

  32 #include "runtime/handles.hpp"
  33 #include "runtime/handles.inline.hpp"
  34 #include "runtime/os.hpp"
  35 #include "runtime/thread.hpp"
  36 
  37 GCTaskThread::GCTaskThread(GCTaskManager* manager,
  38                            uint           which,
  39                            uint           processor_id) :
  40   _manager(manager),
  41   _processor_id(processor_id),
  42   _time_stamps(NULL),
  43   _time_stamp_index(0)
  44 {
  45   if (!os::create_thread(this, os::pgc_thread))
  46     vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");
  47 
  48   if (PrintGCTaskTimeStamps) {
  49     _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
  50 
  51     guarantee(_time_stamps != NULL, "Sanity");
  52   }
  53   set_id(which);
  54   set_name("ParGC Thread#%d", which);
  55 }
  56 
  57 GCTaskThread::~GCTaskThread() {
  58   if (_time_stamps != NULL) {
  59     FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
  60   }
  61 }
  62 
  63 void GCTaskThread::start() {
  64   os::start_thread(this);
  65 }
  66 
  67 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
  68   guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");









  69 
  70   return &(_time_stamps[index]);
  71 }
  72 
  73 void GCTaskThread::print_task_time_stamps() {
  74   assert(PrintGCTaskTimeStamps, "Sanity");
  75   assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
  76 
  77   tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
  78   for(uint i=0; i<_time_stamp_index; i++) {
  79     GCTaskTimeStamp* time_stamp = time_stamp_at(i);
  80     tty->print_cr("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
  81                   time_stamp->name(),
  82                   time_stamp->entry_time(),
  83                   time_stamp->exit_time());
  84   }
  85 
  86   // Reset after dumping the data
  87   _time_stamp_index = 0;
  88 }
  89 
  90 // GC workers get tasks from the GCTaskManager and execute
  91 // them in this method.  If there are no tasks to execute,
  92 // the GC workers wait in the GCTaskManager's get_task()
  93 // for tasks to be enqueued for execution.
  94 
  95 void GCTaskThread::run() {
  96   // Set up the thread for stack overflow support
  97   this->record_stack_base_and_size();
  98   this->initialize_named_thread();
  99   // Bind yourself to your processor.
 100   if (processor_id() != GCTaskManager::sentinel_worker()) {


 110     }
 111   }
 112   // Part of thread setup.
 113   // ??? Are these set up once here to make subsequent ones fast?
 114   HandleMark   hm_outer;
 115   ResourceMark rm_outer;
 116 
 117   TimeStamp timer;
 118 
 119   for (;/* ever */;) {
 120     // These are so we can flush the resources allocated in the inner loop.
 121     HandleMark   hm_inner;
 122     ResourceMark rm_inner;
 123     for (; /* break */; ) {
 124       // This will block until there is a task to be gotten.
 125       GCTask* task = manager()->get_task(which());
 126       GCIdMark gc_id_mark(task->gc_id());
 127       // Record if this is an idle task for later use.
 128       bool is_idle_task = task->is_idle_task();
 129       // In case the update is costly
 130       if (PrintGCTaskTimeStamps) {
 131         timer.update();
 132       }
 133 
 134       jlong entry_time = timer.ticks();
 135       char* name = task->name();
 136 
 137       // If this is the barrier task, it can be destroyed
 138       // by the GC task manager once the do_it() executes.
 139       task->do_it(manager(), which());
 140 
 141       // Use the saved value of is_idle_task because references
 142       // using "task" are not reliable for the barrier task.
 143       if (!is_idle_task) {
 144         manager()->note_completion(which());
 145 
 146         if (PrintGCTaskTimeStamps) {
 147           assert(_time_stamps != NULL,
 148             "Sanity (PrintGCTaskTimeStamps set late?)");
 149 
 150           timer.update();
 151 
 152           GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
 153 
 154           time_stamp->set_name(name);
 155           time_stamp->set_entry_time(entry_time);
 156           time_stamp->set_exit_time(timer.ticks());
 157         }
 158       } else {
 159         // idle tasks complete outside the normal accounting
 160         // so that a task can complete without waiting for idle tasks.
 161         // They have to be terminated separately.
 162         IdleGCTask::destroy((IdleGCTask*)task);
 163         set_is_working(true);
 164       }
 165 
 166       // Check if we should release our inner resources.
 167       if (manager()->should_release_resources(which())) {
 168         manager()->note_release(which());
 169         break;


   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/parallel/gcTaskManager.hpp"
  27 #include "gc/parallel/gcTaskThread.hpp"
  28 #include "gc/shared/gcId.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "runtime/atomic.inline.hpp"
  34 #include "runtime/handles.hpp"
  35 #include "runtime/handles.inline.hpp"
  36 #include "runtime/os.hpp"
  37 #include "runtime/thread.hpp"
  38 
  39 GCTaskThread::GCTaskThread(GCTaskManager* manager,
  40                            uint           which,
  41                            uint           processor_id) :
  42   _manager(manager),
  43   _processor_id(processor_id),
  44   _time_stamps(NULL),
  45   _time_stamp_index(0)
  46 {
  47   if (!os::create_thread(this, os::pgc_thread))
  48     vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");
  49 





  50   set_id(which);
  51   set_name("ParGC Thread#%d", which);
  52 }
  53 
  54 GCTaskThread::~GCTaskThread() {
  55   if (_time_stamps != NULL) {
  56     FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
  57   }
  58 }
  59 
  60 void GCTaskThread::start() {
  61   os::start_thread(this);
  62 }
  63 
  64 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
  65   guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
  66   if (_time_stamps == NULL) {
  67     // We allocate the _time_stamps array lazily since logging can be enabled dynamically
  68     GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
  69     void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL);
  70     if (old != NULL) {
  71       // Someone already setup the time stamps
  72       FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
  73     }
  74   }
  75 
  76   return &(_time_stamps[index]);
  77 }
  78 
  79 void GCTaskThread::print_task_time_stamps() {
  80   assert(log_is_enabled(Debug, gc, task, time), "Sanity");
  81   assert(_time_stamps != NULL, "Sanity");
  82 
  83   log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index);
  84   for(uint i=0; i<_time_stamp_index; i++) {
  85     GCTaskTimeStamp* time_stamp = time_stamp_at(i);
  86     log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
  87                               time_stamp->name(),
  88                               time_stamp->entry_time(),
  89                               time_stamp->exit_time());
  90   }
  91 
  92   // Reset after dumping the data
  93   _time_stamp_index = 0;
  94 }
  95 
  96 // GC workers get tasks from the GCTaskManager and execute
  97 // them in this method.  If there are no tasks to execute,
  98 // the GC workers wait in the GCTaskManager's get_task()
  99 // for tasks to be enqueued for execution.
 100 
 101 void GCTaskThread::run() {
 102   // Set up the thread for stack overflow support
 103   this->record_stack_base_and_size();
 104   this->initialize_named_thread();
 105   // Bind yourself to your processor.
 106   if (processor_id() != GCTaskManager::sentinel_worker()) {


 116     }
 117   }
 118   // Part of thread setup.
 119   // ??? Are these set up once here to make subsequent ones fast?
 120   HandleMark   hm_outer;
 121   ResourceMark rm_outer;
 122 
 123   TimeStamp timer;
 124 
 125   for (;/* ever */;) {
 126     // These are so we can flush the resources allocated in the inner loop.
 127     HandleMark   hm_inner;
 128     ResourceMark rm_inner;
 129     for (; /* break */; ) {
 130       // This will block until there is a task to be gotten.
 131       GCTask* task = manager()->get_task(which());
 132       GCIdMark gc_id_mark(task->gc_id());
 133       // Record if this is an idle task for later use.
 134       bool is_idle_task = task->is_idle_task();
 135       // In case the update is costly
 136       if (log_is_enabled(Debug, gc, task, time)) {
 137         timer.update();
 138       }
 139 
 140       jlong entry_time = timer.ticks();
 141       char* name = task->name();
 142 
 143       // If this is the barrier task, it can be destroyed
 144       // by the GC task manager once the do_it() executes.
 145       task->do_it(manager(), which());
 146 
 147       // Use the saved value of is_idle_task because references
 148       // using "task" are not reliable for the barrier task.
 149       if (!is_idle_task) {
 150         manager()->note_completion(which());
 151 
 152         if (log_is_enabled(Debug, gc, task, time)) {



 153           timer.update();
 154 
 155           GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
 156 
 157           time_stamp->set_name(name);
 158           time_stamp->set_entry_time(entry_time);
 159           time_stamp->set_exit_time(timer.ticks());
 160         }
 161       } else {
 162         // idle tasks complete outside the normal accounting
 163         // so that a task can complete without waiting for idle tasks.
 164         // They have to be terminated separately.
 165         IdleGCTask::destroy((IdleGCTask*)task);
 166         set_is_working(true);
 167       }
 168 
 169       // Check if we should release our inner resources.
 170       if (manager()->should_release_resources(which())) {
 171         manager()->note_release(which());
 172         break;
< prev index next >