13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CODE_CODECACHE_HPP
26 #define SHARE_VM_CODE_CODECACHE_HPP
27
28 #include "code/codeBlob.hpp"
29 #include "memory/allocation.hpp"
30 #include "memory/heap.hpp"
31 #include "oops/instanceKlass.hpp"
32 #include "oops/oopsHierarchy.hpp"
33 #include "runtime/safepoint.hpp"
34
35 // The CodeCache implements the code cache for various pieces of generated
36 // code, e.g., compiled java methods, runtime stubs, transition frames, etc.
37 // The entries in the CodeCache are all CodeBlob's.
38
39 // Implementation:
40 // - Each CodeBlob occupies one chunk of memory.
41 // - Like the offset table in oldspace the zone has at table for
42 // locating a method given a addess of an instruction.
43
44 class OopClosure;
45 class DepChange;
46
47 class ParallelCodeCacheIterator VALUE_OBJ_CLASS_SPEC {
48 friend class CodeCache;
49 private:
50 volatile int _claimed_idx;
51 volatile bool _finished;
52 public:
53 ParallelCodeCacheIterator();
54 void parallel_blobs_do(CodeBlobClosure* f);
55 };
56
57 class CodeCache : AllStatic {
58 friend class VMStructs;
59 private:
60 // CodeHeap is malloc()'ed at startup and never deleted during shutdown,
61 // so that the generated assembly code is always there when it's needed.
62 // This may cause memory leak, but is necessary, for now. See 4423824,
63 // 4422213 or 4436291 for details.
64 static CodeHeap * _heap;
65 static int _number_of_blobs;
66 static int _number_of_adapters;
67 static int _number_of_nmethods;
68 static int _number_of_nmethods_with_dependencies;
69 static bool _needs_cache_clean;
70 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
71
72 static void verify_if_often() PRODUCT_RETURN;
73
74 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
75 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
76
77 static int _codemem_full_count;
78
124 result = NULL;
125 }
126 return result;
127 }
128
129 // Iteration
130 static CodeBlob* first();
131 static CodeBlob* next (CodeBlob* cb);
132 static CodeBlob* alive(CodeBlob *cb);
133 static nmethod* alive_nmethod(CodeBlob *cb);
134 static nmethod* first_nmethod();
135 static nmethod* next_nmethod (CodeBlob* cb);
136 static int nof_blobs() { return _number_of_blobs; }
137 static int nof_adapters() { return _number_of_adapters; }
138 static int nof_nmethods() { return _number_of_nmethods; }
139
140 // GC support
141 static void gc_epilogue();
142 static void gc_prologue();
143 static void verify_oops();
144
145 // Parallel GC support
146 static ParallelCodeCacheIterator parallel_iterator() {
147 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
148 return ParallelCodeCacheIterator();
149 }
150
151 // If "unloading_occurred" is true, then unloads (i.e., breaks root links
152 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
153 // to "true" iff some code got unloaded.
154 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
155 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
156 static void scavenge_root_nmethods_do(CodeBlobClosure* f);
157
158 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
159 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
160 static void add_scavenge_root_nmethod(nmethod* nm);
161 static void drop_scavenge_root_nmethod(nmethod* nm);
162 static void prune_scavenge_root_nmethods();
163
164 // Printing/debugging
165 static void print(); // prints summary
166 static void print_internals();
167 static void verify(); // verifies the code cache
168 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
169 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
170 static void log_state(outputStream* st);
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CODE_CODECACHE_HPP
26 #define SHARE_VM_CODE_CODECACHE_HPP
27
28 #include "code/codeBlob.hpp"
29 #include "memory/allocation.hpp"
30 #include "memory/heap.hpp"
31 #include "oops/instanceKlass.hpp"
32 #include "oops/oopsHierarchy.hpp"
33
34 // The CodeCache implements the code cache for various pieces of generated
35 // code, e.g., compiled java methods, runtime stubs, transition frames, etc.
36 // The entries in the CodeCache are all CodeBlob's.
37
38 // Implementation:
39 // - Each CodeBlob occupies one chunk of memory.
40 // - Like the offset table in oldspace the zone has at table for
41 // locating a method given a addess of an instruction.
42
43 class OopClosure;
44 class DepChange;
45 class ShenandoahParallelCodeCacheIterator;
46
47 class CodeCache : AllStatic {
48 friend class VMStructs;
49 friend class ShenandoahParallelCodeCacheIterator;
50 private:
51 // CodeHeap is malloc()'ed at startup and never deleted during shutdown,
52 // so that the generated assembly code is always there when it's needed.
53 // This may cause memory leak, but is necessary, for now. See 4423824,
54 // 4422213 or 4436291 for details.
55 static CodeHeap * _heap;
56 static int _number_of_blobs;
57 static int _number_of_adapters;
58 static int _number_of_nmethods;
59 static int _number_of_nmethods_with_dependencies;
60 static bool _needs_cache_clean;
61 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
62
63 static void verify_if_often() PRODUCT_RETURN;
64
65 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
66 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
67
68 static int _codemem_full_count;
69
115 result = NULL;
116 }
117 return result;
118 }
119
120 // Iteration
121 static CodeBlob* first();
122 static CodeBlob* next (CodeBlob* cb);
123 static CodeBlob* alive(CodeBlob *cb);
124 static nmethod* alive_nmethod(CodeBlob *cb);
125 static nmethod* first_nmethod();
126 static nmethod* next_nmethod (CodeBlob* cb);
127 static int nof_blobs() { return _number_of_blobs; }
128 static int nof_adapters() { return _number_of_adapters; }
129 static int nof_nmethods() { return _number_of_nmethods; }
130
131 // GC support
132 static void gc_epilogue();
133 static void gc_prologue();
134 static void verify_oops();
135 // If "unloading_occurred" is true, then unloads (i.e., breaks root links
136 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
137 // to "true" iff some code got unloaded.
138 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
139 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
140 static void scavenge_root_nmethods_do(CodeBlobClosure* f);
141
142 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
143 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
144 static void add_scavenge_root_nmethod(nmethod* nm);
145 static void drop_scavenge_root_nmethod(nmethod* nm);
146 static void prune_scavenge_root_nmethods();
147
148 // Printing/debugging
149 static void print(); // prints summary
150 static void print_internals();
151 static void verify(); // verifies the code cache
152 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
153 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
154 static void log_state(outputStream* st);
|