< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




  50 #include "interpreter/interpreter.hpp"
  51 #include "jfr/jfrEvents.hpp"
  52 #include "logging/log.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/filemap.hpp"
  55 #include "memory/heapShared.hpp"
  56 #include "memory/metaspaceClosure.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "oops/access.inline.hpp"
  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/instanceRefKlass.hpp"
  62 #include "oops/klass.inline.hpp"
  63 #include "oops/method.inline.hpp"
  64 #include "oops/methodData.hpp"
  65 #include "oops/objArrayKlass.hpp"
  66 #include "oops/objArrayOop.inline.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/symbol.hpp"
  69 #include "oops/typeArrayKlass.hpp"

  70 #include "prims/jvmtiExport.hpp"
  71 #include "prims/resolvedMethodTable.hpp"
  72 #include "prims/methodHandles.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/biasedLocking.hpp"
  75 #include "runtime/fieldType.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/java.hpp"
  78 #include "runtime/javaCalls.hpp"
  79 #include "runtime/mutexLocker.hpp"
  80 #include "runtime/orderAccess.hpp"

  81 #include "runtime/sharedRuntime.hpp"
  82 #include "runtime/signature.hpp"
  83 #include "services/classLoadingService.hpp"
  84 #include "services/diagnosticCommand.hpp"
  85 #include "services/threadService.hpp"
  86 #include "utilities/macros.hpp"
  87 #if INCLUDE_CDS
  88 #include "classfile/systemDictionaryShared.hpp"
  89 #endif
  90 #if INCLUDE_JVMCI
  91 #include "jvmci/jvmciRuntime.hpp"
  92 #endif
  93 #if INCLUDE_JFR
  94 #include "jfr/jfr.hpp"
  95 #endif
  96 
  97 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  98 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  99 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
 100 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;


 244   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 245 }
 246 
 247 
 248 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 249 
 250 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 251   if (FieldType::is_array(class_name)) {
 252     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 253   } else {
 254     return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
 255   }
 256 }
 257 
 258 // name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
 259 InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
 260                                                                        Handle class_loader,
 261                                                                        Handle protection_domain,
 262                                                                        TRAPS) {
 263   assert(class_name != NULL && !FieldType::is_array(class_name), "must be");
 264   if (FieldType::is_obj(class_name)) {
 265     ResourceMark rm(THREAD);
 266     // Ignore wrapping L and ;.
 267     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 268                                    class_name->utf8_length() - 2, CHECK_NULL);
 269     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 270   } else {
 271     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 272   }
 273 }
 274 
 275 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 276   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 277 }
 278 
 279 // Forwards to resolve_instance_class_or_null
 280 
 281 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 282                                                      Handle class_loader,
 283                                                      Handle protection_domain,
 284                                                      TRAPS) {
 285   assert(FieldType::is_array(class_name), "must be array");
 286   Klass* k = NULL;
 287   FieldArrayInfo fd;
 288   // dimension and object_key in FieldArrayInfo are assigned as a side-effect
 289   // of this call
 290   BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
 291   if (t == T_OBJECT) {
 292     // naked oop "k" is OK here -- we assign back into it
 293     k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
 294                                                          class_loader,
 295                                                          protection_domain,
 296                                                          CHECK_NULL);
 297     if (k != NULL) {
 298       k = k->array_klass(fd.dimension(), CHECK_NULL);
 299     }
 300   } else {
 301     k = Universe::typeArrayKlassObj(t);
 302     k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
 303   }
 304   return k;
 305 }
 306 
 307 
 308 // Must be called for any super-class or super-interface resolution
 309 // during class definition to allow class circularity checking
 310 // super-interface callers:
 311 //    parse_interfaces - for defineClass & jvmtiRedefineClasses
 312 // super-class callers:
 313 //   ClassFileParser - for defineClass & jvmtiRedefineClasses
 314 //   load_shared_class - while loading a class from shared archive
 315 //   resolve_instance_class_or_null:
 316 //     via: handle_parallel_super_load
 317 //      when resolving a class that has an existing placeholder with
 318 //      a saved superclass [i.e. a defineClass is currently in progress]
 319 //      if another thread is trying to resolve the class, it must do
 320 //      super-class checks on its own thread to catch class circularity
 321 // This last call is critical in class circularity checking for cases
 322 // where classloading is delegated to different threads and the
 323 // classloader lock is released.
 324 // Take the case: Base->Super->Base
 325 //   1. If thread T1 tries to do a defineClass of class Base
 326 //    resolve_super_or_fail creates placeholder: T1, Base (super Super)
 327 //   2. resolve_instance_class_or_null does not find SD or placeholder for Super


 431   // The instanceKlass is kept alive because the class loader is on the stack,
 432   // which keeps the loader_data alive, as well as all instanceKlasses in
 433   // the loader_data. parseClassFile adds the instanceKlass to loader_data.
 434   {
 435     MutexLocker mu(SystemDictionary_lock, THREAD);
 436     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 437     SystemDictionary_lock->notify_all();
 438   }
 439   if (HAS_PENDING_EXCEPTION || superk == NULL) {
 440     // can null superk
 441     Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
 442     assert(k == NULL || k == superk, "must be");
 443     if (k == NULL) {
 444       superk = NULL;
 445     }
 446   }
 447 
 448   return superk;
 449 }
 450 













































 451 void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
 452                                                   Handle class_loader,
 453                                                   Handle protection_domain,
 454                                                   TRAPS) {
 455   if(!has_checkPackageAccess()) return;
 456 
 457   // Now we have to call back to java to check if the initating class has access
 458   JavaValue result(T_VOID);
 459   LogTarget(Debug, protectiondomain) lt;
 460   if (lt.is_enabled()) {
 461     ResourceMark rm;
 462     // Print out trace information
 463     LogStream ls(lt);
 464     ls.print_cr("Checking package access");
 465     if (class_loader() != NULL) {
 466       ls.print("class loader: ");
 467       class_loader()->print_value_on(&ls);
 468     } else {
 469       ls.print_cr("class loader: NULL");
 470     }


 648   assert(k != NULL, "invariant");
 649   assert(event->should_commit(), "invariant");
 650   event->set_loadedClass(k);
 651   event->set_definingClassLoader(k->class_loader_data());
 652   event->set_initiatingClassLoader(init_cld);
 653   event->commit();
 654 }
 655 
 656 
 657 // Be careful when modifying this code: once you have run
 658 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
 659 // you need to find_and_remove it before returning.
 660 // So be careful to not exit with a CHECK_ macro betweeen these calls.
 661 //
 662 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
 663 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 664                                                                 Handle class_loader,
 665                                                                 Handle protection_domain,
 666                                                                 TRAPS) {
 667   assert(name != NULL && !FieldType::is_array(name) &&
 668          !FieldType::is_obj(name), "invalid class name");
 669 
 670   EventClassLoad class_load_start_event;
 671 
 672   HandleMark hm(THREAD);
 673 
 674   // Fix for 4474172; see evaluation for more details
 675   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 676   ClassLoaderData* loader_data = register_loader(class_loader);
 677   Dictionary* dictionary = loader_data->dictionary();
 678   unsigned int d_hash = dictionary->compute_hash(name);
 679 
 680   // Do lookup to see if class already exist and the protection domain
 681   // has the right access
 682   // This call uses find which checks protection domain already matches
 683   // All subsequent calls use find_class, and set has_loaded_class so that
 684   // before we return a result we call out to java to check for valid protection domain
 685   // to allow returning the Klass* and add it to the pd_set if it is valid
 686   {
 687     InstanceKlass* probe = dictionary->find(d_hash, name, protection_domain);
 688     if (probe != NULL) return probe;


 959   return dictionary->find(d_hash, class_name,
 960                           protection_domain);
 961 }
 962 
 963 
 964 // Look for a loaded instance or array klass by name.  Do not do any loading.
 965 // return NULL in case of error.
 966 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
 967                                                       Handle class_loader,
 968                                                       Handle protection_domain,
 969                                                       TRAPS) {
 970   Klass* k = NULL;
 971   assert(class_name != NULL, "class name must be non NULL");
 972 
 973   if (FieldType::is_array(class_name)) {
 974     // The name refers to an array.  Parse the name.
 975     // dimension and object_key in FieldArrayInfo are assigned as a
 976     // side-effect of this call
 977     FieldArrayInfo fd;
 978     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
 979     if (t != T_OBJECT) {
 980       k = Universe::typeArrayKlassObj(t);
 981     } else {
 982       k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
 983     }
 984     if (k != NULL) {
 985       k = k->array_klass_or_null(fd.dimension());
 986     }
 987   } else {
 988     k = find(class_name, class_loader, protection_domain, THREAD);
 989   }
 990   return k;
 991 }
 992 
 993 // Note: this method is much like resolve_from_stream, but
 994 // does not publish the classes via the SystemDictionary.
 995 // Handles unsafe_DefineAnonymousClass and redefineclasses
 996 // RedefinedClasses do not add to the class hierarchy
 997 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
 998                                               Handle class_loader,
 999                                               Handle protection_domain,


