hotspot/src/share/vm/memory/sharedHeap.hpp
author brutisso
Thu, 02 Apr 2015 16:06:07 +0200
changeset 30152 5fe1c8494b49
parent 30147 af9a41999c6e
child 30153 596ed88949ad
permissions -rw-r--r--
8076454: Clean up/move things out of SharedHeap Reviewed-by: stefank, sjohanss, david
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29804
dcb9861190d2 8076237: Remove unused _collector_policy field in SharedHeap
brutisso
parents: 29802
diff changeset
     2
 * Copyright (c) 2000, 2015, 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
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// A "SharedHeap" is an implementation of a java heap for HotSpot.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// is an abstract class: there may be many different kinds of heaps.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// class defines the functions that a heap must implement, and contains
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// infrastructure common to all heaps.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    35
// Note on use of FlexibleWorkGang's for GC.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    36
// There are three places where task completion is determined.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    37
// In
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    38
//    1) ParallelTaskTerminator::offer_termination() where _n_threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    39
//    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
    40
//    have offered termination will exactly match the number
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    41
//    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
    42
//    use ParallelTaskTerminator's.  Tasks that want load balancing
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    43
//    by work stealing use this method to gauge completion.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    44
//    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
    45
//    all_tasks_completed() to determine completion.  all_tasks_complete()
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    46
//    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
    47
//    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
    48
//    tasks is set to the number of GC workers, then _n_threads must
29693
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    49
//    be set to the number of active GC workers. G1RootProcessor and
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    50
//    GenCollectedHeap have SubTasksDone.
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    51
//    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
    52
//    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
    53
//    number of active GC workers.  CompactibleFreeListSpace and Space
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    54
//    have SequentialSubTasksDone's.
29693
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    55
//
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    56
// Examples of using SubTasksDone and SequentialSubTasksDone:
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    57
//  G1RootProcessor and GenCollectedHeap::process_roots() use
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    58
//  SubTasksDone* _process_strong_tasks to claim tasks for workers
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    59
//
fac175f7a466 8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents: 28217
diff changeset
    60
//  GenCollectedHeap::gen_process_roots() calls
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11396
diff changeset
    61
//      rem_set()->younger_refs_iterate()
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    62
//  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
    63
//  CardTableModRefBS::par_non_clean_card_iterate_work().  This method
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    64
//  uses SequentialSubTasksDone* _pst to claim tasks.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    65
//  Both SubTasksDone and SequentialSubTasksDone call their method
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    66
//  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
    67
//  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
    68
//  finished the tasks are finished".
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    69
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    70
//  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
    71
//  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
    72
//  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
    73
//  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
    74
//  setting _n_threads to 1.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    75
//
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22550
diff changeset
    76
//  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
    77
//  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
    78
//  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
    79
//  examples.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    80
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    81
//  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
    82
//  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
    83
//  (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
    84
//  on the partitioning done in the previous parallel scavenge).
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 9342
diff changeset
    85
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
class SharedHeap : public CollectedHeap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Full initialization is done in a concrete subtype's "initialize"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // function.
29804
dcb9861190d2 8076237: Remove unused _collector_policy field in SharedHeap
brutisso
parents: 29802
diff changeset
    92
  SharedHeap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
public:
29802
d485440c958a 8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents: 29795
diff changeset
    95
  // Note, the below comment needs to be updated to reflect the changes
d485440c958a 8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents: 29795
diff changeset
    96
  // introduced by JDK-8076225. This should be done as part of JDK-8076289.
d485440c958a 8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents: 29795
diff changeset
    97
  //
d485440c958a 8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents: 29795
diff changeset
    98
  //Some collectors will perform "process_strong_roots" in parallel.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Such a call will involve claiming some fine-grained tasks, such as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // scanning of threads.  To make this process simpler, we provide the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // "strong_roots_parity()" method.  Collectors that start parallel tasks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // whose threads invoke "process_strong_roots" must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // call "change_strong_roots_parity" in sequential code starting such a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // task.  (This also means that a parallel thread may only call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // process_strong_roots once.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  //
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   107
  // For calls to process_roots by sequential code, the parity is
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // updated automatically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // The idea is that objects representing fine-grained tasks, such as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // 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
   112
  // current "process_roots" call only if its parity field is the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // same as the "strong_roots_parity"; task claiming is accomplished by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // updating the parity field to the strong_roots_parity with a CAS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // If the client meats this spec, then strong_roots_parity() will have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // the following properties:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  //   a) to return a different value than was returned before the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  //      call to change_strong_roots_parity, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  //   c) to never return a distinguished value (zero) with which such
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  //      task-claiming variables may be initialized, to indicate "never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  //      claimed".
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   123
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   125
  // 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
   126
  // 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
   127
  // parallel tasks are enabled.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   128
  class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   129
    SharedHeap*   _sh;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   130
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   131
   public:
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   132
    StrongRootsScope(SharedHeap* heap, bool activate = true);
29802
d485440c958a 8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents: 29795
diff changeset
   133
    ~StrongRootsScope();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 2105
diff changeset
   134
  };
30152
5fe1c8494b49 8076454: Clean up/move things out of SharedHeap
brutisso
parents: 30147
diff changeset
   135
 };
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
   136
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
   137
#endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP