src/hotspot/share/gc/z/zNMethodData.cpp
author eosterlund
Tue, 12 Nov 2019 20:01:23 +0000
changeset 59038 b9a42ca342db
parent 58237 944b58cbaf93
child 59247 56bf71d64d51
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:
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     1
/*
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     4
 *
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     8
 *
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    13
 * accompanied this code).
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    14
 *
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    18
 *
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    21
 * questions.
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    22
 */
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    23
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    24
#include "precompiled.hpp"
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    25
#include "gc/z/zAttachedArray.inline.hpp"
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    26
#include "gc/z/zLock.inline.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    27
#include "gc/z/zNMethodData.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    28
#include "memory/allocation.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    29
#include "runtime/atomic.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    30
#include "runtime/orderAccess.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    31
#include "utilities/align.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    32
#include "utilities/debug.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    33
#include "utilities/growableArray.hpp"
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    34
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    35
ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    36
  return ::new (AttachedArray::alloc(immediates.length())) ZNMethodDataOops(immediates, has_non_immediates);
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    37
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    38
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    39
void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    40
  AttachedArray::free(oops);
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    41
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    42
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    43
ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    44
    _immediates(immediates.length()),
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    45
    _has_non_immediates(has_non_immediates) {
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    46
  // Save all immediate oops
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    47
  for (size_t i = 0; i < immediates_count(); i++) {
58237
944b58cbaf93 8230759: ZGC: Fix integer types
stefank
parents: 54171
diff changeset
    48
    immediates_begin()[i] = immediates.at(int(i));
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    49
  }
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    50
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    51
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    52
size_t ZNMethodDataOops::immediates_count() const {
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    53
  return _immediates.length();
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    54
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    55
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    56
oop** ZNMethodDataOops::immediates_begin() const {
54171
07943af21b96 8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
pliden
parents: 53922
diff changeset
    57
  return _immediates(this);
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    58
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    59
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    60
oop** ZNMethodDataOops::immediates_end() const {
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    61
  return immediates_begin() + immediates_count();
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    62
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    63
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    64
bool ZNMethodDataOops::has_non_immediates() const {
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    65
  return _has_non_immediates;
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    66
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    67
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53892
diff changeset
    68
ZNMethodData::ZNMethodData() :
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    69
    _lock(),
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    70
    _oops(NULL) {}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    71
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53892
diff changeset
    72
ZNMethodData::~ZNMethodData() {
53922
00fcc1ef31e8 8219638: ZGC: Free ZNMethodDataOops under a lock
eosterlund
parents: 53921
diff changeset
    73
  ZNMethodDataOops::destroy(_oops);
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53892
diff changeset
    74
}
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53892
diff changeset
    75
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    76
ZReentrantLock* ZNMethodData::lock() {
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    77
  return &_lock;
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    78
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    79
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    80
ZNMethodDataOops* ZNMethodData::oops() const {
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    81
  return OrderAccess::load_acquire(&_oops);
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    82
}
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    83
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    84
ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
53922
00fcc1ef31e8 8219638: ZGC: Free ZNMethodDataOops under a lock
eosterlund
parents: 53921
diff changeset
    85
  ZLocker<ZReentrantLock> locker(&_lock);
00fcc1ef31e8 8219638: ZGC: Free ZNMethodDataOops under a lock
eosterlund
parents: 53921
diff changeset
    86
  ZNMethodDataOops* const old_oops = _oops;
00fcc1ef31e8 8219638: ZGC: Free ZNMethodDataOops under a lock
eosterlund
parents: 53921
diff changeset
    87
  _oops = new_oops;
00fcc1ef31e8 8219638: ZGC: Free ZNMethodDataOops under a lock
eosterlund
parents: 53921
diff changeset
    88
  return old_oops;
53892
33790c8e4647 8219467: ZGC: Move ZNMethodData to its own file
stefank
parents:
diff changeset
    89
}