src/hotspot/share/gc/z/zObjArrayAllocator.cpp
author stefank
Wed, 27 Nov 2019 11:31:46 +0100
changeset 59292 95b1385dd476
parent 58066 8407928b9fe5
child 58679 9c3209ff7550
permissions -rw-r--r--
8234897: 8234748: Clean up atomic and orderAccess includes - part 2 Reviewed-by: tschatzl, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     1
/*
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     4
 *
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     8
 *
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    13
 * accompanied this code).
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    14
 *
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    18
 *
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    21
 * questions.
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    22
 */
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    23
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    24
#include "precompiled.hpp"
57851
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    25
#include "gc/z/zThreadLocalData.hpp"
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    26
#include "gc/z/zObjArrayAllocator.hpp"
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    27
#include "gc/z/zUtils.inline.hpp"
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    28
#include "oops/arrayKlass.hpp"
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    29
#include "runtime/interfaceSupport.inline.hpp"
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    30
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    31
ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, Thread* thread) :
58066
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    32
    ObjArrayAllocator(klass, word_size, length, false /* do_zero */, thread) {}
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    33
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    34
oop ZObjArrayAllocator::finish(HeapWord* mem) const {
58066
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    35
  // Initialize object header and length field
57851
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    36
  ObjArrayAllocator::finish(mem);
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    37
58066
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    38
  // Keep the array alive across safepoints through an invisible
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    39
  // root. Invisible roots are not visited by the heap itarator
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    40
  // and the marking logic will not attempt to follow its elements.
57851
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    41
  ZThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    42
58066
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    43
  // A max segment size of 64K was chosen because microbenchmarking
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    44
  // suggested that it offered a good trade-off between allocation
8407928b9fe5 8230566: ZGC: Don't substitute klass pointer during array clearing
pliden
parents: 57851
diff changeset
    45
  // time and time-to-safepoint
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    46
  const size_t segment_max = ZUtils::bytes_to_words(64 * K);
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    47
  const size_t skip = arrayOopDesc::header_size(ArrayKlass::cast(_klass)->element_type());
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    48
  size_t remaining = _word_size - skip;
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    49
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    50
  while (remaining > 0) {
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    51
    // Clear segment
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    52
    const size_t segment = MIN2(remaining, segment_max);
57851
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    53
    Copy::zero_to_words(mem + (_word_size - remaining), segment);
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    54
    remaining -= segment;
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    55
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    56
    if (remaining > 0) {
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    57
      // Safepoint
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    58
      ThreadBlockInVM tbivm((JavaThread*)_thread);
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    59
    }
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    60
  }
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    61
57851
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    62
  ZThreadLocalData::clear_invisible_root(_thread);
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    63
6728c41f2a08 8229451: ZGC: Make some roots invisible to the heap iterator
pliden
parents: 57850
diff changeset
    64
  return oop(mem);
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents:
diff changeset
    65
}