annotate src/share/vm/code/nmethod.hpp @ 3682:f2e12eb74117

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