< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




  49 #include "oops/typeArrayKlass.hpp"
  50 #include "prims/jvmtiEnvBase.hpp"
  51 #include "prims/methodHandles.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/biasedLocking.hpp"
  54 #include "runtime/fieldType.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/java.hpp"
  57 #include "runtime/javaCalls.hpp"
  58 #include "runtime/mutexLocker.hpp"
  59 #include "runtime/orderAccess.inline.hpp"
  60 #include "runtime/signature.hpp"
  61 #include "services/classLoadingService.hpp"
  62 #include "services/threadService.hpp"
  63 #include "utilities/macros.hpp"
  64 #include "utilities/ticks.hpp"
  65 #if INCLUDE_CDS
  66 #include "classfile/sharedClassUtil.hpp"
  67 #include "classfile/systemDictionaryShared.hpp"
  68 #endif



  69 #if INCLUDE_TRACE
  70 #include "trace/tracing.hpp"
  71 #endif
  72 
  73 Dictionary*            SystemDictionary::_dictionary          = NULL;
  74 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  75 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
  76 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  77 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  78 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  79 
  80 
  81 int         SystemDictionary::_number_of_modifications = 0;
  82 int         SystemDictionary::_sdgeneration               = 0;
  83 const int   SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103,
  84               20201,40423,99991};
  85 
  86 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
  87 
  88 Klass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]


 211     if (throw_error) {
 212       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
 213     } else {
 214       THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
 215     }
 216   }
 217   return (Klass*)klass_h();
 218 }
 219 
 220 
 221 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
 222                                            bool throw_error, TRAPS)
 223 {
 224   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 225 }
 226 
 227 
 228 // Forwards to resolve_instance_class_or_null
 229 
 230 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 231   assert(!THREAD->is_Compiler_thread(),
 232          err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
 233                  class_name->as_C_string(),
 234                  class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
 235   if (FieldType::is_array(class_name)) {
 236     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 237   } else if (FieldType::is_obj(class_name)) {
 238     ResourceMark rm(THREAD);
 239     // Ignore wrapping L and ;.
 240     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 241                                    class_name->utf8_length() - 2, CHECK_NULL);
 242     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 243   } else {
 244     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 245   }
 246 }
 247 
 248 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 249   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 250 }
 251 


1900 
1901   // do a bunch more:
1902   initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
1903 
1904   // Preload ref klasses and set reference types
1905   InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
1906   InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
1907 
1908   initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
1909   InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
1910   InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
1911   InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
1912   InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
1913   InstanceKlass::cast(WK_KLASS(Cleaner_klass))->set_reference_type(REF_CLEANER);
1914 
1915   // JSR 292 classes
1916   WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
1917   WKID jsr292_group_end   = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
1918   initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
1919   initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
1920   initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
1921 
1922   _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
1923   _box_klasses[T_CHAR]    = WK_KLASS(Character_klass);
1924   _box_klasses[T_FLOAT]   = WK_KLASS(Float_klass);
1925   _box_klasses[T_DOUBLE]  = WK_KLASS(Double_klass);
1926   _box_klasses[T_BYTE]    = WK_KLASS(Byte_klass);
1927   _box_klasses[T_SHORT]   = WK_KLASS(Short_klass);
1928   _box_klasses[T_INT]     = WK_KLASS(Integer_klass);
1929   _box_klasses[T_LONG]    = WK_KLASS(Long_klass);
1930   //_box_klasses[T_OBJECT]  = WK_KLASS(object_klass);
1931   //_box_klasses[T_ARRAY]   = WK_KLASS(object_klass);
1932 
1933   { // Compute whether we should use loadClass or loadClassInternal when loading classes.
1934     Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
1935     _has_loadClassInternal = (method != NULL);
1936   }
1937   { // Compute whether we should use checkPackageAccess or NOT
1938     Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
1939     _has_checkPackageAccess = (method != NULL);
1940   }


2326       // the target is stored in the cpCache and if a reference to this
2327       // MethodName is dropped we need a way to make sure the
2328       // class_loader containing this method is kept alive.
2329       // FIXME: the appendix might also preserve this dependency.
2330       ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data();
2331       this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
2332       return methodHandle(THREAD, m);
2333     }
2334   }
2335   THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2336   return empty;
2337 }
2338 
2339 methodHandle SystemDictionary::find_method_handle_invoker(Symbol* name,
2340                                                           Symbol* signature,
2341                                                           KlassHandle accessing_klass,
2342                                                           Handle *appendix_result,
2343                                                           Handle *method_type_result,
2344                                                           TRAPS) {
2345   methodHandle empty;
2346   assert(!THREAD->is_Compiler_thread(), "");
2347   Handle method_type =
2348     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2349 
2350   KlassHandle  mh_klass = SystemDictionary::MethodHandle_klass();
2351   int ref_kind = JVM_REF_invokeVirtual;
2352   Handle name_str = StringTable::intern(name, CHECK_(empty));
2353   objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
2354   assert(appendix_box->obj_at(0) == NULL, "");
2355 
2356   // This should not happen.  JDK code should take care of that.
2357   if (accessing_klass.is_null() || method_type.is_null()) {
2358     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
2359   }
2360 
2361   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
2362   JavaCallArguments args;
2363   args.push_oop(accessing_klass()->java_mirror());
2364   args.push_int(ref_kind);
2365   args.push_oop(mh_klass()->java_mirror());
2366   args.push_oop(name_str());


2394   return klass->is_public() &&
2395          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2396           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2397 }
2398 
2399 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2400 // signature, as interpreted relative to the given class loader.
2401 // Because of class loader constraints, all method handle usage must be
2402 // consistent with this loader.
2403 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2404                                                  KlassHandle accessing_klass,
2405                                                  TRAPS) {
2406   Handle empty;
2407   vmIntrinsics::ID null_iid = vmIntrinsics::_none;  // distinct from all method handle invoker intrinsics
2408   unsigned int hash  = invoke_method_table()->compute_hash(signature, null_iid);
2409   int          index = invoke_method_table()->hash_to_index(hash);
2410   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2411   if (spe != NULL && spe->method_type() != NULL) {
2412     assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
2413     return Handle(THREAD, spe->method_type());
2414   } else if (THREAD->is_Compiler_thread()) {
2415     warning("SystemDictionary::find_method_handle_type called from compiler thread");  // FIXME
2416     return Handle();  // do not attempt from within compiler, unless it was cached
2417   }
2418 
2419   Handle class_loader, protection_domain;
2420   if (accessing_klass.not_null()) {
2421     class_loader      = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader());
2422     protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain());
2423   }
2424   bool can_be_cached = true;
2425   int npts = ArgumentCount(signature).size();
2426   objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
2427   int arg = 0;
2428   Handle rt; // the return type from the signature
2429   ResourceMark rm(THREAD);
2430   for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
2431     oop mirror = NULL;
2432     if (can_be_cached) {
2433       // Use neutral class loader to lookup candidate classes to be placed in the cache.
2434       mirror = ss.as_java_mirror(Handle(), Handle(),




  49 #include "oops/typeArrayKlass.hpp"
  50 #include "prims/jvmtiEnvBase.hpp"
  51 #include "prims/methodHandles.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/biasedLocking.hpp"
  54 #include "runtime/fieldType.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/java.hpp"
  57 #include "runtime/javaCalls.hpp"
  58 #include "runtime/mutexLocker.hpp"
  59 #include "runtime/orderAccess.inline.hpp"
  60 #include "runtime/signature.hpp"
  61 #include "services/classLoadingService.hpp"
  62 #include "services/threadService.hpp"
  63 #include "utilities/macros.hpp"
  64 #include "utilities/ticks.hpp"
  65 #if INCLUDE_CDS
  66 #include "classfile/sharedClassUtil.hpp"
  67 #include "classfile/systemDictionaryShared.hpp"
  68 #endif
  69 #if INCLUDE_JVMCI
  70 #include "jvmci/jvmciRuntime.hpp"
  71 #endif
  72 #if INCLUDE_TRACE
  73 #include "trace/tracing.hpp"
  74 #endif
  75 
  76 Dictionary*            SystemDictionary::_dictionary          = NULL;
  77 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  78 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
  79 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  80 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  81 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  82 
  83 
  84 int         SystemDictionary::_number_of_modifications = 0;
  85 int         SystemDictionary::_sdgeneration               = 0;
  86 const int   SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103,
  87               20201,40423,99991};
  88 
  89 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
  90 
  91 Klass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]


 214     if (throw_error) {
 215       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
 216     } else {
 217       THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
 218     }
 219   }
 220   return (Klass*)klass_h();
 221 }
 222 
 223 
 224 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
 225                                            bool throw_error, TRAPS)
 226 {
 227   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 228 }
 229 
 230 
 231 // Forwards to resolve_instance_class_or_null
 232 
 233 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 234   assert(THREAD->can_call_java(),
 235          err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
 236                  class_name->as_C_string(),
 237                  class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
 238   if (FieldType::is_array(class_name)) {
 239     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 240   } else if (FieldType::is_obj(class_name)) {
 241     ResourceMark rm(THREAD);
 242     // Ignore wrapping L and ;.
 243     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 244                                    class_name->utf8_length() - 2, CHECK_NULL);
 245     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 246   } else {
 247     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 248   }
 249 }
 250 
 251 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 252   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 253 }
 254 


