10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP
26 #define SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP
27
28 #include "classfile/classLoader.hpp"
29 #include "jvmci/systemDictionary_jvmci.hpp"
30 #include "oops/objArrayOop.hpp"
31 #include "oops/symbol.hpp"
32 #include "runtime/java.hpp"
33 #include "runtime/reflectionUtils.hpp"
34 #include "runtime/signature.hpp"
35 #include "utilities/hashtable.hpp"
36
37 // The dictionary in each ClassLoaderData stores all loaded classes, either
38 // initiatied by its class loader or defined by its class loader:
39 //
40 // class loader -> ClassLoaderData -> [class, protection domain set]
41 //
42 // Classes are loaded lazily. The default VM class loader is
43 // represented as NULL.
44
45 // The underlying data structure is an open hash table (Dictionary) per
46 // ClassLoaderData with a fixed number of buckets. During loading the
47 // class loader object is locked, (for the VM loader a private lock object is used).
48 // The global SystemDictionary_lock is held for all additions into the ClassLoaderData
49 // dictionaries. TODO: fix lock granularity so that class loading can
153 do_klass(reflect_ConstructorAccessorImpl_klass, reflect_ConstructorAccessorImpl ) \
154 do_klass(reflect_DelegatingClassLoader_klass, reflect_DelegatingClassLoader ) \
155 do_klass(reflect_ConstantPool_klass, reflect_ConstantPool ) \
156 do_klass(reflect_UnsafeStaticFieldAccessorImpl_klass, reflect_UnsafeStaticFieldAccessorImpl ) \
157 do_klass(reflect_CallerSensitive_klass, reflect_CallerSensitive ) \
158 \
159 /* support for dynamic typing; it's OK if these are NULL in earlier JDKs */ \
160 do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle ) \
161 do_klass(MethodHandle_klass, java_lang_invoke_MethodHandle ) \
162 do_klass(VarHandle_klass, java_lang_invoke_VarHandle ) \
163 do_klass(MemberName_klass, java_lang_invoke_MemberName ) \
164 do_klass(ResolvedMethodName_klass, java_lang_invoke_ResolvedMethodName ) \
165 do_klass(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives ) \
166 do_klass(LambdaForm_klass, java_lang_invoke_LambdaForm ) \
167 do_klass(MethodType_klass, java_lang_invoke_MethodType ) \
168 do_klass(BootstrapMethodError_klass, java_lang_BootstrapMethodError ) \
169 do_klass(CallSite_klass, java_lang_invoke_CallSite ) \
170 do_klass(Context_klass, java_lang_invoke_MethodHandleNatives_CallSiteContext ) \
171 do_klass(ConstantCallSite_klass, java_lang_invoke_ConstantCallSite ) \
172 do_klass(MutableCallSite_klass, java_lang_invoke_MutableCallSite ) \
173 do_klass(VolatileCallSite_klass, java_lang_invoke_VolatileCallSite ) \
174 /* Note: MethodHandle must be first, and VolatileCallSite last in group */ \
175 \
176 do_klass(AssertionStatusDirectives_klass, java_lang_AssertionStatusDirectives ) \
177 do_klass(StringBuffer_klass, java_lang_StringBuffer ) \
178 do_klass(StringBuilder_klass, java_lang_StringBuilder ) \
179 do_klass(internal_Unsafe_klass, jdk_internal_misc_Unsafe ) \
180 do_klass(module_Modules_klass, jdk_internal_module_Modules ) \
181 \
182 /* support for CDS */ \
183 do_klass(ByteArrayInputStream_klass, java_io_ByteArrayInputStream ) \
184 do_klass(URL_klass, java_net_URL ) \
185 do_klass(Jar_Manifest_klass, java_util_jar_Manifest ) \
186 do_klass(jdk_internal_loader_ClassLoaders_klass, jdk_internal_loader_ClassLoaders ) \
187 do_klass(jdk_internal_loader_ClassLoaders_AppClassLoader_klass, jdk_internal_loader_ClassLoaders_AppClassLoader) \
188 do_klass(jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass, jdk_internal_loader_ClassLoaders_PlatformClassLoader) \
189 do_klass(CodeSource_klass, java_security_CodeSource ) \
190 \
191 do_klass(StackTraceElement_klass, java_lang_StackTraceElement ) \
192 \
195 \
196 /* Stack Walking */ \
197 do_klass(StackWalker_klass, java_lang_StackWalker ) \
198 do_klass(AbstractStackWalker_klass, java_lang_StackStreamFactory_AbstractStackWalker ) \
199 do_klass(StackFrameInfo_klass, java_lang_StackFrameInfo ) \
200 do_klass(LiveStackFrameInfo_klass, java_lang_LiveStackFrameInfo ) \
201 \
202 /* support for stack dump lock analysis */ \
203 do_klass(java_util_concurrent_locks_AbstractOwnableSynchronizer_klass, java_util_concurrent_locks_AbstractOwnableSynchronizer) \
204 \
205 /* boxing klasses */ \
206 do_klass(Boolean_klass, java_lang_Boolean ) \
207 do_klass(Character_klass, java_lang_Character ) \
208 do_klass(Float_klass, java_lang_Float ) \
209 do_klass(Double_klass, java_lang_Double ) \
210 do_klass(Byte_klass, java_lang_Byte ) \
211 do_klass(Short_klass, java_lang_Short ) \
212 do_klass(Integer_klass, java_lang_Integer ) \
213 do_klass(Long_klass, java_lang_Long ) \
214 \
215 /* JVMCI classes. These are loaded on-demand. */ \
216 JVMCI_WK_KLASSES_DO(do_klass) \
217 \
218 /*end*/
219
220
221 class SystemDictionary : AllStatic {
222 friend class VMStructs;
223 friend class SystemDictionaryHandles;
224
225 public:
226 enum WKID {
227 NO_WKID = 0,
228
229 #define WK_KLASS_ENUM(name, symbol) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name),
230 WK_KLASSES_DO(WK_KLASS_ENUM)
231 #undef WK_KLASS_ENUM
232
233 WKID_LIMIT,
234
254 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS);
255
256 public:
257
258 // Returns a class with a given class name and class loader.
259 // Loads the class if needed. If not found NULL is returned.
260 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
261 // Version with null loader and protection domain
262 static Klass* resolve_or_null(Symbol* class_name, TRAPS);
263
264 // Resolve a superclass or superinterface. Called from ClassFileParser,
265 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
266 // "child_name" is the class whose super class or interface is being resolved.
267 static InstanceKlass* resolve_super_or_fail(Symbol* child_name,
268 Symbol* class_name,
269 Handle class_loader,
270 Handle protection_domain,
271 bool is_superclass,
272 TRAPS);
273
274 // Parse new stream. This won't update the dictionary or
275 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
276 // Also used by Unsafe_DefineAnonymousClass
277 static InstanceKlass* parse_stream(Symbol* class_name,
278 Handle class_loader,
279 Handle protection_domain,
280 ClassFileStream* st,
281 TRAPS) {
282 return parse_stream(class_name,
283 class_loader,
284 protection_domain,
285 st,
286 NULL, // unsafe_anonymous_host
287 NULL, // cp_patches
288 THREAD);
289 }
290 static InstanceKlass* parse_stream(Symbol* class_name,
291 Handle class_loader,
292 Handle protection_domain,
293 ClassFileStream* st,
368 // loaded or modifications such as hot-swapping or setting/removing
369 // of breakpoints are performed
370 static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; }
371 // Needed by evolution and breakpoint code
372 static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; }
373
374 // Verification
375 static void verify();
376
377 // Initialization
378 static void initialize(TRAPS);
379
380 // Checked fast access to the well-known classes -- so that you don't try to use them
381 // before they are resolved.
382 static InstanceKlass* check_klass(InstanceKlass* k) {
383 assert(k != NULL, "klass not loaded");
384 return k;
385 }
386
387 static bool resolve_wk_klass(WKID id, TRAPS);
388 static void resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
389 static void resolve_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
390 int limit = (int)end_id + 1;
391 resolve_wk_klasses_until((WKID) limit, start_id, THREAD);
392 }
393
394 public:
395 #define WK_KLASS_DECLARE(name, symbol) \
396 static InstanceKlass* name() { return check_klass(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
397 static InstanceKlass** name##_addr() { \
398 return &_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \
399 } \
400 static bool name##_is_loaded() { \
401 return _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] != NULL; \
402 }
403 WK_KLASSES_DO(WK_KLASS_DECLARE);
404 #undef WK_KLASS_DECLARE
405
406 static InstanceKlass* well_known_klass(WKID id) {
407 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP
26 #define SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP
27
28 #include "classfile/classLoader.hpp"
29 #include "jvmci/systemDictionary_jvmci.hpp"
30 #include "oops/fieldStreams.hpp"
31 #include "oops/objArrayOop.hpp"
32 #include "oops/symbol.hpp"
33 #include "runtime/java.hpp"
34 #include "runtime/reflectionUtils.hpp"
35 #include "runtime/signature.hpp"
36 #include "utilities/hashtable.hpp"
37
38 // The dictionary in each ClassLoaderData stores all loaded classes, either
39 // initiatied by its class loader or defined by its class loader:
40 //
41 // class loader -> ClassLoaderData -> [class, protection domain set]
42 //
43 // Classes are loaded lazily. The default VM class loader is
44 // represented as NULL.
45
46 // The underlying data structure is an open hash table (Dictionary) per
47 // ClassLoaderData with a fixed number of buckets. During loading the
48 // class loader object is locked, (for the VM loader a private lock object is used).
49 // The global SystemDictionary_lock is held for all additions into the ClassLoaderData
50 // dictionaries. TODO: fix lock granularity so that class loading can
154 do_klass(reflect_ConstructorAccessorImpl_klass, reflect_ConstructorAccessorImpl ) \
155 do_klass(reflect_DelegatingClassLoader_klass, reflect_DelegatingClassLoader ) \
156 do_klass(reflect_ConstantPool_klass, reflect_ConstantPool ) \
157 do_klass(reflect_UnsafeStaticFieldAccessorImpl_klass, reflect_UnsafeStaticFieldAccessorImpl ) \
158 do_klass(reflect_CallerSensitive_klass, reflect_CallerSensitive ) \
159 \
160 /* support for dynamic typing; it's OK if these are NULL in earlier JDKs */ \
161 do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle ) \
162 do_klass(MethodHandle_klass, java_lang_invoke_MethodHandle ) \
163 do_klass(VarHandle_klass, java_lang_invoke_VarHandle ) \
164 do_klass(MemberName_klass, java_lang_invoke_MemberName ) \
165 do_klass(ResolvedMethodName_klass, java_lang_invoke_ResolvedMethodName ) \
166 do_klass(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives ) \
167 do_klass(LambdaForm_klass, java_lang_invoke_LambdaForm ) \
168 do_klass(MethodType_klass, java_lang_invoke_MethodType ) \
169 do_klass(BootstrapMethodError_klass, java_lang_BootstrapMethodError ) \
170 do_klass(CallSite_klass, java_lang_invoke_CallSite ) \
171 do_klass(Context_klass, java_lang_invoke_MethodHandleNatives_CallSiteContext ) \
172 do_klass(ConstantCallSite_klass, java_lang_invoke_ConstantCallSite ) \
173 do_klass(MutableCallSite_klass, java_lang_invoke_MutableCallSite ) \
174 do_klass(ValueBootstrapMethods_klass, java_lang_invoke_ValueBootstrapMethods ) \
175 do_klass(VolatileCallSite_klass, java_lang_invoke_VolatileCallSite ) \
176 /* Note: MethodHandle must be first, and VolatileCallSite last in group */ \
177 \
178 do_klass(AssertionStatusDirectives_klass, java_lang_AssertionStatusDirectives ) \
179 do_klass(StringBuffer_klass, java_lang_StringBuffer ) \
180 do_klass(StringBuilder_klass, java_lang_StringBuilder ) \
181 do_klass(internal_Unsafe_klass, jdk_internal_misc_Unsafe ) \
182 do_klass(module_Modules_klass, jdk_internal_module_Modules ) \
183 \
184 /* support for CDS */ \
185 do_klass(ByteArrayInputStream_klass, java_io_ByteArrayInputStream ) \
186 do_klass(URL_klass, java_net_URL ) \
187 do_klass(Jar_Manifest_klass, java_util_jar_Manifest ) \
188 do_klass(jdk_internal_loader_ClassLoaders_klass, jdk_internal_loader_ClassLoaders ) \
189 do_klass(jdk_internal_loader_ClassLoaders_AppClassLoader_klass, jdk_internal_loader_ClassLoaders_AppClassLoader) \
190 do_klass(jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass, jdk_internal_loader_ClassLoaders_PlatformClassLoader) \
191 do_klass(CodeSource_klass, java_security_CodeSource ) \
192 \
193 do_klass(StackTraceElement_klass, java_lang_StackTraceElement ) \
194 \
197 \
198 /* Stack Walking */ \
199 do_klass(StackWalker_klass, java_lang_StackWalker ) \
200 do_klass(AbstractStackWalker_klass, java_lang_StackStreamFactory_AbstractStackWalker ) \
201 do_klass(StackFrameInfo_klass, java_lang_StackFrameInfo ) \
202 do_klass(LiveStackFrameInfo_klass, java_lang_LiveStackFrameInfo ) \
203 \
204 /* support for stack dump lock analysis */ \
205 do_klass(java_util_concurrent_locks_AbstractOwnableSynchronizer_klass, java_util_concurrent_locks_AbstractOwnableSynchronizer) \
206 \
207 /* boxing klasses */ \
208 do_klass(Boolean_klass, java_lang_Boolean ) \
209 do_klass(Character_klass, java_lang_Character ) \
210 do_klass(Float_klass, java_lang_Float ) \
211 do_klass(Double_klass, java_lang_Double ) \
212 do_klass(Byte_klass, java_lang_Byte ) \
213 do_klass(Short_klass, java_lang_Short ) \
214 do_klass(Integer_klass, java_lang_Integer ) \
215 do_klass(Long_klass, java_lang_Long ) \
216 \
217 \
218 /* JVMCI classes. These are loaded on-demand. */ \
219 JVMCI_WK_KLASSES_DO(do_klass) \
220 \
221 /*end*/
222
223
224 class SystemDictionary : AllStatic {
225 friend class VMStructs;
226 friend class SystemDictionaryHandles;
227
228 public:
229 enum WKID {
230 NO_WKID = 0,
231
232 #define WK_KLASS_ENUM(name, symbol) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name),
233 WK_KLASSES_DO(WK_KLASS_ENUM)
234 #undef WK_KLASS_ENUM
235
236 WKID_LIMIT,
237
257 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS);
258
259 public:
260
261 // Returns a class with a given class name and class loader.
262 // Loads the class if needed. If not found NULL is returned.
263 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
264 // Version with null loader and protection domain
265 static Klass* resolve_or_null(Symbol* class_name, TRAPS);
266
267 // Resolve a superclass or superinterface. Called from ClassFileParser,
268 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
269 // "child_name" is the class whose super class or interface is being resolved.
270 static InstanceKlass* resolve_super_or_fail(Symbol* child_name,
271 Symbol* class_name,
272 Handle class_loader,
273 Handle protection_domain,
274 bool is_superclass,
275 TRAPS);
276
277 static Klass* resolve_flattenable_field_or_fail(AllFieldStream* fs,
278 Handle class_loader,
279 Handle protection_domain,
280 bool throw_error,
281 TRAPS);
282
283 // Parse new stream. This won't update the dictionary or
284 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
285 // Also used by Unsafe_DefineAnonymousClass
286 static InstanceKlass* parse_stream(Symbol* class_name,
287 Handle class_loader,
288 Handle protection_domain,
289 ClassFileStream* st,
290 TRAPS) {
291 return parse_stream(class_name,
292 class_loader,
293 protection_domain,
294 st,
295 NULL, // unsafe_anonymous_host
296 NULL, // cp_patches
297 THREAD);
298 }
299 static InstanceKlass* parse_stream(Symbol* class_name,
300 Handle class_loader,
301 Handle protection_domain,
302 ClassFileStream* st,
377 // loaded or modifications such as hot-swapping or setting/removing
378 // of breakpoints are performed
379 static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; }
380 // Needed by evolution and breakpoint code
381 static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; }
382
383 // Verification
384 static void verify();
385
386 // Initialization
387 static void initialize(TRAPS);
388
389 // Checked fast access to the well-known classes -- so that you don't try to use them
390 // before they are resolved.
391 static InstanceKlass* check_klass(InstanceKlass* k) {
392 assert(k != NULL, "klass not loaded");
393 return k;
394 }
395
396 static bool resolve_wk_klass(WKID id, TRAPS);
397 static InstanceKlass* check_klass_ValhallaClasses(InstanceKlass* k) { return k; }
398 static void resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
399 static void resolve_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
400 int limit = (int)end_id + 1;
401 resolve_wk_klasses_until((WKID) limit, start_id, THREAD);
402 }
403
404 public:
405 #define WK_KLASS_DECLARE(name, symbol) \
406 static InstanceKlass* name() { return check_klass(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
407 static InstanceKlass** name##_addr() { \
408 return &_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \
409 } \
410 static bool name##_is_loaded() { \
411 return _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] != NULL; \
412 }
413 WK_KLASSES_DO(WK_KLASS_DECLARE);
414 #undef WK_KLASS_DECLARE
415
416 static InstanceKlass* well_known_klass(WKID id) {
417 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|