codeCache.hpp revision 196:d1605aabd0a1
198186Sgordon/* 298186Sgordon * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 378344Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 498186Sgordon * 578344Sobrien * This code is free software; you can redistribute it and/or modify it 678344Sobrien * under the terms of the GNU General Public License version 2 only, as 778344Sobrien * published by the Free Software Foundation. 878344Sobrien * 978344Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1078344Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1178344Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1278344Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1378344Sobrien * accompanied this code). 1478344Sobrien * 1578344Sobrien * You should have received a copy of the GNU General Public License version 1678344Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1778344Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1878344Sobrien * 1978344Sobrien * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2078344Sobrien * CA 95054 USA or visit www.sun.com if you need additional information or 2178344Sobrien * have any questions. 2278344Sobrien * 2378344Sobrien */ 2478344Sobrien 2578344Sobrien// The CodeCache implements the code cache for various pieces of generated 2678344Sobrien// code, e.g., compiled java methods, runtime stubs, transition frames, etc. 2778344Sobrien// The entries in the CodeCache are all CodeBlob's. 2878344Sobrien 2978344Sobrien// Implementation: 3078344Sobrien// - Each CodeBlob occupies one chunk of memory. 3178344Sobrien// - Like the offset table in oldspace the zone has at table for 3278344Sobrien// locating a method given a addess of an instruction. 3378344Sobrien 3478344Sobrienclass OopClosure; 3578344Sobrienclass DepChange; 3678344Sobrien 3778344Sobrienclass CodeCache : AllStatic { 3878344Sobrien friend class VMStructs; 3978344Sobrien private: 4078344Sobrien // CodeHeap is malloc()'ed at startup and never deleted during shutdown, 4178344Sobrien // so that the generated assembly code is always there when it's needed. 4278344Sobrien // This may cause memory leak, but is necessary, for now. See 4423824, 4398186Sgordon // 4422213 or 4436291 for details. 4498186Sgordon static CodeHeap * _heap; 4598186Sgordon static int _number_of_blobs; 4698186Sgordon static int _number_of_nmethods_with_dependencies; 4798186Sgordon static bool _needs_cache_clean; 4898186Sgordon 49103018Sgordon static void verify_if_often() PRODUCT_RETURN; 5098186Sgordon public: 51103018Sgordon 5298186Sgordon // Initialization 5398186Sgordon static void initialize(); 5498186Sgordon 5598186Sgordon // Allocation/administration 5698186Sgordon static CodeBlob* allocate(int size); // allocates a new CodeBlob 5798186Sgordon static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled 5898186Sgordon static int alignment_unit(); // guaranteed alignment of all CodeBlobs 5998186Sgordon static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header) 6098186Sgordon static void free(CodeBlob* cb); // frees a CodeBlob 6178344Sobrien static void flush(); // flushes all CodeBlobs 6278344Sobrien static bool contains(void *p); // returns whether p is included 6378344Sobrien static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs 6478344Sobrien static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods 6598186Sgordon 6698186Sgordon // Lookup 6798186Sgordon static CodeBlob* find_blob(void* start); 6898186Sgordon static nmethod* find_nmethod(void* start); 6998186Sgordon 7098186Sgordon // Lookup that does not fail if you lookup a zombie method (if you call this, be sure to know 7198186Sgordon // what you are doing) 7298186Sgordon static CodeBlob* find_blob_unsafe(void* start) { 7398186Sgordon CodeBlob* result = (CodeBlob*)_heap->find_start(start); 7498186Sgordon // this assert is too strong because the heap code will return the 7598186Sgordon // heapblock containing start. That block can often be larger than 7698186Sgordon // the codeBlob itself. If you look up an address that is within 7798186Sgordon // the heapblock but not in the codeBlob you will assert. 7898186Sgordon // 7998186Sgordon // Most things will not lookup such bad addresses. However 8098186Sgordon // AsyncGetCallTrace can see intermediate frames and get that kind 8198186Sgordon // of invalid address and so can a developer using hsfind. 82103018Sgordon // 8398186Sgordon // The more correct answer is to return NULL if blob_contains() returns 8498186Sgordon // false. 8598186Sgordon // assert(result == NULL || result->blob_contains((address)start), "found wrong CodeBlob"); 8698186Sgordon 8798186Sgordon if (result != NULL && !result->blob_contains((address)start)) { 8898186Sgordon result = NULL; 8998186Sgordon } 9098186Sgordon return result; 9198186Sgordon } 9298186Sgordon 9398186Sgordon // Iteration 9498186Sgordon static CodeBlob* first(); 9598186Sgordon static CodeBlob* next (CodeBlob* cb); 9698186Sgordon static CodeBlob* alive(CodeBlob *cb); 9798186Sgordon static nmethod* alive_nmethod(CodeBlob *cb); 9898186Sgordon static int nof_blobs() { return _number_of_blobs; } 9998186Sgordon 10098186Sgordon // GC support 10198186Sgordon static void gc_epilogue(); 10298186Sgordon static void gc_prologue(); 10398186Sgordon // If "unloading_occurred" is true, then unloads (i.e., breaks root links 10498186Sgordon // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading" 10598186Sgordon // to "true" iff some code got unloaded. 10698186Sgordon static void do_unloading(BoolObjectClosure* is_alive, 10798186Sgordon OopClosure* keep_alive, 10898186Sgordon bool unloading_occurred); 10998186Sgordon static void oops_do(OopClosure* f); 11098186Sgordon 11198186Sgordon // Printing/debugging 11298186Sgordon static void print() PRODUCT_RETURN; // prints summary 11398186Sgordon static void print_internals(); 11498186Sgordon static void verify(); // verifies the code cache 11578344Sobrien 11678344Sobrien // The full limits of the codeCache 11778344Sobrien static address low_bound() { return (address) _heap->low_boundary(); } 11878344Sobrien static address high_bound() { return (address) _heap->high_boundary(); } 11978344Sobrien 12078344Sobrien // Profiling 12178344Sobrien static address first_address(); // first address used for CodeBlobs 12298186Sgordon static address last_address(); // last address used for CodeBlobs 12378344Sobrien static size_t capacity() { return _heap->capacity(); } 12478344Sobrien static size_t max_capacity() { return _heap->max_capacity(); } 12578344Sobrien static size_t unallocated_capacity() { return _heap->unallocated_capacity(); } 12678344Sobrien 12778344Sobrien static bool needs_cache_clean() { return _needs_cache_clean; } 12878344Sobrien static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; } 12978344Sobrien static void clear_inline_caches(); // clear all inline caches 13078344Sobrien 13178344Sobrien // Deoptimization 13278344Sobrien static int mark_for_deoptimization(DepChange& changes); 13378344Sobrien#ifdef HOTSWAP 13478344Sobrien static int mark_for_evol_deoptimization(instanceKlassHandle dependee); 135106643Sgordon#endif // HOTSWAP 13678344Sobrien 13778344Sobrien static void mark_all_nmethods_for_deoptimization(); 13878344Sobrien static int mark_for_deoptimization(methodOop dependee); 13978344Sobrien static void make_marked_nmethods_zombies(); 14078344Sobrien static void make_marked_nmethods_not_entrant(); 14198186Sgordon 14298186Sgordon // tells how many nmethods have dependencies 14378344Sobrien static int number_of_nmethods_with_dependencies(); 14498186Sgordon}; 14598186Sgordon