src/hotspot/share/gc/shared/modRefBarrierSet.inline.hpp
author pliden
Thu, 12 Apr 2018 08:25:56 +0200
changeset 49752 93d84f667d12
parent 49592 77fb0be7d19f
child 50389 7e8c0409a747
permissions -rw-r--r--
8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread Reviewed-by: shade, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     1
/*
48966
e6eb66d2e765 8197454: Need Access decorator for storing oop into uninitialized location
kbarrett
parents: 47998
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     4
 *
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     8
 *
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    13
 * accompanied this code).
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    14
 *
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    18
 *
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    21
 * questions.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    22
 *
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    23
 */
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    24
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    26
#define SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    27
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    28
#include "gc/shared/barrierSet.hpp"
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    29
#include "gc/shared/modRefBarrierSet.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    30
#include "oops/compressedOops.inline.hpp"
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    31
#include "oops/klass.inline.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    32
#include "oops/objArrayOop.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    33
#include "oops/oop.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    34
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    35
// count is number of array elements being written
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    36
void ModRefBarrierSet::write_ref_array(HeapWord* start, size_t count) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    37
  HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    38
  // In the case of compressed oops, start and end may potentially be misaligned;
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    39
  // so we need to conservatively align the first downward (this is not
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    40
  // strictly necessary for current uses, but a case of good hygiene and,
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    41
  // if you will, aesthetics) and the second upward (this is essential for
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    42
  // current uses) to a HeapWord boundary, so we mark all cards overlapping
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    43
  // this write. If this evolves in the future to calling a
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    44
  // logging barrier of narrow oop granularity, like the pre-barrier for G1
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    45
  // (mentioned here merely by way of example), we will need to change this
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    46
  // interface, so it is "exactly precise" (if i may be allowed the adverbial
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    47
  // redundancy for emphasis) and does not include narrow oop slots not
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    48
  // included in the original write interval.
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    49
  HeapWord* aligned_start = align_down(start, HeapWordSize);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    50
  HeapWord* aligned_end   = align_up  (end,   HeapWordSize);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    51
  // If compressed oops were not being used, these should already be aligned
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    52
  assert(UseCompressedOops || (aligned_start == start && aligned_end == end),
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    53
         "Expected heap word alignment of start and end");
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    54
  write_ref_array_work(MemRegion(aligned_start, aligned_end));
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    55
}
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    56
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    57
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    58
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    59
inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    60
oop_store_in_heap(T* addr, oop value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    61
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    62
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    63
  Raw::oop_store(addr, value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    64
  bs->template write_ref_field_post<decorators>(addr, value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    65
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    66
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    67
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    68
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    69
inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    70
oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    71
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    72
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    73
  oop result = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    74
  if (result == compare_value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    75
    bs->template write_ref_field_post<decorators>(addr, new_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    76
  }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    77
  return result;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    78
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    79
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    80
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    81
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    82
inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    83
oop_atomic_xchg_in_heap(oop new_value, T* addr) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    84
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    85
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    86
  oop result = Raw::oop_atomic_xchg(new_value, addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    87
  bs->template write_ref_field_post<decorators>(addr, new_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    88
  return result;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    89
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    90
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    91
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    92
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    93
inline bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    94
oop_arraycopy_in_heap(arrayOop src_obj, arrayOop dst_obj, T* src, T* dst, size_t length) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    95
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    96
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    97
  if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    98
    // Optimized covariant case
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49347
diff changeset
    99
    bs->write_ref_array_pre(dst, length,
48966
e6eb66d2e765 8197454: Need Access decorator for storing oop into uninitialized location
kbarrett
parents: 47998
diff changeset
   100
                            HasDecorator<decorators, AS_DEST_NOT_INITIALIZED>::value);
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   101
    Raw::oop_arraycopy(src_obj, dst_obj, src, dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   102
    bs->write_ref_array((HeapWord*)dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   103
  } else {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   104
    Klass* bound = objArrayOop(dst_obj)->element_klass();
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   105
    T* from = src;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   106
    T* end = from + length;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   107
    for (T* p = dst; from < end; from++, p++) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   108
      T element = *from;
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
   109
      if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) {
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   110
        bs->template write_ref_field_pre<decorators>(p);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   111
        *p = element;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   112
      } else {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   113
        // We must do a barrier to cover the partial copy.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   114
        const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   115
        // pointer delta is scaled to number of elements (length field in
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   116
        // objArrayOop) which we assume is 32 bit.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   117
        assert(pd == (size_t)(int)pd, "length field overflow");
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   118
        bs->write_ref_array((HeapWord*)dst, pd);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   119
        return false;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   120
      }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   121
    }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   122
    bs->write_ref_array((HeapWord*)dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   123
  }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   124
  return true;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   125
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   126
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   127
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   128
inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   129
clone_in_heap(oop src, oop dst, size_t size) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   130
  Raw::clone(src, dst, size);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   131
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   132
  bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   133
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   134
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   135
#endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP