src/share/vm/code/nmethod.hpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 8734
c73c5d205d0a
child 8856
ac27a9c85bea
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial