src/hotspot/share/code/dependencyContext.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 52819 022420a4cc63
child 53775 5d20b085d893
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52819
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     4
 *
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     8
 *
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    14
 *
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    18
 *
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    21
 * questions.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    22
 *
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    23
 */
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52819
diff changeset
    25
#ifndef SHARE_CODE_DEPENDENCYCONTEXT_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52819
diff changeset
    26
#define SHARE_CODE_DEPENDENCYCONTEXT_HPP
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    27
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    28
#include "memory/allocation.hpp"
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    29
#include "oops/oop.hpp"
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    30
#include "runtime/handles.hpp"
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    31
#include "runtime/perfData.hpp"
42055
98554e5a088e 8157453: Convert DependencyContext_test to GTest
jwilhelm
parents: 34223
diff changeset
    32
#include "runtime/safepoint.hpp"
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    33
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    34
class nmethod;
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    35
class DepChange;
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    36
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    37
//
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    38
// nmethodBucket is used to record dependent nmethods for
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    39
// deoptimization.  nmethod dependencies are actually <klass, method>
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    40
// pairs but we really only care about the klass part for purposes of
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    41
// finding nmethods which might need to be deoptimized.  Instead of
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    42
// recording the method, a count of how many times a particular nmethod
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    43
// was recorded is kept.  This ensures that any recording errors are
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    44
// noticed since an nmethod should be removed as many times are it's
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    45
// added.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    46
//
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    47
class nmethodBucket: public CHeapObj<mtClass> {
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    48
  friend class VMStructs;
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    49
 private:
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    50
  nmethod*       _nmethod;
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    51
  volatile int   _count;
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    52
  nmethodBucket* volatile _next;
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    53
  nmethodBucket* volatile _purge_list_next;
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    54
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    55
 public:
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    56
  nmethodBucket(nmethod* nmethod, nmethodBucket* next) :
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    57
    _nmethod(nmethod), _count(1), _next(next), _purge_list_next(NULL) {}
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    58
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    59
  int count()                                { return _count; }
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    60
  int increment()                            { _count += 1; return _count; }
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    61
  int decrement();
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    62
  nmethodBucket* next();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    63
  nmethodBucket* next_not_unloading();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    64
  void set_next(nmethodBucket* b);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    65
  nmethodBucket* purge_list_next();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    66
  void set_purge_list_next(nmethodBucket* b);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    67
  nmethod* get_nmethod()                     { return _nmethod; }
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    68
};
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    69
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    70
//
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    71
// Utility class to manipulate nmethod dependency context.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    72
// Dependency context can be attached either to an InstanceKlass (_dep_context field)
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    73
// or CallSiteContext oop for call_site_target dependencies (see javaClasses.hpp).
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    74
// DependencyContext class operates on some location which holds a nmethodBucket* value
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    75
// and uint64_t integer recording the safepoint counter at the last cleanup.
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    76
//
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    77
class DependencyContext : public StackObj {
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    78
  friend class VMStructs;
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    79
  friend class TestDependencyContext;
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    80
 private:
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    81
  nmethodBucket* volatile* _dependency_context_addr;
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    82
  volatile uint64_t*       _last_cleanup_addr;
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    83
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    84
  bool claim_cleanup();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    85
  void set_dependencies(nmethodBucket* b);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    86
  nmethodBucket* dependencies();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    87
  nmethodBucket* dependencies_not_unloading();
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    88
52819
022420a4cc63 8214556: Crash in DependencyContext::remove_dependent_nmethod still happens
eosterlund
parents: 52781
diff changeset
    89
  static PerfCounter*            _perf_total_buckets_allocated_count;
022420a4cc63 8214556: Crash in DependencyContext::remove_dependent_nmethod still happens
eosterlund
parents: 52781
diff changeset
    90
  static PerfCounter*            _perf_total_buckets_deallocated_count;
022420a4cc63 8214556: Crash in DependencyContext::remove_dependent_nmethod still happens
eosterlund
parents: 52781
diff changeset
    91
  static PerfCounter*            _perf_total_buckets_stale_count;
022420a4cc63 8214556: Crash in DependencyContext::remove_dependent_nmethod still happens
eosterlund
parents: 52781
diff changeset
    92
  static PerfCounter*            _perf_total_buckets_stale_acc_count;
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    93
  static nmethodBucket* volatile _purge_list;
52819
022420a4cc63 8214556: Crash in DependencyContext::remove_dependent_nmethod still happens
eosterlund
parents: 52781
diff changeset
    94
  static uint64_t                _cleaning_epoch_monotonic;
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
    95
  static volatile uint64_t       _cleaning_epoch;
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    96
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    97
 public:
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
    98
#ifdef ASSERT
34223
d12ad6a3a9d7 8144024: Octane fails with "memory leak: allocating handle outside HandleMark"
vlivanov
parents: 34221
diff changeset
    99
  // Safepoints are forbidden during DC lifetime. GC can invalidate
d12ad6a3a9d7 8144024: Octane fails with "memory leak: allocating handle outside HandleMark"
vlivanov
parents: 34221
diff changeset
   100
  // _dependency_context_addr if it relocates the holder
d12ad6a3a9d7 8144024: Octane fails with "memory leak: allocating handle outside HandleMark"
vlivanov
parents: 34221
diff changeset
   101
  // (e.g. CallSiteContext Java object).
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 51887
diff changeset
   102
  uint64_t _safepoint_counter;
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   103
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   104
  DependencyContext(nmethodBucket* volatile* bucket_addr, volatile uint64_t* last_cleanup_addr)
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   105
    : _dependency_context_addr(bucket_addr),
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   106
      _last_cleanup_addr(last_cleanup_addr),
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   107
      _safepoint_counter(SafepointSynchronize::safepoint_counter()) {}
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   108
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   109
  ~DependencyContext() {
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 51887
diff changeset
   110
    assert(_safepoint_counter == SafepointSynchronize::safepoint_counter(), "safepoint happened");
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   111
  }
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   112
#else
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   113
  DependencyContext(nmethodBucket* volatile* bucket_addr, volatile uint64_t* last_cleanup_addr)
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   114
    : _dependency_context_addr(bucket_addr),
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   115
      _last_cleanup_addr(last_cleanup_addr) {}
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   116
#endif // ASSERT
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   117
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   118
  static void init();
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   119
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   120
  int  mark_dependent_nmethods(DepChange& changes);
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   121
  void add_dependent_nmethod(nmethod* nm);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   122
  void remove_dependent_nmethod(nmethod* nm);
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   123
  int  remove_all_dependents();
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   124
  void clean_unloading_dependents();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   125
  static void purge_dependency_contexts();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   126
  static void release(nmethodBucket* b);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   127
  static void cleaning_start();
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52672
diff changeset
   128
  static void cleaning_end();
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   129
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   130
#ifndef PRODUCT
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   131
  void print_dependent_nmethods(bool verbose);
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   132
  bool is_dependent_nmethod(nmethod* nm);
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   133
#endif //PRODUCT
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents:
diff changeset
   134
};
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52819
diff changeset
   135
#endif // SHARE_CODE_DEPENDENCYCONTEXT_HPP