Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/code/codeCache.hpp
48785 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CODE_CODECACHE_HPP25#define SHARE_VM_CODE_CODECACHE_HPP2627#include "code/codeBlob.hpp"28#include "memory/allocation.hpp"29#include "memory/heap.hpp"30#include "oops/instanceKlass.hpp"31#include "oops/oopsHierarchy.hpp"3233// The CodeCache implements the code cache for various pieces of generated34// code, e.g., compiled java methods, runtime stubs, transition frames, etc.35// The entries in the CodeCache are all CodeBlob's.3637// Implementation:38// - Each CodeBlob occupies one chunk of memory.39// - Like the offset table in oldspace the zone has at table for40// locating a method given a addess of an instruction.4142class OopClosure;43class DepChange;4445class CodeCache : AllStatic {46friend class VMStructs;47private:48// CodeHeap is malloc()'ed at startup and never deleted during shutdown,49// so that the generated assembly code is always there when it's needed.50// This may cause memory leak, but is necessary, for now. See 4423824,51// 4422213 or 4436291 for details.52static CodeHeap * _heap;53static int _number_of_blobs;54static int _number_of_adapters;55static int _number_of_nmethods;56static int _number_of_nmethods_with_dependencies;57static bool _needs_cache_clean;58static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()5960static void verify_if_often() PRODUCT_RETURN;6162static void mark_scavenge_root_nmethods() PRODUCT_RETURN;63static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;6465static int _codemem_full_count;6667static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }68static void prune_scavenge_root_nmethods();69static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev);7071public:7273// Initialization74static void initialize();7576static void report_codemem_full();7778// Allocation/administration79static CodeBlob* allocate(int size, bool is_critical = false); // allocates a new CodeBlob80static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled81static int alignment_unit(); // guaranteed alignment of all CodeBlobs82static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)83static void free(CodeBlob* cb); // frees a CodeBlob84static void flush(); // flushes all CodeBlobs85static bool contains(void *p); // returns whether p is included86static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs87static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs88static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods89static void alive_nmethods_do(void f(nmethod* nm)); // iterates over all alive nmethods9091// Lookup92static CodeBlob* find_blob(void* start);93static nmethod* find_nmethod(void* start);9495// Lookup that does not fail if you lookup a zombie method (if you call this, be sure to know96// what you are doing)97static CodeBlob* find_blob_unsafe(void* start) {98// NMT can walk the stack before code cache is created99if (_heap == NULL) return NULL;100101CodeBlob* result = (CodeBlob*)_heap->find_start(start);102// this assert is too strong because the heap code will return the103// heapblock containing start. That block can often be larger than104// the codeBlob itself. If you look up an address that is within105// the heapblock but not in the codeBlob you will assert.106//107// Most things will not lookup such bad addresses. However108// AsyncGetCallTrace can see intermediate frames and get that kind109// of invalid address and so can a developer using hsfind.110//111// The more correct answer is to return NULL if blob_contains() returns112// false.113// assert(result == NULL || result->blob_contains((address)start), "found wrong CodeBlob");114115if (result != NULL && !result->blob_contains((address)start)) {116result = NULL;117}118return result;119}120121// Iteration122static CodeBlob* first();123static CodeBlob* next (CodeBlob* cb);124static CodeBlob* alive(CodeBlob *cb);125static nmethod* alive_nmethod(CodeBlob *cb);126static nmethod* first_nmethod();127static nmethod* next_nmethod (CodeBlob* cb);128static int nof_blobs() { return _number_of_blobs; }129static int nof_adapters() { return _number_of_adapters; }130static int nof_nmethods() { return _number_of_nmethods; }131132// GC support133static void gc_epilogue();134static void gc_prologue();135static void verify_oops();136// If "unloading_occurred" is true, then unloads (i.e., breaks root links137// to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"138// to "true" iff some code got unloaded.139static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);140static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;141142// Apply f to every live code blob in scavengable nmethods. Prune nmethods143// from the list of scavengable nmethods if f->fix_relocations() and a nmethod144// no longer has scavengable oops. If f->fix_relocations(), then f must copy145// objects to their new location immediately to avoid fixing nmethods on the146// basis of the old object locations.147static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);148149static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }150static void add_scavenge_root_nmethod(nmethod* nm);151static void drop_scavenge_root_nmethod(nmethod* nm);152153// Printing/debugging154static void print(); // prints summary155static void print_internals();156static void verify(); // verifies the code cache157static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;158static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage159static void log_state(outputStream* st);160161// The full limits of the codeCache162static address low_bound() { return (address) _heap->low_boundary(); }163static address high_bound() { return (address) _heap->high_boundary(); }164static address high() { return (address) _heap->high(); }165166// Profiling167static address first_address(); // first address used for CodeBlobs168static address last_address(); // last address used for CodeBlobs169static size_t capacity() { return _heap->capacity(); }170static size_t max_capacity() { return _heap->max_capacity(); }171static size_t unallocated_capacity() { return _heap->unallocated_capacity(); }172static double reverse_free_ratio();173174static bool needs_cache_clean() { return _needs_cache_clean; }175static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }176static void clear_inline_caches(); // clear all inline caches177178static void verify_clean_inline_caches();179static void verify_icholder_relocations();180181// Deoptimization182static int mark_for_deoptimization(DepChange& changes);183#ifdef HOTSWAP184static int mark_for_evol_deoptimization(instanceKlassHandle dependee);185#endif // HOTSWAP186187static void mark_all_nmethods_for_deoptimization();188static int mark_for_deoptimization(Method* dependee);189static void make_marked_nmethods_not_entrant();190191// tells how many nmethods have dependencies192static int number_of_nmethods_with_dependencies();193194static int get_codemem_full_count() { return _codemem_full_count; }195};196197#endif // SHARE_VM_CODE_CODECACHE_HPP198199200