提交 8af32fc3 编写于 作者: M mgronlun

8215284: Reduce noise induced by periodic task getFileSize()

Reviewed-by: redestad, egahlin
上级 348423a0
......@@ -33,7 +33,7 @@
#include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp"
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp"
#include "jfr/recorder/repository/jfrRepository.hpp"
#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp"
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/recorder/service/jfrOptionSet.hpp"
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
......@@ -113,7 +113,7 @@ NO_TRANSITION(void, jfr_set_enabled(JNIEnv* env, jobject jvm, jlong event_type_i
NO_TRANSITION_END
NO_TRANSITION(void, jfr_set_file_notification(JNIEnv* env, jobject jvm, jlong threshold))
JfrChunkSizeNotifier::set_chunk_size_threshold((size_t)threshold);
JfrChunkRotation::set_threshold((intptr_t)threshold);
NO_TRANSITION_END
NO_TRANSITION(void, jfr_set_sample_threads(JNIEnv* env, jobject jvm, jboolean sampleThreads))
......@@ -172,6 +172,9 @@ NO_TRANSITION(jboolean, jfr_set_cutoff(JNIEnv* env, jobject jvm, jlong event_typ
return JfrEventSetting::set_cutoff(event_type_id, cutoff_ticks) ? JNI_TRUE : JNI_FALSE;
NO_TRANSITION_END
NO_TRANSITION(jboolean, jfr_should_rotate_disk(JNIEnv* env, jobject jvm))
return JfrChunkRotation::should_rotate() ? JNI_TRUE : JNI_FALSE;
NO_TRANSITION_END
/*
* JVM_ENTRY_NO_ENV entries
......
......@@ -129,6 +129,9 @@ jboolean JNICALL jfr_set_cutoff(JNIEnv* env, jobject jvm, jlong event_type_id, j
void JNICALL jfr_emit_old_object_samples(JNIEnv* env, jobject jvm, jlong cutoff_ticks, jboolean);
jboolean JNICALL jfr_should_rotate_disk(JNIEnv* env, jobject jvm);
#ifdef __cplusplus
}
#endif
......
......@@ -78,7 +78,8 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
(char*)"setForceInstrumentation", (char*)"(Z)V", (void*)jfr_set_force_instrumentation,
(char*)"getUnloadedEventClassCount", (char*)"()J", (void*)jfr_get_unloaded_event_classes_count,
(char*)"setCutoff", (char*)"(JJ)Z", (void*)jfr_set_cutoff,
(char*)"emitOldObjectSamples", (char*)"(JZ)V", (void*)jfr_emit_old_object_samples
(char*)"emitOldObjectSamples", (char*)"(JZ)V", (void*)jfr_emit_old_object_samples,
(char*)"shouldRotateDisk", (char*)"()Z", (void*)jfr_should_rotate_disk
};
const size_t method_array_length = sizeof(method) / sizeof(JNINativeMethod);
......
......@@ -24,29 +24,15 @@
#include "precompiled.hpp"
#include "jfr/jni/jfrJavaSupport.hpp"
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp"
size_t JfrChunkSizeNotifier::_chunk_size_threshold = 0;
static jobject chunk_monitor = NULL;
static intptr_t threshold = 0;
static bool rotate = false;
void JfrChunkSizeNotifier::set_chunk_size_threshold(size_t bytes) {
_chunk_size_threshold = bytes;
}
size_t JfrChunkSizeNotifier::chunk_size_threshold() {
return _chunk_size_threshold;
}
static jobject new_chunk_monitor = NULL;
// lazy install
static jobject get_new_chunk_monitor(Thread* thread) {
static bool initialized = false;
if (initialized) {
assert(new_chunk_monitor != NULL, "invariant");
return new_chunk_monitor;
}
assert(new_chunk_monitor == NULL, "invariant");
static jobject install_chunk_monitor(Thread* thread) {
assert(chunk_monitor == NULL, "invariant");
// read static field
HandleMark hm(thread);
static const char klass[] = "jdk/jfr/internal/JVM";
......@@ -55,19 +41,41 @@ static jobject get_new_chunk_monitor(Thread* thread) {
JavaValue result(T_OBJECT);
JfrJavaArguments field_args(&result, klass, field, signature, thread);
JfrJavaSupport::get_field_global_ref(&field_args, thread);
new_chunk_monitor = result.get_jobject();
initialized = new_chunk_monitor != NULL;
return new_chunk_monitor;
chunk_monitor = result.get_jobject();
return chunk_monitor;
}
void JfrChunkSizeNotifier::notify() {
// lazy install
static jobject get_chunk_monitor(Thread* thread) {
return chunk_monitor != NULL ? chunk_monitor : install_chunk_monitor(thread);
}
static void notify() {
Thread* const thread = Thread::current();
JfrJavaSupport::notify_all(get_new_chunk_monitor(thread), thread);
JfrJavaSupport::notify_all(get_chunk_monitor(thread), thread);
}
void JfrChunkSizeNotifier::release_monitor() {
if (new_chunk_monitor != NULL) {
JfrJavaSupport::destroy_global_jni_handle(new_chunk_monitor);
new_chunk_monitor = NULL;
void JfrChunkRotation::evaluate(const JfrChunkWriter& writer) {
assert(threshold > 0, "invariant");
if (rotate) {
// already in progress
return;
}
assert(!rotate, "invariant");
if (writer.size_written() > threshold) {
rotate = true;
notify();
}
}
bool JfrChunkRotation::should_rotate() {
return rotate;
}
void JfrChunkRotation::on_rotation() {
rotate = false;
}
void JfrChunkRotation::set_threshold(intptr_t bytes) {
threshold = bytes;
}
......@@ -22,24 +22,23 @@
*
*/
#ifndef SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP
#define SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP
#ifndef SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP
#define SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP
#include "memory/allocation.hpp"
class JfrChunkWriter;
//
// Responsible for notifications about current chunk size now exceeding threshold.
// This is a means to initiate a chunk rotation on the basis of size written.
// This is a means to initiate a chunk rotation on the basis of the size written.
//
class JfrChunkSizeNotifier : AllStatic {
friend class JfrRecorder;
private:
static size_t _chunk_size_threshold;
static void release_monitor();
class JfrChunkRotation : AllStatic {
public:
static void set_chunk_size_threshold(size_t bytes);
static size_t chunk_size_threshold();
static void notify();
static void evaluate(const JfrChunkWriter& writer);
static void set_threshold(intptr_t bytes);
static bool should_rotate();
static void on_rotation();
};
#endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP
#endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP
......@@ -28,7 +28,7 @@
#include "jfr/recorder/jfrRecorder.hpp"
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
#include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp"
#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp"
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/recorder/repository/jfrRepository.hpp"
#include "jfr/recorder/service/jfrPostBox.hpp"
......@@ -339,6 +339,7 @@ void JfrRecorderService::prepare_for_vm_error_rotation() {
void JfrRecorderService::open_new_chunk(bool vm_error) {
assert(!_chunkwriter.is_valid(), "invariant");
assert(!JfrStream_lock->owned_by_self(), "invariant");
JfrChunkRotation::on_rotation();
MutexLockerEx stream_lock(JfrStream_lock, Mutex::_no_safepoint_check_flag);
if (!_repository.open_chunk(vm_error)) {
assert(!_chunkwriter.is_valid(), "invariant");
......@@ -534,8 +535,5 @@ void JfrRecorderService::scavenge() {
}
void JfrRecorderService::evaluate_chunk_size_for_rotation() {
const size_t size_written = _chunkwriter.size_written();
if (size_written > JfrChunkSizeNotifier::chunk_size_threshold()) {
JfrChunkSizeNotifier::notify();
}
JfrChunkRotation::evaluate(_chunkwriter);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册