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

SetHeapSamplingInterval handles 1 explicitly

XMLWordPrintable

    • b10
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The documentation of the new JVMTI method SetHeapSamplingInterval method explicitly describes what happens when the interval is 0, which makes me think that 0 is a special value, a corner case.

      However, the JDK source code seems to actually treat 1 as a special value instead of 0.

      --------------------
      from jvmtiEnv.cpp:
      --------------------
              jvmtiError
              JvmtiEnv::SetHeapSamplingInterval(jint sampling_interval) {
                if (sampling_interval < 0) {
                  return JVMTI_ERROR_ILLEGAL_ARGUMENT;
                }
                ThreadHeapSampler::set_sampling_interval(sampling_interval);
                return JVMTI_ERROR_NONE;
              }

      --------------------
      from threadHeapSampler.cpp:
      --------------------
            void ThreadHeapSampler::pick_next_sample(size_t overflowed_bytes) {
              if (get_sampling_interval() == 1) {
                _bytes_until_sample = 1;
                return;
              }

              pick_next_geometric_sample();
              ...
            }

      Please note that special processing (the short path, presumably the fastest) is performed when the interval is exactly 1. The interval equal to 0 goes the long, common path.

      Shouldn't "if (get_sampling_interval() == 1)" be replaced with "if (get_sampling_interval() == 0)" or "if (get_sampling_interval() <= 1)"?




            jcbeyler Jean Christophe Beyler
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: