hotspot/src/share/vm/memory/sharedHeap.hpp
author kbarrett
Thu, 18 Dec 2014 13:26:37 -0500
changeset 28217 57791914628c
parent 25492 d27050bdfb04
child 29693 fac175f7a466
permissions -rw-r--r--
8067499: G1SATBCardTableModRefBS should not inherit from CardTableModRefBSForCTRS Summary: G1SATBCardTableModRefBS inherits from CardTableModRefBS Reviewed-by: mgerdin, brutisso, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
28217
57791914628c 8067499: G1SATBCardTableModRefBS should not inherit from CardTableModRefBSForCTRS
kbarrett
parents: 25492
diff changeset
     2
 * Copyright (c) 2000, 2014, 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: 4458
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4458
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: 4458
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: 6759
diff changeset
    25
#ifndef SHARE_VM_MEMORY_SHAREDHEAP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    26
#define SHARE_VM_MEMORY_SHAREDHEAP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    28
#include "gc_interface/collectedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    29
#include "memory/generation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// A "SharedHeap" is an implementation of a java heap for HotSpot.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// is an abstract class: there may be many different kinds of heaps.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// class defines the functions that a heap must implement, and contains
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// infrastructure common to all heaps.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class Generation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class BarrierSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class GenRemSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class Space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class SpaceClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class OopClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class OopsInGenClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class ObjectClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class SubTasksDone;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class WorkGang;
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    46
class FlexibleWorkGang;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class CollectorPolicy;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11396
diff changeset
    48
class KlassClosure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    50
// Note on use of FlexibleWorkGang's for GC.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    51
// There are three places where task completion is determined.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    52
// In
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    53
//    1) ParallelTaskTerminator::offer_termination() where _n_threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    54
//    must be set to the correct value so that count of workers that
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    55
//    have offered termination will exactly match the number
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    56
//    working on the task.  Tasks such as those derived from GCTask
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    57
//    use ParallelTaskTerminator's.  Tasks that want load balancing
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    58
//    by work stealing use this method to gauge completion.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    59
//    2) SubTasksDone has a variable _n_threads that is used in
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    60
//    all_tasks_completed() to determine completion.  all_tasks_complete()
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    61
//    counts the number of tasks that have been done and then reset
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    62
//    the SubTasksDone so that it can be used again.  When the number of
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    63
//    tasks is set to the number of GC workers, then _n_threads must
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    64
//    be set to the number of active GC workers. G1CollectedHeap,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    65
//    HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    66
//    This seems too many.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    67
//    3) SequentialSubTasksDone has an _n_threads that is used in
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    68
//    a way similar to SubTasksDone and has the same dependency on the
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    69
//    number of active GC workers.  CompactibleFreeListSpace and Space
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    70
//    have SequentialSubTasksDone's.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    71
// Example of using SubTasksDone and SequentialSubTasksDone
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    72
// G1CollectedHeap::g1_process_roots()
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    73
//  to SharedHeap::process_roots() and uses
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    74
//  SubTasksDone* _process_strong_tasks to claim tasks.
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    75
//  process_roots() calls
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11396
diff changeset
    76
//      rem_set()->younger_refs_iterate()
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    77
//  to scan the card table and which eventually calls down into
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    78
//  CardTableModRefBS::par_non_clean_card_iterate_work().  This method
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    79
//  uses SequentialSubTasksDone* _pst to claim tasks.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    80
//  Both SubTasksDone and SequentialSubTasksDone call their method
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    81
//  all_tasks_completed() to count the number of GC workers that have
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    82
//  finished their work.  That logic is "when all the workers are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    83
//  finished the tasks are finished".
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    84
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    85
//  The pattern that appears  in the code is to set _n_threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    86
//  to a value > 1 before a task that you would like executed in parallel
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    87
//  and then to set it to 0 after that task has completed.  A value of
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    88
//  0 is a "special" value in set_n_threads() which translates to
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    89
//  setting _n_threads to 1.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    90
//
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22550
diff changeset
    91
