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/classLoaderData.hpp"
29 #include "oops/objArrayOop.hpp"
30 #include "oops/symbol.hpp"
31 #include "runtime/java.hpp"
32 #include "runtime/mutexLocker.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
50 // be done concurrently, but only by different loaders.
51 //
52 // During loading a placeholder (name, loader) is temporarily placed in
53 // a side data structure, and is used to detect ClassCircularityErrors
54 // and to perform verification during GC. A GC can occur in the midst
55 // of class loading, as we call out to Java, have to take locks, etc.
56 //
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,
294 const InstanceKlass* unsafe_anonymous_host,
295 GrowableArray<Handle>* cp_patches,
296 TRAPS);
297
298 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
299 static InstanceKlass* resolve_from_stream(Symbol* class_name,
300 Handle class_loader,
301 Handle protection_domain,
302 ClassFileStream* st,
303 TRAPS);
304
305 // Lookup an already loaded class. If not found NULL is returned.
306 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
307
308 // Lookup an already loaded instance or array class.
309 // Do not make any queries to class loaders; consult only the cache.
310 // If not found NULL is returned.
311 static Klass* find_instance_or_array_klass(Symbol* class_name,
312 Handle class_loader,
313 Handle protection_domain,
314 TRAPS);
315
513 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry
514 static Handle link_method_handle_constant(Klass* caller,
515 int ref_kind, //e.g., JVM_REF_invokeVirtual
516 Klass* callee,
517 Symbol* name,
518 Symbol* signature,
519 TRAPS);
520
521 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
522 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
523
524 // Record the error when the first attempt to resolve a reference from a constant
525 // pool entry to a class fails.
526 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error,
527 Symbol* message);
528 static void delete_resolution_error(ConstantPool* pool);
529 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
530 Symbol** message);
531
532
533 static ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
534
535 protected:
536
537 enum Constants {
538 _loader_constraint_size = 107, // number of entries in constraint table
539 _resolution_error_size = 107, // number of entries in resolution error table
540 _invoke_method_size = 139, // number of entries in invoke method table
541 _placeholder_table_size = 1009 // number of entries in hash table for placeholders
542 };
543
544
545 // Static tables owned by the SystemDictionary
546
547 // Hashtable holding placeholders for classes being loaded.
548 static PlaceholderTable* _placeholders;
549
550 // Lock object for system class loader
551 static oop _system_loader_lock_obj;
552
|
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/classLoaderData.hpp"
29 #include "oops/objArrayOop.hpp"
30 #include "oops/symbol.hpp"
31 #include "runtime/java.hpp"
32 #include "runtime/mutexLocker.hpp"
33 #include "runtime/reflectionUtils.hpp"
34 #include "runtime/signature.hpp"
35 #include "utilities/hashtable.hpp"
36
37 class ClassInstanceInfo : public StackObj {
38 private:
39 InstanceKlass* _dynamic_nest_host;
40 Handle _class_data;
41
42 public:
43 ClassInstanceInfo() {
44 _dynamic_nest_host = NULL;
45 _class_data = Handle();
46 }
47 ClassInstanceInfo(InstanceKlass* dynamic_nest_host, Handle class_data) {
48 _dynamic_nest_host = dynamic_nest_host;
49 _class_data = class_data;
50 }
51
52 InstanceKlass* dynamic_nest_host() const { return _dynamic_nest_host; }
53 Handle class_data() const { return _class_data; }
54 friend class ClassLoadInfo;
55 };
56
57 class ClassLoadInfo : public StackObj {
58 private:
59 Handle _protection_domain;
60 const InstanceKlass* _unsafe_anonymous_host;
61 GrowableArray<Handle>* _cp_patches;
62 ClassInstanceInfo _class_hidden_info;
63 bool _is_hidden;
64 bool _is_strong_hidden;
65 bool _can_access_vm_annotations;
66
67 public:
68 ClassLoadInfo();
69 ClassLoadInfo(Handle protection_domain);
70 ClassLoadInfo(Handle protection_domain, const InstanceKlass* unsafe_anonymous_host,
71 GrowableArray<Handle>* cp_patches, InstanceKlass* dynamic_nest_host,
72 Handle class_data, bool is_hidden, bool is_strong_hidden,
73 bool can_access_vm_annotations);
74
75 Handle protection_domain() const { return _protection_domain; }
76 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
77 GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
78 const ClassInstanceInfo* class_hidden_info_ptr() const { return &_class_hidden_info; }
79 bool is_hidden() const { return _is_hidden; }
80 bool is_strong_hidden() const { return _is_strong_hidden; }
81 bool can_access_vm_annotations() const { return _can_access_vm_annotations; }
82 };
83
84 // The dictionary in each ClassLoaderData stores all loaded classes, either
85 // initiatied by its class loader or defined by its class loader:
86 //
87 // class loader -> ClassLoaderData -> [class, protection domain set]
88 //
89 // Classes are loaded lazily. The default VM class loader is
90 // represented as NULL.
91
92 // The underlying data structure is an open hash table (Dictionary) per
93 // ClassLoaderData with a fixed number of buckets. During loading the
94 // class loader object is locked, (for the VM loader a private lock object is used).
95 // The global SystemDictionary_lock is held for all additions into the ClassLoaderData
96 // dictionaries. TODO: fix lock granularity so that class loading can
97 // be done concurrently, but only by different loaders.
98 //
99 // During loading a placeholder (name, loader) is temporarily placed in
100 // a side data structure, and is used to detect ClassCircularityErrors
101 // and to perform verification during GC. A GC can occur in the midst
102 // of class loading, as we call out to Java, have to take locks, etc.
103 //
301 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS);
302
303 public:
304
305 // Returns a class with a given class name and class loader.
306 // Loads the class if needed. If not found NULL is returned.
307 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
308 // Version with null loader and protection domain
309 static Klass* resolve_or_null(Symbol* class_name, TRAPS);
310
311 // Resolve a superclass or superinterface. Called from ClassFileParser,
312 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
313 // "child_name" is the class whose super class or interface is being resolved.
314 static InstanceKlass* resolve_super_or_fail(Symbol* child_name,
315 Symbol* class_name,
316 Handle class_loader,
317 Handle protection_domain,
318 bool is_superclass,
319 TRAPS);
320
321 // Parse new stream. This won't update the dictionary or class
322 // hierarchy, simply parse the stream. Used by JVMTI RedefineClasses
323 // and by Unsafe_DefineAnonymousClass and jvm_lookup_define_class.
324 static InstanceKlass* parse_stream(Symbol* class_name,
325 Handle class_loader,
326 ClassFileStream* st,
327 const ClassLoadInfo& cl_info,
328 TRAPS);
329
330 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
331 static InstanceKlass* resolve_from_stream(Symbol* class_name,
332 Handle class_loader,
333 Handle protection_domain,
334 ClassFileStream* st,
335 TRAPS);
336
337 // Lookup an already loaded class. If not found NULL is returned.
338 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
339
340 // Lookup an already loaded instance or array class.
341 // Do not make any queries to class loaders; consult only the cache.
342 // If not found NULL is returned.
343 static Klass* find_instance_or_array_klass(Symbol* class_name,
344 Handle class_loader,
345 Handle protection_domain,
346 TRAPS);
347
545 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry
546 static Handle link_method_handle_constant(Klass* caller,
547 int ref_kind, //e.g., JVM_REF_invokeVirtual
548 Klass* callee,
549 Symbol* name,
550 Symbol* signature,
551 TRAPS);
552
553 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
554 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
555
556 // Record the error when the first attempt to resolve a reference from a constant
557 // pool entry to a class fails.
558 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error,
559 Symbol* message);
560 static void delete_resolution_error(ConstantPool* pool);
561 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
562 Symbol** message);
563
564
565 // Record a nest host resolution/validation error
566 static void add_nest_host_error(const constantPoolHandle& pool, int which,
567 const char* message);
568 static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
569
570 static ProtectionDomainCacheEntry* cache_get(Handle protection_domain);
571
572 protected:
573
574 enum Constants {
575 _loader_constraint_size = 107, // number of entries in constraint table
576 _resolution_error_size = 107, // number of entries in resolution error table
577 _invoke_method_size = 139, // number of entries in invoke method table
578 _placeholder_table_size = 1009 // number of entries in hash table for placeholders
579 };
580
581
582 // Static tables owned by the SystemDictionary
583
584 // Hashtable holding placeholders for classes being loaded.
585 static PlaceholderTable* _placeholders;
586
587 // Lock object for system class loader
588 static oop _system_loader_lock_obj;
589
|