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