RFR: 8342818: Implement JEP 509: JFR CPU-Time Profiling [v50]
Johannes Bechberger
jbechberger at openjdk.org
Wed Jun 4 14:59:33 UTC 2025
On Wed, 4 Jun 2025 14:54:44 GMT, Patricio Chilano Mateo <pchilanomate at openjdk.org> wrote:
>> Which differences to the example code are you seeing?
>>
>>
>> sev.sigev_notify = SIGEV_SIGNAL;
>> sev.sigev_signo = SIG;
>> sev.sigev_value.sival_ptr = &timerid;
>> if (timer_create(CLOCKID, &sev, &timerid) == -1)
>> errExit("timer_create");
>>
>> printf("timer ID is %#jx\n", (uintmax_t) timerid);
>>
>> /* Start the timer. */
>>
>> freq_nanosecs = atoll(argv[2]);
>> its.it_value.tv_sec = freq_nanosecs / 1000000000;
>> its.it_value.tv_nsec = freq_nanosecs % 1000000000;
>> its.it_interval.tv_sec = its.it_value.tv_sec;
>> its.it_interval.tv_nsec = its.it_value.tv_nsec;
>>
>>
>>
>> Is similar to:
>>
>>
>> ((int*)&sev.sigev_notify)[1] = thread->osthread()->thread_id();
>> clockid_t clock;
>> int err = pthread_getcpuclockid(thread->osthread()->pthread_id(), &clock);
>> if (err != 0) {
>> log_error(jfr)("Failed to get clock for thread sampling: %s", os::strerror(err));
>> return false;
>> }
>> if (timer_create(clock, &sev, &t) < 0) {
>> return false;
>> }
>> int64_t period = get_sampling_period();
>> if (period != 0) {
>> set_timer_time(t, period);
>> }
>
> The `sigev_value` member is used to pass data that you can read in the signal handler. The address of `t` won't be valid anymore once you return from this function. In that example the address of `timerid ` is still valid.
Why is this a problem? We don't leak `&t` outside of `create_timer_for_thread`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25302#discussion_r2126820560
More information about the serviceability-dev
mailing list