2148   ClassLoaderData *loader_data = class_loader_data(class_loader);
2149 
2150   {
2151     MutexLocker mu1(SystemDictionary_lock, THREAD);
2152 
2153     // See whether biased locking is enabled and if so set it for this
2154     // klass.
2155     // Note that this must be done past the last potential blocking
2156     // point / safepoint. We enable biased locking lazily using a
2157     // VM_Operation to iterate the SystemDictionary and installing the
2158     // biasable mark word into each InstanceKlass's prototype header.
2159     // To avoid race conditions where we accidentally miss enabling the
2160     // optimization for one class in the process of being added to the
2161     // dictionary, we must not safepoint after the test of
2162     // BiasedLocking::enabled().
2163     if (UseBiasedLocking && BiasedLocking::enabled()) {
2164       // Set biased locking bit for all loaded classes; it will be
2165       // cleared if revocation occurs too often for this type
2166       // NOTE that we must only do this when the class is initally
2167       // defined, not each time it is referenced from a new class loader
2168       if (oopDesc::equals(k->class_loader(), class_loader())) {
2169         k->set_prototype_header(markOopDesc::biased_locking_prototype());
2170       }
2171     }
2172 
2173     // Make a new dictionary entry.
2174     Dictionary* dictionary = loader_data->dictionary();
2175     InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
2176     if (sd_check == NULL) {
2177       dictionary->add_klass(d_hash, name, k);
2178 
2179       notice_modification();
2180     }
2181   #ifdef ASSERT
2182     sd_check = find_class(d_hash, name, dictionary);
2183     assert (sd_check != NULL, "should have entry in dictionary");
2184     // Note: there may be a placeholder entry: for circularity testing
2185     // or for parallel defines
2186   #endif
2187     SystemDictionary_lock->notify_all();
2188   }


