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