src/hotspot/share/code/compiledMethod.cpp
author eosterlund
Tue, 14 May 2019 12:07:24 +0200
changeset 54839 e9db10a375d9
parent 54150 5529640c5f67
child 55293 d19dc5b10fbb
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8222841: Incorrect static call stub interactions with class unloading Reviewed-by: kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     1
/*
54150
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     4
 *
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     8
 *
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    13
 * accompanied this code).
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    14
 *
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    18
 *
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    21
 * questions.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    22
 *
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    23
 */
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    24
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    25
#include "precompiled.hpp"
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    26
#include "code/compiledIC.hpp"
46623
261b9d05b79d 8183299: Improve inlining of CompiledMethod methods into frame::sender
redestad
parents: 42650
diff changeset
    27
#include "code/compiledMethod.inline.hpp"
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    28
#include "code/scopeDesc.hpp"
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    29
#include "code/codeCache.hpp"
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
    30
#include "code/icBuffer.hpp"
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    31
#include "gc/shared/barrierSet.hpp"
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    32
#include "gc/shared/gcBehaviours.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48955
diff changeset
    33
#include "interpreter/bytecode.inline.hpp"
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
    34
#include "logging/log.hpp"
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
    35
#include "logging/logTag.hpp"
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    36
#include "memory/resourceArea.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    37
#include "oops/methodData.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48955
diff changeset
    38
#include "oops/method.inline.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    39
#include "prims/methodHandles.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49340
diff changeset
    40
#include "runtime/handles.inline.hpp"
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    41
#include "runtime/mutexLocker.hpp"
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    42
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    43
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout,
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    44
                               int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps,
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    45
                               bool caller_must_gc_arguments)
42040
70ec5a09a0d5 8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents: 39430
diff changeset
    46
  : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    47
    _mark_for_deoptimization_status(not_marked),
52660
9cb53c505acd 8214056: Allow the GC to attach context information to CompiledMethod
eosterlund
parents: 52659
diff changeset
    48
    _method(method),
9cb53c505acd 8214056: Allow the GC to attach context information to CompiledMethod
eosterlund
parents: 52659
diff changeset
    49
    _gc_data(NULL)
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    50
{
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    51
  init_defaults();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    52
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    53
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    54
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size,
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    55
                               int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size,
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    56
                               OopMapSet* oop_maps, bool caller_must_gc_arguments)
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    57
  : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb,
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    58
             frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    59
    _mark_for_deoptimization_status(not_marked),
52660
9cb53c505acd 8214056: Allow the GC to attach context information to CompiledMethod
eosterlund
parents: 52659
diff changeset
    60
    _method(method),
