src/hotspot/share/oops/method.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 55005 9b70ebd131b4
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    26 #include "classfile/classLoaderDataGraph.hpp"
    26 #include "classfile/classLoaderDataGraph.hpp"
    27 #include "classfile/metadataOnStackMark.hpp"
    27 #include "classfile/metadataOnStackMark.hpp"
    28 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/systemDictionary.hpp"
    29 #include "code/codeCache.hpp"
    29 #include "code/codeCache.hpp"
    30 #include "code/debugInfoRec.hpp"
    30 #include "code/debugInfoRec.hpp"
       
    31 #include "compiler/compilationPolicy.hpp"
    31 #include "gc/shared/collectedHeap.inline.hpp"
    32 #include "gc/shared/collectedHeap.inline.hpp"
    32 #include "interpreter/bytecodeStream.hpp"
    33 #include "interpreter/bytecodeStream.hpp"
    33 #include "interpreter/bytecodeTracer.hpp"
    34 #include "interpreter/bytecodeTracer.hpp"
    34 #include "interpreter/bytecodes.hpp"
    35 #include "interpreter/bytecodes.hpp"
    35 #include "interpreter/interpreter.hpp"
    36 #include "interpreter/interpreter.hpp"
    52 #include "oops/symbol.hpp"
    53 #include "oops/symbol.hpp"
    53 #include "prims/jvmtiExport.hpp"
    54 #include "prims/jvmtiExport.hpp"
    54 #include "prims/methodHandles.hpp"
    55 #include "prims/methodHandles.hpp"
    55 #include "prims/nativeLookup.hpp"
    56 #include "prims/nativeLookup.hpp"
    56 #include "runtime/arguments.hpp"
    57 #include "runtime/arguments.hpp"
    57 #include "runtime/compilationPolicy.hpp"
       
    58 #include "runtime/frame.inline.hpp"
    58 #include "runtime/frame.inline.hpp"
    59 #include "runtime/handles.inline.hpp"
    59 #include "runtime/handles.inline.hpp"
    60 #include "runtime/init.hpp"
    60 #include "runtime/init.hpp"
    61 #include "runtime/orderAccess.hpp"
    61 #include "runtime/orderAccess.hpp"
    62 #include "runtime/relocator.hpp"
    62 #include "runtime/relocator.hpp"
   116 // Release Method*.  The nmethod will be gone when we get here because
   116 // Release Method*.  The nmethod will be gone when we get here because
   117 // we've walked the code cache.
   117 // we've walked the code cache.
   118 void Method::deallocate_contents(ClassLoaderData* loader_data) {
   118 void Method::deallocate_contents(ClassLoaderData* loader_data) {
   119   MetadataFactory::free_metadata(loader_data, constMethod());
   119   MetadataFactory::free_metadata(loader_data, constMethod());
   120   set_constMethod(NULL);
   120   set_constMethod(NULL);
   121 #if INCLUDE_JVMCI
       
   122   if (method_data()) {
       
   123     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
       
   124   }
       
   125 #endif
       
   126   MetadataFactory::free_metadata(loader_data, method_data());
   121   MetadataFactory::free_metadata(loader_data, method_data());
   127   set_method_data(NULL);
   122   set_method_data(NULL);
   128   MetadataFactory::free_metadata(loader_data, method_counters());
   123   MetadataFactory::free_metadata(loader_data, method_counters());
   129   clear_method_counters();
   124   clear_method_counters();
   130   // The nmethod will be gone when we get here.
   125   // The nmethod will be gone when we get here.
   131   if (code() != NULL) _code = NULL;
   126   if (code() != NULL) _code = NULL;
   132 }
   127 }
   133 
   128 
       
   129 void Method::release_C_heap_structures() {
       
   130   if (method_data()) {
       
   131 #if INCLUDE_JVMCI
       
   132     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
       
   133 #endif
       
   134     // Destroy MethodData
       
   135     method_data()->~MethodData();
       
   136   }
       
   137 }
       
   138 
   134 address Method::get_i2c_entry() {
   139 address Method::get_i2c_entry() {
   135   assert(adapter() != NULL, "must have");
   140   assert(adapter() != NULL, "must have");
   136   return adapter()->get_i2c_entry();
   141   return adapter()->get_i2c_entry();
   137 }
   142 }
   138 
   143 
   142 }
   147 }
   143 
   148 
   144 address Method::get_c2i_unverified_entry() {
   149 address Method::get_c2i_unverified_entry() {
   145   assert(adapter() != NULL, "must have");
   150   assert(adapter() != NULL, "must have");
   146   return adapter()->get_c2i_unverified_entry();
   151   return adapter()->get_c2i_unverified_entry();
       
   152 }
       
   153 
       
   154 address Method::get_c2i_no_clinit_check_entry() {
       
   155   assert(VM_Version::supports_fast_class_init_checks(), "");
       
   156   assert(adapter() != NULL, "must have");
       
   157   return adapter()->get_c2i_no_clinit_check_entry();
   147 }
   158 }
   148 
   159 
   149 char* Method::name_and_sig_as_C_string() const {
   160 char* Method::name_and_sig_as_C_string() const {
   150   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
   161   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
   151 }
   162 }
   702 
   713 
   703 bool Method::is_object_initializer() const {
   714 bool Method::is_object_initializer() const {
   704    return name() == vmSymbols::object_initializer_name();
   715    return name() == vmSymbols::object_initializer_name();
   705 }
   716 }
   706 
   717 
       
   718 bool Method::needs_clinit_barrier() const {
       
   719   return is_static() && !method_holder()->is_initialized();
       
   720 }
       
   721 
   707 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
   722 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
   708   int length = method->checked_exceptions_length();
   723   int length = method->checked_exceptions_length();
   709   if (length == 0) {  // common case
   724   if (length == 0) {  // common case
   710     return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
   725     return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
   711   } else {
   726   } else {
   816     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   831     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   817     !native_bind_event_is_interesting);
   832     !native_bind_event_is_interesting);
   818   this->unlink_code();
   833   this->unlink_code();
   819 }
   834 }
   820 
   835 
   821 address Method::critical_native_function() {
       
   822   methodHandle mh(this);
       
   823   return NativeLookup::lookup_critical_entry(mh);
       
   824 }
       
   825 
       
   826 
   836 
   827 void Method::set_signature_handler(address handler) {
   837 void Method::set_signature_handler(address handler) {
   828   address* signature_handler =  signature_handler_addr();
   838   address* signature_handler =  signature_handler_addr();
   829   *signature_handler = handler;
   839   *signature_handler = handler;
   830 }
   840 }
   831 
   841 
   832 
   842 
   833 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
   843 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
       
   844   assert(reason != NULL, "must provide a reason");
   834   if (PrintCompilation && report) {
   845   if (PrintCompilation && report) {
   835     ttyLocker ttyl;
   846     ttyLocker ttyl;
   836     tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
   847     tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
   837     if (comp_level == CompLevel_all) {
   848     if (comp_level == CompLevel_all) {
   838       tty->print("all levels ");
   849       tty->print("all levels ");
   839     } else {
   850     } else {
   840       tty->print("levels ");
   851       tty->print("level %d ", comp_level);
   841       for (int i = (int)CompLevel_none; i <= comp_level; i++) {
       
   842         tty->print("%d ", i);
       
   843       }
       
   844     }
   852     }
   845     this->print_short_name(tty);
   853     this->print_short_name(tty);
   846     int size = this->code_size();
   854     int size = this->code_size();
   847     if (size > 0) {
   855     if (size > 0) {
   848       tty->print(" (%d bytes)", size);
   856       tty->print(" (%d bytes)", size);
   889     return is_not_c2_compilable();
   897     return is_not_c2_compilable();
   890   return false;
   898   return false;
   891 }
   899 }
   892 
   900 
   893 // call this when compiler finds that this method is not compilable
   901 // call this when compiler finds that this method is not compilable
   894 void Method::set_not_compilable(int comp_level, bool report, const char* reason) {
   902 void Method::set_not_compilable(const char* reason, int comp_level, bool report) {
   895   if (is_always_compilable()) {
   903   if (is_always_compilable()) {
   896     // Don't mark a method which should be always compilable
   904     // Don't mark a method which should be always compilable
   897     return;
   905     return;
   898   }
   906   }
   899   print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason);
   907   print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason);
   920   if (is_c2_compile(comp_level))
   928   if (is_c2_compile(comp_level))
   921     return is_not_c2_osr_compilable();
   929     return is_not_c2_osr_compilable();
   922   return false;
   930   return false;
   923 }
   931 }
   924 
   932 
   925 void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) {
   933 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
   926   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
   934   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
   927   if (comp_level == CompLevel_all) {
   935   if (comp_level == CompLevel_all) {
   928     set_not_c1_osr_compilable();
   936     set_not_c1_osr_compilable();
   929     set_not_c2_osr_compilable();
   937     set_not_c2_osr_compilable();
   930   } else {
   938   } else {
   974 #if INCLUDE_CDS
   982 #if INCLUDE_CDS
   975 // Called by class data sharing to remove any entry points (which are not shared)
   983 // Called by class data sharing to remove any entry points (which are not shared)
   976 void Method::unlink_method() {
   984 void Method::unlink_method() {
   977   _code = NULL;
   985   _code = NULL;
   978 
   986 
   979   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
   987   Arguments::assert_is_dumping_archive();
   980   // Set the values to what they should be at run time. Note that
   988   // Set the values to what they should be at run time. Note that
   981   // this Method can no longer be executed during dump time.
   989   // this Method can no longer be executed during dump time.
   982   _i2i_entry = Interpreter::entry_for_cds_method(this);
   990   _i2i_entry = Interpreter::entry_for_cds_method(this);
   983   _from_interpreted_entry = _i2i_entry;
   991   _from_interpreted_entry = _i2i_entry;
   984 
   992 
  1059                                                  +----> [AdapterHandlerEntry] (allocated at run time)
  1067                                                  +----> [AdapterHandlerEntry] (allocated at run time)
  1060                                                               _fingerprint
  1068                                                               _fingerprint
  1061                                                               _c2i_entry ---------------------------------+->[c2i entry..]
  1069                                                               _c2i_entry ---------------------------------+->[c2i entry..]
  1062  _i2i_entry  -------------+                                   _i2c_entry ---------------+-> [i2c entry..] |
  1070  _i2i_entry  -------------+                                   _i2c_entry ---------------+-> [i2c entry..] |
  1063  _from_interpreted_entry  |                                   _c2i_unverified_entry     |                 |
  1071  _from_interpreted_entry  |                                   _c2i_unverified_entry     |                 |
  1064          |                |                                                             |                 |
  1072          |                |                                   _c2i_no_clinit_check_entry|                 |
  1065          |                |  (_cds_entry_table: CODE)                                   |                 |
  1073          |                |  (_cds_entry_table: CODE)                                   |                 |
  1066          |                +->[0]: jmp _entry_table[0] --> (i2i_entry_for "zero_locals") |                 |
  1074          |                +->[0]: jmp _entry_table[0] --> (i2i_entry_for "zero_locals") |                 |
  1067          |                |                               (allocated at run time)       |                 |
  1075          |                |                               (allocated at run time)       |                 |
  1068          |                |  ...                           [asm code ...]               |                 |
  1076          |                |  ...                           [asm code ...]               |                 |
  1069          +-[not compiled]-+  [n]: jmp _entry_table[n]                                   |                 |
  1077          +-[not compiled]-+  [n]: jmp _entry_table[n]                                   |                 |
  1195   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1203   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1196 }
  1204 }
  1197 
  1205 
  1198 // Install compiled code.  Instantly it can execute.
  1206 // Install compiled code.  Instantly it can execute.
  1199 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1207 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1200   MutexLocker pl(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
  1208   assert_lock_strong(CompiledMethod_lock);
  1201   assert( code, "use clear_code to remove code" );
  1209   assert( code, "use clear_code to remove code" );
  1202   assert( mh->check_code(), "" );
  1210   assert( mh->check_code(), "" );
  1203 
  1211 
  1204   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1212   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1205 
  1213 
  1931   }
  1939   }
  1932 #endif
  1940 #endif
  1933   Thread *thread = Thread::current();
  1941   Thread *thread = Thread::current();
  1934   *method->bcp_from(_bci) = Bytecodes::_breakpoint;
  1942   *method->bcp_from(_bci) = Bytecodes::_breakpoint;
  1935   method->incr_number_of_breakpoints(thread);
  1943   method->incr_number_of_breakpoints(thread);
  1936   SystemDictionary::notice_modification();
       
  1937   {
  1944   {
  1938     // Deoptimize all dependents on this method
  1945     // Deoptimize all dependents on this method
  1939     HandleMark hm(thread);
  1946     HandleMark hm(thread);
  1940     methodHandle mh(thread, method);
  1947     methodHandle mh(thread, method);
  1941     CodeCache::flush_dependents_on_method(mh);
  1948     CodeCache::flush_dependents_on_method(mh);
  2081     return count;
  2088     return count;
  2082   }
  2089   }
  2083 #endif // PRODUCT
  2090 #endif // PRODUCT
  2084 };
  2091 };
  2085 
  2092 
  2086 // Something that can't be mistaken for an address or a markOop
  2093 // Something that can't be mistaken for an address or a markWord
  2087 Method* const JNIMethodBlock::_free_method = (Method*)55;
  2094 Method* const JNIMethodBlock::_free_method = (Method*)55;
  2088 
  2095 
  2089 JNIMethodBlockNode::JNIMethodBlockNode(int num_methods) : _top(0), _next(NULL) {
  2096 JNIMethodBlockNode::JNIMethodBlockNode(int num_methods) : _top(0), _next(NULL) {
  2090   _number_of_methods = MAX2(num_methods, min_block_size);
  2097   _number_of_methods = MAX2(num_methods, min_block_size);
  2091   _methods = NEW_C_HEAP_ARRAY(Method*, _number_of_methods, mtInternal);
  2098   _methods = NEW_C_HEAP_ARRAY(Method*, _number_of_methods, mtInternal);