src/hotspot/share/code/codeCache.hpp
author eosterlund
Thu, 22 Nov 2018 10:01:38 +0100
changeset 52661 4f45c682eab0
parent 52453 6e99148dbf33
child 52781 436097b038a1
permissions -rw-r--r--
8213755: Let nmethods be is_unloading() outside of safepoints Reviewed-by: rehn, coleenp, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    25
#ifndef SHARE_VM_CODE_CODECACHE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    26
#define SHARE_VM_CODE_CODECACHE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    28
#include "code/codeBlob.hpp"
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    29
#include "code/nmethod.hpp"
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
    30
#include "gc/shared/gcBehaviours.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    31
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    32
#include "memory/heap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    33
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    34
#include "oops/oopsHierarchy.hpp"
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    35
#include "runtime/mutexLocker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    36
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The CodeCache implements the code cache for various pieces of generated
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// code, e.g., compiled java methods, runtime stubs, transition frames, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// The entries in the CodeCache are all CodeBlob's.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    41
// -- Implementation --
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    42
// The CodeCache consists of one or more CodeHeaps, each of which contains
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    43
// CodeBlobs of a specific CodeBlobType. Currently heaps for the following
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    44
// types are available:
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    45
//  - Non-nmethods: Non-nmethods like Buffers, Adapters and Runtime Stubs
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    46
//  - Profiled nmethods: nmethods that are profiled, i.e., those
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    47
//    executed at level 2 or 3
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    48
//  - Non-Profiled nmethods: nmethods that are not profiled, i.e., those
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    49
//    executed at level 1 or 4 and native methods
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    50
//  - All: Used for code of all types if code cache segmentation is disabled.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    51
//
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    52
// In the rare case of the non-nmethod code heap getting full, non-nmethod code
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    53
// will be stored in the non-profiled code heap as a fallback solution.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    54
//
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    55
// Depending on the availability of compilers and TieredCompilation there
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    56
// may be fewer heaps. The size of the code heaps depends on the values of
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    57
// ReservedCodeCacheSize, NonProfiledCodeHeapSize and ProfiledCodeHeapSize
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    58
// (see CodeCache::heap_available(..) and CodeCache::initialize_heaps(..)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    59
// for details).
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    60
//
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    61
// Code cache segmentation is controlled by the flag SegmentedCodeCache.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    62
// If turned off, all code types are stored in a single code heap. By default
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    63
// code cache segmentation is turned on if TieredCompilation is enabled and
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    64
// ReservedCodeCacheSize >= 240 MB.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    65
//
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    66
// All methods of the CodeCache accepting a CodeBlobType only apply to
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    67
// CodeBlobs of the given type. For example, iteration over the
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    68
// CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    69
// and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    70
//
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    71
// IMPORTANT: If you add new CodeHeaps to the code cache or change the
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    72
// existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    73
// Solaris and BSD.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
    75
class ExceptionCache;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
    76
class KlassDepChange;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
class OopClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
class CodeCache : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  friend class VMStructs;
35123
b0b89d83bcf5 8134994: use separate VMStructs databases for SA and JVMCI
twisti
parents: 34182
diff changeset
    81
  friend class JVMCIVMStructs;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
    82
  template <class T, class Filter> friend class CodeBlobIterator;
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
    83
  friend class WhiteBox;
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 31348
diff changeset
    84
  friend class CodeCacheLoader;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
 private:
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    86
  // CodeHeaps of the cache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    87
  static GrowableArray<CodeHeap*>* _heaps;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
    88
  static GrowableArray<CodeHeap*>* _compiled_heaps;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
    89
  static GrowableArray<CodeHeap*>* _nmethod_heaps;
45622
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
    90
  static GrowableArray<CodeHeap*>* _allocable_heaps;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    91
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    92
  static address _low_bound;                            // Lower bound of CodeHeap addresses
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    93
  static address _high_bound;                           // Upper bound of CodeHeap addresses
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    94
  static int _number_of_nmethods_with_dependencies;     // Total number of nmethods with dependencies
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    95
  static nmethod* _scavenge_root_nmethods;              // linked via nm->scavenge_root_link()
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
    96
  static uint8_t _unloading_cycle;                      // Global state for recognizing old nmethods that need to be unloaded
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
    98
  static ExceptionCache* volatile _exception_cache_purge_list;
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
    99
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   100
  static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   101
  static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   102
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   103
  // CodeHeap management
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   104
  static void initialize_heaps();                             // Initializes the CodeHeaps
