提交 713095a2 编写于 作者: D Denghui Dong 提交者: D-D-H

[Backport] 8233700: EventStream not closed

Summary:

Test Plan: jdk/jfr

Reviewed-by: yuleil

Issue: https://github.com/alibaba/dragonwell8/issues/112
上级 79ae032e
...@@ -229,6 +229,10 @@ JVM_ENTRY_NO_ENV(void, jfr_begin_recording(JNIEnv* env, jobject jvm)) ...@@ -229,6 +229,10 @@ JVM_ENTRY_NO_ENV(void, jfr_begin_recording(JNIEnv* env, jobject jvm))
JfrRecorder::start_recording(); JfrRecorder::start_recording();
JVM_END JVM_END
JVM_ENTRY_NO_ENV(jboolean, jfr_is_recording(JNIEnv * env, jobject jvm))
return JfrRecorder::is_recording() ? JNI_TRUE : JNI_FALSE;
JVM_END
JVM_ENTRY_NO_ENV(void, jfr_end_recording(JNIEnv* env, jobject jvm)) JVM_ENTRY_NO_ENV(void, jfr_end_recording(JNIEnv* env, jobject jvm))
if (!JfrRecorder::is_recording()) { if (!JfrRecorder::is_recording()) {
return; return;
...@@ -236,6 +240,9 @@ JVM_ENTRY_NO_ENV(void, jfr_end_recording(JNIEnv* env, jobject jvm)) ...@@ -236,6 +240,9 @@ JVM_ENTRY_NO_ENV(void, jfr_end_recording(JNIEnv* env, jobject jvm))
JfrRecorder::stop_recording(); JfrRecorder::stop_recording();
JVM_END JVM_END
JVM_ENTRY_NO_ENV(void, jfr_mark_chunk_final(JNIEnv * env, jobject jvm))
JfrRepository::mark_chunk_final();
JVM_END
JVM_ENTRY_NO_ENV(jboolean, jfr_emit_event(JNIEnv* env, jobject jvm, jlong eventTypeId, jlong timeStamp, jlong when)) JVM_ENTRY_NO_ENV(jboolean, jfr_emit_event(JNIEnv* env, jobject jvm, jlong eventTypeId, jlong timeStamp, jlong when))
JfrPeriodicEventSet::requestEvent((JfrEventId)eventTypeId); JfrPeriodicEventSet::requestEvent((JfrEventId)eventTypeId);
......
...@@ -49,8 +49,12 @@ jboolean JNICALL jfr_destroy_jfr(JNIEnv* env, jobject jvm); ...@@ -49,8 +49,12 @@ jboolean JNICALL jfr_destroy_jfr(JNIEnv* env, jobject jvm);
void JNICALL jfr_begin_recording(JNIEnv* env, jobject jvm); void JNICALL jfr_begin_recording(JNIEnv* env, jobject jvm);
jboolean JNICALL jfr_is_recording(JNIEnv* env, jobject jvm);
void JNICALL jfr_end_recording(JNIEnv* env, jobject jvm); void JNICALL jfr_end_recording(JNIEnv* env, jobject jvm);
void JNICALL jfr_mark_chunk_final(JNIEnv* env, jobject jvm);
jboolean JNICALL jfr_emit_event(JNIEnv* env, jobject jvm, jlong eventTypeId, jlong timeStamp, jlong when); jboolean JNICALL jfr_emit_event(JNIEnv* env, jobject jvm, jlong eventTypeId, jlong timeStamp, jlong when);
jobject JNICALL jfr_get_all_event_classes(JNIEnv* env, jobject jvm); jobject JNICALL jfr_get_all_event_classes(JNIEnv* env, jobject jvm);
......
...@@ -36,7 +36,9 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) { ...@@ -36,7 +36,9 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
if (jfr_clz != NULL) { if (jfr_clz != NULL) {
JNINativeMethod method[] = { JNINativeMethod method[] = {
(char*)"beginRecording", (char*)"()V", (void*)jfr_begin_recording, (char*)"beginRecording", (char*)"()V", (void*)jfr_begin_recording,
(char*)"isRecording", (char*)"()Z", (void*)jfr_is_recording,
(char*)"endRecording", (char*)"()V", (void*)jfr_end_recording, (char*)"endRecording", (char*)"()V", (void*)jfr_end_recording,
(char*)"markChunkFinal", (char*)"()V", (void*)jfr_mark_chunk_final,
(char*)"counterTime", (char*)"()J", (void*)jfr_elapsed_counter, (char*)"counterTime", (char*)"()J", (void*)jfr_elapsed_counter,
(char*)"createJFR", (char*)"(Z)Z", (void*)jfr_create_jfr, (char*)"createJFR", (char*)"(Z)Z", (void*)jfr_create_jfr,
(char*)"destroyJFR", (char*)"()Z", (void*)jfr_destroy_jfr, (char*)"destroyJFR", (char*)"()Z", (void*)jfr_destroy_jfr,
......
...@@ -59,7 +59,8 @@ JfrChunk::JfrChunk() : ...@@ -59,7 +59,8 @@ JfrChunk::JfrChunk() :
_last_update_nanos(0), _last_update_nanos(0),
_last_checkpoint_offset(0), _last_checkpoint_offset(0),
_last_metadata_offset(0), _last_metadata_offset(0),
_generation(1) {} _generation(1),
_final(false) {}
JfrChunk::~JfrChunk() { JfrChunk::~JfrChunk() {
reset(); reset();
...@@ -86,10 +87,20 @@ u2 JfrChunk::minor_version() const { ...@@ -86,10 +87,20 @@ u2 JfrChunk::minor_version() const {
return JFR_VERSION_MINOR; return JFR_VERSION_MINOR;
} }
u2 JfrChunk::capabilities() const { void JfrChunk::mark_final() {
_final = true;
}
u2 JfrChunk::flags() const {
// chunk capabilities, CompressedIntegers etc // chunk capabilities, CompressedIntegers etc
static bool compressed_integers = JfrOptionSet::compressed_integers(); u2 flags = 0;
return compressed_integers; if (JfrOptionSet::compressed_integers()) {
flags |= 1 << 0;
}
if (_final) {
flags |= 1 << 1;
}
return flags;
} }
int64_t JfrChunk::cpu_frequency() const { int64_t JfrChunk::cpu_frequency() const {
......
...@@ -44,6 +44,7 @@ class JfrChunk : public JfrCHeapObj { ...@@ -44,6 +44,7 @@ class JfrChunk : public JfrCHeapObj {
int64_t _last_checkpoint_offset; int64_t _last_checkpoint_offset;
int64_t _last_metadata_offset; int64_t _last_metadata_offset;
mutable u1 _generation; mutable u1 _generation;
bool _final;
JfrChunk(); JfrChunk();
~JfrChunk(); ~JfrChunk();
...@@ -53,7 +54,9 @@ class JfrChunk : public JfrCHeapObj { ...@@ -53,7 +54,9 @@ class JfrChunk : public JfrCHeapObj {
u2 major_version() const; u2 major_version() const;
u2 minor_version() const; u2 minor_version() const;
int64_t cpu_frequency() const; int64_t cpu_frequency() const;
u2 capabilities() const; u2 flags() const;
void mark_final();
void update_start_ticks(); void update_start_ticks();
void update_start_nanos(); void update_start_nanos();
......
...@@ -41,8 +41,8 @@ static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE; ...@@ -41,8 +41,8 @@ static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE;
static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE; static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE;
static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE; static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE;
static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE; static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE;
static const int64_t CAPABILITY_OFFSET = GENERATION_OFFSET + 2; static const int64_t FLAG_OFFSET = GENERATION_OFFSET + 2;
static const int64_t HEADER_SIZE = CAPABILITY_OFFSET + 2; static const int64_t HEADER_SIZE = FLAG_OFFSET + 2;
static fio_fd open_chunk(const char* path) { static fio_fd open_chunk(const char* path) {
assert(JfrStream_lock->owned_by_self(), "invariant"); assert(JfrStream_lock->owned_by_self(), "invariant");
...@@ -118,8 +118,8 @@ class JfrChunkHeadWriter : public StackObj { ...@@ -118,8 +118,8 @@ class JfrChunkHeadWriter : public StackObj {
_writer->flush(); _writer->flush();
} }
void write_capabilities() { void write_flags() {
_writer->be_write(_chunk->capabilities()); _writer->be_write(_chunk->flags());
} }
void write_size_to_generation(int64_t size, bool finalize) { void write_size_to_generation(int64_t size, bool finalize) {
...@@ -136,7 +136,7 @@ class JfrChunkHeadWriter : public StackObj { ...@@ -136,7 +136,7 @@ class JfrChunkHeadWriter : public StackObj {
assert(_chunk != NULL, "invariant"); assert(_chunk != NULL, "invariant");
DEBUG_ONLY(assert_writer_position(_writer, SIZE_OFFSET);) DEBUG_ONLY(assert_writer_position(_writer, SIZE_OFFSET);)
write_size_to_generation(size, finalize); write_size_to_generation(size, finalize);
// no need to write capabilities write_flags();
_writer->seek(size); // implicit flush _writer->seek(size); // implicit flush
} }
...@@ -147,7 +147,7 @@ class JfrChunkHeadWriter : public StackObj { ...@@ -147,7 +147,7 @@ class JfrChunkHeadWriter : public StackObj {
write_magic(); write_magic();
write_version(); write_version();
write_size_to_generation(HEADER_SIZE, false); write_size_to_generation(HEADER_SIZE, false);
write_capabilities(); write_flags();
DEBUG_ONLY(assert_writer_position(_writer, HEADER_SIZE);) DEBUG_ONLY(assert_writer_position(_writer, HEADER_SIZE);)
_writer->flush(); _writer->flush();
} }
...@@ -202,7 +202,7 @@ int64_t JfrChunkWriter::write_chunk_header_checkpoint(bool flushpoint) { ...@@ -202,7 +202,7 @@ int64_t JfrChunkWriter::write_chunk_header_checkpoint(bool flushpoint) {
head.write_time(false); head.write_time(false);
head.write_cpu_frequency(); head.write_cpu_frequency();
head.write_next_generation(); head.write_next_generation();
head.write_capabilities(); head.write_flags();
assert(current_offset() - header_content_pos == HEADER_SIZE, "invariant"); assert(current_offset() - header_content_pos == HEADER_SIZE, "invariant");
const u4 checkpoint_size = current_offset() - event_size_offset; const u4 checkpoint_size = current_offset() - event_size_offset;
write_padded_at_offset<u4>(checkpoint_size, event_size_offset); write_padded_at_offset<u4>(checkpoint_size, event_size_offset);
...@@ -212,6 +212,11 @@ int64_t JfrChunkWriter::write_chunk_header_checkpoint(bool flushpoint) { ...@@ -212,6 +212,11 @@ int64_t JfrChunkWriter::write_chunk_header_checkpoint(bool flushpoint) {
return sz_written; return sz_written;
} }
void JfrChunkWriter::mark_chunk_final() {
assert(_chunk != NULL, "invariant");
_chunk->mark_final();
}
int64_t JfrChunkWriter::flush_chunk(bool flushpoint) { int64_t JfrChunkWriter::flush_chunk(bool flushpoint) {
assert(_chunk != NULL, "invariant"); assert(_chunk != NULL, "invariant");
const int64_t sz_written = write_chunk_header_checkpoint(flushpoint); const int64_t sz_written = write_chunk_header_checkpoint(flushpoint);
......
...@@ -59,6 +59,7 @@ class JfrChunkWriter : public JfrChunkWriterBase { ...@@ -59,6 +59,7 @@ class JfrChunkWriter : public JfrChunkWriterBase {
bool has_metadata() const; bool has_metadata() const;
void set_time_stamp(); void set_time_stamp();
void mark_chunk_final();
}; };
#endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKWRITER_HPP #endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKWRITER_HPP
...@@ -114,6 +114,10 @@ void JfrRepository::set_chunk_path(const char* path) { ...@@ -114,6 +114,10 @@ void JfrRepository::set_chunk_path(const char* path) {
chunkwriter().set_path(path); chunkwriter().set_path(path);
} }
void JfrRepository::mark_chunk_final() {
chunkwriter().mark_chunk_final();
}
jlong JfrRepository::current_chunk_start_nanos() { jlong JfrRepository::current_chunk_start_nanos() {
return chunkwriter().current_chunk_start_nanos(); return chunkwriter().current_chunk_start_nanos();
} }
......
...@@ -70,6 +70,7 @@ class JfrRepository : public JfrCHeapObj { ...@@ -70,6 +70,7 @@ class JfrRepository : public JfrCHeapObj {
public: public:
static void set_path(jstring location, JavaThread* jt); static void set_path(jstring location, JavaThread* jt);
static void set_chunk_path(jstring path, JavaThread* jt); static void set_chunk_path(jstring path, JavaThread* jt);
static void mark_chunk_final();
static void flush(JavaThread* jt); static void flush(JavaThread* jt);
static jlong current_chunk_start_nanos(); static jlong current_chunk_start_nanos();
}; };
......
...@@ -432,6 +432,7 @@ void JfrRecorderService::vm_error_rotation() { ...@@ -432,6 +432,7 @@ void JfrRecorderService::vm_error_rotation() {
if (_chunkwriter.is_valid()) { if (_chunkwriter.is_valid()) {
Thread* const t = Thread::current(); Thread* const t = Thread::current();
_storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t); _storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t);
_chunkwriter.mark_chunk_final();
invoke_flush(); invoke_flush();
_chunkwriter.set_time_stamp(); _chunkwriter.set_time_stamp();
_repository.close_chunk(); _repository.close_chunk();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册