2194 // yet and these will be ignored.
2195 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
2196                     Symbol* class_name, Handle class_loader, TRAPS) {
2197 
2198   // First see if it has been loaded directly.
2199   // Force the protection domain to be null.  (This removes protection checks.)
2200   Handle no_protection_domain;
2201   Klass* klass = find_instance_or_array_klass(class_name, class_loader,
2202                                               no_protection_domain, CHECK_NULL);
2203   if (klass != NULL)
2204     return klass;
2205 
2206   // Now look to see if it has been loaded elsewhere, and is subject to
2207   // a loader constraint that would require this loader to return the
2208   // klass that is already loaded.
2209   if (FieldType::is_array(class_name)) {
2210     // For array classes, their Klass*s are not kept in the
2211     // constraint table. The element Klass*s are.
2212     FieldArrayInfo fd;
2213     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
2214     if (t != T_OBJECT) {
2215       klass = Universe::typeArrayKlassObj(t);
2216     } else {
2217       MutexLocker mu(SystemDictionary_lock, THREAD);
2218       klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
2219     }
2220     // If element class already loaded, allocate array klass
2221     if (klass != NULL) {
2222       klass = klass->array_klass_or_null(fd.dimension());
2223     }
2224   } else {
2225     MutexLocker mu(SystemDictionary_lock, THREAD);
2226     // Non-array classes are easy: simply check the constraint table.
2227     klass = constraints()->find_constrained_klass(class_name, class_loader);
2228   }
2229 
2230   return klass;
2231 }
2232 
2233 
2234 bool SystemDictionary::add_loader_constraint(Symbol* class_name,


2534                                                    Handle protection_domain,
2535                                                    SignatureStream::FailureMode failure_mode,
2536                                                    TRAPS) {
2537   Handle empty;
2538 
2539   assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),
2540          "one or the other, or perhaps neither");
2541 
2542   Symbol* type = signature;
2543 
2544   // What we have here must be a valid field descriptor,
2545   // and all valid field descriptors are supported.
2546   // Produce the same java.lang.Class that reflection reports.
2547   if (type->utf8_length() == 1) {
2548 
2549     // It's a primitive.  (Void has a primitive mirror too.)
2550     char ch = type->char_at(0);
2551     assert(is_java_primitive(char2type(ch)) || ch == 'V', "");
2552     return Handle(THREAD, find_java_mirror_for_type(ch));
2553 
2554   } else if (FieldType::is_obj(type) || FieldType::is_array(type)) {
2555 
2556     // It's a reference type.
2557     if (accessing_klass != NULL) {
2558       class_loader      = Handle(THREAD, accessing_klass->class_loader());
2559       protection_domain = Handle(THREAD, accessing_klass->protection_domain());
2560     }
2561     Klass* constant_type_klass;
2562     if (failure_mode == SignatureStream::ReturnNull) {
2563       constant_type_klass = resolve_or_null(type, class_loader, protection_domain,
2564                                             CHECK_(empty));
2565     } else {
2566       bool throw_error = (failure_mode == SignatureStream::NCDFError);
2567       constant_type_klass = resolve_or_fail(type, class_loader, protection_domain,
2568                                             throw_error, CHECK_(empty));
2569     }
2570     if (constant_type_klass == NULL) {
2571       return Handle();  // report failure this way
2572     }
2573     Handle mirror(THREAD, constant_type_klass->java_mirror());
2574 




  50 #include "interpreter/interpreter.hpp"
  51 #include "jfr/jfrEvents.hpp"
  52 #include "logging/log.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/filemap.hpp"
  55 #include "memory/heapShared.hpp"
  56 #include "memory/metaspaceClosure.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "oops/access.inline.hpp"
  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/instanceRefKlass.hpp"
  62 #include "oops/klass.inline.hpp"
  63 #include "oops/method.inline.hpp"
  64 #include "oops/methodData.hpp"
  65 #include "oops/objArrayKlass.hpp"
  66 #include "oops/objArrayOop.inline.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/symbol.hpp"
  69 #include "oops/typeArrayKlass.hpp"
  70 #include "oops/valueKlass.hpp"
  71 #include "prims/jvmtiExport.hpp"
  72 #include "prims/resolvedMethodTable.hpp"
  73 #include "prims/methodHandles.hpp"
  74 #include "runtime/arguments.hpp"
  75 #include "runtime/biasedLocking.hpp"
  76 #include "runtime/fieldType.hpp"
  77 #include "runtime/handles.inline.hpp"
  78 #include "runtime/java.hpp"
  79 #include "runtime/javaCalls.hpp"
  80 #include "runtime/mutexLocker.hpp"
  81 #include "runtime/orderAccess.hpp"
  82 #include "runtime/os.hpp"
  83 #include "runtime/sharedRuntime.hpp"
  84 #include "runtime/signature.hpp"
  85 #include "services/classLoadingService.hpp"
  86 #include "services/diagnosticCommand.hpp"
  87 #include "services/threadService.hpp"
  88 #include "utilities/macros.hpp"
  89 #if INCLUDE_CDS
  90 #include "classfile/systemDictionaryShared.hpp"
  91 #endif
  92 #if INCLUDE_JVMCI
  93 #include "jvmci/jvmciRuntime.hpp"
  94 #endif
  95 #if INCLUDE_JFR
  96 #include "jfr/jfr.hpp"
  97 #endif
  98 
  99 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
 100 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
 101 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
 102 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;


 246   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 247 }
 248 
 249 
 250 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 251 
 252 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 253   if (FieldType::is_array(class_name)) {
 254     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 255   } else {
 256     return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
 257   }
 258 }
 259 
 260 // name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
 261 InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
 262                                                                        Handle class_loader,
 263                                                                        Handle protection_domain,
 264                                                                        TRAPS) {
 265   assert(class_name != NULL && !FieldType::is_array(class_name), "must be");
 266   if (FieldType::is_obj(class_name) || FieldType::is_valuetype(class_name)) {
 267     ResourceMark rm(THREAD);
 268     // Ignore wrapping L and ;. (and Q and ; for value types);
 269     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 270                                    class_name->utf8_length() - 2, CHECK_NULL);
 271     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 272   } else {
 273     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 274   }
 275 }
 276 
 277 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 278   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 279 }
 280 
 281 // Forwards to resolve_instance_class_or_null
 282 
 283 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 284                                                      Handle class_loader,
 285                                                      Handle protection_domain,
 286                                                      TRAPS) {
 287   assert(FieldType::is_array(class_name), "must be array");
 288   Klass* k = NULL;
 289   FieldArrayInfo fd;
 290   // dimension and object_key in FieldArrayInfo are assigned as a side-effect
 291   // of this call
 292   BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
 293   if (t == T_OBJECT  || t == T_VALUETYPE) {
 294     // naked oop "k" is OK here -- we assign back into it
 295     k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
 296                                                          class_loader,
 297                                                          protection_domain,
 298                                                          CHECK_NULL);
 299     if (k != NULL) {
 300       k = k->array_klass(fd.dimension(), CHECK_NULL);
 301     }
 302   } else {
 303     k = Universe::typeArrayKlassObj(t);
 304     k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
 305   }
 306   return k;
 307 }
 308 

 309 // Must be called for any super-class or super-interface resolution
 310 // during class definition to allow class circularity checking
 311 // super-interface callers:
 312 //    parse_interfaces - for defineClass & jvmtiRedefineClasses
 313 // super-class callers:
 314 //   ClassFileParser - for defineClass & jvmtiRedefineClasses
 315 //   load_shared_class - while loading a class from shared archive
 316 //   resolve_instance_class_or_null:
 317 //     via: handle_parallel_super_load
 318 //      when resolving a class that has an existing placeholder with
 319 //      a saved superclass [i.e. a defineClass is currently in progress]
 320 //      if another thread is trying to resolve the class, it must do
 321 //      super-class checks on its own thread to catch class circularity
 322 // This last call is critical in class circularity checking for cases
 323 // where classloading is delegated to different threads and the
 324 // classloader lock is released.
 325 // Take the case: Base->Super->Base
 326 //   1. If thread T1 tries to do a defineClass of class Base
 327 //    resolve_super_or_fail creates placeholder: T1, Base (super Super)
 328 //   2. resolve_instance_class_or_null does not find SD or placeholder for Super


 432   // The instanceKlass is kept alive because the class loader is on the stack,
 433   // which keeps the loader_data alive, as well as all instanceKlasses in
 434   // the loader_data. parseClassFile adds the instanceKlass to loader_data.
 435   {
 436     MutexLocker mu(SystemDictionary_lock, THREAD);
 437     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 438     SystemDictionary_lock->notify_all();
 439   }
 440   if (HAS_PENDING_EXCEPTION || superk == NULL) {
 441     // can null superk
 442     Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
 443     assert(k == NULL || k == superk, "must be");
 444     if (k == NULL) {
 445       superk = NULL;
 446     }
 447   }
 448 
 449   return superk;
 450 }
 451 
 452 Klass* SystemDictionary::resolve_flattenable_field_or_fail(AllFieldStream* fs,
 453                                                            Handle class_loader,
 454                                                            Handle protection_domain,
 455                                                            bool throw_error,
 456                                                            TRAPS) {
 457   Symbol* class_name = fs->signature()->fundamental_name(THREAD);
 458   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 459   ClassLoaderData* loader_data = class_loader_data(class_loader);
 460   unsigned int p_hash = placeholders()->compute_hash(class_name);
 461   int p_index = placeholders()->hash_to_index(p_hash);
 462   bool throw_circularity_error = false;
 463   PlaceholderEntry* oldprobe;
 464 
 465   {
 466     MutexLocker mu(SystemDictionary_lock, THREAD);
 467     oldprobe = placeholders()->get_entry(p_index, p_hash, class_name, loader_data);
 468     if (oldprobe != NULL &&
 469       oldprobe->check_seen_thread(THREAD, PlaceholderTable::FLATTENABLE_FIELD)) {
 470       throw_circularity_error = true;
 471 
 472     } else {
 473       placeholders()->find_and_add(p_index, p_hash, class_name, loader_data,
 474                                    PlaceholderTable::FLATTENABLE_FIELD, NULL, THREAD);
 475     }
 476   }
 477 
 478   Klass* klass = NULL;
 479   if (!throw_circularity_error) {
 480     klass = SystemDictionary::resolve_or_fail(class_name, class_loader,
 481                                                protection_domain, true, THREAD);
 482   } else {
 483     ResourceMark rm(THREAD);
 484     THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), class_name->as_C_string());
 485   }
 486 
 487   {
 488     MutexLocker mu(SystemDictionary_lock, THREAD);
 489     placeholders()->find_and_remove(p_index, p_hash, class_name, loader_data,
 490                                     PlaceholderTable::FLATTENABLE_FIELD, THREAD);
 491   }
 492 
 493   class_name->decrement_refcount();
 494   return klass;
 495 }
 496 
 497 void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
 498                                                   Handle class_loader,
 499                                                   Handle protection_domain,
 500                                                   TRAPS) {
 501   if(!has_checkPackageAccess()) return;
 502 
 503   // Now we have to call back to java to check if the initating class has access
 504   JavaValue result(T_VOID);
 505   LogTarget(Debug, protectiondomain) lt;
 506   if (lt.is_enabled()) {
 507     ResourceMark rm;
 508     // Print out trace information
 509     LogStream ls(lt);
 510     ls.print_cr("Checking package access");
 511     if (class_loader() != NULL) {
 512       ls.print("class loader: ");
 513       class_loader()->print_value_on(&ls);
 514     } else {
 515       ls.print_cr("class loader: NULL");
 516     }


 694   assert(k != NULL, "invariant");
 695   assert(event->should_commit(), "invariant");
 696   event->set_loadedClass(k);
 697   event->set_definingClassLoader(k->class_loader_data());
 698   event->set_initiatingClassLoader(init_cld);
 699   event->commit();
 700 }
 701 
 702 
 703 // Be careful when modifying this code: once you have run
 704 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
 705 // you need to find_and_remove it before returning.
 706 // So be careful to not exit with a CHECK_ macro betweeen these calls.
 707 //
 708 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
 709 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 710                                                                 Handle class_loader,
 711                                                                 Handle protection_domain,
 712                                                                 TRAPS) {
 713   assert(name != NULL && !FieldType::is_array(name) &&
 714          !FieldType::is_obj(name) && !FieldType::is_valuetype(name), "invalid class name");
 715 
 716   EventClassLoad class_load_start_event;
 717 
 718   HandleMark hm(THREAD);
 719 
 720   // Fix for 4474172; see evaluation for more details
 721   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 722   ClassLoaderData* loader_data = register_loader(class_loader);
 723   Dictionary* dictionary = loader_data->dictionary();
 724   unsigned int d_hash = dictionary->compute_hash(name);
 725 
 726   // Do lookup to see if class already exist and the protection domain
 727   // has the right access
 728   // This call uses find which checks protection domain already matches
 729   // All subsequent calls use find_class, and set has_loaded_class so that
 730   // before we return a result we call out to java to check for valid protection domain
 731   // to allow returning the Klass* and add it to the pd_set if it is valid
 732   {
 733     InstanceKlass* probe = dictionary->find(d_hash, name, protection_domain);
 734     if (probe != NULL) return probe;


1005   return dictionary->find(d_hash, class_name,
1006                           protection_domain);
1007 }
1008 
1009 
1010 // Look for a loaded instance or array klass by name.  Do not do any loading.
1011 // return NULL in case of error.
1012 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
1013                                                       Handle class_loader,
1014                                                       Handle protection_domain,
1015                                                       TRAPS) {
1016   Klass* k = NULL;
1017   assert(class_name != NULL, "class name must be non NULL");
1018 
1019   if (FieldType::is_array(class_name)) {
1020     // The name refers to an array.  Parse the name.
1021     // dimension and object_key in FieldArrayInfo are assigned as a
1022     // side-effect of this call
1023     FieldArrayInfo fd;
1024     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
1025     if (t != T_OBJECT  && t != T_VALUETYPE) {
1026       k = Universe::typeArrayKlassObj(t);
1027     } else {
1028       k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
1029     }
1030     if (k != NULL) {
1031       k = k->array_klass_or_null(fd.dimension());
1032     }
1033   } else {
1034     k = find(class_name, class_loader, protection_domain, THREAD);
1035   }
1036   return k;
1037 }
1038 
1039 // Note: this method is much like resolve_from_stream, but
1040 // does not publish the classes via the SystemDictionary.
1041 // Handles unsafe_DefineAnonymousClass and redefineclasses
1042 // RedefinedClasses do not add to the class hierarchy
1043 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
1044                                               Handle class_loader,
1045                                               Handle protection_domain,


2194   ClassLoaderData *loader_data = class_loader_data(class_loader);
2195 
2196   {
2197     MutexLocker mu1(SystemDictionary_lock, THREAD);
2198 
2199     // See whether biased locking is enabled and if so set it for this
2200     // klass.
2201     // Note that this must be done past the last potential blocking
2202     // point / safepoint. We enable biased locking lazily using a
2203     // VM_Operation to iterate the SystemDictionary and installing the
2204     // biasable mark word into each InstanceKlass's prototype header.
2205     // To avoid race conditions where we accidentally miss enabling the
2206     // optimization for one class in the process of being added to the
2207     // dictionary, we must not safepoint after the test of
2208     // BiasedLocking::enabled().
2209     if (UseBiasedLocking && BiasedLocking::enabled()) {
2210       // Set biased locking bit for all loaded classes; it will be
2211       // cleared if revocation occurs too often for this type
2212       // NOTE that we must only do this when the class is initally
2213       // defined, not each time it is referenced from a new class loader
2214       if (oopDesc::equals(k->class_loader(), class_loader()) && !k->is_value()) {
2215         k->set_prototype_header(markOopDesc::biased_locking_prototype());
2216       }
2217     }
2218 
2219     // Make a new dictionary entry.
2220     Dictionary* dictionary = loader_data->dictionary();
2221     InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
2222     if (sd_check == NULL) {
2223       dictionary->add_klass(d_hash, name, k);
2224 
2225       notice_modification();
2226     }
2227   #ifdef ASSERT
2228     sd_check = find_class(d_hash, name, dictionary);
2229     assert (sd_check != NULL, "should have entry in dictionary");
2230     // Note: there may be a placeholder entry: for circularity testing
2231     // or for parallel defines
2232   #endif
2233     SystemDictionary_lock->notify_all();
2234   }