34182
82d1b1696016 8061436: Processing of options related to segmented code cache should be enhanced
thartmann
parents: 34158
diff changeset
   105
  // Check the code heap sizes set by the user via command line
82d1b1696016 8061436: Processing of options related to segmented code cache should be enhanced
thartmann
parents: 34158
diff changeset
   106
  static void check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   107
  // Creates a new heap with the given name and size, containing CodeBlobs of the given type
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28374
diff changeset
   108
  static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
46647
634dc786bf96 8183573: Refactor CodeHeap and AOTCodeHeap to devirtualize hot methods
redestad
parents: 46632
diff changeset
   109
  static CodeHeap* get_code_heap_containing(void* p);         // Returns the CodeHeap containing the given pointer, or NULL
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
   110
  static CodeHeap* get_code_heap(const CodeBlob* cb);         // Returns the CodeHeap for the given CodeBlob
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   111
  static CodeHeap* get_code_heap(int code_blob_type);         // Returns the CodeHeap for the given CodeBlobType
27410
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 26942
diff changeset
   112
  // Returns the name of the VM option to set the size of the corresponding CodeHeap
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 26942
diff changeset
   113
  static const char* get_code_heap_flag_name(int code_blob_type);
48119
c1b46afab3ba 8087339: The code heap might use different alignment for committed size and reserved size
thartmann
parents: 47688
diff changeset
   114
  static size_t page_size(bool aligned = true);               // Returns the page size used by the CodeCache
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   115
  static ReservedCodeSpace reserve_heap_memory(size_t size);  // Reserves one continuous chunk of memory for the CodeHeaps
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   116
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   117
  // Iteration
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   118
  static CodeBlob* first_blob(CodeHeap* heap);                // Returns the first CodeBlob on the given CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   119
  static CodeBlob* first_blob(int code_blob_type);            // Returns the first CodeBlob of the given type
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   120
  static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb);   // Returns the next CodeBlob on the given CodeHeap
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   121
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   122
  static size_t bytes_allocated_in_freelists();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   123
  static int    allocated_segments();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   124
  static size_t freelists_length();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
   125
36591
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   126
  static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   127
  static void prune_scavenge_root_nmethods();
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   128
  static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev);
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   129
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   130
  // Make private to prevent unsafe calls.  Not all CodeBlob*'s are embedded in a CodeHeap.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   131
  static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   137
  static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   138
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   139
  static void add_heap(CodeHeap* heap);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   140
  static const GrowableArray<CodeHeap*>* heaps() { return _heaps; }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   141
  static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   142
  static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   143
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Allocation/administration
40863
f5fec6a2dc9e 8064892: Non-methods code cache overflow is not handled correctly
thartmann
parents: 38133
diff changeset
   145
  static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   146
  static void commit(CodeBlob* cb);                        // called when the allocated CodeBlob has been filled
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   147
  static int  alignment_unit();                            // guaranteed alignment of all CodeBlobs
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   148
  static int  alignment_offset();                          // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   149
  static void free(CodeBlob* cb);                          // frees a CodeBlob
47688
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47624
diff changeset
   150
  static void free_unused_tail(CodeBlob* cb, size_t used); // frees the unused tail of a CodeBlob (only used by TemplateInterpreter::initialize())
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   151
  static bool contains(void *p);                           // returns whether p is included
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   152
  static bool contains(nmethod* nm);                       // returns whether nm is included
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   153
  static void blobs_do(void f(CodeBlob* cb));              // iterates over all CodeBlobs
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   154
  static void blobs_do(CodeBlobClosure* f);                // iterates over all CodeBlobs
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   155
  static void nmethods_do(void f(nmethod* nm));            // iterates over all nmethods
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   156
  static void metadata_do(void f(Metadata* m));            // iterates over metadata in alive nmethods
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Lookup
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   159
  static CodeBlob* find_blob(void* start);              // Returns the CodeBlob containing the given address
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   160
  static CodeBlob* find_blob_unsafe(void* start);       // Same as find_blob but does not fail if looking up a zombie method
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   161
  static nmethod*  find_nmethod(void* start);           // Returns the nmethod containing the given address
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   162
  static CompiledMethod* find_compiled(void* start);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9124
