< prev index next >

src/share/vm/runtime/vmThread.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 "compiler/compileBroker.hpp"
  27 #include "gc_interface/collectedHeap.hpp"


  28 #include "memory/resourceArea.hpp"
  29 #include "oops/method.hpp"
  30 #include "oops/oop.inline.hpp"
  31 #include "runtime/interfaceSupport.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 #include "runtime/os.hpp"
  34 #include "runtime/thread.inline.hpp"
  35 #include "runtime/vmThread.hpp"
  36 #include "runtime/vm_operations.hpp"
  37 #include "services/runtimeService.hpp"
  38 #include "trace/tracing.hpp"
  39 #include "utilities/dtrace.hpp"
  40 #include "utilities/events.hpp"
  41 #include "utilities/xmlstream.hpp"
  42 
  43 #ifndef USDT2
  44 HS_DTRACE_PROBE_DECL3(hotspot, vmops__request, char *, uintptr_t, int);
  45 HS_DTRACE_PROBE_DECL3(hotspot, vmops__begin, char *, uintptr_t, int);
  46 HS_DTRACE_PROBE_DECL3(hotspot, vmops__end, char *, uintptr_t, int);
  47 #endif /* !USDT2 */
  48 
  49 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  50 
  51 // Dummy VM operation to act as first element in our circular double-linked list
  52 class VM_Dummy: public VM_Operation {
  53   VMOp_Type type() const { return VMOp_Dummy; }
  54   void  doit() {};
  55 };
  56 
  57 VMOperationQueue::VMOperationQueue() {
  58   // The queue is a circular doubled-linked list, which always contains


 342   // that could get blocked by Safepoint should not be used after this point,
 343   // otherwise we will hang, since there is no one can end the safepoint.
 344 
 345   // Wait until VM thread is terminated
 346   // Note: it should be OK to use Terminator_lock here. But this is called
 347   // at a very delicate time (VM shutdown) and we are operating in non- VM
 348   // thread at Safepoint. It's safer to not share lock with other threads.
 349   { MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
 350     while(!VMThread::is_terminated()) {
 351         _terminate_lock->wait(Mutex::_no_safepoint_check_flag);
 352     }
 353   }
 354 }
 355 
 356 void VMThread::print_on(outputStream* st) const {
 357   st->print("\"%s\" ", name());
 358   Thread::print_on(st);
 359   st->cr();
 360 }
 361 

















 362 void VMThread::evaluate_operation(VM_Operation* op) {
 363   ResourceMark rm;
 364 
 365   {
 366     PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time());
 367 #ifndef USDT2
 368     HS_DTRACE_PROBE3(hotspot, vmops__begin, op->name(), strlen(op->name()),
 369                      op->evaluation_mode());
 370 #else /* USDT2 */
 371     HOTSPOT_VMOPS_BEGIN(
 372                      (char *) op->name(), strlen(op->name()),
 373                      op->evaluation_mode());
 374 #endif /* USDT2 */
 375 
 376     EventExecuteVMOperation event;
 377 
 378     op->evaluate();
 379 
 380     if (event.should_commit()) {
 381       bool is_concurrent = op->evaluate_concurrently();
 382       event.set_operation(op->type());
 383       event.set_safepoint(op->evaluate_at_safepoint());
 384       event.set_blocking(!is_concurrent);
 385       // Only write caller thread information for non-concurrent vm operations.
 386       // For concurrent vm operations, the thread id is set to 0 indicating thread is unknown.
 387       // This is because the caller thread could have exited already.
 388       event.set_caller(is_concurrent ? 0 : op->calling_thread()->osthread()->thread_id());
 389       event.commit();
 390     }
 391 
 392 #ifndef USDT2
 393     HS_DTRACE_PROBE3(hotspot, vmops__end, op->name(), strlen(op->name()),
 394                      op->evaluation_mode());
 395 #else /* USDT2 */
 396     HOTSPOT_VMOPS_END(
 397                      (char *) op->name(), strlen(op->name()),
 398                      op->evaluation_mode());
 399 #endif /* USDT2 */
 400   }
 401 
 402   // Last access of info in _cur_vm_operation!
 403   bool c_heap_allocated = op->is_cheap_allocated();
 404 
 405   // Mark as completed
 406   if (!op->evaluate_concurrently()) {
 407     op->calling_thread()->increment_vm_operation_completed_count();
 408   }
 409   // It is unsafe to access the _cur_vm_operation after the 'increment_vm_operation_completed_count' call,




   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 "compiler/compileBroker.hpp"
  27 #include "gc_interface/collectedHeap.hpp"
  28 #include "jfr/jfrEvents.hpp"
  29 #include "jfr/support/jfrThreadId.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/method.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "runtime/interfaceSupport.hpp"
  34 #include "runtime/mutexLocker.hpp"
  35 #include "runtime/os.hpp"
  36 #include "runtime/thread.inline.hpp"
  37 #include "runtime/vmThread.hpp"
  38 #include "runtime/vm_operations.hpp"
  39 #include "services/runtimeService.hpp"

  40 #include "utilities/dtrace.hpp"
  41 #include "utilities/events.hpp"
  42 #include "utilities/xmlstream.hpp"
  43 
  44 #ifndef USDT2
  45 HS_DTRACE_PROBE_DECL3(hotspot, vmops__request, char *, uintptr_t, int);
  46 HS_DTRACE_PROBE_DECL3(hotspot, vmops__begin, char *, uintptr_t, int);
  47 HS_DTRACE_PROBE_DECL3(hotspot, vmops__end, char *, uintptr_t, int);
  48 #endif /* !USDT2 */
  49 
  50 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  51 
  52 // Dummy VM operation to act as first element in our circular double-linked list
  53 class VM_Dummy: public VM_Operation {
  54   VMOp_Type type() const { return VMOp_Dummy; }
  55   void  doit() {};
  56 };
  57 
  58 VMOperationQueue::VMOperationQueue() {
  59   // The queue is a circular doubled-linked list, which always contains


 343   // that could get blocked by Safepoint should not be used after this point,
 344   // otherwise we will hang, since there is no one can end the safepoint.
 345 
 346   // Wait until VM thread is terminated
 347   // Note: it should be OK to use Terminator_lock here. But this is called
 348   // at a very delicate time (VM shutdown) and we are operating in non- VM
 349   // thread at Safepoint. It's safer to not share lock with other threads.
 350   { MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
 351     while(!VMThread::is_terminated()) {
 352         _terminate_lock->wait(Mutex::_no_safepoint_check_flag);
 353     }
 354   }
 355 }
 356 
 357 void VMThread::print_on(outputStream* st) const {
 358   st->print("\"%s\" ", name());
 359   Thread::print_on(st);
 360   st->cr();
 361 }
 362 
 363 static void post_vm_operation_event(EventExecuteVMOperation* event, VM_Operation* op) {
 364   assert(event != NULL, "invariant");
 365   assert(event->should_commit(), "invariant");
 366   assert(op != NULL, "invariant");
 367   const bool is_concurrent = op->evaluate_concurrently();
 368   const bool evaluate_at_safepoint = op->evaluate_at_safepoint();
 369   event->set_operation(op->type());
 370   event->set_safepoint(evaluate_at_safepoint);
 371   event->set_blocking(!is_concurrent);
 372   // Only write caller thread information for non-concurrent vm operations.
 373   // For concurrent vm operations, the thread id is set to 0 indicating thread is unknown.
 374   // This is because the caller thread could have exited already.
 375   event->set_caller(is_concurrent ? 0 : JFR_THREAD_ID(op->calling_thread()));
 376   event->set_safepointId(evaluate_at_safepoint ? SafepointSynchronize::safepoint_counter() : 0);
 377   event->commit();
 378 }
 379 
 380 void VMThread::evaluate_operation(VM_Operation* op) {
 381   ResourceMark rm;
 382 
 383   {
 384     PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time());
 385 #ifndef USDT2
 386     HS_DTRACE_PROBE3(hotspot, vmops__begin, op->name(), strlen(op->name()),
 387                      op->evaluation_mode());
 388 #else /* USDT2 */
 389     HOTSPOT_VMOPS_BEGIN(
 390                      (char *) op->name(), strlen(op->name()),
 391                      op->evaluation_mode());
 392 #endif /* USDT2 */
 393 
 394     EventExecuteVMOperation event;

 395     op->evaluate();

 396     if (event.should_commit()) {
 397       post_vm_operation_event(&event, op);








 398     }
 399 
 400 #ifndef USDT2
 401     HS_DTRACE_PROBE3(hotspot, vmops__end, op->name(), strlen(op->name()),
 402                      op->evaluation_mode());
 403 #else /* USDT2 */
 404     HOTSPOT_VMOPS_END(
 405                      (char *) op->name(), strlen(op->name()),
 406                      op->evaluation_mode());
 407 #endif /* USDT2 */
 408   }
 409 
 410   // Last access of info in _cur_vm_operation!
 411   bool c_heap_allocated = op->is_cheap_allocated();
 412 
 413   // Mark as completed
 414   if (!op->evaluate_concurrently()) {
 415     op->calling_thread()->increment_vm_operation_completed_count();
 416   }
 417   // It is unsafe to access the _cur_vm_operation after the 'increment_vm_operation_completed_count' call,


< prev index next >