src/hotspot/share/gc/z/zNMethod.cpp
author stefank
Tue, 26 Nov 2019 10:47:46 +0100
changeset 59290 97d13893ec3c
parent 59248 e92153ed8bdc
permissions -rw-r--r--
8234748: Clean up atomic and orderAccess includes Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     1
/*
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     4
 *
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     8
 *
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    13
 * accompanied this code).
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    14
 *
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    18
 *
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    21
 * questions.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    22
 */
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    23
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    24
#include "precompiled.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    25
#include "code/relocInfo.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    26
#include "code/nmethod.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    27
#include "code/icBuffer.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    28
#include "gc/shared/barrierSet.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    29
#include "gc/shared/barrierSetNMethod.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    30
#include "gc/z/zGlobals.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    31
#include "gc/z/zLock.inline.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    32
#include "gc/z/zNMethod.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    33
#include "gc/z/zNMethodData.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    34
#include "gc/z/zNMethodTable.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    35
#include "gc/z/zOopClosures.inline.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    36
#include "gc/z/zTask.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    37
#include "gc/z/zWorkers.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    38
#include "logging/log.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    39
#include "memory/allocation.inline.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    40
#include "memory/iterator.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    41
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 53921
diff changeset
    42
#include "memory/universe.hpp"
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    43
#include "runtime/atomic.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    44
#include "utilities/debug.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    45
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    46
static ZNMethodData* gc_data(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    47
  return nm->gc_data<ZNMethodData>();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    48
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    49
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    50
static void set_gc_data(nmethod* nm, ZNMethodData* data) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    51
  return nm->set_gc_data<ZNMethodData>(data);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    52
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    53
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    54
void ZNMethod::attach_gc_data(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    55
  GrowableArray<oop*> immediate_oops;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    56
  bool non_immediate_oops = false;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    57
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    58
  // Find all oops relocations
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    59
  RelocIterator iter(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    60
  while (iter.next()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    61
    if (iter.type() != relocInfo::oop_type) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    62
      // Not an oop
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    63
      continue;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    64
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    65
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    66
    oop_Relocation* r = iter.oop_reloc();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    67
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    68
    if (!r->oop_is_immediate()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    69
      // Non-immediate oop found
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    70
      non_immediate_oops = true;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    71
      continue;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    72
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    73
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    74
    if (r->oop_value() != NULL) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    75
      // Non-NULL immediate oop found. NULL oops can safely be
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    76
      // ignored since the method will be re-registered if they
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    77
      // are later patched to be non-NULL.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    78
      immediate_oops.push(r->oop_addr());
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    79
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    80
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    81
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    82
  // Attach GC data to nmethod
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    83
  ZNMethodData* data = gc_data(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    84
  if (data == NULL) {
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
    85
    data = new ZNMethodData();
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    86
    set_gc_data(nm, data);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    87
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    88
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    89
  // Attach oops in GC data
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    90
  ZNMethodDataOops* const new_oops = ZNMethodDataOops::create(immediate_oops, non_immediate_oops);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    91
  ZNMethodDataOops* const old_oops = data->swap_oops(new_oops);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    92
  ZNMethodDataOops::destroy(old_oops);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    93
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    94
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    95
ZReentrantLock* ZNMethod::lock_for_nmethod(nmethod* nm) {
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
    96
  return gc_data(nm)->lock();
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    97
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    98
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    99
void ZNMethod::log_register(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   100
  LogTarget(Trace, gc, nmethod) log;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   101
  if (!log.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   102
    return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   103
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   104
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   105
  const ZNMethodDataOops* const oops = gc_data(nm)->oops();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   106
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   107
  log.print("Register NMethod: %s.%s (" PTR_FORMAT "), "
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   108
            "Compiler: %s, Oops: %d, ImmediateOops: " SIZE_FORMAT ", NonImmediateOops: %s",
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   109
            nm->method()->method_holder()->external_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   110
            nm->method()->name()->as_C_string(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   111
            p2i(nm),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   112
            nm->compiler_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   113
            nm->oops_count() - 1,
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   114
            oops->immediates_count(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   115
            oops->has_non_immediates() ? "Yes" : "No");
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   116
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   117
  LogTarget(Trace, gc, nmethod, oops) log_oops;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   118
  if (!log_oops.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   119
    return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   120
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   121
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   122
  // Print nmethod oops table
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   123
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   124
    oop* const begin = nm->oops_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   125
    oop* const end = nm->oops_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   126
    for (oop* p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   127
      log_oops.print("           Oop[" SIZE_FORMAT "] " PTR_FORMAT " (%s)",
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   128
                     (p - begin), p2i(*p), (*p)->klass()->external_name());
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   129
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   130
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   131
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   132
  // Print nmethod immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   133
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   134
    oop** const begin = oops->immediates_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   135
    oop** const end = oops->immediates_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   136
    for (oop** p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   137
      log_oops.print("  ImmediateOop[" SIZE_FORMAT "] " PTR_FORMAT " @ " PTR_FORMAT " (%s)",
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   138
                     (p - begin), p2i(**p), p2i(*p), (**p)->klass()->external_name());
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   139
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   140
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   141
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   142
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   143
void ZNMethod::log_unregister(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   144
  LogTarget(Debug, gc, nmethod) log;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   145
  if (!log.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   146
    return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   147
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   148
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   149
  log.print("Unregister NMethod: %s.%s (" PTR_FORMAT ")",
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   150
            nm->method()->method_holder()->external_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   151
            nm->method()->name()->as_C_string(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   152
            p2i(nm));
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   153
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   154
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   155
void ZNMethod::register_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   156
  ResourceMark rm;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   157
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   158
  // Create and attach gc data
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   159
  attach_gc_data(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   160
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   161
  log_register(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   162
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   163
  ZNMethodTable::register_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   164
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   165
  // Disarm nmethod entry barrier
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   166
  disarm_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   167
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   168
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   169
void ZNMethod::unregister_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   170
  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   171
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   172
  if (Thread::current()->is_Code_cache_sweeper_thread()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   173
    // The sweeper must wait for any ongoing iteration to complete
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   174
    // before it can unregister an nmethod.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   175
    ZNMethodTable::wait_until_iteration_done();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   176
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   177
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   178
  ResourceMark rm;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   179
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   180
  log_unregister(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   181
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   182
  ZNMethodTable::unregister_nmethod(nm);
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   183
}
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   184
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   185
void ZNMethod::flush_nmethod(nmethod* nm) {
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   186
  // Destroy GC data
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   187
  delete gc_data(nm);
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   188
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   189
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   190
void ZNMethod::disarm_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   191
  BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   192
  if (bs != NULL) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   193
    bs->disarm(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   194
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   195
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   196
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   197
void ZNMethod::nmethod_oops_do(nmethod* nm, OopClosure* cl) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   198
  // Process oops table
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   199
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   200
    oop* const begin = nm->oops_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   201
    oop* const end = nm->oops_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   202
    for (oop* p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   203
      if (*p != Universe::non_oop_word()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   204
        cl->do_oop(p);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   205
      }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   206
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   207
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   208
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   209
  ZNMethodDataOops* const oops = gc_data(nm)->oops();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   210
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   211
  // Process immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   212
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   213
    oop** const begin = oops->immediates_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   214
    oop** const end = oops->immediates_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   215
    for (oop** p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   216
      if (**p != Universe::non_oop_word()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   217
        cl->do_oop(*p);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   218
      }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   219
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   220
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   221
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   222
  // Process non-immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   223
  if (oops->has_non_immediates()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   224
    nm->fix_oop_relocations();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   225
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   226
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   227
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   228
class ZNMethodToOopsDoClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   229
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   230
  OopClosure* _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   231
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   232
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   233
  ZNMethodToOopsDoClosure(OopClosure* cl) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   234
      _cl(cl) {}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   235
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   236
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   237
    ZNMethod::nmethod_oops_do(nm, _cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   238
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   239
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   240
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   241
void ZNMethod::oops_do_begin() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   242
  ZNMethodTable::nmethods_do_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   243
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   244
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   245
void ZNMethod::oops_do_end() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   246
  ZNMethodTable::nmethods_do_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   247
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   248
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   249
void ZNMethod::oops_do(OopClosure* cl) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   250
  ZNMethodToOopsDoClosure nmethod_cl(cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   251
  ZNMethodTable::nmethods_do(&nmethod_cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   252
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   253
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   254
class ZNMethodUnlinkClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   255
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   256
  bool          _unloading_occurred;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   257
  volatile bool _failed;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   258
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   259
  void set_failed() {
59248
e92153ed8bdc 8234736: Harmonize parameter order in Atomic - store
stefank
parents: 58353
diff changeset
   260
    Atomic::store(&_failed, true);
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   261
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   262
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   263
  void unlink(nmethod* nm) {
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   264
    // Unlinking of the dependencies must happen before the
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   265
    // handshake separating unlink and purge.
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   266
    nm->flush_dependencies(false /* delete_immediately */);
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   267
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   268
    // unlink_from_method will take the CompiledMethod_lock.
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   269
    // In this case we don't strictly need it when unlinking nmethods from
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   270
    // the Method, because it is only concurrently unlinked by
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   271
    // the entry barrier, which acquires the per nmethod lock.
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   272
    nm->unlink_from_method();
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   273
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   274
    if (nm->is_osr_method()) {
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   275
      // Invalidate the osr nmethod before the handshake. The nmethod
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   276
      // will be made unloaded after the handshake. Then invalidate_osr_method()
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   277
      // will be called again, which will be a no-op.
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   278
      nm->invalidate_osr_method();
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   279
    }
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   280
  }
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   281
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   282
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   283
  ZNMethodUnlinkClosure(bool unloading_occurred) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   284
      _unloading_occurred(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   285
      _failed(false) {}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   286
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   287
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   288
    if (failed()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   289
      return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   290
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   291
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   292
    if (!nm->is_alive()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   293
      return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   294
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   295
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   296
    if (nm->is_unloading()) {
58353
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   297
      ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   298
      unlink(nm);
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   299
      return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   300
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   301
58353
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   302
    ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   303
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   304
    // Heal oops and disarm
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   305
    ZNMethodOopClosure cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   306
    ZNMethod::nmethod_oops_do(nm, &cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   307
    ZNMethod::disarm_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   308
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   309
    // Clear compiled ICs and exception caches
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   310
    if (!nm->unload_nmethod_caches(_unloading_occurred)) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   311
      set_failed();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   312
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   313
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   314
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   315
  bool failed() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   316
    return Atomic::load(&_failed);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   317
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   318
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   319
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   320
class ZNMethodUnlinkTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   321
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   322
  ZNMethodUnlinkClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   323
  ICRefillVerifier*     _verifier;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   324
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   325
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   326
  ZNMethodUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   327
      ZTask("ZNMethodUnlinkTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   328
      _cl(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   329
      _verifier(verifier) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   330
    ZNMethodTable::nmethods_do_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   331
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   332
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   333
  ~ZNMethodUnlinkTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   334
    ZNMethodTable::nmethods_do_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   335
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   336
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   337
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   338
    ICRefillVerifierMark mark(_verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   339
    ZNMethodTable::nmethods_do(&_cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   340
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   341
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   342
  bool success() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   343
    return !_cl.failed();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   344
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   345
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   346
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   347
void ZNMethod::unlink(ZWorkers* workers, bool unloading_occurred) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   348
  for (;;) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   349
    ICRefillVerifier verifier;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   350
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   351
    {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   352
      ZNMethodUnlinkTask task(unloading_occurred, &verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   353
      workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   354
      if (task.success()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   355
        return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   356
      }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   357
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   358
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   359
    // Cleaning failed because we ran out of transitional IC stubs,
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   360
    // so we have to refill and try again. Refilling requires taking
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   361
    // a safepoint, so we temporarily leave the suspendible thread set.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   362
    SuspendibleThreadSetLeaver sts;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   363
    InlineCacheBuffer::refill_ic_stubs();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   364
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   365
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   366
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   367
class ZNMethodPurgeClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   368
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   369
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   370
    if (nm->is_alive() && nm->is_unloading()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   371
      nm->make_unloaded();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   372
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   373
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   374
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   375
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   376
class ZNMethodPurgeTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   377
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   378
  ZNMethodPurgeClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   379
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   380
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   381
  ZNMethodPurgeTask() :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   382
      ZTask("ZNMethodPurgeTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   383
      _cl() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   384
    ZNMethodTable::nmethods_do_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   385
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   386
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   387
  ~ZNMethodPurgeTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   388
    ZNMethodTable::nmethods_do_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   389
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   390
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   391
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   392
    ZNMethodTable::nmethods_do(&_cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   393
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   394
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   395
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   396
void ZNMethod::purge(ZWorkers* workers) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   397
  ZNMethodPurgeTask task;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   398
  workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   399
}