1903 
1904   // do a bunch more:
1905   initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
1906 
1907   // Preload ref klasses and set reference types
1908   InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
1909   InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
1910 
1911   initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
1912   InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
1913   InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
1914   InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
1915   InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
1916   InstanceKlass::cast(WK_KLASS(Cleaner_klass))->set_reference_type(REF_CLEANER);
1917 
1918   // JSR 292 classes
1919   WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
1920   WKID jsr292_group_end   = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
1921   initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
1922   initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
1923   initialize_wk_klasses_until(NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID), scan, CHECK);
1924 
1925   _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
1926   _box_klasses[T_CHAR]    = WK_KLASS(Character_klass);
1927   _box_klasses[T_FLOAT]   = WK_KLASS(Float_klass);
1928   _box_klasses[T_DOUBLE]  = WK_KLASS(Double_klass);
1929   _box_klasses[T_BYTE]    = WK_KLASS(Byte_klass);
1930   _box_klasses[T_SHORT]   = WK_KLASS(Short_klass);
1931   _box_klasses[T_INT]     = WK_KLASS(Integer_klass);
1932   _box_klasses[T_LONG]    = WK_KLASS(Long_klass);
1933   //_box_klasses[T_OBJECT]  = WK_KLASS(object_klass);
1934   //_box_klasses[T_ARRAY]   = WK_KLASS(object_klass);
1935 
1936   { // Compute whether we should use loadClass or loadClassInternal when loading classes.
1937     Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
1938     _has_loadClassInternal = (method != NULL);
1939   }
1940   { // Compute whether we should use checkPackageAccess or NOT
1941     Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
1942     _has_checkPackageAccess = (method != NULL);
1943   }


2329       // the target is stored in the cpCache and if a reference to this
2330       // MethodName is dropped we need a way to make sure the
2331       // class_loader containing this method is kept alive.
2332       // FIXME: the appendix might also preserve this dependency.
2333       ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data();
2334       this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
2335       return methodHandle(THREAD, m);
2336     }
2337   }
2338   THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2339   return empty;
2340 }
2341 
2342 methodHandle SystemDictionary::find_method_handle_invoker(Symbol* name,
2343                                                           Symbol* signature,
2344                                                           KlassHandle accessing_klass,
2345                                                           Handle *appendix_result,
2346                                                           Handle *method_type_result,
2347                                                           TRAPS) {
2348   methodHandle empty;
2349   assert(THREAD->can_call_java() ,"");
2350   Handle method_type =
2351     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2352 
2353   KlassHandle  mh_klass = SystemDictionary::MethodHandle_klass();
2354   int ref_kind = JVM_REF_invokeVirtual;
2355   Handle name_str = StringTable::intern(name, CHECK_(empty));
2356   objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
2357   assert(appendix_box->obj_at(0) == NULL, "");
2358 
2359   // This should not happen.  JDK code should take care of that.
2360   if (accessing_klass.is_null() || method_type.is_null()) {
2361     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
2362   }
2363 
2364   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
2365   JavaCallArguments args;
2366   args.push_oop(accessing_klass()->java_mirror());
2367   args.push_int(ref_kind);
2368   args.push_oop(mh_klass()->java_mirror());
2369   args.push_oop(name_str());


2397   return klass->is_public() &&
2398          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2399           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2400 }
2401 
2402 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2403 // signature, as interpreted relative to the given class loader.
2404 // Because of class loader constraints, all method handle usage must be
2405 // consistent with this loader.
2406 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2407                                                  KlassHandle accessing_klass,
2408                                                  TRAPS) {
2409   Handle empty;
2410   vmIntrinsics::ID null_iid = vmIntrinsics::_none;  // distinct from all method handle invoker intrinsics
2411   unsigned int hash  = invoke_method_table()->compute_hash(signature, null_iid);
2412   int          index = invoke_method_table()->hash_to_index(hash);
2413   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2414   if (spe != NULL && spe->method_type() != NULL) {
2415     assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
2416     return Handle(THREAD, spe->method_type());
2417   } else if (!THREAD->can_call_java()) {
2418     warning("SystemDictionary::find_method_handle_type called from compiler thread");  // FIXME
2419     return Handle();  // do not attempt from within compiler, unless it was cached
2420   }
2421 
2422   Handle class_loader, protection_domain;
2423   if (accessing_klass.not_null()) {
2424     class_loader      = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader());
2425     protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain());
2426   }
2427   bool can_be_cached = true;
2428   int npts = ArgumentCount(signature).size();
2429   objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
2430   int arg = 0;
2431   Handle rt; // the return type from the signature
2432   ResourceMark rm(THREAD);
2433   for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
2434     oop mirror = NULL;
2435     if (can_be_cached) {
2436       // Use neutral class loader to lookup candidate classes to be placed in the cache.
2437       mirror = ss.as_java_mirror(Handle(), Handle(),


< prev index next >