src/hotspot/share/gc/shared/oopStorage.inline.hpp
author stefank
Thu, 22 Feb 2018 18:36:32 +0100
changeset 49048 4e8c86b75428
parent 48886 e1d09bd56d2d
child 49333 489f1dd40582
permissions -rw-r--r--
8198525: Move _size_policy out of GenCollectorPolicy into GenCollectedHeap Reviewed-by: pliden, sjohanss
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_OOPSTORAGE_INLINE_HPP
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    26
#define SHARE_GC_SHARED_OOPSTORAGE_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.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 "metaprogramming/isConst.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    32
#include "oops/oop.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    33
#include "utilities/count_trailing_zeros.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    34
#include "utilities/debug.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    35
#include "utilities/globalDefinitions.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    36
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    37
class OopStorage::Block /* No base class, to avoid messing up alignment. */ {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    38
  // _data must be the first non-static data member, for alignment.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    39
  oop _data[BitsPerWord];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    40
  static const unsigned _data_pos = 0; // Position of _data.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    41
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    42
  volatile uintx _allocated_bitmask; // One bit per _data element.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    43
  const OopStorage* _owner;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    44
  void* _memory;              // Unaligned storage containing block.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    45
  BlockEntry _active_entry;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    46
  BlockEntry _allocate_entry;
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    47
  Block* volatile _deferred_updates_next;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    48
  volatile uintx _release_refcount;
48816
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
  Block(const OopStorage* owner, void* memory);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    51
  ~Block();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    52
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    53
  void check_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    54
  unsigned get_index(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    55
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    56
  template<typename F, typename BlockPtr>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    57
  static bool iterate_impl(F f, BlockPtr b);
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
  // Noncopyable.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    60
  Block(const Block&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    61
  Block& operator=(const Block&);
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
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    64
  static const BlockEntry& get_active_entry(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    65
  static const BlockEntry& get_allocate_entry(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    66
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    67
  static size_t allocation_size();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    68
  static size_t allocation_alignment_shift();
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
  oop* get_pointer(unsigned index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    71
  const oop* get_pointer(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    72
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    73
  uintx bitmask_for_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    74
  uintx bitmask_for_entry(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    75
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    76
  // Allocation bitmask accessors are racy.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    77
  bool is_full() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    78
  bool is_empty() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    79
  uintx allocated_bitmask() const;
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    80
  bool is_deletable() const;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    81
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    82
  Block* deferred_updates_next() const;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    83
  void set_deferred_updates_next(Block* new_next);
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    84
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    85
  bool contains(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    86
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    87
  // Returns NULL if ptr is not in a block or not allocated in that block.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    88
  static Block* block_for_ptr(const OopStorage* owner, const oop* ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    89
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    90
  oop* allocate();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    91
  static Block* new_block(const OopStorage* owner);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    92
  static void delete_block(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    93
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    94
  void release_entries(uintx releasing, Block* volatile* deferred_list);
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    95
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    96
  template<typename F> bool iterate(F f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    97
  template<typename F> bool iterate(F f) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    98
}; // class Block
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    99
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   100
inline OopStorage::Block* OopStorage::BlockList::head() {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   101
  return const_cast<Block*>(_head);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   102
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   103
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   104
inline const OopStorage::Block* OopStorage::BlockList::chead() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   105
  return _head;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   106
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   107
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   108
inline const OopStorage::Block* OopStorage::BlockList::ctail() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   109
  return _tail;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   110
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   111
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   112
inline OopStorage::Block* OopStorage::BlockList::prev(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   113
  return const_cast<Block*>(_get_entry(block)._prev);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   114
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   115
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   116
inline OopStorage::Block* OopStorage::BlockList::next(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   117
  return const_cast<Block*>(_get_entry(block)._next);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   118
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   119
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   120
inline const OopStorage::Block* OopStorage::BlockList::prev(const Block& block) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   121
  return _get_entry(block)._prev;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   122
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   123
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   124
inline const OopStorage::Block* OopStorage::BlockList::next(const Block& block) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   125
  return _get_entry(block)._next;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   126
}
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>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   129
class OopStorage::OopFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   130
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   131
  explicit OopFn(Closure* cl) : _cl(cl) {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   132
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   133
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   134
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   135
    _cl->do_oop(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   136
    return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   137
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   138
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   139
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   140
  Closure* _cl;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   141
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   142
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   143
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   144
inline OopStorage::OopFn<Closure> OopStorage::oop_fn(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   145
  return OopFn<Closure>(cl);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   146
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   147
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   148
template<typename IsAlive, typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   149
class OopStorage::IfAliveFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   150
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   151
  IfAliveFn(IsAlive* is_alive, F f) : _is_alive(is_alive), _f(f) {}
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
  bool operator()(oop* ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   154
    bool result = true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   155
    oop v = *ptr;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   156
    if (v != NULL) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   157
      if (_is_alive->do_object_b(v)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   158
        result = _f(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   159
      } else {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   160
        *ptr = NULL;            // Clear dead value.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   161
      }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   162
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   163
    return result;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   164
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   165
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   166
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   167
  IsAlive* _is_alive;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   168
  F _f;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   169
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   170
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   171
template<typename IsAlive, typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   172
inline OopStorage::IfAliveFn<IsAlive, F> OopStorage::if_alive_fn(IsAlive* is_alive, F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   173
  return IfAliveFn<IsAlive, F>(is_alive, f);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   176
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   177
class OopStorage::SkipNullFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   178
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   179
  SkipNullFn(F f) : _f(f) {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   180
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   181
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   182
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   183
    return (*ptr != NULL) ? _f(ptr) : 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
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   187
  F _f;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   188
};
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
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   191
inline OopStorage::SkipNullFn<F> OopStorage::skip_null_fn(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   192
  return SkipNullFn<F>(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   193
}
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
// Inline Block accesses for use in iteration inner loop.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   196
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   197
inline void OopStorage::Block::check_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   198
  assert(index < ARRAY_SIZE(_data), "Index out of bounds: %u", index);
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
inline oop* OopStorage::Block::get_pointer(unsigned index) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   202
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   203
  return &_data[index];
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
inline const oop* OopStorage::Block::get_pointer(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   207
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   208
  return &_data[index];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   209
}
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
inline uintx OopStorage::Block::allocated_bitmask() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   212
  return _allocated_bitmask;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   213
}
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
inline uintx OopStorage::Block::bitmask_for_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   216
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   217
  return uintx(1) << index;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   218
}
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
// Provide const or non-const iteration, depending on whether BlockPtr
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   221
// is const Block* or Block*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   222
template<typename F, typename BlockPtr> // BlockPtr := [const] Block*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   223
inline bool OopStorage::Block::iterate_impl(F f, BlockPtr block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   224
  uintx bitmask = block->allocated_bitmask();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   225
  while (bitmask != 0) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   226
    unsigned index = count_trailing_zeros(bitmask);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   227
    bitmask ^= block->bitmask_for_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   228
    if (!f(block->get_pointer(index))) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   229
      return false;
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
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   232
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   233
}
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
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   236
inline bool OopStorage::Block::iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   237
  return iterate_impl(f, this);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   240
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   241
inline bool OopStorage::Block::iterate(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   242
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   243
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   244
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   245
//////////////////////////////////////////////////////////////////////////////
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   246
// Support for serial iteration, always at a safepoint.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   247
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   248
// Provide const or non-const iteration, depending on whether Storage is
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   249
// const OopStorage* or OopStorage*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   250
template<typename F, typename Storage> // Storage := [const] OopStorage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   251
inline bool OopStorage::iterate_impl(F f, Storage* storage) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   252
  assert_at_safepoint();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   253
  // Propagate const/non-const iteration to the block layer, by using
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   254
  // const or non-const blocks as corresponding to Storage.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   255
  typedef typename Conditional<IsConst<Storage>::value, const Block*, Block*>::type BlockPtr;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   256
  for (BlockPtr block = storage->_active_head;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   257
       block != NULL;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   258
       block = storage->_active_list.next(*block)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   259
    if (!block->iterate(f)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   260
      return false;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   261
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   262
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   263
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   264
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   265
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   266
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   267
inline bool OopStorage::iterate_safepoint(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   268
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   269
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   270
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   271
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   272
inline bool OopStorage::iterate_safepoint(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   273
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   274
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   275
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   276
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   277
inline void OopStorage::oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   278
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   279
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   280
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   281
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   282
inline void OopStorage::oops_do(Closure* cl) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   283
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   284
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   285
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   286
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   287
inline void OopStorage::weak_oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   288
  iterate_safepoint(skip_null_fn(oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   289
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   290
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   291
template<typename IsAliveClosure, typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   292
inline void OopStorage::weak_oops_do(IsAliveClosure* is_alive, Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   293
  iterate_safepoint(if_alive_fn(is_alive, oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   294
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   295
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   296
#endif // include guard