src/hotspot/share/runtime/vmThread.hpp
author rehn
Fri, 29 Nov 2019 12:09:25 +0100
changeset 59325 3636bab5e81e
parent 55128 35192d9c2b76
permissions -rw-r--r--
8234086: VM operation can be simplified Reviewed-by: kbarrett, dholmes, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53020
diff changeset
     2
 * Copyright (c) 1998, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53020
diff changeset
    25
#ifndef SHARE_RUNTIME_VMTHREAD_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53020
diff changeset
    26
#define SHARE_RUNTIME_VMTHREAD_HPP
7397
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"
53020
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    30
#include "runtime/task.hpp"
52877
9e041366c764 8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents: 47216
diff changeset
    31
#include "runtime/vmOperations.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
59325
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    33
class VM_QueueHead : public VM_None {
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    34
 public:
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    35
  VM_QueueHead() : VM_None("QueueHead") {}
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    36
};
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    37
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Prioritized queue of VM operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Encapsulates both queue management and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// and priority policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10565
diff changeset
    44
class VMOperationQueue : public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  enum Priorities {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
     SafepointPriority, // Highest priority (operation executed at a safepoint)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
     MediumPriority,    // Medium priority
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
     nof_priorities
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // We maintain a doubled linked list, with explicit count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  int           _queue_length[nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  int           _queue_counter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  VM_Operation* _queue       [nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // we also allow the vmThread to register the ops it has drained so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // can scan them from oops_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  VM_Operation* _drain_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
59325
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    60
  static VM_QueueHead _queue_head[nof_priorities];
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    61
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Double-linked non-empty list insert.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void insert(VM_Operation* q,VM_Operation* n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  void unlink(VM_Operation* q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Basic queue manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  bool queue_empty                (int prio);
59325
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
    68
  void queue_add                  (int prio, VM_Operation *op);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  VM_Operation* queue_remove_front(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void queue_oops_do(int queue, OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  void drain_list_oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  VM_Operation* queue_drain(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // lock-free query: may return the wrong answer but must not break
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  bool queue_peek(int prio) { return _queue_length[prio] > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  VMOperationQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Highlevel operations. Encapsulates policy
55128
35192d9c2b76 8225016: Dead code due to VMOperationQueue::add() always returning true
pchilanomate
parents: 54278
diff changeset
    80
  void add(VM_Operation *op);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  VM_Operation* remove_next();                        // Returns next or null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void set_drain_list(VM_Operation* list) { _drain_list = list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  void verify_queue(int prio) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
53020
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    93
// VM operation timeout handling: warn or abort the VM when VM operation takes
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    94
// too long. Periodic tasks do not participate in safepoint protocol, and therefore
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    95
// can fire when application threads are stopped.
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    96
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    97
class VMOperationTimeoutTask : public PeriodicTask {
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    98
private:
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
    99
  volatile int _armed;
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   100
  jlong _arm_time;
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   101
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   102
public:
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   103
  VMOperationTimeoutTask(size_t interval_time) :
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   104
          PeriodicTask(interval_time), _armed(0), _arm_time(0) {}
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   105
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   106
  virtual void task();
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   107
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   108
  bool is_armed();
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   109
  void arm();
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   110
  void disarm();
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   111
};
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// A single VMThread (the primordial thread) spawns all other threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// and is itself used by other threads to offload heavy vm operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// like scavenge, garbage_collect etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
4489
514173c9a0c2 6361589: Print out stack trace for target thread of GC crash
minqi
parents: 3908
diff changeset
   119
class VMThread: public NamedThread {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static ThreadPriority _current_priority;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  static bool _should_terminate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static bool _terminated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static Monitor * _terminate_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static PerfCounter* _perf_accumulated_vm_operation_time;
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53244
diff changeset
   127
  static uint64_t _coalesced_count;
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   128
53020
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   129
  static VMOperationTimeoutTask* _timeout_task;
c403f39ec349 8181143: Introduce diagnostic flag to abort VM on too long VM operations
shade
parents: 52877
diff changeset
   130
54278
16999bd91ba6 8220774: Add HandshakeALot diag option
rehn
parents: 53895
diff changeset
   131
  static VM_Operation* no_op_safepoint();
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void evaluate_operation(VM_Operation* op);
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   134
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  VMThread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
38290
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   139
  // No destruction allowed
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   140
  ~VMThread() {
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   141
    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
   142
  }
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   143
6b194cfc1557 8154715: Missing destructor and/or TLS clearing calls for terminating threads
dholmes
parents: 38074
diff changeset
   144
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Tester
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  bool is_VM_thread() const                      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // The ever running loop for the VMThread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void loop();
59325
3636bab5e81e 8234086: VM operation can be simplified
rehn
parents: 55128
diff changeset
   150
  static void check_for_forced_cleanup();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Called to stop the VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static void wait_for_vm_thread_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static bool should_terminate()                  { return _should_terminate; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  static bool is_terminated()                     { return _terminated == true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // Execution of vm operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  static void execute(VM_Operation* op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Returns the current vm operation if any.
46496
76ed99d51a67 8152955: Many safepoints of "no vm operation" kind
rehn
parents: 38290
diff changeset
   161
  static VM_Operation* vm_operation()             { return _cur_vm_operation; }
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53244
diff changeset
   162
  static VM_Operation::VMOp_Type vm_op_type()     { return _cur_vm_operation->type(); }
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53244
diff changeset
   163
  static uint64_t get_coalesced_count()           { return _coalesced_count; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Returns the single instance of VMThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static VMThread* vm_thread()                    { return _vm_thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // GC support
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37456
diff changeset
   169
  void oops_do(OopClosure* f, CodeBlobClosure* cf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Performance measurement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static PerfCounter* perf_accumulated_vm_operation_time()               { return _perf_accumulated_vm_operation_time; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // Entry for starting vm thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  virtual void run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Creations/Destructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  static void create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  static void destroy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // VM_Operation support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  static VM_Operation*     _cur_vm_operation;   // Current VM operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  static VMOperationQueue* _vm_queue;           // Queue (w/ policy) of VM operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Pointer to single-instance of VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  static VMThread*     _vm_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   191
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53020
diff changeset
   192
#endif // SHARE_RUNTIME_VMTHREAD_HPP