< prev index next >

src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.cpp

Print this page

 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 "jfr/metadata/jfrSerializer.hpp"
 27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
 28 #include "jfr/recorder/checkpoint/types/jfrType.hpp"
 29 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp"
 30 #include "jfr/recorder/jfrRecorder.hpp"
 31 #include "jfr/support/jfrThreadLocal.hpp"
 32 #include "jfr/utilities/jfrIterator.hpp"
 33 #include "jfr/utilities/jfrLinkedList.inline.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "runtime/handles.inline.hpp"
 36 #include "runtime/safepoint.hpp"
 37 #include "runtime/semaphore.hpp"
 38 #include "runtime/thread.inline.hpp"
 39 #include "utilities/exceptions.hpp"
 40 
 41 class JfrSerializerRegistration : public JfrCHeapObj {
 42  public:
 43   JfrSerializerRegistration* _next; // list support
 44  private:
 45   JfrSerializer* _serializer;
 46   mutable JfrBlobHandle _cache;
 47   JfrTypeId _id;
 48   bool _permit_cache;
 49  public:
 50   JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) :
 51     _next(NULL), _serializer(serializer), _cache(), _id(id), _permit_cache(permit_cache) {}
 52   ~JfrSerializerRegistration() {
 53     delete _serializer;
 54   }
 55 
 56   JfrTypeId id() const {
 57     return _id;
 58   }
 59 

 84   }
 85 };
 86 
 87 static void serialize_threads(JfrCheckpointWriter& writer) {
 88   JfrThreadConstantSet thread_set;
 89   writer.write_type(TYPE_THREAD);
 90   thread_set.serialize(writer);
 91 }
 92 
 93 static void serialize_thread_groups(JfrCheckpointWriter& writer) {
 94   JfrThreadGroupConstant thread_group_set;
 95   writer.write_type(TYPE_THREADGROUP);
 96   thread_group_set.serialize(writer);
 97 }
 98 
 99 void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) {
100   serialize_threads(writer);
101   serialize_thread_groups(writer);
102 }
103 
104 void JfrTypeManager::create_thread_blob(Thread* t) {
105   assert(t != NULL, "invariant");
106   ResourceMark rm(t);
107   HandleMark hm(t);
108   JfrThreadConstant type_thread(t);
109   JfrCheckpointWriter writer(t, true, THREADS, false);
110   writer.write_type(TYPE_THREAD);

111   type_thread.serialize(writer);
112   // create and install a checkpoint blob
113   t->jfr_thread_local()->set_thread_blob(writer.move());
114   assert(t->jfr_thread_local()->has_thread_blob(), "invariant");
115 }
116 
117 void JfrTypeManager::write_thread_checkpoint(Thread* t) {
118   assert(t != NULL, "invariant");
119   if (!t->jfr_thread_local()->has_thread_blob()) {
120     create_thread_blob(t);
121   }
122   JfrCheckpointWriter writer(t, false, THREADS, false);
123   t->jfr_thread_local()->thread_blob()->write(writer);


124 }
125 
126 class SerializerRegistrationGuard : public StackObj {
127  private:
128   static Semaphore _mutex_semaphore;
129  public:
130   SerializerRegistrationGuard() {
131     _mutex_semaphore.wait();
132   }
133   ~SerializerRegistrationGuard() {
134     _mutex_semaphore.signal();
135   }
136 };
137 
138 Semaphore SerializerRegistrationGuard::_mutex_semaphore(1);
139 
140 typedef JfrLinkedList<JfrSerializerRegistration> List;
141 static List types;
142 
143 void JfrTypeManager::destroy() {

 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 "jfr/metadata/jfrSerializer.hpp"
 27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
 28 #include "jfr/recorder/checkpoint/types/jfrType.hpp"
 29 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp"
 30 #include "jfr/recorder/jfrRecorder.hpp"
 31 #include "jfr/support/jfrThreadLocal.hpp"
 32 #include "jfr/utilities/jfrIterator.hpp"
 33 #include "jfr/utilities/jfrLinkedList.inline.hpp"
 34 #include "memory/resourceArea.hpp"


 35 #include "runtime/semaphore.hpp"
 36 #include "runtime/thread.inline.hpp"
 37 #include "utilities/macros.hpp"
 38 
 39 class JfrSerializerRegistration : public JfrCHeapObj {
 40  public:
 41   JfrSerializerRegistration* _next; // list support
 42  private:
 43   JfrSerializer* _serializer;
 44   mutable JfrBlobHandle _cache;
 45   JfrTypeId _id;
 46   bool _permit_cache;
 47  public:
 48   JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) :
 49     _next(NULL), _serializer(serializer), _cache(), _id(id), _permit_cache(permit_cache) {}
 50   ~JfrSerializerRegistration() {
 51     delete _serializer;
 52   }
 53 
 54   JfrTypeId id() const {
 55     return _id;
 56   }
 57 

 82   }
 83 };
 84 
 85 static void serialize_threads(JfrCheckpointWriter& writer) {
 86   JfrThreadConstantSet thread_set;
 87   writer.write_type(TYPE_THREAD);
 88   thread_set.serialize(writer);
 89 }
 90 
 91 static void serialize_thread_groups(JfrCheckpointWriter& writer) {
 92   JfrThreadGroupConstant thread_group_set;
 93   writer.write_type(TYPE_THREADGROUP);
 94   thread_group_set.serialize(writer);
 95 }
 96 
 97 void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) {
 98   serialize_threads(writer);
 99   serialize_thread_groups(writer);
100 }
101 
102 JfrBlobHandle JfrTypeManager::create_thread_blob(JavaThread* jt, traceid tid, oop vthread) {
103   assert(jt != NULL, "invariant");
104   ResourceMark rm(jt);
105   JfrCheckpointWriter writer(jt, true, THREADS, false); // thread local lease


106   writer.write_type(TYPE_THREAD);
107   JfrThreadConstant type_thread(jt, tid, vthread);
108   type_thread.serialize(writer);
109   return writer.move();


110 }
111 
112 void JfrTypeManager::write_checkpoint(Thread* t, traceid tid, oop vthread) {
113   assert(t != NULL, "invariant");
114   Thread* const current = Thread::current(); // not necessarily the same as t
115   assert(current != NULL, "invariant");
116   ResourceMark rm(current);
117   JfrCheckpointWriter writer(current, true, THREADS, !current->is_Java_thread());
118   writer.write_type(TYPE_THREAD);
119   JfrThreadConstant type_thread(t, tid, vthread);
120   type_thread.serialize(writer);
121 }
122 
123 class SerializerRegistrationGuard : public StackObj {
124  private:
125   static Semaphore _mutex_semaphore;
126  public:
127   SerializerRegistrationGuard() {
128     _mutex_semaphore.wait();
129   }
130   ~SerializerRegistrationGuard() {
131     _mutex_semaphore.signal();
132   }
133 };
134 
135 Semaphore SerializerRegistrationGuard::_mutex_semaphore(1);
136 
137 typedef JfrLinkedList<JfrSerializerRegistration> List;
138 static List types;
139 
140 void JfrTypeManager::destroy() {
< prev index next >