src/share/vm/code/codeCache.hpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8074
c1950f51ed60
parent 7535
7ae4e26cb1e0
child 9703
2fdf635bcf28
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CODE_CODECACHE_HPP
aoqi@0 26 #define SHARE_VM_CODE_CODECACHE_HPP
aoqi@0 27
aoqi@0 28 #include "code/codeBlob.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "memory/heap.hpp"
aoqi@0 31 #include "oops/instanceKlass.hpp"
aoqi@0 32 #include "oops/oopsHierarchy.hpp"
aoqi@0 33
aoqi@0 34 // The CodeCache implements the code cache for various pieces of generated
aoqi@0 35 // code, e.g., compiled java methods, runtime stubs, transition frames, etc.
aoqi@0 36 // The entries in the CodeCache are all CodeBlob's.
aoqi@0 37
aoqi@0 38 // Implementation:
aoqi@0 39 // - Each CodeBlob occupies one chunk of memory.
aoqi@0 40 // - Like the offset table in oldspace the zone has at table for
aoqi@0 41 // locating a method given a addess of an instruction.
aoqi@0 42
aoqi@0 43 class OopClosure;
aoqi@0 44 class DepChange;
aoqi@0 45
aoqi@0 46 class CodeCache : AllStatic {
aoqi@0 47 friend class VMStructs;
aoqi@0 48 private:
aoqi@0 49 // CodeHeap is malloc()'ed at startup and never deleted during shutdown,
aoqi@0 50 // so that the generated assembly code is always there when it's needed.
aoqi@0 51 // This may cause memory leak, but is necessary, for now. See 4423824,
aoqi@0 52 // 4422213 or 4436291 for details.
aoqi@0 53 static CodeHeap * _heap;
aoqi@0 54 static int _number_of_blobs;
aoqi@0 55 static int _number_of_adapters;
aoqi@0 56 static int _number_of_nmethods;
aoqi@0 57 static int _number_of_nmethods_with_dependencies;
aoqi@0 58 static bool _needs_cache_clean;
aoqi@0 59 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
aoqi@0 60
aoqi@0 61 static void verify_if_often() PRODUCT_RETURN;
aoqi@0 62
aoqi@0 63 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
aoqi@0 64 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
aoqi@0 65
aoqi@0 66 static int _codemem_full_count;
aoqi@0 67
aoqi@0 68 public:
aoqi@0 69
aoqi@0 70 // Initialization
aoqi@0 71 static void initialize();
aoqi@0 72
aoqi@0 73 static void report_codemem_full();
aoqi@0 74
aoqi@0 75 // Allocation/administration
aoqi@0 76 static CodeBlob* allocate(int size, bool is_critical = false); // allocates a new CodeBlob
aoqi@0 77 static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
aoqi@0 78 static int alignment_unit(); // guaranteed alignment of all CodeBlobs
aoqi@0 79 static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
aoqi@0 80 static void free(CodeBlob* cb); // frees a CodeBlob
aoqi@0 81 static void flush(); // flushes all CodeBlobs
aoqi@0 82 static bool contains(void *p); // returns whether p is included
aoqi@0 83 static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs
aoqi@0 84 static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs
aoqi@0 85 static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods
aoqi@0 86 static void alive_nmethods_do(void f(nmethod* nm)); // iterates over all alive nmethods
aoqi@0 87
aoqi@0 88 // Lookup
aoqi@0 89 static CodeBlob* find_blob(void* start);
aoqi@0 90 static nmethod* find_nmethod(void* start);
aoqi@0 91
aoqi@0 92 // Lookup that does not fail if you lookup a zombie method (if you call this, be sure to know
aoqi@0 93 // what you are doing)
aoqi@0 94 static CodeBlob* find_blob_unsafe(void* start) {
aoqi@0 95 // NMT can walk the stack before code cache is created
aoqi@0 96 if (_heap == NULL) return NULL;
aoqi@0 97
aoqi@0 98 CodeBlob* result = (CodeBlob*)_heap->find_start(start);
aoqi@0 99 // this assert is too strong because the heap code will return the
aoqi@0 100 // heapblock containing start. That block can often be larger than
aoqi@0 101 // the codeBlob itself. If you look up an address that is within
aoqi@0 102 // the heapblock but not in the codeBlob you will assert.
aoqi@0 103 //
aoqi@0 104 // Most things will not lookup such bad addresses. However
aoqi@0 105 // AsyncGetCallTrace can see intermediate frames and get that kind
aoqi@0 106 // of invalid address and so can a developer using hsfind.
aoqi@0 107 //
aoqi@0 108 // The more correct answer is to return NULL if blob_contains() returns
aoqi@0 109 // false.
aoqi@0 110 // assert(result == NULL || result->blob_contains((address)start), "found wrong CodeBlob");
aoqi@0 111
aoqi@0 112 if (result != NULL && !result->blob_contains((address)start)) {
aoqi@0 113 result = NULL;
aoqi@0 114 }
aoqi@0 115 return result;
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 // Iteration
aoqi@0 119 static CodeBlob* first();
aoqi@0 120 static CodeBlob* next (CodeBlob* cb);
aoqi@0 121 static CodeBlob* alive(CodeBlob *cb);
aoqi@0 122 static nmethod* alive_nmethod(CodeBlob *cb);
aoqi@0 123 static nmethod* first_nmethod();
aoqi@0 124 static nmethod* next_nmethod (CodeBlob* cb);
aoqi@0 125 static int nof_blobs() { return _number_of_blobs; }
aoqi@0 126 static int nof_adapters() { return _number_of_adapters; }
aoqi@0 127 static int nof_nmethods() { return _number_of_nmethods; }
aoqi@0 128
aoqi@0 129 // GC support
aoqi@0 130 static void gc_epilogue();
aoqi@0 131 static void gc_prologue();
aoqi@0 132 static void verify_oops();
aoqi@0 133 // If "unloading_occurred" is true, then unloads (i.e., breaks root links
aoqi@0 134 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
aoqi@0 135 // to "true" iff some code got unloaded.
aoqi@0 136 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
aoqi@0 137 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
aoqi@0 138 static void scavenge_root_nmethods_do(CodeBlobClosure* f);
aoqi@0 139
aoqi@0 140 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
aoqi@0 141 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
aoqi@0 142 static void add_scavenge_root_nmethod(nmethod* nm);
aoqi@0 143 static void drop_scavenge_root_nmethod(nmethod* nm);
aoqi@0 144 static void prune_scavenge_root_nmethods();
aoqi@0 145
aoqi@0 146 // Printing/debugging
aoqi@0 147 static void print(); // prints summary
aoqi@0 148 static void print_internals();
aoqi@0 149 static void verify(); // verifies the code cache
aoqi@0 150 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
aoqi@0 151 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
aoqi@0 152 static void log_state(outputStream* st);
aoqi@0 153
aoqi@0 154 // The full limits of the codeCache
aoqi@0 155 static address low_bound() { return (address) _heap->low_boundary(); }
aoqi@0 156 static address high_bound() { return (address) _heap->high_boundary(); }
aoqi@0 157 static address high() { return (address) _heap->high(); }
aoqi@0 158
aoqi@0 159 // Profiling
aoqi@0 160 static address first_address(); // first address used for CodeBlobs
aoqi@0 161 static address last_address(); // last address used for CodeBlobs
aoqi@0 162 static size_t capacity() { return _heap->capacity(); }
aoqi@0 163 static size_t max_capacity() { return _heap->max_capacity(); }
aoqi@0 164 static size_t unallocated_capacity() { return _heap->unallocated_capacity(); }
aoqi@0 165 static double reverse_free_ratio();
aoqi@0 166
aoqi@0 167 static bool needs_cache_clean() { return _needs_cache_clean; }
aoqi@0 168 static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }
aoqi@0 169 static void clear_inline_caches(); // clear all inline caches
aoqi@0 170
stefank@6992 171 static void verify_clean_inline_caches();
stefank@6992 172 static void verify_icholder_relocations();
stefank@6992 173
aoqi@0 174 // Deoptimization
aoqi@0 175 static int mark_for_deoptimization(DepChange& changes);
aoqi@0 176 #ifdef HOTSWAP
aoqi@0 177 static int mark_for_evol_deoptimization(instanceKlassHandle dependee);
aoqi@0 178 #endif // HOTSWAP
aoqi@0 179
aoqi@0 180 static void mark_all_nmethods_for_deoptimization();
aoqi@0 181 static int mark_for_deoptimization(Method* dependee);
aoqi@0 182 static void make_marked_nmethods_not_entrant();
aoqi@0 183
aoqi@0 184 // tells how many nmethods have dependencies
aoqi@0 185 static int number_of_nmethods_with_dependencies();
aoqi@0 186
aoqi@0 187 static int get_codemem_full_count() { return _codemem_full_count; }
aoqi@0 188 };
aoqi@0 189
aoqi@0 190 #endif // SHARE_VM_CODE_CODECACHE_HPP

mercurial