CodeBlob* CodeCache::allocate(int size) { // Do not seize the CodeCache lock here--if the caller has not // already done so, we are going to lose bigtime, since the code // cache will contain a garbage CodeBlob until the caller can // run the constructor for the CodeBlob subclass he is busy // instantiating. guarantee(size >= 0, "allocation request must be reasonable"); assert_locked_or_safepoint(CodeCache_lock); CodeBlob* cb = NULL; _number_of_blobs++; while (true) { cb = (CodeBlob*)_heap->allocate(size); if (cb != NULL) break; if (!_heap->expand_by(CodeCacheExpansionSize)) { // Expansion failed return NULL; } if (PrintCodeCacheExtension) { ResourceMark rm; tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%d bytes)", (intptr_t)_heap->begin(), (intptr_t)_heap->end(), (address)_heap->end() - (address)_heap->begin()); } } verify_if_often(); print_trace("allocation", cb, size); return cb; }
void CodeCache::free(CodeBlob* cb) { assert_locked_or_safepoint(CodeCache_lock); verify_if_often(); if (PrintCodeCache2) { // Need to add a new flag ResourceMark rm; tty->print_cr("CodeCache free: addr: " INTPTR_FORMAT ", size: 0x%x\n", cb, cb->size()); } #ifndef CORE if (cb->is_nmethod() && ((nmethod *)cb)->number_of_dependents() > 0) { _number_of_nmethods_with_dependencies--; } #endif _number_of_blobs--; _heap->deallocate(cb); verify_if_often(); assert(_number_of_blobs >= 0, "sanity check"); }
void CodeCache::free(CodeBlob* cb) { assert_locked_or_safepoint(CodeCache_lock); verify_if_often(); print_trace("free", cb); if (cb->is_nmethod()) { _number_of_nmethods--; if (((nmethod *)cb)->has_dependencies()) { _number_of_nmethods_with_dependencies--; } } if (cb->is_adapter_blob()) { _number_of_adapters--; } _number_of_blobs--; _heap->deallocate(cb); verify_if_often(); assert(_number_of_blobs >= 0, "sanity check"); }
void zone::flush() { ResourceMark rm; TraceTime t("Flushing method cache...", PrintCodeReclamation); EventMarker em("flushing method cache"); // Deoptimize all stack frames Processes::deoptimize_all(); FOR_ALL_NMETHODS(p) { p->makeZombie(true); } flushZombies(false); verify_if_often(); }
nmethod* zone::allocate(int size) { // CSect cs(profilerSemaphore); // for profiler // must get method ID here! (because reclaim might change firstFree) // (compiler may have used peekID to get ID of new nmethod for LRU stuff) if (needsSweep()) doSweep(); nmethod* n = (nmethod*) methodHeap->allocate(size); if (n == NULL) { // allocation failed so flush zombies and retry flushZombies(); n = (nmethod*) methodHeap->allocate(size); if (n == NULL) { print(); fatal("cannot allocate enough space for nmethod"); } } verify_if_often(); return n; }