comparison src/share/vm/code/nmethod.hpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents 957c266d8bc5 f2e12eb74117
children 679e6584c177
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
25 #ifndef SHARE_VM_CODE_NMETHOD_HPP 25 #ifndef SHARE_VM_CODE_NMETHOD_HPP
26 #define SHARE_VM_CODE_NMETHOD_HPP 26 #define SHARE_VM_CODE_NMETHOD_HPP
27 27
28 #include "code/codeBlob.hpp" 28 #include "code/codeBlob.hpp"
29 #include "code/pcDesc.hpp" 29 #include "code/pcDesc.hpp"
30 #include "oops/metadata.hpp"
30 31
31 // This class is used internally by nmethods, to cache 32 // This class is used internally by nmethods, to cache
32 // exception/pc/handler information. 33 // exception/pc/handler information.
33 34
34 class ExceptionCache : public CHeapObj<mtCode> { 35 class ExceptionCache : public CHeapObj<mtCode> {
35 friend class VMStructs; 36 friend class VMStructs;
36 private: 37 private:
37 enum { cache_size = 16 }; 38 enum { cache_size = 16 };
38 klassOop _exception_type; 39 Klass* _exception_type;
39 address _pc[cache_size]; 40 address _pc[cache_size];
40 address _handler[cache_size]; 41 address _handler[cache_size];
41 int _count; 42 int _count;
42 ExceptionCache* _next; 43 ExceptionCache* _next;
43 44
50 51
51 public: 52 public:
52 53
53 ExceptionCache(Handle exception, address pc, address handler); 54 ExceptionCache(Handle exception, address pc, address handler);
54 55
55 klassOop exception_type() { return _exception_type; } 56 Klass* exception_type() { return _exception_type; }
56 klassOop* exception_type_addr() { return &_exception_type; }
57 ExceptionCache* next() { return _next; } 57 ExceptionCache* next() { return _next; }
58 void set_next(ExceptionCache *ec) { _next = ec; } 58 void set_next(ExceptionCache *ec) { _next = ec; }
59 59
60 address match(Handle exception, address pc); 60 address match(Handle exception, address pc);
61 bool match_exception_with_space(Handle exception) ; 61 bool match_exception_with_space(Handle exception) ;
110 friend class VMStructs; 110 friend class VMStructs;
111 friend class NMethodSweeper; 111 friend class NMethodSweeper;
112 friend class CodeCache; // scavengable oops 112 friend class CodeCache; // scavengable oops
113 private: 113 private:
114 // Shared fields for all nmethod's 114 // Shared fields for all nmethod's
115 methodOop _method; 115 Method* _method;
116 int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method 116 int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
117 jmethodID _jmethod_id; // Cache of method()->jmethod_id() 117 jmethodID _jmethod_id; // Cache of method()->jmethod_id()
118 118
119 // Needed to keep nmethods alive that are not the default nmethod for the associated methodOop 119 #ifdef GRAAL
120 oop _graal_compiled_method; 120 // Needed to keep nmethods alive that are not the default nmethod for the associated Method.
121 // This field is initialized to Universe::non_oop_word() so that a non-default nmethod
122 // is not unloaded between being allocated and having this field set in the Graal specific code
123 oop _graal_installed_code;
124 #endif
121 125
122 // To support simple linked-list chaining of nmethods: 126 // To support simple linked-list chaining of nmethods:
123 nmethod* _osr_link; // from instanceKlass::osr_nmethods_head 127 nmethod* _osr_link; // from InstanceKlass::osr_nmethods_head
124 nmethod* _scavenge_root_link; // from CodeCache::scavenge_root_nmethods 128 nmethod* _scavenge_root_link; // from CodeCache::scavenge_root_nmethods
125 nmethod* _saved_nmethod_link; // from CodeCache::speculatively_disconnect 129 nmethod* _saved_nmethod_link; // from CodeCache::speculatively_disconnect
126 130
127 static nmethod* volatile _oops_do_mark_nmethods; 131 static nmethod* volatile _oops_do_mark_nmethods;
128 nmethod* volatile _oops_do_mark_link; 132 nmethod* volatile _oops_do_mark_link;
149 int _trap_offset; 153 int _trap_offset;
150 #endif // def HAVE_DTRACE_H 154 #endif // def HAVE_DTRACE_H
151 int _consts_offset; 155 int _consts_offset;
152 int _stub_offset; 156 int _stub_offset;
153 int _oops_offset; // offset to where embedded oop table begins (inside data) 157 int _oops_offset; // offset to where embedded oop table begins (inside data)
158 int _metadata_offset; // embedded meta data table
154 int _scopes_data_offset; 159 int _scopes_data_offset;
155 int _scopes_pcs_offset; 160 int _scopes_pcs_offset;
156 int _dependencies_offset; 161 int _dependencies_offset;
157 int _handler_table_offset; 162 int _handler_table_offset;
158 int _nul_chk_table_offset; 163 int _nul_chk_table_offset;
177 182
178 // set during construction 183 // set during construction
179 unsigned int _has_unsafe_access:1; // May fault due to unsafe access. 184 unsigned int _has_unsafe_access:1; // May fault due to unsafe access.
180 unsigned int _has_method_handle_invokes:1; // Has this method MethodHandle invokes? 185 unsigned int _has_method_handle_invokes:1; // Has this method MethodHandle invokes?
181 unsigned int _lazy_critical_native:1; // Lazy JNI critical native 186 unsigned int _lazy_critical_native:1; // Lazy JNI critical native
187 unsigned int _has_wide_vectors:1; // Preserve wide vectors at safepoints
182 188
183 // Protected by Patching_lock 189 // Protected by Patching_lock
184 unsigned char _state; // {alive, not_entrant, zombie, unloaded} 190 unsigned char _state; // {alive, not_entrant, zombie, unloaded}
185 191
186 #ifdef ASSERT 192 #ifdef ASSERT
227 ByteSize _native_basic_lock_sp_offset; 233 ByteSize _native_basic_lock_sp_offset;
228 234
229 friend class nmethodLocker; 235 friend class nmethodLocker;
230 236
231 // For native wrappers 237 // For native wrappers
232 nmethod(methodOop method, 238 nmethod(Method* method,
233 int nmethod_size, 239 int nmethod_size,
234 int compile_id, 240 int compile_id,
235 CodeOffsets* offsets, 241 CodeOffsets* offsets,
236 CodeBuffer *code_buffer, 242 CodeBuffer *code_buffer,
237 int frame_size, 243 int frame_size,
239 ByteSize basic_lock_sp_offset, /* synchronized natives only */ 245 ByteSize basic_lock_sp_offset, /* synchronized natives only */
240 OopMapSet* oop_maps); 246 OopMapSet* oop_maps);
241 247
242 #ifdef HAVE_DTRACE_H 248 #ifdef HAVE_DTRACE_H
243 // For native wrappers 249 // For native wrappers
244 nmethod(methodOop method, 250 nmethod(Method* method,
245 int nmethod_size, 251 int nmethod_size,
246 CodeOffsets* offsets, 252 CodeOffsets* offsets,
247 CodeBuffer *code_buffer, 253 CodeBuffer *code_buffer,
248 int frame_size); 254 int frame_size);
249 #endif // def HAVE_DTRACE_H 255 #endif // def HAVE_DTRACE_H
250 256
251 // Creation support 257 // Creation support
252 nmethod(methodOop method, 258 nmethod(Method* method,
253 int nmethod_size, 259 int nmethod_size,
254 int compile_id, 260 int compile_id,
255 int entry_bci, 261 int entry_bci,
256 CodeOffsets* offsets, 262 CodeOffsets* offsets,
257 int orig_pc_offset, 263 int orig_pc_offset,
326 address trap_address() const { return insts_begin() + _trap_offset; } 332 address trap_address() const { return insts_begin() + _trap_offset; }
327 333
328 #endif // def HAVE_DTRACE_H 334 #endif // def HAVE_DTRACE_H
329 335
330 // accessors 336 // accessors
331 methodOop method() const { return _method; } 337 Method* method() const { return _method; }
332 AbstractCompiler* compiler() const { return _compiler; } 338 AbstractCompiler* compiler() const { return _compiler; }
333 339
334 // type info 340 // type info
335 bool is_nmethod() const { return true; } 341 bool is_nmethod() const { return true; }
336 bool is_java_method() const { return !method()->is_native(); } 342 bool is_java_method() const { return !method()->is_native(); }
354 address exception_begin () const { assert(_exception_offset >= 0, "no exception handler"); return header_begin() + _exception_offset ; } 360 address exception_begin () const { assert(_exception_offset >= 0, "no exception handler"); return header_begin() + _exception_offset ; }
355 address deopt_handler_begin () const { assert(_deoptimize_offset >= 0, "no deopt handler"); return header_begin() + _deoptimize_offset ; } 361 address deopt_handler_begin () const { assert(_deoptimize_offset >= 0, "no deopt handler"); return header_begin() + _deoptimize_offset ; }
356 address deopt_mh_handler_begin() const { return header_begin() + _deoptimize_mh_offset ; } 362 address deopt_mh_handler_begin() const { return header_begin() + _deoptimize_mh_offset ; }
357 address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (header_begin() + _unwind_handler_offset) : NULL; } 363 address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (header_begin() + _unwind_handler_offset) : NULL; }
358 oop* oops_begin () const { return (oop*) (header_begin() + _oops_offset) ; } 364 oop* oops_begin () const { return (oop*) (header_begin() + _oops_offset) ; }
359 oop* oops_end () const { return (oop*) (header_begin() + _scopes_data_offset) ; } 365 oop* oops_end () const { return (oop*) (header_begin() + _metadata_offset) ; }
366
367 Metadata** metadata_begin () const { return (Metadata**) (header_begin() + _metadata_offset) ; }
368 Metadata** metadata_end () const { return (Metadata**) (header_begin() + _scopes_data_offset) ; }
360 369
361 address scopes_data_begin () const { return header_begin() + _scopes_data_offset ; } 370 address scopes_data_begin () const { return header_begin() + _scopes_data_offset ; }
362 address scopes_data_end () const { return header_begin() + _scopes_pcs_offset ; } 371 address scopes_data_end () const { return header_begin() + _scopes_pcs_offset ; }
363 PcDesc* scopes_pcs_begin () const { return (PcDesc*)(header_begin() + _scopes_pcs_offset ); } 372 PcDesc* scopes_pcs_begin () const { return (PcDesc*)(header_begin() + _scopes_pcs_offset ); }
364 PcDesc* scopes_pcs_end () const { return (PcDesc*)(header_begin() + _dependencies_offset) ; } 373 PcDesc* scopes_pcs_end () const { return (PcDesc*)(header_begin() + _dependencies_offset) ; }
372 // Sizes 381 // Sizes
373 int consts_size () const { return consts_end () - consts_begin (); } 382 int consts_size () const { return consts_end () - consts_begin (); }
374 int insts_size () const { return insts_end () - insts_begin (); } 383 int insts_size () const { return insts_end () - insts_begin (); }
375 int stub_size () const { return stub_end () - stub_begin (); } 384 int stub_size () const { return stub_end () - stub_begin (); }
376 int oops_size () const { return (address) oops_end () - (address) oops_begin (); } 385 int oops_size () const { return (address) oops_end () - (address) oops_begin (); }
386 int metadata_size () const { return (address) metadata_end () - (address) metadata_begin (); }
377 int scopes_data_size () const { return scopes_data_end () - scopes_data_begin (); } 387 int scopes_data_size () const { return scopes_data_end () - scopes_data_begin (); }
378 int scopes_pcs_size () const { return (intptr_t) scopes_pcs_end () - (intptr_t) scopes_pcs_begin (); } 388 int scopes_pcs_size () const { return (intptr_t) scopes_pcs_end () - (intptr_t) scopes_pcs_begin (); }
379 int dependencies_size () const { return dependencies_end () - dependencies_begin (); } 389 int dependencies_size () const { return dependencies_end () - dependencies_begin (); }
380 int handler_table_size() const { return handler_table_end() - handler_table_begin(); } 390 int handler_table_size() const { return handler_table_end() - handler_table_begin(); }
381 int nul_chk_table_size() const { return nul_chk_table_end() - nul_chk_table_begin(); } 391 int nul_chk_table_size() const { return nul_chk_table_end() - nul_chk_table_begin(); }
385 // Containment 395 // Containment
386 bool consts_contains (address addr) const { return consts_begin () <= addr && addr < consts_end (); } 396 bool consts_contains (address addr) const { return consts_begin () <= addr && addr < consts_end (); }
387 bool insts_contains (address addr) const { return insts_begin () <= addr && addr < insts_end (); } 397 bool insts_contains (address addr) const { return insts_begin () <= addr && addr < insts_end (); }
388 bool stub_contains (address addr) const { return stub_begin () <= addr && addr < stub_end (); } 398 bool stub_contains (address addr) const { return stub_begin () <= addr && addr < stub_end (); }
389 bool oops_contains (oop* addr) const { return oops_begin () <= addr && addr < oops_end (); } 399 bool oops_contains (oop* addr) const { return oops_begin () <= addr && addr < oops_end (); }
400 bool metadata_contains (Metadata** addr) const { return metadata_begin () <= addr && addr < metadata_end (); }
390 bool scopes_data_contains (address addr) const { return scopes_data_begin () <= addr && addr < scopes_data_end (); } 401 bool scopes_data_contains (address addr) const { return scopes_data_begin () <= addr && addr < scopes_data_end (); }
391 bool scopes_pcs_contains (PcDesc* addr) const { return scopes_pcs_begin () <= addr && addr < scopes_pcs_end (); } 402 bool scopes_pcs_contains (PcDesc* addr) const { return scopes_pcs_begin () <= addr && addr < scopes_pcs_end (); }
392 bool handler_table_contains(address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); } 403 bool handler_table_contains(address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); }
393 bool nul_chk_table_contains(address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); } 404 bool nul_chk_table_contains(address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
394 405
439 bool is_speculatively_disconnected() const { return _speculatively_disconnected; } 450 bool is_speculatively_disconnected() const { return _speculatively_disconnected; }
440 void set_speculatively_disconnected(bool z) { _speculatively_disconnected = z; } 451 void set_speculatively_disconnected(bool z) { _speculatively_disconnected = z; }
441 452
442 bool is_lazy_critical_native() const { return _lazy_critical_native; } 453 bool is_lazy_critical_native() const { return _lazy_critical_native; }
443 void set_lazy_critical_native(bool z) { _lazy_critical_native = z; } 454 void set_lazy_critical_native(bool z) { _lazy_critical_native = z; }
455
456 bool has_wide_vectors() const { return _has_wide_vectors; }
457 void set_has_wide_vectors(bool z) { _has_wide_vectors = z; }
444 458
445 int comp_level() const { return _comp_level; } 459 int comp_level() const { return _comp_level; }
446 460
447 // Support for oops in scopes and relocs: 461 // Support for oops in scopes and relocs:
448 // Note: index 0 is reserved for null. 462 // Note: index 0 is reserved for null.
452 assert(index > 0 && index <= oops_size(), "must be a valid non-zero index"); 466 assert(index > 0 && index <= oops_size(), "must be a valid non-zero index");
453 assert(!_oops_are_stale, "oops are stale"); 467 assert(!_oops_are_stale, "oops are stale");
454 return &oops_begin()[index - 1]; 468 return &oops_begin()[index - 1];
455 } 469 }
456 470
457 void copy_oops(GrowableArray<jobject>* oops); 471 // Support for meta data in scopes and relocs:
472 // Note: index 0 is reserved for null.
473 Metadata* metadata_at(int index) const { return index == 0 ? NULL: *metadata_addr_at(index); }
474 Metadata** metadata_addr_at(int index) const { // for GC
475 // relocation indexes are biased by 1 (because 0 is reserved)
476 assert(index > 0 && index <= metadata_size(), "must be a valid non-zero index");
477 return &metadata_begin()[index - 1];
478 }
479
480 void copy_values(GrowableArray<jobject>* oops);
481 void copy_values(GrowableArray<Metadata*>* metadata);
458 482
459 // Relocation support 483 // Relocation support
460 private: 484 private:
461 void fix_oop_relocations(address begin, address end, bool initialize_immediates); 485 void fix_oop_relocations(address begin, address end, bool initialize_immediates);
462 inline void initialize_immediate_oop(oop* dest, jobject handle); 486 inline void initialize_immediate_oop(oop* dest, jobject handle);
520 void cleanup_inline_caches(); 544 void cleanup_inline_caches();
521 bool inlinecache_check_contains(address addr) const { 545 bool inlinecache_check_contains(address addr) const {
522 return (addr >= code_begin() && addr < verified_entry_point()); 546 return (addr >= code_begin() && addr < verified_entry_point());
523 } 547 }
524 548
549 // Check that all metadata is still alive
550 void verify_metadata_loaders(address low_boundary, BoolObjectClosure* is_alive);
551
525 // unlink and deallocate this nmethod 552 // unlink and deallocate this nmethod
526 // Only NMethodSweeper class is expected to use this. NMethodSweeper is not 553 // Only NMethodSweeper class is expected to use this. NMethodSweeper is not
527 // expected to use any other private methods/data in this class. 554 // expected to use any other private methods/data in this class.
528 555
529 protected: 556 protected:
537 564
538 // See comment at definition of _last_seen_on_stack 565 // See comment at definition of _last_seen_on_stack
539 void mark_as_seen_on_stack(); 566 void mark_as_seen_on_stack();
540 bool can_not_entrant_be_converted(); 567 bool can_not_entrant_be_converted();
541 568
542 // Evolution support. We make old (discarded) compiled methods point to new methodOops. 569 // Evolution support. We make old (discarded) compiled methods point to new Method*s.
543 void set_method(methodOop method) { _method = method; } 570 void set_method(Method* method) { _method = method; }
544 571
545 572 #ifdef GRAAL
546 oop graal_compiled_method() { return _graal_compiled_method; } 573 oop graal_installed_code() { return _graal_installed_code == Universe::non_oop_word() ? NULL : _graal_installed_code ; }
547 void set_graal_compiled_method(oop compiled_method) { _graal_compiled_method = compiled_method; } 574 void set_graal_installed_code(oop installed_code) { _graal_installed_code = installed_code; }
575 #endif
548 576
549 // GC support 577 // GC support
550 void do_unloading(BoolObjectClosure* is_alive, OopClosure* keep_alive, 578 void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
551 bool unloading_occurred); 579 bool can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred);
552 bool can_unload(BoolObjectClosure* is_alive, OopClosure* keep_alive,
553 oop* root, bool unloading_occurred);
554 580
555 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, 581 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map,
556 OopClosure* f); 582 OopClosure* f);
557 void oops_do(OopClosure* f) { oops_do(f, false); } 583 void oops_do(OopClosure* f) { oops_do(f, false); }
558 void oops_do(OopClosure* f, bool do_strong_roots_only); 584 void oops_do(OopClosure* f, bool do_strong_roots_only);
641 void log_identity(xmlStream* log) const; 667 void log_identity(xmlStream* log) const;
642 void log_new_nmethod() const; 668 void log_new_nmethod() const;
643 void log_state_change() const; 669 void log_state_change() const;
644 670
645 // Prints block-level comments, including nmethod specific block labels: 671 // Prints block-level comments, including nmethod specific block labels:
646 virtual void print_block_comment(outputStream* stream, address block_begin) { 672 virtual void print_block_comment(outputStream* stream, address block_begin) const {
647 print_nmethod_labels(stream, block_begin); 673 print_nmethod_labels(stream, block_begin);
648 CodeBlob::print_block_comment(stream, block_begin); 674 CodeBlob::print_block_comment(stream, block_begin);
649 } 675 }
650 void print_nmethod_labels(outputStream* stream, address block_begin); 676 void print_nmethod_labels(outputStream* stream, address block_begin) const;
651 677
652 // Prints a comment for one native instruction (reloc info, pc desc) 678 // Prints a comment for one native instruction (reloc info, pc desc)
653 void print_code_comment_on(outputStream* st, int column, address begin, address end); 679 void print_code_comment_on(outputStream* st, int column, address begin, address end);
654 static void print_statistics(); 680 static void print_statistics();
655 681
674 bool check_dependency_on(DepChange& changes); 700 bool check_dependency_on(DepChange& changes);
675 701
676 // Evolution support. Tells if this compiled method is dependent on any of 702 // Evolution support. Tells if this compiled method is dependent on any of
677 // methods m() of class dependee, such that if m() in dependee is replaced, 703 // methods m() of class dependee, such that if m() in dependee is replaced,
678 // this compiled method will have to be deoptimized. 704 // this compiled method will have to be deoptimized.
679 bool is_evol_dependent_on(klassOop dependee); 705 bool is_evol_dependent_on(Klass* dependee);
680 706
681 // Fast breakpoint support. Tells if this compiled method is 707 // Fast breakpoint support. Tells if this compiled method is
682 // dependent on the given method. Returns true if this nmethod 708 // dependent on the given method. Returns true if this nmethod
683 // corresponds to the given method as well. 709 // corresponds to the given method as well.
684 bool is_dependent_on_method(methodOop dependee); 710 bool is_dependent_on_method(Method* dependee);
685 711
686 // is it ok to patch at address? 712 // is it ok to patch at address?
687 bool is_patchable_at(address instr_address); 713 bool is_patchable_at(address instr_address);
688 714
689 // UseBiasedLocking support 715 // UseBiasedLocking support
697 // support for code generation 723 // support for code generation
698 static int verified_entry_point_offset() { return offset_of(nmethod, _verified_entry_point); } 724 static int verified_entry_point_offset() { return offset_of(nmethod, _verified_entry_point); }
699 static int osr_entry_point_offset() { return offset_of(nmethod, _osr_entry_point); } 725 static int osr_entry_point_offset() { return offset_of(nmethod, _osr_entry_point); }
700 static int entry_bci_offset() { return offset_of(nmethod, _entry_bci); } 726 static int entry_bci_offset() { return offset_of(nmethod, _entry_bci); }
701 727
728 // RedefineClasses support. Mark metadata in nmethods as on_stack so that
729 // redefine classes doesn't purge it.
730 static void mark_on_stack(nmethod* nm) {
731 nm->metadata_do(Metadata::mark_on_stack);
732 }
733 void metadata_do(void f(Metadata*));
702 }; 734 };
703 735
704 // Locks an nmethod so its code will not get removed and it will not 736 // Locks an nmethod so its code will not get removed and it will not
705 // be made into a zombie, even if it is a not_entrant method. After the 737 // be made into a zombie, even if it is a not_entrant method. After the
706 // nmethod becomes a zombie, if CompiledMethodUnload event processing 738 // nmethod becomes a zombie, if CompiledMethodUnload event processing