comparison src/share/vm/oops/method.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents c6a1ffc707ff a1ebd310d5c1
children 36bcc10e01c0
comparison
equal deleted inserted replaced
10086:e0fb8a213650 10408:836a62f43af9
72 method_type, 72 method_type,
73 CHECK_NULL); 73 CHECK_NULL);
74 74
75 int size = Method::size(access_flags.is_native()); 75 int size = Method::size(access_flags.is_native());
76 76
77 return new (loader_data, size, false, THREAD) Method(cm, access_flags, size); 77 return new (loader_data, size, false, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags, size);
78 } 78 }
79 79
80 Method::Method(ConstMethod* xconst, AccessFlags access_flags, int size) { 80 Method::Method(ConstMethod* xconst, AccessFlags access_flags, int size) {
81 No_Safepoint_Verifier no_safepoint; 81 No_Safepoint_Verifier no_safepoint;
82 set_constMethod(xconst); 82 set_constMethod(xconst);
89 set_jfr_towrite(false); 89 set_jfr_towrite(false);
90 set_force_inline(false); 90 set_force_inline(false);
91 set_hidden(false); 91 set_hidden(false);
92 set_dont_inline(false); 92 set_dont_inline(false);
93 set_method_data(NULL); 93 set_method_data(NULL);
94 set_interpreter_throwout_count(0); 94 set_method_counters(NULL);
95 set_vtable_index(Method::garbage_vtable_index); 95 set_vtable_index(Method::garbage_vtable_index);
96 96
97 // Fix and bury in Method* 97 // Fix and bury in Method*
98 set_interpreter_entry(NULL); // sets i2i entry and from_int 98 set_interpreter_entry(NULL); // sets i2i entry and from_int
99 set_adapter_entry(NULL); 99 set_adapter_entry(NULL);
103 clear_native_function(); 103 clear_native_function();
104 set_signature_handler(NULL); 104 set_signature_handler(NULL);
105 } 105 }
106 106
107 NOT_PRODUCT(set_compiled_invocation_count(0);) 107 NOT_PRODUCT(set_compiled_invocation_count(0);)
108 set_interpreter_invocation_count(0);
109 invocation_counter()->init();
110 backedge_counter()->init();
111 clear_number_of_breakpoints();
112
113 #ifdef GRAAL
114 set_graal_invocation_time(0L);
115 set_graal_priority(0);
116 #endif
117
118 #ifdef TIERED
119 set_rate(0);
120 set_prev_event_count(0);
121 set_prev_time(0);
122 #endif
123 } 108 }
124 109
125 // Release Method*. The nmethod will be gone when we get here because 110 // Release Method*. The nmethod will be gone when we get here because
126 // we've walked the code cache. 111 // we've walked the code cache.
127 void Method::deallocate_contents(ClassLoaderData* loader_data) { 112 void Method::deallocate_contents(ClassLoaderData* loader_data) {
128 MetadataFactory::free_metadata(loader_data, constMethod()); 113 MetadataFactory::free_metadata(loader_data, constMethod());
129 set_constMethod(NULL); 114 set_constMethod(NULL);
130 MetadataFactory::free_metadata(loader_data, method_data()); 115 MetadataFactory::free_metadata(loader_data, method_data());
131 set_method_data(NULL); 116 set_method_data(NULL);
117 MetadataFactory::free_metadata(loader_data, method_counters());
118 set_method_counters(NULL);
132 // The nmethod will be gone when we get here. 119 // The nmethod will be gone when we get here.
133 if (code() != NULL) _code = NULL; 120 if (code() != NULL) _code = NULL;
134 } 121 }
135 122
136 address Method::get_i2c_entry() { 123 address Method::get_i2c_entry() {
326 if (is_accessor() || is_empty_method() || (code() != NULL)) { 313 if (is_accessor() || is_empty_method() || (code() != NULL)) {
327 // interpreter doesn't bump invocation counter of trivial methods 314 // interpreter doesn't bump invocation counter of trivial methods
328 // compiler does not bump invocation counter of compiled methods 315 // compiler does not bump invocation counter of compiled methods
329 return true; 316 return true;
330 } 317 }
331 else if (_invocation_counter.carry() || (method_data() != NULL && method_data()->invocation_counter()->carry())) { 318 else if ((method_counters() != NULL &&
319 method_counters()->invocation_counter()->carry()) ||
320 (method_data() != NULL &&
321 method_data()->invocation_counter()->carry())) {
332 // The carry bit is set when the counter overflows and causes 322 // The carry bit is set when the counter overflows and causes
333 // a compilation to occur. We don't know how many times 323 // a compilation to occur. We don't know how many times
334 // the counter has been reset, so we simply assume it has 324 // the counter has been reset, so we simply assume it has
335 // been executed more than n times. 325 // been executed more than n times.
336 return true; 326 return true;
388 method->print_name(tty); 378 method->print_name(tty);
389 tty->cr(); 379 tty->cr();
390 // At the end of the run, the MDO, full of data, will be dumped. 380 // At the end of the run, the MDO, full of data, will be dumped.
391 } 381 }
392 } 382 }
383 }
384
385 MethodCounters* Method::build_method_counters(Method* m, TRAPS) {
386 methodHandle mh(m);
387 ClassLoaderData* loader_data = mh->method_holder()->class_loader_data();
388 MethodCounters* counters = MethodCounters::allocate(loader_data, CHECK_NULL);
389 if (mh->method_counters() == NULL) {
390 mh->set_method_counters(counters);
391 } else {
392 MetadataFactory::free_metadata(loader_data, counters);
393 }
394 return mh->method_counters();
393 } 395 }
394 396
395 void Method::cleanup_inline_caches() { 397 void Method::cleanup_inline_caches() {
396 // The current system doesn't use inline caches in the interpreter 398 // The current system doesn't use inline caches in the interpreter
397 // => nothing to do (keep this method around for future use) 399 // => nothing to do (keep this method around for future use)
797 if (is_native()) { 799 if (is_native()) {
798 *native_function_addr() = NULL; 800 *native_function_addr() = NULL;
799 set_signature_handler(NULL); 801 set_signature_handler(NULL);
800 } 802 }
801 NOT_PRODUCT(set_compiled_invocation_count(0);) 803 NOT_PRODUCT(set_compiled_invocation_count(0);)
802 invocation_counter()->reset();
803 backedge_counter()->reset();
804 _adapter = NULL; 804 _adapter = NULL;
805 _from_compiled_entry = NULL; 805 _from_compiled_entry = NULL;
806 806
807 // In case of DumpSharedSpaces, _method_data should always be NULL. 807 // In case of DumpSharedSpaces, _method_data should always be NULL.
808 // 808 //
811 // have already been called (before an exception happened), so 811 // have already been called (before an exception happened), so
812 // this->_method_data may not be NULL. 812 // this->_method_data may not be NULL.
813 assert(!DumpSharedSpaces || _method_data == NULL, "unexpected method data?"); 813 assert(!DumpSharedSpaces || _method_data == NULL, "unexpected method data?");
814 814
815 set_method_data(NULL); 815 set_method_data(NULL);
816 set_interpreter_throwout_count(0); 816 set_method_counters(NULL);
817 set_interpreter_invocation_count(0);
818 } 817 }
819 818
820 // Called when the method_holder is getting linked. Setup entrypoints so the method 819 // Called when the method_holder is getting linked. Setup entrypoints so the method
821 // is ready to be called from interpreter, compiler, and vtables. 820 // is ready to be called from interpreter, compiler, and vtables.
822 void Method::link_method(methodHandle h_method, TRAPS) { 821 void Method::link_method(methodHandle h_method, TRAPS) {
831 assert(this == h_method(), "wrong h_method()" ); 830 assert(this == h_method(), "wrong h_method()" );
832 address entry = Interpreter::entry_for_method(h_method); 831 address entry = Interpreter::entry_for_method(h_method);
833 assert(entry != NULL, "interpreter entry must be non-null"); 832 assert(entry != NULL, "interpreter entry must be non-null");
834 // Sets both _i2i_entry and _from_interpreted_entry 833 // Sets both _i2i_entry and _from_interpreted_entry
835 set_interpreter_entry(entry); 834 set_interpreter_entry(entry);
836 if (is_native() && !is_method_handle_intrinsic()) { 835
836 // Don't overwrite already registered native entries.
837 if (is_native() && !has_native_function()) {
837 set_native_function( 838 set_native_function(
838 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), 839 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
839 !native_bind_event_is_interesting); 840 !native_bind_event_is_interesting);
840 } 841 }
841 842
884 // This function must not hit a safepoint! 885 // This function must not hit a safepoint!
885 address Method::verified_code_entry() { 886 address Method::verified_code_entry() {
886 debug_only(No_Safepoint_Verifier nsv;) 887 debug_only(No_Safepoint_Verifier nsv;)
887 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code); 888 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
888 if (code == NULL && UseCodeCacheFlushing) { 889 if (code == NULL && UseCodeCacheFlushing) {
889 nmethod *saved_code = CodeCache::find_and_remove_saved_code(this); 890 nmethod *saved_code = CodeCache::reanimate_saved_code(this);
890 if (saved_code != NULL) { 891 if (saved_code != NULL) {
891 methodHandle method(this); 892 methodHandle method(this);
892 assert( ! saved_code->is_osr_method(), "should not get here for osr" ); 893 assert( ! saved_code->is_osr_method(), "should not get here for osr" );
893 set_code( method, saved_code ); 894 set_code( method, saved_code );
894 } 895 }
1556 clear_matches(this, -1); 1557 clear_matches(this, -1);
1557 } 1558 }
1558 1559
1559 1560
1560 int Method::invocation_count() { 1561 int Method::invocation_count() {
1562 MethodCounters *mcs = method_counters();
1561 if (TieredCompilation) { 1563 if (TieredCompilation) {
1562 MethodData* const mdo = method_data(); 1564 MethodData* const mdo = method_data();
1563 if (invocation_counter()->carry() || ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) { 1565 if (((mcs != NULL) ? mcs->invocation_counter()->carry() : false) ||
1566 ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) {
1564 return InvocationCounter::count_limit; 1567 return InvocationCounter::count_limit;
1565 } else { 1568 } else {
1566 return invocation_counter()->count() + ((mdo != NULL) ? mdo->invocation_counter()->count() : 0); 1569 return ((mcs != NULL) ? mcs->invocation_counter()->count() : 0) +
1570 ((mdo != NULL) ? mdo->invocation_counter()->count() : 0);
1567 } 1571 }
1568 } else { 1572 } else {
1569 return invocation_counter()->count(); 1573 return (mcs == NULL) ? 0 : mcs->invocation_counter()->count();
1570 } 1574 }
1571 } 1575 }
1572 1576
1573 int Method::backedge_count() { 1577 int Method::backedge_count() {
1578 MethodCounters *mcs = method_counters();
1574 if (TieredCompilation) { 1579 if (TieredCompilation) {
1575 MethodData* const mdo = method_data(); 1580 MethodData* const mdo = method_data();
1576 if (backedge_counter()->carry() || ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) { 1581 if (((mcs != NULL) ? mcs->backedge_counter()->carry() : false) ||
1582 ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) {
1577 return InvocationCounter::count_limit; 1583 return InvocationCounter::count_limit;
1578 } else { 1584 } else {
1579 return backedge_counter()->count() + ((mdo != NULL) ? mdo->backedge_counter()->count() : 0); 1585 return ((mcs != NULL) ? mcs->backedge_counter()->count() : 0) +
1586 ((mdo != NULL) ? mdo->backedge_counter()->count() : 0);
1580 } 1587 }
1581 } else { 1588 } else {
1582 return backedge_counter()->count(); 1589 return (mcs == NULL) ? 0 : mcs->backedge_counter()->count();
1583 } 1590 }
1584 } 1591 }
1585 1592
1586 int Method::highest_comp_level() const { 1593 int Method::highest_comp_level() const {
1587 MethodData* mdo = method_data(); 1594 const MethodData* mdo = method_data();
1588 if (mdo != NULL) { 1595 if (mdo != NULL) {
1589 return mdo->highest_comp_level(); 1596 return mdo->highest_comp_level();
1590 } else { 1597 } else {
1591 return CompLevel_none; 1598 return CompLevel_none;
1592 } 1599 }
1593 } 1600 }
1594 1601
1595 int Method::highest_osr_comp_level() const { 1602 int Method::highest_osr_comp_level() const {
1596 MethodData* mdo = method_data(); 1603 const MethodData* mdo = method_data();
1597 if (mdo != NULL) { 1604 if (mdo != NULL) {
1598 return mdo->highest_osr_comp_level(); 1605 return mdo->highest_osr_comp_level();
1599 } else { 1606 } else {
1600 return CompLevel_none; 1607 return CompLevel_none;
1601 } 1608 }
1632 if (code == Bytecodes::_breakpoint) 1639 if (code == Bytecodes::_breakpoint)
1633 code = method->orig_bytecode_at(_bci); 1640 code = method->orig_bytecode_at(_bci);
1634 assert(orig_bytecode() == code, "original bytecode must be the same"); 1641 assert(orig_bytecode() == code, "original bytecode must be the same");
1635 } 1642 }
1636 #endif 1643 #endif
1644 Thread *thread = Thread::current();
1637 *method->bcp_from(_bci) = Bytecodes::_breakpoint; 1645 *method->bcp_from(_bci) = Bytecodes::_breakpoint;
1638 method->incr_number_of_breakpoints(); 1646 method->incr_number_of_breakpoints(thread);
1639 SystemDictionary::notice_modification(); 1647 SystemDictionary::notice_modification();
1640 { 1648 {
1641 // Deoptimize all dependents on this method 1649 // Deoptimize all dependents on this method
1642 Thread *thread = Thread::current();
1643 HandleMark hm(thread); 1650 HandleMark hm(thread);
1644 methodHandle mh(thread, method); 1651 methodHandle mh(thread, method);
1645 Universe::flush_dependents_on_method(mh); 1652 Universe::flush_dependents_on_method(mh);
1646 } 1653 }
1647 } 1654 }
1648 1655
1649 void BreakpointInfo::clear(Method* method) { 1656 void BreakpointInfo::clear(Method* method) {
1650 *method->bcp_from(_bci) = orig_bytecode(); 1657 *method->bcp_from(_bci) = orig_bytecode();
1651 assert(method->number_of_breakpoints() > 0, "must not go negative"); 1658 assert(method->number_of_breakpoints() > 0, "must not go negative");
1652 method->decr_number_of_breakpoints(); 1659 method->decr_number_of_breakpoints(Thread::current());
1653 } 1660 }
1654 1661
1655 // jmethodID handling 1662 // jmethodID handling
1656 1663
1657 // This is a block allocating object, sort of like JNIHandleBlock, only a 1664 // This is a block allocating object, sort of like JNIHandleBlock, only a
1980 md->is_metadata(), "should be metadata"); 1987 md->is_metadata(), "should be metadata");
1981 guarantee(md == NULL || 1988 guarantee(md == NULL ||
1982 md->is_methodData(), "should be method data"); 1989 md->is_methodData(), "should be method data");
1983 } 1990 }
1984 1991
1985 #ifdef GRAAL
1986 void Method::reset_counters() {
1987 invocation_counter()->reset();
1988 backedge_counter()->reset();
1989 _interpreter_invocation_count = 0;
1990 _interpreter_throwout_count = 0;
1991 #ifndef PRODUCT
1992 _compiled_invocation_count = 0;
1993 #endif 1992 #endif
1994 }
1995 #endif