comparison src/share/vm/classfile/systemDictionary.cpp @ 7212:291ffc492eb6

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Fri, 14 Dec 2012 14:35:13 +0100
parents 2cb439954abf 90273fc0a981
children 3ac7d10a6572
comparison
equal deleted inserted replaced
7163:2ed8d74e5984 7212:291ffc492eb6
104 104
105 _java_system_loader = (oop)result.get_jobject(); 105 _java_system_loader = (oop)result.get_jobject();
106 } 106 }
107 107
108 108
109 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) { 109 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
110 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data(); 110 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
111 return ClassLoaderDataGraph::find_or_create(class_loader); 111 return ClassLoaderDataGraph::find_or_create(class_loader, CHECK_NULL);
112 } 112 }
113 113
114 // ---------------------------------------------------------------------------- 114 // ----------------------------------------------------------------------------
115 // debugging 115 // debugging
116 116
589 !FieldType::is_obj(name), "invalid class name"); 589 !FieldType::is_obj(name), "invalid class name");
590 590
591 // UseNewReflection 591 // UseNewReflection
592 // Fix for 4474172; see evaluation for more details 592 // Fix for 4474172; see evaluation for more details
593 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); 593 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
594 ClassLoaderData *loader_data = register_loader(class_loader); 594 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
595 595
596 // Do lookup to see if class already exist and the protection domain 596 // Do lookup to see if class already exist and the protection domain
597 // has the right access 597 // has the right access
598 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); 598 unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
599 int d_index = dictionary()->hash_to_index(d_hash); 599 int d_index = dictionary()->hash_to_index(d_hash);
886 // UseNewReflection 886 // UseNewReflection
887 // The result of this call should be consistent with the result 887 // The result of this call should be consistent with the result
888 // of the call to resolve_instance_class_or_null(). 888 // of the call to resolve_instance_class_or_null().
889 // See evaluation 6790209 and 4474172 for more details. 889 // See evaluation 6790209 and 4474172 for more details.
890 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); 890 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
891 ClassLoaderData* loader_data = register_loader(class_loader); 891 ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
892 892
893 unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data); 893 unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data);
894 int d_index = dictionary()->hash_to_index(d_hash); 894 int d_index = dictionary()->hash_to_index(d_hash);
895 895
896 { 896 {
946 KlassHandle host_klass, 946 KlassHandle host_klass,
947 GrowableArray<Handle>* cp_patches, 947 GrowableArray<Handle>* cp_patches,
948 TRAPS) { 948 TRAPS) {
949 TempNewSymbol parsed_name = NULL; 949 TempNewSymbol parsed_name = NULL;
950 950
951 ClassLoaderData* loader_data;
952 if (host_klass.not_null()) {
953 // Create a new CLD for anonymous class, that uses the same class loader
954 // as the host_klass
955 assert(EnableInvokeDynamic, "");
956 guarantee(host_klass->class_loader() == class_loader(), "should be the same");
957 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
958 loader_data->record_dependency(host_klass(), CHECK_NULL);
959 } else {
960 loader_data = ClassLoaderData::class_loader_data(class_loader());
961 }
962
951 // Parse the stream. Note that we do this even though this klass might 963 // Parse the stream. Note that we do this even though this klass might
952 // already be present in the SystemDictionary, otherwise we would not 964 // already be present in the SystemDictionary, otherwise we would not
953 // throw potential ClassFormatErrors. 965 // throw potential ClassFormatErrors.
954 // 966 //
955 // Note: "name" is updated. 967 // Note: "name" is updated.
957 // super classes are loaded (resolve_super_or_fail). We expect this 969 // super classes are loaded (resolve_super_or_fail). We expect this
958 // to be called for all classes but java.lang.Object; and we preload 970 // to be called for all classes but java.lang.Object; and we preload
959 // java.lang.Object through resolve_or_fail, not this path. 971 // java.lang.Object through resolve_or_fail, not this path.
960 972
961 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, 973 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
962 class_loader, 974 loader_data,
963 protection_domain, 975 protection_domain,
964 host_klass, 976 host_klass,
965 cp_patches, 977 cp_patches,
966 parsed_name, 978 parsed_name,
967 true, 979 true,
971 // was an error or not (don't want to modify any system dictionary 983 // was an error or not (don't want to modify any system dictionary
972 // data structures). 984 // data structures).
973 // Parsed name could be null if we threw an error before we got far 985 // Parsed name could be null if we threw an error before we got far
974 // enough along to parse it -- in that case, there is nothing to clean up. 986 // enough along to parse it -- in that case, there is nothing to clean up.
975 if (parsed_name != NULL) { 987 if (parsed_name != NULL) {
976 ClassLoaderData* loader_data = class_loader_data(class_loader);
977
978 unsigned int p_hash = placeholders()->compute_hash(parsed_name, 988 unsigned int p_hash = placeholders()->compute_hash(parsed_name,
979 loader_data); 989 loader_data);
980 int p_index = placeholders()->hash_to_index(p_hash); 990 int p_index = placeholders()->hash_to_index(p_hash);
981 { 991 {
982 MutexLocker mu(SystemDictionary_lock, THREAD); 992 MutexLocker mu(SystemDictionary_lock, THREAD);
985 } 995 }
986 } 996 }
987 997
988 if (host_klass.not_null() && k.not_null()) { 998 if (host_klass.not_null() && k.not_null()) {
989 assert(EnableInvokeDynamic, ""); 999 assert(EnableInvokeDynamic, "");
1000 k->set_host_klass(host_klass());
990 // If it's anonymous, initialize it now, since nobody else will. 1001 // If it's anonymous, initialize it now, since nobody else will.
991 k->class_loader_data()->record_dependency(host_klass(), CHECK_NULL);
992 k->set_host_klass(host_klass());
993 1002
994 { 1003 {
995 MutexLocker mu_r(Compile_lock, THREAD); 1004 MutexLocker mu_r(Compile_lock, THREAD);
996 1005
997 // Add to class hierarchy, initialize vtables, and do possible 1006 // Add to class hierarchy, initialize vtables, and do possible
1000 1009
1001 // But, do not add to system dictionary. 1010 // But, do not add to system dictionary.
1002 } 1011 }
1003 1012
1004 // Rewrite and patch constant pool here. 1013 // Rewrite and patch constant pool here.
1005 k->link_class(THREAD); 1014 k->link_class(CHECK_NULL);
1006 if (cp_patches != NULL) { 1015 if (cp_patches != NULL) {
1007 k->constants()->patch_resolved_references(cp_patches); 1016 k->constants()->patch_resolved_references(cp_patches);
1008 } 1017 }
1009 k->eager_initialize(THREAD); 1018 k->eager_initialize(CHECK_NULL);
1010 1019
1011 // notify jvmti 1020 // notify jvmti
1012 if (JvmtiExport::should_post_class_load()) { 1021 if (JvmtiExport::should_post_class_load()) {
1013 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); 1022 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1014 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); 1023 JvmtiExport::post_class_load((JavaThread *) THREAD, k());
1037 bool DoObjectLock = true; 1046 bool DoObjectLock = true;
1038 if (is_parallelCapable(class_loader)) { 1047 if (is_parallelCapable(class_loader)) {
1039 DoObjectLock = false; 1048 DoObjectLock = false;
1040 } 1049 }
1041 1050
1042 ClassLoaderData* loader_data = register_loader(class_loader); 1051 ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
1043 1052
1044 // Make sure we are synchronized on the class loader before we proceed 1053 // Make sure we are synchronized on the class loader before we proceed
1045 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); 1054 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1046 check_loader_lock_contention(lockObject, THREAD); 1055 check_loader_lock_contention(lockObject, THREAD);
1047 ObjectLocker ol(lockObject, THREAD, DoObjectLock); 1056 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1057 // super classes are loaded (resolve_super_or_fail). We expect this 1066 // super classes are loaded (resolve_super_or_fail). We expect this
1058 // to be called for all classes but java.lang.Object; and we preload 1067 // to be called for all classes but java.lang.Object; and we preload
1059 // java.lang.Object through resolve_or_fail, not this path. 1068 // java.lang.Object through resolve_or_fail, not this path.
1060 1069
1061 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, 1070 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
1062 class_loader, 1071 loader_data,
1063 protection_domain, 1072 protection_domain,
1064 parsed_name, 1073 parsed_name,
1065 verify, 1074 verify,
1066 THREAD); 1075 THREAD);
1067 1076
2341 return spe->method(); 2350 return spe->method();
2342 } 2351 }
2343 2352
2344 // Helper for unpacking the return value from linkMethod and linkCallSite. 2353 // Helper for unpacking the return value from linkMethod and linkCallSite.
2345 static methodHandle unpack_method_and_appendix(Handle mname, 2354 static methodHandle unpack_method_and_appendix(Handle mname,
2355 KlassHandle accessing_klass,
2346 objArrayHandle appendix_box, 2356 objArrayHandle appendix_box,
2347 Handle* appendix_result, 2357 Handle* appendix_result,
2348 TRAPS) { 2358 TRAPS) {
2349 methodHandle empty; 2359 methodHandle empty;
2350 if (mname.not_null()) { 2360 if (mname.not_null()) {
2359 if (appendix != NULL) { tty->print("appendix = "); appendix->print(); } 2369 if (appendix != NULL) { tty->print("appendix = "); appendix->print(); }
2360 tty->cr(); 2370 tty->cr();
2361 #endif //PRODUCT 2371 #endif //PRODUCT
2362 } 2372 }
2363 (*appendix_result) = Handle(THREAD, appendix); 2373 (*appendix_result) = Handle(THREAD, appendix);
2374 // the target is stored in the cpCache and if a reference to this
2375 // MethodName is dropped we need a way to make sure the
2376 // class_loader containing this method is kept alive.
2377 // FIXME: the appendix might also preserve this dependency.
2378 ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data();
2379 this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
2364 return methodHandle(THREAD, m); 2380 return methodHandle(THREAD, m);
2365 } 2381 }
2366 } 2382 }
2367 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty); 2383 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2368 return empty; 2384 return empty;
2403 vmSymbols::linkMethod_name(), 2419 vmSymbols::linkMethod_name(),
2404 vmSymbols::linkMethod_signature(), 2420 vmSymbols::linkMethod_signature(),
2405 &args, CHECK_(empty)); 2421 &args, CHECK_(empty));
2406 Handle mname(THREAD, (oop) result.get_jobject()); 2422 Handle mname(THREAD, (oop) result.get_jobject());
2407 (*method_type_result) = method_type; 2423 (*method_type_result) = method_type;
2408 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); 2424 return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
2409 } 2425 }
2410 2426
2411 2427
2412 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given 2428 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2413 // signature, as interpreted relative to the given class loader. 2429 // signature, as interpreted relative to the given class loader.
2594 vmSymbols::linkCallSite_name(), 2610 vmSymbols::linkCallSite_name(),
2595 vmSymbols::linkCallSite_signature(), 2611 vmSymbols::linkCallSite_signature(),
2596 &args, CHECK_(empty)); 2612 &args, CHECK_(empty));
2597 Handle mname(THREAD, (oop) result.get_jobject()); 2613 Handle mname(THREAD, (oop) result.get_jobject());
2598 (*method_type_result) = method_type; 2614 (*method_type_result) = method_type;
2599 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); 2615 return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD);
2600 } 2616 }
2601 2617
2602 // Since the identity hash code for symbols changes when the symbols are 2618 // Since the identity hash code for symbols changes when the symbols are
2603 // moved from the regular perm gen (hash in the mark word) to the shared 2619 // moved from the regular perm gen (hash in the mark word) to the shared
2604 // spaces (hash is the address), the classes loaded into the dictionary 2620 // spaces (hash is the address), the classes loaded into the dictionary