src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp
author zgu
Wed, 27 Nov 2019 11:52:57 -0500
changeset 59296 9186be5c78ba
permissions -rw-r--r--
8228720: Shenandoah: Implementation of concurrent class unloading Reviewed-by: rkennke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59296
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     1
/*
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     2
 * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     3
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     6
 * published by the Free Software Foundation.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     7
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    12
 * accompanied this code).
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    13
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    17
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    20
 * questions.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    21
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    22
 */
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    23
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    24
#include "precompiled.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    25
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    26
#include "gc/shenandoah/shenandoahBarrierSetNMethod.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    27
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    28
#include "gc/shenandoah/shenandoahCodeRoots.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    29
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    30
#include "gc/shenandoah/shenandoahLock.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    31
#include "gc/shenandoah/shenandoahNMethod.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    32
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    33
#include "memory/iterator.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    34
#include "memory/resourceArea.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    35
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    36
bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    37
  ShenandoahReentrantLock* lock = ShenandoahNMethod::lock_for_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    38
  assert(lock != NULL, "Must be");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    39
  ShenandoahReentrantLocker locker(lock);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    40
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    41
  if (!is_armed(nm)) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    42
    // Some other thread got here first and healed the oops
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    43
    // and disarmed the nmethod.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    44
    return true;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    45
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    46
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    47
  if (nm->is_unloading()) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    48
    // We don't need to take the lock when unlinking nmethods from
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    49
    // the Method, because it is only concurrently unlinked by
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    50
    // the entry barrier, which acquires the per nmethod lock.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    51
    nm->unlink_from_method();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    52
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    53
    // We can end up calling nmethods that are unloading
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    54
    // since we clear compiled ICs lazily. Returning false
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    55
    // will re-resovle the call and update the compiled IC.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    56
    return false;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    57
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    58
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    59
  // Heal oops and disarm
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    60
  ShenandoahEvacOOMScope scope;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    61
  ShenandoahNMethod::heal_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    62
  ShenandoahNMethod::disarm_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    63
  return true;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    64
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    65
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    66
int ShenandoahBarrierSetNMethod::disarmed_value() const {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    67
  return ShenandoahCodeRoots::disarmed_value();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    68
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    69
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    70
ByteSize ShenandoahBarrierSetNMethod::thread_disarmed_offset() const {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    71
  return ShenandoahThreadLocalData::disarmed_value_offset();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    72
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    73
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    74
int* ShenandoahBarrierSetNMethod::disarmed_value_address() const {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    75
  return ShenandoahCodeRoots::disarmed_value_address();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    76
}