/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
* 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.
*
*/
#ifndef SHARE_VM_CODE_CODECACHE_HPP
#define SHARE_VM_CODE_CODECACHE_HPP
#include "code/codeBlob.hpp"
#include "memory/allocation.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/oopsHierarchy.hpp"
// 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.
// Implementation:
// - Each CodeBlob occupies one chunk of memory.
// - Like the offset table in oldspace the zone has at table for
// locating a method given a addess of an instruction.
class OopClosure;
class DepChange;
friend class VMStructs;
private:
// CodeHeap is malloc()'ed at startup and never deleted during shutdown,
// so that the generated assembly code is always there when it's needed.
// This may cause memory leak, but is necessary, for now. See 4423824,
// 4422213 or 4436291 for details.
static int _number_of_blobs;
static int _number_of_adapters;
static int _number_of_nmethods;
static int _number_of_nmethods_with_dependencies;
static bool _needs_cache_clean;
static int _codemem_full_count;
public:
// Initialization
static void initialize();
static void report_codemem_full();
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 flush(); // flushes all CodeBlobs
static bool contains(void *p); // returns whether p is included
// Lookup
// Lookup that does not fail if you lookup a zombie method (if you call this, be sure to know
// what you are doing)
// NMT can walk the stack before code cache is created
// this assert is too strong because the heap code will return the
// heapblock containing start. That block can often be larger than
// the codeBlob itself. If you look up an address that is within
// the heapblock but not in the codeBlob you will assert.
//
// Most things will not lookup such bad addresses. However
// AsyncGetCallTrace can see intermediate frames and get that kind
// of invalid address and so can a developer using hsfind.
//
// The more correct answer is to return NULL if blob_contains() returns
// false.
// assert(result == NULL || result->blob_contains((address)start), "found wrong CodeBlob");
}
return result;
}
// Iteration
static nmethod* first_nmethod();
// GC support
static void gc_epilogue();
static void gc_prologue();
static void verify_oops();
// 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.
bool unloading_occurred);
}
static void scavenge_root_nmethods_do(CodeBlobClosure* f);
static void prune_scavenge_root_nmethods();
static void print_internals();
static void verify(); // verifies the code cache
// The full limits of the codeCache
// Profiling
static size_t largest_free_block();
static void clear_inline_caches(); // clear all inline caches
// Deoptimization
#ifdef HOTSWAP
#endif // HOTSWAP
static void mark_all_nmethods_for_deoptimization();
static void make_marked_nmethods_zombies();
static void make_marked_nmethods_not_entrant();
// tells how many nmethods have dependencies
static int number_of_nmethods_with_dependencies();
};
#endif // SHARE_VM_CODE_CODECACHE_HPP