9cb53c505acd 8214056: Allow the GC to attach context information to CompiledMethod
eosterlund
parents: 52659
diff changeset
    61
    _gc_data(NULL)
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
    62
{
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    63
  init_defaults();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    64
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    65
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    66
void CompiledMethod::init_defaults() {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    67
  _has_unsafe_access          = 0;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    68
  _has_method_handle_invokes  = 0;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    69
  _lazy_critical_native       = 0;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    70
  _has_wide_vectors           = 0;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    71
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    72
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    73
bool CompiledMethod::is_method_handle_return(address return_pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    74
  if (!has_method_handle_invokes())  return false;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    75
  PcDesc* pd = pc_desc_at(return_pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    76
  if (pd == NULL)
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    77
    return false;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    78
  return pd->is_method_handle_invoke();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    79
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    80
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    81
// Returns a string version of the method state.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    82
const char* CompiledMethod::state() const {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    83
  int state = get_state();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    84
  switch (state) {
48007
ab3959df2115 8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents: 47687
diff changeset
    85
  case not_installed:
ab3959df2115 8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents: 47687
diff changeset
    86
    return "not installed";
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    87
  case in_use:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    88
    return "in use";
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    89
  case not_used:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    90
    return "not_used";
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    91
  case not_entrant:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    92
    return "not_entrant";
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    93
  case zombie:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    94
    return "zombie";
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    95
  case unloaded:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    96
    return "unloaded";
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    97
  default:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    98
    fatal("unexpected method state: %d", state);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
    99
    return NULL;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   100
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   101
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   102
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   103
//-----------------------------------------------------------------------------
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   104
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   105
ExceptionCache* CompiledMethod::exception_cache_acquire() const {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   106
  return OrderAccess::load_acquire(&_exception_cache);
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   107
}
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   108
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   109
void CompiledMethod::add_exception_cache_entry(ExceptionCache* new_entry) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   110
  assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   111
  assert(new_entry != NULL,"Must be non null");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   112
  assert(new_entry->next() == NULL, "Must be null");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   113
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   114
  for (;;) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   115
    ExceptionCache *ec = exception_cache();
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   116
    if (ec != NULL) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   117
      Klass* ex_klass = ec->exception_type();
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   118
      if (!ex_klass->is_loader_alive()) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   119
        // We must guarantee that entries are not inserted with new next pointer
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   120
        // edges to ExceptionCache entries with dead klasses, due to bad interactions
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   121
        // with concurrent ExceptionCache cleanup. Therefore, the inserts roll
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   122
        // the head pointer forward to the first live ExceptionCache, so that the new
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   123
        // next pointers always point at live ExceptionCaches, that are not removed due
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   124
        // to concurrent ExceptionCache cleanup.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   125
        ExceptionCache* next = ec->next();
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   126
        if (Atomic::cmpxchg(next, &_exception_cache, ec) == ec) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   127
          CodeCache::release_exception_cache(ec);
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   128
        }
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   129
        continue;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   130
      }
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   131
      ec = exception_cache();
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   132
      if (ec != NULL) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   133
        new_entry->set_next(ec);
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   134
      }
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   135
    }
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   136
    if (Atomic::cmpxchg(new_entry, &_exception_cache, ec) == ec) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   137
      return;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   138
    }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   139
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   140
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   141
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 49480
diff changeset
   142
void CompiledMethod::clean_exception_cache() {
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   143
  // For each nmethod, only a single thread may call this cleanup function
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   144
  // at the same time, whether called in STW cleanup or concurrent cleanup.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   145
  // Note that if the GC is processing exception cache cleaning in a concurrent phase,
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   146
  // then a single writer may contend with cleaning up the head pointer to the
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   147
  // first ExceptionCache node that has a Klass* that is alive. That is fine,
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   148
  // as long as there is no concurrent cleanup of next pointers from concurrent writers.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   149
  // And the concurrent writers do not clean up next pointers, only the head.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   150
  // Also note that concurent readers will walk through Klass* pointers that are not
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   151
  // alive. That does not cause ABA problems, because Klass* is deleted after
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   152
  // a handshake with all threads, after all stale ExceptionCaches have been
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   153
  // unlinked. That is also when the CodeCache::exception_cache_purge_list()
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   154
  // is deleted, with all ExceptionCache entries that were cleaned concurrently.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   155
  // That similarly implies that CAS operations on ExceptionCache entries do not
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   156
  // suffer from ABA problems as unlinking and deletion is separated by a global
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   157
  // handshake operation.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   158
  ExceptionCache* prev = NULL;
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   159
  ExceptionCache* curr = exception_cache_acquire();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   160
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   161
  while (curr != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   162
    ExceptionCache* next = curr->next();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   163
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   164
    if (!curr->exception_type()->is_loader_alive()) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   165
      if (prev == NULL) {
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   166
        // Try to clean head; this is contended by concurrent inserts, that
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   167
        // both lazily clean the head, and insert entries at the head. If
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   168
        // the CAS fails, the operation is restarted.
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   169
        if (Atomic::cmpxchg(next, &_exception_cache, curr) != curr) {
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   170
          prev = NULL;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   171
          curr = exception_cache_acquire();
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   172
          continue;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   173
        }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   174
      } else {
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   175
        // It is impossible to during cleanup connect the next pointer to
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   176
        // an ExceptionCache that has not been published before a safepoint
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   177
        // prior to the cleanup. Therefore, release is not required.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   178
        prev->set_next(next);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   179
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   180
      // prev stays the same.
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   181
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   182
      CodeCache::release_exception_cache(curr);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   183
    } else {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   184
      prev = curr;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   185
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   186
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   187
    curr = next;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   188
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   189
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   190
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   191
// public method for accessing the exception cache
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   192
// These are the public access methods.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   193
address CompiledMethod::handler_for_exception_and_pc(Handle exception, address pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   194
  // We never grab a lock to read the exception cache, so we may
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   195
  // have false negatives. This is okay, as it can only happen during
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   196
  // the first few exception lookups for a given nmethod.
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   197
  ExceptionCache* ec = exception_cache_acquire();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   198
  while (ec != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   199
    address ret_val;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   200
    if ((ret_val = ec->match(exception,pc)) != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   201
      return ret_val;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   202
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   203
    ec = ec->next();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   204
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   205
  return NULL;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   206
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   207
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   208
void CompiledMethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   209
  // There are potential race conditions during exception cache updates, so we
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   210
  // must own the ExceptionCache_lock before doing ANY modifications. Because
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   211
  // we don't lock during reads, it is possible to have several threads attempt
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   212
  // to update the cache with the same data. We need to check for already inserted
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   213
  // copies of the current data before adding it.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   214
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   215
  MutexLocker ml(ExceptionCache_lock);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   216
  ExceptionCache* target_entry = exception_cache_entry_for_exception(exception);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   217
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   218
  if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   219
    target_entry = new ExceptionCache(exception,pc,handler);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   220
    add_exception_cache_entry(target_entry);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   221
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   222
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   223
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   224
// private method for handling exception cache
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   225
// These methods are private, and used to manipulate the exception cache
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   226
// directly.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   227
ExceptionCache* CompiledMethod::exception_cache_entry_for_exception(Handle exception) {
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   228
  ExceptionCache* ec = exception_cache_acquire();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   229
  while (ec != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   230
    if (ec->match_exception_with_space(exception)) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   231
      return ec;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   232
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   233
    ec = ec->next();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   234
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   235
  return NULL;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   236
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   237
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   238
//-------------end of code for ExceptionCache--------------
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   239
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   240
bool CompiledMethod::is_at_poll_return(address pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   241
  RelocIterator iter(this, pc, pc+1);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   242
  while (iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   243
    if (iter.type() == relocInfo::poll_return_type)
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   244
      return true;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   245
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   246
  return false;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   247
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   248
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   249
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   250
bool CompiledMethod::is_at_poll_or_poll_return(address pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   251
  RelocIterator iter(this, pc, pc+1);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   252
  while (iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   253
    relocInfo::relocType t = iter.type();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   254
    if (t == relocInfo::poll_return_type || t == relocInfo::poll_type)
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   255
      return true;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   256
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   257
  return false;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   258
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   259
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   260
void CompiledMethod::verify_oop_relocations() {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   261
  // Ensure sure that the code matches the current oop values
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   262
  RelocIterator iter(this, NULL, NULL);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   263
  while (iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   264
    if (iter.type() == relocInfo::oop_type) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   265
      oop_Relocation* reloc = iter.oop_reloc();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   266
      if (!reloc->oop_is_immediate()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   267
        reloc->verify_oop_relocation();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   268
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   269
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   270
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   271
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   272
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   273
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   274
ScopeDesc* CompiledMethod::scope_desc_at(address pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   275
  PcDesc* pd = pc_desc_at(pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   276
  guarantee(pd != NULL, "scope must be present");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   277
  return new ScopeDesc(this, pd->scope_decode_offset(),
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   278
                       pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   279
                       pd->return_oop());
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   280
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   281
46796
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   282
ScopeDesc* CompiledMethod::scope_desc_near(address pc) {
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   283
  PcDesc* pd = pc_desc_near(pc);
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   284
  guarantee(pd != NULL, "scope must be present");
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   285
  return new ScopeDesc(this, pd->scope_decode_offset(),
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   286
                       pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   287
                       pd->return_oop());
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   288
}
ec791efbdecf 8172791: Issues with JEP 270 (ReservedStackArea)
fparain
parents: 46630
diff changeset
   289
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   290
address CompiledMethod::oops_reloc_begin() const {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   291
  // If the method is not entrant or zombie then a JMP is plastered over the
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   292
  // first few bytes.  If an oop in the old code was there, that oop
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   293
  // should not get GC'd.  Skip the first few bytes of oops on
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   294
  // not-entrant methods.
52410
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   295
  if (frame_complete_offset() != CodeOffsets::frame_never_safe &&
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   296
      code_begin() + frame_complete_offset() >
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   297
      verified_entry_point() + NativeJump::instruction_size)
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   298
  {
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   299
    // If we have a frame_complete_offset after the native jump, then there
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   300
    // is no point trying to look for oops before that. This is a requirement
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   301
    // for being allowed to scan oops concurrently.
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   302
    return code_begin() + frame_complete_offset();
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   303
  }
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   304
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   305
  // It is not safe to read oops concurrently using entry barriers, if their
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   306
  // location depend on whether the nmethod is entrant or not.
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   307
  assert(BarrierSet::barrier_set()->barrier_set_nmethod() == NULL, "Not safe oop scan");
9d3abb1b7b1f 8212585: Clean up CompiledMethod::oops_reloc_begin()
eosterlund
parents: 52405
diff changeset
   308
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   309
  address low_boundary = verified_entry_point();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   310
  if (!is_in_use() && is_nmethod()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   311
    low_boundary += NativeJump::instruction_size;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   312
    // %%% Note:  On SPARC we patch only a 4-byte trap, not a full NativeJump.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   313
    // This means that the low_boundary is going to be a little too high.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   314
    // This shouldn't matter, since oops of non-entrant methods are never used.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   315
    // In fact, why are we bothering to look at oops in a non-entrant method??
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   316
  }
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   317
  return low_boundary;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   318
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   319
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   320
int CompiledMethod::verify_icholder_relocations() {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   321
  ResourceMark rm;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   322
  int count = 0;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   323
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   324
  RelocIterator iter(this);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   325
  while(iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   326
    if (iter.type() == relocInfo::virtual_call_type) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42040
diff changeset
   327
      if (CompiledIC::is_icholder_call_site(iter.virtual_call_reloc(), this)) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   328
        CompiledIC *ic = CompiledIC_at(&iter);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   329
        if (TraceCompiledIC) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   330
          tty->print("noticed icholder " INTPTR_FORMAT " ", p2i(ic->cached_icholder()));
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   331
          ic->print();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   332
        }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   333
        assert(ic->cached_icholder() != NULL, "must be non-NULL");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   334
        count++;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   335
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   336
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   337
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   338
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   339
  return count;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   340
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   341
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   342
// Method that knows how to preserve outgoing arguments at call. This method must be
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   343
// called with a frame corresponding to a Java invoke
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   344
void CompiledMethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   345
  if (method() != NULL && !method()->is_native()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   346
    address pc = fr.pc();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   347
    SimpleScopeDesc ssd(this, pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   348
    Bytecode_invoke call(ssd.method(), ssd.bci());
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   349
    bool has_receiver = call.has_receiver();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   350
    bool has_appendix = call.has_appendix();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   351
    Symbol* signature = call.signature();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   352
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   353
    // The method attached by JIT-compilers should be used, if present.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   354
    // Bytecode can be inaccurate in such case.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   355
    Method* callee = attached_method_before_pc(pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   356
    if (callee != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   357
      has_receiver = !(callee->access_flags().is_static());
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   358
      has_appendix = false;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   359
      signature = callee->signature();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   360
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   361
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   362
    fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   363
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   364
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   365
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   366
Method* CompiledMethod::attached_method(address call_instr) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   367
  assert(code_contains(call_instr), "not part of the nmethod");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   368
  RelocIterator iter(this, call_instr, call_instr + 1);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   369
  while (iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   370
    if (iter.addr() == call_instr) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   371
      switch(iter.type()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   372
        case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   373
        case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   374
        case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46623
diff changeset
   375
        default:                               break;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   376
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   377
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   378
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   379
  return NULL; // not found
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   380
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   381
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   382
Method* CompiledMethod::attached_method_before_pc(address pc) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   383
  if (NativeCall::is_call_before(pc)) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   384
    NativeCall* ncall = nativeCall_before(pc);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   385
    return attached_method(ncall->instruction_address());
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   386
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   387
  return NULL; // not a call
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   388
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   389
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   390
void CompiledMethod::clear_inline_caches() {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   391
  assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint");
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   392
  if (is_zombie()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   393
    return;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   394
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   395
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   396
  RelocIterator iter(this);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   397
  while (iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   398
    iter.reloc()->clear_inline_cache();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   399
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   400
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   401
53651
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 52896
diff changeset
   402
// Clear IC callsites, releasing ICStubs of all compiled ICs
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 52896
diff changeset
   403
// as well as any associated CompiledICHolders.
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 52896
diff changeset
   404
void CompiledMethod::clear_ic_callsites() {
52384
d6dc479bcdd3 8212681: Refactor IC locking to use a fine grained CompiledICLocker
eosterlund
parents: 51591
diff changeset
   405
  assert(CompiledICLocker::is_safe(this), "mt unsafe call");
50995
3c59afe1afc9 8206394: missing ResourceMark in AOTCompiledMethod::metadata_do, AOTCompiledMethod::clear_inline_caches , CompiledMethod::clear_ic_stubs , CompiledMethod::cleanup_inline_caches_impl
mbaesken
parents: 50416
diff changeset
   406
  ResourceMark rm;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   407
  RelocIterator iter(this);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   408
  while(iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   409
    if (iter.type() == relocInfo::virtual_call_type) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   410
      CompiledIC* ic = CompiledIC_at(&iter);
53651
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 52896
diff changeset
   411
      ic->set_to_clean(false);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   412
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   413
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   414
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   415
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   416
#ifdef ASSERT
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 49480
diff changeset
   417
// Check class_loader is alive for this bit of metadata.
54150
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   418
class CheckClass : public MetadataClosure {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   419
  void do_metadata(Metadata* md) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   420
    Klass* klass = NULL;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   421
    if (md->is_klass()) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   422
      klass = ((Klass*)md);
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   423
    } else if (md->is_method()) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   424
      klass = ((Method*)md)->method_holder();
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   425
    } else if (md->is_methodData()) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   426
      klass = ((MethodData*)md)->method()->method_holder();
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   427
    } else {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   428
      md->print();
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   429
      ShouldNotReachHere();
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   430
    }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   431
    assert(klass->is_loader_alive(), "must be alive");
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   432
  }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   433
};
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   434
#endif // ASSERT
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   435
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42040
diff changeset
   436
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   437
bool CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   438
  if (ic->is_clean()) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   439
    return true;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   440
  }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   441
  if (ic->is_icholder_call()) {
49969
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   442
    // The only exception is compiledICHolder metdata which may
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   443
    // yet be marked below. (We check this further below).
49969
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   444
    CompiledICHolder* cichk_metdata = ic->cached_icholder();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   445
49969
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   446
    if (cichk_metdata->is_loader_alive()) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   447
      return true;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   448
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   449
  } else {
49969
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   450
    Metadata* ic_metdata = ic->cached_metadata();
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   451
    if (ic_metdata != NULL) {
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   452
      if (ic_metdata->is_klass()) {
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   453
        if (((Klass*)ic_metdata)->is_loader_alive()) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   454
          return true;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   455
        }
49969
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   456
      } else if (ic_metdata->is_method()) {
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   457
        Method* method = (Method*)ic_metdata;
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   458
        assert(!method->is_old(), "old method should have been cleaned");
8624981f1ffa 8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents: 49890
diff changeset
   459
        if (method->method_holder()->is_loader_alive()) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   460
          return true;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   461
        }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   462
      } else {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   463
        ShouldNotReachHere();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   464
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   465
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   466
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   467
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   468
  return ic->set_to_clean();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   469
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   470
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   471
// Clean references to unloaded nmethods at addr from this one, which is not unloaded.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   472
template <class CompiledICorStaticCall>
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   473
static bool clean_if_nmethod_is_unloaded(CompiledICorStaticCall *ic, address addr, CompiledMethod* from,
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   474
                                         bool clean_all) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   475
  // Ok, to lookup references to zombies here
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   476
  CodeBlob *cb = CodeCache::find_blob_unsafe(addr);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   477
  CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   478
  if (nm != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   479
    // Clean inline caches pointing to both zombie and not_entrant methods
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   480
    if (clean_all || !nm->is_in_use() || nm->is_unloading() || (nm->method()->code() != nm)) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   481
      if (!ic->set_to_clean(from->is_alive())) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   482
        return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   483
      }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   484
      assert(ic->is_clean(), "nmethod " PTR_FORMAT "not clean %s", p2i(from), from->method()->name_and_sig_as_C_string());
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   485
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   486
  }
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   487
  return true;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   488
}
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   489
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   490
static bool clean_if_nmethod_is_unloaded(CompiledIC *ic, CompiledMethod* from,
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   491
                                         bool clean_all) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   492
  return clean_if_nmethod_is_unloaded(ic, ic->ic_destination(), from, clean_all);
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   493
}
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   494
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   495
static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, CompiledMethod* from,
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   496
                                         bool clean_all) {
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   497
  return clean_if_nmethod_is_unloaded(csc, csc->destination(), from, clean_all);
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   498
}
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   499
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   500
// Cleans caches in nmethods that point to either classes that are unloaded
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   501
// or nmethods that are unloaded.
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   502
//
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   503
// Can be called either in parallel by G1 currently or after all
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   504
// nmethods are unloaded.  Return postponed=true in the parallel case for
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   505
// inline caches found that point to nmethods that are not yet visited during
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   506
// the do_unloading walk.
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   507
bool CompiledMethod::unload_nmethod_caches(bool unloading_occurred) {
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   508
  ResourceMark rm;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   509
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   510
  // Exception cache only needs to be called if unloading occurred
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   511
  if (unloading_occurred) {
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   512
    clean_exception_cache();
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   513
  }
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   514
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   515
  if (!cleanup_inline_caches_impl(unloading_occurred, false)) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   516
    return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   517
  }
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   518
54150
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   519
#ifdef ASSERT
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   520
  // Check that the metadata embedded in the nmethod is alive
54150
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   521
  CheckClass check_class;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   522
  metadata_do(&check_class);
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   523
#endif
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   524
  return true;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   525
}
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   526
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   527
void CompiledMethod::cleanup_inline_caches(bool clean_all) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   528
  for (;;) {
52896
98408c7c0b73 8214936: assert(_needs_refill == 0) failed: Forgot to handle a failed IC transition requiring IC stubs
eosterlund
parents: 52857
diff changeset
   529
    ICRefillVerifier ic_refill_verifier;
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   530
    { CompiledICLocker ic_locker(this);
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   531
      if (cleanup_inline_caches_impl(false, clean_all)) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   532
        return;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   533
      }
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   534
    }
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   535
    InlineCacheBuffer::refill_ic_stubs();
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   536
  }
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   537
}
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   538
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   539
// Called to clean up after class unloading for live nmethods and from the sweeper
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   540
// for all methods.
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   541
bool CompiledMethod::cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all) {
52384
d6dc479bcdd3 8212681: Refactor IC locking to use a fine grained CompiledICLocker
eosterlund
parents: 51591
diff changeset
   542
  assert(CompiledICLocker::is_safe(this), "mt unsafe call");
50995
3c59afe1afc9 8206394: missing ResourceMark in AOTCompiledMethod::metadata_do, AOTCompiledMethod::clear_inline_caches , CompiledMethod::clear_ic_stubs , CompiledMethod::cleanup_inline_caches_impl
mbaesken
parents: 50416
diff changeset
   543
  ResourceMark rm;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   544
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   545
  // Find all calls in an nmethod and clear the ones that point to non-entrant,
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   546
  // zombie and unloaded nmethods.
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   547
  RelocIterator iter(this, oops_reloc_begin());
54839
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   548
  bool is_in_static_stub = false;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   549
  while(iter.next()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   550
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   551
    switch (iter.type()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   552
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   553
    case relocInfo::virtual_call_type:
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   554
      if (unloading_occurred) {
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   555
        // If class unloading occurred we first clear ICs where the cached metadata
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49969
diff changeset
   556
        // is referring to an unloaded klass or method.
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   557
        if (!clean_ic_if_metadata_is_dead(CompiledIC_at(&iter))) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   558
          return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   559
        }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   560
      }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   561
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   562
      if (!clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all)) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   563
        return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   564
      }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   565
      break;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   566
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   567
    case relocInfo::opt_virtual_call_type:
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   568
      if (!clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all)) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   569
        return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   570
      }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   571
      break;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   572
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   573
    case relocInfo::static_call_type:
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   574
      if (!clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, clean_all)) {
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   575
        return false;
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   576
      }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   577
      break;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   578
54839
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   579
    case relocInfo::static_stub_type: {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   580
      is_in_static_stub = true;
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   581
      break;
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   582
    }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   583
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   584
    case relocInfo::metadata_type: {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   585
      // Only the metadata relocations contained in static/opt virtual call stubs
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   586
      // contains the Method* passed to c2i adapters. It is the only metadata
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   587
      // relocation that needs to be walked, as it is the one metadata relocation
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   588
      // that violates the invariant that all metadata relocations have an oop
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   589
      // in the compiled method (due to deferred resolution and code patching).
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   590
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   591
      // This causes dead metadata to remain in compiled methods that are not
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   592
      // unloading. Unless these slippery metadata relocations of the static
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   593
      // stubs are at least cleared, subsequent class redefinition operations
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   594
      // will access potentially free memory, and JavaThread execution
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   595
      // concurrent to class unloading may call c2i adapters with dead methods.
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   596
      if (!is_in_static_stub) {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   597
        // The first metadata relocation after a static stub relocation is the
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   598
        // metadata relocation of the static stub used to pass the Method* to
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   599
        // c2i adapters.
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   600
        continue;
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   601
      }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   602
      is_in_static_stub = false;
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   603
      metadata_Relocation* r = iter.metadata_reloc();
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   604
      Metadata* md = r->metadata_value();
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   605
      if (md != NULL && md->is_method()) {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   606
        Method* method = static_cast<Method*>(md);
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   607
        if (!method->method_holder()->is_loader_alive()) {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   608
          Atomic::store((Method*)NULL, r->metadata_addr());
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   609
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   610
          if (!r->metadata_is_immediate()) {
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   611
            r->fix_metadata_relocation();
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   612
          }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   613
        }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   614
      }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   615
      break;
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   616
    }
e9db10a375d9 8222841: Incorrect static call stub interactions with class unloading
eosterlund
parents: 54150
diff changeset
   617
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46623
diff changeset
   618
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46623
diff changeset
   619
      break;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   620
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   621
  }
52857
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   622
7e268f863ff0 8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents: 52660
diff changeset
   623
  return true;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
diff changeset
   624
}
51591
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   625
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   626
// Iterating over all nmethods, e.g. with the help of CodeCache::nmethods_do(fun) was found
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   627
// to not be inherently safe. There is a chance that fields are seen which are not properly
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   628
// initialized. This happens despite the fact that nmethods_do() asserts the CodeCache_lock
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   629
// to be held.
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   630
// To bundle knowledge about necessary checks in one place, this function was introduced.
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   631
// It is not claimed that these checks are sufficient, but they were found to be necessary.
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   632
bool CompiledMethod::nmethod_access_is_safe(nmethod* nm) {
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   633
  Method* method = (nm == NULL) ? NULL : nm->method();  // nm->method() may be uninitialized, i.e. != NULL, but invalid
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   634
  return (nm != NULL) && (method != NULL) && (method->signature() != NULL) &&
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   635
         !nm->is_zombie() && !nm->is_not_installed() &&
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   636
         os::is_readable_pointer(method) &&
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   637
         os::is_readable_pointer(method->constants()) &&
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   638
         os::is_readable_pointer(method->signature());
9183040e34d8 8209950: SIGBUS in CodeHeapState::print_names()
lucy
parents: 51333
diff changeset
   639
}
54150
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   640
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   641
class HasEvolDependency : public MetadataClosure {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   642
  bool _has_evol_dependency;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   643
 public:
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   644
  HasEvolDependency() : _has_evol_dependency(false) {}
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   645
  void do_metadata(Metadata* md) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   646
    if (md->is_method()) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   647
      Method* method = (Method*)md;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   648
      if (method->is_old()) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   649
        _has_evol_dependency = true;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   650
      }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   651
    }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   652
  }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   653
  bool has_evol_dependency() const { return _has_evol_dependency; }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   654
};
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   655
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   656
bool CompiledMethod::has_evol_metadata() {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   657
  // Check the metadata in relocIter and CompiledIC and also deoptimize
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   658
  // any nmethod that has reference to old methods.
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   659
  HasEvolDependency check_evol;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   660
  metadata_do(&check_evol);
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   661
  if (check_evol.has_evol_dependency() && log_is_enabled(Debug, redefine, class, nmethod)) {
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   662
    ResourceMark rm;
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   663
    log_debug(redefine, class, nmethod)
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   664
            ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on in nmethod metadata",
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   665
             _method->method_holder()->external_name(),
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   666
             _method->name()->as_C_string(),
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   667
             _method->signature()->as_C_string(),
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   668
             compile_id());
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   669
  }
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   670
  return check_evol.has_evol_dependency();
5529640c5f67 8220512: Deoptimize redefinition functions that have dirty ICs
coleenp
parents: 53651
diff changeset
   671
}