< prev index next >

src/share/vm/oops/method.cpp

Print this page




 158   return dest;
 159 }
 160 
 161 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) {
 162   Symbol* klass_name = klass->name();
 163   klass_name->as_klass_external_name(buf, size);
 164   int len = (int)strlen(buf);
 165 
 166   if (len < size - 1) {
 167     buf[len++] = '.';
 168 
 169     method_name->as_C_string(&(buf[len]), size - len);
 170     len = (int)strlen(buf);
 171 
 172     signature->as_C_string(&(buf[len]), size - len);
 173   }
 174 
 175   return buf;
 176 }
 177 
 178 int Method::fast_exception_handler_bci_for(methodHandle mh, Klass* ex_klass, int throw_bci, TRAPS) {
 179   // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
 180   // access exception table
 181   ExceptionTable table(mh());
 182   int length = table.length();
 183   // iterate through all entries sequentially
 184   constantPoolHandle pool(THREAD, mh->constants());
 185   for (int i = 0; i < length; i ++) {
 186     //reacquire the table in case a GC happened
 187     ExceptionTable table(mh());
 188     int beg_bci = table.start_pc(i);
 189     int end_bci = table.end_pc(i);
 190     assert(beg_bci <= end_bci, "inconsistent exception table");
 191     if (beg_bci <= throw_bci && throw_bci < end_bci) {
 192       // exception handler bci range covers throw_bci => investigate further
 193       int handler_bci = table.handler_pc(i);
 194       int klass_index = table.catch_type_index(i);
 195       if (klass_index == 0) {
 196         return handler_bci;
 197       } else if (ex_klass == NULL) {
 198         return handler_bci;


1061   if (is_native() && !has_native_function()) {
1062     set_native_function(
1063       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
1064       !native_bind_event_is_interesting);
1065   }
1066 
1067   // Setup compiler entrypoint.  This is made eagerly, so we do not need
1068   // special handling of vtables.  An alternative is to make adapters more
1069   // lazily by calling make_adapter() from from_compiled_entry() for the
1070   // normal calls.  For vtable calls life gets more complicated.  When a
1071   // call-site goes mega-morphic we need adapters in all methods which can be
1072   // called from the vtable.  We need adapters on such methods that get loaded
1073   // later.  Ditto for mega-morphic itable calls.  If this proves to be a
1074   // problem we'll make these lazily later.
1075   (void) make_adapters(h_method, CHECK);
1076 
1077   // ONLY USE the h_method now as make_adapter may have blocked
1078 
1079 }
1080 
1081 address Method::make_adapters(methodHandle mh, TRAPS) {
1082   // Adapters for compiled code are made eagerly here.  They are fairly
1083   // small (generally < 100 bytes) and quick to make (and cached and shared)
1084   // so making them eagerly shouldn't be too expensive.
1085   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1086   if (adapter == NULL ) {
1087     if (!is_init_completed()) {
1088       // Don't throw exceptions during VM initialization because java.lang.* classes
1089       // might not have been initialized, causing problems when constructing the
1090       // Java exception object.
1091       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1092     } else {
1093       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1094     }
1095   }
1096 
1097   if (mh->is_shared()) {
1098     assert(mh->adapter() == adapter, "must be");
1099     assert(mh->_from_compiled_entry != NULL, "must be");
1100   } else {
1101     mh->set_adapter_entry(adapter);


1130 // It returns the compiled code entry point, after asserting not null.
1131 // This function is called after potential safepoints so that nmethod
1132 // or adapter that it points to is still live and valid.
1133 // This function must not hit a safepoint!
1134 address Method::verified_code_entry() {
1135   debug_only(NoSafepointVerifier nsv;)
1136   assert(_from_compiled_entry != NULL, "must be set");
1137   return _from_compiled_entry;
1138 }
1139 
1140 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1141 // (could be racing a deopt).
1142 // Not inline to avoid circular ref.
1143 bool Method::check_code() const {
1144   // cached in a register or local.  There's a race on the value of the field.
1145   CompiledMethod *code = (CompiledMethod *)OrderAccess::load_ptr_acquire(&_code);
1146   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1147 }
1148 
1149 // Install compiled code.  Instantly it can execute.
1150 void Method::set_code(methodHandle mh, CompiledMethod *code) {
1151   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1152   assert( code, "use clear_code to remove code" );
1153   assert( mh->check_code(), "" );
1154 
1155   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1156 
1157   // These writes must happen in this order, because the interpreter will
1158   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1159   // which jumps to _from_compiled_entry.
1160   mh->_code = code;             // Assign before allowing compiled code to exec
1161 
1162   int comp_level = code->comp_level();
1163   // In theory there could be a race here. In practice it is unlikely
1164   // and not worth worrying about.
1165   if (comp_level > mh->highest_comp_level()) {
1166     mh->set_highest_comp_level(comp_level);
1167   }
1168 
1169   OrderAccess::storestore();
1170 #ifdef SHARK


1333   m->link_method(m, CHECK_(empty));
1334 
1335   if (TraceMethodHandles && (Verbose || WizardMode)) {
1336     ttyLocker ttyl;
1337     m->print_on(tty);
1338   }
1339 
1340   return m;
1341 }
1342 
1343 Klass* Method::check_non_bcp_klass(Klass* klass) {
1344   if (klass != NULL && klass->class_loader() != NULL) {
1345     if (klass->is_objArray_klass())
1346       klass = ObjArrayKlass::cast(klass)->bottom_klass();
1347     return klass;
1348   }
1349   return NULL;
1350 }
1351 
1352 
1353 methodHandle Method::clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length,
1354                                                 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) {
1355   // Code below does not work for native methods - they should never get rewritten anyway
1356   assert(!m->is_native(), "cannot rewrite native methods");
1357   // Allocate new Method*
1358   AccessFlags flags = m->access_flags();
1359 
1360   ConstMethod* cm = m->constMethod();
1361   int checked_exceptions_len = cm->checked_exceptions_length();
1362   int localvariable_len = cm->localvariable_table_length();
1363   int exception_table_len = cm->exception_table_length();
1364   int method_parameters_len = cm->method_parameters_length();
1365   int method_annotations_len = cm->method_annotations_length();
1366   int parameter_annotations_len = cm->parameter_annotations_length();
1367   int type_annotations_len = cm->type_annotations_length();
1368   int default_annotations_len = cm->default_annotations_length();
1369 
1370   InlineTableSizes sizes(
1371       localvariable_len,
1372       new_compressed_linenumber_size,
1373       exception_table_len,


1528   case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle):
1529   case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_VarHandle):
1530     if (!is_native())  break;
1531     id = MethodHandles::signature_polymorphic_name_id(method_holder(), name());
1532     if (is_static() != MethodHandles::is_signature_polymorphic_static(id))
1533       id = vmIntrinsics::_none;
1534     break;
1535 
1536   default:
1537     break;
1538   }
1539 
1540   if (id != vmIntrinsics::_none) {
1541     // Set up its iid.  It is an alias method.
1542     set_intrinsic_id(id);
1543     return;
1544   }
1545 }
1546 
1547 // These two methods are static since a GC may move the Method
1548 bool Method::load_signature_classes(methodHandle m, TRAPS) {
1549   if (!THREAD->can_call_java()) {
1550     // There is nothing useful this routine can do from within the Compile thread.
1551     // Hopefully, the signature contains only well-known classes.
1552     // We could scan for this and return true/false, but the caller won't care.
1553     return false;
1554   }
1555   bool sig_is_loaded = true;
1556   Handle class_loader(THREAD, m->method_holder()->class_loader());
1557   Handle protection_domain(THREAD, m->method_holder()->protection_domain());
1558   ResourceMark rm(THREAD);
1559   Symbol*  signature = m->signature();
1560   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
1561     if (ss.is_object()) {
1562       Symbol* sym = ss.as_symbol(CHECK_(false));
1563       Symbol*  name  = sym;
1564       Klass* klass = SystemDictionary::resolve_or_null(name, class_loader,
1565                                              protection_domain, THREAD);
1566       // We are loading classes eagerly. If a ClassNotFoundException or
1567       // a LinkageError was generated, be sure to ignore it.
1568       if (HAS_PENDING_EXCEPTION) {
1569         if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) ||
1570             PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1571           CLEAR_PENDING_EXCEPTION;
1572         } else {
1573           return false;
1574         }
1575       }
1576       if( klass == NULL) { sig_is_loaded = false; }
1577     }
1578   }
1579   return sig_is_loaded;
1580 }
1581 
1582 bool Method::has_unloaded_classes_in_signature(methodHandle m, TRAPS) {
1583   Handle class_loader(THREAD, m->method_holder()->class_loader());
1584   Handle protection_domain(THREAD, m->method_holder()->protection_domain());
1585   ResourceMark rm(THREAD);
1586   Symbol*  signature = m->signature();
1587   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
1588     if (ss.type() == T_OBJECT) {
1589       Symbol* name = ss.as_symbol_or_null();
1590       if (name == NULL) return true;
1591       Klass* klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD);
1592       if (klass == NULL) return true;
1593     }
1594   }
1595   return false;
1596 }
1597 
1598 // Exposed so field engineers can debug VM
1599 void Method::print_short_name(outputStream* st) {
1600   ResourceMark rm;
1601 #ifdef PRODUCT
1602   st->print(" %s::", method_holder()->external_name());




 158   return dest;
 159 }
 160 
 161 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) {
 162   Symbol* klass_name = klass->name();
 163   klass_name->as_klass_external_name(buf, size);
 164   int len = (int)strlen(buf);
 165 
 166   if (len < size - 1) {
 167     buf[len++] = '.';
 168 
 169     method_name->as_C_string(&(buf[len]), size - len);
 170     len = (int)strlen(buf);
 171 
 172     signature->as_C_string(&(buf[len]), size - len);
 173   }
 174 
 175   return buf;
 176 }
 177 
 178 int Method::fast_exception_handler_bci_for(const methodHandle& mh, Klass* ex_klass, int throw_bci, TRAPS) {
 179   // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
 180   // access exception table
 181   ExceptionTable table(mh());
 182   int length = table.length();
 183   // iterate through all entries sequentially
 184   constantPoolHandle pool(THREAD, mh->constants());
 185   for (int i = 0; i < length; i ++) {
 186     //reacquire the table in case a GC happened
 187     ExceptionTable table(mh());
 188     int beg_bci = table.start_pc(i);
 189     int end_bci = table.end_pc(i);
 190     assert(beg_bci <= end_bci, "inconsistent exception table");
 191     if (beg_bci <= throw_bci && throw_bci < end_bci) {
 192       // exception handler bci range covers throw_bci => investigate further
 193       int handler_bci = table.handler_pc(i);
 194       int klass_index = table.catch_type_index(i);
 195       if (klass_index == 0) {
 196         return handler_bci;
 197       } else if (ex_klass == NULL) {
 198         return handler_bci;


1061   if (is_native() && !has_native_function()) {
1062     set_native_function(
1063       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
1064       !native_bind_event_is_interesting);
1065   }
1066 
1067   // Setup compiler entrypoint.  This is made eagerly, so we do not need
1068   // special handling of vtables.  An alternative is to make adapters more
1069   // lazily by calling make_adapter() from from_compiled_entry() for the
1070   // normal calls.  For vtable calls life gets more complicated.  When a
1071   // call-site goes mega-morphic we need adapters in all methods which can be
1072   // called from the vtable.  We need adapters on such methods that get loaded
1073   // later.  Ditto for mega-morphic itable calls.  If this proves to be a
1074   // problem we'll make these lazily later.
1075   (void) make_adapters(h_method, CHECK);
1076 
1077   // ONLY USE the h_method now as make_adapter may have blocked
1078 
1079 }
1080 
1081 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1082   // Adapters for compiled code are made eagerly here.  They are fairly
1083   // small (generally < 100 bytes) and quick to make (and cached and shared)
1084   // so making them eagerly shouldn't be too expensive.
1085   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1086   if (adapter == NULL ) {
1087     if (!is_init_completed()) {
1088       // Don't throw exceptions during VM initialization because java.lang.* classes
1089       // might not have been initialized, causing problems when constructing the
1090       // Java exception object.
1091       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1092     } else {
1093       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1094     }
1095   }
1096 
1097   if (mh->is_shared()) {
1098     assert(mh->adapter() == adapter, "must be");
1099     assert(mh->_from_compiled_entry != NULL, "must be");
1100   } else {
1101     mh->set_adapter_entry(adapter);


1130 // It returns the compiled code entry point, after asserting not null.
1131 // This function is called after potential safepoints so that nmethod
1132 // or adapter that it points to is still live and valid.
1133 // This function must not hit a safepoint!
1134 address Method::verified_code_entry() {
1135   debug_only(NoSafepointVerifier nsv;)
1136   assert(_from_compiled_entry != NULL, "must be set");
1137   return _from_compiled_entry;
1138 }
1139 
1140 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1141 // (could be racing a deopt).
1142 // Not inline to avoid circular ref.
1143 bool Method::check_code() const {
1144   // cached in a register or local.  There's a race on the value of the field.
1145   CompiledMethod *code = (CompiledMethod *)OrderAccess::load_ptr_acquire(&_code);
1146   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1147 }
1148 
1149 // Install compiled code.  Instantly it can execute.
1150 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1151   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1152   assert( code, "use clear_code to remove code" );
1153   assert( mh->check_code(), "" );
1154 
1155   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1156 
1157   // These writes must happen in this order, because the interpreter will
1158   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1159   // which jumps to _from_compiled_entry.
1160   mh->_code = code;             // Assign before allowing compiled code to exec
1161 
1162   int comp_level = code->comp_level();
1163   // In theory there could be a race here. In practice it is unlikely
1164   // and not worth worrying about.
1165   if (comp_level > mh->highest_comp_level()) {
1166     mh->set_highest_comp_level(comp_level);
1167   }
1168 
1169   OrderAccess::storestore();
1170 #ifdef SHARK


1333   m->link_method(m, CHECK_(empty));
1334 
1335   if (TraceMethodHandles && (Verbose || WizardMode)) {
1336     ttyLocker ttyl;
1337     m->print_on(tty);
1338   }
1339 
1340   return m;
1341 }
1342 
1343 Klass* Method::check_non_bcp_klass(Klass* klass) {
1344   if (klass != NULL && klass->class_loader() != NULL) {
1345     if (klass->is_objArray_klass())
1346       klass = ObjArrayKlass::cast(klass)->bottom_klass();
1347     return klass;
1348   }
1349   return NULL;
1350 }
1351 
1352 
1353 methodHandle Method::clone_with_new_data(const methodHandle& m, u_char* new_code, int new_code_length,
1354                                                 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) {
1355   // Code below does not work for native methods - they should never get rewritten anyway
1356   assert(!m->is_native(), "cannot rewrite native methods");
1357   // Allocate new Method*
1358   AccessFlags flags = m->access_flags();
1359 
1360   ConstMethod* cm = m->constMethod();
1361   int checked_exceptions_len = cm->checked_exceptions_length();
1362   int localvariable_len = cm->localvariable_table_length();
1363   int exception_table_len = cm->exception_table_length();
1364   int method_parameters_len = cm->method_parameters_length();
1365   int method_annotations_len = cm->method_annotations_length();
1366   int parameter_annotations_len = cm->parameter_annotations_length();
1367   int type_annotations_len = cm->type_annotations_length();
1368   int default_annotations_len = cm->default_annotations_length();
1369 
1370   InlineTableSizes sizes(
1371       localvariable_len,
1372       new_compressed_linenumber_size,
1373       exception_table_len,


1528   case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle):
1529   case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_VarHandle):
1530     if (!is_native())  break;
1531     id = MethodHandles::signature_polymorphic_name_id(method_holder(), name());
1532     if (is_static() != MethodHandles::is_signature_polymorphic_static(id))
1533       id = vmIntrinsics::_none;
1534     break;
1535 
1536   default:
1537     break;
1538   }
1539 
1540   if (id != vmIntrinsics::_none) {
1541     // Set up its iid.  It is an alias method.
1542     set_intrinsic_id(id);
1543     return;
1544   }
1545 }
1546 
1547 // These two methods are static since a GC may move the Method
1548 bool Method::load_signature_classes(const methodHandle& m, TRAPS) {
1549   if (!THREAD->can_call_java()) {
1550     // There is nothing useful this routine can do from within the Compile thread.
1551     // Hopefully, the signature contains only well-known classes.
1552     // We could scan for this and return true/false, but the caller won't care.
1553     return false;
1554   }
1555   bool sig_is_loaded = true;
1556   Handle class_loader(THREAD, m->method_holder()->class_loader());
1557   Handle protection_domain(THREAD, m->method_holder()->protection_domain());
1558   ResourceMark rm(THREAD);
1559   Symbol*  signature = m->signature();
1560   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
1561     if (ss.is_object()) {
1562       Symbol* sym = ss.as_symbol(CHECK_(false));
1563       Symbol*  name  = sym;
1564       Klass* klass = SystemDictionary::resolve_or_null(name, class_loader,
1565                                              protection_domain, THREAD);
1566       // We are loading classes eagerly. If a ClassNotFoundException or
1567       // a LinkageError was generated, be sure to ignore it.
1568       if (HAS_PENDING_EXCEPTION) {
1569         if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) ||
1570             PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1571           CLEAR_PENDING_EXCEPTION;
1572         } else {
1573           return false;
1574         }
1575       }
1576       if( klass == NULL) { sig_is_loaded = false; }
1577     }
1578   }
1579   return sig_is_loaded;
1580 }
1581 
1582 bool Method::has_unloaded_classes_in_signature(const methodHandle& m, TRAPS) {
1583   Handle class_loader(THREAD, m->method_holder()->class_loader());
1584   Handle protection_domain(THREAD, m->method_holder()->protection_domain());
1585   ResourceMark rm(THREAD);
1586   Symbol*  signature = m->signature();
1587   for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
1588     if (ss.type() == T_OBJECT) {
1589       Symbol* name = ss.as_symbol_or_null();
1590       if (name == NULL) return true;
1591       Klass* klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD);
1592       if (klass == NULL) return true;
1593     }
1594   }
1595   return false;
1596 }
1597 
1598 // Exposed so field engineers can debug VM
1599 void Method::print_short_name(outputStream* st) {
1600   ResourceMark rm;
1601 #ifdef PRODUCT
1602   st->print(" %s::", method_holder()->external_name());


< prev index next >