src/hotspot/share/gc/shared/modRefBarrierSet.inline.hpp
author stefank
Thu, 22 Feb 2018 18:36:32 +0100
changeset 49048 4e8c86b75428
parent 48966 e6eb66d2e765
child 49347 edb65305d3ac
permissions -rw-r--r--
8198525: Move _size_policy out of GenCollectorPolicy into GenCollectedHeap Reviewed-by: pliden, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    28
#include "gc/shared/modRefBarrierSet.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    29
#include "oops/klass.inline.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    30
#include "oops/objArrayOop.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    31
#include "oops/oop.hpp"
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    32
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    33
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    34
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    35
inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    36
oop_store_in_heap(T* addr, oop value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    37
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    38
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    39
  Raw::oop_store(addr, value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    40
  bs->template write_ref_field_post<decorators>(addr, value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    41
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    42
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    43
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    44
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    45
inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    46
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
    47
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    48
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    49
  oop result = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    50
  if (result == compare_value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    51
    bs->template write_ref_field_post<decorators>(addr, new_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    52
  }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    53
  return result;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    54
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    55
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    56
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    57
template <typename T>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    58
inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    59
oop_atomic_xchg_in_heap(oop new_value, T* addr) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    60
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    61
  bs->template write_ref_field_pre<decorators>(addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    62
  oop result = Raw::oop_atomic_xchg(new_value, addr);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    63
  bs->template write_ref_field_post<decorators>(addr, new_value);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    64
  return result;
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 bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    70
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
    71
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    72
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    73
  if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    74
    // Optimized covariant case
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    75
    bs->write_ref_array_pre(dst, (int)length,
48966
e6eb66d2e765 8197454: Need Access decorator for storing oop into uninitialized location
kbarrett
parents: 47998
diff changeset
    76
                            HasDecorator<decorators, AS_DEST_NOT_INITIALIZED>::value);
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    77
    Raw::oop_arraycopy(src_obj, dst_obj, src, dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    78
    bs->write_ref_array((HeapWord*)dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    79
  } else {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    80
    Klass* bound = objArrayOop(dst_obj)->element_klass();
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    81
    T* from = src;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    82
    T* end = from + length;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    83
    for (T* p = dst; from < end; from++, p++) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    84
      T element = *from;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    85
      if (bound->is_instanceof_or_null(element)) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    86
        bs->template write_ref_field_pre<decorators>(p);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    87
        *p = element;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    88
      } else {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    89
        // We must do a barrier to cover the partial copy.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    90
        const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    91
        // pointer delta is scaled to number of elements (length field in
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    92
        // objArrayOop) which we assume is 32 bit.
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    93
        assert(pd == (size_t)(int)pd, "length field overflow");
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    94
        bs->write_ref_array((HeapWord*)dst, pd);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    95
        return false;
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
    }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    98
    bs->write_ref_array((HeapWord*)dst, length);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
    99
  }
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   100
  return true;
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   101
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   102
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   103
template <DecoratorSet decorators, typename BarrierSetT>
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   104
inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   105
clone_in_heap(oop src, oop dst, size_t size) {
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   106
  Raw::clone(src, dst, size);
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   107
  BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   108
  bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   109
}
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   110
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
diff changeset
   111
#endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP