2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2016-04-26 10:28:51 +02:00
|
|
|
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_CODE_CODECACHE_HPP
|
|
|
|
#define SHARE_VM_CODE_CODECACHE_HPP
|
|
|
|
|
|
|
|
#include "code/codeBlob.hpp"
|
2014-09-17 08:00:07 +02:00
|
|
|
#include "code/nmethod.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "memory/heap.hpp"
|
|
|
|
#include "oops/instanceKlass.hpp"
|
|
|
|
#include "oops/oopsHierarchy.hpp"
|
2014-09-17 08:00:07 +02:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// The CodeCache implements the code cache for various pieces of generated
|
|
|
|
// code, e.g., compiled java methods, runtime stubs, transition frames, etc.
|
|
|
|
// The entries in the CodeCache are all CodeBlob's.
|
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
// -- Implementation --
|
|
|
|
// The CodeCache consists of one or more CodeHeaps, each of which contains
|
|
|
|
// CodeBlobs of a specific CodeBlobType. Currently heaps for the following
|
|
|
|
// types are available:
|
2014-09-30 15:44:43 +02:00
|
|
|
// - Non-nmethods: Non-nmethods like Buffers, Adapters and Runtime Stubs
|
2014-09-17 08:00:07 +02:00
|
|
|
// - Profiled nmethods: nmethods that are profiled, i.e., those
|
|
|
|
// executed at level 2 or 3
|
|
|
|
// - Non-Profiled nmethods: nmethods that are not profiled, i.e., those
|
|
|
|
// executed at level 1 or 4 and native methods
|
|
|
|
// - All: Used for code of all types if code cache segmentation is disabled.
|
|
|
|
//
|
2014-09-30 15:44:43 +02:00
|
|
|
// In the rare case of the non-nmethod code heap getting full, non-nmethod code
|
2014-09-17 08:00:07 +02:00
|
|
|
// will be stored in the non-profiled code heap as a fallback solution.
|
|
|
|
//
|
|
|
|
// Depending on the availability of compilers and TieredCompilation there
|
|
|
|
// may be fewer heaps. The size of the code heaps depends on the values of
|
|
|
|
// ReservedCodeCacheSize, NonProfiledCodeHeapSize and ProfiledCodeHeapSize
|
|
|
|
// (see CodeCache::heap_available(..) and CodeCache::initialize_heaps(..)
|
|
|
|
// for details).
|
|
|
|
//
|
|
|
|
// Code cache segmentation is controlled by the flag SegmentedCodeCache.
|
|
|
|
// If turned off, all code types are stored in a single code heap. By default
|
|
|
|
// code cache segmentation is turned on if TieredCompilation is enabled and
|
|
|
|
// ReservedCodeCacheSize >= 240 MB.
|
|
|
|
//
|
|
|
|
// All methods of the CodeCache accepting a CodeBlobType only apply to
|
|
|
|
// CodeBlobs of the given type. For example, iteration over the
|
|
|
|
// CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
|
|
|
|
// and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
|
|
|
|
//
|
|
|
|
// IMPORTANT: If you add new CodeHeaps to the code cache or change the
|
|
|
|
// existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
|
|
|
|
// Solaris and BSD.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
class OopClosure;
|
2016-02-19 20:40:20 +03:00
|
|
|
class KlassDepChange;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
class CodeCache : AllStatic {
|
|
|
|
friend class VMStructs;
|
2015-12-14 17:02:02 -10:00
|
|
|
friend class JVMCIVMStructs;
|
2016-12-11 19:07:04 -08:00
|
|
|
template <class T, class Filter> friend class CodeBlobIterator;
|
2014-11-10 19:04:38 +03:00
|
|
|
friend class WhiteBox;
|
2015-07-01 10:53:26 +02:00
|
|
|
friend class CodeCacheLoader;
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
2014-09-17 08:00:07 +02:00
|
|
|
// CodeHeaps of the cache
|
|
|
|
static GrowableArray<CodeHeap*>* _heaps;
|
2016-12-11 19:07:04 -08:00
|
|
|
static GrowableArray<CodeHeap*>* _compiled_heaps;
|
|
|
|
static GrowableArray<CodeHeap*>* _nmethod_heaps;
|
2014-09-17 08:00:07 +02:00
|
|
|
|
|
|
|
static address _low_bound; // Lower bound of CodeHeap addresses
|
|
|
|
static address _high_bound; // Upper bound of CodeHeap addresses
|
|
|
|
static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies
|
|
|
|
static bool _needs_cache_clean; // True if inline caches of the nmethods needs to be flushed
|
|
|
|
static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-09-15 21:53:47 -07:00
|
|
|
static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
|
|
|
|
static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
|
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
// CodeHeap management
|
|
|
|
static void initialize_heaps(); // Initializes the CodeHeaps
|
2015-11-16 15:35:43 +01:00
|
|
|
// Check the code heap sizes set by the user via command line
|
|
|
|
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);
|
2014-09-17 08:00:07 +02:00
|
|
|
// Creates a new heap with the given name and size, containing CodeBlobs of the given type
|
2015-01-28 07:55:27 +01:00
|
|
|
static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
|
2014-11-10 19:04:38 +03:00
|
|
|
static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob
|
2014-09-17 08:00:07 +02:00
|
|
|
static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType
|
2014-10-17 08:56:07 +02:00
|
|
|
// Returns the name of the VM option to set the size of the corresponding CodeHeap
|
|
|
|
static const char* get_code_heap_flag_name(int code_blob_type);
|
2015-01-28 07:55:27 +01:00
|
|
|
static size_t heap_alignment(); // Returns the alignment of the CodeHeaps in bytes
|
2014-09-17 08:00:07 +02:00
|
|
|
static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
// Iteration
|
|
|
|
static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap
|
|
|
|
static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type
|
2016-12-11 19:07:04 -08:00
|
|
|
static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the next CodeBlob on the given CodeHeap
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
static size_t bytes_allocated_in_freelists();
|
|
|
|
static int allocated_segments();
|
|
|
|
static size_t freelists_length();
|
|
|
|
|
2016-03-07 14:41:31 -05:00
|
|
|
static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
|
|
|
|
static void prune_scavenge_root_nmethods();
|
|
|
|
static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev);
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Make private to prevent unsafe calls. Not all CodeBlob*'s are embedded in a CodeHeap.
|
|
|
|
static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; }
|
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
public:
|
2007-12-01 00:00:00 +00:00
|
|
|
// Initialization
|
|
|
|
static void initialize();
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs);
|
|
|
|
|
|
|
|
static void add_heap(CodeHeap* heap);
|
|
|
|
static const GrowableArray<CodeHeap*>* heaps() { return _heaps; }
|
|
|
|
static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; }
|
|
|
|
static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Allocation/administration
|
2016-08-19 08:34:30 +02:00
|
|
|
static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
|
2014-10-24 14:25:46 +02:00
|
|
|
static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
|
|
|
|
static int alignment_unit(); // guaranteed alignment of all CodeBlobs
|
|
|
|
static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
|
|
|
|
static void free(CodeBlob* cb); // frees a CodeBlob
|
|
|
|
static bool contains(void *p); // returns whether p is included
|
2016-12-11 19:07:04 -08:00
|
|
|
static bool contains(nmethod* nm); // returns whether nm is included
|
2014-10-24 14:25:46 +02:00
|
|
|
static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs
|
|
|
|
static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs
|
|
|
|
static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods
|
2016-04-26 10:28:51 +02:00
|
|
|
static void metadata_do(void f(Metadata* m)); // iterates over metadata in alive nmethods
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Lookup
|
2014-09-17 08:00:07 +02:00
|
|
|
static CodeBlob* find_blob(void* start); // Returns the CodeBlob containing the given address
|
|
|
|
static CodeBlob* find_blob_unsafe(void* start); // Same as find_blob but does not fail if looking up a zombie method
|
|
|
|
static nmethod* find_nmethod(void* start); // Returns the nmethod containing the given address
|
2016-04-26 10:28:51 +02:00
|
|
|
static CompiledMethod* find_compiled(void* start);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-11-09 11:35:44 +01:00
|
|
|
static int blob_count(); // Returns the total number of CodeBlobs in the cache
|
|
|
|
static int blob_count(int code_blob_type);
|
|
|
|
static int adapter_count(); // Returns the total number of Adapters in the cache
|
|
|
|
static int adapter_count(int code_blob_type);
|
|
|
|
static int nmethod_count(); // Returns the total number of nmethods in the cache
|
|
|
|
static int nmethod_count(int code_blob_type);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// GC support
|
|
|
|
static void gc_epilogue();
|
|
|
|
static void gc_prologue();
|
2011-03-18 15:52:42 -07:00
|
|
|
static void verify_oops();
|
2007-12-01 00:00:00 +00:00
|
|
|
// If "unloading_occurred" is true, then unloads (i.e., breaks root links
|
|
|
|
// to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
|
|
|
|
// to "true" iff some code got unloaded.
|
2012-09-25 14:58:12 +02:00
|
|
|
static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
|
2009-09-15 21:53:47 -07:00
|
|
|
static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
|
2016-03-07 14:41:31 -05:00
|
|
|
|
|
|
|
// Apply f to every live code blob in scavengable nmethods. Prune nmethods
|
|
|
|
// from the list of scavengable nmethods if f->fix_relocations() and a nmethod
|
|
|
|
// no longer has scavengable oops. If f->fix_relocations(), then f must copy
|
|
|
|
// objects to their new location immediately to avoid fixing nmethods on the
|
|
|
|
// basis of the old object locations.
|
|
|
|
static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);
|
2009-09-15 21:53:47 -07:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
|
2009-09-15 21:53:47 -07:00
|
|
|
static void add_scavenge_root_nmethod(nmethod* nm);
|
|
|
|
static void drop_scavenge_root_nmethod(nmethod* nm);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Printing/debugging
|
2013-01-14 13:52:08 -05:00
|
|
|
static void print(); // prints summary
|
2007-12-01 00:00:00 +00:00
|
|
|
static void print_internals();
|
2014-03-07 07:42:40 +01:00
|
|
|
static void print_memory_overhead();
|
2007-12-01 00:00:00 +00:00
|
|
|
static void verify(); // verifies the code cache
|
2009-09-15 21:53:47 -07:00
|
|
|
static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
|
2013-01-14 13:52:08 -05:00
|
|
|
static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
|
2011-03-09 09:15:16 -08:00
|
|
|
static void log_state(outputStream* st);
|
2014-09-17 08:00:07 +02:00
|
|
|
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"); }
|
|
|
|
static void report_codemem_full(int code_blob_type, bool print);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-10 13:27:33 +02:00
|
|
|
// Dcmd (Diagnostic commands)
|
|
|
|
static void print_codelist(outputStream* st);
|
|
|
|
static void print_layout(outputStream* st);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// The full limits of the codeCache
|
2014-09-17 08:00:07 +02:00
|
|
|
static address low_bound() { return _low_bound; }
|
2015-11-09 11:35:44 +01:00
|
|
|
static address low_bound(int code_blob_type);
|
2014-09-17 08:00:07 +02:00
|
|
|
static address high_bound() { return _high_bound; }
|
2015-11-09 11:35:44 +01:00
|
|
|
static address high_bound(int code_blob_type);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Have to use far call instructions to call this pc.
|
|
|
|
static bool is_far_target(address pc);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Profiling
|
2014-09-17 08:00:07 +02:00
|
|
|
static size_t capacity();
|
2014-10-01 10:01:46 +02:00
|
|
|
static size_t unallocated_capacity(int code_blob_type);
|
2014-09-17 08:00:07 +02:00
|
|
|
static size_t unallocated_capacity();
|
|
|
|
static size_t max_capacity();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
static double reverse_free_ratio(int code_blob_type);
|
|
|
|
|
|
|
|
static bool needs_cache_clean() { return _needs_cache_clean; }
|
|
|
|
static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }
|
|
|
|
static void clear_inline_caches(); // clear all inline caches
|
2016-04-05 01:46:40 -07:00
|
|
|
static void cleanup_inline_caches();
|
2014-09-17 08:00:07 +02:00
|
|
|
|
2015-11-09 11:35:44 +01:00
|
|
|
// Returns true if an own CodeHeap for the given CodeBlobType is available
|
|
|
|
static bool heap_available(int code_blob_type);
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Returns the CodeBlobType for the given CompiledMethod
|
2016-04-26 10:28:51 +02:00
|
|
|
static int get_code_blob_type(CompiledMethod* cm) {
|
|
|
|
return get_code_heap(cm)->code_blob_type();
|
2015-06-15 10:24:38 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
static bool code_blob_type_accepts_compiled(int type) {
|
|
|
|
bool result = type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
|
|
|
|
AOT_ONLY( result = result || type == CodeBlobType::AOT; )
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool code_blob_type_accepts_nmethod(int type) {
|
|
|
|
return type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:24:38 +02:00
|
|
|
// Returns the CodeBlobType for the given compilation level
|
2014-09-17 08:00:07 +02:00
|
|
|
static int get_code_blob_type(int comp_level) {
|
|
|
|
if (comp_level == CompLevel_none ||
|
|
|
|
comp_level == CompLevel_simple ||
|
|
|
|
comp_level == CompLevel_full_optimization) {
|
|
|
|
// Non profiled methods
|
|
|
|
return CodeBlobType::MethodNonProfiled;
|
|
|
|
} else if (comp_level == CompLevel_limited_profile ||
|
|
|
|
comp_level == CompLevel_full_profile) {
|
|
|
|
// Profiled methods
|
|
|
|
return CodeBlobType::MethodProfiled;
|
|
|
|
}
|
|
|
|
ShouldNotReachHere();
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-07-07 10:12:40 +02:00
|
|
|
static void verify_clean_inline_caches();
|
|
|
|
static void verify_icholder_relocations();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Deoptimization
|
2015-01-06 19:30:28 -05:00
|
|
|
private:
|
2016-02-19 20:40:20 +03:00
|
|
|
static int mark_for_deoptimization(KlassDepChange& changes);
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef HOTSWAP
|
|
|
|
static int mark_for_evol_deoptimization(instanceKlassHandle dependee);
|
|
|
|
#endif // HOTSWAP
|
|
|
|
|
2015-01-06 19:30:28 -05:00
|
|
|
public:
|
2007-12-01 00:00:00 +00:00
|
|
|
static void mark_all_nmethods_for_deoptimization();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
static int mark_for_deoptimization(Method* dependee);
|
2007-12-01 00:00:00 +00:00
|
|
|
static void make_marked_nmethods_not_entrant();
|
|
|
|
|
2015-01-06 19:30:28 -05:00
|
|
|
// Flushing and deoptimization
|
|
|
|
static void flush_dependents_on(instanceKlassHandle dependee);
|
|
|
|
#ifdef HOTSWAP
|
|
|
|
// Flushing and deoptimization in case of evolution
|
|
|
|
static void flush_evol_dependents_on(instanceKlassHandle dependee);
|
|
|
|
#endif // HOTSWAP
|
|
|
|
// Support for fullspeed debugging
|
|
|
|
static void flush_dependents_on_method(methodHandle dependee);
|
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
// tells how many nmethods have dependencies
|
2007-12-01 00:00:00 +00:00
|
|
|
static int number_of_nmethods_with_dependencies();
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2015-11-09 11:35:44 +01:00
|
|
|
static int get_codemem_full_count(int code_blob_type) {
|
|
|
|
CodeHeap* heap = get_code_heap(code_blob_type);
|
|
|
|
return (heap != NULL) ? heap->full_count() : 0;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
|
|
|
|
// Iterator to iterate over nmethods in the CodeCache.
|
2016-12-11 19:07:04 -08:00
|
|
|
template <class T, class Filter> class CodeBlobIterator : public StackObj {
|
2014-09-17 08:00:07 +02:00
|
|
|
private:
|
|
|
|
CodeBlob* _code_blob; // Current CodeBlob
|
2016-12-11 19:07:04 -08:00
|
|
|
GrowableArrayIterator<CodeHeap*> _heap;
|
|
|
|
GrowableArrayIterator<CodeHeap*> _end;
|
2014-09-17 08:00:07 +02:00
|
|
|
|
|
|
|
public:
|
2016-12-11 19:07:04 -08:00
|
|
|
CodeBlobIterator(T* nm = NULL) {
|
|
|
|
if (Filter::heaps() == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_heap = Filter::heaps()->begin();
|
|
|
|
_end = Filter::heaps()->end();
|
|
|
|
// If set to NULL, initialized by first call to next()
|
|
|
|
_code_blob = (CodeBlob*)nm;
|
|
|
|
if (nm != NULL) {
|
|
|
|
address start = nm->code_begin();
|
|
|
|
while(!(*_heap)->contains(start)) {
|
|
|
|
++_heap;
|
|
|
|
}
|
|
|
|
assert((*_heap)->contains(start), "match not found");
|
|
|
|
}
|
2014-09-17 08:00:07 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Advance iterator to next blob
|
2014-09-17 08:00:07 +02:00
|
|
|
bool next() {
|
|
|
|
assert_locked_or_safepoint(CodeCache_lock);
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
bool result = next_blob();
|
|
|
|
while (!result && _heap != _end) {
|
|
|
|
// Advance to next code heap of segmented code cache
|
|
|
|
if (++_heap == _end) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result = next_blob();
|
2014-09-17 08:00:07 +02:00
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Advance iterator to next alive blob
|
2014-09-17 08:00:07 +02:00
|
|
|
bool next_alive() {
|
|
|
|
bool result = next();
|
|
|
|
while(result && !_code_blob->is_alive()) {
|
|
|
|
result = next();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool end() const { return _code_blob == NULL; }
|
2016-12-11 19:07:04 -08:00
|
|
|
T* method() const { return (T*)_code_blob; }
|
2014-09-17 08:00:07 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
// Advance iterator to the next blob in the current code heap
|
|
|
|
bool next_blob() {
|
|
|
|
if (_heap == _end) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
CodeHeap *heap = *_heap;
|
2014-09-17 08:00:07 +02:00
|
|
|
// Get first method CodeBlob
|
|
|
|
if (_code_blob == NULL) {
|
2016-12-11 19:07:04 -08:00
|
|
|
_code_blob = CodeCache::first_blob(heap);
|
2014-09-17 08:00:07 +02:00
|
|
|
if (_code_blob == NULL) {
|
|
|
|
return false;
|
2016-12-11 19:07:04 -08:00
|
|
|
} else if (Filter::apply(_code_blob)) {
|
2014-09-17 08:00:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Search for next method CodeBlob
|
2016-12-11 19:07:04 -08:00
|
|
|
_code_blob = CodeCache::next_blob(heap, _code_blob);
|
|
|
|
while (_code_blob != NULL && !Filter::apply(_code_blob)) {
|
|
|
|
_code_blob = CodeCache::next_blob(heap, _code_blob);
|
2014-09-17 08:00:07 +02:00
|
|
|
}
|
|
|
|
return _code_blob != NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-26 10:28:51 +02:00
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
struct CompiledMethodFilter {
|
|
|
|
static bool apply(CodeBlob* cb) { return cb->is_compiled(); }
|
|
|
|
static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::compiled_heaps(); }
|
|
|
|
};
|
2016-04-26 10:28:51 +02:00
|
|
|
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
struct NMethodFilter {
|
|
|
|
static bool apply(CodeBlob* cb) { return cb->is_nmethod(); }
|
|
|
|
static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::nmethod_heaps(); }
|
|
|
|
};
|
2016-04-26 10:28:51 +02:00
|
|
|
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
typedef CodeBlobIterator<CompiledMethod, CompiledMethodFilter> CompiledMethodIterator;
|
|
|
|
typedef CodeBlobIterator<nmethod, NMethodFilter> NMethodIterator;
|
2016-04-26 10:28:51 +02:00
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#endif // SHARE_VM_CODE_CODECACHE_HPP
|