hotspot/src/share/vm/runtime/vmThread.hpp
author phh
Wed, 28 Oct 2009 16:25:51 -0400
changeset 4434 4b41e5b42f81
parent 3908 24b55ad4c228
child 4489 514173c9a0c2
permissions -rw-r--r--
6887571: Increase default heap config sizes Summary: Apply modification of existing server heap size ergo to all collectors except CMS. Reviewed-by: jmasa, ysr, xlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// Prioritized queue of VM operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Encapsulates both queue management and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// and priority policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class VMOperationQueue : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  enum Priorities {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
     SafepointPriority, // Highest priority (operation executed at a safepoint)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
     MediumPriority,    // Medium priority
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
     nof_priorities
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // We maintain a doubled linked list, with explicit count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  int           _queue_length[nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  int           _queue_counter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  VM_Operation* _queue       [nof_priorities];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // we also allow the vmThread to register the ops it has drained so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // can scan them from oops_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  VM_Operation* _drain_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Double-linked non-empty list insert.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void insert(VM_Operation* q,VM_Operation* n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void unlink(VM_Operation* q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Basic queue manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  bool queue_empty                (int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  void queue_add_front            (int prio, VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  void queue_add_back             (int prio, VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  VM_Operation* queue_remove_front(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void queue_oops_do(int queue, OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  void drain_list_oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  VM_Operation* queue_drain(int prio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // lock-free query: may return the wrong answer but must not break
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  bool queue_peek(int prio) { return _queue_length[prio] > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  VMOperationQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Highlevel operations. Encapsulates policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  bool add(VM_Operation *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  VM_Operation* remove_next();                        // Returns next or null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  VM_Operation* remove_next_at_safepoint_priority()   { return queue_remove_front(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void set_drain_list(VM_Operation* list) { _drain_list = list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  void verify_queue(int prio) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// A single VMThread (the primordial thread) spawns all other threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// and is itself used by other threads to offload heavy vm operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// like scavenge, garbage_collect etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
class VMThread: public Thread {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  static ThreadPriority _current_priority;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static bool _should_terminate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  static bool _terminated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  static Monitor * _terminate_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  static PerfCounter* _perf_accumulated_vm_operation_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  void evaluate_operation(VM_Operation* op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  VMThread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Tester
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  bool is_VM_thread() const                      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  bool is_GC_thread() const                      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  char* name() const { return (char*)"VM Thread"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // The ever running loop for the VMThread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  void loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Called to stop the VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  static void wait_for_vm_thread_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  static bool should_terminate()                  { return _should_terminate; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static bool is_terminated()                     { return _terminated == true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Execution of vm operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static void execute(VM_Operation* op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Returns the current vm operation if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  static VM_Operation* vm_operation()             { return _cur_vm_operation;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // Returns the single instance of VMThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static VMThread* vm_thread()                    { return _vm_thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // GC support
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   124
  void oops_do(OopClosure* f, CodeBlobClosure* cf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void print() const                              { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // Performance measurement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static PerfCounter* perf_accumulated_vm_operation_time()               { return _perf_accumulated_vm_operation_time; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Entry for starting vm thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  virtual void run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // Creations/Destructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static void create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void destroy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // VM_Operation support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static VM_Operation*     _cur_vm_operation;   // Current VM operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static VMOperationQueue* _vm_queue;           // Queue (w/ policy) of VM operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // Pointer to single-instance of VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static VMThread*     _vm_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
};