36 #include "compiler/directivesParser.hpp"
37 #include "compiler/disassembler.hpp"
38 #include "interpreter/bytecode.hpp"
39 #include "logging/log.hpp"
40 #include "logging/logStream.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "oops/methodData.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "prims/jvm.h"
45 #include "prims/jvmtiImpl.hpp"
46 #include "runtime/atomic.hpp"
47 #include "runtime/orderAccess.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "runtime/sharedRuntime.hpp"
50 #include "runtime/sweeper.hpp"
51 #include "utilities/align.hpp"
52 #include "utilities/dtrace.hpp"
53 #include "utilities/events.hpp"
54 #include "utilities/resourceHash.hpp"
55 #include "utilities/xmlstream.hpp"
56 #ifdef SHARK
57 #include "shark/sharkCompiler.hpp"
58 #endif
59 #if INCLUDE_JVMCI
60 #include "jvmci/jvmciJavaClasses.hpp"
61 #endif
62
63 #ifdef DTRACE_ENABLED
64
65 // Only bother with this argument setup if dtrace is available
66
67 #define DTRACE_METHOD_UNLOAD_PROBE(method) \
68 { \
69 Method* m = (method); \
70 if (m != NULL) { \
71 Symbol* klass_name = m->klass_name(); \
72 Symbol* name = m->name(); \
73 Symbol* signature = m->signature(); \
74 HOTSPOT_COMPILED_METHOD_UNLOAD( \
75 (char *) klass_name->bytes(), klass_name->utf8_length(), \
76 (char *) name->bytes(), name->utf8_length(), \
77 (char *) signature->bytes(), signature->utf8_length()); \
78 } \
183 pc_desc_queries,
184 (double)(pc_desc_tests + pc_desc_searches)
185 / pc_desc_queries);
186 tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d",
187 pc_desc_resets,
188 pc_desc_queries, pc_desc_approx,
189 pc_desc_repeats, pc_desc_hits,
190 pc_desc_tests, pc_desc_searches, pc_desc_adds);
191 }
192 };
193
194 #ifdef COMPILER1
195 static java_nmethod_stats_struct c1_java_nmethod_stats;
196 #endif
197 #ifdef COMPILER2
198 static java_nmethod_stats_struct c2_java_nmethod_stats;
199 #endif
200 #if INCLUDE_JVMCI
201 static java_nmethod_stats_struct jvmci_java_nmethod_stats;
202 #endif
203 #ifdef SHARK
204 static java_nmethod_stats_struct shark_java_nmethod_stats;
205 #endif
206 static java_nmethod_stats_struct unknown_java_nmethod_stats;
207
208 static native_nmethod_stats_struct native_nmethod_stats;
209 static pc_nmethod_stats_struct pc_nmethod_stats;
210
211 static void note_java_nmethod(nmethod* nm) {
212 #ifdef COMPILER1
213 if (nm->is_compiled_by_c1()) {
214 c1_java_nmethod_stats.note_nmethod(nm);
215 } else
216 #endif
217 #ifdef COMPILER2
218 if (nm->is_compiled_by_c2()) {
219 c2_java_nmethod_stats.note_nmethod(nm);
220 } else
221 #endif
222 #if INCLUDE_JVMCI
223 if (nm->is_compiled_by_jvmci()) {
224 jvmci_java_nmethod_stats.note_nmethod(nm);
225 } else
226 #endif
227 #ifdef SHARK
228 if (nm->is_compiled_by_shark()) {
229 shark_java_nmethod_stats.note_nmethod(nm);
230 } else
231 #endif
232 {
233 unknown_java_nmethod_stats.note_nmethod(nm);
234 }
235 }
236 #endif // !PRODUCT
237
238 //---------------------------------------------------------------------------------
239
240
241 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) {
242 assert(pc != NULL, "Must be non null");
243 assert(exception.not_null(), "Must be non null");
244 assert(handler != NULL, "Must be non null");
245
246 _count = 0;
247 _exception_type = exception->klass();
248 _next = NULL;
249
250 add_address_and_handler(pc,handler);
251 }
1308 "/Free CodeCache:" SIZE_FORMAT "Kb",
1309 is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),
1310 CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024);
1311 }
1312
1313 // We need to deallocate any ExceptionCache data.
1314 // Note that we do not need to grab the nmethod lock for this, it
1315 // better be thread safe if we're disposing of it!
1316 ExceptionCache* ec = exception_cache();
1317 set_exception_cache(NULL);
1318 while(ec != NULL) {
1319 ExceptionCache* next = ec->next();
1320 delete ec;
1321 ec = next;
1322 }
1323
1324 if (on_scavenge_root_list()) {
1325 CodeCache::drop_scavenge_root_nmethod(this);
1326 }
1327
1328 #ifdef SHARK
1329 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin());
1330 #endif // SHARK
1331
1332 CodeBlob::flush();
1333 CodeCache::free(this);
1334 }
1335
1336 //
1337 // Notify all classes this nmethod is dependent on that it is no
1338 // longer dependent. This should only be called in two situations.
1339 // First, when a nmethod transitions to a zombie all dependents need
1340 // to be clear. Since zombification happens at a safepoint there's no
1341 // synchronization issues. The second place is a little more tricky.
1342 // During phase 1 of mark sweep class unloading may happen and as a
1343 // result some nmethods may get unloaded. In this case the flushing
1344 // of dependencies must happen during phase 1 since after GC any
1345 // dependencies in the unloaded nmethod won't be updated, so
1346 // traversing the dependency information in unsafe. In that case this
1347 // function is called with a non-NULL argument and this function only
1348 // notifies instanceKlasses that are reachable
1349
1350 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1351 assert_locked_or_safepoint(CodeCache_lock);
2228 if (!debug_scavenge_root.ok())
2229 fatal("found an unadvertised bad scavengable oop in the code cache");
2230 }
2231 assert(scavenge_root_not_marked(), "");
2232 }
2233
2234 #endif // PRODUCT
2235
2236 // Printing operations
2237
2238 void nmethod::print() const {
2239 ResourceMark rm;
2240 ttyLocker ttyl; // keep the following output all in one block
2241
2242 tty->print("Compiled method ");
2243
2244 if (is_compiled_by_c1()) {
2245 tty->print("(c1) ");
2246 } else if (is_compiled_by_c2()) {
2247 tty->print("(c2) ");
2248 } else if (is_compiled_by_shark()) {
2249 tty->print("(shark) ");
2250 } else if (is_compiled_by_jvmci()) {
2251 tty->print("(JVMCI) ");
2252 } else {
2253 tty->print("(nm) ");
2254 }
2255
2256 print_on(tty, NULL);
2257
2258 if (WizardMode) {
2259 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2260 tty->print(" for method " INTPTR_FORMAT , p2i(method()));
2261 tty->print(" { ");
2262 tty->print_cr("%s ", state());
2263 if (on_scavenge_root_list()) tty->print("scavenge_root ");
2264 tty->print_cr("}:");
2265 }
2266 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2267 p2i(this),
2268 p2i(this) + size(),
2269 size());
2850 void nmethod::print_handler_table() {
2851 ExceptionHandlerTable(this).print();
2852 }
2853
2854 void nmethod::print_nul_chk_table() {
2855 ImplicitExceptionTable(this).print(code_begin());
2856 }
2857
2858 void nmethod::print_statistics() {
2859 ttyLocker ttyl;
2860 if (xtty != NULL) xtty->head("statistics type='nmethod'");
2861 native_nmethod_stats.print_native_nmethod_stats();
2862 #ifdef COMPILER1
2863 c1_java_nmethod_stats.print_nmethod_stats("C1");
2864 #endif
2865 #ifdef COMPILER2
2866 c2_java_nmethod_stats.print_nmethod_stats("C2");
2867 #endif
2868 #if INCLUDE_JVMCI
2869 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
2870 #endif
2871 #ifdef SHARK
2872 shark_java_nmethod_stats.print_nmethod_stats("Shark");
2873 #endif
2874 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2875 DebugInformationRecorder::print_statistics();
2876 #ifndef PRODUCT
2877 pc_nmethod_stats.print_pc_stats();
2878 #endif
2879 Dependencies::print_statistics();
2880 if (xtty != NULL) xtty->tail("statistics");
2881 }
2882
2883 #endif // !PRODUCT
2884
2885 #if INCLUDE_JVMCI
2886 void nmethod::clear_jvmci_installed_code() {
2887 // write_ref_method_pre/post can only be safely called at a
2888 // safepoint or while holding the CodeCache_lock
2889 assert(CodeCache_lock->is_locked() ||
2890 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2891 if (_jvmci_installed_code != NULL) {
2892 // This must be done carefully to maintain nmethod remembered sets properly
|
36 #include "compiler/directivesParser.hpp"
37 #include "compiler/disassembler.hpp"
38 #include "interpreter/bytecode.hpp"
39 #include "logging/log.hpp"
40 #include "logging/logStream.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "oops/methodData.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "prims/jvm.h"
45 #include "prims/jvmtiImpl.hpp"
46 #include "runtime/atomic.hpp"
47 #include "runtime/orderAccess.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "runtime/sharedRuntime.hpp"
50 #include "runtime/sweeper.hpp"
51 #include "utilities/align.hpp"
52 #include "utilities/dtrace.hpp"
53 #include "utilities/events.hpp"
54 #include "utilities/resourceHash.hpp"
55 #include "utilities/xmlstream.hpp"
56 #if INCLUDE_JVMCI
57 #include "jvmci/jvmciJavaClasses.hpp"
58 #endif
59
60 #ifdef DTRACE_ENABLED
61
62 // Only bother with this argument setup if dtrace is available
63
64 #define DTRACE_METHOD_UNLOAD_PROBE(method) \
65 { \
66 Method* m = (method); \
67 if (m != NULL) { \
68 Symbol* klass_name = m->klass_name(); \
69 Symbol* name = m->name(); \
70 Symbol* signature = m->signature(); \
71 HOTSPOT_COMPILED_METHOD_UNLOAD( \
72 (char *) klass_name->bytes(), klass_name->utf8_length(), \
73 (char *) name->bytes(), name->utf8_length(), \
74 (char *) signature->bytes(), signature->utf8_length()); \
75 } \
180 pc_desc_queries,
181 (double)(pc_desc_tests + pc_desc_searches)
182 / pc_desc_queries);
183 tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d",
184 pc_desc_resets,
185 pc_desc_queries, pc_desc_approx,
186 pc_desc_repeats, pc_desc_hits,
187 pc_desc_tests, pc_desc_searches, pc_desc_adds);
188 }
189 };
190
191 #ifdef COMPILER1
192 static java_nmethod_stats_struct c1_java_nmethod_stats;
193 #endif
194 #ifdef COMPILER2
195 static java_nmethod_stats_struct c2_java_nmethod_stats;
196 #endif
197 #if INCLUDE_JVMCI
198 static java_nmethod_stats_struct jvmci_java_nmethod_stats;
199 #endif
200 static java_nmethod_stats_struct unknown_java_nmethod_stats;
201
202 static native_nmethod_stats_struct native_nmethod_stats;
203 static pc_nmethod_stats_struct pc_nmethod_stats;
204
205 static void note_java_nmethod(nmethod* nm) {
206 #ifdef COMPILER1
207 if (nm->is_compiled_by_c1()) {
208 c1_java_nmethod_stats.note_nmethod(nm);
209 } else
210 #endif
211 #ifdef COMPILER2
212 if (nm->is_compiled_by_c2()) {
213 c2_java_nmethod_stats.note_nmethod(nm);
214 } else
215 #endif
216 #if INCLUDE_JVMCI
217 if (nm->is_compiled_by_jvmci()) {
218 jvmci_java_nmethod_stats.note_nmethod(nm);
219 } else
220 #endif
221 {
222 unknown_java_nmethod_stats.note_nmethod(nm);
223 }
224 }
225 #endif // !PRODUCT
226
227 //---------------------------------------------------------------------------------
228
229
230 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) {
231 assert(pc != NULL, "Must be non null");
232 assert(exception.not_null(), "Must be non null");
233 assert(handler != NULL, "Must be non null");
234
235 _count = 0;
236 _exception_type = exception->klass();
237 _next = NULL;
238
239 add_address_and_handler(pc,handler);
240 }
1297 "/Free CodeCache:" SIZE_FORMAT "Kb",
1298 is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),
1299 CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024);
1300 }
1301
1302 // We need to deallocate any ExceptionCache data.
1303 // Note that we do not need to grab the nmethod lock for this, it
1304 // better be thread safe if we're disposing of it!
1305 ExceptionCache* ec = exception_cache();
1306 set_exception_cache(NULL);
1307 while(ec != NULL) {
1308 ExceptionCache* next = ec->next();
1309 delete ec;
1310 ec = next;
1311 }
1312
1313 if (on_scavenge_root_list()) {
1314 CodeCache::drop_scavenge_root_nmethod(this);
1315 }
1316
1317 CodeBlob::flush();
1318 CodeCache::free(this);
1319 }
1320
1321 //
1322 // Notify all classes this nmethod is dependent on that it is no
1323 // longer dependent. This should only be called in two situations.
1324 // First, when a nmethod transitions to a zombie all dependents need
1325 // to be clear. Since zombification happens at a safepoint there's no
1326 // synchronization issues. The second place is a little more tricky.
1327 // During phase 1 of mark sweep class unloading may happen and as a
1328 // result some nmethods may get unloaded. In this case the flushing
1329 // of dependencies must happen during phase 1 since after GC any
1330 // dependencies in the unloaded nmethod won't be updated, so
1331 // traversing the dependency information in unsafe. In that case this
1332 // function is called with a non-NULL argument and this function only
1333 // notifies instanceKlasses that are reachable
1334
1335 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1336 assert_locked_or_safepoint(CodeCache_lock);
2213 if (!debug_scavenge_root.ok())
2214 fatal("found an unadvertised bad scavengable oop in the code cache");
2215 }
2216 assert(scavenge_root_not_marked(), "");
2217 }
2218
2219 #endif // PRODUCT
2220
2221 // Printing operations
2222
2223 void nmethod::print() const {
2224 ResourceMark rm;
2225 ttyLocker ttyl; // keep the following output all in one block
2226
2227 tty->print("Compiled method ");
2228
2229 if (is_compiled_by_c1()) {
2230 tty->print("(c1) ");
2231 } else if (is_compiled_by_c2()) {
2232 tty->print("(c2) ");
2233 } else if (is_compiled_by_jvmci()) {
2234 tty->print("(JVMCI) ");
2235 } else {
2236 tty->print("(nm) ");
2237 }
2238
2239 print_on(tty, NULL);
2240
2241 if (WizardMode) {
2242 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2243 tty->print(" for method " INTPTR_FORMAT , p2i(method()));
2244 tty->print(" { ");
2245 tty->print_cr("%s ", state());
2246 if (on_scavenge_root_list()) tty->print("scavenge_root ");
2247 tty->print_cr("}:");
2248 }
2249 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2250 p2i(this),
2251 p2i(this) + size(),
2252 size());
2833 void nmethod::print_handler_table() {
2834 ExceptionHandlerTable(this).print();
2835 }
2836
2837 void nmethod::print_nul_chk_table() {
2838 ImplicitExceptionTable(this).print(code_begin());
2839 }
2840
2841 void nmethod::print_statistics() {
2842 ttyLocker ttyl;
2843 if (xtty != NULL) xtty->head("statistics type='nmethod'");
2844 native_nmethod_stats.print_native_nmethod_stats();
2845 #ifdef COMPILER1
2846 c1_java_nmethod_stats.print_nmethod_stats("C1");
2847 #endif
2848 #ifdef COMPILER2
2849 c2_java_nmethod_stats.print_nmethod_stats("C2");
2850 #endif
2851 #if INCLUDE_JVMCI
2852 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
2853 #endif
2854 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2855 DebugInformationRecorder::print_statistics();
2856 #ifndef PRODUCT
2857 pc_nmethod_stats.print_pc_stats();
2858 #endif
2859 Dependencies::print_statistics();
2860 if (xtty != NULL) xtty->tail("statistics");
2861 }
2862
2863 #endif // !PRODUCT
2864
2865 #if INCLUDE_JVMCI
2866 void nmethod::clear_jvmci_installed_code() {
2867 // write_ref_method_pre/post can only be safely called at a
2868 // safepoint or while holding the CodeCache_lock
2869 assert(CodeCache_lock->is_locked() ||
2870 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2871 if (_jvmci_installed_code != NULL) {
2872 // This must be done carefully to maintain nmethod remembered sets properly
|