src/hotspot/share/gc/z/zNMethod.cpp
author stefank
Mon, 25 Nov 2019 12:30:24 +0100
changeset 59248 e92153ed8bdc
parent 58353 146bb7afdcf4
child 59290 97d13893ec3c
permissions -rw-r--r--
8234736: Harmonize parameter order in Atomic - store Reviewed-by: rehn, 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 "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() {
59248
e92153ed8bdc 8234736: Harmonize parameter order in Atomic - store
stefank
parents: 58353
diff changeset
   261
    Atomic::store(&_failed, true);
53894
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
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   264
  void unlink(nmethod* nm) {
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   265
    // Unlinking of the dependencies must happen before the
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   266
    // handshake separating unlink and purge.
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   267
    nm->flush_dependencies(false /* delete_immediately */);
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   268
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   269
    // unlink_from_method will take the CompiledMethod_lock.
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   270
    // 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
   271
    // the Method, because it is only concurrently unlinked by
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   272
    // the entry barrier, which acquires the per nmethod lock.
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 57490
diff changeset
   273
    nm->unlink_from_method();
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   274
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   275
    if (nm->is_osr_method()) {
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   276
      // Invalidate the osr nmethod before the handshake. The nmethod
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   277
      // will be made unloaded after the handshake. Then invalidate_osr_method()
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   278
      // will be called again, which will be a no-op.
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   279
      nm->invalidate_osr_method();
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
  }
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   282
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   283
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   284
  ZNMethodUnlinkClosure(bool unloading_occurred) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   285
      _unloading_occurred(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   286
      _failed(false) {}
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   287
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   288
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   289
    if (failed()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   290
      return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   293
    if (!nm->is_alive()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   294
      return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   297
    if (nm->is_unloading()) {
58353
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   298
      ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
57490
7826a2a06f87 8224674: NMethod state machine is not monotonic
eosterlund
parents: 55479
diff changeset
   299
      unlink(nm);
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   300
      return;
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
58353
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   303
    ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
146bb7afdcf4 8219724: ZGC: Make inline cache cleaning more robust
eosterlund
parents: 58226
diff changeset
   304
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   305
    // Heal oops and disarm
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   306
    ZNMethodOopClosure cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   307
    ZNMethod::nmethod_oops_do(nm, &cl);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   308
    ZNMethod::disarm_nmethod(nm);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   309
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   310
    // Clear compiled ICs and exception caches
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   311
    if (!nm->unload_nmethod_caches(_unloading_occurred)) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   312
      set_failed();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   316
  bool failed() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   317
    return Atomic::load(&_failed);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   321
class ZNMethodUnlinkTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   322
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   323
  ZNMethodUnlinkClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   324
  ICRefillVerifier*     _verifier;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   325
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   326
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   327
  ZNMethodUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   328
      ZTask("ZNMethodUnlinkTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   329
      _cl(unloading_occurred),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   330
      _verifier(verifier) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   331
    ZNMethodTable::nmethods_do_begin();
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
  ~ZNMethodUnlinkTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   335
    ZNMethodTable::nmethods_do_end();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   338
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   339
    ICRefillVerifierMark mark(_verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   340
    ZNMethodTable::nmethods_do(&_cl);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   343
  bool success() const {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   344
    return !_cl.failed();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   348
void ZNMethod::unlink(ZWorkers* workers, bool unloading_occurred) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   349
  for (;;) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   350
    ICRefillVerifier verifier;
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
    {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   353
      ZNMethodUnlinkTask task(unloading_occurred, &verifier);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   354
      workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   355
      if (task.success()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   356
        return;
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   360
    // 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
   361
    // 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
   362
    // 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
   363
    SuspendibleThreadSetLeaver sts;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   364
    InlineCacheBuffer::refill_ic_stubs();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   368
class ZNMethodPurgeClosure : public NMethodClosure {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   369
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   370
  virtual void do_nmethod(nmethod* nm) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   371
    if (nm->is_alive() && nm->is_unloading()) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   372
      nm->make_unloaded();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   377
class ZNMethodPurgeTask : public ZTask {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   378
private:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   379
  ZNMethodPurgeClosure _cl;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   380
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   381
public:
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   382
  ZNMethodPurgeTask() :
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   383
      ZTask("ZNMethodPurgeTask"),
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   384
      _cl() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   385
    ZNMethodTable::nmethods_do_begin();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   388
  ~ZNMethodPurgeTask() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   389
    ZNMethodTable::nmethods_do_end();
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   392
  virtual void work() {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   393
    ZNMethodTable::nmethods_do(&_cl);
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
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   397
void ZNMethod::purge(ZWorkers* workers) {
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   398
  ZNMethodPurgeTask task;
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   399
  workers->run_concurrent(&task);
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
diff changeset
   400
}