8227011: Starting a JFR recording in response to JVMTI VMInit and / or Java agent premain corrupts memory

Reviewed-by: egahlin, rwestberg
This commit is contained in:
Markus Grönlund 2019-07-02 17:46:38 +02:00
parent 6e16ff4cea
commit ebde73209f
4 changed files with 13 additions and 7 deletions

@ -194,9 +194,6 @@ bool JfrRecorder::on_vm_start() {
if (!validate_recording_options(thread)) {
return false;
}
if (!JfrJavaEventWriter::initialize()) {
return false;
}
if (!JfrOptionSet::configure(thread)) {
return false;
}
@ -246,6 +243,9 @@ bool JfrRecorder::create_components() {
ResourceMark rm;
HandleMark hm;
if (!create_java_event_writer()) {
return false;
}
if (!create_jvmti_agent()) {
return false;
}
@ -287,6 +287,10 @@ static JfrStringPool* _stringpool = NULL;
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;
}

@ -40,6 +40,7 @@ class JfrRecorder : public JfrCHeapObj {
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();

@ -135,8 +135,7 @@ static bool setup_event_writer_offsets(TRAPS) {
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 @@ jboolean JfrJavaEventWriter::flush(jobject writer, jint used, jint requested, Ja
// 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

@ -33,13 +33,14 @@ class Thread;
class JfrJavaEventWriter : AllStatic {
friend class JfrCheckpointThreadClosure;
friend class JfrJavaEventWriterNotifyOperation;
friend class JfrJavaEventWriterNotificationClosure;
friend class JfrJavaEventWriterNotifyOperation;
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);