--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp Fri May 17 15:53:21 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp Fri May 17 16:02:27 2019 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, 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
@@ -39,7 +39,7 @@
#include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
#include "jfr/recorder/checkpoint/types/jfrTypeSet.hpp"
#include "jfr/support/jfrThreadLocal.hpp"
-#include "jfr/writers/jfrJavaEventWriter.hpp"
+#include "jfr/utilities/jfrThreadIterator.hpp"
#include "memory/metaspaceGCThresholdUpdater.hpp"
#include "memory/referenceType.hpp"
#include "memory/universe.hpp"
@@ -93,12 +93,10 @@
// Requires a ResourceMark for get_thread_name/as_utf8
void JfrCheckpointThreadClosure::do_thread(Thread* t) {
assert(t != NULL, "invariant");
- assert_locked_or_safepoint(Threads_lock);
const JfrThreadLocal* const tl = t->jfr_thread_local();
assert(tl != NULL, "invariant");
- if (tl->is_dead()) {
- return;
- }
+ assert(!tl->is_dead(), "invariant");
+ assert(!tl->is_excluded(), "invariant");
++_count;
_writer.write_key(tl->thread_id());
_writer.write(t->name());
@@ -110,7 +108,6 @@
_writer.write(java_lang_Thread::thread_id(jt->threadObj()));
_writer.write(JfrThreadGroup::thread_group_id(jt, _curthread));
// since we are iterating threads during a safepoint, also issue notification
- JfrJavaEventWriter::notify(jt);
return;
}
_writer.write((const char*)NULL); // java name
@@ -119,13 +116,18 @@
}
void JfrThreadConstantSet::serialize(JfrCheckpointWriter& writer) {
- assert(SafepointSynchronize::is_at_safepoint(), "invariant");
JfrCheckpointThreadClosure tc(writer);
- Threads::threads_do(&tc);
+ JfrJavaThreadIterator javathreads;
+ while (javathreads.has_next()) {
+ tc.do_thread(javathreads.next());
+ }
+ JfrNonJavaThreadIterator nonjavathreads;
+ while (nonjavathreads.has_next()) {
+ tc.do_thread(nonjavathreads.next());
+ }
}
void JfrThreadGroupConstant::serialize(JfrCheckpointWriter& writer) {
- assert(SafepointSynchronize::is_at_safepoint(), "invariant");
JfrThreadGroup::serialize(writer);
}
@@ -298,16 +300,23 @@
class TypeSetSerialization {
private:
+ size_t _elements;
bool _class_unload;
+ bool _flushpoint;
public:
- explicit TypeSetSerialization(bool class_unload) : _class_unload(class_unload) {}
+ explicit TypeSetSerialization(bool class_unload, bool flushpoint) : _elements(0), _class_unload(class_unload), _flushpoint(flushpoint) {}
void write(JfrCheckpointWriter& writer, JfrCheckpointWriter* leakp_writer) {
- JfrTypeSet::serialize(&writer, leakp_writer, _class_unload);
+ MutexLocker cld_lock(SafepointSynchronize::is_at_safepoint() ? NULL : ClassLoaderDataGraph_lock);
+ MutexLocker lock(SafepointSynchronize::is_at_safepoint() ? NULL : Module_lock);
+ _elements = JfrTypeSet::serialize(&writer, leakp_writer, _class_unload, _flushpoint);
+ }
+ size_t elements() const {
+ return _elements;
}
};
void ClassUnloadTypeSet::serialize(JfrCheckpointWriter& writer) {
- TypeSetSerialization type_set(true);
+ TypeSetSerialization type_set(true, false);
if (LeakProfiler::is_running()) {
JfrCheckpointWriter leakp_writer(false, true, Thread::current());
type_set.write(writer, &leakp_writer);
@@ -317,8 +326,19 @@
type_set.write(writer, NULL);
};
+void FlushTypeSet::serialize(JfrCheckpointWriter& writer) {
+ assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
+ TypeSetSerialization type_set(false, true);
+ type_set.write(writer, NULL);
+ _elements = type_set.elements();
+}
+
+size_t FlushTypeSet::elements() const {
+ return _elements;
+}
+
void TypeSet::serialize(JfrCheckpointWriter& writer) {
- TypeSetSerialization type_set(false);
+ TypeSetSerialization type_set(false, false);
if (LeakProfiler::is_suspended()) {
JfrCheckpointWriter leakp_writer(false, true, Thread::current());
type_set.write(writer, &leakp_writer);
@@ -335,20 +355,23 @@
void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) {
assert(_thread != NULL, "invariant");
assert(_thread == Thread::current(), "invariant");
- assert(_thread->is_Java_thread(), "invariant");
- assert(!_thread->jfr_thread_local()->has_thread_checkpoint(), "invariant");
ResourceMark rm(_thread);
- const oop threadObj = _thread->threadObj();
- assert(threadObj != NULL, "invariant");
- const u8 java_lang_thread_id = java_lang_Thread::thread_id(threadObj);
+ HandleMark hm(_thread);
const char* const thread_name = _thread->name();
- const traceid thread_group_id = JfrThreadGroup::thread_group_id(_thread);
writer.write_count(1);
writer.write_key(_thread->jfr_thread_local()->thread_id());
writer.write(thread_name);
writer.write((traceid)_thread->osthread()->thread_id());
- writer.write(thread_name);
- writer.write(java_lang_thread_id);
- writer.write(thread_group_id);
- JfrThreadGroup::serialize(&writer, thread_group_id);
+ if (_thread->is_Java_thread()) {
+ JavaThread* const jt = (JavaThread*)_thread;
+ writer.write(jt->name());
+ writer.write(java_lang_Thread::thread_id(jt->threadObj()));
+ const traceid thread_group_id = JfrThreadGroup::thread_group_id(jt, jt);
+ writer.write(thread_group_id);
+ JfrThreadGroup::serialize(&writer, thread_group_id);
+ return;
+ }
+ writer.write((const char*)NULL); // java name
+ writer.write((traceid)0); // java thread id
+ writer.write((traceid)0); // java thread group
}