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

On Windows CPUPerformanceInterface::CPUPerformance::initialize() returns the wrong value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 15
    • 14
    • hotspot
    • jfr
    • x86
    • windows

      I think the Windows version is broken and returning true when it should be returning false! Certainly this logic makes no sense to me:

      bool CPUPerformanceInterface::CPUPerformance::initialize() {
        if (!pdh_acquire()) {
          return true;
        }
        _context_switches = create_counter_query(PDH_SYSTEM_IDX, PDH_CONTEXT_SWITCH_RATE_IDX);
        _process_cpu_load = create_process_query();
        if (_process_cpu_load == NULL) {
          return true;
        }
        allocate_counters(_process_cpu_load, 2);
        if (initialize_process_counter(_process_cpu_load, 0, PDH_PROCESSOR_TIME_IDX) != OS_OK) {
          return true;
        }
        if (initialize_process_counter(_process_cpu_load, 1, PDH_PRIV_PROCESSOR_TIME_IDX) != OS_OK) {
          return true;
        }
        _process_cpu_load->set.initialized = true;
        _machine_cpu_load = create_multi_counter_query();
        if (_machine_cpu_load == NULL) {
          return true;
        }
        initialize_cpu_query(_machine_cpu_load, PDH_PROCESSOR_TIME_IDX);
        return true;
      }

      Only the final return should return true; all the others should return false.

            mgronlun Markus Grönlund
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: