Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8358752

JFR: Register sigevent more portably

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • hotspot
    • jfr

      SonarCloud complains this is a dodgy access:

      bool JfrCPUSamplerThread::create_timer_for_thread(JavaThread* thread, timer_t& timerid) {
        struct sigevent sev;
        sev.sigev_notify = SIGEV_THREAD_ID;
        sev.sigev_signo = SIG;
        sev.sigev_value.sival_ptr = nullptr;
        ((int*)&sev.sigev_notify)[1] = thread->osthread()->thread_id(); // <--- here

      I suspect the intent is to reach for platform-specific _tid field there. The current expression seems to hit the right spot:

      typedef struct sigevent {
          __sigval_t sigev_value;
          int sigev_signo;
          int sigev_notify;
          union {
              int _pad[__SIGEV_PAD_SIZE];
              __pid_t _tid;
             struct {
                    void (*_function) (__sigval_t); /* Function to start. */
                    pthread_attr_t *_attribute; /* Thread attributes. */
              } _sigev_thread;
          } _sigev_un;
      } sigevent_t;

      ...but I do not think it is 100% portable. Maybe it is possible to somehow access `sev._sigev_un._tid` directly without breaking too many builds.

            jbechberger Johannes Bechberger
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: