Mercurial > hg > graal-compiler
annotate src/share/vm/code/nmethod.cpp @ 9097:a0ab945fb95f
build output during buildvms command is sent to console (instead of log files) if -c option is given
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 22:13:26 +0200 |
parents | c6a1ffc707ff |
children | fe9a18fbb15e 197426668a5d |
rev | line source |
---|---|
7066 | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
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 #include "precompiled.hpp" | |
26 #include "code/codeCache.hpp" | |
27 #include "code/compiledIC.hpp" | |
28 #include "code/dependencies.hpp" | |
29 #include "code/nmethod.hpp" | |
30 #include "code/scopeDesc.hpp" | |
31 #include "compiler/abstractCompiler.hpp" | |
32 #include "compiler/compileBroker.hpp" | |
33 #include "compiler/compileLog.hpp" | |
34 #include "compiler/compilerOracle.hpp" | |
35 #include "compiler/disassembler.hpp" | |
36 #include "interpreter/bytecode.hpp" | |
37 #include "oops/methodData.hpp" | |
38 #include "prims/jvmtiRedefineClassesTrace.hpp" | |
39 #include "prims/jvmtiImpl.hpp" | |
40 #include "runtime/sharedRuntime.hpp" | |
41 #include "runtime/sweeper.hpp" | |
42 #include "utilities/dtrace.hpp" | |
43 #include "utilities/events.hpp" | |
44 #include "utilities/xmlstream.hpp" | |
45 #ifdef SHARK | |
46 #include "shark/sharkCompiler.hpp" | |
47 #endif | |
8160
a357b7a3de5e
Fix imports.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8159
diff
changeset
|
48 #ifdef GRAAL |
a357b7a3de5e
Fix imports.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8159
diff
changeset
|
49 #include "graal/graalJavaAccess.hpp" |
a357b7a3de5e
Fix imports.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8159
diff
changeset
|
50 #endif |
7066 | 51 |
52 #ifdef DTRACE_ENABLED | |
53 | |
54 // Only bother with this argument setup if dtrace is available | |
55 | |
56 #ifndef USDT2 | |
57 HS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load, | |
58 const char*, int, const char*, int, const char*, int, void*, size_t); | |
59 | |
60 HS_DTRACE_PROBE_DECL6(hotspot, compiled__method__unload, | |
61 char*, int, char*, int, char*, int); | |
62 | |
63 #define DTRACE_METHOD_UNLOAD_PROBE(method) \ | |
64 { \ | |
65 Method* m = (method); \ | |
66 if (m != NULL) { \ | |
67 Symbol* klass_name = m->klass_name(); \ | |
68 Symbol* name = m->name(); \ | |
69 Symbol* signature = m->signature(); \ | |
70 HS_DTRACE_PROBE6(hotspot, compiled__method__unload, \ | |
71 klass_name->bytes(), klass_name->utf8_length(), \ | |
72 name->bytes(), name->utf8_length(), \ | |
73 signature->bytes(), signature->utf8_length()); \ | |
74 } \ | |
75 } | |
76 #else /* USDT2 */ | |
77 #define DTRACE_METHOD_UNLOAD_PROBE(method) \ | |
78 { \ | |
79 Method* m = (method); \ | |
80 if (m != NULL) { \ | |
81 Symbol* klass_name = m->klass_name(); \ | |
82 Symbol* name = m->name(); \ | |
83 Symbol* signature = m->signature(); \ | |
84 HOTSPOT_COMPILED_METHOD_UNLOAD( \ | |
85 (char *) klass_name->bytes(), klass_name->utf8_length(), \ | |
86 (char *) name->bytes(), name->utf8_length(), \ | |
87 (char *) signature->bytes(), signature->utf8_length()); \ | |
88 } \ | |
89 } | |
90 #endif /* USDT2 */ | |
91 | |
92 #else // ndef DTRACE_ENABLED | |
93 | |
94 #define DTRACE_METHOD_UNLOAD_PROBE(method) | |
95 | |
96 #endif | |
97 | |
98 bool nmethod::is_compiled_by_c1() const { | |
99 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing | |
100 if (is_native_method()) return false; | |
101 return compiler()->is_c1(); | |
102 } | |
7125
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
103 bool nmethod::is_compiled_by_graal() const { |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
104 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
105 if (is_native_method()) return false; |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
106 return compiler()->is_graal(); |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
107 } |
7066 | 108 bool nmethod::is_compiled_by_c2() const { |
109 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing | |
110 if (is_native_method()) return false; | |
111 return compiler()->is_c2(); | |
112 } | |
113 bool nmethod::is_compiled_by_shark() const { | |
114 if (is_native_method()) return false; | |
115 assert(compiler() != NULL, "must be"); | |
116 return compiler()->is_shark(); | |
117 } | |
118 | |
119 | |
120 | |
121 //--------------------------------------------------------------------------------- | |
122 // NMethod statistics | |
123 // They are printed under various flags, including: | |
124 // PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation. | |
125 // (In the latter two cases, they like other stats are printed to the log only.) | |
126 | |
8152
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
127 #ifndef PRODUCT |
7066 | 128 // These variables are put into one block to reduce relocations |
129 // and make it simpler to print from the debugger. | |
130 static | |
131 struct nmethod_stats_struct { | |
132 int nmethod_count; | |
133 int total_size; | |
134 int relocation_size; | |
135 int consts_size; | |
136 int insts_size; | |
137 int stub_size; | |
138 int scopes_data_size; | |
139 int scopes_pcs_size; | |
140 int dependencies_size; | |
141 int handler_table_size; | |
142 int nul_chk_table_size; | |
143 int oops_size; | |
144 | |
145 void note_nmethod(nmethod* nm) { | |
146 nmethod_count += 1; | |
147 total_size += nm->size(); | |
148 relocation_size += nm->relocation_size(); | |
149 consts_size += nm->consts_size(); | |
150 insts_size += nm->insts_size(); | |
151 stub_size += nm->stub_size(); | |
152 oops_size += nm->oops_size(); | |
153 scopes_data_size += nm->scopes_data_size(); | |
154 scopes_pcs_size += nm->scopes_pcs_size(); | |
155 dependencies_size += nm->dependencies_size(); | |
156 handler_table_size += nm->handler_table_size(); | |
157 nul_chk_table_size += nm->nul_chk_table_size(); | |
158 } | |
159 void print_nmethod_stats() { | |
160 if (nmethod_count == 0) return; | |
161 tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count); | |
162 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); | |
163 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); | |
164 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); | |
165 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); | |
166 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); | |
167 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); | |
168 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); | |
169 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); | |
170 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); | |
171 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); | |
172 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); | |
173 } | |
174 | |
175 int native_nmethod_count; | |
176 int native_total_size; | |
177 int native_relocation_size; | |
178 int native_insts_size; | |
179 int native_oops_size; | |
180 void note_native_nmethod(nmethod* nm) { | |
181 native_nmethod_count += 1; | |
182 native_total_size += nm->size(); | |
183 native_relocation_size += nm->relocation_size(); | |
184 native_insts_size += nm->insts_size(); | |
185 native_oops_size += nm->oops_size(); | |
186 } | |
187 void print_native_nmethod_stats() { | |
188 if (native_nmethod_count == 0) return; | |
189 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); | |
190 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); | |
191 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); | |
192 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); | |
193 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); | |
194 } | |
195 | |
196 int pc_desc_resets; // number of resets (= number of caches) | |
197 int pc_desc_queries; // queries to nmethod::find_pc_desc | |
198 int pc_desc_approx; // number of those which have approximate true | |
199 int pc_desc_repeats; // number of _pc_descs[0] hits | |
200 int pc_desc_hits; // number of LRU cache hits | |
201 int pc_desc_tests; // total number of PcDesc examinations | |
202 int pc_desc_searches; // total number of quasi-binary search steps | |
203 int pc_desc_adds; // number of LUR cache insertions | |
204 | |
205 void print_pc_stats() { | |
206 tty->print_cr("PcDesc Statistics: %d queries, %.2f comparisons per query", | |
207 pc_desc_queries, | |
208 (double)(pc_desc_tests + pc_desc_searches) | |
209 / pc_desc_queries); | |
210 tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d", | |
211 pc_desc_resets, | |
212 pc_desc_queries, pc_desc_approx, | |
213 pc_desc_repeats, pc_desc_hits, | |
214 pc_desc_tests, pc_desc_searches, pc_desc_adds); | |
215 } | |
216 } nmethod_stats; | |
8152
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
217 #endif //PRODUCT |
7066 | 218 |
219 | |
220 //--------------------------------------------------------------------------------- | |
221 | |
222 | |
223 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { | |
224 assert(pc != NULL, "Must be non null"); | |
225 assert(exception.not_null(), "Must be non null"); | |
226 assert(handler != NULL, "Must be non null"); | |
227 | |
228 _count = 0; | |
229 _exception_type = exception->klass(); | |
230 _next = NULL; | |
231 | |
232 add_address_and_handler(pc,handler); | |
233 } | |
234 | |
235 | |
236 address ExceptionCache::match(Handle exception, address pc) { | |
237 assert(pc != NULL,"Must be non null"); | |
238 assert(exception.not_null(),"Must be non null"); | |
239 if (exception->klass() == exception_type()) { | |
240 return (test_address(pc)); | |
241 } | |
242 | |
243 return NULL; | |
244 } | |
245 | |
246 | |
247 bool ExceptionCache::match_exception_with_space(Handle exception) { | |
248 assert(exception.not_null(),"Must be non null"); | |
249 if (exception->klass() == exception_type() && count() < cache_size) { | |
250 return true; | |
251 } | |
252 return false; | |
253 } | |
254 | |
255 | |
256 address ExceptionCache::test_address(address addr) { | |
257 for (int i=0; i<count(); i++) { | |
258 if (pc_at(i) == addr) { | |
259 return handler_at(i); | |
260 } | |
261 } | |
262 return NULL; | |
263 } | |
264 | |
265 | |
266 bool ExceptionCache::add_address_and_handler(address addr, address handler) { | |
267 if (test_address(addr) == handler) return true; | |
268 if (count() < cache_size) { | |
269 set_pc_at(count(),addr); | |
270 set_handler_at(count(), handler); | |
271 increment_count(); | |
272 return true; | |
273 } | |
274 return false; | |
275 } | |
276 | |
277 | |
278 // private method for handling exception cache | |
279 // These methods are private, and used to manipulate the exception cache | |
280 // directly. | |
281 ExceptionCache* nmethod::exception_cache_entry_for_exception(Handle exception) { | |
282 ExceptionCache* ec = exception_cache(); | |
283 while (ec != NULL) { | |
284 if (ec->match_exception_with_space(exception)) { | |
285 return ec; | |
286 } | |
287 ec = ec->next(); | |
288 } | |
289 return NULL; | |
290 } | |
291 | |
292 | |
293 //----------------------------------------------------------------------------- | |
294 | |
295 | |
296 // Helper used by both find_pc_desc methods. | |
297 static inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) { | |
298 NOT_PRODUCT(++nmethod_stats.pc_desc_tests); | |
299 if (!approximate) | |
300 return pc->pc_offset() == pc_offset; | |
301 else | |
302 return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset(); | |
303 } | |
304 | |
305 void PcDescCache::reset_to(PcDesc* initial_pc_desc) { | |
306 if (initial_pc_desc == NULL) { | |
307 _pc_descs[0] = NULL; // native method; no PcDescs at all | |
308 return; | |
309 } | |
310 NOT_PRODUCT(++nmethod_stats.pc_desc_resets); | |
311 // reset the cache by filling it with benign (non-null) values | |
312 assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); | |
313 for (int i = 0; i < cache_size; i++) | |
314 _pc_descs[i] = initial_pc_desc; | |
315 } | |
316 | |
317 PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { | |
318 NOT_PRODUCT(++nmethod_stats.pc_desc_queries); | |
319 NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx); | |
320 | |
321 // Note: one might think that caching the most recently | |
322 // read value separately would be a win, but one would be | |
323 // wrong. When many threads are updating it, the cache | |
324 // line it's in would bounce between caches, negating | |
325 // any benefit. | |
326 | |
327 // In order to prevent race conditions do not load cache elements | |
328 // repeatedly, but use a local copy: | |
329 PcDesc* res; | |
330 | |
331 // Step one: Check the most recently added value. | |
332 res = _pc_descs[0]; | |
333 if (res == NULL) return NULL; // native method; no PcDescs at all | |
334 if (match_desc(res, pc_offset, approximate)) { | |
335 NOT_PRODUCT(++nmethod_stats.pc_desc_repeats); | |
336 return res; | |
337 } | |
338 | |
339 // Step two: Check the rest of the LRU cache. | |
340 for (int i = 1; i < cache_size; ++i) { | |
341 res = _pc_descs[i]; | |
342 if (res->pc_offset() < 0) break; // optimization: skip empty cache | |
343 if (match_desc(res, pc_offset, approximate)) { | |
344 NOT_PRODUCT(++nmethod_stats.pc_desc_hits); | |
345 return res; | |
346 } | |
347 } | |
348 | |
349 // Report failure. | |
350 return NULL; | |
351 } | |
352 | |
353 void PcDescCache::add_pc_desc(PcDesc* pc_desc) { | |
354 NOT_PRODUCT(++nmethod_stats.pc_desc_adds); | |
355 // Update the LRU cache by shifting pc_desc forward. | |
356 for (int i = 0; i < cache_size; i++) { | |
357 PcDesc* next = _pc_descs[i]; | |
358 _pc_descs[i] = pc_desc; | |
359 pc_desc = next; | |
360 } | |
361 } | |
362 | |
363 // adjust pcs_size so that it is a multiple of both oopSize and | |
364 // sizeof(PcDesc) (assumes that if sizeof(PcDesc) is not a multiple | |
365 // of oopSize, then 2*sizeof(PcDesc) is) | |
366 static int adjust_pcs_size(int pcs_size) { | |
367 int nsize = round_to(pcs_size, oopSize); | |
368 if ((nsize % sizeof(PcDesc)) != 0) { | |
369 nsize = pcs_size + sizeof(PcDesc); | |
370 } | |
371 assert((nsize % oopSize) == 0, "correct alignment"); | |
372 return nsize; | |
373 } | |
374 | |
375 //----------------------------------------------------------------------------- | |
376 | |
377 | |
378 void nmethod::add_exception_cache_entry(ExceptionCache* new_entry) { | |
379 assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock"); | |
380 assert(new_entry != NULL,"Must be non null"); | |
381 assert(new_entry->next() == NULL, "Must be null"); | |
382 | |
383 if (exception_cache() != NULL) { | |
384 new_entry->set_next(exception_cache()); | |
385 } | |
386 set_exception_cache(new_entry); | |
387 } | |
388 | |
389 void nmethod::remove_from_exception_cache(ExceptionCache* ec) { | |
390 ExceptionCache* prev = NULL; | |
391 ExceptionCache* curr = exception_cache(); | |
392 assert(curr != NULL, "nothing to remove"); | |
393 // find the previous and next entry of ec | |
394 while (curr != ec) { | |
395 prev = curr; | |
396 curr = curr->next(); | |
397 assert(curr != NULL, "ExceptionCache not found"); | |
398 } | |
399 // now: curr == ec | |
400 ExceptionCache* next = curr->next(); | |
401 if (prev == NULL) { | |
402 set_exception_cache(next); | |
403 } else { | |
404 prev->set_next(next); | |
405 } | |
406 delete curr; | |
407 } | |
408 | |
409 | |
410 // public method for accessing the exception cache | |
411 // These are the public access methods. | |
412 address nmethod::handler_for_exception_and_pc(Handle exception, address pc) { | |
413 // We never grab a lock to read the exception cache, so we may | |
414 // have false negatives. This is okay, as it can only happen during | |
415 // the first few exception lookups for a given nmethod. | |
416 ExceptionCache* ec = exception_cache(); | |
417 while (ec != NULL) { | |
418 address ret_val; | |
419 if ((ret_val = ec->match(exception,pc)) != NULL) { | |
420 return ret_val; | |
421 } | |
422 ec = ec->next(); | |
423 } | |
424 return NULL; | |
425 } | |
426 | |
427 | |
428 void nmethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) { | |
429 // There are potential race conditions during exception cache updates, so we | |
430 // must own the ExceptionCache_lock before doing ANY modifications. Because | |
431 // we don't lock during reads, it is possible to have several threads attempt | |
432 // to update the cache with the same data. We need to check for already inserted | |
433 // copies of the current data before adding it. | |
434 | |
435 MutexLocker ml(ExceptionCache_lock); | |
436 ExceptionCache* target_entry = exception_cache_entry_for_exception(exception); | |
437 | |
438 if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) { | |
439 target_entry = new ExceptionCache(exception,pc,handler); | |
440 add_exception_cache_entry(target_entry); | |
441 } | |
442 } | |
443 | |
444 | |
445 //-------------end of code for ExceptionCache-------------- | |
446 | |
447 | |
448 int nmethod::total_size() const { | |
449 return | |
450 consts_size() + | |
451 insts_size() + | |
452 stub_size() + | |
453 scopes_data_size() + | |
454 scopes_pcs_size() + | |
455 handler_table_size() + | |
456 nul_chk_table_size(); | |
457 } | |
458 | |
459 const char* nmethod::compile_kind() const { | |
460 if (is_osr_method()) return "osr"; | |
461 if (method() != NULL && is_native_method()) return "c2n"; | |
462 return NULL; | |
463 } | |
464 | |
465 // Fill in default values for various flag fields | |
466 void nmethod::init_defaults() { | |
467 _state = alive; | |
468 _marked_for_reclamation = 0; | |
469 _has_flushed_dependencies = 0; | |
470 _speculatively_disconnected = 0; | |
471 _has_unsafe_access = 0; | |
472 _has_method_handle_invokes = 0; | |
473 _lazy_critical_native = 0; | |
474 _has_wide_vectors = 0; | |
475 _marked_for_deoptimization = 0; | |
476 _lock_count = 0; | |
477 _stack_traversal_mark = 0; | |
478 _unload_reported = false; // jvmti state | |
479 | |
480 #ifdef ASSERT | |
481 _oops_are_stale = false; | |
482 #endif | |
483 | |
484 _oops_do_mark_link = NULL; | |
485 _jmethod_id = NULL; | |
486 _osr_link = NULL; | |
487 _scavenge_root_link = NULL; | |
488 _scavenge_root_state = 0; | |
489 _saved_nmethod_link = NULL; | |
490 _compiler = NULL; | |
491 #ifdef GRAAL | |
492 _graal_installed_code = NULL; | |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
493 _triggered_deoptimizations = NULL; |
7066 | 494 #endif |
495 #ifdef HAVE_DTRACE_H | |
496 _trap_offset = 0; | |
497 #endif // def HAVE_DTRACE_H | |
498 } | |
499 | |
500 nmethod* nmethod::new_native_nmethod(methodHandle method, | |
501 int compile_id, | |
502 CodeBuffer *code_buffer, | |
503 int vep_offset, | |
504 int frame_complete, | |
505 int frame_size, | |
506 ByteSize basic_lock_owner_sp_offset, | |
507 ByteSize basic_lock_sp_offset, | |
508 OopMapSet* oop_maps) { | |
509 code_buffer->finalize_oop_references(method); | |
510 // create nmethod | |
511 nmethod* nm = NULL; | |
512 { | |
513 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
514 int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod)); | |
8864
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
515 if (CodeCache::has_space(native_nmethod_size)) { |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
516 CodeOffsets offsets; |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
517 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
518 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
519 nm = new (native_nmethod_size) nmethod(method(), native_nmethod_size, |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
520 compile_id, &offsets, |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
521 code_buffer, frame_size, |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
522 basic_lock_owner_sp_offset, |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
523 basic_lock_sp_offset, oop_maps); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
524 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_native_nmethod(nm)); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
525 if (PrintAssembly && nm != NULL) |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
526 Disassembler::decode(nm); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
527 } |
7066 | 528 } |
529 // verify nmethod | |
530 debug_only(if (nm) nm->verify();) // might block | |
531 | |
532 if (nm != NULL) { | |
533 nm->log_new_nmethod(); | |
534 } | |
535 | |
536 return nm; | |
537 } | |
538 | |
539 #ifdef HAVE_DTRACE_H | |
540 nmethod* nmethod::new_dtrace_nmethod(methodHandle method, | |
541 CodeBuffer *code_buffer, | |
542 int vep_offset, | |
543 int trap_offset, | |
544 int frame_complete, | |
545 int frame_size) { | |
546 code_buffer->finalize_oop_references(method); | |
547 // create nmethod | |
548 nmethod* nm = NULL; | |
549 { | |
550 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
551 int nmethod_size = allocation_size(code_buffer, sizeof(nmethod)); | |
8864
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
552 if (CodeCache::has_space(nmethod_size)) { |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
553 CodeOffsets offsets; |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
554 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
555 offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
556 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); |
8883 | 557 |
8864
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
558 nm = new (nmethod_size) nmethod(method(), nmethod_size, |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
559 &offsets, code_buffer, frame_size); |
8883 | 560 |
8864
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
561 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_nmethod(nm)); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
562 if (PrintAssembly && nm != NULL) |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
563 Disassembler::decode(nm); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
564 } |
7066 | 565 } |
566 // verify nmethod | |
567 debug_only(if (nm) nm->verify();) // might block | |
568 | |
569 if (nm != NULL) { | |
570 nm->log_new_nmethod(); | |
571 } | |
572 | |
573 return nm; | |
574 } | |
575 | |
576 #endif // def HAVE_DTRACE_H | |
577 | |
578 nmethod* nmethod::new_nmethod(methodHandle method, | |
579 int compile_id, | |
580 int entry_bci, | |
581 CodeOffsets* offsets, | |
582 int orig_pc_offset, | |
583 DebugInformationRecorder* debug_info, | |
584 Dependencies* dependencies, | |
585 CodeBuffer* code_buffer, int frame_size, | |
586 OopMapSet* oop_maps, | |
587 ExceptionHandlerTable* handler_table, | |
588 ImplicitExceptionTable* nul_chk_table, | |
589 AbstractCompiler* compiler, | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
590 int comp_level, |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
591 GrowableArray<jlong>* leaf_graph_ids |
7066 | 592 #ifdef GRAAL |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
593 , Handle installed_code, |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
594 Handle triggered_deoptimizations |
7066 | 595 #endif |
596 ) | |
597 { | |
598 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); | |
599 code_buffer->finalize_oop_references(method); | |
7693
826632227602
fixed visual studio warnings
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7660
diff
changeset
|
600 int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); |
7066 | 601 // create nmethod |
602 nmethod* nm = NULL; | |
603 { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
604 int nmethod_size = | |
605 allocation_size(code_buffer, sizeof(nmethod)) | |
606 + adjust_pcs_size(debug_info->pcs_size()) | |
607 + round_to(dependencies->size_in_bytes() , oopSize) | |
608 + round_to(handler_table->size_in_bytes(), oopSize) | |
609 + round_to(nul_chk_table->size_in_bytes(), oopSize) | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
610 + round_to(debug_info->data_size() , oopSize) |
8883 | 611 + leaf_graph_ids_size; |
612 if (CodeCache::has_space(nmethod_size)) { | |
613 nm = new (nmethod_size) | |
7066 | 614 nmethod(method(), nmethod_size, compile_id, entry_bci, offsets, |
615 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, | |
616 oop_maps, | |
617 handler_table, | |
618 nul_chk_table, | |
619 compiler, | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
620 comp_level, |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
621 leaf_graph_ids |
7066 | 622 #ifdef GRAAL |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
623 , installed_code, |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
624 triggered_deoptimizations |
7066 | 625 #endif |
8883 | 626 ); |
627 } | |
7066 | 628 if (nm != NULL) { |
629 // To make dependency checking during class loading fast, record | |
630 // the nmethod dependencies in the classes it is dependent on. | |
631 // This allows the dependency checking code to simply walk the | |
632 // class hierarchy above the loaded class, checking only nmethods | |
633 // which are dependent on those classes. The slow way is to | |
634 // check every nmethod for dependencies which makes it linear in | |
635 // the number of methods compiled. For applications with a lot | |
636 // classes the slow way is too slow. | |
637 for (Dependencies::DepStream deps(nm); deps.next(); ) { | |
638 Klass* klass = deps.context_type(); | |
639 if (klass == NULL) continue; // ignore things like evol_method | |
640 | |
641 // record this nmethod as dependent on this klass | |
642 InstanceKlass::cast(klass)->add_dependent_nmethod(nm); | |
643 } | |
644 } | |
8152
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
645 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_nmethod(nm)); |
7066 | 646 if (PrintAssembly && nm != NULL) |
647 Disassembler::decode(nm); | |
648 } | |
649 | |
650 // verify nmethod | |
651 debug_only(if (nm) nm->verify();) // might block | |
652 | |
653 if (nm != NULL) { | |
654 nm->log_new_nmethod(); | |
655 } | |
656 | |
657 // done | |
658 return nm; | |
659 } | |
660 | |
661 | |
662 // For native wrappers | |
663 nmethod::nmethod( | |
664 Method* method, | |
665 int nmethod_size, | |
666 int compile_id, | |
667 CodeOffsets* offsets, | |
668 CodeBuffer* code_buffer, | |
669 int frame_size, | |
670 ByteSize basic_lock_owner_sp_offset, | |
671 ByteSize basic_lock_sp_offset, | |
672 OopMapSet* oop_maps ) | |
673 : CodeBlob("native nmethod", code_buffer, sizeof(nmethod), | |
674 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), | |
675 _native_receiver_sp_offset(basic_lock_owner_sp_offset), | |
676 _native_basic_lock_sp_offset(basic_lock_sp_offset) | |
677 { | |
678 { | |
679 debug_only(No_Safepoint_Verifier nsv;) | |
680 assert_locked_or_safepoint(CodeCache_lock); | |
681 | |
682 init_defaults(); | |
683 _method = method; | |
684 _entry_bci = InvocationEntryBci; | |
685 // We have no exception handler or deopt handler make the | |
686 // values something that will never match a pc like the nmethod vtable entry | |
687 _exception_offset = 0; | |
688 _deoptimize_offset = 0; | |
689 _deoptimize_mh_offset = 0; | |
690 _orig_pc_offset = 0; | |
691 | |
692 _consts_offset = data_offset(); | |
693 _stub_offset = data_offset(); | |
694 _oops_offset = data_offset(); | |
695 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
696 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
697 _scopes_pcs_offset = _scopes_data_offset; | |
698 _dependencies_offset = _scopes_pcs_offset; | |
699 _handler_table_offset = _dependencies_offset; | |
700 _nul_chk_table_offset = _handler_table_offset; | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
701 _leaf_graph_ids_offset = _nul_chk_table_offset; |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
702 _nmethod_end_offset = _leaf_graph_ids_offset; |
7066 | 703 _compile_id = compile_id; |
704 _comp_level = CompLevel_none; | |
705 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
706 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
707 _osr_entry_point = NULL; | |
708 _exception_cache = NULL; | |
709 _pc_desc_cache.reset_to(NULL); | |
710 | |
711 code_buffer->copy_values_to(this); | |
712 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { | |
713 CodeCache::add_scavenge_root_nmethod(this); | |
714 } | |
715 debug_only(verify_scavenge_root_oops()); | |
716 CodeCache::commit(this); | |
717 } | |
718 | |
719 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | |
720 ttyLocker ttyl; // keep the following output all in one block | |
721 // This output goes directly to the tty, not the compiler log. | |
722 // To enable tools to match it up with the compilation activity, | |
723 // be sure to tag this tty output with the compile ID. | |
724 if (xtty != NULL) { | |
725 xtty->begin_head("print_native_nmethod"); | |
726 xtty->method(_method); | |
727 xtty->stamp(); | |
728 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
729 } | |
730 // print the header part first | |
731 print(); | |
732 // then print the requested information | |
733 if (PrintNativeNMethods) { | |
734 print_code(); | |
735 if (oop_maps != NULL) { | |
736 oop_maps->print(); | |
737 } | |
738 } | |
739 if (PrintRelocations) { | |
740 print_relocations(); | |
741 } | |
742 if (xtty != NULL) { | |
743 xtty->tail("print_native_nmethod"); | |
744 } | |
745 } | |
746 } | |
747 | |
748 // For dtrace wrappers | |
749 #ifdef HAVE_DTRACE_H | |
750 nmethod::nmethod( | |
751 Method* method, | |
752 int nmethod_size, | |
753 CodeOffsets* offsets, | |
754 CodeBuffer* code_buffer, | |
755 int frame_size) | |
756 : CodeBlob("dtrace nmethod", code_buffer, sizeof(nmethod), | |
757 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, NULL), | |
758 _native_receiver_sp_offset(in_ByteSize(-1)), | |
759 _native_basic_lock_sp_offset(in_ByteSize(-1)) | |
760 { | |
761 { | |
762 debug_only(No_Safepoint_Verifier nsv;) | |
763 assert_locked_or_safepoint(CodeCache_lock); | |
764 | |
765 init_defaults(); | |
766 _method = method; | |
767 _entry_bci = InvocationEntryBci; | |
768 // We have no exception handler or deopt handler make the | |
769 // values something that will never match a pc like the nmethod vtable entry | |
770 _exception_offset = 0; | |
771 _deoptimize_offset = 0; | |
772 _deoptimize_mh_offset = 0; | |
773 _unwind_handler_offset = -1; | |
774 _trap_offset = offsets->value(CodeOffsets::Dtrace_trap); | |
775 _orig_pc_offset = 0; | |
776 _consts_offset = data_offset(); | |
777 _stub_offset = data_offset(); | |
778 _oops_offset = data_offset(); | |
779 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
780 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
781 _scopes_pcs_offset = _scopes_data_offset; | |
782 _dependencies_offset = _scopes_pcs_offset; | |
783 _handler_table_offset = _dependencies_offset; | |
784 _nul_chk_table_offset = _handler_table_offset; | |
785 _nmethod_end_offset = _nul_chk_table_offset; | |
786 _compile_id = 0; // default | |
787 _comp_level = CompLevel_none; | |
788 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
789 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
790 _osr_entry_point = NULL; | |
791 _exception_cache = NULL; | |
792 _pc_desc_cache.reset_to(NULL); | |
793 | |
794 code_buffer->copy_values_to(this); | |
795 debug_only(verify_scavenge_root_oops()); | |
796 CodeCache::commit(this); | |
797 } | |
798 | |
799 if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | |
800 ttyLocker ttyl; // keep the following output all in one block | |
801 // This output goes directly to the tty, not the compiler log. | |
802 // To enable tools to match it up with the compilation activity, | |
803 // be sure to tag this tty output with the compile ID. | |
804 if (xtty != NULL) { | |
805 xtty->begin_head("print_dtrace_nmethod"); | |
806 xtty->method(_method); | |
807 xtty->stamp(); | |
808 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
809 } | |
810 // print the header part first | |
811 print(); | |
812 // then print the requested information | |
813 if (PrintNMethods) { | |
814 print_code(); | |
815 } | |
816 if (PrintRelocations) { | |
817 print_relocations(); | |
818 } | |
819 if (xtty != NULL) { | |
820 xtty->tail("print_dtrace_nmethod"); | |
821 } | |
822 } | |
823 } | |
824 #endif // def HAVE_DTRACE_H | |
825 | |
826 void* nmethod::operator new(size_t size, int nmethod_size) { | |
8864
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
827 void* alloc = CodeCache::allocate(nmethod_size); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
828 guarantee(alloc != NULL, "CodeCache should have enough space"); |
3c786355ffb4
8009026: [parfait] Null pointer deference in hotspot/src/share/vm/code/nmethod.cpp
morris
parents:
6983
diff
changeset
|
829 return alloc; |
7066 | 830 } |
831 | |
832 | |
833 nmethod::nmethod( | |
834 Method* method, | |
835 int nmethod_size, | |
836 int compile_id, | |
837 int entry_bci, | |
838 CodeOffsets* offsets, | |
839 int orig_pc_offset, | |
840 DebugInformationRecorder* debug_info, | |
841 Dependencies* dependencies, | |
842 CodeBuffer *code_buffer, | |
843 int frame_size, | |
844 OopMapSet* oop_maps, | |
845 ExceptionHandlerTable* handler_table, | |
846 ImplicitExceptionTable* nul_chk_table, | |
847 AbstractCompiler* compiler, | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
848 int comp_level, |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
849 GrowableArray<jlong>* leaf_graph_ids |
7066 | 850 #ifdef GRAAL |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
851 , Handle installed_code, |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
852 Handle triggered_deoptimizations |
7066 | 853 #endif |
854 ) | |
855 : CodeBlob("nmethod", code_buffer, sizeof(nmethod), | |
856 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), | |
857 _native_receiver_sp_offset(in_ByteSize(-1)), | |
858 _native_basic_lock_sp_offset(in_ByteSize(-1)) | |
859 { | |
860 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); | |
861 { | |
862 debug_only(No_Safepoint_Verifier nsv;) | |
863 assert_locked_or_safepoint(CodeCache_lock); | |
864 | |
865 init_defaults(); | |
866 _method = method; | |
867 _entry_bci = entry_bci; | |
868 _compile_id = compile_id; | |
869 _comp_level = comp_level; | |
870 _compiler = compiler; | |
871 _orig_pc_offset = orig_pc_offset; | |
872 | |
873 // Section offsets | |
874 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); | |
875 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); | |
876 | |
877 #ifdef GRAAL | |
878 _graal_installed_code = installed_code(); | |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
879 _triggered_deoptimizations = (typeArrayOop)triggered_deoptimizations(); |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
880 #endif |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
881 if (compiler->is_graal()) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
882 // Graal might not produce any stub sections |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
883 if (offsets->value(CodeOffsets::Exceptions) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
884 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
885 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
886 _exception_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
887 } |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
888 if (offsets->value(CodeOffsets::Deopt) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
889 _deoptimize_offset = code_offset() + offsets->value(CodeOffsets::Deopt); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
890 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
891 _deoptimize_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
892 } |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
893 if (offsets->value(CodeOffsets::DeoptMH) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
894 _deoptimize_mh_offset = code_offset() + offsets->value(CodeOffsets::DeoptMH); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
895 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
896 _deoptimize_mh_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
897 } |
7066 | 898 } else { |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
899 // Exception handler and deopt handler are in the stub section |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
900 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set"); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
901 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set"); |
7066 | 902 |
903 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); | |
904 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); | |
905 if (offsets->value(CodeOffsets::DeoptMH) != -1) { | |
906 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); | |
907 } else { | |
908 _deoptimize_mh_offset = -1; | |
909 } | |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
910 } |
7066 | 911 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { |
912 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); | |
913 } else { | |
914 _unwind_handler_offset = -1; | |
915 } | |
916 | |
7693
826632227602
fixed visual studio warnings
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7660
diff
changeset
|
917 int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
918 |
7066 | 919 _oops_offset = data_offset(); |
920 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
921 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
922 | |
923 _scopes_pcs_offset = _scopes_data_offset + round_to(debug_info->data_size (), oopSize); | |
924 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); | |
925 _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize); | |
926 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize); | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
927 _leaf_graph_ids_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
928 _nmethod_end_offset = _leaf_graph_ids_offset + leaf_graph_ids_size; |
7066 | 929 |
930 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
931 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
932 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry); | |
933 _exception_cache = NULL; | |
934 _pc_desc_cache.reset_to(scopes_pcs_begin()); | |
935 | |
936 // Copy contents of ScopeDescRecorder to nmethod | |
937 code_buffer->copy_values_to(this); | |
938 debug_info->copy_to(this); | |
939 dependencies->copy_to(this); | |
940 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { | |
941 CodeCache::add_scavenge_root_nmethod(this); | |
942 } | |
943 debug_only(verify_scavenge_root_oops()); | |
944 | |
945 CodeCache::commit(this); | |
946 | |
947 // Copy contents of ExceptionHandlerTable to nmethod | |
948 handler_table->copy_to(this); | |
949 nul_chk_table->copy_to(this); | |
950 | |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
951 if (leaf_graph_ids != NULL && leaf_graph_ids_size > 0) { |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
952 memcpy(leaf_graph_ids_begin(), leaf_graph_ids->adr_at(0), leaf_graph_ids_size); |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
953 } |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7154
diff
changeset
|
954 |
7066 | 955 // we use the information of entry points to find out if a method is |
956 // static or non static | |
957 assert(compiler->is_c2() || | |
958 _method->is_static() == (entry_point() == _verified_entry_point), | |
959 " entry points must be same for static methods and vice versa"); | |
960 } | |
961 | |
962 bool printnmethods = PrintNMethods | |
963 || CompilerOracle::should_print(_method) | |
964 || CompilerOracle::has_option_string(_method, "PrintNMethods"); | |
965 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) { | |
966 print_nmethod(printnmethods); | |
967 } | |
968 } | |
969 | |
970 | |
971 // Print a short set of xml attributes to identify this nmethod. The | |
972 // output should be embedded in some other element. | |
973 void nmethod::log_identity(xmlStream* log) const { | |
974 log->print(" compile_id='%d'", compile_id()); | |
975 const char* nm_kind = compile_kind(); | |
976 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind); | |
977 if (compiler() != NULL) { | |
978 log->print(" compiler='%s'", compiler()->name()); | |
979 } | |
980 if (TieredCompilation) { | |
981 log->print(" level='%d'", comp_level()); | |
982 } | |
983 } | |
984 | |
985 | |
986 #define LOG_OFFSET(log, name) \ | |
987 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \ | |
988 log->print(" " XSTR(name) "_offset='%d'" , \ | |
989 (intptr_t)name##_begin() - (intptr_t)this) | |
990 | |
991 | |
992 void nmethod::log_new_nmethod() const { | |
993 if (LogCompilation && xtty != NULL) { | |
994 ttyLocker ttyl; | |
995 HandleMark hm; | |
996 xtty->begin_elem("nmethod"); | |
997 log_identity(xtty); | |
998 xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", code_begin(), size()); | |
999 xtty->print(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
1000 | |
1001 LOG_OFFSET(xtty, relocation); | |
1002 LOG_OFFSET(xtty, consts); | |
1003 LOG_OFFSET(xtty, insts); | |
1004 LOG_OFFSET(xtty, stub); | |
1005 LOG_OFFSET(xtty, scopes_data); | |
1006 LOG_OFFSET(xtty, scopes_pcs); | |
1007 LOG_OFFSET(xtty, dependencies); | |
1008 LOG_OFFSET(xtty, handler_table); | |
1009 LOG_OFFSET(xtty, nul_chk_table); | |
1010 LOG_OFFSET(xtty, oops); | |
1011 | |
1012 xtty->method(method()); | |
1013 xtty->stamp(); | |
1014 xtty->end_elem(); | |
1015 } | |
1016 } | |
1017 | |
1018 #undef LOG_OFFSET | |
1019 | |
1020 | |
1021 // Print out more verbose output usually for a newly created nmethod. | |
1022 void nmethod::print_on(outputStream* st, const char* msg) const { | |
1023 if (st != NULL) { | |
1024 ttyLocker ttyl; | |
1025 if (WizardMode) { | |
1026 CompileTask::print_compilation(st, this, msg, /*short_form:*/ true); | |
1027 st->print_cr(" (" INTPTR_FORMAT ")", this); | |
1028 } else { | |
1029 CompileTask::print_compilation(st, this, msg, /*short_form:*/ false); | |
1030 } | |
1031 } | |
1032 } | |
1033 | |
1034 | |
1035 void nmethod::print_nmethod(bool printmethod) { | |
1036 ttyLocker ttyl; // keep the following output all in one block | |
1037 if (xtty != NULL) { | |
1038 xtty->begin_head("print_nmethod"); | |
1039 xtty->stamp(); | |
1040 xtty->end_head(); | |
1041 } | |
1042 // print the header part first | |
1043 print(); | |
1044 // then print the requested information | |
1045 if (printmethod) { | |
1046 print_code(); | |
1047 print_pcs(); | |
1048 if (oop_maps()) { | |
1049 oop_maps()->print(); | |
1050 } | |
1051 } | |
1052 if (PrintDebugInfo) { | |
1053 print_scopes(); | |
1054 } | |
1055 if (PrintRelocations) { | |
1056 print_relocations(); | |
1057 } | |
1058 if (PrintDependencies) { | |
1059 print_dependencies(); | |
1060 } | |
1061 if (PrintExceptionHandlers) { | |
1062 print_handler_table(); | |
1063 print_nul_chk_table(); | |
1064 } | |
1065 if (xtty != NULL) { | |
1066 xtty->tail("print_nmethod"); | |
1067 } | |
1068 } | |
1069 | |
1070 | |
1071 // Promote one word from an assembly-time handle to a live embedded oop. | |
1072 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) { | |
1073 if (handle == NULL || | |
1074 // As a special case, IC oops are initialized to 1 or -1. | |
1075 handle == (jobject) Universe::non_oop_word()) { | |
1076 (*dest) = (oop) handle; | |
1077 } else { | |
1078 (*dest) = JNIHandles::resolve_non_null(handle); | |
1079 } | |
1080 } | |
1081 | |
1082 | |
1083 // Have to have the same name because it's called by a template | |
1084 void nmethod::copy_values(GrowableArray<jobject>* array) { | |
1085 int length = array->length(); | |
1086 assert((address)(oops_begin() + length) <= (address)oops_end(), "oops big enough"); | |
1087 oop* dest = oops_begin(); | |
1088 for (int index = 0 ; index < length; index++) { | |
1089 initialize_immediate_oop(&dest[index], array->at(index)); | |
1090 } | |
1091 | |
1092 // Now we can fix up all the oops in the code. We need to do this | |
1093 // in the code because the assembler uses jobjects as placeholders. | |
1094 // The code and relocations have already been initialized by the | |
1095 // CodeBlob constructor, so it is valid even at this early point to | |
1096 // iterate over relocations and patch the code. | |
1097 fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); | |
1098 } | |
1099 | |
1100 void nmethod::copy_values(GrowableArray<Metadata*>* array) { | |
1101 int length = array->length(); | |
1102 assert((address)(metadata_begin() + length) <= (address)metadata_end(), "big enough"); | |
1103 Metadata** dest = metadata_begin(); | |
1104 for (int index = 0 ; index < length; index++) { | |
1105 dest[index] = array->at(index); | |
1106 } | |
1107 } | |
1108 | |
1109 bool nmethod::is_at_poll_return(address pc) { | |
1110 RelocIterator iter(this, pc, pc+1); | |
1111 while (iter.next()) { | |
1112 if (iter.type() == relocInfo::poll_return_type) | |
1113 return true; | |
1114 } | |
1115 return false; | |
1116 } | |
1117 | |
1118 | |
1119 bool nmethod::is_at_poll_or_poll_return(address pc) { | |
1120 RelocIterator iter(this, pc, pc+1); | |
1121 while (iter.next()) { | |
1122 relocInfo::relocType t = iter.type(); | |
1123 if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) | |
1124 return true; | |
1125 } | |
1126 return false; | |
1127 } | |
1128 | |
1129 | |
1130 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) { | |
1131 // re-patch all oop-bearing instructions, just in case some oops moved | |
1132 RelocIterator iter(this, begin, end); | |
1133 while (iter.next()) { | |
1134 if (iter.type() == relocInfo::oop_type) { | |
1135 oop_Relocation* reloc = iter.oop_reloc(); | |
1136 if (initialize_immediates && reloc->oop_is_immediate()) { | |
1137 oop* dest = reloc->oop_addr(); | |
1138 initialize_immediate_oop(dest, (jobject) *dest); | |
1139 } | |
1140 // Refresh the oop-related bits of this instruction. | |
1141 reloc->fix_oop_relocation(); | |
1142 } else if (iter.type() == relocInfo::metadata_type) { | |
1143 metadata_Relocation* reloc = iter.metadata_reloc(); | |
1144 reloc->fix_metadata_relocation(); | |
1145 } | |
1146 | |
1147 // There must not be any interfering patches or breakpoints. | |
1148 assert(!(iter.type() == relocInfo::breakpoint_type | |
1149 && iter.breakpoint_reloc()->active()), | |
1150 "no active breakpoint"); | |
1151 } | |
1152 } | |
1153 | |
1154 | |
1155 void nmethod::verify_oop_relocations() { | |
1156 // Ensure sure that the code matches the current oop values | |
1157 RelocIterator iter(this, NULL, NULL); | |
1158 while (iter.next()) { | |
1159 if (iter.type() == relocInfo::oop_type) { | |
1160 oop_Relocation* reloc = iter.oop_reloc(); | |
1161 if (!reloc->oop_is_immediate()) { | |
1162 reloc->verify_oop_relocation(); | |
1163 } | |
1164 } | |
1165 } | |
1166 } | |
1167 | |
1168 | |
1169 ScopeDesc* nmethod::scope_desc_at(address pc) { | |
1170 PcDesc* pd = pc_desc_at(pc); | |
1171 guarantee(pd != NULL, "scope must be present"); | |
1172 return new ScopeDesc(this, pd->scope_decode_offset(), | |
1173 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), | |
1174 pd->return_oop()); | |
1175 } | |
1176 | |
1177 | |
1178 void nmethod::clear_inline_caches() { | |
1179 assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint"); | |
1180 if (is_zombie()) { | |
1181 return; | |
1182 } | |
1183 | |
1184 RelocIterator iter(this); | |
1185 while (iter.next()) { | |
1186 iter.reloc()->clear_inline_cache(); | |
1187 } | |
1188 } | |
1189 | |
1190 | |
1191 void nmethod::cleanup_inline_caches() { | |
1192 | |
1193 assert_locked_or_safepoint(CompiledIC_lock); | |
1194 | |
1195 // If the method is not entrant or zombie then a JMP is plastered over the | |
1196 // first few bytes. If an oop in the old code was there, that oop | |
1197 // should not get GC'd. Skip the first few bytes of oops on | |
1198 // not-entrant methods. | |
1199 address low_boundary = verified_entry_point(); | |
1200 if (!is_in_use()) { | |
1201 low_boundary += NativeJump::instruction_size; | |
1202 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1203 // This means that the low_boundary is going to be a little too high. | |
1204 // This shouldn't matter, since oops of non-entrant methods are never used. | |
1205 // In fact, why are we bothering to look at oops in a non-entrant method?? | |
1206 } | |
1207 | |
1208 // Find all calls in an nmethod, and clear the ones that points to zombie methods | |
1209 ResourceMark rm; | |
1210 RelocIterator iter(this, low_boundary); | |
1211 while(iter.next()) { | |
1212 switch(iter.type()) { | |
1213 case relocInfo::virtual_call_type: | |
1214 case relocInfo::opt_virtual_call_type: { | |
1215 CompiledIC *ic = CompiledIC_at(iter.reloc()); | |
1216 // Ok, to lookup references to zombies here | |
1217 CodeBlob *cb = CodeCache::find_blob_unsafe(ic->ic_destination()); | |
1218 if( cb != NULL && cb->is_nmethod() ) { | |
1219 nmethod* nm = (nmethod*)cb; | |
1220 // Clean inline caches pointing to both zombie and not_entrant methods | |
1221 if (!nm->is_in_use() || (nm->method()->code() != nm)) ic->set_to_clean(); | |
1222 } | |
1223 break; | |
1224 } | |
1225 case relocInfo::static_call_type: { | |
1226 CompiledStaticCall *csc = compiledStaticCall_at(iter.reloc()); | |
1227 CodeBlob *cb = CodeCache::find_blob_unsafe(csc->destination()); | |
1228 if( cb != NULL && cb->is_nmethod() ) { | |
1229 nmethod* nm = (nmethod*)cb; | |
1230 // Clean inline caches pointing to both zombie and not_entrant methods | |
1231 if (!nm->is_in_use() || (nm->method()->code() != nm)) csc->set_to_clean(); | |
1232 } | |
1233 break; | |
1234 } | |
1235 } | |
1236 } | |
1237 } | |
1238 | |
1239 // This is a private interface with the sweeper. | |
1240 void nmethod::mark_as_seen_on_stack() { | |
1241 assert(is_not_entrant(), "must be a non-entrant method"); | |
1242 // Set the traversal mark to ensure that the sweeper does 2 | |
1243 // cleaning passes before moving to zombie. | |
1244 set_stack_traversal_mark(NMethodSweeper::traversal_count()); | |
1245 } | |
1246 | |
1247 // Tell if a non-entrant method can be converted to a zombie (i.e., | |
1248 // there are no activations on the stack, not in use by the VM, | |
1249 // and not in use by the ServiceThread) | |
1250 bool nmethod::can_not_entrant_be_converted() { | |
1251 assert(is_not_entrant(), "must be a non-entrant method"); | |
1252 | |
1253 // Since the nmethod sweeper only does partial sweep the sweeper's traversal | |
1254 // count can be greater than the stack traversal count before it hits the | |
1255 // nmethod for the second time. | |
1256 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && | |
1257 !is_locked_by_vm(); | |
1258 } | |
1259 | |
1260 void nmethod::inc_decompile_count() { | |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
1261 if (!is_compiled_by_c2() && !is_compiled_by_graal()) return; |
7066 | 1262 // Could be gated by ProfileTraps, but do not bother... |
1263 Method* m = method(); | |
1264 if (m == NULL) return; | |
1265 MethodData* mdo = m->method_data(); | |
1266 if (mdo == NULL) return; | |
1267 // There is a benign race here. See comments in methodData.hpp. | |
1268 mdo->inc_decompile_count(); | |
1269 } | |
1270 | |
1271 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) { | |
1272 | |
1273 post_compiled_method_unload(); | |
1274 | |
1275 // Since this nmethod is being unloaded, make sure that dependencies | |
1276 // recorded in instanceKlasses get flushed and pass non-NULL closure to | |
1277 // indicate that this work is being done during a GC. | |
1278 assert(Universe::heap()->is_gc_active(), "should only be called during gc"); | |
1279 assert(is_alive != NULL, "Should be non-NULL"); | |
1280 // A non-NULL is_alive closure indicates that this is being called during GC. | |
1281 flush_dependencies(is_alive); | |
1282 | |
1283 // Break cycle between nmethod & method | |
1284 if (TraceClassUnloading && WizardMode) { | |
1285 tty->print_cr("[Class unloading: Making nmethod " INTPTR_FORMAT | |
1286 " unloadable], Method*(" INTPTR_FORMAT | |
1287 "), cause(" INTPTR_FORMAT ")", | |
1288 this, (address)_method, (address)cause); | |
1289 if (!Universe::heap()->is_gc_active()) | |
1290 cause->klass()->print(); | |
1291 } | |
1292 // Unlink the osr method, so we do not look this up again | |
1293 if (is_osr_method()) { | |
1294 invalidate_osr_method(); | |
1295 } | |
1296 // If _method is already NULL the Method* is about to be unloaded, | |
1297 // so we don't have to break the cycle. Note that it is possible to | |
1298 // have the Method* live here, in case we unload the nmethod because | |
1299 // it is pointing to some oop (other than the Method*) being unloaded. | |
1300 if (_method != NULL) { | |
1301 // OSR methods point to the Method*, but the Method* does not | |
1302 // point back! | |
1303 if (_method->code() == this) { | |
1304 _method->clear_code(); // Break a cycle | |
1305 } | |
1306 _method = NULL; // Clear the method of this dead nmethod | |
1307 } | |
1308 | |
9030
9a3e25e270a0
Clear installed code pointer when unloading method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9023
diff
changeset
|
1309 #ifdef GRAAL |
9046
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1310 // The method can only be unloaded after the pointer to the installed code |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1311 // Java wrapper is no longer alive. Here we need to clear out this weak |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1312 // reference to the dead object. |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1313 if (_graal_installed_code != NULL) { |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1314 _graal_installed_code = NULL; |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1315 } |
9030
9a3e25e270a0
Clear installed code pointer when unloading method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9023
diff
changeset
|
1316 #endif |
9a3e25e270a0
Clear installed code pointer when unloading method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9023
diff
changeset
|
1317 |
7066 | 1318 // Make the class unloaded - i.e., change state and notify sweeper |
1319 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
1320 if (is_in_use()) { | |
1321 // Transitioning directly from live to unloaded -- so | |
1322 // we need to force a cache clean-up; remember this | |
1323 // for later on. | |
1324 CodeCache::set_needs_cache_clean(true); | |
1325 } | |
1326 _state = unloaded; | |
1327 | |
1328 // Log the unloading. | |
1329 log_state_change(); | |
1330 | |
1331 // The Method* is gone at this point | |
1332 assert(_method == NULL, "Tautology"); | |
1333 | |
1334 set_osr_link(NULL); | |
1335 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods | |
1336 NMethodSweeper::notify(this); | |
1337 } | |
1338 | |
1339 void nmethod::invalidate_osr_method() { | |
1340 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); | |
1341 // Remove from list of active nmethods | |
1342 if (method() != NULL) | |
1343 method()->method_holder()->remove_osr_nmethod(this); | |
1344 // Set entry as invalid | |
1345 _entry_bci = InvalidOSREntryBci; | |
1346 } | |
1347 | |
1348 void nmethod::log_state_change() const { | |
1349 if (LogCompilation) { | |
1350 if (xtty != NULL) { | |
1351 ttyLocker ttyl; // keep the following output all in one block | |
1352 if (_state == unloaded) { | |
1353 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", | |
1354 os::current_thread_id()); | |
1355 } else { | |
1356 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s", | |
1357 os::current_thread_id(), | |
1358 (_state == zombie ? " zombie='1'" : "")); | |
1359 } | |
1360 log_identity(xtty); | |
1361 xtty->stamp(); | |
1362 xtty->end_elem(); | |
1363 } | |
1364 } | |
1365 if (PrintCompilation && _state != unloaded) { | |
1366 print_on(tty, _state == zombie ? "made zombie" : "made not entrant"); | |
1367 } | |
1368 } | |
1369 | |
1370 // Common functionality for both make_not_entrant and make_zombie | |
1371 bool nmethod::make_not_entrant_or_zombie(unsigned int state) { | |
1372 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); | |
1373 assert(!is_zombie(), "should not already be a zombie"); | |
1374 | |
1375 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below. | |
1376 nmethodLocker nml(this); | |
1377 methodHandle the_method(method()); | |
1378 No_Safepoint_Verifier nsv; | |
1379 | |
1380 { | |
1381 // invalidate osr nmethod before acquiring the patching lock since | |
1382 // they both acquire leaf locks and we don't want a deadlock. | |
1383 // This logic is equivalent to the logic below for patching the | |
1384 // verified entry point of regular methods. | |
1385 if (is_osr_method()) { | |
1386 // this effectively makes the osr nmethod not entrant | |
1387 invalidate_osr_method(); | |
1388 } | |
1389 | |
1390 // Enter critical section. Does not block for safepoint. | |
1391 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); | |
1392 | |
1393 if (_state == state) { | |
1394 // another thread already performed this transition so nothing | |
1395 // to do, but return false to indicate this. | |
1396 return false; | |
1397 } | |
1398 | |
1399 // The caller can be calling the method statically or through an inline | |
1400 // cache call. | |
1401 if (!is_osr_method() && !is_not_entrant()) { | |
9046
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1402 address stub = SharedRuntime::get_handle_wrong_method_stub(); |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1403 #ifdef GRAAL |
9023
f94bb5d20e5d
Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8883
diff
changeset
|
1404 if (_graal_installed_code != NULL && !HotSpotInstalledCode::isDefault(_graal_installed_code)) { |
f94bb5d20e5d
Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8883
diff
changeset
|
1405 // This was manually installed machine code. Patch entry with stub that throws an exception. |
9046
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1406 stub = SharedRuntime::get_deoptimized_installed_code_stub(); |
9023
f94bb5d20e5d
Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8883
diff
changeset
|
1407 } |
9046
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1408 #endif |
c6a1ffc707ff
Comments and #ifdef GRAAL for recent changes to C++ code for calling nmethods directly.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9030
diff
changeset
|
1409 NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), stub); |
7066 | 1410 } |
1411 | |
1412 if (is_in_use()) { | |
1413 // It's a true state change, so mark the method as decompiled. | |
1414 // Do it only for transition from alive. | |
1415 inc_decompile_count(); | |
1416 } | |
1417 | |
1418 // Change state | |
1419 _state = state; | |
1420 | |
1421 // Log the transition once | |
1422 log_state_change(); | |
1423 | |
1424 // Remove nmethod from method. | |
1425 // We need to check if both the _code and _from_compiled_code_entry_point | |
1426 // refer to this nmethod because there is a race in setting these two fields | |
1427 // in Method* as seen in bugid 4947125. | |
1428 // If the vep() points to the zombie nmethod, the memory for the nmethod | |
1429 // could be flushed and the compiler and vtable stubs could still call | |
1430 // through it. | |
1431 if (method() != NULL && (method()->code() == this || | |
1432 method()->from_compiled_entry() == verified_entry_point())) { | |
1433 HandleMark hm; | |
1434 method()->clear_code(); | |
1435 } | |
1436 | |
1437 if (state == not_entrant) { | |
1438 mark_as_seen_on_stack(); | |
1439 } | |
1440 | |
1441 } // leave critical region under Patching_lock | |
1442 | |
1443 // When the nmethod becomes zombie it is no longer alive so the | |
1444 // dependencies must be flushed. nmethods in the not_entrant | |
1445 // state will be flushed later when the transition to zombie | |
1446 // happens or they get unloaded. | |
1447 if (state == zombie) { | |
1448 { | |
1449 // Flushing dependecies must be done before any possible | |
1450 // safepoint can sneak in, otherwise the oops used by the | |
1451 // dependency logic could have become stale. | |
1452 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
1453 flush_dependencies(NULL); | |
1454 } | |
1455 | |
1456 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload | |
1457 // event and it hasn't already been reported for this nmethod then | |
1458 // report it now. The event may have been reported earilier if the GC | |
1459 // marked it for unloading). JvmtiDeferredEventQueue support means | |
1460 // we no longer go to a safepoint here. | |
1461 post_compiled_method_unload(); | |
1462 | |
1463 #ifdef ASSERT | |
1464 // It's no longer safe to access the oops section since zombie | |
1465 // nmethods aren't scanned for GC. | |
1466 _oops_are_stale = true; | |
1467 #endif | |
1468 } else { | |
1469 assert(state == not_entrant, "other cases may need to be handled differently"); | |
1470 } | |
1471 | |
1472 if (TraceCreateZombies) { | |
7112
60bef2672469
changed System.err output to TTY to avoid that DaCapo benchmarks fail digest validation
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7088
diff
changeset
|
1473 ResourceMark m; |
60bef2672469
changed System.err output to TTY to avoid that DaCapo benchmarks fail digest validation
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7088
diff
changeset
|
1474 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", this, this->method()->name_and_sig_as_C_string(), (state == not_entrant) ? "not entrant" : "zombie"); |
7066 | 1475 } |
1476 | |
1477 // Make sweeper aware that there is a zombie method that needs to be removed | |
1478 NMethodSweeper::notify(this); | |
1479 | |
1480 return true; | |
1481 } | |
1482 | |
1483 void nmethod::flush() { | |
1484 // Note that there are no valid oops in the nmethod anymore. | |
1485 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); | |
1486 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); | |
1487 | |
1488 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); | |
1489 assert_locked_or_safepoint(CodeCache_lock); | |
1490 | |
1491 // completely deallocate this method | |
1492 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, this); | |
1493 if (PrintMethodFlushing) { | |
1494 tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb", | |
1495 _compile_id, this, CodeCache::nof_blobs(), CodeCache::unallocated_capacity()/1024); | |
1496 } | |
1497 | |
1498 // We need to deallocate any ExceptionCache data. | |
1499 // Note that we do not need to grab the nmethod lock for this, it | |
1500 // better be thread safe if we're disposing of it! | |
1501 ExceptionCache* ec = exception_cache(); | |
1502 set_exception_cache(NULL); | |
1503 while(ec != NULL) { | |
1504 ExceptionCache* next = ec->next(); | |
1505 delete ec; | |
1506 ec = next; | |
1507 } | |
1508 | |
1509 if (on_scavenge_root_list()) { | |
1510 CodeCache::drop_scavenge_root_nmethod(this); | |
1511 } | |
1512 | |
1513 if (is_speculatively_disconnected()) { | |
1514 CodeCache::remove_saved_code(this); | |
1515 } | |
1516 | |
1517 #ifdef SHARK | |
1518 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin()); | |
1519 #endif // SHARK | |
1520 | |
1521 ((CodeBlob*)(this))->flush(); | |
1522 | |
1523 CodeCache::free(this); | |
1524 } | |
1525 | |
1526 | |
1527 // | |
1528 // Notify all classes this nmethod is dependent on that it is no | |
1529 // longer dependent. This should only be called in two situations. | |
1530 // First, when a nmethod transitions to a zombie all dependents need | |
1531 // to be clear. Since zombification happens at a safepoint there's no | |
1532 // synchronization issues. The second place is a little more tricky. | |
1533 // During phase 1 of mark sweep class unloading may happen and as a | |
1534 // result some nmethods may get unloaded. In this case the flushing | |
1535 // of dependencies must happen during phase 1 since after GC any | |
1536 // dependencies in the unloaded nmethod won't be updated, so | |
1537 // traversing the dependency information in unsafe. In that case this | |
1538 // function is called with a non-NULL argument and this function only | |
1539 // notifies instanceKlasses that are reachable | |
1540 | |
1541 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { | |
1542 assert_locked_or_safepoint(CodeCache_lock); | |
1543 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), | |
1544 "is_alive is non-NULL if and only if we are called during GC"); | |
1545 if (!has_flushed_dependencies()) { | |
1546 set_has_flushed_dependencies(); | |
1547 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
1548 Klass* klass = deps.context_type(); | |
1549 if (klass == NULL) continue; // ignore things like evol_method | |
1550 | |
1551 // During GC the is_alive closure is non-NULL, and is used to | |
1552 // determine liveness of dependees that need to be updated. | |
1553 if (is_alive == NULL || klass->is_loader_alive(is_alive)) { | |
1554 InstanceKlass::cast(klass)->remove_dependent_nmethod(this); | |
1555 } | |
1556 } | |
1557 } | |
1558 } | |
1559 | |
1560 | |
1561 // If this oop is not live, the nmethod can be unloaded. | |
1562 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred) { | |
1563 assert(root != NULL, "just checking"); | |
1564 oop obj = *root; | |
1565 if (obj == NULL || is_alive->do_object_b(obj)) { | |
1566 return false; | |
1567 } | |
1568 | |
1569 // If ScavengeRootsInCode is true, an nmethod might be unloaded | |
1570 // simply because one of its constant oops has gone dead. | |
1571 // No actual classes need to be unloaded in order for this to occur. | |
1572 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading"); | |
1573 make_unloaded(is_alive, obj); | |
1574 return true; | |
1575 } | |
1576 | |
1577 // ------------------------------------------------------------------ | |
1578 // post_compiled_method_load_event | |
1579 // new method for install_code() path | |
1580 // Transfer information from compilation to jvmti | |
1581 void nmethod::post_compiled_method_load_event() { | |
1582 | |
1583 Method* moop = method(); | |
1584 #ifndef USDT2 | |
1585 HS_DTRACE_PROBE8(hotspot, compiled__method__load, | |
1586 moop->klass_name()->bytes(), | |
1587 moop->klass_name()->utf8_length(), | |
1588 moop->name()->bytes(), | |
1589 moop->name()->utf8_length(), | |
1590 moop->signature()->bytes(), | |
1591 moop->signature()->utf8_length(), | |
1592 insts_begin(), insts_size()); | |
1593 #else /* USDT2 */ | |
1594 HOTSPOT_COMPILED_METHOD_LOAD( | |
1595 (char *) moop->klass_name()->bytes(), | |
1596 moop->klass_name()->utf8_length(), | |
1597 (char *) moop->name()->bytes(), | |
1598 moop->name()->utf8_length(), | |
1599 (char *) moop->signature()->bytes(), | |
1600 moop->signature()->utf8_length(), | |
1601 insts_begin(), insts_size()); | |
1602 #endif /* USDT2 */ | |
1603 | |
1604 if (JvmtiExport::should_post_compiled_method_load() || | |
1605 JvmtiExport::should_post_compiled_method_unload()) { | |
1606 get_and_cache_jmethod_id(); | |
1607 } | |
1608 | |
1609 if (JvmtiExport::should_post_compiled_method_load()) { | |
1610 // Let the Service thread (which is a real Java thread) post the event | |
1611 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); | |
1612 JvmtiDeferredEventQueue::enqueue( | |
1613 JvmtiDeferredEvent::compiled_method_load_event(this)); | |
1614 } | |
1615 } | |
1616 | |
1617 jmethodID nmethod::get_and_cache_jmethod_id() { | |
1618 if (_jmethod_id == NULL) { | |
1619 // Cache the jmethod_id since it can no longer be looked up once the | |
1620 // method itself has been marked for unloading. | |
1621 _jmethod_id = method()->jmethod_id(); | |
1622 } | |
1623 return _jmethod_id; | |
1624 } | |
1625 | |
1626 void nmethod::post_compiled_method_unload() { | |
1627 if (unload_reported()) { | |
1628 // During unloading we transition to unloaded and then to zombie | |
1629 // and the unloading is reported during the first transition. | |
1630 return; | |
1631 } | |
1632 | |
1633 assert(_method != NULL && !is_unloaded(), "just checking"); | |
1634 DTRACE_METHOD_UNLOAD_PROBE(method()); | |
1635 | |
1636 // If a JVMTI agent has enabled the CompiledMethodUnload event then | |
1637 // post the event. Sometime later this nmethod will be made a zombie | |
1638 // by the sweeper but the Method* will not be valid at that point. | |
1639 // If the _jmethod_id is null then no load event was ever requested | |
1640 // so don't bother posting the unload. The main reason for this is | |
1641 // that the jmethodID is a weak reference to the Method* so if | |
1642 // it's being unloaded there's no way to look it up since the weak | |
1643 // ref will have been cleared. | |
1644 if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) { | |
1645 assert(!unload_reported(), "already unloaded"); | |
1646 JvmtiDeferredEvent event = | |
1647 JvmtiDeferredEvent::compiled_method_unload_event(this, | |
1648 _jmethod_id, insts_begin()); | |
1649 if (SafepointSynchronize::is_at_safepoint()) { | |
1650 // Don't want to take the queueing lock. Add it as pending and | |
1651 // it will get enqueued later. | |
1652 JvmtiDeferredEventQueue::add_pending_event(event); | |
1653 } else { | |
1654 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); | |
1655 JvmtiDeferredEventQueue::enqueue(event); | |
1656 } | |
1657 } | |
1658 | |
1659 // The JVMTI CompiledMethodUnload event can be enabled or disabled at | |
1660 // any time. As the nmethod is being unloaded now we mark it has | |
1661 // having the unload event reported - this will ensure that we don't | |
1662 // attempt to report the event in the unlikely scenario where the | |
1663 // event is enabled at the time the nmethod is made a zombie. | |
1664 set_unload_reported(); | |
1665 } | |
1666 | |
1667 // This is called at the end of the strong tracing/marking phase of a | |
1668 // GC to unload an nmethod if it contains otherwise unreachable | |
1669 // oops. | |
1670 | |
1671 void nmethod::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) { | |
1672 // Make sure the oop's ready to receive visitors | |
1673 assert(!is_zombie() && !is_unloaded(), | |
1674 "should not call follow on zombie or unloaded nmethod"); | |
1675 | |
1676 // If the method is not entrant then a JMP is plastered over the | |
1677 // first few bytes. If an oop in the old code was there, that oop | |
1678 // should not get GC'd. Skip the first few bytes of oops on | |
1679 // not-entrant methods. | |
1680 address low_boundary = verified_entry_point(); | |
1681 if (is_not_entrant()) { | |
1682 low_boundary += NativeJump::instruction_size; | |
1683 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1684 // (See comment above.) | |
1685 } | |
1686 | |
1687 // The RedefineClasses() API can cause the class unloading invariant | |
1688 // to no longer be true. See jvmtiExport.hpp for details. | |
1689 // Also, leave a debugging breadcrumb in local flag. | |
1690 bool a_class_was_redefined = JvmtiExport::has_redefined_a_class(); | |
1691 if (a_class_was_redefined) { | |
1692 // This set of the unloading_occurred flag is done before the | |
1693 // call to post_compiled_method_unload() so that the unloading | |
1694 // of this nmethod is reported. | |
1695 unloading_occurred = true; | |
1696 } | |
1697 | |
1698 #ifdef GRAAL | |
1699 // Follow Graal method | |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1700 if (_graal_installed_code != NULL) { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1701 if (HotSpotInstalledCode::isDefault(_graal_installed_code)) { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1702 if (!is_alive->do_object_b(_graal_installed_code)) { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1703 _graal_installed_code = NULL; |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1704 } |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1705 } else { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1706 if (can_unload(is_alive, (oop*)&_graal_installed_code, unloading_occurred)) { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1707 return; |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1708 } |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1709 } |
7066 | 1710 } |
1711 #endif | |
1712 | |
1713 // Exception cache | |
1714 ExceptionCache* ec = exception_cache(); | |
1715 while (ec != NULL) { | |
1716 Klass* ex_klass = ec->exception_type(); | |
1717 ExceptionCache* next_ec = ec->next(); | |
1718 if (ex_klass != NULL && !ex_klass->is_loader_alive(is_alive)) { | |
1719 remove_from_exception_cache(ec); | |
1720 } | |
1721 ec = next_ec; | |
1722 } | |
1723 | |
1724 // If class unloading occurred we first iterate over all inline caches and | |
1725 // clear ICs where the cached oop is referring to an unloaded klass or method. | |
1726 // The remaining live cached oops will be traversed in the relocInfo::oop_type | |
1727 // iteration below. | |
1728 if (unloading_occurred) { | |
1729 RelocIterator iter(this, low_boundary); | |
1730 while(iter.next()) { | |
1731 if (iter.type() == relocInfo::virtual_call_type) { | |
1732 CompiledIC *ic = CompiledIC_at(iter.reloc()); | |
1733 if (ic->is_icholder_call()) { | |
1734 // The only exception is compiledICHolder oops which may | |
1735 // yet be marked below. (We check this further below). | |
1736 CompiledICHolder* cichk_oop = ic->cached_icholder(); | |
1737 if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) && | |
1738 cichk_oop->holder_klass()->is_loader_alive(is_alive)) { | |
1739 continue; | |
1740 } | |
1741 } else { | |
1742 Metadata* ic_oop = ic->cached_metadata(); | |
1743 if (ic_oop != NULL) { | |
1744 if (ic_oop->is_klass()) { | |
1745 if (((Klass*)ic_oop)->is_loader_alive(is_alive)) { | |
1746 continue; | |
1747 } | |
1748 } else if (ic_oop->is_method()) { | |
1749 if (((Method*)ic_oop)->method_holder()->is_loader_alive(is_alive)) { | |
1750 continue; | |
1751 } | |
1752 } else { | |
1753 ShouldNotReachHere(); | |
1754 } | |
1755 } | |
1756 } | |
1757 ic->set_to_clean(); | |
1758 } | |
1759 } | |
1760 } | |
1761 | |
1762 // Compiled code | |
1763 { | |
1764 RelocIterator iter(this, low_boundary); | |
1765 while (iter.next()) { | |
1766 if (iter.type() == relocInfo::oop_type) { | |
1767 oop_Relocation* r = iter.oop_reloc(); | |
1768 // In this loop, we must only traverse those oops directly embedded in | |
1769 // the code. Other oops (oop_index>0) are seen as part of scopes_oops. | |
1770 assert(1 == (r->oop_is_immediate()) + | |
1771 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), | |
1772 "oop must be found in exactly one place"); | |
1773 if (r->oop_is_immediate() && r->oop_value() != NULL) { | |
1774 if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) { | |
1775 return; | |
1776 } | |
1777 } | |
1778 } | |
1779 } | |
1780 } | |
1781 | |
1782 | |
1783 // Scopes | |
1784 for (oop* p = oops_begin(); p < oops_end(); p++) { | |
1785 if (*p == Universe::non_oop_word()) continue; // skip non-oops | |
1786 if (can_unload(is_alive, p, unloading_occurred)) { | |
1787 return; | |
1788 } | |
1789 } | |
1790 | |
1791 // Ensure that all metadata is still alive | |
1792 verify_metadata_loaders(low_boundary, is_alive); | |
1793 } | |
1794 | |
1795 #ifdef ASSERT | |
1796 | |
1797 class CheckClass : AllStatic { | |
1798 static BoolObjectClosure* _is_alive; | |
1799 | |
1800 // Check class_loader is alive for this bit of metadata. | |
1801 static void check_class(Metadata* md) { | |
1802 Klass* klass = NULL; | |
1803 if (md->is_klass()) { | |
1804 klass = ((Klass*)md); | |
1805 } else if (md->is_method()) { | |
1806 klass = ((Method*)md)->method_holder(); | |
1807 } else if (md->is_methodData()) { | |
1808 klass = ((MethodData*)md)->method()->method_holder(); | |
1809 } else { | |
1810 md->print(); | |
1811 ShouldNotReachHere(); | |
1812 } | |
1813 assert(klass->is_loader_alive(_is_alive), "must be alive"); | |
1814 } | |
1815 public: | |
1816 static void do_check_class(BoolObjectClosure* is_alive, nmethod* nm) { | |
1817 assert(SafepointSynchronize::is_at_safepoint(), "this is only ok at safepoint"); | |
1818 _is_alive = is_alive; | |
1819 nm->metadata_do(check_class); | |
1820 } | |
1821 }; | |
1822 | |
1823 // This is called during a safepoint so can use static data | |
1824 BoolObjectClosure* CheckClass::_is_alive = NULL; | |
1825 #endif // ASSERT | |
1826 | |
1827 | |
1828 // Processing of oop references should have been sufficient to keep | |
1829 // all strong references alive. Any weak references should have been | |
1830 // cleared as well. Visit all the metadata and ensure that it's | |
1831 // really alive. | |
1832 void nmethod::verify_metadata_loaders(address low_boundary, BoolObjectClosure* is_alive) { | |
1833 #ifdef ASSERT | |
8152
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
1834 RelocIterator iter(this, low_boundary); |
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
1835 while (iter.next()) { |
7066 | 1836 // static_stub_Relocations may have dangling references to |
1837 // Method*s so trim them out here. Otherwise it looks like | |
1838 // compiled code is maintaining a link to dead metadata. | |
1839 address static_call_addr = NULL; | |
1840 if (iter.type() == relocInfo::opt_virtual_call_type) { | |
1841 CompiledIC* cic = CompiledIC_at(iter.reloc()); | |
1842 if (!cic->is_call_to_interpreted()) { | |
1843 static_call_addr = iter.addr(); | |
1844 } | |
1845 } else if (iter.type() == relocInfo::static_call_type) { | |
1846 CompiledStaticCall* csc = compiledStaticCall_at(iter.reloc()); | |
1847 if (!csc->is_call_to_interpreted()) { | |
1848 static_call_addr = iter.addr(); | |
1849 } | |
1850 } | |
1851 if (static_call_addr != NULL) { | |
1852 RelocIterator sciter(this, low_boundary); | |
1853 while (sciter.next()) { | |
1854 if (sciter.type() == relocInfo::static_stub_type && | |
1855 sciter.static_stub_reloc()->static_call() == static_call_addr) { | |
1856 sciter.static_stub_reloc()->clear_inline_cache(); | |
1857 } | |
1858 } | |
1859 } | |
1860 } | |
1861 // Check that the metadata embedded in the nmethod is alive | |
1862 CheckClass::do_check_class(is_alive, this); | |
1863 #endif | |
1864 } | |
1865 | |
1866 | |
1867 // Iterate over metadata calling this function. Used by RedefineClasses | |
1868 void nmethod::metadata_do(void f(Metadata*)) { | |
1869 address low_boundary = verified_entry_point(); | |
1870 if (is_not_entrant()) { | |
1871 low_boundary += NativeJump::instruction_size; | |
1872 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1873 // (See comment above.) | |
1874 } | |
1875 { | |
1876 // Visit all immediate references that are embedded in the instruction stream. | |
1877 RelocIterator iter(this, low_boundary); | |
1878 while (iter.next()) { | |
1879 if (iter.type() == relocInfo::metadata_type ) { | |
1880 metadata_Relocation* r = iter.metadata_reloc(); | |
1881 // In this lmetadata, we must only follow those metadatas directly embedded in | |
1882 // the code. Other metadatas (oop_index>0) are seen as part of | |
1883 // the metadata section below. | |
1884 assert(1 == (r->metadata_is_immediate()) + | |
1885 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), | |
1886 "metadata must be found in exactly one place"); | |
1887 if (r->metadata_is_immediate() && r->metadata_value() != NULL) { | |
1888 Metadata* md = r->metadata_value(); | |
1889 f(md); | |
1890 } | |
1891 } | |
1892 } | |
1893 } | |
1894 | |
1895 // Visit the metadata section | |
1896 for (Metadata** p = metadata_begin(); p < metadata_end(); p++) { | |
1897 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops | |
1898 Metadata* md = *p; | |
1899 f(md); | |
1900 } | |
1901 // Call function Method*, not embedded in these other places. | |
1902 if (_method != NULL) f(_method); | |
1903 } | |
1904 | |
1905 | |
1906 // This method is called twice during GC -- once while | |
1907 // tracing the "active" nmethods on thread stacks during | |
1908 // the (strong) marking phase, and then again when walking | |
1909 // the code cache contents during the weak roots processing | |
1910 // phase. The two uses are distinguished by means of the | |
1911 // 'do_strong_roots_only' flag, which is true in the first | |
1912 // case. We want to walk the weak roots in the nmethod | |
1913 // only in the second case. The weak roots in the nmethod | |
1914 // are the oops in the ExceptionCache and the InlineCache | |
1915 // oops. | |
1916 void nmethod::oops_do(OopClosure* f, bool do_strong_roots_only) { | |
1917 // make sure the oops ready to receive visitors | |
1918 assert(!is_zombie() && !is_unloaded(), | |
1919 "should not call follow on zombie or unloaded nmethod"); | |
1920 | |
1921 // If the method is not entrant or zombie then a JMP is plastered over the | |
1922 // first few bytes. If an oop in the old code was there, that oop | |
1923 // should not get GC'd. Skip the first few bytes of oops on | |
1924 // not-entrant methods. | |
1925 address low_boundary = verified_entry_point(); | |
1926 if (is_not_entrant()) { | |
1927 low_boundary += NativeJump::instruction_size; | |
1928 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1929 // (See comment above.) | |
1930 } | |
1931 | |
1932 #ifdef GRAAL | |
8269
985a97ba083c
Fix spacing.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8215
diff
changeset
|
1933 if (_graal_installed_code != NULL) { |
7066 | 1934 f->do_oop((oop*) &_graal_installed_code); |
1935 } | |
8215
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1936 if (_triggered_deoptimizations != NULL) { |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1937 f->do_oop((oop*) &_triggered_deoptimizations); |
b89a97928e72
Implement weak reference semantics for HotSpotInstalledCode in the default method installation case. Add new boolean[] array as parameter to the code installation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8160
diff
changeset
|
1938 } |
7066 | 1939 #endif |
1940 | |
1941 RelocIterator iter(this, low_boundary); | |
1942 | |
1943 while (iter.next()) { | |
1944 if (iter.type() == relocInfo::oop_type ) { | |
1945 oop_Relocation* r = iter.oop_reloc(); | |
1946 // In this loop, we must only follow those oops directly embedded in | |
1947 // the code. Other oops (oop_index>0) are seen as part of scopes_oops. | |
1948 assert(1 == (r->oop_is_immediate()) + | |
1949 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), | |
1950 "oop must be found in exactly one place"); | |
1951 if (r->oop_is_immediate() && r->oop_value() != NULL) { | |
1952 f->do_oop(r->oop_addr()); | |
1953 } | |
1954 } | |
1955 } | |
1956 | |
1957 // Scopes | |
1958 // This includes oop constants not inlined in the code stream. | |
1959 for (oop* p = oops_begin(); p < oops_end(); p++) { | |
1960 if (*p == Universe::non_oop_word()) continue; // skip non-oops | |
1961 f->do_oop(p); | |
1962 } | |
1963 } | |
1964 | |
1965 #define NMETHOD_SENTINEL ((nmethod*)badAddress) | |
1966 | |
1967 nmethod* volatile nmethod::_oops_do_mark_nmethods; | |
1968 | |
1969 // An nmethod is "marked" if its _mark_link is set non-null. | |
1970 // Even if it is the end of the linked list, it will have a non-null link value, | |
1971 // as long as it is on the list. | |
1972 // This code must be MP safe, because it is used from parallel GC passes. | |
1973 bool nmethod::test_set_oops_do_mark() { | |
1974 assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called"); | |
1975 nmethod* observed_mark_link = _oops_do_mark_link; | |
1976 if (observed_mark_link == NULL) { | |
1977 // Claim this nmethod for this thread to mark. | |
1978 observed_mark_link = (nmethod*) | |
1979 Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL); | |
1980 if (observed_mark_link == NULL) { | |
1981 | |
1982 // Atomically append this nmethod (now claimed) to the head of the list: | |
1983 nmethod* observed_mark_nmethods = _oops_do_mark_nmethods; | |
1984 for (;;) { | |
1985 nmethod* required_mark_nmethods = observed_mark_nmethods; | |
1986 _oops_do_mark_link = required_mark_nmethods; | |
1987 observed_mark_nmethods = (nmethod*) | |
1988 Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods); | |
1989 if (observed_mark_nmethods == required_mark_nmethods) | |
1990 break; | |
1991 } | |
1992 // Mark was clear when we first saw this guy. | |
1993 NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark")); | |
1994 return false; | |
1995 } | |
1996 } | |
1997 // On fall through, another racing thread marked this nmethod before we did. | |
1998 return true; | |
1999 } | |
2000 | |
2001 void nmethod::oops_do_marking_prologue() { | |
2002 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("[oops_do_marking_prologue")); | |
2003 assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row"); | |
2004 // We use cmpxchg_ptr instead of regular assignment here because the user | |
2005 // may fork a bunch of threads, and we need them all to see the same state. | |
2006 void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL); | |
2007 guarantee(observed == NULL, "no races in this sequential code"); | |
2008 } | |
2009 | |
2010 void nmethod::oops_do_marking_epilogue() { | |
2011 assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row"); | |
2012 nmethod* cur = _oops_do_mark_nmethods; | |
2013 while (cur != NMETHOD_SENTINEL) { | |
2014 assert(cur != NULL, "not NULL-terminated"); | |
2015 nmethod* next = cur->_oops_do_mark_link; | |
2016 cur->_oops_do_mark_link = NULL; | |
2017 cur->fix_oop_relocations(); | |
2018 NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark")); | |
2019 cur = next; | |
2020 } | |
2021 void* required = _oops_do_mark_nmethods; | |
2022 void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required); | |
2023 guarantee(observed == required, "no races in this sequential code"); | |
2024 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("oops_do_marking_epilogue]")); | |
2025 } | |
2026 | |
2027 class DetectScavengeRoot: public OopClosure { | |
2028 bool _detected_scavenge_root; | |
2029 public: | |
2030 DetectScavengeRoot() : _detected_scavenge_root(false) | |
2031 { NOT_PRODUCT(_print_nm = NULL); } | |
2032 bool detected_scavenge_root() { return _detected_scavenge_root; } | |
2033 virtual void do_oop(oop* p) { | |
2034 if ((*p) != NULL && (*p)->is_scavengable()) { | |
2035 NOT_PRODUCT(maybe_print(p)); | |
2036 _detected_scavenge_root = true; | |
2037 } | |
2038 } | |
2039 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2040 | |
2041 #ifndef PRODUCT | |
2042 nmethod* _print_nm; | |
2043 void maybe_print(oop* p) { | |
2044 if (_print_nm == NULL) return; | |
2045 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); | |
2046 tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")", | |
2047 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), | |
2048 (intptr_t)(*p), (intptr_t)p); | |
2049 (*p)->print(); | |
2050 } | |
2051 #endif //PRODUCT | |
2052 }; | |
2053 | |
2054 bool nmethod::detect_scavenge_root_oops() { | |
2055 DetectScavengeRoot detect_scavenge_root; | |
2056 NOT_PRODUCT(if (TraceScavenge) detect_scavenge_root._print_nm = this); | |
2057 oops_do(&detect_scavenge_root); | |
2058 return detect_scavenge_root.detected_scavenge_root(); | |
2059 } | |
2060 | |
2061 // Method that knows how to preserve outgoing arguments at call. This method must be | |
2062 // called with a frame corresponding to a Java invoke | |
2063 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { | |
2064 #ifndef SHARK | |
2065 if (!method()->is_native()) { | |
2066 SimpleScopeDesc ssd(this, fr.pc()); | |
2067 Bytecode_invoke call(ssd.method(), ssd.bci()); | |
2068 // compiled invokedynamic call sites have an implicit receiver at | |
2069 // resolution time, so make sure it gets GC'ed. | |
2070 bool has_receiver = !call.is_invokestatic(); | |
2071 Symbol* signature = call.signature(); | |
2072 fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f); | |
2073 } | |
2074 #endif // !SHARK | |
2075 } | |
2076 | |
2077 | |
2078 oop nmethod::embeddedOop_at(u_char* p) { | |
2079 RelocIterator iter(this, p, p + 1); | |
2080 while (iter.next()) | |
2081 if (iter.type() == relocInfo::oop_type) { | |
2082 return iter.oop_reloc()->oop_value(); | |
2083 } | |
2084 return NULL; | |
2085 } | |
2086 | |
2087 | |
2088 inline bool includes(void* p, void* from, void* to) { | |
2089 return from <= p && p < to; | |
2090 } | |
2091 | |
2092 | |
2093 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) { | |
2094 assert(count >= 2, "must be sentinel values, at least"); | |
2095 | |
2096 #ifdef ASSERT | |
2097 // must be sorted and unique; we do a binary search in find_pc_desc() | |
2098 int prev_offset = pcs[0].pc_offset(); | |
2099 assert(prev_offset == PcDesc::lower_offset_limit, | |
2100 "must start with a sentinel"); | |
2101 for (int i = 1; i < count; i++) { | |
2102 int this_offset = pcs[i].pc_offset(); | |
2103 assert(this_offset > prev_offset, "offsets must be sorted"); | |
2104 prev_offset = this_offset; | |
2105 } | |
2106 assert(prev_offset == PcDesc::upper_offset_limit, | |
2107 "must end with a sentinel"); | |
2108 #endif //ASSERT | |
2109 | |
2110 // Search for MethodHandle invokes and tag the nmethod. | |
2111 for (int i = 0; i < count; i++) { | |
2112 if (pcs[i].is_method_handle_invoke()) { | |
2113 set_has_method_handle_invokes(true); | |
2114 break; | |
2115 } | |
2116 } | |
2117 assert(has_method_handle_invokes() == (_deoptimize_mh_offset != -1), "must have deopt mh handler"); | |
2118 | |
2119 int size = count * sizeof(PcDesc); | |
2120 assert(scopes_pcs_size() >= size, "oob"); | |
2121 memcpy(scopes_pcs_begin(), pcs, size); | |
2122 | |
2123 // Adjust the final sentinel downward. | |
2124 PcDesc* last_pc = &scopes_pcs_begin()[count-1]; | |
2125 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity"); | |
2126 last_pc->set_pc_offset(content_size() + 1); | |
2127 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) { | |
2128 // Fill any rounding gaps with copies of the last record. | |
2129 last_pc[1] = last_pc[0]; | |
2130 } | |
2131 // The following assert could fail if sizeof(PcDesc) is not | |
2132 // an integral multiple of oopSize (the rounding term). | |
2133 // If it fails, change the logic to always allocate a multiple | |
2134 // of sizeof(PcDesc), and fill unused words with copies of *last_pc. | |
2135 assert(last_pc + 1 == scopes_pcs_end(), "must match exactly"); | |
2136 } | |
2137 | |
2138 void nmethod::copy_scopes_data(u_char* buffer, int size) { | |
2139 assert(scopes_data_size() >= size, "oob"); | |
2140 memcpy(scopes_data_begin(), buffer, size); | |
2141 } | |
2142 | |
2143 | |
2144 #ifdef ASSERT | |
2145 static PcDesc* linear_search(nmethod* nm, int pc_offset, bool approximate) { | |
2146 PcDesc* lower = nm->scopes_pcs_begin(); | |
2147 PcDesc* upper = nm->scopes_pcs_end(); | |
2148 lower += 1; // exclude initial sentinel | |
2149 PcDesc* res = NULL; | |
2150 for (PcDesc* p = lower; p < upper; p++) { | |
2151 NOT_PRODUCT(--nmethod_stats.pc_desc_tests); // don't count this call to match_desc | |
2152 if (match_desc(p, pc_offset, approximate)) { | |
2153 if (res == NULL) | |
2154 res = p; | |
2155 else | |
2156 res = (PcDesc*) badAddress; | |
2157 } | |
2158 } | |
2159 return res; | |
2160 } | |
2161 #endif | |
2162 | |
2163 | |
2164 // Finds a PcDesc with real-pc equal to "pc" | |
2165 PcDesc* nmethod::find_pc_desc_internal(address pc, bool approximate) { | |
2166 address base_address = code_begin(); | |
2167 if ((pc < base_address) || | |
2168 (pc - base_address) >= (ptrdiff_t) PcDesc::upper_offset_limit) { | |
2169 return NULL; // PC is wildly out of range | |
2170 } | |
2171 int pc_offset = (int) (pc - base_address); | |
2172 | |
2173 // Check the PcDesc cache if it contains the desired PcDesc | |
2174 // (This as an almost 100% hit rate.) | |
2175 PcDesc* res = _pc_desc_cache.find_pc_desc(pc_offset, approximate); | |
2176 if (res != NULL) { | |
2177 assert(res == linear_search(this, pc_offset, approximate), "cache ok"); | |
2178 return res; | |
2179 } | |
2180 | |
2181 // Fallback algorithm: quasi-linear search for the PcDesc | |
2182 // Find the last pc_offset less than the given offset. | |
2183 // The successor must be the required match, if there is a match at all. | |
2184 // (Use a fixed radix to avoid expensive affine pointer arithmetic.) | |
2185 PcDesc* lower = scopes_pcs_begin(); | |
2186 PcDesc* upper = scopes_pcs_end(); | |
2187 upper -= 1; // exclude final sentinel | |
2188 if (lower >= upper) return NULL; // native method; no PcDescs at all | |
2189 | |
2190 #define assert_LU_OK \ | |
2191 /* invariant on lower..upper during the following search: */ \ | |
2192 assert(lower->pc_offset() < pc_offset, "sanity"); \ | |
2193 assert(upper->pc_offset() >= pc_offset, "sanity") | |
2194 assert_LU_OK; | |
2195 | |
2196 // Use the last successful return as a split point. | |
2197 PcDesc* mid = _pc_desc_cache.last_pc_desc(); | |
2198 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2199 if (mid->pc_offset() < pc_offset) { | |
2200 lower = mid; | |
2201 } else { | |
2202 upper = mid; | |
2203 } | |
2204 | |
2205 // Take giant steps at first (4096, then 256, then 16, then 1) | |
2206 const int LOG2_RADIX = 4 /*smaller steps in debug mode:*/ debug_only(-1); | |
2207 const int RADIX = (1 << LOG2_RADIX); | |
2208 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) { | |
2209 while ((mid = lower + step) < upper) { | |
2210 assert_LU_OK; | |
2211 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2212 if (mid->pc_offset() < pc_offset) { | |
2213 lower = mid; | |
2214 } else { | |
2215 upper = mid; | |
2216 break; | |
2217 } | |
2218 } | |
2219 assert_LU_OK; | |
2220 } | |
2221 | |
2222 // Sneak up on the value with a linear search of length ~16. | |
2223 while (true) { | |
2224 assert_LU_OK; | |
2225 mid = lower + 1; | |
2226 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2227 if (mid->pc_offset() < pc_offset) { | |
2228 lower = mid; | |
2229 } else { | |
2230 upper = mid; | |
2231 break; | |
2232 } | |
2233 } | |
2234 #undef assert_LU_OK | |
2235 | |
2236 if (match_desc(upper, pc_offset, approximate)) { | |
2237 assert(upper == linear_search(this, pc_offset, approximate), "search ok"); | |
2238 _pc_desc_cache.add_pc_desc(upper); | |
2239 return upper; | |
2240 } else { | |
2241 assert(NULL == linear_search(this, pc_offset, approximate), "search ok"); | |
2242 return NULL; | |
2243 } | |
2244 } | |
2245 | |
2246 | |
2247 bool nmethod::check_all_dependencies() { | |
2248 bool found_check = false; | |
2249 // wholesale check of all dependencies | |
2250 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2251 if (deps.check_dependency() != NULL) { | |
2252 found_check = true; | |
2253 NOT_DEBUG(break); | |
2254 } | |
2255 } | |
2256 return found_check; // tell caller if we found anything | |
2257 } | |
2258 | |
2259 bool nmethod::check_dependency_on(DepChange& changes) { | |
2260 // What has happened: | |
2261 // 1) a new class dependee has been added | |
2262 // 2) dependee and all its super classes have been marked | |
2263 bool found_check = false; // set true if we are upset | |
2264 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2265 // Evaluate only relevant dependencies. | |
2266 if (deps.spot_check_dependency_at(changes) != NULL) { | |
2267 found_check = true; | |
2268 NOT_DEBUG(break); | |
2269 } | |
2270 } | |
2271 return found_check; | |
2272 } | |
2273 | |
2274 bool nmethod::is_evol_dependent_on(Klass* dependee) { | |
2275 InstanceKlass *dependee_ik = InstanceKlass::cast(dependee); | |
2276 Array<Method*>* dependee_methods = dependee_ik->methods(); | |
2277 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2278 if (deps.type() == Dependencies::evol_method) { | |
2279 Method* method = deps.method_argument(0); | |
2280 for (int j = 0; j < dependee_methods->length(); j++) { | |
2281 if (dependee_methods->at(j) == method) { | |
2282 // RC_TRACE macro has an embedded ResourceMark | |
2283 RC_TRACE(0x01000000, | |
2284 ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)", | |
2285 _method->method_holder()->external_name(), | |
2286 _method->name()->as_C_string(), | |
2287 _method->signature()->as_C_string(), compile_id(), | |
2288 method->method_holder()->external_name(), | |
2289 method->name()->as_C_string(), | |
2290 method->signature()->as_C_string())); | |
2291 if (TraceDependencies || LogCompilation) | |
2292 deps.log_dependency(dependee); | |
2293 return true; | |
2294 } | |
2295 } | |
2296 } | |
2297 } | |
2298 return false; | |
2299 } | |
2300 | |
2301 // Called from mark_for_deoptimization, when dependee is invalidated. | |
2302 bool nmethod::is_dependent_on_method(Method* dependee) { | |
2303 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2304 if (deps.type() != Dependencies::evol_method) | |
2305 continue; | |
2306 Method* method = deps.method_argument(0); | |
2307 if (method == dependee) return true; | |
2308 } | |
2309 return false; | |
2310 } | |
2311 | |
2312 | |
2313 bool nmethod::is_patchable_at(address instr_addr) { | |
2314 assert(insts_contains(instr_addr), "wrong nmethod used"); | |
2315 if (is_zombie()) { | |
2316 // a zombie may never be patched | |
2317 return false; | |
2318 } | |
2319 return true; | |
2320 } | |
2321 | |
2322 | |
2323 address nmethod::continuation_for_implicit_exception(address pc) { | |
2324 // Exception happened outside inline-cache check code => we are inside | |
2325 // an active nmethod => use cpc to determine a return address | |
2326 int exception_offset = pc - code_begin(); | |
2327 int cont_offset = ImplicitExceptionTable(this).at( exception_offset ); | |
2328 #ifdef ASSERT | |
2329 if (cont_offset == 0) { | |
2330 Thread* thread = ThreadLocalStorage::get_thread_slow(); | |
2331 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY | |
2332 HandleMark hm(thread); | |
2333 ResourceMark rm(thread); | |
2334 CodeBlob* cb = CodeCache::find_blob(pc); | |
2335 assert(cb != NULL && cb == this, ""); | |
2336 tty->print_cr("implicit exception happened at " INTPTR_FORMAT, pc); | |
2337 print(); | |
2338 method()->print_codes(); | |
2339 print_code(); | |
2340 print_pcs(); | |
2341 } | |
2342 #endif | |
2343 if (cont_offset == 0) { | |
2344 // Let the normal error handling report the exception | |
2345 return NULL; | |
2346 } | |
2347 return code_begin() + cont_offset; | |
2348 } | |
2349 | |
2350 | |
2351 | |
2352 void nmethod_init() { | |
2353 // make sure you didn't forget to adjust the filler fields | |
2354 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word"); | |
2355 } | |
2356 | |
2357 | |
2358 //------------------------------------------------------------------------------------------- | |
2359 | |
2360 | |
2361 // QQQ might we make this work from a frame?? | |
2362 nmethodLocker::nmethodLocker(address pc) { | |
2363 CodeBlob* cb = CodeCache::find_blob(pc); | |
2364 guarantee(cb != NULL && cb->is_nmethod(), "bad pc for a nmethod found"); | |
2365 _nm = (nmethod*)cb; | |
2366 lock_nmethod(_nm); | |
2367 } | |
2368 | |
2369 // Only JvmtiDeferredEvent::compiled_method_unload_event() | |
2370 // should pass zombie_ok == true. | |
2371 void nmethodLocker::lock_nmethod(nmethod* nm, bool zombie_ok) { | |
2372 if (nm == NULL) return; | |
2373 Atomic::inc(&nm->_lock_count); | |
2374 guarantee(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method"); | |
2375 } | |
2376 | |
2377 void nmethodLocker::unlock_nmethod(nmethod* nm) { | |
2378 if (nm == NULL) return; | |
2379 Atomic::dec(&nm->_lock_count); | |
2380 guarantee(nm->_lock_count >= 0, "unmatched nmethod lock/unlock"); | |
2381 } | |
2382 | |
2383 | |
2384 // ----------------------------------------------------------------------------- | |
2385 // nmethod::get_deopt_original_pc | |
2386 // | |
2387 // Return the original PC for the given PC if: | |
2388 // (a) the given PC belongs to a nmethod and | |
2389 // (b) it is a deopt PC | |
2390 address nmethod::get_deopt_original_pc(const frame* fr) { | |
2391 if (fr->cb() == NULL) return NULL; | |
2392 | |
2393 nmethod* nm = fr->cb()->as_nmethod_or_null(); | |
2394 if (nm != NULL && nm->is_deopt_pc(fr->pc())) | |
2395 return nm->get_original_pc(fr); | |
2396 | |
2397 return NULL; | |
2398 } | |
2399 | |
2400 | |
2401 // ----------------------------------------------------------------------------- | |
2402 // MethodHandle | |
2403 | |
2404 bool nmethod::is_method_handle_return(address return_pc) { | |
2405 if (!has_method_handle_invokes()) return false; | |
2406 PcDesc* pd = pc_desc_at(return_pc); | |
2407 if (pd == NULL) | |
2408 return false; | |
2409 return pd->is_method_handle_invoke(); | |
2410 } | |
2411 | |
2412 | |
2413 // ----------------------------------------------------------------------------- | |
2414 // Verification | |
2415 | |
2416 class VerifyOopsClosure: public OopClosure { | |
2417 nmethod* _nm; | |
2418 bool _ok; | |
2419 public: | |
2420 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { } | |
2421 bool ok() { return _ok; } | |
2422 virtual void do_oop(oop* p) { | |
2423 if ((*p) == NULL || (*p)->is_oop()) return; | |
2424 if (_ok) { | |
2425 _nm->print_nmethod(true); | |
2426 _ok = false; | |
2427 } | |
2428 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", | |
2429 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); | |
2430 } | |
2431 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2432 }; | |
2433 | |
2434 void nmethod::verify() { | |
2435 | |
2436 // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant | |
2437 // seems odd. | |
2438 | |
2439 if( is_zombie() || is_not_entrant() ) | |
2440 return; | |
2441 | |
2442 // Make sure all the entry points are correctly aligned for patching. | |
2443 NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point()); | |
2444 | |
2445 // assert(method()->is_oop(), "must be valid"); | |
2446 | |
2447 ResourceMark rm; | |
2448 | |
2449 if (!CodeCache::contains(this)) { | |
2450 fatal(err_msg("nmethod at " INTPTR_FORMAT " not in zone", this)); | |
2451 } | |
2452 | |
2453 if(is_native_method() ) | |
2454 return; | |
2455 | |
2456 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); | |
2457 if (nm != this) { | |
2458 fatal(err_msg("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", | |
2459 this)); | |
2460 } | |
2461 | |
2462 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2463 if (! p->verify(this)) { | |
2464 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", this); | |
2465 } | |
2466 } | |
2467 | |
2468 VerifyOopsClosure voc(this); | |
2469 oops_do(&voc); | |
2470 assert(voc.ok(), "embedded oops must be OK"); | |
2471 verify_scavenge_root_oops(); | |
2472 | |
2473 verify_scopes(); | |
2474 } | |
2475 | |
2476 | |
2477 void nmethod::verify_interrupt_point(address call_site) { | |
2478 // This code does not work in release mode since | |
2479 // owns_lock only is available in debug mode. | |
2480 CompiledIC* ic = NULL; | |
2481 Thread *cur = Thread::current(); | |
2482 if (CompiledIC_lock->owner() == cur || | |
2483 ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) && | |
2484 SafepointSynchronize::is_at_safepoint())) { | |
2485 ic = CompiledIC_at(this, call_site); | |
2486 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); | |
2487 } else { | |
2488 MutexLocker ml_verify (CompiledIC_lock); | |
2489 ic = CompiledIC_at(this, call_site); | |
2490 } | |
8501
41fc46da946a
-More fixes and passrate(fop)
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
7693
diff
changeset
|
2491 |
7066 | 2492 PcDesc* pd = pc_desc_at(ic->end_of_call()); |
2493 assert(pd != NULL, "PcDesc must exist"); | |
2494 for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(), | |
2495 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), | |
2496 pd->return_oop()); | |
2497 !sd->is_top(); sd = sd->sender()) { | |
2498 sd->verify(); | |
2499 } | |
2500 } | |
2501 | |
2502 void nmethod::verify_scopes() { | |
2503 if( !method() ) return; // Runtime stubs have no scope | |
2504 if (method()->is_native()) return; // Ignore stub methods. | |
2505 // iterate through all interrupt point | |
2506 // and verify the debug information is valid. | |
2507 RelocIterator iter((nmethod*)this); | |
2508 while (iter.next()) { | |
2509 address stub = NULL; | |
2510 switch (iter.type()) { | |
2511 case relocInfo::virtual_call_type: | |
2512 verify_interrupt_point(iter.addr()); | |
2513 break; | |
2514 case relocInfo::opt_virtual_call_type: | |
2515 stub = iter.opt_virtual_call_reloc()->static_stub(); | |
2516 verify_interrupt_point(iter.addr()); | |
2517 break; | |
2518 case relocInfo::static_call_type: | |
2519 stub = iter.static_call_reloc()->static_stub(); | |
2520 //verify_interrupt_point(iter.addr()); | |
2521 break; | |
2522 case relocInfo::runtime_call_type: | |
2523 address destination = iter.reloc()->value(); | |
2524 // Right now there is no way to find out which entries support | |
2525 // an interrupt point. It would be nice if we had this | |
2526 // information in a table. | |
2527 break; | |
2528 } | |
2529 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section"); | |
2530 } | |
2531 } | |
2532 | |
2533 | |
2534 // ----------------------------------------------------------------------------- | |
2535 // Non-product code | |
2536 #ifndef PRODUCT | |
2537 | |
2538 class DebugScavengeRoot: public OopClosure { | |
2539 nmethod* _nm; | |
2540 bool _ok; | |
2541 public: | |
2542 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { } | |
2543 bool ok() { return _ok; } | |
2544 virtual void do_oop(oop* p) { | |
2545 if ((*p) == NULL || !(*p)->is_scavengable()) return; | |
2546 if (_ok) { | |
2547 _nm->print_nmethod(true); | |
2548 _ok = false; | |
2549 } | |
2550 tty->print_cr("*** scavengable oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", | |
2551 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); | |
2552 (*p)->print(); | |
2553 } | |
2554 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2555 }; | |
2556 | |
2557 void nmethod::verify_scavenge_root_oops() { | |
2558 if (!on_scavenge_root_list()) { | |
2559 // Actually look inside, to verify the claim that it's clean. | |
2560 DebugScavengeRoot debug_scavenge_root(this); | |
2561 oops_do(&debug_scavenge_root); | |
2562 if (!debug_scavenge_root.ok()) | |
2563 fatal("found an unadvertised bad scavengable oop in the code cache"); | |
2564 } | |
2565 assert(scavenge_root_not_marked(), ""); | |
2566 } | |
2567 | |
2568 #endif // PRODUCT | |
2569 | |
2570 // Printing operations | |
2571 | |
2572 void nmethod::print() const { | |
2573 ResourceMark rm; | |
2574 ttyLocker ttyl; // keep the following output all in one block | |
2575 | |
2576 tty->print("Compiled method "); | |
2577 | |
2578 if (is_compiled_by_c1()) { | |
2579 tty->print("(c1) "); | |
2580 } else if (is_compiled_by_c2()) { | |
2581 tty->print("(c2) "); | |
2582 } else if (is_compiled_by_shark()) { | |
2583 tty->print("(shark) "); | |
7125
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
2584 } else if (is_compiled_by_graal()) { |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
2585 tty->print("(Graal) "); |
7066 | 2586 } else { |
2587 tty->print("(nm) "); | |
2588 } | |
2589 | |
2590 print_on(tty, NULL); | |
2591 | |
2592 if (WizardMode) { | |
2593 tty->print("((nmethod*) "INTPTR_FORMAT ") ", this); | |
2594 tty->print(" for method " INTPTR_FORMAT , (address)method()); | |
2595 tty->print(" { "); | |
2596 if (is_in_use()) tty->print("in_use "); | |
2597 if (is_not_entrant()) tty->print("not_entrant "); | |
2598 if (is_zombie()) tty->print("zombie "); | |
2599 if (is_unloaded()) tty->print("unloaded "); | |
2600 if (on_scavenge_root_list()) tty->print("scavenge_root "); | |
2601 tty->print_cr("}:"); | |
2602 } | |
2603 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2604 (address)this, | |
2605 (address)this + size(), | |
2606 size()); | |
2607 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2608 relocation_begin(), | |
2609 relocation_end(), | |
2610 relocation_size()); | |
2611 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2612 consts_begin(), | |
2613 consts_end(), | |
2614 consts_size()); | |
2615 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2616 insts_begin(), | |
2617 insts_end(), | |
2618 insts_size()); | |
2619 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2620 stub_begin(), | |
2621 stub_end(), | |
2622 stub_size()); | |
2623 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2624 oops_begin(), | |
2625 oops_end(), | |
2626 oops_size()); | |
2627 if (metadata_size () > 0) tty->print_cr(" metadata [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2628 metadata_begin(), | |
2629 metadata_end(), | |
2630 metadata_size()); | |
2631 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2632 scopes_data_begin(), | |
2633 scopes_data_end(), | |
2634 scopes_data_size()); | |
2635 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2636 scopes_pcs_begin(), | |
2637 scopes_pcs_end(), | |
2638 scopes_pcs_size()); | |
2639 if (dependencies_size () > 0) tty->print_cr(" dependencies [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2640 dependencies_begin(), | |
2641 dependencies_end(), | |
2642 dependencies_size()); | |
2643 if (handler_table_size() > 0) tty->print_cr(" handler table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2644 handler_table_begin(), | |
2645 handler_table_end(), | |
2646 handler_table_size()); | |
2647 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2648 nul_chk_table_begin(), | |
2649 nul_chk_table_end(), | |
2650 nul_chk_table_size()); | |
2651 } | |
2652 | |
2653 void nmethod::print_code() { | |
2654 HandleMark hm; | |
2655 ResourceMark m; | |
2656 Disassembler::decode(this); | |
2657 } | |
2658 | |
2659 | |
2660 #ifndef PRODUCT | |
2661 | |
2662 void nmethod::print_scopes() { | |
2663 // Find the first pc desc for all scopes in the code and print it. | |
2664 ResourceMark rm; | |
2665 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2666 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null) | |
2667 continue; | |
2668 | |
2669 ScopeDesc* sd = scope_desc_at(p->real_pc(this)); | |
2670 sd->print_on(tty, p); | |
2671 } | |
2672 } | |
2673 | |
2674 void nmethod::print_dependencies() { | |
2675 ResourceMark rm; | |
2676 ttyLocker ttyl; // keep the following output all in one block | |
2677 tty->print_cr("Dependencies:"); | |
2678 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2679 deps.print_dependency(); | |
2680 Klass* ctxk = deps.context_type(); | |
2681 if (ctxk != NULL) { | |
2682 if (ctxk->oop_is_instance() && ((InstanceKlass*)ctxk)->is_dependent_nmethod(this)) { | |
2683 tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name()); | |
2684 } | |
2685 } | |
2686 deps.log_dependency(); // put it into the xml log also | |
2687 } | |
2688 } | |
2689 | |
2690 | |
2691 void nmethod::print_relocations() { | |
2692 ResourceMark m; // in case methods get printed via the debugger | |
2693 tty->print_cr("relocations:"); | |
2694 RelocIterator iter(this); | |
2695 iter.print(); | |
2696 if (UseRelocIndex) { | |
2697 jint* index_end = (jint*)relocation_end() - 1; | |
2698 jint index_size = *index_end; | |
2699 jint* index_start = (jint*)( (address)index_end - index_size ); | |
2700 tty->print_cr(" index @" INTPTR_FORMAT ": index_size=%d", index_start, index_size); | |
2701 if (index_size > 0) { | |
2702 jint* ip; | |
2703 for (ip = index_start; ip+2 <= index_end; ip += 2) | |
2704 tty->print_cr(" (%d %d) addr=" INTPTR_FORMAT " @" INTPTR_FORMAT, | |
2705 ip[0], | |
2706 ip[1], | |
2707 header_end()+ip[0], | |
2708 relocation_begin()-1+ip[1]); | |
2709 for (; ip < index_end; ip++) | |
2710 tty->print_cr(" (%d ?)", ip[0]); | |
2711 tty->print_cr(" @" INTPTR_FORMAT ": index_size=%d", ip, *ip++); | |
2712 tty->print_cr("reloc_end @" INTPTR_FORMAT ":", ip); | |
2713 } | |
2714 } | |
2715 } | |
2716 | |
2717 | |
2718 void nmethod::print_pcs() { | |
2719 ResourceMark m; // in case methods get printed via debugger | |
2720 tty->print_cr("pc-bytecode offsets:"); | |
2721 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2722 p->print(this); | |
2723 } | |
2724 } | |
2725 | |
2726 #endif // PRODUCT | |
2727 | |
2728 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) { | |
2729 RelocIterator iter(this, begin, end); | |
2730 bool have_one = false; | |
2731 while (iter.next()) { | |
2732 have_one = true; | |
2733 switch (iter.type()) { | |
2734 case relocInfo::none: return "no_reloc"; | |
2735 case relocInfo::oop_type: { | |
2736 stringStream st; | |
2737 oop_Relocation* r = iter.oop_reloc(); | |
2738 oop obj = r->oop_value(); | |
2739 st.print("oop("); | |
2740 if (obj == NULL) st.print("NULL"); | |
2741 else obj->print_value_on(&st); | |
2742 st.print(")"); | |
2743 return st.as_string(); | |
2744 } | |
2745 case relocInfo::metadata_type: { | |
2746 stringStream st; | |
2747 metadata_Relocation* r = iter.metadata_reloc(); | |
2748 Metadata* obj = r->metadata_value(); | |
2749 st.print("metadata("); | |
2750 if (obj == NULL) st.print("NULL"); | |
2751 else obj->print_value_on(&st); | |
2752 st.print(")"); | |
2753 return st.as_string(); | |
2754 } | |
2755 case relocInfo::virtual_call_type: return "virtual_call"; | |
2756 case relocInfo::opt_virtual_call_type: return "optimized virtual_call"; | |
2757 case relocInfo::static_call_type: return "static_call"; | |
2758 case relocInfo::static_stub_type: return "static_stub"; | |
2759 case relocInfo::runtime_call_type: return "runtime_call"; | |
2760 case relocInfo::external_word_type: return "external_word"; | |
2761 case relocInfo::internal_word_type: return "internal_word"; | |
2762 case relocInfo::section_word_type: return "section_word"; | |
2763 case relocInfo::poll_type: return "poll"; | |
2764 case relocInfo::poll_return_type: return "poll_return"; | |
2765 case relocInfo::type_mask: return "type_bit_mask"; | |
2766 } | |
2767 } | |
2768 return have_one ? "other" : NULL; | |
2769 } | |
2770 | |
2771 // Return a the last scope in (begin..end] | |
2772 ScopeDesc* nmethod::scope_desc_in(address begin, address end) { | |
2773 PcDesc* p = pc_desc_near(begin+1); | |
2774 if (p != NULL && p->real_pc(this) <= end) { | |
2775 return new ScopeDesc(this, p->scope_decode_offset(), | |
2776 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(), | |
2777 p->return_oop()); | |
2778 } | |
2779 return NULL; | |
2780 } | |
2781 | |
2782 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const { | |
2783 if (block_begin == entry_point()) stream->print_cr("[Entry Point]"); | |
2784 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); | |
2785 if (GRAAL_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); | |
2786 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); | |
2787 if (GRAAL_ONLY(_deoptimize_offset >= 0 &&) block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); | |
2788 | |
2789 if (has_method_handle_invokes()) | |
2790 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); | |
2791 | |
2792 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); | |
2793 | |
2794 if (block_begin == entry_point()) { | |
2795 methodHandle m = method(); | |
2796 if (m.not_null()) { | |
2797 stream->print(" # "); | |
2798 m->print_value_on(stream); | |
2799 stream->cr(); | |
2800 } | |
2801 if (m.not_null() && !is_osr_method()) { | |
2802 ResourceMark rm; | |
2803 int sizeargs = m->size_of_parameters(); | |
2804 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); | |
2805 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); | |
2806 { | |
2807 int sig_index = 0; | |
2808 if (!m->is_static()) | |
2809 sig_bt[sig_index++] = T_OBJECT; // 'this' | |
2810 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) { | |
2811 BasicType t = ss.type(); | |
2812 sig_bt[sig_index++] = t; | |
2813 if (type2size[t] == 2) { | |
2814 sig_bt[sig_index++] = T_VOID; | |
2815 } else { | |
2816 assert(type2size[t] == 1, "size is 1 or 2"); | |
2817 } | |
2818 } | |
2819 assert(sig_index == sizeargs, ""); | |
2820 } | |
2821 const char* spname = "sp"; // make arch-specific? | |
2822 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, false); | |
2823 int stack_slot_offset = this->frame_size() * wordSize; | |
2824 int tab1 = 14, tab2 = 24; | |
2825 int sig_index = 0; | |
2826 int arg_index = (m->is_static() ? 0 : -1); | |
2827 bool did_old_sp = false; | |
2828 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) { | |
2829 bool at_this = (arg_index == -1); | |
2830 bool at_old_sp = false; | |
2831 BasicType t = (at_this ? T_OBJECT : ss.type()); | |
2832 assert(t == sig_bt[sig_index], "sigs in sync"); | |
2833 if (at_this) | |
2834 stream->print(" # this: "); | |
2835 else | |
2836 stream->print(" # parm%d: ", arg_index); | |
2837 stream->move_to(tab1); | |
2838 VMReg fst = regs[sig_index].first(); | |
2839 VMReg snd = regs[sig_index].second(); | |
2840 if (fst->is_reg()) { | |
2841 stream->print("%s", fst->name()); | |
2842 if (snd->is_valid()) { | |
2843 stream->print(":%s", snd->name()); | |
2844 } | |
2845 } else if (fst->is_stack()) { | |
2846 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset; | |
2847 if (offset == stack_slot_offset) at_old_sp = true; | |
2848 stream->print("[%s+0x%x]", spname, offset); | |
2849 } else { | |
2850 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd); | |
2851 } | |
2852 stream->print(" "); | |
2853 stream->move_to(tab2); | |
2854 stream->print("= "); | |
2855 if (at_this) { | |
2856 m->method_holder()->print_value_on(stream); | |
2857 } else { | |
2858 bool did_name = false; | |
2859 if (!at_this && ss.is_object()) { | |
2860 Symbol* name = ss.as_symbol_or_null(); | |
2861 if (name != NULL) { | |
2862 name->print_value_on(stream); | |
2863 did_name = true; | |
2864 } | |
2865 } | |
2866 if (!did_name) | |
2867 stream->print("%s", type2name(t)); | |
2868 } | |
2869 if (at_old_sp) { | |
2870 stream->print(" (%s of caller)", spname); | |
2871 did_old_sp = true; | |
2872 } | |
2873 stream->cr(); | |
2874 sig_index += type2size[t]; | |
2875 arg_index += 1; | |
2876 if (!at_this) ss.next(); | |
2877 } | |
2878 if (!did_old_sp) { | |
2879 stream->print(" # "); | |
2880 stream->move_to(tab1); | |
2881 stream->print("[%s+0x%x]", spname, stack_slot_offset); | |
2882 stream->print(" (%s of caller)", spname); | |
2883 stream->cr(); | |
2884 } | |
2885 } | |
2886 } | |
2887 } | |
2888 | |
2889 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) { | |
2890 // First, find an oopmap in (begin, end]. | |
2891 // We use the odd half-closed interval so that oop maps and scope descs | |
2892 // which are tied to the byte after a call are printed with the call itself. | |
2893 address base = code_begin(); | |
2894 OopMapSet* oms = oop_maps(); | |
2895 if (oms != NULL) { | |
2896 for (int i = 0, imax = oms->size(); i < imax; i++) { | |
2897 OopMap* om = oms->at(i); | |
2898 address pc = base + om->offset(); | |
2899 if (pc > begin) { | |
2900 if (pc <= end) { | |
2901 st->move_to(column); | |
2902 st->print("; "); | |
2903 om->print_on(st); | |
2904 } | |
2905 break; | |
2906 } | |
2907 } | |
2908 } | |
2909 | |
2910 // Print any debug info present at this pc. | |
2911 ScopeDesc* sd = scope_desc_in(begin, end); | |
2912 if (sd != NULL) { | |
2913 st->move_to(column); | |
2914 if (sd->bci() == SynchronizationEntryBCI) { | |
2915 st->print(";*synchronization entry"); | |
2916 } else { | |
2917 if (sd->method() == NULL) { | |
2918 st->print("method is NULL"); | |
2919 } else if (sd->method()->is_native()) { | |
2920 st->print("method is native"); | |
2921 } else { | |
2922 Bytecodes::Code bc = sd->method()->java_code_at(sd->bci()); | |
2923 st->print(";*%s", Bytecodes::name(bc)); | |
2924 switch (bc) { | |
2925 case Bytecodes::_invokevirtual: | |
2926 case Bytecodes::_invokespecial: | |
2927 case Bytecodes::_invokestatic: | |
2928 case Bytecodes::_invokeinterface: | |
2929 { | |
2930 Bytecode_invoke invoke(sd->method(), sd->bci()); | |
2931 st->print(" "); | |
2932 if (invoke.name() != NULL) | |
2933 invoke.name()->print_symbol_on(st); | |
2934 else | |
2935 st->print("<UNKNOWN>"); | |
2936 break; | |
2937 } | |
2938 case Bytecodes::_getfield: | |
2939 case Bytecodes::_putfield: | |
2940 case Bytecodes::_getstatic: | |
2941 case Bytecodes::_putstatic: | |
2942 { | |
2943 Bytecode_field field(sd->method(), sd->bci()); | |
2944 st->print(" "); | |
2945 if (field.name() != NULL) | |
2946 field.name()->print_symbol_on(st); | |
2947 else | |
2948 st->print("<UNKNOWN>"); | |
2949 } | |
2950 } | |
2951 } | |
2952 } | |
2953 | |
2954 // Print all scopes | |
2955 for (;sd != NULL; sd = sd->sender()) { | |
2956 st->move_to(column); | |
2957 st->print("; -"); | |
2958 if (sd->method() == NULL) { | |
2959 st->print("method is NULL"); | |
2960 } else { | |
2961 sd->method()->print_short_name(st); | |
2962 } | |
2963 int lineno = sd->method()->line_number_from_bci(sd->bci()); | |
2964 if (lineno != -1) { | |
2965 st->print("@%d (line %d)", sd->bci(), lineno); | |
2966 } else { | |
2967 st->print("@%d", sd->bci()); | |
2968 } | |
2969 st->cr(); | |
2970 } | |
2971 } | |
2972 | |
2973 // Print relocation information | |
2974 const char* str = reloc_string_for(begin, end); | |
2975 if (str != NULL) { | |
2976 if (sd != NULL) st->cr(); | |
2977 st->move_to(column); | |
2978 st->print("; {%s}", str); | |
2979 } | |
2980 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin()); | |
2981 if (cont_offset != 0) { | |
2982 st->move_to(column); | |
2983 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, code_begin() + cont_offset); | |
2984 } | |
2985 | |
2986 } | |
2987 | |
2988 #ifndef PRODUCT | |
2989 | |
2990 void nmethod::print_value_on(outputStream* st) const { | |
2991 st->print("nmethod"); | |
2992 print_on(st, NULL); | |
2993 } | |
2994 | |
2995 void nmethod::print_calls(outputStream* st) { | |
2996 RelocIterator iter(this); | |
2997 while (iter.next()) { | |
2998 switch (iter.type()) { | |
2999 case relocInfo::virtual_call_type: | |
3000 case relocInfo::opt_virtual_call_type: { | |
3001 VerifyMutexLocker mc(CompiledIC_lock); | |
3002 CompiledIC_at(iter.reloc())->print(); | |
3003 break; | |
3004 } | |
3005 case relocInfo::static_call_type: | |
3006 st->print_cr("Static call at " INTPTR_FORMAT, iter.reloc()->addr()); | |
3007 compiledStaticCall_at(iter.reloc())->print(); | |
3008 break; | |
3009 } | |
3010 } | |
3011 } | |
3012 | |
3013 void nmethod::print_handler_table() { | |
3014 ExceptionHandlerTable(this).print(); | |
3015 } | |
3016 | |
3017 void nmethod::print_nul_chk_table() { | |
3018 ImplicitExceptionTable(this).print(code_begin()); | |
3019 } | |
3020 | |
3021 void nmethod::print_statistics() { | |
3022 ttyLocker ttyl; | |
3023 if (xtty != NULL) xtty->head("statistics type='nmethod'"); | |
3024 nmethod_stats.print_native_nmethod_stats(); | |
3025 nmethod_stats.print_nmethod_stats(); | |
3026 DebugInformationRecorder::print_statistics(); | |
3027 nmethod_stats.print_pc_stats(); | |
3028 Dependencies::print_statistics(); | |
3029 if (xtty != NULL) xtty->tail("statistics"); | |
3030 } | |
8152
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
3031 |
2bc6f232f74e
More fixes in the C++ part.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
3032 #endif // PRODUCT |