Thu, 13 Dec 2018 14:36:54 +0100
8215284: Reduce noise induced by periodic task getFileSize()
Reviewed-by: redestad, egahlin
1.1 --- a/src/share/vm/jfr/jni/jfrJniMethod.cpp Thu Dec 13 14:21:04 2018 +0100 1.2 +++ b/src/share/vm/jfr/jni/jfrJniMethod.cpp Thu Dec 13 14:36:54 2018 +0100 1.3 @@ -33,7 +33,7 @@ 1.4 #include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp" 1.5 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" 1.6 #include "jfr/recorder/repository/jfrRepository.hpp" 1.7 -#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp" 1.8 +#include "jfr/recorder/repository/jfrChunkRotation.hpp" 1.9 #include "jfr/recorder/repository/jfrChunkWriter.hpp" 1.10 #include "jfr/recorder/service/jfrOptionSet.hpp" 1.11 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" 1.12 @@ -113,7 +113,7 @@ 1.13 NO_TRANSITION_END 1.14 1.15 NO_TRANSITION(void, jfr_set_file_notification(JNIEnv* env, jobject jvm, jlong threshold)) 1.16 - JfrChunkSizeNotifier::set_chunk_size_threshold((size_t)threshold); 1.17 + JfrChunkRotation::set_threshold((intptr_t)threshold); 1.18 NO_TRANSITION_END 1.19 1.20 NO_TRANSITION(void, jfr_set_sample_threads(JNIEnv* env, jobject jvm, jboolean sampleThreads)) 1.21 @@ -172,6 +172,9 @@ 1.22 return JfrEventSetting::set_cutoff(event_type_id, cutoff_ticks) ? JNI_TRUE : JNI_FALSE; 1.23 NO_TRANSITION_END 1.24 1.25 +NO_TRANSITION(jboolean, jfr_should_rotate_disk(JNIEnv* env, jobject jvm)) 1.26 + return JfrChunkRotation::should_rotate() ? JNI_TRUE : JNI_FALSE; 1.27 +NO_TRANSITION_END 1.28 1.29 /* 1.30 * JVM_ENTRY_NO_ENV entries
2.1 --- a/src/share/vm/jfr/jni/jfrJniMethod.hpp Thu Dec 13 14:21:04 2018 +0100 2.2 +++ b/src/share/vm/jfr/jni/jfrJniMethod.hpp Thu Dec 13 14:36:54 2018 +0100 2.3 @@ -129,6 +129,9 @@ 2.4 2.5 void JNICALL jfr_emit_old_object_samples(JNIEnv* env, jobject jvm, jlong cutoff_ticks, jboolean); 2.6 2.7 +jboolean JNICALL jfr_should_rotate_disk(JNIEnv* env, jobject jvm); 2.8 + 2.9 + 2.10 #ifdef __cplusplus 2.11 } 2.12 #endif
3.1 --- a/src/share/vm/jfr/jni/jfrJniMethodRegistration.cpp Thu Dec 13 14:21:04 2018 +0100 3.2 +++ b/src/share/vm/jfr/jni/jfrJniMethodRegistration.cpp Thu Dec 13 14:36:54 2018 +0100 3.3 @@ -78,7 +78,8 @@ 3.4 (char*)"setForceInstrumentation", (char*)"(Z)V", (void*)jfr_set_force_instrumentation, 3.5 (char*)"getUnloadedEventClassCount", (char*)"()J", (void*)jfr_get_unloaded_event_classes_count, 3.6 (char*)"setCutoff", (char*)"(JJ)Z", (void*)jfr_set_cutoff, 3.7 - (char*)"emitOldObjectSamples", (char*)"(JZ)V", (void*)jfr_emit_old_object_samples 3.8 + (char*)"emitOldObjectSamples", (char*)"(JZ)V", (void*)jfr_emit_old_object_samples, 3.9 + (char*)"shouldRotateDisk", (char*)"()Z", (void*)jfr_should_rotate_disk 3.10 }; 3.11 3.12 const size_t method_array_length = sizeof(method) / sizeof(JNINativeMethod);
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/share/vm/jfr/recorder/repository/jfrChunkRotation.cpp Thu Dec 13 14:36:54 2018 +0100 4.3 @@ -0,0 +1,81 @@ 4.4 +/* 4.5 + * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + * 4.26 + */ 4.27 + 4.28 +#include "precompiled.hpp" 4.29 +#include "jfr/jni/jfrJavaSupport.hpp" 4.30 +#include "jfr/recorder/repository/jfrChunkRotation.hpp" 4.31 +#include "jfr/recorder/repository/jfrChunkWriter.hpp" 4.32 + 4.33 +static jobject chunk_monitor = NULL; 4.34 +static intptr_t threshold = 0; 4.35 +static bool rotate = false; 4.36 + 4.37 +static jobject install_chunk_monitor(Thread* thread) { 4.38 + assert(chunk_monitor == NULL, "invariant"); 4.39 + // read static field 4.40 + HandleMark hm(thread); 4.41 + static const char klass[] = "jdk/jfr/internal/JVM"; 4.42 + static const char field[] = "FILE_DELTA_CHANGE"; 4.43 + static const char signature[] = "Ljava/lang/Object;"; 4.44 + JavaValue result(T_OBJECT); 4.45 + JfrJavaArguments field_args(&result, klass, field, signature, thread); 4.46 + JfrJavaSupport::get_field_global_ref(&field_args, thread); 4.47 + chunk_monitor = result.get_jobject(); 4.48 + return chunk_monitor; 4.49 +} 4.50 + 4.51 +// lazy install 4.52 +static jobject get_chunk_monitor(Thread* thread) { 4.53 + return chunk_monitor != NULL ? chunk_monitor : install_chunk_monitor(thread); 4.54 +} 4.55 + 4.56 +static void notify() { 4.57 + Thread* const thread = Thread::current(); 4.58 + JfrJavaSupport::notify_all(get_chunk_monitor(thread), thread); 4.59 +} 4.60 + 4.61 +void JfrChunkRotation::evaluate(const JfrChunkWriter& writer) { 4.62 + assert(threshold > 0, "invariant"); 4.63 + if (rotate) { 4.64 + // already in progress 4.65 + return; 4.66 + } 4.67 + assert(!rotate, "invariant"); 4.68 + if (writer.size_written() > threshold) { 4.69 + rotate = true; 4.70 + notify(); 4.71 + } 4.72 +} 4.73 + 4.74 +bool JfrChunkRotation::should_rotate() { 4.75 + return rotate; 4.76 +} 4.77 + 4.78 +void JfrChunkRotation::on_rotation() { 4.79 + rotate = false; 4.80 +} 4.81 + 4.82 +void JfrChunkRotation::set_threshold(intptr_t bytes) { 4.83 + threshold = bytes; 4.84 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/share/vm/jfr/recorder/repository/jfrChunkRotation.hpp Thu Dec 13 14:36:54 2018 +0100 5.3 @@ -0,0 +1,44 @@ 5.4 +/* 5.5 + * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + * 5.26 + */ 5.27 + 5.28 +#ifndef SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP 5.29 +#define SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP 5.30 + 5.31 +#include "memory/allocation.hpp" 5.32 + 5.33 +class JfrChunkWriter; 5.34 + 5.35 +// 5.36 +// Responsible for notifications about current chunk size now exceeding threshold. 5.37 +// This is a means to initiate a chunk rotation on the basis of the size written. 5.38 +// 5.39 +class JfrChunkRotation : AllStatic { 5.40 + public: 5.41 + static void evaluate(const JfrChunkWriter& writer); 5.42 + static void set_threshold(intptr_t bytes); 5.43 + static bool should_rotate(); 5.44 + static void on_rotation(); 5.45 +}; 5.46 + 5.47 +#endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRCHUNKROTATION_HPP
6.1 --- a/src/share/vm/jfr/recorder/repository/jfrChunkSizeNotifier.cpp Thu Dec 13 14:21:04 2018 +0100 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,73 +0,0 @@ 6.4 -/* 6.5 - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 - * 6.8 - * This code is free software; you can redistribute it and/or modify it 6.9 - * under the terms of the GNU General Public License version 2 only, as 6.10 - * published by the Free Software Foundation. 6.11 - * 6.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 - * version 2 for more details (a copy is included in the LICENSE file that 6.16 - * accompanied this code). 6.17 - * 6.18 - * You should have received a copy of the GNU General Public License version 6.19 - * 2 along with this work; if not, write to the Free Software Foundation, 6.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 - * 6.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 - * or visit www.oracle.com if you need additional information or have any 6.24 - * questions. 6.25 - * 6.26 - */ 6.27 - 6.28 -#include "precompiled.hpp" 6.29 -#include "jfr/jni/jfrJavaSupport.hpp" 6.30 -#include "jfr/recorder/repository/jfrChunkWriter.hpp" 6.31 -#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp" 6.32 - 6.33 -size_t JfrChunkSizeNotifier::_chunk_size_threshold = 0; 6.34 - 6.35 -void JfrChunkSizeNotifier::set_chunk_size_threshold(size_t bytes) { 6.36 - _chunk_size_threshold = bytes; 6.37 -} 6.38 - 6.39 -size_t JfrChunkSizeNotifier::chunk_size_threshold() { 6.40 - return _chunk_size_threshold; 6.41 -} 6.42 - 6.43 -static jobject new_chunk_monitor = NULL; 6.44 - 6.45 -// lazy install 6.46 -static jobject get_new_chunk_monitor(Thread* thread) { 6.47 - static bool initialized = false; 6.48 - if (initialized) { 6.49 - assert(new_chunk_monitor != NULL, "invariant"); 6.50 - return new_chunk_monitor; 6.51 - } 6.52 - assert(new_chunk_monitor == NULL, "invariant"); 6.53 - // read static field 6.54 - HandleMark hm(thread); 6.55 - static const char klass[] = "jdk/jfr/internal/JVM"; 6.56 - static const char field[] = "FILE_DELTA_CHANGE"; 6.57 - static const char signature[] = "Ljava/lang/Object;"; 6.58 - JavaValue result(T_OBJECT); 6.59 - JfrJavaArguments field_args(&result, klass, field, signature, thread); 6.60 - JfrJavaSupport::get_field_global_ref(&field_args, thread); 6.61 - new_chunk_monitor = result.get_jobject(); 6.62 - initialized = new_chunk_monitor != NULL; 6.63 - return new_chunk_monitor; 6.64 -} 6.65 - 6.66 -void JfrChunkSizeNotifier::notify() { 6.67 - Thread* const thread = Thread::current(); 6.68 - JfrJavaSupport::notify_all(get_new_chunk_monitor(thread), thread); 6.69 -} 6.70 - 6.71 -void JfrChunkSizeNotifier::release_monitor() { 6.72 - if (new_chunk_monitor != NULL) { 6.73 - JfrJavaSupport::destroy_global_jni_handle(new_chunk_monitor); 6.74 - new_chunk_monitor = NULL; 6.75 - } 6.76 -}
7.1 --- a/src/share/vm/jfr/recorder/repository/jfrChunkSizeNotifier.hpp Thu Dec 13 14:21:04 2018 +0100 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,45 +0,0 @@ 7.4 -/* 7.5 - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 7.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 - * 7.8 - * This code is free software; you can redistribute it and/or modify it 7.9 - * under the terms of the GNU General Public License version 2 only, as 7.10 - * published by the Free Software Foundation. 7.11 - * 7.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 - * version 2 for more details (a copy is included in the LICENSE file that 7.16 - * accompanied this code). 7.17 - * 7.18 - * You should have received a copy of the GNU General Public License version 7.19 - * 2 along with this work; if not, write to the Free Software Foundation, 7.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 - * 7.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 - * or visit www.oracle.com if you need additional information or have any 7.24 - * questions. 7.25 - * 7.26 - */ 7.27 - 7.28 -#ifndef SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP 7.29 -#define SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP 7.30 - 7.31 -#include "memory/allocation.hpp" 7.32 - 7.33 -// 7.34 -// Responsible for notifications about current chunk size now exceeding threshold. 7.35 -// This is a means to initiate a chunk rotation on the basis of size written. 7.36 -// 7.37 -class JfrChunkSizeNotifier : AllStatic { 7.38 - friend class JfrRecorder; 7.39 - private: 7.40 - static size_t _chunk_size_threshold; 7.41 - static void release_monitor(); 7.42 - public: 7.43 - static void set_chunk_size_threshold(size_t bytes); 7.44 - static size_t chunk_size_threshold(); 7.45 - static void notify(); 7.46 -}; 7.47 - 7.48 -#endif // SHARE_VM_JFR_RECORDER_REPOSITORY_JFRRCHUNKSIZENOTIFIER_HPP
8.1 --- a/src/share/vm/jfr/recorder/service/jfrRecorderService.cpp Thu Dec 13 14:21:04 2018 +0100 8.2 +++ b/src/share/vm/jfr/recorder/service/jfrRecorderService.cpp Thu Dec 13 14:36:54 2018 +0100 8.3 @@ -28,7 +28,7 @@ 8.4 #include "jfr/recorder/jfrRecorder.hpp" 8.5 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" 8.6 #include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp" 8.7 -#include "jfr/recorder/repository/jfrChunkSizeNotifier.hpp" 8.8 +#include "jfr/recorder/repository/jfrChunkRotation.hpp" 8.9 #include "jfr/recorder/repository/jfrChunkWriter.hpp" 8.10 #include "jfr/recorder/repository/jfrRepository.hpp" 8.11 #include "jfr/recorder/service/jfrPostBox.hpp" 8.12 @@ -339,6 +339,7 @@ 8.13 void JfrRecorderService::open_new_chunk(bool vm_error) { 8.14 assert(!_chunkwriter.is_valid(), "invariant"); 8.15 assert(!JfrStream_lock->owned_by_self(), "invariant"); 8.16 + JfrChunkRotation::on_rotation(); 8.17 MutexLockerEx stream_lock(JfrStream_lock, Mutex::_no_safepoint_check_flag); 8.18 if (!_repository.open_chunk(vm_error)) { 8.19 assert(!_chunkwriter.is_valid(), "invariant"); 8.20 @@ -534,8 +535,5 @@ 8.21 } 8.22 8.23 void JfrRecorderService::evaluate_chunk_size_for_rotation() { 8.24 - const size_t size_written = _chunkwriter.size_written(); 8.25 - if (size_written > JfrChunkSizeNotifier::chunk_size_threshold()) { 8.26 - JfrChunkSizeNotifier::notify(); 8.27 - } 8.28 + JfrChunkRotation::evaluate(_chunkwriter); 8.29 }