hotspot/src/share/vm/compiler/compileBroker.cpp
changeset 27696 c43940b3cf78
parent 27642 8c9eff693145
child 27706 3f10f4ac2bd6
equal deleted inserted replaced
27695:c6e0ac3339ac 27696:c43940b3cf78
   592 
   592 
   593 /**
   593 /**
   594  * Add a CompileTask to a CompileQueue.
   594  * Add a CompileTask to a CompileQueue.
   595  */
   595  */
   596 void CompileQueue::add(CompileTask* task) {
   596 void CompileQueue::add(CompileTask* task) {
   597   assert(lock()->owned_by_self(), "must own lock");
   597   assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
   598 
   598 
   599   task->set_next(NULL);
   599   task->set_next(NULL);
   600   task->set_prev(NULL);
   600   task->set_prev(NULL);
   601 
   601 
   602   if (_last == NULL) {
   602   if (_last == NULL) {
   623   if (LogCompilation && xtty != NULL) {
   623   if (LogCompilation && xtty != NULL) {
   624     task->log_task_queued();
   624     task->log_task_queued();
   625   }
   625   }
   626 
   626 
   627   // Notify CompilerThreads that a task is available.
   627   // Notify CompilerThreads that a task is available.
   628   lock()->notify_all();
   628   MethodCompileQueue_lock->notify_all();
   629 }
   629 }
   630 
   630 
   631 /**
   631 /**
   632  * Empties compilation queue by putting all compilation tasks onto
   632  * Empties compilation queue by putting all compilation tasks onto
   633  * a freelist. Furthermore, the method wakes up all threads that are
   633  * a freelist. Furthermore, the method wakes up all threads that are
   634  * waiting on a compilation task to finish. This can happen if background
   634  * waiting on a compilation task to finish. This can happen if background
   635  * compilation is disabled.
   635  * compilation is disabled.
   636  */
   636  */
   637 void CompileQueue::free_all() {
   637 void CompileQueue::free_all() {
   638   MutexLocker mu(lock());
   638   MutexLocker mu(MethodCompileQueue_lock);
   639   CompileTask* next = _first;
   639   CompileTask* next = _first;
   640 
   640 
   641   // Iterate over all tasks in the compile queue
   641   // Iterate over all tasks in the compile queue
   642   while (next != NULL) {
   642   while (next != NULL) {
   643     CompileTask* current = next;
   643     CompileTask* current = next;
   651     CompileTask::free(current);
   651     CompileTask::free(current);
   652   }
   652   }
   653   _first = NULL;
   653   _first = NULL;
   654 
   654 
   655   // Wake up all threads that block on the queue.
   655   // Wake up all threads that block on the queue.
   656   lock()->notify_all();
   656   MethodCompileQueue_lock->notify_all();
   657 }
   657 }
   658 
   658 
   659 /**
   659 /**
   660  * Get the next CompileTask from a CompileQueue
   660  * Get the next CompileTask from a CompileQueue
   661  */
   661  */
   662 CompileTask* CompileQueue::get() {
   662 CompileTask* CompileQueue::get() {
   663   MutexLocker locker(lock());
   663   MutexLocker locker(MethodCompileQueue_lock);
   664   // If _first is NULL we have no more compile jobs. There are two reasons for
   664   // If _first is NULL we have no more compile jobs. There are two reasons for
   665   // having no compile jobs: First, we compiled everything we wanted. Second,
   665   // having no compile jobs: First, we compiled everything we wanted. Second,
   666   // we ran out of code cache so compilation has been disabled. In the latter
   666   // we ran out of code cache so compilation has been disabled. In the latter
   667   // case we perform code cache sweeps to free memory such that we can re-enable
   667   // case we perform code cache sweeps to free memory such that we can re-enable
   668   // compilation.
   668   // compilation.
   679     // the stable state, i.e., we do not want to evict methods from the
   679     // the stable state, i.e., we do not want to evict methods from the
   680     // code cache if it is unnecessary.
   680     // code cache if it is unnecessary.
   681     // We need a timed wait here, since compiler threads can exit if compilation
   681     // We need a timed wait here, since compiler threads can exit if compilation
   682     // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
   682     // is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
   683     // is not critical and we do not want idle compiler threads to wake up too often.
   683     // is not critical and we do not want idle compiler threads to wake up too often.
   684     lock()->wait(!Mutex::_no_safepoint_check_flag, 5*1000);
   684     MethodCompileQueue_lock->wait(!Mutex::_no_safepoint_check_flag, 5*1000);
   685   }
   685   }
   686 
   686 
   687   if (CompileBroker::is_compilation_disabled_forever()) {
   687   if (CompileBroker::is_compilation_disabled_forever()) {
   688     return NULL;
   688     return NULL;
   689   }
   689   }
   699 }
   699 }
   700 
   700 
   701 // Clean & deallocate stale compile tasks.
   701 // Clean & deallocate stale compile tasks.
   702 // Temporarily releases MethodCompileQueue lock.
   702 // Temporarily releases MethodCompileQueue lock.
   703 void CompileQueue::purge_stale_tasks() {
   703 void CompileQueue::purge_stale_tasks() {
   704   assert(lock()->owned_by_self(), "must own lock");
   704   assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
   705   if (_first_stale != NULL) {
   705   if (_first_stale != NULL) {
   706     // Stale tasks are purged when MCQ lock is released,
   706     // Stale tasks are purged when MCQ lock is released,
   707     // but _first_stale updates are protected by MCQ lock.
   707     // but _first_stale updates are protected by MCQ lock.
   708     // Once task processing starts and MCQ lock is released,
   708     // Once task processing starts and MCQ lock is released,
   709     // other compiler threads can reuse _first_stale.
   709     // other compiler threads can reuse _first_stale.
   710     CompileTask* head = _first_stale;
   710     CompileTask* head = _first_stale;
   711     _first_stale = NULL;
   711     _first_stale = NULL;
   712     {
   712     {
   713       MutexUnlocker ul(lock());
   713       MutexUnlocker ul(MethodCompileQueue_lock);
   714       for (CompileTask* task = head; task != NULL; ) {
   714       for (CompileTask* task = head; task != NULL; ) {
   715         CompileTask* next_task = task->next();
   715         CompileTask* next_task = task->next();
   716         CompileTaskWrapper ctw(task); // Frees the task
   716         CompileTaskWrapper ctw(task); // Frees the task
   717         task->set_failure_reason("stale task");
   717         task->set_failure_reason("stale task");
   718         task = next_task;
   718         task = next_task;
   720     }
   720     }
   721   }
   721   }
   722 }
   722 }
   723 
   723 
   724 void CompileQueue::remove(CompileTask* task) {
   724 void CompileQueue::remove(CompileTask* task) {
   725    assert(lock()->owned_by_self(), "must own lock");
   725    assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
   726   if (task->prev() != NULL) {
   726   if (task->prev() != NULL) {
   727     task->prev()->set_next(task->next());
   727     task->prev()->set_next(task->next());
   728   } else {
   728   } else {
   729     // max is the first element
   729     // max is the first element
   730     assert(task == _first, "Sanity");
   730     assert(task == _first, "Sanity");
   740   }
   740   }
   741   --_size;
   741   --_size;
   742 }
   742 }
   743 
   743 
   744 void CompileQueue::remove_and_mark_stale(CompileTask* task) {
   744 void CompileQueue::remove_and_mark_stale(CompileTask* task) {
   745   assert(lock()->owned_by_self(), "must own lock");
   745   assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
   746   remove(task);
   746   remove(task);
   747 
   747 
   748   // Enqueue the task for reclamation (should be done outside MCQ lock)
   748   // Enqueue the task for reclamation (should be done outside MCQ lock)
   749   task->set_next(_first_stale);
   749   task->set_next(_first_stale);
   750   task->set_prev(NULL);
   750   task->set_prev(NULL);
   778     _c2_compile_queue->print(st);
   778     _c2_compile_queue->print(st);
   779   }
   779   }
   780 }
   780 }
   781 
   781 
   782 void CompileQueue::print(outputStream* st) {
   782 void CompileQueue::print(outputStream* st) {
   783   assert(lock()->owned_by_self(), "must own lock");
   783   assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
   784   st->print_cr("Contents of %s", name());
   784   st->print_cr("Contents of %s", name());
   785   st->print_cr("----------------------------");
   785   st->print_cr("----------------------------");
   786   CompileTask* task = _first;
   786   CompileTask* task = _first;
   787   if (task == NULL) {
   787   if (task == NULL) {
   788     st->print_cr("Empty");
   788     st->print_cr("Empty");
  1064 #if !defined(ZERO) && !defined(SHARK)
  1064 #if !defined(ZERO) && !defined(SHARK)
  1065   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
  1065   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
  1066 #endif // !ZERO && !SHARK
  1066 #endif // !ZERO && !SHARK
  1067   // Initialize the compilation queue
  1067   // Initialize the compilation queue
  1068   if (c2_compiler_count > 0) {
  1068   if (c2_compiler_count > 0) {
  1069     _c2_compile_queue  = new CompileQueue("C2 compile queue",  MethodCompileQueue_lock);
  1069     _c2_compile_queue  = new CompileQueue("C2 compile queue");
  1070     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
  1070     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
  1071   }
  1071   }
  1072   if (c1_compiler_count > 0) {
  1072   if (c1_compiler_count > 0) {
  1073     _c1_compile_queue  = new CompileQueue("C1 compile queue",  MethodCompileQueue_lock);
  1073     _c1_compile_queue  = new CompileQueue("C1 compile queue");
  1074     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
  1074     _compilers[0]->set_num_compiler_threads(c1_compiler_count);
  1075   }
  1075   }
  1076 
  1076 
  1077   int compiler_count = c1_compiler_count + c2_compiler_count;
  1077   int compiler_count = c1_compiler_count + c2_compiler_count;
  1078 
  1078 
  1212   bool         blocking = false;
  1212   bool         blocking = false;
  1213   CompileQueue* queue  = compile_queue(comp_level);
  1213   CompileQueue* queue  = compile_queue(comp_level);
  1214 
  1214 
  1215   // Acquire our lock.
  1215   // Acquire our lock.
  1216   {
  1216   {
  1217     MutexLocker locker(queue->lock(), thread);
  1217     MutexLocker locker(MethodCompileQueue_lock, thread);
  1218 
  1218 
  1219     // Make sure the method has not slipped into the queues since
  1219     // Make sure the method has not slipped into the queues since
  1220     // last we checked; note that those checks were "fast bail-outs".
  1220     // last we checked; note that those checks were "fast bail-outs".
  1221     // Here we need to be more careful, see 14012000 below.
  1221     // Here we need to be more careful, see 14012000 below.
  1222     if (compilation_is_in_queue(method)) {
  1222     if (compilation_is_in_queue(method)) {