< prev index next >

src/hotspot/share/jfr/jni/jfrJavaSupport.cpp

Print this page
*** 48,23 ***
  #include "runtime/threadSMR.hpp"
  #include "utilities/growableArray.hpp"
  #include "classfile/vmSymbols.hpp"
  
  #ifdef ASSERT
! void JfrJavaSupport::check_java_thread_in_vm(JavaThread* t) {
    assert(t != NULL, "invariant");
!   assert(t->thread_state() == _thread_in_vm, "invariant");
  }
  
  void JfrJavaSupport::check_java_thread_in_native(JavaThread* t) {
!   assert(t != NULL, "invariant");
-   assert(t->thread_state() == _thread_in_native, "invariant");
  }
  
! static void check_new_unstarted_java_thread(JavaThread* t) {
!   assert(t != NULL, "invariant");
!   assert(t->thread_state() == _thread_new, "invariant");
  }
  #endif
  
  /*
   *  Handles and references
--- 48,31 ---
  #include "runtime/threadSMR.hpp"
  #include "utilities/growableArray.hpp"
  #include "classfile/vmSymbols.hpp"
  
  #ifdef ASSERT
! static void check_java_thread_state(JavaThread* t, JavaThreadState state) {
    assert(t != NULL, "invariant");
!   assert(t->is_Java_thread(), "invariant");
+   assert(t->thread_state() == state, "invariant");
+ }
+ 
+ void JfrJavaSupport::check_java_thread_in_vm(JavaThread* t) {
+   check_java_thread_state(t, _thread_in_vm);
  }
  
  void JfrJavaSupport::check_java_thread_in_native(JavaThread* t) {
!   check_java_thread_state(t, _thread_in_native);
  }
  
! void JfrJavaSupport::check_java_thread_in_java(JavaThread* t) {
!   check_java_thread_state(t, _thread_in_Java);
! }
+ 
+ static void check_new_unstarted_java_thread(JavaThread* jt, jobject vthread = NULL) {
+   if (vthread != NULL) return;
+   check_java_thread_state(jt, _thread_new);
  }
  #endif
  
  /*
   *  Handles and references

*** 712,21 ***
    ThreadExclusionListAccess lock;
    remove_thread_from_exclusion_list(as_handle(thread));
  }
  
  // includes removal
! static bool check_exclusion_state_on_thread_start(JavaThread* jt) {
-   Handle h_obj(jt, jt->threadObj());
    ThreadExclusionListAccess lock;
!   if (thread_is_not_excluded(h_obj)) {
      return false;
    }
!   remove_thread_from_exclusion_list(h_obj);
    return true;
  }
  
! static JavaThread* get_native(jobject thread) {
    ThreadsListHandle tlh;
    JavaThread* native_thread = NULL;
    (void)tlh.cv_internal_thread_to_JavaThread(thread, &native_thread, NULL);
    return native_thread;
  }
--- 720,20 ---
    ThreadExclusionListAccess lock;
    remove_thread_from_exclusion_list(as_handle(thread));
  }
  
  // includes removal
! static bool check_exclusion_state_on_thread_start(Handle h_threadObj) {
    ThreadExclusionListAccess lock;
!   if (thread_is_not_excluded(h_threadObj)) {
      return false;
    }
!   remove_thread_from_exclusion_list(h_threadObj);
    return true;
  }
  
! JavaThread* JfrJavaSupport::get_native(jobject thread) {
    ThreadsListHandle tlh;
    JavaThread* native_thread = NULL;
    (void)tlh.cv_internal_thread_to_JavaThread(thread, &native_thread, NULL);
    return native_thread;
  }

*** 813,17 ***
    assert(handler_oop != NULL, "invariant");
    h_mirror->obj_field_put(handler_field_descriptor.offset(), handler_oop);
    return true;
  }
  
! void JfrJavaSupport::on_thread_start(Thread* t) {
!   assert(t != NULL, "invariant");
!   assert(Thread::current() == t, "invariant");
!   if (!t->is_Java_thread()) {
!     return;
    }
!   DEBUG_ONLY(check_new_unstarted_java_thread(JavaThread::cast(t));)
!   HandleMark hm(t);
!   if (check_exclusion_state_on_thread_start(JavaThread::cast(t))) {
!     JfrThreadLocal::exclude(t);
    }
  }
--- 820,51 ---
    assert(handler_oop != NULL, "invariant");
    h_mirror->obj_field_put(handler_field_descriptor.offset(), handler_oop);
    return true;
  }
  
! bool JfrJavaSupport::on_thread_start(JavaThread* jt, jobject vthread) {
!   assert(jt != NULL, "invariant");
!   assert(Thread::current() == jt, "invariant");
!   DEBUG_ONLY(check_new_unstarted_java_thread(jt, vthread);)
!   HandleMark hm(jt);
+   const oop threadObj = vthread != NULL ? resolve_non_null(vthread) : jt->threadObj();
+   Handle h_obj(jt, threadObj);
+   if (check_exclusion_state_on_thread_start(h_obj)) {
+     if (vthread != NULL) {
+       exclude(vthread);
+     } else {
+       JfrThreadLocal::exclude(jt);
+     }
+     return false;
    }
!   return true;
! }
! 
! static bool find_field(const InstanceKlass* ik,
+                        Symbol* name_symbol,
+                        Symbol* signature_symbol,
+                        fieldDescriptor* fd,
+                        bool is_static = false,
+                        bool allow_super = false) {
+   assert(ik != NULL, "invariant");
+   if (allow_super || is_static) {
+     return ik->find_field(name_symbol, signature_symbol, is_static, fd) != NULL;
+   } else {
+     return ik->find_local_field(name_symbol, signature_symbol, fd);
    }
  }
+ 
+ bool JfrJavaSupport::compute_field_offset(int &dest_offset,
+                                           Klass* klass,
+                                           Symbol* name_symbol,
+                                           Symbol* signature_symbol,
+                                           bool is_static,
+                                           bool allow_super) {
+   fieldDescriptor fd;
+   const InstanceKlass* const ik = InstanceKlass::cast(klass);
+   if (!find_field(ik, name_symbol, signature_symbol, &fd, is_static, allow_super)) {
+     return false;
+   }
+   dest_offset = fd.offset();
+   return true;
+ }
< prev index next >