Skip to content

Commit ace70a6

Browse files
committed
8358666: [REDO] Implement JEP 509: JFR CPU-Time Profiling
Reviewed-by: mgronlun
1 parent 48b97ac commit ace70a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2191
-140
lines changed

src/hotspot/os/posix/signals_posix.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,14 @@ bool PosixSignals::is_sig_ignored(int sig) {
15051505
}
15061506
}
15071507

1508+
void* PosixSignals::get_signal_handler_for_signal(int sig) {
1509+
struct sigaction oact;
1510+
if (sigaction(sig, (struct sigaction*)nullptr, &oact) == -1) {
1511+
return nullptr;
1512+
}
1513+
return get_signal_handler(&oact);
1514+
}
1515+
15081516
static void signal_sets_init() {
15091517
sigemptyset(&preinstalled_sigs);
15101518

src/hotspot/os/posix/signals_posix.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class PosixSignals : public AllStatic {
5252

5353
static bool is_sig_ignored(int sig);
5454

55+
static void* get_signal_handler_for_signal(int sig);
56+
5557
static void hotspot_sigmask(Thread* thread);
5658

5759
static void print_signal_handler(outputStream* st, int sig, char* buf, size_t buflen);

src/hotspot/share/jfr/jfr.inline.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
inline bool Jfr::has_sample_request(JavaThread* jt) {
3434
assert(jt != nullptr, "invariant");
35-
return jt->jfr_thread_local()->has_sample_request();
35+
JfrThreadLocal* tl = jt->jfr_thread_local();
36+
return tl->has_sample_request() || tl->has_cpu_time_jfr_requests();
3637
}
3738

3839
inline void Jfr::check_and_process_sample_request(JavaThread* jt) {

src/hotspot/share/jfr/jni/jfrJniMethod.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "jfr/jfr.hpp"
2626
#include "jfr/jfrEvents.hpp"
27+
#include "jfr/periodic/sampling/jfrCPUTimeThreadSampler.hpp"
2728
#include "jfr/periodic/sampling/jfrThreadSampler.hpp"
2829
#include "jfr/recorder/jfrEventSetting.hpp"
2930
#include "jfr/recorder/jfrRecorder.hpp"
@@ -169,6 +170,11 @@ NO_TRANSITION(jboolean, jfr_set_throttle(JNIEnv* env, jclass jvm, jlong event_ty
169170
return JNI_TRUE;
170171
NO_TRANSITION_END
171172

173+
JVM_ENTRY_NO_ENV(void, jfr_set_cpu_throttle(JNIEnv* env, jclass jvm, jdouble rate, jboolean auto_adapt))
174+
JfrEventSetting::set_enabled(JfrCPUTimeSampleEvent, rate > 0);
175+
JfrCPUTimeThreadSampling::set_rate(rate, auto_adapt == JNI_TRUE);
176+
JVM_END
177+
172178
NO_TRANSITION(void, jfr_set_miscellaneous(JNIEnv* env, jclass jvm, jlong event_type_id, jlong value))
173179
JfrEventSetting::set_miscellaneous(event_type_id, value);
174180
const JfrEventId typed_event_id = (JfrEventId)event_type_id;

src/hotspot/share/jfr/jni/jfrJniMethod.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ jlong JNICALL jfr_get_unloaded_event_classes_count(JNIEnv* env, jclass jvm);
129129

130130
jboolean JNICALL jfr_set_throttle(JNIEnv* env, jclass jvm, jlong event_type_id, jlong event_sample_size, jlong period_ms);
131131

132+
void JNICALL jfr_set_cpu_throttle(JNIEnv* env, jclass jvm, jdouble rate, jboolean auto_adapt);
133+
132134
void JNICALL jfr_set_miscellaneous(JNIEnv* env, jclass jvm, jlong id, jlong value);
133135

134136
void JNICALL jfr_emit_old_object_samples(JNIEnv* env, jclass jvm, jlong cutoff_ticks, jboolean, jboolean);

src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
8383
(char*)"getUnloadedEventClassCount", (char*)"()J", (void*)jfr_get_unloaded_event_classes_count,
8484
(char*)"setMiscellaneous", (char*)"(JJ)V", (void*)jfr_set_miscellaneous,
8585
(char*)"setThrottle", (char*)"(JJJ)Z", (void*)jfr_set_throttle,
86+
(char*)"setCPUThrottle", (char*)"(DZ)V", (void*)jfr_set_cpu_throttle,
8687
(char*)"emitOldObjectSamples", (char*)"(JZZ)V", (void*)jfr_emit_old_object_samples,
8788
(char*)"shouldRotateDisk", (char*)"()Z", (void*)jfr_should_rotate_disk,
8889
(char*)"exclude", (char*)"(Ljava/lang/Thread;)V", (void*)jfr_exclude_thread,

src/hotspot/share/jfr/metadata/metadata.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,22 @@
962962
<Field type="ThreadState" name="state" label="Thread State" />
963963
</Event>
964964

965+
<Event name="CPUTimeSample" category="Java Virtual Machine, Profiling" label="CPU Time Method Sample"
966+
description="Snapshot of a threads state from the CPU time sampler. The throttle can be either an upper bound for the event emission rate, e.g. 100/s, or the cpu-time period, e.g. 10ms, with s, ms, us and ns supported as time units."
967+
throttle="true" thread="false" experimental="true" startTime="false">
968+
<Field type="StackTrace" name="stackTrace" label="Stack Trace" />
969+
<Field type="Thread" name="eventThread" label="Thread" />
970+
<Field type="boolean" name="failed" label="Failed" description="Failed to obtain the stack trace" />
971+
<Field type="Tickspan" name="samplingPeriod" label="CPU Time Sampling Period"/>
972+
<Field type="boolean" name="biased" label="Biased" description="The sample is safepoint-biased" />
973+
</Event>
974+
975+
<Event name="CPUTimeSamplesLost" category="Java Virtual Machine, Profiling" label="CPU Time Method Profiling Lost Samples" description="Records that the CPU time sampler lost samples"
976+
thread="false" stackTrace="false" startTime="false" experimental="true">
977+
<Field type="int" name="lostSamples" label="Lost Samples" />
978+
<Field type="Thread" name="eventThread" label="Thread" />
979+
</Event>
980+
965981
<Event name="ThreadDump" category="Java Virtual Machine, Runtime" label="Thread Dump" period="everyChunk">
966982
<Field type="string" name="result" label="Thread Dump" />
967983
</Event>

0 commit comments

Comments
 (0)