src/hotspot/share/gc/shared/oopStorage.inline.hpp
author kbarrett
Mon, 29 Jan 2018 16:51:21 -0500
changeset 48816 3495d6050efe
child 48886 e1d09bd56d2d
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_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;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    47
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    48
  Block(const OopStorage* owner, void* memory);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    49
  ~Block();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    50
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    51
  void check_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    52
  unsigned get_index(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    53
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    54
  template<typename F, typename BlockPtr>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    55
  static bool iterate_impl(F f, BlockPtr b);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    56
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    57
  // Noncopyable.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    58
  Block(const Block&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    59
  Block& operator=(const Block&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    60
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    61
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    62
  static const BlockEntry& get_active_entry(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    63
  static const BlockEntry& get_allocate_entry(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    64
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    65
  static size_t allocation_size();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    66
  static size_t allocation_alignment_shift();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    67
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    68
  oop* get_pointer(unsigned index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    69
  const oop* get_pointer(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    70
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    71
  uintx bitmask_for_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    72
  uintx bitmask_for_entry(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    73
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    74
  // Allocation bitmask accessors are racy.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    75
  bool is_full() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    76
  bool is_empty() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    77
  uintx allocated_bitmask() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    78
  uintx cmpxchg_allocated_bitmask(uintx new_value, uintx compare_value);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    79
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    80
  bool contains(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    81
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    82
  // 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
    83
  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
    84
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    85
  oop* allocate();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    86
  static Block* new_block(const OopStorage* owner);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    87
  static void delete_block(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    88
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    89
  template<typename F> bool iterate(F f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    90
  template<typename F> bool iterate(F f) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    91
}; // class Block
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    92
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    93
inline OopStorage::Block* OopStorage::BlockList::head() {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    94
  return const_cast<Block*>(_head);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    95
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    96
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    97
inline const OopStorage::Block* OopStorage::BlockList::chead() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    98
  return _head;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   101
inline const OopStorage::Block* OopStorage::BlockList::ctail() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   102
  return _tail;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   105
inline OopStorage::Block* OopStorage::BlockList::prev(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   106
  return const_cast<Block*>(_get_entry(block)._prev);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   109
inline OopStorage::Block* OopStorage::BlockList::next(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   110
  return const_cast<Block*>(_get_entry(block)._next);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   113
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
   114
  return _get_entry(block)._prev;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   117
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
   118
  return _get_entry(block)._next;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   121
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   122
class OopStorage::OopFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   123
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   124
  explicit OopFn(Closure* cl) : _cl(cl) {}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   125
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   126
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   127
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   128
    _cl->do_oop(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   129
    return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   130
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   131
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   132
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   133
  Closure* _cl;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   136
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   137
inline OopStorage::OopFn<Closure> OopStorage::oop_fn(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   138
  return OopFn<Closure>(cl);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   141
template<typename IsAlive, typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   142
class OopStorage::IfAliveFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   143
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   144
  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
   145
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   146
  bool operator()(oop* ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   147
    bool result = true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   148
    oop v = *ptr;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   149
    if (v != NULL) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   150
      if (_is_alive->do_object_b(v)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   151
        result = _f(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   152
      } else {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   153
        *ptr = NULL;            // Clear dead value.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   154
      }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   155
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   156
    return result;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   157
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   158
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   159
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   160
  IsAlive* _is_alive;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   161
  F _f;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   164
template<typename IsAlive, typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   165
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
   166
  return IfAliveFn<IsAlive, F>(is_alive, f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   167
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   168
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   169
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   170
class OopStorage::SkipNullFn VALUE_OBJ_CLASS_SPEC {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   171
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   172
  SkipNullFn(F f) : _f(f) {}
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
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   175
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   176
    return (*ptr != NULL) ? _f(ptr) : true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   177
  }
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
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   180
  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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   183
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   184
inline OopStorage::SkipNullFn<F> OopStorage::skip_null_fn(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   185
  return SkipNullFn<F>(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   186
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   187
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   188
// Inline Block accesses for use in iteration inner loop.
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
inline void OopStorage::Block::check_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   191
  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
   192
}
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
inline oop* OopStorage::Block::get_pointer(unsigned index) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   195
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   196
  return &_data[index];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   197
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   198
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   199
inline const oop* OopStorage::Block::get_pointer(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   200
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   201
  return &_data[index];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   202
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   203
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   204
inline uintx OopStorage::Block::allocated_bitmask() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   205
  return _allocated_bitmask;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   208
inline uintx OopStorage::Block::bitmask_for_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   209
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   210
  return uintx(1) << index;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   211
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   212
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   213
// Provide const or non-const iteration, depending on whether BlockPtr
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   214
// is const Block* or Block*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   215
template<typename F, typename BlockPtr> // BlockPtr := [const] Block*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   216
inline bool OopStorage::Block::iterate_impl(F f, BlockPtr block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   217
  uintx bitmask = block->allocated_bitmask();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   218
  while (bitmask != 0) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   219
    unsigned index = count_trailing_zeros(bitmask);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   220
    bitmask ^= block->bitmask_for_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   221
    if (!f(block->get_pointer(index))) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   222
      return false;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   223
    }
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
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   226
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   227
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   228
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   229
inline bool OopStorage::Block::iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   230
  return iterate_impl(f, this);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   233
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   234
inline bool OopStorage::Block::iterate(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   235
  return iterate_impl(f, this);
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
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
// Support for serial iteration, always at a safepoint.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   240
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   241
// 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
   242
// const OopStorage* or OopStorage*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   243
template<typename F, typename Storage> // Storage := [const] OopStorage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   244
inline bool OopStorage::iterate_impl(F f, Storage* storage) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   245
  assert_at_safepoint();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   246
  // 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
   247
  // const or non-const blocks as corresponding to Storage.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   248
  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
   249
  for (BlockPtr block = storage->_active_head;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   250
       block != NULL;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   251
       block = storage->_active_list.next(*block)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   252
    if (!block->iterate(f)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   253
      return false;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   254
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   255
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   256
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   257
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   258
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   259
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   260
inline bool OopStorage::iterate_safepoint(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   261
  return iterate_impl(f, this);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   264
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   265
inline bool OopStorage::iterate_safepoint(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   266
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   267
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   268
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   269
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   270
inline void OopStorage::oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   271
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   272
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   273
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   274
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   275
inline void OopStorage::oops_do(Closure* cl) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   276
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   277
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   278
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   279
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   280
inline void OopStorage::weak_oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   281
  iterate_safepoint(skip_null_fn(oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   282
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   283
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   284
template<typename IsAliveClosure, typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   285
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
   286
  iterate_safepoint(if_alive_fn(is_alive, oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   287
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   288
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   289
#endif // include guard