src/hotspot/share/gc/z/zBarrierSetNMethod.cpp
author mgronlun
Wed, 30 Oct 2019 19:43:52 +0100
changeset 58863 c16ac7a2eba4
parent 58226 408c445d04e8
child 59284 88502b1cf76f
permissions -rw-r--r--
8226511: Implement JFR Event Streaming Reviewed-by: egahlin, mseledtsov, mgronlun Contributed-by: erik.gahlin@oracle.com, mikhailo.seledtsov@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     1
/*
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 55479
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     4
 *
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     8
 *
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    13
 * accompanied this code).
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    14
 *
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    18
 *
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    21
 * questions.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    22
 */
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    23
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    24
#include "precompiled.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    25
#include "code/nmethod.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    26
#include "gc/z/zBarrierSetNMethod.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    27
#include "gc/z/zGlobals.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    28
#include "gc/z/zLock.inline.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    29
#include "gc/z/zOopClosures.hpp"
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53282
diff changeset
    30
#include "gc/z/zNMethod.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    31
#include "gc/z/zThreadLocalData.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    32
#include "logging/log.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    33
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    34
bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53282
diff changeset
    35
  ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    36
  log_trace(nmethod, barrier)("Entered critical zone for %p", nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    37
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    38
  if (!is_armed(nm)) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    39
    // Some other thread got here first and healed the oops
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    40
    // and disarmed the nmethod.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    41
    return true;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    42
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    43
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    44
  if (nm->is_unloading()) {
53282
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
    45
    // We don't need to take the lock when unlinking nmethods from
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
    46
    // the Method, because it is only concurrently unlinked by
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
    47
    // the entry barrier, which acquires the per nmethod lock.
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 55479
diff changeset
    48
    nm->unlink_from_method();
53282
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
    49
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    50
    // We can end up calling nmethods that are unloading
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    51
    // since we clear compiled ICs lazily. Returning false
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    52
    // will re-resovle the call and update the compiled IC.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    53
    return false;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    54
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    55
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    56
  // Heal oops and disarm
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    57
  ZNMethodOopClosure cl;
54567
224515275cf9 8219718: ZGC: Make nmethod entry barriers and nmethod::is_unloading use ZNMethodDataOops
eosterlund
parents: 53894
diff changeset
    58
  ZNMethod::nmethod_oops_do(nm, &cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    59
  disarm(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    60
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    61
  return true;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    62
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    63
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    64
int ZBarrierSetNMethod::disarmed_value() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    65
  // We override the default BarrierSetNMethod::disarmed_value() since
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    66
  // this can be called by GC threads, which doesn't keep an up to date
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    67
  // address_bad_mask.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    68
  const uintptr_t disarmed_addr = ((uintptr_t)&ZAddressBadMask) + ZNMethodDisarmedOffset;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    69
  return *((int*)disarmed_addr);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    70
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    71
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    72
ByteSize ZBarrierSetNMethod::thread_disarmed_offset() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    73
  return ZThreadLocalData::nmethod_disarmed_offset();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents:
diff changeset
    74
}