src/hotspot/share/runtime/vmThread.hpp
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 47216 71c04702a3d5
child 52877 9e041366c764
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37456
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4489
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4489
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4489
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_RUNTIME_VMTHREAD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/perfData.hpp"
37456
bf26e0f4235f 8153742: Move Thread::current() to thread.hpp
stefank
parents: 24331
diff changeset
    29
#include "runtime/thread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/vm_operations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Prioritized queue of VM operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Encapsulates both queue management and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// and priority policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10565
diff changeset
    38
class VMOperationQueue : public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  enum Priorities {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
     SafepointPriority, // Highest priority (operation executed at a safepoint)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
     MediumPriority,    // Medium priority
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
     nof_priorities
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // We maintain a doubled linked list, with explicit count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  int           _queue_length[nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  int           _queue_counter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  VM_Operation* _queue       [nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // we also allow the vmThread to register the ops it has drained so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // can scan them from oops_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  VM_Operation* _drain_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // Double-linked non-empty list insert.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  void insert(VM_Operation* q,VM_Operation* n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void unlink(VM_Operation* q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Basic queue manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  bool queue_empty                (int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void queue_add_front            (int prio, VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void queue_add_back             (int prio, VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  VM_Operation* queue_remove_front(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void queue_oops_do(int queue, OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  void drain_list_oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  VM_Operation* queue_drain(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // lock-free query: may return the wrong answer but must not break
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  bool queue_peek(int prio) { return _queue_length[prio] > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  VMOperationQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Highlevel operations. Encapsulates policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  bool add(VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  VM_Operation* remove_next();                        // Returns next or null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  VM_Operation* remove_next_at_safepoint_priority()   { return queue_remove_front(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void set_drain_list(VM_Operation* list) { _drain_list = list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void verify_queue(int prio) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// A single VMThread (the primordial thread) spawns all other threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// and is itself used by other threads to offload heavy vm operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// like scavenge, garbage_collect etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
4489
514173c9a0c2 6361589: Print out stack trace for target thread of GC crash
minqi
parents: 3908
diff changeset
    93
class VMThread: public NamedThread {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static ThreadPriority _current_priority;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static bool _should_terminate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static bool _terminated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  static Monitor * _terminate_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  static PerfCounter* _perf_accumulated_vm_operation_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   102
  static const char* _no_op_reason;
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   103
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   104
  static bool no_op_safepoint_needed(bool check_time);
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   105
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  void evaluate_operation(VM_Operation* op);
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   107
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  VMThread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
38290
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   112
  // No destruction allowed
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   113
  ~VMThread() {
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   114
    guarantee(false, "VMThread deletion must fix the race with VM termination");
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   115
  }
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   116
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   117
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Tester
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  bool is_VM_thread() const                      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  bool is_GC_thread() const                      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // The ever running loop for the VMThread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Called to stop the VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static void wait_for_vm_thread_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  static bool should_terminate()                  { return _should_terminate; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  static bool is_terminated()                     { return _terminated == true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Execution of vm operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void execute(VM_Operation* op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Returns the current vm operation if any.
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   134
  static VM_Operation* vm_operation()             { return _cur_vm_operation; }
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   135
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   136
  // Returns the current vm operation name or set reason
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   137
  static const char* vm_safepoint_description()   { return _cur_vm_operation != NULL ? _cur_vm_operation->name() : _no_op_reason; };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Returns the single instance of VMThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static VMThread* vm_thread()                    { return _vm_thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // GC support
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37456
diff changeset
   143
  void oops_do(OopClosure* f, CodeBlobClosure* cf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // Performance measurement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static PerfCounter* perf_accumulated_vm_operation_time()               { return _perf_accumulated_vm_operation_time; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Entry for starting vm thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  virtual void run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Creations/Destructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static void create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  static void destroy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // VM_Operation support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  static VM_Operation*     _cur_vm_operation;   // Current VM operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  static VMOperationQueue* _vm_queue;           // Queue (w/ policy) of VM operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Pointer to single-instance of VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  static VMThread*     _vm_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   165
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   166
#endif // SHARE_VM_RUNTIME_VMTHREAD_HPP