src/hotspot/share/gc/parallel/psClosure.inline.hpp
author tschatzl
Fri, 29 Nov 2019 10:20:17 +0100
changeset 59321 5775e4825e58
parent 53244 9807daeb47c4
permissions -rw-r--r--
8233998: New young regions registered too early in collection set Reviewed-by: sangheki, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52117
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52117
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
52117
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     4
 *
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     8
 *
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    13
 * accompanied this code).
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    14
 *
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    18
 *
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    21
 * questions.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    22
 *
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    23
 */
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52117
diff changeset
    25
#ifndef SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52117
diff changeset
    26
#define SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP
52117
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    27
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    28
#include "gc/parallel/psPromotionManager.inline.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    29
#include "gc/parallel/psScavenge.inline.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    30
#include "memory/iterator.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    31
#include "oops/access.inline.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    32
#include "oops/oop.inline.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    34
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    35
template <bool promote_immediately>
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    36
class PSRootsClosure: public OopClosure {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    37
private:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    38
  PSPromotionManager* _promotion_manager;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    39
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    40
  template <class T> void do_oop_work(T *p) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    41
    if (PSScavenge::should_scavenge(p)) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    42
      // We never card mark roots, maybe call a func without test?
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    43
      _promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    44
    }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    45
  }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    46
public:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    47
  PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    48
  void do_oop(oop* p)       { PSRootsClosure::do_oop_work(p); }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    49
  void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    50
};
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    51
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    52
typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    53
typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    54
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    55
// Scavenges a single oop in a ClassLoaderData.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    56
class PSScavengeFromCLDClosure: public OopClosure {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    57
private:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    58
  PSPromotionManager* _pm;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    59
  // Used to redirty a scanned cld if it has oops
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    60
  // pointing to the young generation after being scanned.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    61
  ClassLoaderData*    _scanned_cld;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    62
public:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    63
  PSScavengeFromCLDClosure(PSPromotionManager* pm) : _pm(pm), _scanned_cld(NULL) { }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    64
  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    65
  void do_oop(oop* p)       {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    66
    ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    67
    assert(!psh->is_in_reserved(p), "GC barrier needed");
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    68
    if (PSScavenge::should_scavenge(p)) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    69
      assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    70
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    71
      oop o = *p;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    72
      oop new_obj;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    73
      if (o->is_forwarded()) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    74
        new_obj = o->forwardee();
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    75
      } else {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    76
        new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    77
      }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    78
      RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    79
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    80
      if (PSScavenge::is_obj_in_young(new_obj)) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    81
        do_cld_barrier();
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    82
      }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    83
    }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    84
  }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    85
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    86
  void set_scanned_cld(ClassLoaderData* cld) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    87
    assert(_scanned_cld == NULL || cld == NULL, "Should always only handling one cld at a time");
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    88
    _scanned_cld = cld;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    89
  }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    90
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    91
private:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    92
  void do_cld_barrier() {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    93
    assert(_scanned_cld != NULL, "Should not be called without having a scanned cld");
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    94
    _scanned_cld->record_modified_oops();
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    95
  }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    96
};
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    97
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    98
// Scavenges the oop in a ClassLoaderData.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
    99
class PSScavengeCLDClosure: public CLDClosure {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   100
private:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   101
  PSScavengeFromCLDClosure _oop_closure;
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   102
public:
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   103
  PSScavengeCLDClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   104
  void do_cld(ClassLoaderData* cld) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   105
    // If the cld has not been dirtied we know that there's
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   106
    // no references into  the young gen and we can skip it.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   107
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   108
    if (cld->has_modified_oops()) {
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   109
      // Setup the promotion manager to redirty this cld
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   110
      // if references are left in the young gen.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   111
      _oop_closure.set_scanned_cld(cld);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   112
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   113
      // Clean the cld since we're going to scavenge all the metadata.
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   114
      cld->oops_do(&_oop_closure, false, /*clear_modified_oops*/true);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   115
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   116
      _oop_closure.set_scanned_cld(NULL);
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   117
    }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   118
  }
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   119
};
a2edf32cd813 8201436: Replace oop_ps_push_contents with oop_iterate and closure
lkorinth
parents:
diff changeset
   120
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52117
diff changeset
   121
#endif // SHARE_GC_PARALLEL_PSCLOSURE_INLINE_HPP