src/hotspot/share/gc/shared/scavengableNMethods.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 54786 ebf733a324d4
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     1
/*
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     4
 *
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     8
 *
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    13
 * accompanied this code).
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    14
 *
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    18
 *
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    21
 * questions.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    22
 *
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    23
 */
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    24
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    25
#include "precompiled.hpp"
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    26
#include "code/codeCache.hpp"
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    27
#include "code/nmethod.hpp"
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    28
#include "gc/shared/scavengableNMethods.hpp"
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    29
#include "gc/shared/scavengableNMethodsData.hpp"
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
    30
#include "runtime/mutexLocker.hpp"
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    31
#include "utilities/debug.hpp"
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    32
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    33
static ScavengableNMethodsData gc_data(nmethod* nm) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    34
  return ScavengableNMethodsData(nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    35
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    36
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    37
nmethod* ScavengableNMethods::_head = NULL;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    38
BoolObjectClosure* ScavengableNMethods::_is_scavengable = NULL;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    39
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    40
void ScavengableNMethods::initialize(BoolObjectClosure* is_scavengable) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    41
  _is_scavengable = is_scavengable;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    42
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    43
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    44
// Conditionally adds the nmethod to the list if it is
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    45
// not already on the list and has a scavengeable root.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    46
void ScavengableNMethods::register_nmethod(nmethod* nm) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    47
  assert_locked_or_safepoint(CodeCache_lock);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    48
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    49
  ScavengableNMethodsData data = gc_data(nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    50
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    51
  if (data.on_list() || !has_scavengable_oops(nm)) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    52
    return;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    53
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    54
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    55
  data.set_on_list();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    56
  data.set_next(_head);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    57
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    58
  _head = nm;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    59
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    60
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    61
void ScavengableNMethods::unregister_nmethod(nmethod* nm) {
54177
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    62
  assert_locked_or_safepoint(CodeCache_lock);
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    63
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    64
  if (gc_data(nm).on_list()) {
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    65
    nmethod* prev = NULL;
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    66
    for (nmethod* cur = _head; cur != NULL; cur = gc_data(cur).next()) {
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    67
      if (cur == nm) {
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    68
        unlist_nmethod(cur, prev);
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    69
        return;
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    70
      }
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    71
      prev = cur;
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    72
    }
b4779a44476b 8220606: Move ScavengableNMethods unlinking to unregister_nmethod
stefank
parents: 54122
diff changeset
    73
  }
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    74
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    75
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    76
#ifndef PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    77
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    78
class DebugScavengableOops: public OopClosure {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    79
  BoolObjectClosure* _is_scavengable;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    80
  nmethod*           _nm;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    81
  bool               _ok;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    82
public:
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    83
  DebugScavengableOops(BoolObjectClosure* is_scavengable, nmethod* nm) :
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    84
      _is_scavengable(is_scavengable),
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    85
      _nm(nm),
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    86
      _ok(true) { }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    87
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    88
  bool ok() { return _ok; }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    89
  virtual void do_oop(oop* p) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    90
    if (*p == NULL || !_is_scavengable->do_object_b(*p)) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    91
      return;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    92
    }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    93
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    94
    if (_ok) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    95
      _nm->print_nmethod(true);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    96
      _ok = false;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    97
    }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    98
    tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
    99
                  p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   100
    (*p)->print();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   101
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   102
  virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   103
};
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   104
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   105
#endif // PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   106
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   107
void ScavengableNMethods::verify_nmethod(nmethod* nm) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   108
#ifndef PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   109
  if (!gc_data(nm).on_list()) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   110
    // Actually look inside, to verify the claim that it's clean.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   111
    DebugScavengableOops cl(_is_scavengable, nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   112
    nm->oops_do(&cl);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   113
    if (!cl.ok())
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   114
      fatal("found an unadvertised bad scavengable oop in the code cache");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   115
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   116
  assert(gc_data(nm).not_marked(), "");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   117
#endif // PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   118
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   119
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   120
class HasScavengableOops: public OopClosure {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   121
  BoolObjectClosure* _is_scavengable;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   122
  bool               _found;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   123
public:
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   124
  HasScavengableOops(BoolObjectClosure* is_scavengable, nmethod* nm) :
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   125
      _is_scavengable(is_scavengable),
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   126
      _found(false) {}
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   127
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   128
  bool found() { return _found; }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   129
  virtual void do_oop(oop* p) {
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   130
    if (!_found && *p != NULL && _is_scavengable->do_object_b(*p)) {
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   131
      _found = true;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   132
    }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   133
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   134
  virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   135
};
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   136
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   137
bool ScavengableNMethods::has_scavengable_oops(nmethod* nm) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   138
  HasScavengableOops cl(_is_scavengable, nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   139
  nm->oops_do(&cl);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   140
  return cl.found();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   141
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   142
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   143
// Walk the list of methods which might contain oops to the java heap.
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   144
void ScavengableNMethods::nmethods_do_and_prune(CodeBlobToOopClosure* cl) {
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   145
  assert_locked_or_safepoint(CodeCache_lock);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   146
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   147
  debug_only(mark_on_list_nmethods());
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   148
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   149
  nmethod* prev = NULL;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   150
  nmethod* cur = _head;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   151
  while (cur != NULL) {
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   152
    assert(cur->is_alive(), "Must be");
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   153
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   154
    ScavengableNMethodsData data = gc_data(cur);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   155
    debug_only(data.clear_marked());
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   156
    assert(data.on_list(), "else shouldn't be on this list");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   157
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   158
    if (cl != NULL) {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   159
      cl->do_code_blob(cur);
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   160
    }
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   161
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   162
    nmethod* const next = data.next();
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   163
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   164
    if (!has_scavengable_oops(cur)) {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   165
      unlist_nmethod(cur, prev);
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   166
    } else {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   167
      prev = cur;
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   168
    }
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   169
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   170
    cur = next;
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   171
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   172
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   173
  // Check for stray marks.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   174
  debug_only(verify_unlisted_nmethods(NULL));
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   175
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   176
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   177
void ScavengableNMethods::prune_nmethods() {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   178
  nmethods_do_and_prune(NULL /* No closure */);
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   179
}
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   180
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   181
// Walk the list of methods which might contain oops to the java heap.
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   182
void ScavengableNMethods::nmethods_do(CodeBlobToOopClosure* cl) {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   183
  nmethods_do_and_prune(cl);
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   184
}
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   185
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   186
#ifndef PRODUCT
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   187
void ScavengableNMethods::asserted_non_scavengable_nmethods_do(CodeBlobClosure* cl) {
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   188
  // While we are here, verify the integrity of the list.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   189
  mark_on_list_nmethods();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   190
  for (nmethod* cur = _head; cur != NULL; cur = gc_data(cur).next()) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   191
    assert(gc_data(cur).on_list(), "else shouldn't be on this list");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   192
    gc_data(cur).clear_marked();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   193
  }
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   194
  verify_unlisted_nmethods(cl);
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   195
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   196
#endif // PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   197
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   198
void ScavengableNMethods::unlist_nmethod(nmethod* nm, nmethod* prev) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   199
  assert_locked_or_safepoint(CodeCache_lock);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   200
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   201
  assert((prev == NULL && _head == nm) ||
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   202
         (prev != NULL && gc_data(prev).next() == nm), "precondition");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   203
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   204
  ScavengableNMethodsData data = gc_data(nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   205
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   206
  if (prev == NULL) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   207
    _head = data.next();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   208
  } else {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   209
    gc_data(prev).set_next(data.next());
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   210
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   211
  data.set_next(NULL);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   212
  data.clear_on_list();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   213
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   214
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   215
#ifndef PRODUCT
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   216
// Temporarily mark nmethods that are claimed to be on the scavenge list.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   217
void ScavengableNMethods::mark_on_list_nmethods() {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   218
  NMethodIterator iter(NMethodIterator::only_alive);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   219
  while(iter.next()) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   220
    nmethod* nm = iter.method();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   221
    ScavengableNMethodsData data = gc_data(nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   222
    assert(data.not_marked(), "clean state");
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   223
    if (data.on_list())
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   224
      data.set_marked();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   225
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   226
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   227
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   228
// If the closure is given, run it on the unlisted nmethods.
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   229
// Also make sure that the effects of mark_on_list_nmethods is gone.
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   230
void ScavengableNMethods::verify_unlisted_nmethods(CodeBlobClosure* cl) {
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   231
  NMethodIterator iter(NMethodIterator::only_alive);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   232
  while(iter.next()) {
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   233
    nmethod* nm = iter.method();
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   234
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   235
    verify_nmethod(nm);
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   236
54178
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   237
    if (cl != NULL && !gc_data(nm).on_list()) {
98e21d4da074 8220609: Cleanups in ScavengableNMethods
stefank
parents: 54177
diff changeset
   238
      cl->do_code_blob(nm);
54122
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   239
    }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   240
  }
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   241
}
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   242
4b1426ed1c44 8220343: Move scavenge_root_nmethods from shared code
stefank
parents:
diff changeset
   243
#endif //PRODUCT