src/hotspot/share/gc/shared/oopStorage.inline.hpp
author kbarrett
Thu, 03 May 2018 17:36:50 -0400
changeset 49977 9f758f0bb058
parent 49392 2956d0ece7a9
child 50209 2fdce199fcb9
permissions -rw-r--r--
8200557: OopStorage parallel iteration scales poorly Summary: Change representation of sequence of all blocks for better scaling. Reviewed-by: coleenp, eosterlund
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 "metaprogramming/conditional.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    30
#include "metaprogramming/isConst.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    31
#include "oops/oop.hpp"
49333
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 48886
diff changeset
    32
#include "runtime/safepoint.hpp"
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    33
#include "utilities/align.hpp"
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    34
#include "utilities/count_trailing_zeros.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    35
#include "utilities/debug.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    36
#include "utilities/globalDefinitions.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
    37
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    38
// Array of all active blocks.  Refcounted for lock-free reclaim of
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    39
// old array when a new array is allocated for expansion.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    40
class OopStorage::BlockArray {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    41
  friend class OopStorage::TestAccess;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    42
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    43
  size_t _size;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    44
  volatile size_t _block_count;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    45
  mutable volatile int _refcount;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    46
  // Block* _blocks[1];            // Pseudo flexible array member.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    47
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    48
  BlockArray(size_t size);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    49
  ~BlockArray();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    50
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    51
  // Noncopyable
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    52
  BlockArray(const BlockArray&);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    53
  BlockArray& operator=(const BlockArray&);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    54
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    55
  static size_t blocks_offset();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    56
  Block* const* base_ptr() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    57
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    58
  Block* const* block_ptr(size_t index) const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    59
  Block** block_ptr(size_t index);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    60
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    61
public:
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    62
  static BlockArray* create(size_t size, AllocFailType alloc_fail = AllocFailStrategy::EXIT_OOM);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    63
  static void destroy(BlockArray* ba);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    64
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    65
  inline Block* at(size_t i) const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    66
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    67
  size_t size() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    68
  size_t block_count() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    69
  size_t block_count_acquire() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    70
  void increment_refcount() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    71
  bool decrement_refcount() const; // Return true if zero, otherwise false
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    72
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    73
  // Support for OopStorage::allocate.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    74
  // Add block to the end of the array.  Updates block count at the
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    75
  // end of the operation, with a release_store. Returns true if the
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    76
  // block was added, false if there was no room available.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    77
  // precondition: owner's _allocation_mutex is locked, or at safepoint.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    78
  bool push(Block* block);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    79
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    80
  // Support OopStorage::delete_empty_blocks_xxx operations.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    81
  // Remove block from the array.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    82
  // precondition: block must be present at its active_index element.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    83
  void remove(Block* block);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    84
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    85
  void copy_from(const BlockArray* from);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    86
};
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    87
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    88
inline size_t OopStorage::BlockArray::blocks_offset() {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    89
  return align_up(sizeof(BlockArray), sizeof(Block*));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    90
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    91
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    92
inline OopStorage::Block* const* OopStorage::BlockArray::base_ptr() const {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    93
  const void* ptr = reinterpret_cast<const char*>(this) + blocks_offset();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    94
  return reinterpret_cast<Block* const*>(ptr);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    95
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    96
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    97
inline OopStorage::Block* const* OopStorage::BlockArray::block_ptr(size_t index) const {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    98
  return base_ptr() + index;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
    99
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   100
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   101
inline OopStorage::Block** OopStorage::BlockArray::block_ptr(size_t index) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   102
  return const_cast<Block**>(base_ptr() + index);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   103
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   104
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   105
inline OopStorage::Block* OopStorage::BlockArray::at(size_t index) const {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   106
  assert(index < _block_count, "precondition");
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   107
  return *block_ptr(index);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   108
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   109
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   110
// A Block has an embedded BlockEntry to provide the links between
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   111
// Blocks in a BlockList.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   112
class OopStorage::BlockEntry {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   113
  friend class OopStorage::BlockList;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   114
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   115
  // Members are mutable, and we deal exclusively with pointers to
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   116
  // const, to make const blocks easier to use; a block being const
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   117
  // doesn't prevent modifying its list state.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   118
  mutable const Block* _prev;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   119
  mutable const Block* _next;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   120
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   121
  // Noncopyable.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   122
  BlockEntry(const BlockEntry&);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   123
  BlockEntry& operator=(const BlockEntry&);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   124
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   125
public:
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   126
  BlockEntry();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   127
  ~BlockEntry();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   128
};
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   129
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   130
// Fixed-sized array of oops, plus bookkeeping data.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   131
// All blocks are in the storage's _active_array, at the block's _active_index.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   132
// Non-full blocks are in the storage's _allocate_list, linked through the
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   133
// block's _allocate_entry.  Empty blocks are at the end of that list.
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   134
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
   135
  // _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
   136
  oop _data[BitsPerWord];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   137
  static const unsigned _data_pos = 0; // Position of _data.
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
  volatile uintx _allocated_bitmask; // One bit per _data element.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   140
  const OopStorage* _owner;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   141
  void* _memory;              // Unaligned storage containing block.
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   142
  size_t _active_index;
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   143
  BlockEntry _allocate_entry;
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   144
  Block* volatile _deferred_updates_next;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   145
  volatile uintx _release_refcount;
48816
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
  Block(const OopStorage* owner, void* memory);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   148
  ~Block();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   149
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   150
  void check_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   151
  unsigned get_index(const oop* ptr) const;
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
  template<typename F, typename BlockPtr>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   154
  static bool iterate_impl(F f, BlockPtr b);
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
  // Noncopyable.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   157
  Block(const Block&);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   158
  Block& operator=(const Block&);
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
  static const BlockEntry& get_allocate_entry(const Block& block);
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
  static size_t allocation_size();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   164
  static size_t allocation_alignment_shift();
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
  oop* get_pointer(unsigned index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   167
  const oop* get_pointer(unsigned index) const;
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
  uintx bitmask_for_index(unsigned index) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   170
  uintx bitmask_for_entry(const oop* ptr) const;
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
  // Allocation bitmask accessors are racy.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   173
  bool is_full() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   174
  bool is_empty() const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   175
  uintx allocated_bitmask() const;
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   176
  bool is_deletable() const;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   177
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   178
  Block* deferred_updates_next() const;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   179
  void set_deferred_updates_next(Block* new_next);
48816
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
  bool contains(const oop* ptr) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   182
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   183
  size_t active_index() const;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   184
  void set_active_index(size_t index);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   185
  static size_t active_index_safe(const Block* block); // Returns 0 if access fails.
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   186
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   187
  // 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
   188
  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
   189
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   190
  oop* allocate();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   191
  static Block* new_block(const OopStorage* owner);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   192
  static void delete_block(const Block& block);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   193
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   194
  void release_entries(uintx releasing, Block* volatile* deferred_list);
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   195
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   196
  template<typename F> bool iterate(F f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   197
  template<typename F> bool iterate(F f) const;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   198
}; // class Block
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
inline OopStorage::Block* OopStorage::BlockList::head() {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   201
  return const_cast<Block*>(_head);
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
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   204
inline OopStorage::Block* OopStorage::BlockList::tail() {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   205
  return const_cast<Block*>(_tail);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   206
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   207
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   208
inline const OopStorage::Block* OopStorage::BlockList::chead() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   209
  return _head;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   212
inline const OopStorage::Block* OopStorage::BlockList::ctail() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   213
  return _tail;
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
inline OopStorage::Block* OopStorage::BlockList::prev(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   217
  return const_cast<Block*>(_get_entry(block)._prev);
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
inline OopStorage::Block* OopStorage::BlockList::next(Block& block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   221
  return const_cast<Block*>(_get_entry(block)._next);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   222
}
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
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
   225
  return _get_entry(block)._prev;
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
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
   229
  return _get_entry(block)._next;
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
template<typename Closure>
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49333
diff changeset
   233
class OopStorage::OopFn {
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   234
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   235
  explicit OopFn(Closure* cl) : _cl(cl) {}
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
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   238
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   239
    _cl->do_oop(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   240
    return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   241
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   242
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   243
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   244
  Closure* _cl;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   247
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   248
inline OopStorage::OopFn<Closure> OopStorage::oop_fn(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   249
  return OopFn<Closure>(cl);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   250
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   251
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   252
template<typename IsAlive, typename F>
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49333
diff changeset
   253
class OopStorage::IfAliveFn {
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   254
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   255
  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
   256
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   257
  bool operator()(oop* ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   258
    bool result = true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   259
    oop v = *ptr;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   260
    if (v != NULL) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   261
      if (_is_alive->do_object_b(v)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   262
        result = _f(ptr);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   263
      } else {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   264
        *ptr = NULL;            // Clear dead value.
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
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   267
    return result;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   270
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   271
  IsAlive* _is_alive;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   272
  F _f;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   275
template<typename IsAlive, typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   276
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
   277
  return IfAliveFn<IsAlive, F>(is_alive, f);
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   280
template<typename F>
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49333
diff changeset
   281
class OopStorage::SkipNullFn {
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   282
public:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   283
  SkipNullFn(F f) : _f(f) {}
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
  template<typename OopPtr>     // [const] oop*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   286
  bool operator()(OopPtr ptr) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   287
    return (*ptr != NULL) ? _f(ptr) : true;
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
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   290
private:
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   291
  F _f;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   292
};
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   293
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   294
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   295
inline OopStorage::SkipNullFn<F> OopStorage::skip_null_fn(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   296
  return SkipNullFn<F>(f);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   297
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   298
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   299
// Inline Block accesses for use in iteration inner loop.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   300
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   301
inline void OopStorage::Block::check_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   302
  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
   303
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   304
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   305
inline oop* OopStorage::Block::get_pointer(unsigned index) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   306
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   307
  return &_data[index];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   308
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   309
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   310
inline const oop* OopStorage::Block::get_pointer(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   311
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   312
  return &_data[index];
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   313
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   314
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   315
inline uintx OopStorage::Block::allocated_bitmask() const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   316
  return _allocated_bitmask;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   317
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   318
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   319
inline uintx OopStorage::Block::bitmask_for_index(unsigned index) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   320
  check_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   321
  return uintx(1) << index;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   322
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   323
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   324
// Provide const or non-const iteration, depending on whether BlockPtr
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   325
// is const Block* or Block*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   326
template<typename F, typename BlockPtr> // BlockPtr := [const] Block*
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   327
inline bool OopStorage::Block::iterate_impl(F f, BlockPtr block) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   328
  uintx bitmask = block->allocated_bitmask();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   329
  while (bitmask != 0) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   330
    unsigned index = count_trailing_zeros(bitmask);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   331
    bitmask ^= block->bitmask_for_index(index);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   332
    if (!f(block->get_pointer(index))) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   333
      return false;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   334
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   335
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   336
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   337
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   338
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   339
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   340
inline bool OopStorage::Block::iterate(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   341
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   342
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   343
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   344
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   345
inline bool OopStorage::Block::iterate(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   346
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   347
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   348
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   349
//////////////////////////////////////////////////////////////////////////////
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   350
// Support for serial iteration, always at a safepoint.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   351
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   352
// 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
   353
// const OopStorage* or OopStorage*, respectively.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   354
template<typename F, typename Storage> // Storage := [const] OopStorage
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   355
inline bool OopStorage::iterate_impl(F f, Storage* storage) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   356
  assert_at_safepoint();
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   357
  // 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
   358
  // const or non-const blocks as corresponding to Storage.
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   359
  typedef typename Conditional<IsConst<Storage>::value, const Block*, Block*>::type BlockPtr;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   360
  BlockArray* blocks = storage->_active_array;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   361
  size_t limit = blocks->block_count();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   362
  for (size_t i = 0; i < limit; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49392
diff changeset
   363
    BlockPtr block = blocks->at(i);
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   364
    if (!block->iterate(f)) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   365
      return false;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   366
    }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   367
  }
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   368
  return true;
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   369
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   370
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   371
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   372
inline bool OopStorage::iterate_safepoint(F f) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   373
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   374
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   375
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   376
template<typename F>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   377
inline bool OopStorage::iterate_safepoint(F f) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   378
  return iterate_impl(f, this);
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   379
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   380
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   381
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   382
inline void OopStorage::oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   383
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   384
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   385
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   386
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   387
inline void OopStorage::oops_do(Closure* cl) const {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   388
  iterate_safepoint(oop_fn(cl));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   389
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   390
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   391
template<typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   392
inline void OopStorage::weak_oops_do(Closure* cl) {
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   393
  iterate_safepoint(skip_null_fn(oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   394
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   395
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   396
template<typename IsAliveClosure, typename Closure>
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   397
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
   398
  iterate_safepoint(if_alive_fn(is_alive, oop_fn(cl)));
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   399
}
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   400
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
diff changeset
   401
#endif // include guard