8227011: Starting a JFR recording in response to JVMTI VMInit and / or Java agent premain corrupts memory
Reviewed-by: egahlin, rwestberg
--- a/src/hotspot/share/jfr/recorder/jfrRecorder.cpp Tue Jul 02 14:31:43 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/jfrRecorder.cpp Tue Jul 02 17:46:38 2019 +0200
@@ -194,9 +194,6 @@
if (!validate_recording_options(thread)) {
return false;
}
- if (!JfrJavaEventWriter::initialize()) {
- return false;
- }
if (!JfrOptionSet::configure(thread)) {
return false;
}
@@ -246,6 +243,9 @@
ResourceMark rm;
HandleMark hm;
+ if (!create_java_event_writer()) {
+ return false;
+ }
if (!create_jvmti_agent()) {
return false;
}
@@ -287,6 +287,10 @@
static JfrOSInterface* _os_interface = NULL;
static JfrThreadSampling* _thread_sampling = NULL;
+bool JfrRecorder::create_java_event_writer() {
+ return JfrJavaEventWriter::initialize();
+}
+
bool JfrRecorder::create_jvmti_agent() {
return JfrOptionSet::allow_retransforms() ? JfrJvmtiAgent::create() : true;
}
--- a/src/hotspot/share/jfr/recorder/jfrRecorder.hpp Tue Jul 02 14:31:43 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/jfrRecorder.hpp Tue Jul 02 17:46:38 2019 +0200
@@ -40,6 +40,7 @@
private:
static bool create_checkpoint_manager();
static bool create_chunk_repository();
+ static bool create_java_event_writer();
static bool create_jvmti_agent();
static bool create_os_interface();
static bool create_post_box();
--- a/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp Tue Jul 02 14:31:43 2019 +0200
+++ b/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp Tue Jul 02 17:46:38 2019 +0200
@@ -135,8 +135,7 @@
bool JfrJavaEventWriter::initialize() {
static bool initialized = false;
if (!initialized) {
- Thread* thread = Thread::current();
- initialized = setup_event_writer_offsets(thread);
+ initialized = setup_event_writer_offsets(Thread::current());
}
return initialized;
}
@@ -155,6 +154,7 @@
// large enough to accommodate the "requested size".
const bool is_valid = buffer->free_size() >= (size_t)(used + requested);
u1* const new_current_position = is_valid ? buffer->pos() + used : buffer->pos();
+ assert(start_pos_offset != invalid_offset, "invariant");
w->long_field_put(start_pos_offset, (jlong)buffer->pos());
w->long_field_put(current_pos_offset, (jlong)new_current_position);
// only update java writer if underlying memory changed
--- a/src/hotspot/share/jfr/writers/jfrJavaEventWriter.hpp Tue Jul 02 14:31:43 2019 +0200
+++ b/src/hotspot/share/jfr/writers/jfrJavaEventWriter.hpp Tue Jul 02 17:46:38 2019 +0200
@@ -33,13 +33,14 @@
class JfrJavaEventWriter : AllStatic {
friend class JfrCheckpointThreadClosure;
+ friend class JfrJavaEventWriterNotificationClosure;
friend class JfrJavaEventWriterNotifyOperation;
- friend class JfrJavaEventWriterNotificationClosure;
+ friend class JfrRecorder;
private:
+ static bool initialize();
static void notify(JavaThread* jt);
public:
- static bool initialize();
static void notify();
static jobject event_writer(Thread* t);
static jobject new_event_writer(TRAPS);