src/share/vm/code/nmethod.hpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6429
606acabe7b5c
child 6876
710a3c8b516e
child 6941
63e0c47ca943
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

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

mercurial