< prev index next >

src/hotspot/share/jfr/periodic/jfrThreadCPULoadEvent.cpp

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -105,12 +105,11 @@
    return true;
  }
  
  void JfrThreadCPULoadEvent::send_events() {
    Thread* periodic_thread = Thread::current();
-   JfrThreadLocal* const periodic_thread_tl = periodic_thread->jfr_thread_local();
-   traceid periodic_thread_id = periodic_thread_tl->thread_id();
+   traceid periodic_thread_id = JfrThreadLocal::thread_id(periodic_thread);
    const int processor_count = JfrThreadCPULoadEvent::get_processor_count();
    JfrTicks event_time = JfrTicks::now();
    jlong cur_wallclock_time = JfrThreadCPULoadEvent::get_wallclock_time();
  
    JfrJavaThreadIterator iter;

@@ -122,21 +121,20 @@
      EventThreadCPULoad event(UNTIMED);
      if (JfrThreadCPULoadEvent::update_event(event, jt, cur_wallclock_time, processor_count)) {
        event.set_starttime(event_time);
        if (jt != periodic_thread) {
          // Commit reads the thread id from this thread's trace data, so put it there temporarily
-         periodic_thread_tl->set_thread_id(JFR_THREAD_ID(jt));
+         JfrThreadLocal::impersonate(periodic_thread, JFR_THREAD_ID(jt));
        } else {
-         periodic_thread_tl->set_thread_id(periodic_thread_id);
+         JfrThreadLocal::impersonate(periodic_thread, periodic_thread_id);
        }
        event.commit();
      }
    }
    log_trace(jfr)("Measured CPU usage for %d threads in %.3f milliseconds", number_of_threads,
      (double)(JfrTicks::now() - event_time).milliseconds());
-   // Restore this thread's thread id
-   periodic_thread_tl->set_thread_id(periodic_thread_id);
+   JfrThreadLocal::stop_impersonating(periodic_thread);
  }
  
  void JfrThreadCPULoadEvent::send_event_for_thread(JavaThread* jt) {
    EventThreadCPULoad event;
    if (event.should_commit()) {
< prev index next >