src/hotspot/share/gc/z/zThread.hpp
changeset 58706 d8e211419aaf
parent 58125 9b4717ca9bd1
equal deleted inserted replaced
58705:f5662bdbee4a 58706:d8e211419aaf
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 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.
    24 #ifndef SHARE_GC_Z_ZTHREAD_HPP
    24 #ifndef SHARE_GC_Z_ZTHREAD_HPP
    25 #define SHARE_GC_Z_ZTHREAD_HPP
    25 #define SHARE_GC_Z_ZTHREAD_HPP
    26 
    26 
    27 #include "memory/allocation.hpp"
    27 #include "memory/allocation.hpp"
    28 #include "utilities/globalDefinitions.hpp"
    28 #include "utilities/globalDefinitions.hpp"
    29 #include "utilities/debug.hpp"
       
    30 
    29 
    31 class ZThread : public AllStatic {
    30 class ZThread : public AllStatic {
    32   friend class ZTask;
    31   friend class ZTask;
    33   friend class ZWorkersInitializeTask;
    32   friend class ZWorkersInitializeTask;
    34   friend class ZRuntimeWorkersInitializeTask;
    33   friend class ZRuntimeWorkersInitializeTask;
    41   static THREAD_LOCAL bool      _is_worker;
    40   static THREAD_LOCAL bool      _is_worker;
    42   static THREAD_LOCAL bool      _is_runtime_worker;
    41   static THREAD_LOCAL bool      _is_runtime_worker;
    43   static THREAD_LOCAL uint      _worker_id;
    42   static THREAD_LOCAL uint      _worker_id;
    44 
    43 
    45   static void initialize();
    44   static void initialize();
    46 
    45   static void ensure_initialized();
    47   static void ensure_initialized() {
       
    48     if (!_initialized) {
       
    49       initialize();
       
    50     }
       
    51   }
       
    52 
    46 
    53   static void set_worker();
    47   static void set_worker();
    54   static void set_runtime_worker();
    48   static void set_runtime_worker();
    55 
    49 
    56   static bool has_worker_id();
    50   static bool has_worker_id();
    57   static void set_worker_id(uint worker_id);
    51   static void set_worker_id(uint worker_id);
    58   static void clear_worker_id();
    52   static void clear_worker_id();
    59 
    53 
    60 public:
    54 public:
    61   static const char* name();
    55   static const char* name();
    62 
    56   static uintptr_t id();
    63   static uintptr_t id() {
    57   static bool is_vm();
    64     ensure_initialized();
    58   static bool is_java();
    65     return _id;
    59   static bool is_worker();
    66   }
    60   static bool is_runtime_worker();
    67 
    61   static uint worker_id();
    68   static bool is_vm() {
       
    69     ensure_initialized();
       
    70     return _is_vm;
       
    71   }
       
    72 
       
    73   static bool is_java() {
       
    74     ensure_initialized();
       
    75     return _is_java;
       
    76   }
       
    77 
       
    78   static bool is_worker() {
       
    79     ensure_initialized();
       
    80     return _is_worker;
       
    81   }
       
    82 
       
    83   static bool is_runtime_worker() {
       
    84     ensure_initialized();
       
    85     return _is_runtime_worker;
       
    86   }
       
    87 
       
    88   static uint worker_id() {
       
    89     assert(has_worker_id(), "Worker id not initialized");
       
    90     return _worker_id;
       
    91   }
       
    92 };
    62 };
    93 
    63 
    94 #endif // SHARE_GC_Z_ZTHREAD_HPP
    64 #endif // SHARE_GC_Z_ZTHREAD_HPP