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