< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




 458   }
 459 
 460   if (HAS_PENDING_EXCEPTION) return;
 461 
 462   // If no exception has been thrown, we have validated the protection domain
 463   // Insert the protection domain of the initiating class into the set.
 464   {
 465     // We recalculate the entry here -- we've called out to java since
 466     // the last time it was calculated.
 467     ClassLoaderData* loader_data = class_loader_data(class_loader);
 468 
 469     Symbol*  kn = klass->name();
 470     unsigned int d_hash = dictionary()->compute_hash(kn, loader_data);
 471     int d_index = dictionary()->hash_to_index(d_hash);
 472 
 473     MutexLocker mu(SystemDictionary_lock, THREAD);
 474     {
 475       // Note that we have an entry, and entries can be deleted only during GC,
 476       // so we cannot allow GC to occur while we're holding this entry.
 477 
 478       // We're using a No_Safepoint_Verifier to catch any place where we
 479       // might potentially do a GC at all.
 480       // Dictionary::do_unloading() asserts that classes in SD are only
 481       // unloaded at a safepoint. Anonymous classes are not in SD.
 482       No_Safepoint_Verifier nosafepoint;
 483       dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data,
 484                                           protection_domain, THREAD);
 485     }
 486   }
 487 }
 488 
 489 // We only get here if this thread finds that another thread
 490 // has already claimed the placeholder token for the current operation,
 491 // but that other thread either never owned or gave up the
 492 // object lock
 493 // Waits on SystemDictionary_lock to indicate placeholder table updated
 494 // On return, caller must recheck placeholder table state
 495 //
 496 // We only get here if
 497 //  1) custom classLoader, i.e. not bootstrap classloader
 498 //  2) UnsyncloadClass not set
 499 //  3) custom classLoader has broken the class loader objectLock
 500 //     so another thread got here in parallel
 501 //
 502 // lockObject must be held.


 891 
 892   post_class_load_event(class_load_start_time, k, class_loader);
 893 
 894 #ifdef ASSERT
 895   {
 896     ClassLoaderData* loader_data = k->class_loader_data();
 897     MutexLocker mu(SystemDictionary_lock, THREAD);
 898     Klass* kk = find_class(name, loader_data);
 899     assert(kk == k(), "should be present in dictionary");
 900   }
 901 #endif
 902 
 903   // return if the protection domain in NULL
 904   if (protection_domain() == NULL) return k();
 905 
 906   // Check the protection domain has the right access
 907   {
 908     MutexLocker mu(SystemDictionary_lock, THREAD);
 909     // Note that we have an entry, and entries can be deleted only during GC,
 910     // so we cannot allow GC to occur while we're holding this entry.
 911     // We're using a No_Safepoint_Verifier to catch any place where we
 912     // might potentially do a GC at all.
 913     // Dictionary::do_unloading() asserts that classes in SD are only
 914     // unloaded at a safepoint. Anonymous classes are not in SD.
 915     No_Safepoint_Verifier nosafepoint;
 916     if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
 917                                                  loader_data,
 918                                                  protection_domain)) {
 919       return k();
 920     }
 921   }
 922 
 923   // Verify protection domain. If it fails an exception is thrown
 924   validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL);
 925 
 926   return k();
 927 }
 928 
 929 
 930 // This routine does not lock the system dictionary.
 931 //
 932 // Since readers don't hold a lock, we must make sure that system
 933 // dictionary entries are only removed at a safepoint (when only one
 934 // thread is running), and are added to in a safe way (all links must
 935 // be updated in an MT-safe manner).


 944                               TRAPS) {
 945 
 946   // The result of this call should be consistent with the result
 947   // of the call to resolve_instance_class_or_null().
 948   // See evaluation 6790209 and 4474172 for more details.
 949   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 950   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader());
 951 
 952   if (loader_data == NULL) {
 953     // If the ClassLoaderData has not been setup,
 954     // then the class loader has no entries in the dictionary.
 955     return NULL;
 956   }
 957 
 958   unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data);
 959   int d_index = dictionary()->hash_to_index(d_hash);
 960 
 961   {
 962     // Note that we have an entry, and entries can be deleted only during GC,
 963     // so we cannot allow GC to occur while we're holding this entry.
 964     // We're using a No_Safepoint_Verifier to catch any place where we
 965     // might potentially do a GC at all.
 966     // Dictionary::do_unloading() asserts that classes in SD are only
 967     // unloaded at a safepoint. Anonymous classes are not in SD.
 968     No_Safepoint_Verifier nosafepoint;
 969     return dictionary()->find(d_index, d_hash, class_name, loader_data,
 970                               protection_domain, THREAD);
 971   }
 972 }
 973 
 974 
 975 // Look for a loaded instance or array klass by name.  Do not do any loading.
 976 // return NULL in case of error.
 977 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
 978                                                       Handle class_loader,
 979                                                       Handle protection_domain,
 980                                                       TRAPS) {
 981   Klass* k = NULL;
 982   assert(class_name != NULL, "class name must be non NULL");
 983 
 984   if (FieldType::is_array(class_name)) {
 985     // The name refers to an array.  Parse the name.
 986     // dimension and object_key in FieldArrayInfo are assigned as a
 987     // side-effect of this call
 988     FieldArrayInfo fd;


2193     // For array classes, their Klass*s are not kept in the
2194     // constraint table. The element classes are.
2195     FieldArrayInfo fd;
2196     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
2197     // primitive types always pass
2198     if (t != T_OBJECT) {
2199       return true;
2200     } else {
2201       constraint_name = fd.object_key();
2202     }
2203   }
2204   unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1);
2205   int d_index1 = dictionary()->hash_to_index(d_hash1);
2206 
2207   unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2);
2208   int d_index2 = dictionary()->hash_to_index(d_hash2);
2209   {
2210   MutexLocker mu_s(SystemDictionary_lock, THREAD);
2211 
2212   // Better never do a GC while we're holding these oops
2213   No_Safepoint_Verifier nosafepoint;
2214 
2215   Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
2216   Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
2217   return constraints()->add_entry(constraint_name, klass1, class_loader1,
2218                                   klass2, class_loader2);
2219   }
2220 }
2221 
2222 // Add entry to resolution error table to record the error when the first
2223 // attempt to resolve a reference to a class has failed.
2224 void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int which,
2225                                             Symbol* error, Symbol* message) {
2226   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2227   int index = resolution_errors()->hash_to_index(hash);
2228   {
2229     MutexLocker ml(SystemDictionary_lock, Thread::current());
2230     resolution_errors()->add_entry(index, hash, pool, which, error, message);
2231   }
2232 }
2233 




 458   }
 459 
 460   if (HAS_PENDING_EXCEPTION) return;
 461 
 462   // If no exception has been thrown, we have validated the protection domain
 463   // Insert the protection domain of the initiating class into the set.
 464   {
 465     // We recalculate the entry here -- we've called out to java since
 466     // the last time it was calculated.
 467     ClassLoaderData* loader_data = class_loader_data(class_loader);
 468 
 469     Symbol*  kn = klass->name();
 470     unsigned int d_hash = dictionary()->compute_hash(kn, loader_data);
 471     int d_index = dictionary()->hash_to_index(d_hash);
 472 
 473     MutexLocker mu(SystemDictionary_lock, THREAD);
 474     {
 475       // Note that we have an entry, and entries can be deleted only during GC,
 476       // so we cannot allow GC to occur while we're holding this entry.
 477 
 478       // We're using a NoSafepointVerifier to catch any place where we
 479       // might potentially do a GC at all.
 480       // Dictionary::do_unloading() asserts that classes in SD are only
 481       // unloaded at a safepoint. Anonymous classes are not in SD.
 482       NoSafepointVerifier nosafepoint;
 483       dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data,
 484                                           protection_domain, THREAD);
 485     }
 486   }
 487 }
 488 
 489 // We only get here if this thread finds that another thread
 490 // has already claimed the placeholder token for the current operation,
 491 // but that other thread either never owned or gave up the
 492 // object lock
 493 // Waits on SystemDictionary_lock to indicate placeholder table updated
 494 // On return, caller must recheck placeholder table state
 495 //
 496 // We only get here if
 497 //  1) custom classLoader, i.e. not bootstrap classloader
 498 //  2) UnsyncloadClass not set
 499 //  3) custom classLoader has broken the class loader objectLock
 500 //     so another thread got here in parallel
 501 //
 502 // lockObject must be held.


 891 
 892   post_class_load_event(class_load_start_time, k, class_loader);
 893 
 894 #ifdef ASSERT
 895   {
 896     ClassLoaderData* loader_data = k->class_loader_data();
 897     MutexLocker mu(SystemDictionary_lock, THREAD);
 898     Klass* kk = find_class(name, loader_data);
 899     assert(kk == k(), "should be present in dictionary");
 900   }
 901 #endif
 902 
 903   // return if the protection domain in NULL
 904   if (protection_domain() == NULL) return k();
 905 
 906   // Check the protection domain has the right access
 907   {
 908     MutexLocker mu(SystemDictionary_lock, THREAD);
 909     // Note that we have an entry, and entries can be deleted only during GC,
 910     // so we cannot allow GC to occur while we're holding this entry.
 911     // We're using a NoSafepointVerifier to catch any place where we
 912     // might potentially do a GC at all.
 913     // Dictionary::do_unloading() asserts that classes in SD are only
 914     // unloaded at a safepoint. Anonymous classes are not in SD.
 915     NoSafepointVerifier nosafepoint;
 916     if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
 917                                                  loader_data,
 918                                                  protection_domain)) {
 919       return k();
 920     }
 921   }
 922 
 923   // Verify protection domain. If it fails an exception is thrown
 924   validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL);
 925 
 926   return k();
 927 }
 928 
 929 
 930 // This routine does not lock the system dictionary.
 931 //
 932 // Since readers don't hold a lock, we must make sure that system
 933 // dictionary entries are only removed at a safepoint (when only one
 934 // thread is running), and are added to in a safe way (all links must
 935 // be updated in an MT-safe manner).


 944                               TRAPS) {
 945 
 946   // The result of this call should be consistent with the result
 947   // of the call to resolve_instance_class_or_null().
 948   // See evaluation 6790209 and 4474172 for more details.
 949   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 950   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader());
 951 
 952   if (loader_data == NULL) {
 953     // If the ClassLoaderData has not been setup,
 954     // then the class loader has no entries in the dictionary.
 955     return NULL;
 956   }
 957 
 958   unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data);
 959   int d_index = dictionary()->hash_to_index(d_hash);
 960 
 961   {
 962     // Note that we have an entry, and entries can be deleted only during GC,
 963     // so we cannot allow GC to occur while we're holding this entry.
 964     // We're using a NoSafepointVerifier to catch any place where we
 965     // might potentially do a GC at all.
 966     // Dictionary::do_unloading() asserts that classes in SD are only
 967     // unloaded at a safepoint. Anonymous classes are not in SD.
 968     NoSafepointVerifier nosafepoint;
 969     return dictionary()->find(d_index, d_hash, class_name, loader_data,
 970                               protection_domain, THREAD);
 971   }
 972 }
 973 
 974 
 975 // Look for a loaded instance or array klass by name.  Do not do any loading.
 976 // return NULL in case of error.
 977 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
 978                                                       Handle class_loader,
 979                                                       Handle protection_domain,
 980                                                       TRAPS) {
 981   Klass* k = NULL;
 982   assert(class_name != NULL, "class name must be non NULL");
 983 
 984   if (FieldType::is_array(class_name)) {
 985     // The name refers to an array.  Parse the name.
 986     // dimension and object_key in FieldArrayInfo are assigned as a
 987     // side-effect of this call
 988     FieldArrayInfo fd;


2193     // For array classes, their Klass*s are not kept in the
2194     // constraint table. The element classes are.
2195     FieldArrayInfo fd;
2196     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
2197     // primitive types always pass
2198     if (t != T_OBJECT) {
2199       return true;
2200     } else {
2201       constraint_name = fd.object_key();
2202     }
2203   }
2204   unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1);
2205   int d_index1 = dictionary()->hash_to_index(d_hash1);
2206 
2207   unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2);
2208   int d_index2 = dictionary()->hash_to_index(d_hash2);
2209   {
2210   MutexLocker mu_s(SystemDictionary_lock, THREAD);
2211 
2212   // Better never do a GC while we're holding these oops
2213   NoSafepointVerifier nosafepoint;
2214 
2215   Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
2216   Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
2217   return constraints()->add_entry(constraint_name, klass1, class_loader1,
2218                                   klass2, class_loader2);
2219   }
2220 }
2221 
2222 // Add entry to resolution error table to record the error when the first
2223 // attempt to resolve a reference to a class has failed.
2224 void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int which,
2225                                             Symbol* error, Symbol* message) {
2226   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2227   int index = resolution_errors()->hash_to_index(hash);
2228   {
2229     MutexLocker ml(SystemDictionary_lock, Thread::current());
2230     resolution_errors()->add_entry(index, hash, pool, which, error, message);
2231   }
2232 }
2233 


< prev index next >