diff changeset
   163
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   164
  static int       blob_count();                        // Returns the total number of CodeBlobs in the cache
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   165
  static int       blob_count(int code_blob_type);
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   166
  static int       adapter_count();                     // Returns the total number of Adapters in the cache
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   167
  static int       adapter_count(int code_blob_type);
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   168
  static int       nmethod_count();                     // Returns the total number of nmethods in the cache
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   169
  static int       nmethod_count(int code_blob_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  static void gc_epilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  static void gc_prologue();
8724
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   174
  static void verify_oops();
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49611
diff changeset
   175
  // If any oops are not marked this method unloads (i.e., breaks root links
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // to) any unmarked codeBlobs in the cache.  Sets "marked_for_unloading"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // to "true" iff some code got unloaded.
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49611
diff changeset
   178
  // "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   179
  class UnloadingScope: StackObj {
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   180
    ClosureIsUnloadingBehaviour _is_unloading_behaviour;
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   181
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   182
  public:
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   183
    UnloadingScope(BoolObjectClosure* is_alive)
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   184
      : _is_unloading_behaviour(is_alive)
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   185
    {
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   186
      IsUnloadingBehaviour::set_current(&_is_unloading_behaviour);
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   187
      increment_unloading_cycle();
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   188
    }
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   189
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   190
    ~UnloadingScope() {
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   191
      IsUnloadingBehaviour::set_current(NULL);
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   192
    }
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   193
  };
13878
6e6a462a6cff 7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents: 13728
diff changeset
   194
  static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
52453
6e99148dbf33 8213411: JDK-8209189 incorrect for Big Endian (JVM crashes)
eosterlund
parents: 52405
diff changeset
   195
  static uint8_t unloading_cycle() { return _unloading_cycle; }
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 50416
diff changeset
   196
  static void increment_unloading_cycle();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   197
  static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
52405
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   198
  static void release_exception_cache(ExceptionCache* entry);
c0c6cdea32f1 8212989: Allow CompiledMethod ExceptionCache have unloaded klasses
eosterlund
parents: 52385
diff changeset
   199
  static void purge_exception_caches();
36591
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   200
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   201
  // Apply f to every live code blob in scavengable nmethods. Prune nmethods
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   202
  // from the list of scavengable nmethods if f->fix_relocations() and a nmethod
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   203
  // no longer has scavengable oops.  If f->fix_relocations(), then f must copy
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   204
  // objects to their new location immediately to avoid fixing nmethods on the
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   205
  // basis of the old object locations.
d0622cab5983 8150013: ParNew: Prune nmethods scavengable list.
cvarming
parents: 35123
diff changeset
   206
  static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   207
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   208
  static nmethod* scavenge_root_nmethods()            { return _scavenge_root_nmethods; }
47624
b055cb5170f5 8185141: Generalize scavengeable nmethod root handling
eosterlund
parents: 47216
diff changeset
   209
  // register_scavenge_root_nmethod() conditionally adds the nmethod to the list
b055cb5170f5 8185141: Generalize scavengeable nmethod root handling
eosterlund
parents: 47216
diff changeset
   210
  // if it is not already on the list and has a scavengeable root
b055cb5170f5 8185141: Generalize scavengeable nmethod root handling
eosterlund
parents: 47216
diff changeset
   211
  static void register_scavenge_root_nmethod(nmethod* nm);
b055cb5170f5 8185141: Generalize scavengeable nmethod root handling
eosterlund
parents: 47216
diff changeset
   212
  static void verify_scavenge_root_nmethod(nmethod* nm);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   213
  static void add_scavenge_root_nmethod(nmethod* nm);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   214
  static void drop_scavenge_root_nmethod(nmethod* nm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Printing/debugging
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
   217
  static void print();                           // prints summary
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  static void print_internals();
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 20290
diff changeset
   219
  static void print_memory_overhead();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  static void verify();                          // verifies the code cache
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   221
  static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
   222
  static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
8672
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
   223
  static void log_state(outputStream* st);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   224
  static const char* get_code_heap_name(int code_blob_type)  { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   225
  static void report_codemem_full(int code_blob_type, bool print);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 25492
diff changeset
   227
  // Dcmd (Diagnostic commands)
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 25492
diff changeset
   228
  static void print_codelist(outputStream* st);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 25492
diff changeset
   229
  static void print_layout(outputStream* st);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 25492
diff changeset
   230
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // The full limits of the codeCache
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   232
  static address low_bound()                          { return _low_bound; }
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   233
  static address low_bound(int code_blob_type);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   234
  static address high_bound()                         { return _high_bound; }
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   235
  static address high_bound(int code_blob_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   237
  // Have to use far call instructions to call this pc.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   238
  static bool is_far_target(address pc);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   239
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Profiling
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   241
  static size_t capacity();
26942
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   242
  static size_t unallocated_capacity(int code_blob_type);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   243
  static size_t unallocated_capacity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   244
  static size_t max_capacity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   245
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   246
  static double reverse_free_ratio(int code_blob_type);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   247
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   248
  static void clear_inline_caches();                  // clear all inline caches
50416
ef980b9ac191 8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents: 49611
diff changeset
   249
  static void cleanup_inline_caches();                // clean unloaded/zombie nmethods from inline caches
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   251
  // Returns true if an own CodeHeap for the given CodeBlobType is available
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   252
  static bool heap_available(int code_blob_type);
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   253
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   254
  // Returns the CodeBlobType for the given CompiledMethod
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   255
  static int get_code_blob_type(CompiledMethod* cm) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   256
    return get_code_heap(cm)->code_blob_type();
31348
c28f02c7abb5 8077279: assert(ic->is_clean()) failed: IC should be clean
sjohanss
parents: 31037
diff changeset
   257
  }
c28f02c7abb5 8077279: assert(ic->is_clean()) failed: IC should be clean
sjohanss
parents: 31037
diff changeset
   258
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   259
  static bool code_blob_type_accepts_compiled(int type) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   260
    bool result = type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   261
    AOT_ONLY( result = result || type == CodeBlobType::AOT; )
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   262
    return result;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   263
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   264
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   265
  static bool code_blob_type_accepts_nmethod(int type) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   266
    return type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   267
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   268
45622
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
   269
  static bool code_blob_type_accepts_allocable(int type) {
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
   270
    return type <= CodeBlobType::All;
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
   271
  }
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
   272
3e4f81c922de 8181757: NonNMethod heap in segmented CodeCache is not scanned in some cases
dlong
parents: 43945
diff changeset
   273
31348
c28f02c7abb5 8077279: assert(ic->is_clean()) failed: IC should be clean
sjohanss
parents: 31037
diff changeset
   274
  // Returns the CodeBlobType for the given compilation level
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   275
  static int get_code_blob_type(int comp_level) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   276
    if (comp_level == CompLevel_none ||
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   277
        comp_level == CompLevel_simple ||
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   278
        comp_level == CompLevel_full_optimization) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   279
      // Non profiled methods
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   280
      return CodeBlobType::MethodNonProfiled;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   281
    } else if (comp_level == CompLevel_limited_profile ||
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   282
               comp_level == CompLevel_full_profile) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   283
      // Profiled methods
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   284
      return CodeBlobType::MethodProfiled;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   285
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   286
    ShouldNotReachHere();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   287
    return 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   288
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   290
  static void verify_clean_inline_caches();
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   291
  static void verify_icholder_relocations();
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   292
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // Deoptimization
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   294
 private:
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents: 35123
diff changeset
   295
  static int  mark_for_deoptimization(KlassDepChange& changes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
#ifdef HOTSWAP
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43945
diff changeset
   297
  static int  mark_for_evol_deoptimization(InstanceKlass* dependee);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
#endif // HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   300
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  static void mark_all_nmethods_for_deoptimization();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   302
  static int  mark_for_deoptimization(Method* dependee);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  static void make_marked_nmethods_not_entrant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   305
  // Flushing and deoptimization
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43945
diff changeset
   306
  static void flush_dependents_on(InstanceKlass* dependee);
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   307
#ifdef HOTSWAP
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   308
  // Flushing and deoptimization in case of evolution
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43945
diff changeset
   309
  static void flush_evol_dependents_on(InstanceKlass* dependee);
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   310
#endif // HOTSWAP
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   311
  // Support for fullspeed debugging
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46647
diff changeset
   312
  static void flush_dependents_on_method(const methodHandle& dependee);
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27642
diff changeset
   313
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   314
  // tells how many nmethods have dependencies
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  static int number_of_nmethods_with_dependencies();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
   316
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   317
  static int get_codemem_full_count(int code_blob_type) {
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   318
    CodeHeap* heap = get_code_heap(code_blob_type);
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   319
    return (heap != NULL) ? heap->full_count() : 0;
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 32401
diff changeset
   320
  }
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   321
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   322
  // CodeHeap State Analytics.
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   323
  // interface methods for CodeHeap printing, called by CompileBroker
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   324
  static void aggregate(outputStream *out, const char* granularity);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   325
  static void discard(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   326
  static void print_usedSpace(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   327
  static void print_freeSpace(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   328
  static void print_count(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   329
  static void print_space(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   330
  static void print_age(outputStream *out);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 48119
diff changeset
   331
  static void print_names(outputStream *out);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
   333
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   334
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   335
// Iterator to iterate over nmethods in the CodeCache.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   336
template <class T, class Filter> class CodeBlobIterator : public StackObj {
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   337
 public:
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   338
  enum LivenessFilter { all_blobs, only_alive, only_alive_and_not_unloading };
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   339
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   340
 private:
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   341
  CodeBlob* _code_blob;   // Current CodeBlob
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   342
  GrowableArrayIterator<CodeHeap*> _heap;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   343
  GrowableArrayIterator<CodeHeap*> _end;
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   344
  bool _only_alive;
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   345
  bool _only_not_unloading;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   346
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   347
 public:
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   348
  CodeBlobIterator(LivenessFilter filter, T* nm = NULL)
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   349
    : _only_alive(filter == only_alive || filter == only_alive_and_not_unloading),
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   350
      _only_not_unloading(filter == only_alive_and_not_unloading)
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   351
  {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   352
    if (Filter::heaps() == NULL) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   353
      return;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   354
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   355
    _heap = Filter::heaps()->begin();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   356
    _end = Filter::heaps()->end();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   357
    // If set to NULL, initialized by first call to next()
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   358
    _code_blob = (CodeBlob*)nm;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   359
    if (nm != NULL) {
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42664
diff changeset
   360
      while(!(*_heap)->contains_blob(_code_blob)) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   361
        ++_heap;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   362
      }
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42664
diff changeset
   363
      assert((*_heap)->contains_blob(_code_blob), "match not found");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   364
    }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   365
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   366
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   367
  // Advance iterator to next blob
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   368
  bool next() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   369
    assert_locked_or_safepoint(CodeCache_lock);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   370
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   371
    for (;;) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   372
      // Walk through heaps as required
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   373
      if (!next_blob()) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   374
        if (_heap == _end) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   375
          return false;
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   376
        }
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   377
        ++_heap;
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   378
        continue;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   379
      }
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   380
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   381
      // Filter is_alive as required
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   382
      if (_only_alive && !_code_blob->is_alive()) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   383
        continue;
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   384
      }
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   385
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   386
      // Filter is_unloading as required
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   387
      if (_only_not_unloading) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   388
        CompiledMethod* cm = _code_blob->as_compiled_method_or_null();
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   389
        if (cm != NULL && cm->is_unloading()) {
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   390
          continue;
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   391
        }
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   392
      }
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   393
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   394
      return true;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   395
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   396
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   397
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   398
  bool end()  const { return _code_blob == NULL; }
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52453
diff changeset
   399
  T* method() const { return (T*)_code_blob; }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   400
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   401
private:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   402
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   403
  // Advance iterator to the next blob in the current code heap
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   404
  bool next_blob() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   405
    if (_heap == _end) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   406
      return false;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   407
    }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   408
    CodeHeap *heap = *_heap;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   409
    // Get first method CodeBlob
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   410
    if (_code_blob == NULL) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   411
      _code_blob = CodeCache::first_blob(heap);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   412
      if (_code_blob == NULL) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   413
        return false;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   414
      } else if (Filter::apply(_code_blob)) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   415
        return true;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   416
      }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   417
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   418
    // Search for next method CodeBlob
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   419
    _code_blob = CodeCache::next_blob(heap, _code_blob);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   420
    while (_code_blob != NULL && !Filter::apply(_code_blob)) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   421
      _code_blob = CodeCache::next_blob(heap, _code_blob);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   422
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   423
    return _code_blob != NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   424
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   425
};
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   426
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   427
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   428
struct CompiledMethodFilter {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   429
  static bool apply(CodeBlob* cb) { return cb->is_compiled(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   430
  static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::compiled_heaps(); }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   431
};
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37289
diff changeset
   432
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   433
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   434
struct NMethodFilter {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   435
  static bool apply(CodeBlob* cb) { return cb->is_nmethod(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   436
  static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::nmethod_heaps(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   437
};
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   438
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   439
typedef CodeBlobIterator<CompiledMethod, CompiledMethodFilter> CompiledMethodIterator;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   440
typedef CodeBlobIterator<nmethod, NMethodFilter> NMethodIterator;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40863
diff changeset
   441
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
   442
#endif // SHARE_VM_CODE_CODECACHE_HPP