src/hotspot/share/gc/g1/g1RootClosures.cpp
author jwilhelm
Wed, 14 Feb 2018 13:29:45 +0100
changeset 48969 7eb296a8ce2c
parent 47216 71c04702a3d5
child 49336 4b7dae855f23
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     1
/*
46281
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     4
 *
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     8
 *
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    13
 * accompanied this code).
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    14
 *
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    18
 *
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    21
 * questions.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    22
 *
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    23
 */
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    24
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    25
#include "precompiled.hpp"
34639
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    26
#include "gc/g1/g1OopClosures.inline.hpp"
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    27
#include "gc/g1/g1RootClosures.hpp"
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    28
#include "gc/g1/g1SharedClosures.hpp"
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    29
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    30
// Closures used for standard G1 evacuation.
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    31
class G1EvacuationClosures : public G1EvacuationRootClosures {
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    32
  G1SharedClosures<G1MarkNone> _closures;
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    33
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    34
public:
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    35
  G1EvacuationClosures(G1CollectedHeap* g1h,
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    36
                       G1ParScanThreadState* pss,
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    37
                       bool gcs_are_young) :
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    38
      _closures(g1h, pss, gcs_are_young, /* must_claim_cld */ false) {}
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    39
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    40
  OopClosure* weak_oops()   { return &_closures._buffered_oops; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    41
  OopClosure* strong_oops() { return &_closures._buffered_oops; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    42
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    43
  CLDClosure* weak_clds()             { return &_closures._clds; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    44
  CLDClosure* strong_clds()           { return &_closures._clds; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    45
  CLDClosure* second_pass_weak_clds() { return NULL; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    46
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    47
  CodeBlobClosure* strong_codeblobs()      { return &_closures._codeblobs; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    48
  CodeBlobClosure* weak_codeblobs()        { return &_closures._codeblobs; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    49
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    50
  void flush()                 { _closures._buffered_oops.done(); }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    51
  double closure_app_seconds() { return _closures._buffered_oops.closure_app_seconds(); }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    52
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    53
  OopClosure* raw_strong_oops() { return &_closures._oops; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    54
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    55
  bool trace_metadata()         { return false; }
cb73d3c05599 8144712: Remove g1RootClosures.inline.hpp
ehelin
parents: 34308
diff changeset
    56
};
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    57
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    58
// Closures used during initial mark.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    59
// The treatment of "weak" roots is selectable through the template parameter,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    60
// this is usually used to control unloading of classes and interned strings.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    61
template <G1Mark MarkWeak>
46281
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
    62
class G1InitialMarkClosures : public G1EvacuationRootClosures {
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    63
  G1SharedClosures<G1MarkFromRoot> _strong;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    64
  G1SharedClosures<MarkWeak>       _weak;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    65
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    66
  // Filter method to help with returning the appropriate closures
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    67
  // depending on the class template parameter.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    68
  template <G1Mark Mark, typename T>
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    69
  T* null_if(T* t) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    70
    if (Mark == MarkWeak) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    71
      return NULL;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    72
    }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    73
    return t;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    74
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    75
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    76
public:
46281
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
    77
  G1InitialMarkClosures(G1CollectedHeap* g1h,
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
    78
                        G1ParScanThreadState* pss) :
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    79
      _strong(g1h, pss, /* process_only_dirty_klasses */ false, /* must_claim_cld */ true),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    80
      _weak(g1h, pss,   /* process_only_dirty_klasses */ false, /* must_claim_cld */ true) {}
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    81
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    82
  OopClosure* weak_oops()   { return &_weak._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    83
  OopClosure* strong_oops() { return &_strong._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    84
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    85
  // If MarkWeak is G1MarkPromotedFromRoot then the weak CLDs must be processed in a second pass.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    86
  CLDClosure* weak_clds()             { return null_if<G1MarkPromotedFromRoot>(&_weak._clds); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    87
  CLDClosure* strong_clds()           { return &_strong._clds; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    88
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    89
  // If MarkWeak is G1MarkFromRoot then all CLDs are processed by the weak and strong variants
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    90
  // return a NULL closure for the following specialized versions in that case.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    91
  CLDClosure* second_pass_weak_clds() { return null_if<G1MarkFromRoot>(&_weak._clds); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    92
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    93
  CodeBlobClosure* strong_codeblobs()      { return &_strong._codeblobs; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    94
  CodeBlobClosure* weak_codeblobs()        { return &_weak._codeblobs; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    95
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    96
  void flush() {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    97
    _strong._buffered_oops.done();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    98
    _weak._buffered_oops.done();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    99
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   100
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   101
  double closure_app_seconds() {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   102
    return _strong._buffered_oops.closure_app_seconds() +
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   103
           _weak._buffered_oops.closure_app_seconds();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   104
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   105
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   106
  OopClosure* raw_strong_oops() { return &_strong._oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   107
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   108
  // If we are not marking all weak roots then we are tracing
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   109
  // which metadata is alive.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   110
  bool trace_metadata()         { return MarkWeak == G1MarkPromotedFromRoot; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   111
};
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   112
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   113
G1EvacuationRootClosures* G1EvacuationRootClosures::create_root_closures(G1ParScanThreadState* pss, G1CollectedHeap* g1h) {
34308
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   114
  G1EvacuationRootClosures* res = create_root_closures_ext(pss, g1h);
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   115
  if (res != NULL) {
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   116
    return res;
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   117
  }
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   118
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   119
  if (g1h->collector_state()->during_initial_mark_pause()) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   120
    if (ClassUnloadingWithConcurrentMark) {
46281
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
   121
      res = new G1InitialMarkClosures<G1MarkPromotedFromRoot>(g1h, pss);
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   122
    } else {
46281
758ec922d4f2 8160874: Remove typo in G1InitalMarkClosures
tschatzl
parents: 38074
diff changeset
   123
      res = new G1InitialMarkClosures<G1MarkFromRoot>(g1h, pss);
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   124
    }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   125
  } else {
34308
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   126
    res = new G1EvacuationClosures(g1h, pss, g1h->collector_state()->gcs_are_young());
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   127
  }
34308
4496e81c890d 8142494: Add extension point to G1EvacuationRootClosures
ehelin
parents: 33213
diff changeset
   128
  return res;
33213
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   129
}