src/hotspot/share/gc/z/zAttachedArray.inline.hpp
author eosterlund
Tue, 12 Nov 2019 20:01:23 +0000
changeset 59038 b9a42ca342db
parent 58237 944b58cbaf93
permissions -rw-r--r--
8233061: ZGC: Enforce memory ordering in segmented bit maps Reviewed-by: pliden, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54170
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     1
/*
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     4
 *
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     8
 *
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    13
 * accompanied this code).
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    14
 *
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    18
 *
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    21
 * questions.
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    22
 */
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    23
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    24
#ifndef SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    25
#define SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    26
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    27
#include "gc/z/zAttachedArray.hpp"
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    28
#include "memory/allocation.hpp"
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    29
#include "utilities/align.hpp"
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    30
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    31
template <typename ObjectT, typename ArrayT>
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    32
inline size_t ZAttachedArray<ObjectT, ArrayT>::object_size() {
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    33
  return align_up(sizeof(ObjectT), sizeof(ArrayT));
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    34
}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    35
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    36
template <typename ObjectT, typename ArrayT>
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    37
inline void* ZAttachedArray<ObjectT, ArrayT>::alloc(size_t length) {
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    38
  const size_t array_size = sizeof(ArrayT) * length;
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    39
  char* const addr = AllocateHeap(object_size() + array_size, mtGC);
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    40
  ::new (addr + object_size()) ArrayT[length];
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    41
  return addr;
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    42
}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    43
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    44
template <typename ObjectT, typename ArrayT>
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    45
inline void ZAttachedArray<ObjectT, ArrayT>::free(ObjectT* obj) {
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    46
  FreeHeap(obj);
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    47
}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    48
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    49
template <typename ObjectT, typename ArrayT>
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    50
inline ZAttachedArray<ObjectT, ArrayT>::ZAttachedArray(size_t length) :
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    51
    _length(length) {}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    52
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    53
template <typename ObjectT, typename ArrayT>
58237
944b58cbaf93 8230759: ZGC: Fix integer types
stefank
parents: 54170
diff changeset
    54
inline size_t ZAttachedArray<ObjectT, ArrayT>::length() const {
54170
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    55
  return _length;
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    56
}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    57
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    58
template <typename ObjectT, typename ArrayT>
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    59
inline ArrayT* ZAttachedArray<ObjectT, ArrayT>::operator()(const ObjectT* obj) const {
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    60
  return reinterpret_cast<ArrayT*>(reinterpret_cast<uintptr_t>(obj) + object_size());
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    61
}
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    62
8f1771ea1e39 8220595: ZGC: Introduce ZAttachedArray
pliden
parents:
diff changeset
    63
#endif // SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP