hotspot/src/share/vm/gc/g1/g1RootClosures.cpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 33213 b937f634f56e
child 34308 4496e81c890d
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
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
/*
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    26
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    27
#include "gc/g1/bufferingOopClosure.hpp"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    28
#include "gc/g1/g1CodeBlobClosure.hpp"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    29
#include "gc/g1/g1CollectedHeap.hpp"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    30
#include "gc/g1/g1OopClosures.inline.hpp"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    31
#include "gc/g1/g1RootClosures.hpp"
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    32
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    33
class G1ParScanThreadState;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    34
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    35
// Simple holder object for a complete set of closures used by the G1 evacuation code.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    36
template <G1Mark Mark>
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    37
class G1SharedClosures VALUE_OBJ_CLASS_SPEC {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    38
public:
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    39
  G1ParCopyClosure<G1BarrierNone,  Mark> _oops;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    40
  G1ParCopyClosure<G1BarrierKlass, Mark> _oop_in_klass;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    41
  G1KlassScanClosure                     _klass_in_cld_closure;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    42
  CLDToKlassAndOopClosure                _clds;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    43
  G1CodeBlobClosure                      _codeblobs;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    44
  BufferingOopClosure                    _buffered_oops;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    45
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    46
  G1SharedClosures(G1CollectedHeap* g1h, G1ParScanThreadState* pss, bool process_only_dirty_klasses, bool must_claim_cld) :
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    47
    _oops(g1h, pss),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    48
    _oop_in_klass(g1h, pss),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    49
    _klass_in_cld_closure(&_oop_in_klass, process_only_dirty_klasses),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    50
    _clds(&_klass_in_cld_closure, &_oops, must_claim_cld),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    51
    _codeblobs(&_oops),
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    52
    _buffered_oops(&_oops) {}
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    53
};
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    54
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    55
class G1EvacuationClosures : public G1EvacuationRootClosures {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    56
  G1SharedClosures<G1MarkNone> _closures;
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
public:
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    59
  G1EvacuationClosures(G1CollectedHeap* g1h,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    60
                       G1ParScanThreadState* pss,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    61
                       bool gcs_are_young) :
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    62
      _closures(g1h, pss, gcs_are_young, /* must_claim_cld */ false) {}
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    63
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    64
  OopClosure* weak_oops()   { return &_closures._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    65
  OopClosure* strong_oops() { return &_closures._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    66
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    67
  CLDClosure* weak_clds()             { return &_closures._clds; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    68
  CLDClosure* strong_clds()           { return &_closures._clds; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    69
  CLDClosure* thread_root_clds()      { return NULL; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    70
  CLDClosure* second_pass_weak_clds() { return NULL; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    71
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    72
  CodeBlobClosure* strong_codeblobs()      { return &_closures._codeblobs; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    73
  CodeBlobClosure* weak_codeblobs()        { return &_closures._codeblobs; }
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
  void flush()                 { _closures._buffered_oops.done(); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    76
  double closure_app_seconds() { return _closures._buffered_oops.closure_app_seconds(); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    77
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    78
  OopClosure* raw_strong_oops() { return &_closures._oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    79
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    80
  bool trace_metadata()         { return false; }
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
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    83
// Closures used during initial mark.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    84
// The treatment of "weak" roots is selectable through the template parameter,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    85
// 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
    86
template <G1Mark MarkWeak>
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    87
class G1InitalMarkClosures : public G1EvacuationRootClosures {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    88
  G1SharedClosures<G1MarkFromRoot> _strong;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    89
  G1SharedClosures<MarkWeak>       _weak;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    90
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    91
  // Filter method to help with returning the appropriate closures
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    92
  // depending on the class template parameter.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    93
  template <G1Mark Mark, typename T>
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    94
  T* null_if(T* t) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    95
    if (Mark == MarkWeak) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    96
      return NULL;
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    97
    }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
    98
    return t;
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
public:
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   102
  G1InitalMarkClosures(G1CollectedHeap* g1h,
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   103
                       G1ParScanThreadState* pss) :
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   104
      _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
   105
      _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
   106
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   107
  OopClosure* weak_oops()   { return &_weak._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   108
  OopClosure* strong_oops() { return &_strong._buffered_oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   109
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   110
  // 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
   111
  CLDClosure* weak_clds()             { return null_if<G1MarkPromotedFromRoot>(&_weak._clds); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   112
  CLDClosure* strong_clds()           { return &_strong._clds; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   113
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   114
  // 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
   115
  // 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
   116
  CLDClosure* thread_root_clds()      { return null_if<G1MarkFromRoot>(&_strong._clds); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   117
  CLDClosure* second_pass_weak_clds() { return null_if<G1MarkFromRoot>(&_weak._clds); }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   118
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   119
  CodeBlobClosure* strong_codeblobs()      { return &_strong._codeblobs; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   120
  CodeBlobClosure* weak_codeblobs()        { return &_weak._codeblobs; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   121
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   122
  void flush() {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   123
    _strong._buffered_oops.done();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   124
    _weak._buffered_oops.done();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   125
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   126
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   127
  double closure_app_seconds() {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   128
    return _strong._buffered_oops.closure_app_seconds() +
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   129
           _weak._buffered_oops.closure_app_seconds();
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   130
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   131
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   132
  OopClosure* raw_strong_oops() { return &_strong._oops; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   133
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   134
  // 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
   135
  // which metadata is alive.
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   136
  bool trace_metadata()         { return MarkWeak == G1MarkPromotedFromRoot; }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   137
};
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   138
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   139
G1EvacuationRootClosures* G1EvacuationRootClosures::create_root_closures(G1ParScanThreadState* pss, G1CollectedHeap* g1h) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   140
  if (g1h->collector_state()->during_initial_mark_pause()) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   141
    if (ClassUnloadingWithConcurrentMark) {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   142
      return new G1InitalMarkClosures<G1MarkPromotedFromRoot>(g1h, pss);
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   143
    } else {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   144
      return new G1InitalMarkClosures<G1MarkFromRoot>(g1h, pss);
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   145
    }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   146
  } else {
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   147
    return new G1EvacuationClosures(g1h, pss, g1h->collector_state()->gcs_are_young());
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   148
  }
b937f634f56e 8138762: Refactor setup of evacuation closures in G1
mgerdin
parents:
diff changeset
   149
}