60 // Implementation of Method
61
62 Method* Method::allocate(ClassLoaderData* loader_data,
63 int byte_code_size,
64 AccessFlags access_flags,
65 InlineTableSizes* sizes,
66 ConstMethod::MethodType method_type,
67 TRAPS) {
68 assert(!access_flags.is_native() || byte_code_size == 0,
69 "native methods should not contain byte codes");
70 ConstMethod* cm = ConstMethod::allocate(loader_data,
71 byte_code_size,
72 sizes,
73 method_type,
74 CHECK_NULL);
75 int size = Method::size(access_flags.is_native());
76 return new (loader_data, size, false, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
77 }
78
79 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
80 No_Safepoint_Verifier no_safepoint;
81 set_constMethod(xconst);
82 set_access_flags(access_flags);
83 #ifdef CC_INTERP
84 set_result_index(T_VOID);
85 #endif
86 set_intrinsic_id(vmIntrinsics::_none);
87 set_jfr_towrite(false);
88 set_force_inline(false);
89 set_hidden(false);
90 set_dont_inline(false);
91 set_has_injected_profile(false);
92 set_method_data(NULL);
93 clear_method_counters();
94 set_vtable_index(Method::garbage_vtable_index);
95
96 // Fix and bury in Method*
97 set_interpreter_entry(NULL); // sets i2i entry and from_int
98 set_adapter_entry(NULL);
99 clear_code(); // from_c/from_i get set to c2i/i2i
100
981 // Since restore_unshareable_info can be called more than once for a method, don't
982 // redo any work. If this field is restored, there is nothing to do.
983 if (_from_compiled_entry == NULL) {
984 // restore method's vtable by calling a virtual function
985 restore_vtable();
986
987 methodHandle mh(THREAD, this);
988 link_method(mh, CHECK);
989 }
990 }
991
992
993 // The verified_code_entry() must be called when a invoke is resolved
994 // on this method.
995
996 // It returns the compiled code entry point, after asserting not null.
997 // This function is called after potential safepoints so that nmethod
998 // or adapter that it points to is still live and valid.
999 // This function must not hit a safepoint!
1000 address Method::verified_code_entry() {
1001 debug_only(No_Safepoint_Verifier nsv;)
1002 assert(_from_compiled_entry != NULL, "must be set");
1003 return _from_compiled_entry;
1004 }
1005
1006 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1007 // (could be racing a deopt).
1008 // Not inline to avoid circular ref.
1009 bool Method::check_code() const {
1010 // cached in a register or local. There's a race on the value of the field.
1011 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
1012 return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1013 }
1014
1015 // Install compiled code. Instantly it can execute.
1016 void Method::set_code(methodHandle mh, nmethod *code) {
1017 assert( code, "use clear_code to remove code" );
1018 assert( mh->check_code(), "" );
1019
1020 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1021
1531 st->print(" %s::", method_holder()->internal_name());
1532 #endif
1533 name()->print_symbol_on(st);
1534 if (WizardMode) signature()->print_symbol_on(st);
1535 else if (MethodHandles::is_signature_polymorphic(intrinsic_id()))
1536 MethodHandles::print_as_basic_type_signature_on(st, signature(), true);
1537 }
1538
1539 // Comparer for sorting an object array containing
1540 // Method*s.
1541 static int method_comparator(Method* a, Method* b) {
1542 return a->name()->fast_compare(b->name());
1543 }
1544
1545 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
1546 // default_methods also uses this without the ordering for fast find_method
1547 void Method::sort_methods(Array<Method*>* methods, bool idempotent, bool set_idnums) {
1548 int length = methods->length();
1549 if (length > 1) {
1550 {
1551 No_Safepoint_Verifier nsv;
1552 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent);
1553 }
1554 // Reset method ordering
1555 if (set_idnums) {
1556 for (int i = 0; i < length; i++) {
1557 Method* m = methods->at(i);
1558 m->set_method_idnum(i);
1559 m->set_orig_method_idnum(i);
1560 }
1561 }
1562 }
1563 }
1564
1565 //-----------------------------------------------------------------------------------
1566 // Non-product code unless JVM/TI needs it
1567
1568 #if !defined(PRODUCT) || INCLUDE_JVMTI
1569 class SignatureTypePrinter : public SignatureTypeNames {
1570 private:
1571 outputStream* _st;
|
60 // Implementation of Method
61
62 Method* Method::allocate(ClassLoaderData* loader_data,
63 int byte_code_size,
64 AccessFlags access_flags,
65 InlineTableSizes* sizes,
66 ConstMethod::MethodType method_type,
67 TRAPS) {
68 assert(!access_flags.is_native() || byte_code_size == 0,
69 "native methods should not contain byte codes");
70 ConstMethod* cm = ConstMethod::allocate(loader_data,
71 byte_code_size,
72 sizes,
73 method_type,
74 CHECK_NULL);
75 int size = Method::size(access_flags.is_native());
76 return new (loader_data, size, false, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
77 }
78
79 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
80 NoSafepointVerifier no_safepoint;
81 set_constMethod(xconst);
82 set_access_flags(access_flags);
83 #ifdef CC_INTERP
84 set_result_index(T_VOID);
85 #endif
86 set_intrinsic_id(vmIntrinsics::_none);
87 set_jfr_towrite(false);
88 set_force_inline(false);
89 set_hidden(false);
90 set_dont_inline(false);
91 set_has_injected_profile(false);
92 set_method_data(NULL);
93 clear_method_counters();
94 set_vtable_index(Method::garbage_vtable_index);
95
96 // Fix and bury in Method*
97 set_interpreter_entry(NULL); // sets i2i entry and from_int
98 set_adapter_entry(NULL);
99 clear_code(); // from_c/from_i get set to c2i/i2i
100
981 // Since restore_unshareable_info can be called more than once for a method, don't
982 // redo any work. If this field is restored, there is nothing to do.
983 if (_from_compiled_entry == NULL) {
984 // restore method's vtable by calling a virtual function
985 restore_vtable();
986
987 methodHandle mh(THREAD, this);
988 link_method(mh, CHECK);
989 }
990 }
991
992
993 // The verified_code_entry() must be called when a invoke is resolved
994 // on this method.
995
996 // It returns the compiled code entry point, after asserting not null.
997 // This function is called after potential safepoints so that nmethod
998 // or adapter that it points to is still live and valid.
999 // This function must not hit a safepoint!
1000 address Method::verified_code_entry() {
1001 debug_only(NoSafepointVerifier nsv;)
1002 assert(_from_compiled_entry != NULL, "must be set");
1003 return _from_compiled_entry;
1004 }
1005
1006 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1007 // (could be racing a deopt).
1008 // Not inline to avoid circular ref.
1009 bool Method::check_code() const {
1010 // cached in a register or local. There's a race on the value of the field.
1011 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
1012 return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1013 }
1014
1015 // Install compiled code. Instantly it can execute.
1016 void Method::set_code(methodHandle mh, nmethod *code) {
1017 assert( code, "use clear_code to remove code" );
1018 assert( mh->check_code(), "" );
1019
1020 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1021
1531 st->print(" %s::", method_holder()->internal_name());
1532 #endif
1533 name()->print_symbol_on(st);
1534 if (WizardMode) signature()->print_symbol_on(st);
1535 else if (MethodHandles::is_signature_polymorphic(intrinsic_id()))
1536 MethodHandles::print_as_basic_type_signature_on(st, signature(), true);
1537 }
1538
1539 // Comparer for sorting an object array containing
1540 // Method*s.
1541 static int method_comparator(Method* a, Method* b) {
1542 return a->name()->fast_compare(b->name());
1543 }
1544
1545 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
1546 // default_methods also uses this without the ordering for fast find_method
1547 void Method::sort_methods(Array<Method*>* methods, bool idempotent, bool set_idnums) {
1548 int length = methods->length();
1549 if (length > 1) {
1550 {
1551 NoSafepointVerifier nsv;
1552 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent);
1553 }
1554 // Reset method ordering
1555 if (set_idnums) {
1556 for (int i = 0; i < length; i++) {
1557 Method* m = methods->at(i);
1558 m->set_method_idnum(i);
1559 m->set_orig_method_idnum(i);
1560 }
1561 }
1562 }
1563 }
1564
1565 //-----------------------------------------------------------------------------------
1566 // Non-product code unless JVM/TI needs it
1567
1568 #if !defined(PRODUCT) || INCLUDE_JVMTI
1569 class SignatureTypePrinter : public SignatureTypeNames {
1570 private:
1571 outputStream* _st;
|