2240 // yet and these will be ignored.
2241 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
2242                     Symbol* class_name, Handle class_loader, TRAPS) {
2243 
2244   // First see if it has been loaded directly.
2245   // Force the protection domain to be null.  (This removes protection checks.)
2246   Handle no_protection_domain;
2247   Klass* klass = find_instance_or_array_klass(class_name, class_loader,
2248                                               no_protection_domain, CHECK_NULL);
2249   if (klass != NULL)
2250     return klass;
2251 
2252   // Now look to see if it has been loaded elsewhere, and is subject to
2253   // a loader constraint that would require this loader to return the
2254   // klass that is already loaded.
2255   if (FieldType::is_array(class_name)) {
2256     // For array classes, their Klass*s are not kept in the
2257     // constraint table. The element Klass*s are.
2258     FieldArrayInfo fd;
2259     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
2260     if (t != T_OBJECT && t != T_VALUETYPE) {
2261       klass = Universe::typeArrayKlassObj(t);
2262     } else {
2263       MutexLocker mu(SystemDictionary_lock, THREAD);
2264       klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
2265     }
2266     // If element class already loaded, allocate array klass
2267     if (klass != NULL) {
2268       klass = klass->array_klass_or_null(fd.dimension());
2269     }
2270   } else {
2271     MutexLocker mu(SystemDictionary_lock, THREAD);
2272     // Non-array classes are easy: simply check the constraint table.
2273     klass = constraints()->find_constrained_klass(class_name, class_loader);
2274   }
2275 
2276   return klass;
2277 }
2278 
2279 
2280 bool SystemDictionary::add_loader_constraint(Symbol* class_name,


2580                                                    Handle protection_domain,
2581                                                    SignatureStream::FailureMode failure_mode,
2582                                                    TRAPS) {
2583   Handle empty;
2584 
2585   assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),
2586          "one or the other, or perhaps neither");
2587 
2588   Symbol* type = signature;
2589 
2590   // What we have here must be a valid field descriptor,
2591   // and all valid field descriptors are supported.
2592   // Produce the same java.lang.Class that reflection reports.
2593   if (type->utf8_length() == 1) {
2594 
2595     // It's a primitive.  (Void has a primitive mirror too.)
2596     char ch = type->char_at(0);
2597     assert(is_java_primitive(char2type(ch)) || ch == 'V', "");
2598     return Handle(THREAD, find_java_mirror_for_type(ch));
2599 
2600   } else if (FieldType::is_obj(type) || FieldType::is_valuetype(type) || FieldType::is_array(type)) {
2601 
2602     // It's a reference type.
2603     if (accessing_klass != NULL) {
2604       class_loader      = Handle(THREAD, accessing_klass->class_loader());
2605       protection_domain = Handle(THREAD, accessing_klass->protection_domain());
2606     }
2607     Klass* constant_type_klass;
2608     if (failure_mode == SignatureStream::ReturnNull) {
2609       constant_type_klass = resolve_or_null(type, class_loader, protection_domain,
2610                                             CHECK_(empty));
2611     } else {
2612       bool throw_error = (failure_mode == SignatureStream::NCDFError);
2613       constant_type_klass = resolve_or_fail(type, class_loader, protection_domain,
2614                                             throw_error, CHECK_(empty));
2615     }
2616     if (constant_type_klass == NULL) {
2617       return Handle();  // report failure this way
2618     }
2619     Handle mirror(THREAD, constant_type_klass->java_mirror());
2620 


< prev index next >