src/share/vm/code/nmethod.hpp

Tue, 15 Mar 2011 06:50:01 -0700

author
dcubed
date
Tue, 15 Mar 2011 06:50:01 -0700
changeset 2625
65f880e2869b
parent 2621
3d5a546351ef
parent 2624
46a56fac55c7
child 2657
d673ef06fe96
permissions
-rw-r--r--

Merge

duke@435 1 /*
kamg@2511 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CODE_NMETHOD_HPP
stefank@2314 26 #define SHARE_VM_CODE_NMETHOD_HPP
stefank@2314 27
stefank@2314 28 #include "code/codeBlob.hpp"
stefank@2314 29 #include "code/pcDesc.hpp"
stefank@2314 30
duke@435 31 // This class is used internally by nmethods, to cache
duke@435 32 // exception/pc/handler information.
duke@435 33
duke@435 34 class ExceptionCache : public CHeapObj {
duke@435 35 friend class VMStructs;
duke@435 36 private:
duke@435 37 enum { cache_size = 16 };
duke@435 38 klassOop _exception_type;
duke@435 39 address _pc[cache_size];
duke@435 40 address _handler[cache_size];
duke@435 41 int _count;
duke@435 42 ExceptionCache* _next;
duke@435 43
duke@435 44 address pc_at(int index) { assert(index >= 0 && index < count(),""); return _pc[index]; }
duke@435 45 void set_pc_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _pc[index] = a; }
duke@435 46 address handler_at(int index) { assert(index >= 0 && index < count(),""); return _handler[index]; }
duke@435 47 void set_handler_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _handler[index] = a; }
duke@435 48 int count() { return _count; }
duke@435 49 void increment_count() { _count++; }
duke@435 50
duke@435 51 public:
duke@435 52
duke@435 53 ExceptionCache(Handle exception, address pc, address handler);
duke@435 54
duke@435 55 klassOop exception_type() { return _exception_type; }
duke@435 56 klassOop* exception_type_addr() { return &_exception_type; }
duke@435 57 ExceptionCache* next() { return _next; }
duke@435 58 void set_next(ExceptionCache *ec) { _next = ec; }
duke@435 59
duke@435 60 address match(Handle exception, address pc);
duke@435 61 bool match_exception_with_space(Handle exception) ;
duke@435 62 address test_address(address addr);
duke@435 63 bool add_address_and_handler(address addr, address handler) ;
duke@435 64 };
duke@435 65
duke@435 66
duke@435 67 // cache pc descs found in earlier inquiries
duke@435 68 class PcDescCache VALUE_OBJ_CLASS_SPEC {
duke@435 69 friend class VMStructs;
duke@435 70 private:
duke@435 71 enum { cache_size = 4 };
duke@435 72 PcDesc* _pc_descs[cache_size]; // last cache_size pc_descs found
duke@435 73 public:
phh@2621 74 PcDescCache() { debug_only(_pc_descs[0] = NULL); }
duke@435 75 void reset_to(PcDesc* initial_pc_desc);
duke@435 76 PcDesc* find_pc_desc(int pc_offset, bool approximate);
duke@435 77 void add_pc_desc(PcDesc* pc_desc);
phh@2621 78 PcDesc* last_pc_desc() { return _pc_descs[0]; }
duke@435 79 };
duke@435 80
duke@435 81
duke@435 82 // nmethods (native methods) are the compiled code versions of Java methods.
never@1999 83 //
never@1999 84 // An nmethod contains:
duke@435 85 // - header (the nmethod structure)
duke@435 86 // [Relocation]
duke@435 87 // - relocation information
duke@435 88 // - constant part (doubles, longs and floats used in nmethod)
twisti@1918 89 // - oop table
duke@435 90 // [Code]
duke@435 91 // - code body
duke@435 92 // - exception handler
duke@435 93 // - stub code
duke@435 94 // [Debugging information]
duke@435 95 // - oop array
duke@435 96 // - data array
duke@435 97 // - pcs
duke@435 98 // [Exception handler table]
duke@435 99 // - handler entry point array
duke@435 100 // [Implicit Null Pointer exception table]
duke@435 101 // - implicit null table array
duke@435 102
duke@435 103 class Dependencies;
duke@435 104 class ExceptionHandlerTable;
duke@435 105 class ImplicitExceptionTable;
duke@435 106 class AbstractCompiler;
duke@435 107 class xmlStream;
duke@435 108
duke@435 109 class nmethod : public CodeBlob {
duke@435 110 friend class VMStructs;
duke@435 111 friend class NMethodSweeper;
jrose@1424 112 friend class CodeCache; // non-perm oops
duke@435 113 private:
duke@435 114 // Shared fields for all nmethod's
duke@435 115 methodOop _method;
duke@435 116 int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
never@1971 117 jmethodID _jmethod_id; // Cache of method()->jmethod_id()
duke@435 118
jrose@1424 119 // To support simple linked-list chaining of nmethods:
jrose@1424 120 nmethod* _osr_link; // from instanceKlass::osr_nmethods_head
jrose@1424 121 nmethod* _scavenge_root_link; // from CodeCache::scavenge_root_nmethods
kvn@1637 122 nmethod* _saved_nmethod_link; // from CodeCache::speculatively_disconnect
jrose@1424 123
jrose@1424 124 static nmethod* volatile _oops_do_mark_nmethods;
jrose@1424 125 nmethod* volatile _oops_do_mark_link;
duke@435 126
duke@435 127 AbstractCompiler* _compiler; // The compiler which compiled this nmethod
duke@435 128
never@1999 129 // offsets for entry points
never@1999 130 address _entry_point; // entry point with class check
never@1999 131 address _verified_entry_point; // entry point without class check
never@1999 132 address _osr_entry_point; // entry point for on stack replacement
never@1999 133
duke@435 134 // Offsets for different nmethod parts
duke@435 135 int _exception_offset;
twisti@1639 136 // All deoptee's will resume execution at this location described by
twisti@1639 137 // this offset.
duke@435 138 int _deoptimize_offset;
twisti@1639 139 // All deoptee's at a MethodHandle call site will resume execution
twisti@1639 140 // at this location described by this offset.
twisti@1639 141 int _deoptimize_mh_offset;
never@1813 142 // Offset of the unwind handler if it exists
never@1813 143 int _unwind_handler_offset;
never@1813 144
kamg@551 145 #ifdef HAVE_DTRACE_H
kamg@551 146 int _trap_offset;
kamg@551 147 #endif // def HAVE_DTRACE_H
twisti@2117 148 int _consts_offset;
duke@435 149 int _stub_offset;
twisti@1918 150 int _oops_offset; // offset to where embedded oop table begins (inside data)
duke@435 151 int _scopes_data_offset;
duke@435 152 int _scopes_pcs_offset;
duke@435 153 int _dependencies_offset;
duke@435 154 int _handler_table_offset;
duke@435 155 int _nul_chk_table_offset;
duke@435 156 int _nmethod_end_offset;
duke@435 157
duke@435 158 // location in frame (offset for sp) that deopt can store the original
duke@435 159 // pc during a deopt.
duke@435 160 int _orig_pc_offset;
duke@435 161
never@1999 162 int _compile_id; // which compilation made this nmethod
never@1999 163 int _comp_level; // compilation level
duke@435 164
never@1999 165 // protected by CodeCache_lock
never@1999 166 bool _has_flushed_dependencies; // Used for maintenance of dependencies (CodeCache_lock)
never@1999 167 bool _speculatively_disconnected; // Marked for potential unload
duke@435 168
never@1999 169 bool _marked_for_reclamation; // Used by NMethodSweeper (set only by sweeper)
never@1999 170 bool _marked_for_deoptimization; // Used for stack deoptimization
never@1999 171
never@1999 172 // used by jvmti to track if an unload event has been posted for this nmethod.
never@1999 173 bool _unload_reported;
never@1999 174
never@1999 175 // set during construction
never@1999 176 unsigned int _has_unsafe_access:1; // May fault due to unsafe access.
never@1999 177 unsigned int _has_method_handle_invokes:1; // Has this method MethodHandle invokes?
never@1999 178
never@1999 179 // Protected by Patching_lock
phh@2621 180 unsigned char _state; // {alive, not_entrant, zombie, unloaded}
never@1999 181
never@2081 182 #ifdef ASSERT
never@2081 183 bool _oops_are_stale; // indicates that it's no longer safe to access oops section
never@2081 184 #endif
never@2081 185
duke@435 186 enum { alive = 0,
twisti@1040 187 not_entrant = 1, // uncommon trap has happened but activations may still exist
duke@435 188 zombie = 2,
duke@435 189 unloaded = 3 };
duke@435 190
duke@435 191
jrose@1424 192 jbyte _scavenge_root_state;
jrose@1424 193
duke@435 194 NOT_PRODUCT(bool _has_debug_info; )
duke@435 195
dcubed@2624 196 // Nmethod Flushing lock. If non-zero, then the nmethod is not removed
dcubed@2624 197 // and is not made into a zombie. However, once the nmethod is made into
dcubed@2624 198 // a zombie, it will be locked one final time if CompiledMethodUnload
dcubed@2624 199 // event processing needs to be done.
duke@435 200 jint _lock_count;
duke@435 201
duke@435 202 // not_entrant method removal. Each mark_sweep pass will update
duke@435 203 // this mark to current sweep invocation count if it is seen on the
duke@435 204 // stack. An not_entrant method can be removed when there is no
duke@435 205 // more activations, i.e., when the _stack_traversal_mark is less than
duke@435 206 // current sweep traversal index.
duke@435 207 long _stack_traversal_mark;
duke@435 208
duke@435 209 ExceptionCache *_exception_cache;
duke@435 210 PcDescCache _pc_desc_cache;
duke@435 211
kamg@2361 212 // These are used for compiled synchronized native methods to
duke@435 213 // locate the owner and stack slot for the BasicLock so that we can
duke@435 214 // properly revoke the bias of the owner if necessary. They are
duke@435 215 // needed because there is no debug information for compiled native
duke@435 216 // wrappers and the oop maps are insufficient to allow
duke@435 217 // frame::retrieve_receiver() to work. Currently they are expected
duke@435 218 // to be byte offsets from the Java stack pointer for maximum code
duke@435 219 // sharing between platforms. Note that currently biased locking
duke@435 220 // will never cause Class instances to be biased but this code
duke@435 221 // handles the static synchronized case as well.
kamg@2361 222 // JVMTI's GetLocalInstance() also uses these offsets to find the receiver
kamg@2361 223 // for non-static native wrapper frames.
kamg@2361 224 ByteSize _native_receiver_sp_offset;
kamg@2361 225 ByteSize _native_basic_lock_sp_offset;
duke@435 226
duke@435 227 friend class nmethodLocker;
duke@435 228
duke@435 229 // For native wrappers
duke@435 230 nmethod(methodOop method,
duke@435 231 int nmethod_size,
duke@435 232 CodeOffsets* offsets,
duke@435 233 CodeBuffer *code_buffer,
duke@435 234 int frame_size,
duke@435 235 ByteSize basic_lock_owner_sp_offset, /* synchronized natives only */
duke@435 236 ByteSize basic_lock_sp_offset, /* synchronized natives only */
duke@435 237 OopMapSet* oop_maps);
duke@435 238
kamg@551 239 #ifdef HAVE_DTRACE_H
kamg@551 240 // For native wrappers
kamg@551 241 nmethod(methodOop method,
kamg@551 242 int nmethod_size,
kamg@551 243 CodeOffsets* offsets,
kamg@551 244 CodeBuffer *code_buffer,
kamg@551 245 int frame_size);
kamg@551 246 #endif // def HAVE_DTRACE_H
kamg@551 247
duke@435 248 // Creation support
duke@435 249 nmethod(methodOop method,
duke@435 250 int nmethod_size,
duke@435 251 int compile_id,
duke@435 252 int entry_bci,
duke@435 253 CodeOffsets* offsets,
duke@435 254 int orig_pc_offset,
duke@435 255 DebugInformationRecorder *recorder,
duke@435 256 Dependencies* dependencies,
duke@435 257 CodeBuffer *code_buffer,
duke@435 258 int frame_size,
duke@435 259 OopMapSet* oop_maps,
duke@435 260 ExceptionHandlerTable* handler_table,
duke@435 261 ImplicitExceptionTable* nul_chk_table,
duke@435 262 AbstractCompiler* compiler,
duke@435 263 int comp_level);
duke@435 264
duke@435 265 // helper methods
duke@435 266 void* operator new(size_t size, int nmethod_size);
duke@435 267
duke@435 268 const char* reloc_string_for(u_char* begin, u_char* end);
never@1544 269 // Returns true if this thread changed the state of the nmethod or
never@1544 270 // false if another thread performed the transition.
never@1576 271 bool make_not_entrant_or_zombie(unsigned int state);
duke@435 272 void inc_decompile_count();
duke@435 273
duke@435 274 // Used to manipulate the exception cache
duke@435 275 void add_exception_cache_entry(ExceptionCache* new_entry);
duke@435 276 ExceptionCache* exception_cache_entry_for_exception(Handle exception);
duke@435 277
duke@435 278 // Inform external interfaces that a compiled method has been unloaded
never@1999 279 void post_compiled_method_unload();
never@1999 280
never@1999 281 // Initailize fields to their default values
never@1999 282 void init_defaults();
duke@435 283
duke@435 284 public:
duke@435 285 // create nmethod with entry_bci
duke@435 286 static nmethod* new_nmethod(methodHandle method,
duke@435 287 int compile_id,
duke@435 288 int entry_bci,
duke@435 289 CodeOffsets* offsets,
duke@435 290 int orig_pc_offset,
duke@435 291 DebugInformationRecorder* recorder,
duke@435 292 Dependencies* dependencies,
duke@435 293 CodeBuffer *code_buffer,
duke@435 294 int frame_size,
duke@435 295 OopMapSet* oop_maps,
duke@435 296 ExceptionHandlerTable* handler_table,
duke@435 297 ImplicitExceptionTable* nul_chk_table,
duke@435 298 AbstractCompiler* compiler,
duke@435 299 int comp_level);
duke@435 300
duke@435 301 static nmethod* new_native_nmethod(methodHandle method,
duke@435 302 CodeBuffer *code_buffer,
duke@435 303 int vep_offset,
duke@435 304 int frame_complete,
duke@435 305 int frame_size,
duke@435 306 ByteSize receiver_sp_offset,
duke@435 307 ByteSize basic_lock_sp_offset,
duke@435 308 OopMapSet* oop_maps);
duke@435 309
kamg@551 310 #ifdef HAVE_DTRACE_H
kamg@551 311 // The method we generate for a dtrace probe has to look
kamg@551 312 // like an nmethod as far as the rest of the system is concerned
kamg@551 313 // which is somewhat unfortunate.
kamg@551 314 static nmethod* new_dtrace_nmethod(methodHandle method,
kamg@551 315 CodeBuffer *code_buffer,
kamg@551 316 int vep_offset,
kamg@551 317 int trap_offset,
kamg@551 318 int frame_complete,
kamg@551 319 int frame_size);
kamg@551 320
kamg@551 321 int trap_offset() const { return _trap_offset; }
twisti@2103 322 address trap_address() const { return insts_begin() + _trap_offset; }
kamg@551 323
kamg@551 324 #endif // def HAVE_DTRACE_H
kamg@551 325
duke@435 326 // accessors
duke@435 327 methodOop method() const { return _method; }
duke@435 328 AbstractCompiler* compiler() const { return _compiler; }
duke@435 329
duke@435 330 #ifndef PRODUCT
duke@435 331 bool has_debug_info() const { return _has_debug_info; }
duke@435 332 void set_has_debug_info(bool f) { _has_debug_info = false; }
duke@435 333 #endif // NOT PRODUCT
duke@435 334
duke@435 335 // type info
duke@435 336 bool is_nmethod() const { return true; }
duke@435 337 bool is_java_method() const { return !method()->is_native(); }
duke@435 338 bool is_native_method() const { return method()->is_native(); }
duke@435 339 bool is_osr_method() const { return _entry_bci != InvocationEntryBci; }
duke@435 340
duke@435 341 bool is_compiled_by_c1() const;
duke@435 342 bool is_compiled_by_c2() const;
twisti@2047 343 bool is_compiled_by_shark() const;
duke@435 344
duke@435 345 // boundaries for different parts
twisti@2117 346 address consts_begin () const { return header_begin() + _consts_offset ; }
twisti@2117 347 address consts_end () const { return header_begin() + code_offset() ; }
twisti@2117 348 address insts_begin () const { return header_begin() + code_offset() ; }
twisti@2103 349 address insts_end () const { return header_begin() + _stub_offset ; }
twisti@2117 350 address stub_begin () const { return header_begin() + _stub_offset ; }
twisti@2117 351 address stub_end () const { return header_begin() + _oops_offset ; }
twisti@1639 352 address exception_begin () const { return header_begin() + _exception_offset ; }
twisti@1639 353 address deopt_handler_begin () const { return header_begin() + _deoptimize_offset ; }
twisti@1639 354 address deopt_mh_handler_begin() const { return header_begin() + _deoptimize_mh_offset ; }
never@1813 355 address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (header_begin() + _unwind_handler_offset) : NULL; }
twisti@1918 356 oop* oops_begin () const { return (oop*) (header_begin() + _oops_offset) ; }
twisti@1918 357 oop* oops_end () const { return (oop*) (header_begin() + _scopes_data_offset) ; }
twisti@1918 358
twisti@1639 359 address scopes_data_begin () const { return header_begin() + _scopes_data_offset ; }
twisti@1639 360 address scopes_data_end () const { return header_begin() + _scopes_pcs_offset ; }
twisti@1639 361 PcDesc* scopes_pcs_begin () const { return (PcDesc*)(header_begin() + _scopes_pcs_offset ); }
twisti@1639 362 PcDesc* scopes_pcs_end () const { return (PcDesc*)(header_begin() + _dependencies_offset) ; }
twisti@1639 363 address dependencies_begin () const { return header_begin() + _dependencies_offset ; }
twisti@1639 364 address dependencies_end () const { return header_begin() + _handler_table_offset ; }
twisti@1639 365 address handler_table_begin () const { return header_begin() + _handler_table_offset ; }
twisti@1639 366 address handler_table_end () const { return header_begin() + _nul_chk_table_offset ; }
twisti@1639 367 address nul_chk_table_begin () const { return header_begin() + _nul_chk_table_offset ; }
twisti@1639 368 address nul_chk_table_end () const { return header_begin() + _nmethod_end_offset ; }
duke@435 369
twisti@1918 370 // Sizes
twisti@2117 371 int consts_size () const { return consts_end () - consts_begin (); }
twisti@2103 372 int insts_size () const { return insts_end () - insts_begin (); }
twisti@1918 373 int stub_size () const { return stub_end () - stub_begin (); }
twisti@1918 374 int oops_size () const { return (address) oops_end () - (address) oops_begin (); }
twisti@1918 375 int scopes_data_size () const { return scopes_data_end () - scopes_data_begin (); }
twisti@1918 376 int scopes_pcs_size () const { return (intptr_t) scopes_pcs_end () - (intptr_t) scopes_pcs_begin (); }
twisti@1918 377 int dependencies_size () const { return dependencies_end () - dependencies_begin (); }
twisti@1918 378 int handler_table_size() const { return handler_table_end() - handler_table_begin(); }
twisti@1918 379 int nul_chk_table_size() const { return nul_chk_table_end() - nul_chk_table_begin(); }
duke@435 380
duke@435 381 int total_size () const;
duke@435 382
twisti@1918 383 // Containment
twisti@2117 384 bool consts_contains (address addr) const { return consts_begin () <= addr && addr < consts_end (); }
twisti@2103 385 bool insts_contains (address addr) const { return insts_begin () <= addr && addr < insts_end (); }
duke@435 386 bool stub_contains (address addr) const { return stub_begin () <= addr && addr < stub_end (); }
twisti@1918 387 bool oops_contains (oop* addr) const { return oops_begin () <= addr && addr < oops_end (); }
duke@435 388 bool scopes_data_contains (address addr) const { return scopes_data_begin () <= addr && addr < scopes_data_end (); }
duke@435 389 bool scopes_pcs_contains (PcDesc* addr) const { return scopes_pcs_begin () <= addr && addr < scopes_pcs_end (); }
duke@435 390 bool handler_table_contains(address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); }
duke@435 391 bool nul_chk_table_contains(address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
duke@435 392
duke@435 393 // entry points
duke@435 394 address entry_point() const { return _entry_point; } // normal entry point
duke@435 395 address verified_entry_point() const { return _verified_entry_point; } // if klass is correct
duke@435 396
duke@435 397 // flag accessing and manipulation
never@1999 398 bool is_in_use() const { return _state == alive; }
never@1999 399 bool is_alive() const { return _state == alive || _state == not_entrant; }
never@1999 400 bool is_not_entrant() const { return _state == not_entrant; }
never@1999 401 bool is_zombie() const { return _state == zombie; }
never@1999 402 bool is_unloaded() const { return _state == unloaded; }
duke@435 403
never@1544 404 // Make the nmethod non entrant. The nmethod will continue to be
never@1544 405 // alive. It is used when an uncommon trap happens. Returns true
never@1544 406 // if this thread changed the state of the nmethod or false if
never@1544 407 // another thread performed the transition.
never@1544 408 bool make_not_entrant() { return make_not_entrant_or_zombie(not_entrant); }
never@1544 409 bool make_zombie() { return make_not_entrant_or_zombie(zombie); }
duke@435 410
duke@435 411 // used by jvmti to track if the unload event has been reported
duke@435 412 bool unload_reported() { return _unload_reported; }
duke@435 413 void set_unload_reported() { _unload_reported = true; }
duke@435 414
never@1999 415 bool is_marked_for_deoptimization() const { return _marked_for_deoptimization; }
never@1999 416 void mark_for_deoptimization() { _marked_for_deoptimization = true; }
duke@435 417
duke@435 418 void make_unloaded(BoolObjectClosure* is_alive, oop cause);
duke@435 419
duke@435 420 bool has_dependencies() { return dependencies_size() != 0; }
duke@435 421 void flush_dependencies(BoolObjectClosure* is_alive);
never@1999 422 bool has_flushed_dependencies() { return _has_flushed_dependencies; }
never@1999 423 void set_has_flushed_dependencies() {
duke@435 424 assert(!has_flushed_dependencies(), "should only happen once");
never@1999 425 _has_flushed_dependencies = 1;
duke@435 426 }
duke@435 427
never@1999 428 bool is_marked_for_reclamation() const { return _marked_for_reclamation; }
never@1999 429 void mark_for_reclamation() { _marked_for_reclamation = 1; }
duke@435 430
never@1999 431 bool has_unsafe_access() const { return _has_unsafe_access; }
never@1999 432 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
duke@435 433
never@1999 434 bool has_method_handle_invokes() const { return _has_method_handle_invokes; }
never@1999 435 void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; }
twisti@1570 436
never@1999 437 bool is_speculatively_disconnected() const { return _speculatively_disconnected; }
never@1999 438 void set_speculatively_disconnected(bool z) { _speculatively_disconnected = z; }
kvn@1637 439
duke@435 440 int comp_level() const { return _comp_level; }
duke@435 441
twisti@1918 442 // Support for oops in scopes and relocs:
twisti@1918 443 // Note: index 0 is reserved for null.
twisti@1918 444 oop oop_at(int index) const { return index == 0 ? (oop) NULL: *oop_addr_at(index); }
twisti@1918 445 oop* oop_addr_at(int index) const { // for GC
twisti@1918 446 // relocation indexes are biased by 1 (because 0 is reserved)
twisti@1918 447 assert(index > 0 && index <= oops_size(), "must be a valid non-zero index");
never@2081 448 assert(!_oops_are_stale, "oops are stale");
twisti@1918 449 return &oops_begin()[index - 1];
twisti@1918 450 }
twisti@1918 451
twisti@1918 452 void copy_oops(GrowableArray<jobject>* oops);
twisti@1918 453
twisti@1918 454 // Relocation support
twisti@1918 455 private:
twisti@1918 456 void fix_oop_relocations(address begin, address end, bool initialize_immediates);
twisti@1918 457 inline void initialize_immediate_oop(oop* dest, jobject handle);
twisti@1918 458
twisti@1918 459 public:
twisti@1918 460 void fix_oop_relocations(address begin, address end) { fix_oop_relocations(begin, end, false); }
twisti@1918 461 void fix_oop_relocations() { fix_oop_relocations(NULL, NULL, false); }
twisti@1918 462
twisti@1918 463 bool is_at_poll_return(address pc);
twisti@1918 464 bool is_at_poll_or_poll_return(address pc);
twisti@1918 465
jrose@1424 466 // Non-perm oop support
jrose@1424 467 bool on_scavenge_root_list() const { return (_scavenge_root_state & 1) != 0; }
jrose@1424 468 protected:
jrose@1424 469 enum { npl_on_list = 0x01, npl_marked = 0x10 };
jrose@1424 470 void set_on_scavenge_root_list() { _scavenge_root_state = npl_on_list; }
jrose@1424 471 void clear_on_scavenge_root_list() { _scavenge_root_state = 0; }
jrose@1424 472 // assertion-checking and pruning logic uses the bits of _scavenge_root_state
jrose@1424 473 #ifndef PRODUCT
jrose@1424 474 void set_scavenge_root_marked() { _scavenge_root_state |= npl_marked; }
jrose@1424 475 void clear_scavenge_root_marked() { _scavenge_root_state &= ~npl_marked; }
jrose@1424 476 bool scavenge_root_not_marked() { return (_scavenge_root_state &~ npl_on_list) == 0; }
jrose@1424 477 // N.B. there is no positive marked query, and we only use the not_marked query for asserts.
jrose@1424 478 #endif //PRODUCT
jrose@1424 479 nmethod* scavenge_root_link() const { return _scavenge_root_link; }
jrose@1424 480 void set_scavenge_root_link(nmethod *n) { _scavenge_root_link = n; }
jrose@1424 481
kvn@1637 482 nmethod* saved_nmethod_link() const { return _saved_nmethod_link; }
kvn@1637 483 void set_saved_nmethod_link(nmethod *n) { _saved_nmethod_link = n; }
kvn@1637 484
jrose@1424 485 public:
jrose@1424 486
duke@435 487 // Sweeper support
duke@435 488 long stack_traversal_mark() { return _stack_traversal_mark; }
duke@435 489 void set_stack_traversal_mark(long l) { _stack_traversal_mark = l; }
duke@435 490
duke@435 491 // Exception cache support
duke@435 492 ExceptionCache* exception_cache() const { return _exception_cache; }
duke@435 493 void set_exception_cache(ExceptionCache *ec) { _exception_cache = ec; }
duke@435 494 address handler_for_exception_and_pc(Handle exception, address pc);
duke@435 495 void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
duke@435 496 void remove_from_exception_cache(ExceptionCache* ec);
duke@435 497
duke@435 498 // implicit exceptions support
duke@435 499 address continuation_for_implicit_exception(address pc);
duke@435 500
duke@435 501 // On-stack replacement support
duke@435 502 int osr_entry_bci() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _entry_bci; }
duke@435 503 address osr_entry() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _osr_entry_point; }
duke@435 504 void invalidate_osr_method();
jrose@1424 505 nmethod* osr_link() const { return _osr_link; }
jrose@1424 506 void set_osr_link(nmethod *n) { _osr_link = n; }
duke@435 507
duke@435 508 // tells whether frames described by this nmethod can be deoptimized
duke@435 509 // note: native wrappers cannot be deoptimized.
duke@435 510 bool can_be_deoptimized() const { return is_java_method(); }
duke@435 511
duke@435 512 // Inline cache support
duke@435 513 void clear_inline_caches();
duke@435 514 void cleanup_inline_caches();
duke@435 515 bool inlinecache_check_contains(address addr) const {
twisti@2103 516 return (addr >= code_begin() && addr < verified_entry_point());
duke@435 517 }
duke@435 518
duke@435 519 // unlink and deallocate this nmethod
duke@435 520 // Only NMethodSweeper class is expected to use this. NMethodSweeper is not
duke@435 521 // expected to use any other private methods/data in this class.
duke@435 522
duke@435 523 protected:
duke@435 524 void flush();
duke@435 525
duke@435 526 public:
dcubed@2624 527 // When true is returned, it is unsafe to remove this nmethod even if
dcubed@2624 528 // it is a zombie, since the VM or the ServiceThread might still be
dcubed@2624 529 // using it.
duke@435 530 bool is_locked_by_vm() const { return _lock_count >0; }
duke@435 531
duke@435 532 // See comment at definition of _last_seen_on_stack
duke@435 533 void mark_as_seen_on_stack();
duke@435 534 bool can_not_entrant_be_converted();
duke@435 535
duke@435 536 // Evolution support. We make old (discarded) compiled methods point to new methodOops.
duke@435 537 void set_method(methodOop method) { _method = method; }
duke@435 538
duke@435 539 // GC support
duke@435 540 void do_unloading(BoolObjectClosure* is_alive, OopClosure* keep_alive,
duke@435 541 bool unloading_occurred);
duke@435 542 bool can_unload(BoolObjectClosure* is_alive, OopClosure* keep_alive,
duke@435 543 oop* root, bool unloading_occurred);
duke@435 544
duke@435 545 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map,
duke@435 546 OopClosure* f);
twisti@1918 547 void oops_do(OopClosure* f) { oops_do(f, false); }
twisti@1918 548 void oops_do(OopClosure* f, bool do_strong_roots_only);
jrose@1424 549 bool detect_scavenge_root_oops();
jrose@1424 550 void verify_scavenge_root_oops() PRODUCT_RETURN;
jrose@1424 551
jrose@1424 552 bool test_set_oops_do_mark();
jrose@1424 553 static void oops_do_marking_prologue();
jrose@1424 554 static void oops_do_marking_epilogue();
jrose@1424 555 static bool oops_do_marking_is_active() { return _oops_do_mark_nmethods != NULL; }
jrose@1424 556 DEBUG_ONLY(bool test_oops_do_mark() { return _oops_do_mark_link != NULL; })
duke@435 557
duke@435 558 // ScopeDesc for an instruction
duke@435 559 ScopeDesc* scope_desc_at(address pc);
duke@435 560
duke@435 561 private:
duke@435 562 ScopeDesc* scope_desc_in(address begin, address end);
duke@435 563
twisti@1639 564 address* orig_pc_addr(const frame* fr) { return (address*) ((address)fr->unextended_sp() + _orig_pc_offset); }
duke@435 565
duke@435 566 PcDesc* find_pc_desc_internal(address pc, bool approximate);
duke@435 567
duke@435 568 PcDesc* find_pc_desc(address pc, bool approximate) {
duke@435 569 PcDesc* desc = _pc_desc_cache.last_pc_desc();
twisti@2103 570 if (desc != NULL && desc->pc_offset() == pc - code_begin()) {
duke@435 571 return desc;
duke@435 572 }
duke@435 573 return find_pc_desc_internal(pc, approximate);
duke@435 574 }
duke@435 575
duke@435 576 public:
duke@435 577 // ScopeDesc retrieval operation
duke@435 578 PcDesc* pc_desc_at(address pc) { return find_pc_desc(pc, false); }
duke@435 579 // pc_desc_near returns the first PcDesc at or after the givne pc.
duke@435 580 PcDesc* pc_desc_near(address pc) { return find_pc_desc(pc, true); }
duke@435 581
duke@435 582 public:
duke@435 583 // copying of debugging information
duke@435 584 void copy_scopes_pcs(PcDesc* pcs, int count);
duke@435 585 void copy_scopes_data(address buffer, int size);
duke@435 586
twisti@1639 587 // Deopt
twisti@1639 588 // Return true is the PC is one would expect if the frame is being deopted.
twisti@1639 589 bool is_deopt_pc (address pc) { return is_deopt_entry(pc) || is_deopt_mh_entry(pc); }
twisti@1639 590 bool is_deopt_entry (address pc) { return pc == deopt_handler_begin(); }
twisti@1639 591 bool is_deopt_mh_entry(address pc) { return pc == deopt_mh_handler_begin(); }
duke@435 592 // Accessor/mutator for the original pc of a frame before a frame was deopted.
duke@435 593 address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }
duke@435 594 void set_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }
duke@435 595
twisti@1639 596 static address get_deopt_original_pc(const frame* fr);
twisti@1639 597
twisti@1570 598 // MethodHandle
twisti@1570 599 bool is_method_handle_return(address return_pc);
twisti@1570 600
duke@435 601 // jvmti support:
duke@435 602 void post_compiled_method_load_event();
never@1971 603 jmethodID get_and_cache_jmethod_id();
duke@435 604
duke@435 605 // verify operations
duke@435 606 void verify();
duke@435 607 void verify_scopes();
duke@435 608 void verify_interrupt_point(address interrupt_point);
duke@435 609
iveresov@2138 610 // print compilation helper
iveresov@2138 611 static void print_compilation(outputStream *st, const char *method_name, const char *title,
iveresov@2138 612 methodOop method, bool is_blocking, int compile_id, int bci, int comp_level);
iveresov@2138 613
duke@435 614 // printing support
jrose@535 615 void print() const;
jrose@535 616 void print_code();
duke@435 617 void print_relocations() PRODUCT_RETURN;
duke@435 618 void print_pcs() PRODUCT_RETURN;
duke@435 619 void print_scopes() PRODUCT_RETURN;
duke@435 620 void print_dependencies() PRODUCT_RETURN;
duke@435 621 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 622 void print_calls(outputStream* st) PRODUCT_RETURN;
duke@435 623 void print_handler_table() PRODUCT_RETURN;
duke@435 624 void print_nul_chk_table() PRODUCT_RETURN;
jrose@535 625 void print_nmethod(bool print_code);
duke@435 626
bobv@2036 627 // need to re-define this from CodeBlob else the overload hides it
bobv@2036 628 virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }
duke@435 629 void print_on(outputStream* st, const char* title) const;
duke@435 630
duke@435 631 // Logging
duke@435 632 void log_identity(xmlStream* log) const;
duke@435 633 void log_new_nmethod() const;
never@1544 634 void log_state_change() const;
duke@435 635
jrose@1590 636 // Prints block-level comments, including nmethod specific block labels:
jrose@1590 637 virtual void print_block_comment(outputStream* stream, address block_begin) {
jrose@1590 638 print_nmethod_labels(stream, block_begin);
jrose@1590 639 CodeBlob::print_block_comment(stream, block_begin);
jrose@1590 640 }
jrose@1590 641 void print_nmethod_labels(outputStream* stream, address block_begin);
jrose@1590 642
duke@435 643 // Prints a comment for one native instruction (reloc info, pc desc)
jrose@535 644 void print_code_comment_on(outputStream* st, int column, address begin, address end);
duke@435 645 static void print_statistics() PRODUCT_RETURN;
duke@435 646
duke@435 647 // Compiler task identification. Note that all OSR methods
duke@435 648 // are numbered in an independent sequence if CICountOSR is true,
duke@435 649 // and native method wrappers are also numbered independently if
duke@435 650 // CICountNative is true.
duke@435 651 int compile_id() const { return _compile_id; }
duke@435 652 const char* compile_kind() const;
duke@435 653
duke@435 654 // For debugging
duke@435 655 // CompiledIC* IC_at(char* p) const;
duke@435 656 // PrimitiveIC* primitiveIC_at(char* p) const;
duke@435 657 oop embeddedOop_at(address p);
duke@435 658
duke@435 659 // tells if any of this method's dependencies have been invalidated
duke@435 660 // (this is expensive!)
duke@435 661 bool check_all_dependencies();
duke@435 662
duke@435 663 // tells if this compiled method is dependent on the given changes,
duke@435 664 // and the changes have invalidated it
duke@435 665 bool check_dependency_on(DepChange& changes);
duke@435 666
duke@435 667 // Evolution support. Tells if this compiled method is dependent on any of
duke@435 668 // methods m() of class dependee, such that if m() in dependee is replaced,
duke@435 669 // this compiled method will have to be deoptimized.
duke@435 670 bool is_evol_dependent_on(klassOop dependee);
duke@435 671
duke@435 672 // Fast breakpoint support. Tells if this compiled method is
duke@435 673 // dependent on the given method. Returns true if this nmethod
duke@435 674 // corresponds to the given method as well.
duke@435 675 bool is_dependent_on_method(methodOop dependee);
duke@435 676
duke@435 677 // is it ok to patch at address?
duke@435 678 bool is_patchable_at(address instr_address);
duke@435 679
duke@435 680 // UseBiasedLocking support
kamg@2361 681 ByteSize native_receiver_sp_offset() {
kamg@2361 682 return _native_receiver_sp_offset;
duke@435 683 }
kamg@2361 684 ByteSize native_basic_lock_sp_offset() {
kamg@2361 685 return _native_basic_lock_sp_offset;
duke@435 686 }
duke@435 687
duke@435 688 // support for code generation
duke@435 689 static int verified_entry_point_offset() { return offset_of(nmethod, _verified_entry_point); }
duke@435 690 static int osr_entry_point_offset() { return offset_of(nmethod, _osr_entry_point); }
duke@435 691 static int entry_bci_offset() { return offset_of(nmethod, _entry_bci); }
duke@435 692
duke@435 693 };
duke@435 694
dcubed@2624 695 // Locks an nmethod so its code will not get removed and it will not
dcubed@2624 696 // be made into a zombie, even if it is a not_entrant method. After the
dcubed@2624 697 // nmethod becomes a zombie, if CompiledMethodUnload event processing
dcubed@2624 698 // needs to be done, then lock_nmethod() is used directly to keep the
dcubed@2624 699 // generated code from being reused too early.
duke@435 700 class nmethodLocker : public StackObj {
duke@435 701 nmethod* _nm;
duke@435 702
kamg@2511 703 public:
kamg@2511 704
dcubed@2624 705 // note: nm can be NULL
dcubed@2624 706 // Only JvmtiDeferredEvent::compiled_method_unload_event()
dcubed@2624 707 // should pass zombie_ok == true.
dcubed@2624 708 static void lock_nmethod(nmethod* nm, bool zombie_ok = false);
duke@435 709 static void unlock_nmethod(nmethod* nm); // (ditto)
duke@435 710
duke@435 711 nmethodLocker(address pc); // derive nm from pc
duke@435 712 nmethodLocker(nmethod *nm) { _nm = nm; lock_nmethod(_nm); }
duke@435 713 nmethodLocker() { _nm = NULL; }
duke@435 714 ~nmethodLocker() { unlock_nmethod(_nm); }
duke@435 715
duke@435 716 nmethod* code() { return _nm; }
duke@435 717 void set_code(nmethod* new_nm) {
duke@435 718 unlock_nmethod(_nm); // note: This works even if _nm==new_nm.
duke@435 719 _nm = new_nm;
duke@435 720 lock_nmethod(_nm);
duke@435 721 }
duke@435 722 };
stefank@2314 723
stefank@2314 724 #endif // SHARE_VM_CODE_NMETHOD_HPP

mercurial