src/hotspot/share/gc/z/zNMethod.cpp
author stefank
Thu, 09 May 2019 14:28:30 +0200
changeset 54786 ebf733a324d4
parent 53921 a590b6107ab3
child 55005 9b70ebd131b4
permissions -rw-r--r--
8223624: Cleanup includes of universe.hpp Reviewed-by: coleenp, lkorinth
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
/*
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
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 "runtime/orderAccess.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    45
#include "utilities/debug.hpp"
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    46
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    47
static ZNMethodData* gc_data(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    48
  return nm->gc_data<ZNMethodData>();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    51
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
    52
  return nm->set_gc_data<ZNMethodData>(data);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    55
void ZNMethod::attach_gc_data(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    56
  GrowableArray<oop*> immediate_oops;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    57
  bool non_immediate_oops = false;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    58
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    59
  // Find all oops relocations
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    60
  RelocIterator iter(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    61
  while (iter.next()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    62
    if (iter.type() != relocInfo::oop_type) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    63
      // Not an oop
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    64
      continue;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    67
    oop_Relocation* r = iter.oop_reloc();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    68
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    69
    if (!r->oop_is_immediate()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    70
      // Non-immediate oop found
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    71
      non_immediate_oops = true;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    72
      continue;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    75
    if (r->oop_value() != NULL) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    76
      // 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
    77
      // 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
    78
      // are later patched to be non-NULL.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    79
      immediate_oops.push(r->oop_addr());
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    83
  // Attach GC data to nmethod
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    84
  ZNMethodData* data = gc_data(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    85
  if (data == NULL) {
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
    86
    data = new ZNMethodData();
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    87
    set_gc_data(nm, data);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    90
  // Attach oops in GC data
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    91
  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
    92
  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
    93
  ZNMethodDataOops::destroy(old_oops);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
    96
ZReentrantLock* ZNMethod::lock_for_nmethod(nmethod* nm) {
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
    97
  return gc_data(nm)->lock();
53894
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   100
void ZNMethod::log_register(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   101
  LogTarget(Trace, gc, nmethod) log;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   102
  if (!log.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   103
    return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   106
  const ZNMethodDataOops* const oops = gc_data(nm)->oops();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   107
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   108
  log.print("Register NMethod: %s.%s (" PTR_FORMAT "), "
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   109
            "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
   110
            nm->method()->method_holder()->external_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   111
            nm->method()->name()->as_C_string(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   112
            p2i(nm),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   113
            nm->compiler_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   114
            nm->oops_count() - 1,
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   115
            oops->immediates_count(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   116
            oops->has_non_immediates() ? "Yes" : "No");
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   117
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   118
  LogTarget(Trace, gc, nmethod, oops) log_oops;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   119
  if (!log_oops.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   120
    return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   123
  // Print nmethod oops table
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   124
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   125
    oop* const begin = nm->oops_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   126
    oop* const end = nm->oops_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   127
    for (oop* p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   128
      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
   129
                     (p - begin), p2i(*p), (*p)->klass()->external_name());
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   133
  // Print nmethod immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   134
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   135
    oop** const begin = oops->immediates_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   136
    oop** const end = oops->immediates_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   137
    for (oop** p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   138
      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
   139
                     (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
   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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   144
void ZNMethod::log_unregister(const nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   145
  LogTarget(Debug, gc, nmethod) log;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   146
  if (!log.is_enabled()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   147
    return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   150
  log.print("Unregister NMethod: %s.%s (" PTR_FORMAT ")",
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   151
            nm->method()->method_holder()->external_name(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   152
            nm->method()->name()->as_C_string(),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   153
            p2i(nm));
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   156
void ZNMethod::register_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   157
  ResourceMark rm;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   158
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   159
  // Create and attach gc data
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   160
  attach_gc_data(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   161
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   162
  log_register(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   163
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   164
  ZNMethodTable::register_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   165
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   166
  // Disarm nmethod entry barrier
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   167
  disarm_nmethod(nm);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   170
void ZNMethod::unregister_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   171
  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
   172
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   173
  if (Thread::current()->is_Code_cache_sweeper_thread()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   174
    // 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
   175
    // before it can unregister an nmethod.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   176
    ZNMethodTable::wait_until_iteration_done();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   179
  ResourceMark rm;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   180
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   181
  log_unregister(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   182
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   183
  ZNMethodTable::unregister_nmethod(nm);
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   184
}
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   185
53921
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   186
void ZNMethod::flush_nmethod(nmethod* nm) {
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   187
  // Destroy GC data
a590b6107ab3 8218974: Free GC native structures in nmethod::flush
eosterlund
parents: 53894
diff changeset
   188
  delete gc_data(nm);
53894
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   191
void ZNMethod::disarm_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   192
  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
   193
  if (bs != NULL) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   194
    bs->disarm(nm);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   198
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
   199
  // Process oops table
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   200
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   201
    oop* const begin = nm->oops_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   202
    oop* const end = nm->oops_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   203
    for (oop* p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   204
      if (*p != Universe::non_oop_word()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   205
        cl->do_oop(p);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   210
  ZNMethodDataOops* const oops = gc_data(nm)->oops();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   211
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   212
  // Process immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   213
  {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   214
    oop** const begin = oops->immediates_begin();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   215
    oop** const end = oops->immediates_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   216
    for (oop** p = begin; p < end; p++) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   217
      if (**p != Universe::non_oop_word()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   218
        cl->do_oop(*p);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   223
  // Process non-immediate oops
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   224
  if (oops->has_non_immediates()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   225
    nm->fix_oop_relocations();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   229
class ZNMethodToOopsDoClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   230
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   231
  OopClosure* _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   232
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   233
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   234
  ZNMethodToOopsDoClosure(OopClosure* cl) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   235
      _cl(cl) {}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   236
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   237
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   238
    ZNMethod::nmethod_oops_do(nm, _cl);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   242
void ZNMethod::oops_do_begin() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   243
  ZNMethodTable::nmethods_do_begin();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   246
void ZNMethod::oops_do_end() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   247
  ZNMethodTable::nmethods_do_end();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   250
void ZNMethod::oops_do(OopClosure* cl) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   251
  ZNMethodToOopsDoClosure nmethod_cl(cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   252
  ZNMethodTable::nmethods_do(&nmethod_cl);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   255
class ZNMethodUnlinkClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   256
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   257
  bool          _unloading_occurred;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   258
  volatile bool _failed;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   259
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   260
  void set_failed() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   261
    Atomic::store(true, &_failed);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   262
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   263
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   264
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   265
  ZNMethodUnlinkClosure(bool unloading_occurred) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   266
      _unloading_occurred(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   267
      _failed(false) {}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   268
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   269
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   270
    if (failed()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   271
      return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   272
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   273
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   274
    if (!nm->is_alive()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   275
      return;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   276
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   277
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   278
    ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   279
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   280
    if (nm->is_unloading()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   281
      // Unlinking of the dependencies must happen before the
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   282
      // handshake separating unlink and purge.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   283
      nm->flush_dependencies(false /* delete_immediately */);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   284
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   285
      // We don't need to take the lock when unlinking nmethods from
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   286
      // the Method, because it is only concurrently unlinked by
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   287
      // the entry barrier, which acquires the per nmethod lock.
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   288
      nm->unlink_from_method(false /* acquire_lock */);
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
    // Heal oops and disarm
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   293
    ZNMethodOopClosure cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   294
    ZNMethod::nmethod_oops_do(nm, &cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   295
    ZNMethod::disarm_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   296
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   297
    // Clear compiled ICs and exception caches
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   298
    if (!nm->unload_nmethod_caches(_unloading_occurred)) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   299
      set_failed();
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
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   302
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   303
  bool failed() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   304
    return Atomic::load(&_failed);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   305
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   306
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   307
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   308
class ZNMethodUnlinkTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   309
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   310
  ZNMethodUnlinkClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   311
  ICRefillVerifier*     _verifier;
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
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   314
  ZNMethodUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   315
      ZTask("ZNMethodUnlinkTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   316
      _cl(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   317
      _verifier(verifier) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   318
    ZNMethodTable::nmethods_do_begin();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   321
  ~ZNMethodUnlinkTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   322
    ZNMethodTable::nmethods_do_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   323
  }
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
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   326
    ICRefillVerifierMark mark(_verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   327
    ZNMethodTable::nmethods_do(&_cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   328
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   329
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   330
  bool success() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   331
    return !_cl.failed();
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
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   334
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   335
void ZNMethod::unlink(ZWorkers* workers, bool unloading_occurred) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   336
  for (;;) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   337
    ICRefillVerifier verifier;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   338
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   339
    {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   340
      ZNMethodUnlinkTask task(unloading_occurred, &verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   341
      workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   342
      if (task.success()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   343
        return;
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
    // 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
   348
    // 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
   349
    // 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
   350
    SuspendibleThreadSetLeaver sts;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   351
    InlineCacheBuffer::refill_ic_stubs();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   352
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   353
}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   354
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   355
class ZNMethodPurgeClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   356
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   357
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   358
    if (nm->is_alive() && nm->is_unloading()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   359
      nm->make_unloaded();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   360
    }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   361
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   362
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   363
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   364
class ZNMethodPurgeTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   365
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   366
  ZNMethodPurgeClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   367
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
  ZNMethodPurgeTask() :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   370
      ZTask("ZNMethodPurgeTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   371
      _cl() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   372
    ZNMethodTable::nmethods_do_begin();
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
  ~ZNMethodPurgeTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   376
    ZNMethodTable::nmethods_do_end();
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   377
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   378
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   379
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   380
    ZNMethodTable::nmethods_do(&_cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   381
  }
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   382
};
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   383
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   384
void ZNMethod::purge(ZWorkers* workers) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   385
  ZNMethodPurgeTask task;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   386
  workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   387
}