//  Some code uses _n_termination to decide if work should be done in
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    92
//  parallel.  The notorious possibly_parallel_oops_do() in threads.cpp
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    93
//  is an example of such code.  Look for variable "is_par" for other
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    94
//  examples.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    95
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    96
//  The active_workers is not reset to 0 after a parallel phase.  It's
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    97
//  value may be used in later phases and in one instance at least
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    98
//  (the parallel remark) it has to be used (the parallel remark depends
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    99
//  on the partitioning done in the previous parallel scavenge).
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   100
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
class SharedHeap : public CollectedHeap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   104
  friend class VM_GC_Operation;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   105
  friend class VM_CGC_Operation;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   106
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // For claiming strong_roots tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  SubTasksDone* _process_strong_tasks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // There should be only a single instance of "SharedHeap" in a program.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // This is enforced with the protected constructor below, which will also
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // set the static pointer "_sh" to that instance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static SharedHeap* _sh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // A gc policy, controls global gc resource issues
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  CollectorPolicy *_collector_policy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // See the discussion below, in the specification of the reader function
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // for this variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  int _strong_roots_parity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // If we're doing parallel GC, use this gang of threads.
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   125
  FlexibleWorkGang* _workers;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Full initialization is done in a concrete subtype's "initialize"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  SharedHeap(CollectorPolicy* policy_);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   131
  // Returns true if the calling thread holds the heap lock,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   132
  // or the calling thread is a par gc thread and the heap_lock is held
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   133
  // by the vm thread doing a gc operation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   134
  bool heap_lock_held_for_gc();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   135
  // True if the heap_lock is held by the a non-gc thread invoking a gc
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   136
  // operation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   137
  bool _thread_holds_heap_lock_for_gc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   138
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static SharedHeap* heap() { return _sh; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void set_barrier_set(BarrierSet* bs);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   143
  SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Does operations required after initialization has been done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  virtual void post_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Initialization of ("weak") reference processing support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  virtual void ref_processing_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Iteration functions.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11396
diff changeset
   152
  void oop_iterate(ExtendedOopClosure* cl) = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Iterate over all spaces in use in the heap, in an undefined order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  virtual void space_iterate(SpaceClosure* cl) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // A SharedHeap will contain some number of spaces.  This finds the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // space whose reserved area contains the given address, or else returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  virtual Space* space_containing(const void* addr) const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  bool no_gc_in_progress() { return !is_gc_active(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // Some collectors will perform "process_strong_roots" in parallel.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Such a call will involve claiming some fine-grained tasks, such as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // scanning of threads.  To make this process simpler, we provide the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // "strong_roots_parity()" method.  Collectors that start parallel tasks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // whose threads invoke "process_strong_roots" must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // call "change_strong_roots_parity" in sequential code starting such a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // task.  (This also means that a parallel thread may only call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // process_strong_roots once.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  //
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   173
  // For calls to process_roots by sequential code, the parity is
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // updated automatically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // The idea is that objects representing fine-grained tasks, such as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // threads, will contain a "parity" field.  A task will is claimed in the
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   178
  // current "process_roots" call only if its parity field is the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // same as the "strong_roots_parity"; task claiming is accomplished by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // updating the parity field to the strong_roots_parity with a CAS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // If the client meats this spec, then strong_roots_parity() will have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // the following properties:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  //   a) to return a different value than was returned before the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  //      call to change_strong_roots_parity, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  //   c) to never return a distinguished value (zero) with which such
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  //      task-claiming variables may be initialized, to indicate "never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  //      claimed".
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   189
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  int strong_roots_parity() { return _strong_roots_parity; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   192
  // Call these in sequential code around process_roots.
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   193
  // strong_roots_prologue calls change_strong_roots_parity, if
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   194
  // parallel tasks are enabled.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   195
  class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   196
    // Used to implement the Thread work barrier.
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   197
    static Monitor* _lock;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   198
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   199
    SharedHeap*   _sh;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   200
    volatile jint _n_workers_done_with_threads;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   201
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   202
   public:
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   203
    StrongRootsScope(SharedHeap* heap, bool activate = true);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   204
    ~StrongRootsScope();
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   205
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   206
    // Mark that this thread is done with the Threads work.
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   207
    void mark_worker_done_with_threads(uint n_workers);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   208
    // Wait until all n_workers are done with the Threads work.
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   209
    void wait_until_all_workers_done_with_threads(uint n_workers);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   210
  };
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   211
  friend class StrongRootsScope;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   212
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   213
  // The current active StrongRootScope
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   214
  StrongRootsScope* _strong_roots_scope;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   215
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   216
  StrongRootsScope* active_strong_roots_scope() const;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   217
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   218
 private:
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   219
  void register_strong_roots_scope(StrongRootsScope* scope);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   220
  void unregister_strong_roots_scope(StrongRootsScope* scope);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   221
  void change_strong_roots_parity();
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   222
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   223
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  enum ScanningOption {
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   225
    SO_None                =  0x0,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   226
    SO_AllCodeCache        =  0x8,
22550
820966182ab9 8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents: 22234
diff changeset
   227
    SO_ScavengeCodeCache   = 0x10
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   230
  FlexibleWorkGang* workers() const { return _workers; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Invoke the "do_oop" method the closure "roots" on all root locations.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11396
diff changeset
   233
  // The "so" argument determines which roots the closure is applied to:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // "SO_None" does none;
22550
820966182ab9 8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents: 22234
diff changeset
   235
  // "SO_AllCodeCache" applies the closure to all elements of the CodeCache.
820966182ab9 8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents: 22234
diff changeset
   236
  // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache.
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   237
  void process_roots(bool activate_scope,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   238
                     ScanningOption so,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   239
                     OopClosure* strong_roots,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   240
                     OopClosure* weak_roots,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   241
                     CLDClosure* strong_cld_closure,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   242
                     CLDClosure* weak_cld_closure,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   243
                     CodeBlobClosure* code_roots);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   244
  void process_all_roots(bool activate_scope,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   245
                         ScanningOption so,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   246
                         OopClosure* roots,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   247
                         CLDClosure* cld_closure,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   248
                         CodeBlobClosure* code_roots);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   249
  void process_strong_roots(bool activate_scope,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                            ScanningOption so,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                            OopClosure* roots,
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   252
                            CLDClosure* cld_closure,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   253
                            CodeBlobClosure* code_roots);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   254
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
22883
5378704451dc 8034764: Use process_strong_roots to adjust the StringTable
stefank
parents: 22882
diff changeset
   256
  // Apply "root_closure" to the JNI weak roots..
22882
195c8f70d605 8034761: Remove the do_code_roots parameter from process_strong_roots
stefank
parents: 22551
diff changeset
   257
  void process_weak_roots(OopClosure* root_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // The functions below are helper functions that a subclass of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // "SharedHeap" can use in the implementation of its virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   263
public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Do anything common to GC's.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  virtual void gc_prologue(bool full) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  virtual void gc_epilogue(bool full) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   269
  // Sets the number of parallel threads that will be doing tasks
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   270
  // (such as process roots) subsequently.
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
   271
  virtual void set_par_threads(uint t);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   272
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   273
  int n_termination();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   274
  void set_n_termination(int t);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
   275
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  // New methods from CollectedHeap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Some utilities.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   281
  void print_size_transition(outputStream* out,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   282
                             size_t bytes_before,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                             size_t bytes_after,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
                             size_t capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
   286
22882
195c8f70d605 8034761: Remove the do_code_roots parameter from process_strong_roots
stefank
parents: 22551
diff changeset
   287
inline SharedHeap::ScanningOption operator|(SharedHeap::ScanningOption so0, SharedHeap::ScanningOption so1) {
195c8f70d605 8034761: Remove the do_code_roots parameter from process_strong_roots
stefank
parents: 22551
diff changeset
   288
  return static_cast<SharedHeap::ScanningOption>(static_cast<int>(so0) | static_cast<int>(so1));
195c8f70d605 8034761: Remove the do_code_roots parameter from process_strong_roots
stefank
parents: 22551
diff changeset
   289
}
195c8f70d605 8034761: Remove the do_code_roots parameter from process_strong_roots
stefank
parents: 22551
diff changeset
   290
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
   291
#endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP