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