changeset 46643:cb5f289ba033

8183545: Event tracing, transition hooks Reviewed-by: dcubed, egahlin
author rehn
date Fri, 07 Jul 2017 23:04:06 +0200
parents f64dc604ef8d
children a5813fb66270
files hotspot/src/share/vm/classfile/javaClasses.cpp hotspot/src/share/vm/runtime/thread.cpp hotspot/src/share/vm/runtime/thread.hpp hotspot/src/share/vm/runtime/thread.inline.hpp hotspot/src/share/vm/trace/traceMacros.hpp
diffstat 5 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp	Fri Jul 07 16:49:45 2017 +0000
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp	Fri Jul 07 23:04:06 2017 +0200
@@ -1334,7 +1334,9 @@
 
 // Read thread status value from threadStatus field in java.lang.Thread java class.
 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
-  assert(Thread::current()->is_Watcher_thread() || Thread::current()->is_VM_thread() ||
+  // Make sure the caller is operating on behalf of the VM or is
+  // running VM code (state == _thread_in_vm).
+  assert(Threads_lock->owned_by_self() || Thread::current()->is_VM_thread() ||
          JavaThread::current()->thread_state() == _thread_in_vm,
          "Java Thread is not running in vm");
   // The threadStatus is only present starting in 1.5
--- a/hotspot/src/share/vm/runtime/thread.cpp	Fri Jul 07 16:49:45 2017 +0000
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Fri Jul 07 23:04:06 2017 +0200
@@ -2193,6 +2193,11 @@
   if (check_asyncs) {
     check_and_handle_async_exceptions();
   }
+#if INCLUDE_TRACE
+  if (is_trace_suspend()) {
+    TRACE_SUSPEND_THREAD(this);
+  }
+#endif
 }
 
 void JavaThread::send_thread_stop(oop java_throwable)  {
@@ -2423,6 +2428,11 @@
       fatal("missed deoptimization!");
     }
   }
+#if INCLUDE_TRACE
+  if (thread->is_trace_suspend()) {
+    TRACE_SUSPEND_THREAD(thread);
+  }
+#endif
 }
 
 // Slow path when the native==>VM/Java barriers detect a safepoint is in
--- a/hotspot/src/share/vm/runtime/thread.hpp	Fri Jul 07 16:49:45 2017 +0000
+++ b/hotspot/src/share/vm/runtime/thread.hpp	Fri Jul 07 23:04:06 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -202,7 +202,9 @@
     _deopt_suspend          = 0x10000000U, // thread needs to self suspend for deopt
 
     _has_async_exception    = 0x00000001U, // there is a pending async exception
-    _critical_native_unlock = 0x00000002U  // Must call back to unlock JNI critical lock
+    _critical_native_unlock = 0x00000002U, // Must call back to unlock JNI critical lock
+
+    _trace_flag             = 0x00000004U  // call tracing backend
   };
 
   // various suspension related flags - atomically updated
@@ -382,6 +384,9 @@
   inline void set_critical_native_unlock();
   inline void clear_critical_native_unlock();
 
+  inline void set_trace_flag();
+  inline void clear_trace_flag();
+
   // Support for Unhandled Oop detection
   // Add the field for both, fastdebug and debug, builds to keep
   // Thread's fields layout the same.
@@ -450,6 +455,7 @@
 
   TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
   TRACE_DATA* trace_data() const        { return &_trace_data; }
+  bool is_trace_suspend()               { return (_suspend_flags & _trace_flag) != 0; }
 
   const ThreadExt& ext() const          { return _ext; }
   ThreadExt& ext()                      { return _ext; }
@@ -1261,8 +1267,7 @@
   // Return true if JavaThread has an asynchronous condition or
   // if external suspension is requested.
   bool has_special_runtime_exit_condition() {
-    // We call is_external_suspend() last since external suspend should
-    // be less common. Because we don't use is_external_suspend_with_lock
+    // Because we don't use is_external_suspend_with_lock
     // it is possible that we won't see an asynchronous external suspend
     // request that has just gotten started, i.e., SR_lock grabbed but
     // _external_suspend field change either not made yet or not visible
@@ -1272,7 +1277,7 @@
     // we have checked is_external_suspend(), we will recheck its value
     // under SR_lock in java_suspend_self().
     return (_special_runtime_exit_condition != _no_async_condition) ||
-            is_external_suspend() || is_deopt_suspend();
+            is_external_suspend() || is_deopt_suspend() || is_trace_suspend();
   }
 
   void set_pending_unsafe_access_error()          { _special_runtime_exit_condition = _async_unsafe_access_error; }
--- a/hotspot/src/share/vm/runtime/thread.inline.hpp	Fri Jul 07 16:49:45 2017 +0000
+++ b/hotspot/src/share/vm/runtime/thread.inline.hpp	Fri Jul 07 23:04:06 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -66,6 +66,12 @@
 inline void Thread::clear_critical_native_unlock() {
   clear_suspend_flag(_critical_native_unlock);
 }
+inline void Thread::set_trace_flag() {
+  set_suspend_flag(_trace_flag);
+}
+inline void Thread::clear_trace_flag() {
+  clear_suspend_flag(_trace_flag);
+}
 
 inline jlong Thread::cooked_allocated_bytes() {
   jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
--- a/hotspot/src/share/vm/trace/traceMacros.hpp	Fri Jul 07 16:49:45 2017 +0000
+++ b/hotspot/src/share/vm/trace/traceMacros.hpp	Fri Jul 07 23:04:06 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,7 @@
 #define TRACE_INITIALIZE() JNI_OK
 #define TRACE_VM_EXIT()
 #define TRACE_VM_ERROR()
+#define TRACE_SUSPEND_THREAD(t)
 
 #define TRACE_DEFINE_TRACE_ID_METHODS typedef int ___IGNORED_hs_trace_type1
 #define TRACE_DEFINE_TRACE_ID_FIELD typedef int ___IGNORED_hs_trace_type2