20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 # include "incls/_precompiled.incl"
26 # include "incls/_systemDictionary.cpp.incl"
27
28
29 Dictionary* SystemDictionary::_dictionary = NULL;
30 PlaceholderTable* SystemDictionary::_placeholders = NULL;
31 Dictionary* SystemDictionary::_shared_dictionary = NULL;
32 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
33 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
34
35
36 int SystemDictionary::_number_of_modifications = 0;
37
38 oop SystemDictionary::_system_loader_lock_obj = NULL;
39
40 klassOop SystemDictionary::_object_klass = NULL;
41 klassOop SystemDictionary::_string_klass = NULL;
42 klassOop SystemDictionary::_class_klass = NULL;
43 klassOop SystemDictionary::_cloneable_klass = NULL;
44 klassOop SystemDictionary::_classloader_klass = NULL;
45 klassOop SystemDictionary::_serializable_klass = NULL;
46 klassOop SystemDictionary::_system_klass = NULL;
47
48 klassOop SystemDictionary::_throwable_klass = NULL;
49 klassOop SystemDictionary::_error_klass = NULL;
50 klassOop SystemDictionary::_threaddeath_klass = NULL;
51 klassOop SystemDictionary::_exception_klass = NULL;
52 klassOop SystemDictionary::_runtime_exception_klass = NULL;
53 klassOop SystemDictionary::_classNotFoundException_klass = NULL;
54 klassOop SystemDictionary::_noClassDefFoundError_klass = NULL;
55 klassOop SystemDictionary::_linkageError_klass = NULL;
56 klassOop SystemDictionary::_classCastException_klass = NULL;
57 klassOop SystemDictionary::_arrayStoreException_klass = NULL;
58 klassOop SystemDictionary::_virtualMachineError_klass = NULL;
59 klassOop SystemDictionary::_outOfMemoryError_klass = NULL;
60 klassOop SystemDictionary::_StackOverflowError_klass = NULL;
61 klassOop SystemDictionary::_illegalMonitorStateException_klass = NULL;
62 klassOop SystemDictionary::_protectionDomain_klass = NULL;
63 klassOop SystemDictionary::_AccessControlContext_klass = NULL;
64
65 klassOop SystemDictionary::_reference_klass = NULL;
66 klassOop SystemDictionary::_soft_reference_klass = NULL;
67 klassOop SystemDictionary::_weak_reference_klass = NULL;
68 klassOop SystemDictionary::_final_reference_klass = NULL;
69 klassOop SystemDictionary::_phantom_reference_klass = NULL;
70 klassOop SystemDictionary::_finalizer_klass = NULL;
71
72 klassOop SystemDictionary::_thread_klass = NULL;
73 klassOop SystemDictionary::_threadGroup_klass = NULL;
74 klassOop SystemDictionary::_properties_klass = NULL;
75 klassOop SystemDictionary::_reflect_accessible_object_klass = NULL;
76 klassOop SystemDictionary::_reflect_field_klass = NULL;
77 klassOop SystemDictionary::_reflect_method_klass = NULL;
78 klassOop SystemDictionary::_reflect_constructor_klass = NULL;
79 klassOop SystemDictionary::_reflect_magic_klass = NULL;
80 klassOop SystemDictionary::_reflect_method_accessor_klass = NULL;
81 klassOop SystemDictionary::_reflect_constructor_accessor_klass = NULL;
82 klassOop SystemDictionary::_reflect_delegating_classloader_klass = NULL;
83 klassOop SystemDictionary::_reflect_constant_pool_klass = NULL;
84 klassOop SystemDictionary::_reflect_unsafe_static_field_accessor_impl_klass = NULL;
85
86 klassOop SystemDictionary::_vector_klass = NULL;
87 klassOop SystemDictionary::_hashtable_klass = NULL;
88 klassOop SystemDictionary::_stringBuffer_klass = NULL;
89
90 klassOop SystemDictionary::_stackTraceElement_klass = NULL;
91
92 klassOop SystemDictionary::_java_nio_Buffer_klass = NULL;
93
94 klassOop SystemDictionary::_sun_misc_AtomicLongCSImpl_klass = NULL;
95 klassOop SystemDictionary::_sun_jkernel_DownloadManager_klass = NULL;
96
97 klassOop SystemDictionary::_boolean_klass = NULL;
98 klassOop SystemDictionary::_char_klass = NULL;
99 klassOop SystemDictionary::_float_klass = NULL;
100 klassOop SystemDictionary::_double_klass = NULL;
101 klassOop SystemDictionary::_byte_klass = NULL;
102 klassOop SystemDictionary::_short_klass = NULL;
103 klassOop SystemDictionary::_int_klass = NULL;
104 klassOop SystemDictionary::_long_klass = NULL;
105 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
106
107 oop SystemDictionary::_java_system_loader = NULL;
108
109 bool SystemDictionary::_has_loadClassInternal = false;
110 bool SystemDictionary::_has_checkPackageAccess = false;
111
112 // lazily initialized klass variables
113 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
114
115
116 // ----------------------------------------------------------------------------
117 // Java-level SystemLoader
118
119 oop SystemDictionary::java_system_loader() {
120 return _java_system_loader;
121 }
122
123 void SystemDictionary::compute_java_system_loader(TRAPS) {
124 KlassHandle system_klass(THREAD, _classloader_klass);
125 JavaValue result(T_OBJECT);
126 JavaCalls::call_static(&result,
127 KlassHandle(THREAD, _classloader_klass),
128 vmSymbolHandles::getSystemClassLoader_name(),
129 vmSymbolHandles::void_classloader_signature(),
130 CHECK);
131
132 _java_system_loader = (oop)result.get_jobject();
133 }
134
135
136 // ----------------------------------------------------------------------------
137 // debugging
138
139 #ifdef ASSERT
140
141 // return true if class_name contains no '.' (internal format is '/')
142 bool SystemDictionary::is_internal_format(symbolHandle class_name) {
143 if (class_name.not_null()) {
144 ResourceMark rm;
145 char* name = class_name->as_C_string();
146 return strchr(name, '.') == NULL;
147 } else {
275 // loadClassFromxxx or defineClass via parseClassFile Super ...
276 // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base)
277 // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base
278 // 3.4 calls resolve_super_or_fail Base
279 // 3.5 finds T1,Base -> throws class circularity
280 //OR 4. If T2 tries to resolve Super via defineClass Super ...
281 // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base)
282 // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super)
283 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2
284 // 4.4 finds T2, Super -> throws class circularity
285 // Must be called, even if superclass is null, since this is
286 // where the placeholder entry is created which claims this
287 // thread is loading this class/classloader.
288 klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name,
289 symbolHandle class_name,
290 Handle class_loader,
291 Handle protection_domain,
292 bool is_superclass,
293 TRAPS) {
294
295 // Double-check, if child class is already loaded, just return super-class,interface
296 // Don't add a placedholder if already loaded, i.e. already in system dictionary
297 // Make sure there's a placeholder for the *child* before resolving.
298 // Used as a claim that this thread is currently loading superclass/classloader
299 // Used here for ClassCircularity checks and also for heap verification
300 // (every instanceKlass in the heap needs to be in the system dictionary
301 // or have a placeholder).
302 // Must check ClassCircularity before checking if super class is already loaded
303 //
304 // We might not already have a placeholder if this child_name was
305 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass);
306 // the name of the class might not be known until the stream is actually
307 // parsed.
308 // Bugs 4643874, 4715493
309 // compute_hash can have a safepoint
310
311 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader);
312 int d_index = dictionary()->hash_to_index(d_hash);
313 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader);
314 int p_index = placeholders()->hash_to_index(p_hash);
902 // so we cannot allow GC to occur while we're holding this entry.
903 // We're using a No_Safepoint_Verifier to catch any place where we
904 // might potentially do a GC at all.
905 // SystemDictionary::do_unloading() asserts that classes are only
906 // unloaded at a safepoint.
907 No_Safepoint_Verifier nosafepoint;
908 return dictionary()->find(d_index, d_hash, class_name, class_loader,
909 protection_domain, THREAD);
910 }
911 }
912
913
914 // Look for a loaded instance or array klass by name. Do not do any loading.
915 // return NULL in case of error.
916 klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name,
917 Handle class_loader,
918 Handle protection_domain,
919 TRAPS) {
920 klassOop k = NULL;
921 assert(class_name() != NULL, "class name must be non NULL");
922 if (FieldType::is_array(class_name())) {
923 // The name refers to an array. Parse the name.
924 jint dimension;
925 symbolOop object_key;
926
927 // dimension and object_key are assigned as a side-effect of this call
928 BasicType t = FieldType::get_array_info(class_name(), &dimension,
929 &object_key, CHECK_(NULL));
930 if (t != T_OBJECT) {
931 k = Universe::typeArrayKlassObj(t);
932 } else {
933 symbolHandle h_key(THREAD, object_key);
934 k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD);
935 }
936 if (k != NULL) {
937 k = Klass::cast(k)->array_klass_or_null(dimension);
938 }
939 } else {
940 k = find(class_name, class_loader, protection_domain, THREAD);
941 }
942 return k;
943 }
944
945 // Note: this method is much like resolve_from_stream, but
946 // updates no supplemental data structures.
947 // TODO consolidate the two methods with a helper routine?
948 klassOop SystemDictionary::parse_stream(symbolHandle class_name,
949 Handle class_loader,
950 Handle protection_domain,
951 ClassFileStream* st,
952 TRAPS) {
953 symbolHandle parsed_name;
954
955 // Parse the stream. Note that we do this even though this klass might
956 // already be present in the SystemDictionary, otherwise we would not
957 // throw potential ClassFormatErrors.
958 //
959 // Note: "name" is updated.
960 // Further note: a placeholder will be added for this class when
961 // super classes are loaded (resolve_super_or_fail). We expect this
962 // to be called for all classes but java.lang.Object; and we preload
963 // java.lang.Object through resolve_or_fail, not this path.
964
1665 f->do_oop(&_java_system_loader);
1666 preloaded_oops_do(f);
1667
1668 lazily_loaded_oops_do(f);
1669
1670 // Adjust dictionary
1671 dictionary()->oops_do(f);
1672
1673 // Partially loaded classes
1674 placeholders()->oops_do(f);
1675
1676 // Adjust constraint table
1677 constraints()->oops_do(f);
1678
1679 // Adjust resolution error table
1680 resolution_errors()->oops_do(f);
1681 }
1682
1683
1684 void SystemDictionary::preloaded_oops_do(OopClosure* f) {
1685 f->do_oop((oop*) &_string_klass);
1686 f->do_oop((oop*) &_object_klass);
1687 f->do_oop((oop*) &_class_klass);
1688 f->do_oop((oop*) &_cloneable_klass);
1689 f->do_oop((oop*) &_classloader_klass);
1690 f->do_oop((oop*) &_serializable_klass);
1691 f->do_oop((oop*) &_system_klass);
1692
1693 f->do_oop((oop*) &_throwable_klass);
1694 f->do_oop((oop*) &_error_klass);
1695 f->do_oop((oop*) &_threaddeath_klass);
1696 f->do_oop((oop*) &_exception_klass);
1697 f->do_oop((oop*) &_runtime_exception_klass);
1698 f->do_oop((oop*) &_classNotFoundException_klass);
1699 f->do_oop((oop*) &_noClassDefFoundError_klass);
1700 f->do_oop((oop*) &_linkageError_klass);
1701 f->do_oop((oop*) &_classCastException_klass);
1702 f->do_oop((oop*) &_arrayStoreException_klass);
1703 f->do_oop((oop*) &_virtualMachineError_klass);
1704 f->do_oop((oop*) &_outOfMemoryError_klass);
1705 f->do_oop((oop*) &_StackOverflowError_klass);
1706 f->do_oop((oop*) &_illegalMonitorStateException_klass);
1707 f->do_oop((oop*) &_protectionDomain_klass);
1708 f->do_oop((oop*) &_AccessControlContext_klass);
1709
1710 f->do_oop((oop*) &_reference_klass);
1711 f->do_oop((oop*) &_soft_reference_klass);
1712 f->do_oop((oop*) &_weak_reference_klass);
1713 f->do_oop((oop*) &_final_reference_klass);
1714 f->do_oop((oop*) &_phantom_reference_klass);
1715 f->do_oop((oop*) &_finalizer_klass);
1716
1717 f->do_oop((oop*) &_thread_klass);
1718 f->do_oop((oop*) &_threadGroup_klass);
1719 f->do_oop((oop*) &_properties_klass);
1720 f->do_oop((oop*) &_reflect_accessible_object_klass);
1721 f->do_oop((oop*) &_reflect_field_klass);
1722 f->do_oop((oop*) &_reflect_method_klass);
1723 f->do_oop((oop*) &_reflect_constructor_klass);
1724 f->do_oop((oop*) &_reflect_magic_klass);
1725 f->do_oop((oop*) &_reflect_method_accessor_klass);
1726 f->do_oop((oop*) &_reflect_constructor_accessor_klass);
1727 f->do_oop((oop*) &_reflect_delegating_classloader_klass);
1728 f->do_oop((oop*) &_reflect_constant_pool_klass);
1729 f->do_oop((oop*) &_reflect_unsafe_static_field_accessor_impl_klass);
1730
1731 f->do_oop((oop*) &_stringBuffer_klass);
1732 f->do_oop((oop*) &_vector_klass);
1733 f->do_oop((oop*) &_hashtable_klass);
1734
1735 f->do_oop((oop*) &_stackTraceElement_klass);
1736
1737 f->do_oop((oop*) &_java_nio_Buffer_klass);
1738
1739 f->do_oop((oop*) &_sun_misc_AtomicLongCSImpl_klass);
1740 f->do_oop((oop*) &_sun_jkernel_DownloadManager_klass);
1741
1742 f->do_oop((oop*) &_boolean_klass);
1743 f->do_oop((oop*) &_char_klass);
1744 f->do_oop((oop*) &_float_klass);
1745 f->do_oop((oop*) &_double_klass);
1746 f->do_oop((oop*) &_byte_klass);
1747 f->do_oop((oop*) &_short_klass);
1748 f->do_oop((oop*) &_int_klass);
1749 f->do_oop((oop*) &_long_klass);
1750 {
1751 for (int i = 0; i < T_VOID+1; i++) {
1752 if (_box_klasses[i] != NULL) {
1753 assert(i >= T_BOOLEAN, "checking");
1754 f->do_oop((oop*) &_box_klasses[i]);
1755 }
1756 }
1757 }
1758
1759 // The basic type mirrors would have already been processed in
1760 // Universe::oops_do(), via a call to shared_oops_do(), so should
1761 // not be processed again.
1762
1763 f->do_oop((oop*) &_system_loader_lock_obj);
1764 FilteredFieldsMap::klasses_oops_do(f);
1765 }
1766
1767 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) {
1768 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass);
1769 }
1822
1823 // ----------------------------------------------------------------------------
1824 // Initialization
1825
1826 void SystemDictionary::initialize(TRAPS) {
1827 // Allocate arrays
1828 assert(dictionary() == NULL,
1829 "SystemDictionary should only be initialized once");
1830 _dictionary = new Dictionary(_nof_buckets);
1831 _placeholders = new PlaceholderTable(_nof_buckets);
1832 _number_of_modifications = 0;
1833 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
1834 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
1835
1836 // Allocate private object used as system class loader lock
1837 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK);
1838 // Initialize basic classes
1839 initialize_preloaded_classes(CHECK);
1840 }
1841
1842
1843 void SystemDictionary::initialize_preloaded_classes(TRAPS) {
1844 assert(_object_klass == NULL, "preloaded classes should only be initialized once");
1845 // Preload commonly used klasses
1846 _object_klass = resolve_or_fail(vmSymbolHandles::java_lang_Object(), true, CHECK);
1847 _string_klass = resolve_or_fail(vmSymbolHandles::java_lang_String(), true, CHECK);
1848 _class_klass = resolve_or_fail(vmSymbolHandles::java_lang_Class(), true, CHECK);
1849 debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(_class_klass));
1850 // Fixup mirrors for classes loaded before java.lang.Class.
1851 // These calls iterate over the objects currently in the perm gen
1852 // so calling them at this point is matters (not before when there
1853 // are fewer objects and not later after there are more objects
1854 // in the perm gen.
1855 Universe::initialize_basic_type_mirrors(CHECK);
1856 Universe::fixup_mirrors(CHECK);
1857
1858 _cloneable_klass = resolve_or_fail(vmSymbolHandles::java_lang_Cloneable(), true, CHECK);
1859 _classloader_klass = resolve_or_fail(vmSymbolHandles::java_lang_ClassLoader(), true, CHECK);
1860 _serializable_klass = resolve_or_fail(vmSymbolHandles::java_io_Serializable(), true, CHECK);
1861 _system_klass = resolve_or_fail(vmSymbolHandles::java_lang_System(), true, CHECK);
1862
1863 _throwable_klass = resolve_or_fail(vmSymbolHandles::java_lang_Throwable(), true, CHECK);
1864 _error_klass = resolve_or_fail(vmSymbolHandles::java_lang_Error(), true, CHECK);
1865 _threaddeath_klass = resolve_or_fail(vmSymbolHandles::java_lang_ThreadDeath(), true, CHECK);
1866 _exception_klass = resolve_or_fail(vmSymbolHandles::java_lang_Exception(), true, CHECK);
1867 _runtime_exception_klass = resolve_or_fail(vmSymbolHandles::java_lang_RuntimeException(), true, CHECK);
1868 _protectionDomain_klass = resolve_or_fail(vmSymbolHandles::java_security_ProtectionDomain(), true, CHECK);
1869 _AccessControlContext_klass = resolve_or_fail(vmSymbolHandles::java_security_AccessControlContext(), true, CHECK);
1870 _classNotFoundException_klass = resolve_or_fail(vmSymbolHandles::java_lang_ClassNotFoundException(), true, CHECK);
1871 _noClassDefFoundError_klass = resolve_or_fail(vmSymbolHandles::java_lang_NoClassDefFoundError(), true, CHECK);
1872 _linkageError_klass = resolve_or_fail(vmSymbolHandles::java_lang_LinkageError(), true, CHECK);
1873 _classCastException_klass = resolve_or_fail(vmSymbolHandles::java_lang_ClassCastException(), true, CHECK);
1874 _arrayStoreException_klass = resolve_or_fail(vmSymbolHandles::java_lang_ArrayStoreException(), true, CHECK);
1875 _virtualMachineError_klass = resolve_or_fail(vmSymbolHandles::java_lang_VirtualMachineError(), true, CHECK);
1876 _outOfMemoryError_klass = resolve_or_fail(vmSymbolHandles::java_lang_OutOfMemoryError(), true, CHECK);
1877 _StackOverflowError_klass = resolve_or_fail(vmSymbolHandles::java_lang_StackOverflowError(), true, CHECK);
1878 _illegalMonitorStateException_klass = resolve_or_fail(vmSymbolHandles::java_lang_IllegalMonitorStateException(), true, CHECK);
1879
1880 // Preload ref klasses and set reference types
1881 _reference_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_Reference(), true, CHECK);
1882 instanceKlass::cast(_reference_klass)->set_reference_type(REF_OTHER);
1883 instanceRefKlass::update_nonstatic_oop_maps(_reference_klass);
1884
1885 _soft_reference_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_SoftReference(), true, CHECK);
1886 instanceKlass::cast(_soft_reference_klass)->set_reference_type(REF_SOFT);
1887 _weak_reference_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_WeakReference(), true, CHECK);
1888 instanceKlass::cast(_weak_reference_klass)->set_reference_type(REF_WEAK);
1889 _final_reference_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_FinalReference(), true, CHECK);
1890 instanceKlass::cast(_final_reference_klass)->set_reference_type(REF_FINAL);
1891 _phantom_reference_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_PhantomReference(), true, CHECK);
1892 instanceKlass::cast(_phantom_reference_klass)->set_reference_type(REF_PHANTOM);
1893 _finalizer_klass = resolve_or_fail(vmSymbolHandles::java_lang_ref_Finalizer(), true, CHECK);
1894
1895 _thread_klass = resolve_or_fail(vmSymbolHandles::java_lang_Thread(), true, CHECK);
1896 _threadGroup_klass = resolve_or_fail(vmSymbolHandles::java_lang_ThreadGroup(), true, CHECK);
1897 _properties_klass = resolve_or_fail(vmSymbolHandles::java_util_Properties(), true, CHECK);
1898 _reflect_accessible_object_klass = resolve_or_fail(vmSymbolHandles::java_lang_reflect_AccessibleObject(), true, CHECK);
1899 _reflect_field_klass = resolve_or_fail(vmSymbolHandles::java_lang_reflect_Field(), true, CHECK);
1900 _reflect_method_klass = resolve_or_fail(vmSymbolHandles::java_lang_reflect_Method(), true, CHECK);
1901 _reflect_constructor_klass = resolve_or_fail(vmSymbolHandles::java_lang_reflect_Constructor(), true, CHECK);
1902 // Universe::is_gte_jdk14x_version() is not set up by this point.
1903 // It's okay if these turn out to be NULL in non-1.4 JDKs.
1904 _reflect_magic_klass = resolve_or_null(vmSymbolHandles::sun_reflect_MagicAccessorImpl(), CHECK);
1905 _reflect_method_accessor_klass = resolve_or_null(vmSymbolHandles::sun_reflect_MethodAccessorImpl(), CHECK);
1906 _reflect_constructor_accessor_klass = resolve_or_null(vmSymbolHandles::sun_reflect_ConstructorAccessorImpl(), CHECK);
1907 _reflect_delegating_classloader_klass = resolve_or_null(vmSymbolHandles::sun_reflect_DelegatingClassLoader(), CHECK);
1908 _reflect_constant_pool_klass = resolve_or_null(vmSymbolHandles::sun_reflect_ConstantPool(), CHECK);
1909 _reflect_unsafe_static_field_accessor_impl_klass = resolve_or_null(vmSymbolHandles::sun_reflect_UnsafeStaticFieldAccessorImpl(), CHECK);
1910
1911 _vector_klass = resolve_or_fail(vmSymbolHandles::java_util_Vector(), true, CHECK);
1912 _hashtable_klass = resolve_or_fail(vmSymbolHandles::java_util_Hashtable(), true, CHECK);
1913 _stringBuffer_klass = resolve_or_fail(vmSymbolHandles::java_lang_StringBuffer(), true, CHECK);
1914
1915 // It's NULL in non-1.4 JDKs.
1916 _stackTraceElement_klass = resolve_or_null(vmSymbolHandles::java_lang_StackTraceElement(), CHECK);
1917
1918 // Universe::is_gte_jdk14x_version() is not set up by this point.
1919 // It's okay if this turns out to be NULL in non-1.4 JDKs.
1920 _java_nio_Buffer_klass = resolve_or_null(vmSymbolHandles::java_nio_Buffer(), CHECK);
1921
1922 // If this class isn't present, it won't be referenced.
1923 _sun_misc_AtomicLongCSImpl_klass = resolve_or_null(vmSymbolHandles::sun_misc_AtomicLongCSImpl(), CHECK);
1924 #ifdef KERNEL
1925 _sun_jkernel_DownloadManager_klass = resolve_or_null(vmSymbolHandles::sun_jkernel_DownloadManager(), CHECK);
1926 if (_sun_jkernel_DownloadManager_klass == NULL) {
1927 warning("Cannot find sun/jkernel/DownloadManager");
1928 }
1929 #endif // KERNEL
1930
1931 // Preload boxing klasses
1932 _boolean_klass = resolve_or_fail(vmSymbolHandles::java_lang_Boolean(), true, CHECK);
1933 _char_klass = resolve_or_fail(vmSymbolHandles::java_lang_Character(), true, CHECK);
1934 _float_klass = resolve_or_fail(vmSymbolHandles::java_lang_Float(), true, CHECK);
1935 _double_klass = resolve_or_fail(vmSymbolHandles::java_lang_Double(), true, CHECK);
1936 _byte_klass = resolve_or_fail(vmSymbolHandles::java_lang_Byte(), true, CHECK);
1937 _short_klass = resolve_or_fail(vmSymbolHandles::java_lang_Short(), true, CHECK);
1938 _int_klass = resolve_or_fail(vmSymbolHandles::java_lang_Integer(), true, CHECK);
1939 _long_klass = resolve_or_fail(vmSymbolHandles::java_lang_Long(), true, CHECK);
1940
1941 _box_klasses[T_BOOLEAN] = _boolean_klass;
1942 _box_klasses[T_CHAR] = _char_klass;
1943 _box_klasses[T_FLOAT] = _float_klass;
1944 _box_klasses[T_DOUBLE] = _double_klass;
1945 _box_klasses[T_BYTE] = _byte_klass;
1946 _box_klasses[T_SHORT] = _short_klass;
1947 _box_klasses[T_INT] = _int_klass;
1948 _box_klasses[T_LONG] = _long_klass;
1949 //_box_klasses[T_OBJECT] = _object_klass;
1950 //_box_klasses[T_ARRAY] = _object_klass;
1951
1952 { // Compute whether we should use loadClass or loadClassInternal when loading classes.
1953 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
1954 _has_loadClassInternal = (method != NULL);
1955 }
1956
1957 { // Compute whether we should use checkPackageAccess or NOT
1958 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
1959 _has_checkPackageAccess = (method != NULL);
1960 }
1961 }
1962
1963 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
1964 // If so, returns the basic type it holds. If not, returns T_OBJECT.
1965 BasicType SystemDictionary::box_klass_type(klassOop k) {
1966 assert(k != NULL, "");
1967 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
1968 if (_box_klasses[i] == k)
1969 return (BasicType)i;
1970 }
1971 return T_OBJECT;
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 # include "incls/_precompiled.incl"
26 # include "incls/_systemDictionary.cpp.incl"
27
28
29 Dictionary* SystemDictionary::_dictionary = NULL;
30 PlaceholderTable* SystemDictionary::_placeholders = NULL;
31 Dictionary* SystemDictionary::_shared_dictionary = NULL;
32 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
33 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
34
35
36 int SystemDictionary::_number_of_modifications = 0;
37
38 oop SystemDictionary::_system_loader_lock_obj = NULL;
39
40 klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
41 = { NULL /*, NULL...*/ };
42
43 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
44
45 oop SystemDictionary::_java_system_loader = NULL;
46
47 bool SystemDictionary::_has_loadClassInternal = false;
48 bool SystemDictionary::_has_checkPackageAccess = false;
49
50 // lazily initialized klass variables
51 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
52
53
54 // ----------------------------------------------------------------------------
55 // Java-level SystemLoader
56
57 oop SystemDictionary::java_system_loader() {
58 return _java_system_loader;
59 }
60
61 void SystemDictionary::compute_java_system_loader(TRAPS) {
62 KlassHandle system_klass(THREAD, WK_KLASS(classloader_klass));
63 JavaValue result(T_OBJECT);
64 JavaCalls::call_static(&result,
65 KlassHandle(THREAD, WK_KLASS(classloader_klass)),
66 vmSymbolHandles::getSystemClassLoader_name(),
67 vmSymbolHandles::void_classloader_signature(),
68 CHECK);
69
70 _java_system_loader = (oop)result.get_jobject();
71 }
72
73
74 // ----------------------------------------------------------------------------
75 // debugging
76
77 #ifdef ASSERT
78
79 // return true if class_name contains no '.' (internal format is '/')
80 bool SystemDictionary::is_internal_format(symbolHandle class_name) {
81 if (class_name.not_null()) {
82 ResourceMark rm;
83 char* name = class_name->as_C_string();
84 return strchr(name, '.') == NULL;
85 } else {
213 // loadClassFromxxx or defineClass via parseClassFile Super ...
214 // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base)
215 // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base
216 // 3.4 calls resolve_super_or_fail Base
217 // 3.5 finds T1,Base -> throws class circularity
218 //OR 4. If T2 tries to resolve Super via defineClass Super ...
219 // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base)
220 // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super)
221 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2
222 // 4.4 finds T2, Super -> throws class circularity
223 // Must be called, even if superclass is null, since this is
224 // where the placeholder entry is created which claims this
225 // thread is loading this class/classloader.
226 klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name,
227 symbolHandle class_name,
228 Handle class_loader,
229 Handle protection_domain,
230 bool is_superclass,
231 TRAPS) {
232
233 // Try to get one of the well-known klasses.
234 // They are trusted, and do not participate in circularities.
235 { klassOop k = find_well_known_klass(class_name());
236 if (k != NULL) {
237 return k;
238 }
239 }
240
241 // Double-check, if child class is already loaded, just return super-class,interface
242 // Don't add a placedholder if already loaded, i.e. already in system dictionary
243 // Make sure there's a placeholder for the *child* before resolving.
244 // Used as a claim that this thread is currently loading superclass/classloader
245 // Used here for ClassCircularity checks and also for heap verification
246 // (every instanceKlass in the heap needs to be in the system dictionary
247 // or have a placeholder).
248 // Must check ClassCircularity before checking if super class is already loaded
249 //
250 // We might not already have a placeholder if this child_name was
251 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass);
252 // the name of the class might not be known until the stream is actually
253 // parsed.
254 // Bugs 4643874, 4715493
255 // compute_hash can have a safepoint
256
257 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader);
258 int d_index = dictionary()->hash_to_index(d_hash);
259 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader);
260 int p_index = placeholders()->hash_to_index(p_hash);
848 // so we cannot allow GC to occur while we're holding this entry.
849 // We're using a No_Safepoint_Verifier to catch any place where we
850 // might potentially do a GC at all.
851 // SystemDictionary::do_unloading() asserts that classes are only
852 // unloaded at a safepoint.
853 No_Safepoint_Verifier nosafepoint;
854 return dictionary()->find(d_index, d_hash, class_name, class_loader,
855 protection_domain, THREAD);
856 }
857 }
858
859
860 // Look for a loaded instance or array klass by name. Do not do any loading.
861 // return NULL in case of error.
862 klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name,
863 Handle class_loader,
864 Handle protection_domain,
865 TRAPS) {
866 klassOop k = NULL;
867 assert(class_name() != NULL, "class name must be non NULL");
868
869 // Try to get one of the well-known klasses.
870 k = find_well_known_klass(class_name());
871 if (k != NULL) {
872 return k;
873 }
874
875 if (FieldType::is_array(class_name())) {
876 // The name refers to an array. Parse the name.
877 jint dimension;
878 symbolOop object_key;
879
880 // dimension and object_key are assigned as a side-effect of this call
881 BasicType t = FieldType::get_array_info(class_name(), &dimension,
882 &object_key, CHECK_(NULL));
883 if (t != T_OBJECT) {
884 k = Universe::typeArrayKlassObj(t);
885 } else {
886 symbolHandle h_key(THREAD, object_key);
887 k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD);
888 }
889 if (k != NULL) {
890 k = Klass::cast(k)->array_klass_or_null(dimension);
891 }
892 } else {
893 k = find(class_name, class_loader, protection_domain, THREAD);
894 }
895 return k;
896 }
897
898 // Quick range check for names of well-known classes:
899 static symbolOop wk_klass_name_limits[2] = {NULL, NULL};
900
901 #ifndef PRODUCT
902 static int find_wkk_calls, find_wkk_probes, find_wkk_wins;
903 // counts for "hello world": 3983, 1616, 1075
904 // => 60% hit after limit guard, 25% total win rate
905 #endif
906
907 klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) {
908 // A bounds-check on class_name will quickly get a negative result.
909 NOT_PRODUCT(find_wkk_calls++);
910 if (class_name >= wk_klass_name_limits[0] &&
911 class_name <= wk_klass_name_limits[1]) {
912 NOT_PRODUCT(find_wkk_probes++);
913 vmSymbols::SID sid = vmSymbols::find_sid(class_name);
914 if (sid != vmSymbols::NO_SID) {
915 klassOop k = NULL;
916 switch (sid) {
917 #define WK_KLASS_CASE(name, symbol, ignore_option) \
918 case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \
919 k = WK_KLASS(name); break;
920 WK_KLASSES_DO(WK_KLASS_CASE)
921 #undef WK_KLASS_CASE
922 }
923 NOT_PRODUCT(if (k != NULL) find_wkk_wins++);
924 return k;
925 }
926 }
927 return NULL;
928 }
929
930 // Note: this method is much like resolve_from_stream, but
931 // updates no supplemental data structures.
932 // TODO consolidate the two methods with a helper routine?
933 klassOop SystemDictionary::parse_stream(symbolHandle class_name,
934 Handle class_loader,
935 Handle protection_domain,
936 ClassFileStream* st,
937 TRAPS) {
938 symbolHandle parsed_name;
939
940 // Parse the stream. Note that we do this even though this klass might
941 // already be present in the SystemDictionary, otherwise we would not
942 // throw potential ClassFormatErrors.
943 //
944 // Note: "name" is updated.
945 // Further note: a placeholder will be added for this class when
946 // super classes are loaded (resolve_super_or_fail). We expect this
947 // to be called for all classes but java.lang.Object; and we preload
948 // java.lang.Object through resolve_or_fail, not this path.
949
1650 f->do_oop(&_java_system_loader);
1651 preloaded_oops_do(f);
1652
1653 lazily_loaded_oops_do(f);
1654
1655 // Adjust dictionary
1656 dictionary()->oops_do(f);
1657
1658 // Partially loaded classes
1659 placeholders()->oops_do(f);
1660
1661 // Adjust constraint table
1662 constraints()->oops_do(f);
1663
1664 // Adjust resolution error table
1665 resolution_errors()->oops_do(f);
1666 }
1667
1668
1669 void SystemDictionary::preloaded_oops_do(OopClosure* f) {
1670 f->do_oop((oop*) &wk_klass_name_limits[0]);
1671 f->do_oop((oop*) &wk_klass_name_limits[1]);
1672
1673 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
1674 f->do_oop((oop*) &_well_known_klasses[k]);
1675 }
1676
1677 {
1678 for (int i = 0; i < T_VOID+1; i++) {
1679 if (_box_klasses[i] != NULL) {
1680 assert(i >= T_BOOLEAN, "checking");
1681 f->do_oop((oop*) &_box_klasses[i]);
1682 }
1683 }
1684 }
1685
1686 // The basic type mirrors would have already been processed in
1687 // Universe::oops_do(), via a call to shared_oops_do(), so should
1688 // not be processed again.
1689
1690 f->do_oop((oop*) &_system_loader_lock_obj);
1691 FilteredFieldsMap::klasses_oops_do(f);
1692 }
1693
1694 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) {
1695 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass);
1696 }
1749
1750 // ----------------------------------------------------------------------------
1751 // Initialization
1752
1753 void SystemDictionary::initialize(TRAPS) {
1754 // Allocate arrays
1755 assert(dictionary() == NULL,
1756 "SystemDictionary should only be initialized once");
1757 _dictionary = new Dictionary(_nof_buckets);
1758 _placeholders = new PlaceholderTable(_nof_buckets);
1759 _number_of_modifications = 0;
1760 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
1761 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
1762
1763 // Allocate private object used as system class loader lock
1764 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK);
1765 // Initialize basic classes
1766 initialize_preloaded_classes(CHECK);
1767 }
1768
1769 // Compact table of directions on the initialization of klasses:
1770 static const short wk_init_info[] = {
1771 #define WK_KLASS_INIT_INFO(name, symbol, option) \
1772 ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) << 1) \
1773 | (SystemDictionary::option < SystemDictionary::Opt ? 0 : 1) ),
1774 WK_KLASSES_DO(WK_KLASS_INIT_INFO)
1775 #undef WK_KLASS_INIT_INFO
1776 0
1777 };
1778
1779 bool SystemDictionary::initialize_wk_klass(WKID id, bool must_load, TRAPS) {
1780 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1781 int info = wk_init_info[id - FIRST_WKID];
1782 int sid = (info >> 1);
1783 symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid);
1784 klassOop* klassp = &_well_known_klasses[id];
1785 if ((*klassp) == NULL) {
1786 if (must_load) {
1787 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
1788 } else {
1789 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass
1790 }
1791 }
1792 return ((*klassp) != NULL);
1793 }
1794
1795 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
1796 assert((int)start_id <= (int)limit_id, "IDs are out of order!");
1797 for (int id = (int)start_id; id < (int)limit_id; id++) {
1798 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1799 int info = wk_init_info[id - FIRST_WKID];
1800 int sid = (info >> 1);
1801 bool opt = (info & 1);
1802
1803 initialize_wk_klass((WKID)id, !opt, CHECK);
1804
1805 // Update limits, so find_well_known_klass can be very fast:
1806 symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid);
1807 if (wk_klass_name_limits[1] == NULL) {
1808 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s;
1809 } else if (wk_klass_name_limits[1] < s) {
1810 wk_klass_name_limits[1] = s;
1811 } else if (wk_klass_name_limits[0] > s) {
1812 wk_klass_name_limits[0] = s;
1813 }
1814 }
1815 }
1816
1817
1818 void SystemDictionary::initialize_preloaded_classes(TRAPS) {
1819 assert(WK_KLASS(object_klass) == NULL, "preloaded classes should only be initialized once");
1820 // Preload commonly used klasses
1821 WKID scan = FIRST_WKID;
1822 // first do Object, String, Class
1823 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(class_klass), scan, CHECK);
1824
1825 debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(class_klass)));
1826
1827 // Fixup mirrors for classes loaded before java.lang.Class.
1828 // These calls iterate over the objects currently in the perm gen
1829 // so calling them at this point is matters (not before when there
1830 // are fewer objects and not later after there are more objects
1831 // in the perm gen.
1832 Universe::initialize_basic_type_mirrors(CHECK);
1833 Universe::fixup_mirrors(CHECK);
1834
1835 // do a bunch more:
1836 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(reference_klass), scan, CHECK);
1837
1838 // Preload ref klasses and set reference types
1839 instanceKlass::cast(WK_KLASS(reference_klass))->set_reference_type(REF_OTHER);
1840 instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(reference_klass));
1841
1842 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(phantom_reference_klass), scan, CHECK);
1843 instanceKlass::cast(WK_KLASS(soft_reference_klass))->set_reference_type(REF_SOFT);
1844 instanceKlass::cast(WK_KLASS(weak_reference_klass))->set_reference_type(REF_WEAK);
1845 instanceKlass::cast(WK_KLASS(final_reference_klass))->set_reference_type(REF_FINAL);
1846 instanceKlass::cast(WK_KLASS(phantom_reference_klass))->set_reference_type(REF_PHANTOM);
1847
1848 initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
1849
1850 _box_klasses[T_BOOLEAN] = WK_KLASS(boolean_klass);
1851 _box_klasses[T_CHAR] = WK_KLASS(char_klass);
1852 _box_klasses[T_FLOAT] = WK_KLASS(float_klass);
1853 _box_klasses[T_DOUBLE] = WK_KLASS(double_klass);
1854 _box_klasses[T_BYTE] = WK_KLASS(byte_klass);
1855 _box_klasses[T_SHORT] = WK_KLASS(short_klass);
1856 _box_klasses[T_INT] = WK_KLASS(int_klass);
1857 _box_klasses[T_LONG] = WK_KLASS(long_klass);
1858 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
1859 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
1860
1861 #ifdef KERNEL
1862 _sun_jkernel_DownloadManager_klass = resolve_or_null(vmSymbolHandles::sun_jkernel_DownloadManager(), CHECK);
1863 if (_sun_jkernel_DownloadManager_klass == NULL) {
1864 warning("Cannot find sun/jkernel/DownloadManager");
1865 }
1866 #endif // KERNEL
1867 { // Compute whether we should use loadClass or loadClassInternal when loading classes.
1868 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
1869 _has_loadClassInternal = (method != NULL);
1870 }
1871
1872 { // Compute whether we should use checkPackageAccess or NOT
1873 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
1874 _has_checkPackageAccess = (method != NULL);
1875 }
1876 }
1877
1878 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
1879 // If so, returns the basic type it holds. If not, returns T_OBJECT.
1880 BasicType SystemDictionary::box_klass_type(klassOop k) {
1881 assert(k != NULL, "");
1882 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
1883 if (_box_klasses[i] == k)
1884 return (BasicType)i;
1885 }
1886 return T_OBJECT;
|