src/share/vm/code/nmethod.hpp

Fri, 29 Jan 2010 08:33:24 -0800

author
twisti
date
Fri, 29 Jan 2010 08:33:24 -0800
changeset 1636
24128c2ffa87
parent 1635
ba263cfb7611
child 1637
5f24d0319e54
permissions
-rw-r--r--

6921339: backout 6917766
Reviewed-by: mr

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

mercurial