annotate src/share/vm/code/nmethod.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c7c777385a15
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // This class is used internally by nmethods, to cache
duke@0 26 // exception/pc/handler information.
duke@0 27
duke@0 28 class ExceptionCache : public CHeapObj {
duke@0 29 friend class VMStructs;
duke@0 30 private:
duke@0 31 static address _unwind_handler;
duke@0 32 enum { cache_size = 16 };
duke@0 33 klassOop _exception_type;
duke@0 34 address _pc[cache_size];
duke@0 35 address _handler[cache_size];
duke@0 36 int _count;
duke@0 37 ExceptionCache* _next;
duke@0 38
duke@0 39 address pc_at(int index) { assert(index >= 0 && index < count(),""); return _pc[index]; }
duke@0 40 void set_pc_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _pc[index] = a; }
duke@0 41 address handler_at(int index) { assert(index >= 0 && index < count(),""); return _handler[index]; }
duke@0 42 void set_handler_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _handler[index] = a; }
duke@0 43 int count() { return _count; }
duke@0 44 void increment_count() { _count++; }
duke@0 45
duke@0 46 public:
duke@0 47
duke@0 48 ExceptionCache(Handle exception, address pc, address handler);
duke@0 49
duke@0 50 klassOop exception_type() { return _exception_type; }
duke@0 51 klassOop* exception_type_addr() { return &_exception_type; }
duke@0 52 ExceptionCache* next() { return _next; }
duke@0 53 void set_next(ExceptionCache *ec) { _next = ec; }
duke@0 54
duke@0 55 address match(Handle exception, address pc);
duke@0 56 bool match_exception_with_space(Handle exception) ;
duke@0 57 address test_address(address addr);
duke@0 58 bool add_address_and_handler(address addr, address handler) ;
duke@0 59
duke@0 60 static address unwind_handler() { return _unwind_handler; }
duke@0 61 };
duke@0 62
duke@0 63
duke@0 64 // cache pc descs found in earlier inquiries
duke@0 65 class PcDescCache VALUE_OBJ_CLASS_SPEC {
duke@0 66 friend class VMStructs;
duke@0 67 private:
duke@0 68 enum { cache_size = 4 };
duke@0 69 PcDesc* _last_pc_desc; // most recent pc_desc found
duke@0 70 PcDesc* _pc_descs[cache_size]; // last cache_size pc_descs found
duke@0 71 public:
duke@0 72 PcDescCache() { debug_only(_last_pc_desc = NULL); }
duke@0 73 void reset_to(PcDesc* initial_pc_desc);
duke@0 74 PcDesc* find_pc_desc(int pc_offset, bool approximate);
duke@0 75 void add_pc_desc(PcDesc* pc_desc);
duke@0 76 PcDesc* last_pc_desc() { return _last_pc_desc; }
duke@0 77 };
duke@0 78
duke@0 79
duke@0 80 // nmethods (native methods) are the compiled code versions of Java methods.
duke@0 81
duke@0 82 struct nmFlags {
duke@0 83 friend class VMStructs;
duke@0 84 unsigned int version:8; // version number (0 = first version)
duke@0 85 unsigned int level:4; // optimization level
duke@0 86 unsigned int age:4; // age (in # of sweep steps)
duke@0 87
duke@0 88 unsigned int state:2; // {alive, zombie, unloaded)
duke@0 89
duke@0 90 unsigned int isUncommonRecompiled:1; // recompiled because of uncommon trap?
duke@0 91 unsigned int isToBeRecompiled:1; // to be recompiled as soon as it matures
duke@0 92 unsigned int hasFlushedDependencies:1; // Used for maintenance of dependencies
duke@0 93 unsigned int markedForReclamation:1; // Used by NMethodSweeper
duke@0 94
duke@0 95 unsigned int has_unsafe_access:1; // May fault due to unsafe access.
duke@0 96
duke@0 97 void clear();
duke@0 98 };
duke@0 99
duke@0 100
duke@0 101 // A nmethod contains:
duke@0 102 // - header (the nmethod structure)
duke@0 103 // [Relocation]
duke@0 104 // - relocation information
duke@0 105 // - constant part (doubles, longs and floats used in nmethod)
duke@0 106 // [Code]
duke@0 107 // - code body
duke@0 108 // - exception handler
duke@0 109 // - stub code
duke@0 110 // [Debugging information]
duke@0 111 // - oop array
duke@0 112 // - data array
duke@0 113 // - pcs
duke@0 114 // [Exception handler table]
duke@0 115 // - handler entry point array
duke@0 116 // [Implicit Null Pointer exception table]
duke@0 117 // - implicit null table array
duke@0 118
duke@0 119 class Dependencies;
duke@0 120 class ExceptionHandlerTable;
duke@0 121 class ImplicitExceptionTable;
duke@0 122 class AbstractCompiler;
duke@0 123 class xmlStream;
duke@0 124
duke@0 125 class nmethod : public CodeBlob {
duke@0 126 friend class VMStructs;
duke@0 127 friend class NMethodSweeper;
duke@0 128 private:
duke@0 129 // Shared fields for all nmethod's
duke@0 130 static int _zombie_instruction_size;
duke@0 131
duke@0 132 methodOop _method;
duke@0 133 int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
duke@0 134
duke@0 135 nmethod* _link; // To support simple linked-list chaining of nmethods
duke@0 136
duke@0 137 AbstractCompiler* _compiler; // The compiler which compiled this nmethod
duke@0 138
duke@0 139 // Offsets for different nmethod parts
duke@0 140 int _exception_offset;
duke@0 141 // All deoptee's will resume execution at this location described by this offset
duke@0 142 int _deoptimize_offset;
duke@0 143 int _stub_offset;
duke@0 144 int _consts_offset;
duke@0 145 int _scopes_data_offset;
duke@0 146 int _scopes_pcs_offset;
duke@0 147 int _dependencies_offset;
duke@0 148 int _handler_table_offset;
duke@0 149 int _nul_chk_table_offset;
duke@0 150 int _nmethod_end_offset;
duke@0 151
duke@0 152 // location in frame (offset for sp) that deopt can store the original
duke@0 153 // pc during a deopt.
duke@0 154 int _orig_pc_offset;
duke@0 155
duke@0 156 int _compile_id; // which compilation made this nmethod
duke@0 157 int _comp_level; // compilation level
duke@0 158
duke@0 159 // offsets for entry points
duke@0 160 address _entry_point; // entry point with class check
duke@0 161 address _verified_entry_point; // entry point without class check
duke@0 162 address _osr_entry_point; // entry point for on stack replacement
duke@0 163
duke@0 164 nmFlags flags; // various flags to keep track of nmethod state
duke@0 165 bool _markedForDeoptimization; // Used for stack deoptimization
duke@0 166 enum { alive = 0,
duke@0 167 not_entrant = 1, // uncommon trap has happend but activations may still exist
duke@0 168 zombie = 2,
duke@0 169 unloaded = 3 };
duke@0 170
duke@0 171 // used by jvmti to track if an unload event has been posted for this nmethod.
duke@0 172 bool _unload_reported;
duke@0 173
duke@0 174 NOT_PRODUCT(bool _has_debug_info; )
duke@0 175
duke@0 176 // Nmethod Flushing lock (if non-zero, then the nmethod is not removed)
duke@0 177 jint _lock_count;
duke@0 178
duke@0 179 // not_entrant method removal. Each mark_sweep pass will update
duke@0 180 // this mark to current sweep invocation count if it is seen on the
duke@0 181 // stack. An not_entrant method can be removed when there is no
duke@0 182 // more activations, i.e., when the _stack_traversal_mark is less than
duke@0 183 // current sweep traversal index.
duke@0 184 long _stack_traversal_mark;
duke@0 185
duke@0 186 ExceptionCache *_exception_cache;
duke@0 187 PcDescCache _pc_desc_cache;
duke@0 188
duke@0 189 // These are only used for compiled synchronized native methods to
duke@0 190 // locate the owner and stack slot for the BasicLock so that we can
duke@0 191 // properly revoke the bias of the owner if necessary. They are
duke@0 192 // needed because there is no debug information for compiled native
duke@0 193 // wrappers and the oop maps are insufficient to allow
duke@0 194 // frame::retrieve_receiver() to work. Currently they are expected
duke@0 195 // to be byte offsets from the Java stack pointer for maximum code
duke@0 196 // sharing between platforms. Note that currently biased locking
duke@0 197 // will never cause Class instances to be biased but this code
duke@0 198 // handles the static synchronized case as well.
duke@0 199 ByteSize _compiled_synchronized_native_basic_lock_owner_sp_offset;
duke@0 200 ByteSize _compiled_synchronized_native_basic_lock_sp_offset;
duke@0 201
duke@0 202 friend class nmethodLocker;
duke@0 203
duke@0 204 // For native wrappers
duke@0 205 nmethod(methodOop method,
duke@0 206 int nmethod_size,
duke@0 207 CodeOffsets* offsets,
duke@0 208 CodeBuffer *code_buffer,
duke@0 209 int frame_size,
duke@0 210 ByteSize basic_lock_owner_sp_offset, /* synchronized natives only */
duke@0 211 ByteSize basic_lock_sp_offset, /* synchronized natives only */
duke@0 212 OopMapSet* oop_maps);
duke@0 213
duke@0 214 // Creation support
duke@0 215 nmethod(methodOop method,
duke@0 216 int nmethod_size,
duke@0 217 int compile_id,
duke@0 218 int entry_bci,
duke@0 219 CodeOffsets* offsets,
duke@0 220 int orig_pc_offset,
duke@0 221 DebugInformationRecorder *recorder,
duke@0 222 Dependencies* dependencies,
duke@0 223 CodeBuffer *code_buffer,
duke@0 224 int frame_size,
duke@0 225 OopMapSet* oop_maps,
duke@0 226 ExceptionHandlerTable* handler_table,
duke@0 227 ImplicitExceptionTable* nul_chk_table,
duke@0 228 AbstractCompiler* compiler,
duke@0 229 int comp_level);
duke@0 230
duke@0 231 // helper methods
duke@0 232 void* operator new(size_t size, int nmethod_size);
duke@0 233 void check_store();
duke@0 234
duke@0 235 const char* reloc_string_for(u_char* begin, u_char* end);
duke@0 236 void make_not_entrant_or_zombie(int state);
duke@0 237 void inc_decompile_count();
duke@0 238
duke@0 239 // used to check that writes to nmFlags are done consistently.
duke@0 240 static void check_safepoint() PRODUCT_RETURN;
duke@0 241
duke@0 242 // Used to manipulate the exception cache
duke@0 243 void add_exception_cache_entry(ExceptionCache* new_entry);
duke@0 244 ExceptionCache* exception_cache_entry_for_exception(Handle exception);
duke@0 245
duke@0 246 // Inform external interfaces that a compiled method has been unloaded
duke@0 247 inline void post_compiled_method_unload();
duke@0 248
duke@0 249 public:
duke@0 250 // create nmethod with entry_bci
duke@0 251 static nmethod* new_nmethod(methodHandle method,
duke@0 252 int compile_id,
duke@0 253 int entry_bci,
duke@0 254 CodeOffsets* offsets,
duke@0 255 int orig_pc_offset,
duke@0 256 DebugInformationRecorder* recorder,
duke@0 257 Dependencies* dependencies,
duke@0 258 CodeBuffer *code_buffer,
duke@0 259 int frame_size,
duke@0 260 OopMapSet* oop_maps,
duke@0 261 ExceptionHandlerTable* handler_table,
duke@0 262 ImplicitExceptionTable* nul_chk_table,
duke@0 263 AbstractCompiler* compiler,
duke@0 264 int comp_level);
duke@0 265
duke@0 266 static nmethod* new_native_nmethod(methodHandle method,
duke@0 267 CodeBuffer *code_buffer,
duke@0 268 int vep_offset,
duke@0 269 int frame_complete,
duke@0 270 int frame_size,
duke@0 271 ByteSize receiver_sp_offset,
duke@0 272 ByteSize basic_lock_sp_offset,
duke@0 273 OopMapSet* oop_maps);
duke@0 274
duke@0 275 // accessors
duke@0 276 methodOop method() const { return _method; }
duke@0 277 AbstractCompiler* compiler() const { return _compiler; }
duke@0 278
duke@0 279 #ifndef PRODUCT
duke@0 280 bool has_debug_info() const { return _has_debug_info; }
duke@0 281 void set_has_debug_info(bool f) { _has_debug_info = false; }
duke@0 282 #endif // NOT PRODUCT
duke@0 283
duke@0 284 // type info
duke@0 285 bool is_nmethod() const { return true; }
duke@0 286 bool is_java_method() const { return !method()->is_native(); }
duke@0 287 bool is_native_method() const { return method()->is_native(); }
duke@0 288 bool is_osr_method() const { return _entry_bci != InvocationEntryBci; }
duke@0 289 bool is_osr_only_method() const { return is_osr_method(); }
duke@0 290
duke@0 291 bool is_compiled_by_c1() const;
duke@0 292 bool is_compiled_by_c2() const;
duke@0 293
duke@0 294 // boundaries for different parts
duke@0 295 address code_begin () const { return _entry_point; }
duke@0 296 address code_end () const { return header_begin() + _stub_offset ; }
duke@0 297 address exception_begin () const { return header_begin() + _exception_offset ; }
duke@0 298 address deopt_handler_begin() const { return header_begin() + _deoptimize_offset ; }
duke@0 299 address stub_begin () const { return header_begin() + _stub_offset ; }
duke@0 300 address stub_end () const { return header_begin() + _consts_offset ; }
duke@0 301 address consts_begin () const { return header_begin() + _consts_offset ; }
duke@0 302 address consts_end () const { return header_begin() + _scopes_data_offset ; }
duke@0 303 address scopes_data_begin () const { return header_begin() + _scopes_data_offset ; }
duke@0 304 address scopes_data_end () const { return header_begin() + _scopes_pcs_offset ; }
duke@0 305 PcDesc* scopes_pcs_begin () const { return (PcDesc*)(header_begin() + _scopes_pcs_offset ); }
duke@0 306 PcDesc* scopes_pcs_end () const { return (PcDesc*)(header_begin() + _dependencies_offset); }
duke@0 307 address dependencies_begin () const { return header_begin() + _dependencies_offset ; }
duke@0 308 address dependencies_end () const { return header_begin() + _handler_table_offset ; }
duke@0 309 address handler_table_begin() const { return header_begin() + _handler_table_offset ; }
duke@0 310 address handler_table_end () const { return header_begin() + _nul_chk_table_offset ; }
duke@0 311 address nul_chk_table_begin() const { return header_begin() + _nul_chk_table_offset ; }
duke@0 312 address nul_chk_table_end () const { return header_begin() + _nmethod_end_offset ; }
duke@0 313
duke@0 314 int code_size () const { return code_end () - code_begin (); }
duke@0 315 int stub_size () const { return stub_end () - stub_begin (); }
duke@0 316 int consts_size () const { return consts_end () - consts_begin (); }
duke@0 317 int scopes_data_size () const { return scopes_data_end () - scopes_data_begin (); }
duke@0 318 int scopes_pcs_size () const { return (intptr_t)scopes_pcs_end () - (intptr_t)scopes_pcs_begin (); }
duke@0 319 int dependencies_size () const { return dependencies_end () - dependencies_begin (); }
duke@0 320 int handler_table_size() const { return handler_table_end() - handler_table_begin(); }
duke@0 321 int nul_chk_table_size() const { return nul_chk_table_end() - nul_chk_table_begin(); }
duke@0 322
duke@0 323 int total_size () const;
duke@0 324
duke@0 325 bool code_contains (address addr) const { return code_begin () <= addr && addr < code_end (); }
duke@0 326 bool stub_contains (address addr) const { return stub_begin () <= addr && addr < stub_end (); }
duke@0 327 bool consts_contains (address addr) const { return consts_begin () <= addr && addr < consts_end (); }
duke@0 328 bool scopes_data_contains (address addr) const { return scopes_data_begin () <= addr && addr < scopes_data_end (); }
duke@0 329 bool scopes_pcs_contains (PcDesc* addr) const { return scopes_pcs_begin () <= addr && addr < scopes_pcs_end (); }
duke@0 330 bool handler_table_contains(address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); }
duke@0 331 bool nul_chk_table_contains(address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
duke@0 332
duke@0 333 // entry points
duke@0 334 address entry_point() const { return _entry_point; } // normal entry point
duke@0 335 address verified_entry_point() const { return _verified_entry_point; } // if klass is correct
duke@0 336
duke@0 337 // flag accessing and manipulation
duke@0 338 bool is_in_use() const { return flags.state == alive; }
duke@0 339 bool is_alive() const { return flags.state == alive || flags.state == not_entrant; }
duke@0 340 bool is_not_entrant() const { return flags.state == not_entrant; }
duke@0 341 bool is_zombie() const { return flags.state == zombie; }
duke@0 342 bool is_unloaded() const { return flags.state == unloaded; }
duke@0 343
duke@0 344 // Make the nmethod non entrant. The nmethod will continue to be alive.
duke@0 345 // It is used when an uncommon trap happens.
duke@0 346 void make_not_entrant() { make_not_entrant_or_zombie(not_entrant); }
duke@0 347 void make_zombie() { make_not_entrant_or_zombie(zombie); }
duke@0 348
duke@0 349 // used by jvmti to track if the unload event has been reported
duke@0 350 bool unload_reported() { return _unload_reported; }
duke@0 351 void set_unload_reported() { _unload_reported = true; }
duke@0 352
duke@0 353 bool is_marked_for_deoptimization() const { return _markedForDeoptimization; }
duke@0 354 void mark_for_deoptimization() { _markedForDeoptimization = true; }
duke@0 355
duke@0 356 void make_unloaded(BoolObjectClosure* is_alive, oop cause);
duke@0 357
duke@0 358 bool has_dependencies() { return dependencies_size() != 0; }
duke@0 359 void flush_dependencies(BoolObjectClosure* is_alive);
duke@0 360 bool has_flushed_dependencies() { return flags.hasFlushedDependencies; }
duke@0 361 void set_has_flushed_dependencies() {
duke@0 362 check_safepoint();
duke@0 363 assert(!has_flushed_dependencies(), "should only happen once");
duke@0 364 flags.hasFlushedDependencies = 1;
duke@0 365 }
duke@0 366
duke@0 367 bool is_marked_for_reclamation() const { return flags.markedForReclamation; }
duke@0 368 void mark_for_reclamation() { check_safepoint(); flags.markedForReclamation = 1; }
duke@0 369 void unmark_for_reclamation() { check_safepoint(); flags.markedForReclamation = 0; }
duke@0 370
duke@0 371 bool has_unsafe_access() const { return flags.has_unsafe_access; }
duke@0 372 void set_has_unsafe_access(bool z) { flags.has_unsafe_access = z; }
duke@0 373
duke@0 374 int level() const { return flags.level; }
duke@0 375 void set_level(int newLevel) { check_safepoint(); flags.level = newLevel; }
duke@0 376
duke@0 377 int comp_level() const { return _comp_level; }
duke@0 378
duke@0 379 int version() const { return flags.version; }
duke@0 380 void set_version(int v);
duke@0 381
duke@0 382 // Sweeper support
duke@0 383 long stack_traversal_mark() { return _stack_traversal_mark; }
duke@0 384 void set_stack_traversal_mark(long l) { _stack_traversal_mark = l; }
duke@0 385
duke@0 386 // Exception cache support
duke@0 387 ExceptionCache* exception_cache() const { return _exception_cache; }
duke@0 388 void set_exception_cache(ExceptionCache *ec) { _exception_cache = ec; }
duke@0 389 address handler_for_exception_and_pc(Handle exception, address pc);
duke@0 390 void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
duke@0 391 void remove_from_exception_cache(ExceptionCache* ec);
duke@0 392
duke@0 393 // implicit exceptions support
duke@0 394 address continuation_for_implicit_exception(address pc);
duke@0 395
duke@0 396 // On-stack replacement support
duke@0 397 int osr_entry_bci() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _entry_bci; }
duke@0 398 address osr_entry() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _osr_entry_point; }
duke@0 399 void invalidate_osr_method();
duke@0 400 nmethod* link() const { return _link; }
duke@0 401 void set_link(nmethod *n) { _link = n; }
duke@0 402
duke@0 403 // tells whether frames described by this nmethod can be deoptimized
duke@0 404 // note: native wrappers cannot be deoptimized.
duke@0 405 bool can_be_deoptimized() const { return is_java_method(); }
duke@0 406
duke@0 407 // Inline cache support
duke@0 408 void clear_inline_caches();
duke@0 409 void cleanup_inline_caches();
duke@0 410 bool inlinecache_check_contains(address addr) const {
duke@0 411 return (addr >= instructions_begin() && addr < verified_entry_point());
duke@0 412 }
duke@0 413
duke@0 414 // unlink and deallocate this nmethod
duke@0 415 // Only NMethodSweeper class is expected to use this. NMethodSweeper is not
duke@0 416 // expected to use any other private methods/data in this class.
duke@0 417
duke@0 418 protected:
duke@0 419 void flush();
duke@0 420
duke@0 421 public:
duke@0 422 // If returning true, it is unsafe to remove this nmethod even though it is a zombie
duke@0 423 // nmethod, since the VM might have a reference to it. Should only be called from a safepoint.
duke@0 424 bool is_locked_by_vm() const { return _lock_count >0; }
duke@0 425
duke@0 426 // See comment at definition of _last_seen_on_stack
duke@0 427 void mark_as_seen_on_stack();
duke@0 428 bool can_not_entrant_be_converted();
duke@0 429
duke@0 430 // Evolution support. We make old (discarded) compiled methods point to new methodOops.
duke@0 431 void set_method(methodOop method) { _method = method; }
duke@0 432
duke@0 433 // GC support
duke@0 434 void do_unloading(BoolObjectClosure* is_alive, OopClosure* keep_alive,
duke@0 435 bool unloading_occurred);
duke@0 436 bool can_unload(BoolObjectClosure* is_alive, OopClosure* keep_alive,
duke@0 437 oop* root, bool unloading_occurred);
duke@0 438
duke@0 439 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map,
duke@0 440 OopClosure* f);
duke@0 441 void oops_do(OopClosure* f);
duke@0 442
duke@0 443 // ScopeDesc for an instruction
duke@0 444 ScopeDesc* scope_desc_at(address pc);
duke@0 445
duke@0 446 private:
duke@0 447 ScopeDesc* scope_desc_in(address begin, address end);
duke@0 448
duke@0 449 address* orig_pc_addr(const frame* fr ) { return (address*) ((address)fr->unextended_sp() + _orig_pc_offset); }
duke@0 450
duke@0 451 PcDesc* find_pc_desc_internal(address pc, bool approximate);
duke@0 452
duke@0 453 PcDesc* find_pc_desc(address pc, bool approximate) {
duke@0 454 PcDesc* desc = _pc_desc_cache.last_pc_desc();
duke@0 455 if (desc != NULL && desc->pc_offset() == pc - instructions_begin()) {
duke@0 456 return desc;
duke@0 457 }
duke@0 458 return find_pc_desc_internal(pc, approximate);
duke@0 459 }
duke@0 460
duke@0 461 public:
duke@0 462 // ScopeDesc retrieval operation
duke@0 463 PcDesc* pc_desc_at(address pc) { return find_pc_desc(pc, false); }
duke@0 464 // pc_desc_near returns the first PcDesc at or after the givne pc.
duke@0 465 PcDesc* pc_desc_near(address pc) { return find_pc_desc(pc, true); }
duke@0 466
duke@0 467 public:
duke@0 468 // copying of debugging information
duke@0 469 void copy_scopes_pcs(PcDesc* pcs, int count);
duke@0 470 void copy_scopes_data(address buffer, int size);
duke@0 471
duke@0 472 // deopt
duke@0 473 // return true is the pc is one would expect if the frame is being deopted.
duke@0 474 bool is_deopt_pc(address pc);
duke@0 475 // Accessor/mutator for the original pc of a frame before a frame was deopted.
duke@0 476 address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }
duke@0 477 void set_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }
duke@0 478
duke@0 479 // jvmti support:
duke@0 480 void post_compiled_method_load_event();
duke@0 481
duke@0 482 // verify operations
duke@0 483 void verify();
duke@0 484 void verify_scopes();
duke@0 485 void verify_interrupt_point(address interrupt_point);
duke@0 486
duke@0 487 // printing support
duke@0 488 void print() const PRODUCT_RETURN;
duke@0 489 void print_code() PRODUCT_RETURN;
duke@0 490 void print_relocations() PRODUCT_RETURN;
duke@0 491 void print_pcs() PRODUCT_RETURN;
duke@0 492 void print_scopes() PRODUCT_RETURN;
duke@0 493 void print_dependencies() PRODUCT_RETURN;
duke@0 494 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@0 495 void print_calls(outputStream* st) PRODUCT_RETURN;
duke@0 496 void print_handler_table() PRODUCT_RETURN;
duke@0 497 void print_nul_chk_table() PRODUCT_RETURN;
duke@0 498 void print_nmethod(bool print_code) PRODUCT_RETURN;
duke@0 499
duke@0 500 void print_on(outputStream* st, const char* title) const;
duke@0 501
duke@0 502 // Logging
duke@0 503 void log_identity(xmlStream* log) const;
duke@0 504 void log_new_nmethod() const;
duke@0 505 void log_state_change(int state) const;
duke@0 506
duke@0 507 // Prints a comment for one native instruction (reloc info, pc desc)
duke@0 508 void print_code_comment_on(outputStream* st, int column, address begin, address end) PRODUCT_RETURN;
duke@0 509 static void print_statistics() PRODUCT_RETURN;
duke@0 510
duke@0 511 // Compiler task identification. Note that all OSR methods
duke@0 512 // are numbered in an independent sequence if CICountOSR is true,
duke@0 513 // and native method wrappers are also numbered independently if
duke@0 514 // CICountNative is true.
duke@0 515 int compile_id() const { return _compile_id; }
duke@0 516 const char* compile_kind() const;
duke@0 517
duke@0 518 // For debugging
duke@0 519 // CompiledIC* IC_at(char* p) const;
duke@0 520 // PrimitiveIC* primitiveIC_at(char* p) const;
duke@0 521 oop embeddedOop_at(address p);
duke@0 522
duke@0 523 // tells if any of this method's dependencies have been invalidated
duke@0 524 // (this is expensive!)
duke@0 525 bool check_all_dependencies();
duke@0 526
duke@0 527 // tells if this compiled method is dependent on the given changes,
duke@0 528 // and the changes have invalidated it
duke@0 529 bool check_dependency_on(DepChange& changes);
duke@0 530
duke@0 531 // Evolution support. Tells if this compiled method is dependent on any of
duke@0 532 // methods m() of class dependee, such that if m() in dependee is replaced,
duke@0 533 // this compiled method will have to be deoptimized.
duke@0 534 bool is_evol_dependent_on(klassOop dependee);
duke@0 535
duke@0 536 // Fast breakpoint support. Tells if this compiled method is
duke@0 537 // dependent on the given method. Returns true if this nmethod
duke@0 538 // corresponds to the given method as well.
duke@0 539 bool is_dependent_on_method(methodOop dependee);
duke@0 540
duke@0 541 // is it ok to patch at address?
duke@0 542 bool is_patchable_at(address instr_address);
duke@0 543
duke@0 544 // UseBiasedLocking support
duke@0 545 ByteSize compiled_synchronized_native_basic_lock_owner_sp_offset() {
duke@0 546 return _compiled_synchronized_native_basic_lock_owner_sp_offset;
duke@0 547 }
duke@0 548 ByteSize compiled_synchronized_native_basic_lock_sp_offset() {
duke@0 549 return _compiled_synchronized_native_basic_lock_sp_offset;
duke@0 550 }
duke@0 551
duke@0 552 // support for code generation
duke@0 553 static int verified_entry_point_offset() { return offset_of(nmethod, _verified_entry_point); }
duke@0 554 static int osr_entry_point_offset() { return offset_of(nmethod, _osr_entry_point); }
duke@0 555 static int entry_bci_offset() { return offset_of(nmethod, _entry_bci); }
duke@0 556
duke@0 557 };
duke@0 558
duke@0 559 // Locks an nmethod so its code will not get removed, even if it is a zombie/not_entrant method
duke@0 560 class nmethodLocker : public StackObj {
duke@0 561 nmethod* _nm;
duke@0 562
duke@0 563 static void lock_nmethod(nmethod* nm); // note: nm can be NULL
duke@0 564 static void unlock_nmethod(nmethod* nm); // (ditto)
duke@0 565
duke@0 566 public:
duke@0 567 nmethodLocker(address pc); // derive nm from pc
duke@0 568 nmethodLocker(nmethod *nm) { _nm = nm; lock_nmethod(_nm); }
duke@0 569 nmethodLocker() { _nm = NULL; }
duke@0 570 ~nmethodLocker() { unlock_nmethod(_nm); }
duke@0 571
duke@0 572 nmethod* code() { return _nm; }
duke@0 573 void set_code(nmethod* new_nm) {
duke@0 574 unlock_nmethod(_nm); // note: This works even if _nm==new_nm.
duke@0 575 _nm = new_nm;
duke@0 576 lock_nmethod(_nm);
duke@0 577 }
duke@0 578 };