test/hotspot/gtest/jfr/test_threadCpuLoad.cpp
changeset 58863 c16ac7a2eba4
parent 50630 4cb865aa94b5
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
     1 /*
     1 /*
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    34 
    34 
    35 #include "logging/log.hpp"
    35 #include "logging/log.hpp"
    36 #include "jfr/jfrEvents.hpp"
    36 #include "jfr/jfrEvents.hpp"
    37 #include "jfr/support/jfrThreadId.hpp"
    37 #include "jfr/support/jfrThreadId.hpp"
    38 #include "jfr/support/jfrThreadLocal.hpp"
    38 #include "jfr/support/jfrThreadLocal.hpp"
       
    39 #include "jfr/utilities/jfrThreadIterator.hpp"
    39 #include "jfr/utilities/jfrTime.hpp"
    40 #include "jfr/utilities/jfrTime.hpp"
    40 #include "utilities/globalDefinitions.hpp"
    41 #include "utilities/globalDefinitions.hpp"
    41 #include "runtime/os.hpp"
    42 #include "runtime/os.hpp"
    42 #include "runtime/thread.inline.hpp"
       
    43 #include "runtime/threadSMR.inline.hpp"
       
    44 
    43 
    45 #include "unittest.hpp"
    44 #include "unittest.hpp"
    46 
    45 
    47 namespace {
    46 namespace {
    48 
    47 
    79   class MockJavaThread : public ::JavaThread {
    78   class MockJavaThread : public ::JavaThread {
    80   public:
    79   public:
    81     MockJavaThread() : ::JavaThread() {}
    80     MockJavaThread() : ::JavaThread() {}
    82   };
    81   };
    83 
    82 
    84   class MockJavaThreadIteratorWithHandle
    83   class MockJfrJavaThreadIterator
    85   {
    84   {
    86   public:
    85   public:
    87     MockJavaThread* next() { return NULL; }
    86     MockJavaThread* next() { return NULL; }
    88     int length() { return 0; }
    87     bool has_next() const { return false; }
       
    88   };
       
    89 
       
    90   class MockJfrJavaThreadIteratorAdapter
       
    91   {
       
    92   public:
       
    93     MockJavaThread* next() { return NULL; }
       
    94     bool has_next() const { return false; }
    89   };
    95   };
    90 
    96 
    91 // Reincluding source files in the anonymous namespace unfortunately seems to
    97 // Reincluding source files in the anonymous namespace unfortunately seems to
    92 // behave strangely with precompiled headers (only when using gcc though)
    98 // behave strangely with precompiled headers (only when using gcc though)
    93 #ifndef DONT_USE_PRECOMPILED_HEADER
    99 #ifndef DONT_USE_PRECOMPILED_HEADER
    95 #endif
   101 #endif
    96 
   102 
    97 #define os MockOs
   103 #define os MockOs
    98 #define EventThreadCPULoad MockEventThreadCPULoad
   104 #define EventThreadCPULoad MockEventThreadCPULoad
    99 #define JavaThread MockJavaThread
   105 #define JavaThread MockJavaThread
   100 #define JavaThreadIteratorWithHandle MockJavaThreadIteratorWithHandle
   106 #define JfrJavaThreadIterator MockJfrJavaThreadIterator
       
   107 #define JfrJavaThreadIteratorAdapter MockJfrJavaThreadIteratorAdapter
   101 
   108 
   102 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp"
   109 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp"
   103 #include "jfr/periodic/jfrThreadCPULoadEvent.cpp"
   110 #include "jfr/periodic/jfrThreadCPULoadEvent.cpp"
   104 
   111 
   105 #undef os
   112 #undef os
   106 #undef EventThreadCPULoad
   113 #undef EventThreadCPULoad
   107 #undef JavaThread
   114 #undef JavaThread
   108 #undef JavaThreadIteratorWithHandle
   115 #define JfrJavaThreadIterator MockJfrJavaThreadIterator
       
   116 #define JfrJavaThreadIteratorAdapter MockJfrJavaThreadIteratorAdapter
   109 
   117 
   110 } // anonymous namespace
   118 } // anonymous namespace
   111 
   119 
   112 class JfrTestThreadCPULoadSingle : public ::testing::Test {
   120 class JfrTestThreadCPULoadSingle : public ::testing::Test {
   113 protected:
   121 protected: