src/hotspot/share/gc/shared/oopStorageParState.inline.hpp
author kbarrett
Mon, 29 Jan 2018 16:51:21 -0500
changeset 48816 3495d6050efe
child 49005 cc2b457f2589
permissions -rw-r--r--
8194898: Move OopStorage inline definitions to an .inline.hpp Reviewed-by: coleenp, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     1
/*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     4
 *
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     8
 *
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    14
 *
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    18
 *
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    21
 * questions.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    22
 *
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    23
 */
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    24
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    25
#ifndef SHARE_GC_SHARED_OOPSTORAGEPARSTATE_INLINE_HPP
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    26
#define SHARE_GC_SHARED_OOPSTORAGEPARSTATE_INLINE_HPP
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    27
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    28
#include "gc/shared/oopStorage.inline.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    29
#include "memory/allocation.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    30
#include "metaprogramming/conditional.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    31
#include "utilities/macros.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    32
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    33
#if INCLUDE_ALL_GCS
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    34
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    35
//////////////////////////////////////////////////////////////////////////////
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    36
// Support for parallel and optionally concurrent state iteration.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    37
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    38
// Parallel iteration is for the exclusive use of the GC.  Other iteration
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    39
// clients must use serial iteration.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    40
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    41
// Concurrent Iteration
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    42
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    43
// Iteration involves the _active_list, which contains all of the blocks owned
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    44
// by a storage object.  This is a doubly-linked list, linked through
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    45
// dedicated fields in the blocks.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    46
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    47
// At most one concurrent ParState can exist at a time for a given storage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    48
// object.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    49
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    50
// A concurrent ParState sets the associated storage's
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    51
// _concurrent_iteration_active flag true when the state is constructed, and
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    52
// sets it false when the state is destroyed.  These assignments are made with
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    53
// _active_mutex locked.  Meanwhile, empty block deletion is not done while
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    54
// _concurrent_iteration_active is true.  The flag check and the dependent
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    55
// removal of a block from the _active_list is performed with _active_mutex
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    56
// locked.  This prevents concurrent iteration and empty block deletion from
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    57
// interfering with with each other.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    58
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    59
// Both allocate() and delete_empty_blocks_concurrent() lock the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    60
// _allocate_mutex while performing their respective list manipulations,
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    61
// preventing them from interfering with each other.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    62
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    63
// When allocate() creates a new block, it is added to the front of the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    64
// _active_list.  Then _active_head is set to the new block.  When concurrent
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    65
// iteration is started (by a parallel worker thread calling the state's
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    66
// iterate() function), the current _active_head is used as the initial block
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    67
// for the iteration, with iteration proceeding down the list headed by that
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    68
// block.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    69
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    70
// As a result, the list over which concurrent iteration operates is stable.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    71
// However, once the iteration is started, later allocations may add blocks to
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    72
// the front of the list that won't be examined by the iteration.  And while
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    73
// the list is stable, concurrent allocate() and release() operations may
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    74
// change the set of allocated entries in a block at any time during the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    75
// iteration.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    76
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    77
// As a result, a concurrent iteration handler must accept that some
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    78
// allocations and releases that occur after the iteration started will not be
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    79
// seen by the iteration.  Further, some may overlap examination by the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    80
// iteration.  To help with this, allocate() and release() have an invariant
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    81
// that an entry's value must be NULL when it is not in use.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    82
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    83
// An in-progress delete_empty_blocks_concurrent() operation can contend with
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    84
// the start of a concurrent iteration over the _active_mutex.  Since both are
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    85
// under GC control, that potential contention can be eliminated by never
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    86
// scheduling both operations to run at the same time.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    87
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    88
// ParState<concurrent, is_const>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    89
//   concurrent must be true if iteration is concurrent with the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    90
//   mutator, false if iteration is at a safepoint.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    91
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    92
//   is_const must be true if the iteration is over a constant storage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    93
//   object, false if the iteration may modify the storage object.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    94
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    95
// ParState([const] OopStorage* storage)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    96
//   Construct an object for managing an iteration over storage.  For a
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    97
//   concurrent ParState, empty block deletion for the associated storage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    98
//   is inhibited for the life of the ParState.  There can be no more
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    99
//   than one live concurrent ParState at a time for a given storage object.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   100
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   101
// template<typename F> void iterate(F f)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   102
//   Repeatedly claims a block from the associated storage that has
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   103
//   not been processed by this iteration (possibly by other threads),
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   104
//   and applies f to each entry in the claimed block. Assume p is of
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   105
//   type const oop* or oop*, according to is_const. Then f(p) must be
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   106
//   a valid expression whose value is ignored.  Concurrent uses must
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   107
//   be prepared for an entry's value to change at any time, due to
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   108
//   mutator activity.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   109
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   110
// template<typename Closure> void oops_do(Closure* cl)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   111
//   Wrapper around iterate, providing an adaptation layer allowing
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   112
//   the use of OopClosures and similar objects for iteration.  Assume
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   113
//   p is of type const oop* or oop*, according to is_const.  Then
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   114
//   cl->do_oop(p) must be a valid expression whose value is ignored.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   115
//   Concurrent uses must be prepared for the entry's value to change
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   116
//   at any time, due to mutator activity.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   117
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   118
// Optional operations, provided only if !concurrent && !is_const.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   119
// These are not provided when is_const, because the storage object
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   120
// may be modified by the iteration infrastructure, even if the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   121
// provided closure doesn't modify the storage object.  These are not
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   122
// provided when concurrent because any pre-filtering behavior by the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   123
// iteration infrastructure is inappropriate for concurrent iteration;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   124
// modifications of the storage by the mutator could result in the
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   125
// pre-filtering being applied (successfully or not) to objects that
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   126
// are unrelated to what the closure finds in the entry.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   127
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   128
// template<typename Closure> void weak_oops_do(Closure* cl)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   129
// template<typename IsAliveClosure, typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   130
// void weak_oops_do(IsAliveClosure* is_alive, Closure* cl)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   131
//   Wrappers around iterate, providing an adaptation layer allowing
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   132
//   the use of is-alive closures and OopClosures for iteration.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   133
//   Assume p is of type oop*.  Then
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   134
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   135
//   - cl->do_oop(p) must be a valid expression whose value is ignored.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   136
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   137
//   - is_alive->do_object_b(*p) must be a valid expression whose value
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   138
//   is convertible to bool.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   139
//
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   140
//   If *p == NULL then neither is_alive nor cl will be invoked for p.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   141
//   If is_alive->do_object_b(*p) is false, then cl will not be
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   142
//   invoked on p.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   143
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   144
class OopStorage::BasicParState VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   145
  OopStorage* _storage;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   146
  void* volatile _next_block;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   147
  bool _concurrent;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   148
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   149
  // Noncopyable.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   150
  BasicParState(const BasicParState&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   151
  BasicParState& operator=(const BasicParState&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   152
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   153
  void update_iteration_state(bool value);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   154
  void ensure_iteration_started();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   155
  Block* claim_next_block();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   156
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   157
  // Wrapper for iteration handler; ignore handler result and return true.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   158
  template<typename F> class AlwaysTrueFn;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   159
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   160
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   161
  BasicParState(OopStorage* storage, bool concurrent);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   162
  ~BasicParState();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   163
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   164
  template<bool is_const, typename F> void iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   165
    // Wrap f in ATF so we can use Block::iterate.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   166
    AlwaysTrueFn<F> atf_f(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   167
    ensure_iteration_started();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   168
    typename Conditional<is_const, const Block*, Block*>::type block;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   169
    while ((block = claim_next_block()) != NULL) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   170
      block->iterate(atf_f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   171
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   172
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   173
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   174
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   175
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   176
class OopStorage::BasicParState::AlwaysTrueFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   177
  F _f;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   178
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   179
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   180
  AlwaysTrueFn(F f) : _f(f) {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   181
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   182
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   183
  bool operator()(OopPtr ptr) const { _f(ptr); return true; }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   184
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   185
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   186
template<bool concurrent, bool is_const>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   187
class OopStorage::ParState VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   188
  BasicParState _basic_state;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   189
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   190
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   191
  ParState(const OopStorage* storage) :
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   192
    // For simplicity, always recorded as non-const.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   193
    _basic_state(const_cast<OopStorage*>(storage), concurrent)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   194
  {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   195
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   196
  template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   197
  void iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   198
    _basic_state.template iterate<is_const>(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   199
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   200
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   201
  template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   202
  void oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   203
    this->iterate(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   204
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   205
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   206
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   207
template<>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   208
class OopStorage::ParState<false, false> VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   209
  BasicParState _basic_state;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   210
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   211
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   212
  ParState(OopStorage* storage) :
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   213
    _basic_state(storage, false)
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   214
  {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   215
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   216
  template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   217
  void iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   218
    _basic_state.template iterate<false>(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   219
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   220
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   221
  template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   222
  void oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   223
    this->iterate(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   224
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   225
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   226
  template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   227
  void weak_oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   228
    this->iterate(skip_null_fn(oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   229
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   230
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   231
  template<typename IsAliveClosure, typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   232
  void weak_oops_do(IsAliveClosure* is_alive, Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   233
    this->iterate(if_alive_fn(is_alive, oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   234
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   235
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   236
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   237
#endif // INCLUDE_ALL_GCS
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   238
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   239
#endif // include guard