hotspot/src/share/vm/classfile/classFileParser.cpp
changeset 13952 e3cf184080bc
parent 13738 d67be49a5beb
child 14079 5e5c9b7ce8cb
child 13974 791cba24758f
equal deleted inserted replaced
13918:b01a48301e67 13952:e3cf184080bc
   780 }
   780 }
   781 
   781 
   782 
   782 
   783 Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp,
   783 Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp,
   784                                                  int length,
   784                                                  int length,
   785                                                    ClassLoaderData* loader_data,
   785                                                  ClassLoaderData* loader_data,
   786                                                  Handle protection_domain,
   786                                                  Handle protection_domain,
   787                                                  Symbol* class_name,
   787                                                  Symbol* class_name,
   788                                                  TRAPS) {
   788                                                  TRAPS) {
   789   ClassFileStream* cfs = stream();
   789   ClassFileStream* cfs = stream();
   790   assert(length > 0, "only called for length>0");
   790   assert(length > 0, "only called for length>0");
  1070   }
  1070   }
  1071 };
  1071 };
  1072 
  1072 
  1073 Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data,
  1073 Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data,
  1074                                          Symbol* class_name,
  1074                                          Symbol* class_name,
  1075                                               constantPoolHandle cp, bool is_interface,
  1075                                          constantPoolHandle cp,
  1076                                               FieldAllocationCount *fac,
  1076                                          bool is_interface,
       
  1077                                          FieldAllocationCount *fac,
  1077                                          Array<AnnotationArray*>** fields_annotations,
  1078                                          Array<AnnotationArray*>** fields_annotations,
  1078                                               u2* java_fields_count_ptr, TRAPS) {
  1079                                          u2* java_fields_count_ptr, TRAPS) {
  1079   ClassFileStream* cfs = stream();
  1080   ClassFileStream* cfs = stream();
  1080   cfs->guarantee_more(2, CHECK_NULL);  // length
  1081   cfs->guarantee_more(2, CHECK_NULL);  // length
  1081   u2 length = cfs->get_u2_fast();
  1082   u2 length = cfs->get_u2_fast();
  1082   *java_fields_count_ptr = length;
  1083   *java_fields_count_ptr = length;
  1083 
  1084 
  2167     guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute,
  2168     guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute,
  2168                       "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle));
  2169                       "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle));
  2169   }
  2170   }
  2170 
  2171 
  2171   // All sizing information for a Method* is finally available, now create it
  2172   // All sizing information for a Method* is finally available, now create it
  2172   Method* m = Method::allocate(loader_data,
  2173   Method* m = Method::allocate(loader_data, code_length, access_flags,
  2173                                         code_length,
  2174                                linenumber_table_length,
  2174                                         access_flags,
  2175                                total_lvt_length,
  2175                                             linenumber_table_length,
  2176                                exception_table_length,
  2176                                             total_lvt_length,
  2177                                checked_exceptions_length,
  2177                                             exception_table_length,
  2178                                CHECK_(nullHandle));
  2178                                             checked_exceptions_length,
       
  2179                                             CHECK_(nullHandle));
       
  2180 
  2179 
  2181   ClassLoadingService::add_class_method_size(m->size()*HeapWordSize);
  2180   ClassLoadingService::add_class_method_size(m->size()*HeapWordSize);
  2182 
  2181 
  2183   // Fill in information from fixed part (access_flags already set)
  2182   // Fill in information from fixed part (access_flags already set)
  2184   m->set_constants(cp());
  2183   m->set_constants(cp());
  2349 // The promoted_flags parameter is used to pass relevant access_flags
  2348 // The promoted_flags parameter is used to pass relevant access_flags
  2350 // from the methods back up to the containing klass. These flag values
  2349 // from the methods back up to the containing klass. These flag values
  2351 // are added to klass's access_flags.
  2350 // are added to klass's access_flags.
  2352 
  2351 
  2353 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data,
  2352 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data,
  2354                                                  constantPoolHandle cp,
  2353                                                constantPoolHandle cp,
  2355                                                  bool is_interface,
  2354                                                bool is_interface,
  2356                                               AccessFlags* promoted_flags,
  2355                                                AccessFlags* promoted_flags,
  2357                                               bool* has_final_method,
  2356                                                bool* has_final_method,
  2358                                                  Array<AnnotationArray*>** methods_annotations,
  2357                                                Array<AnnotationArray*>** methods_annotations,
  2359                                                  Array<AnnotationArray*>** methods_parameter_annotations,
  2358                                                Array<AnnotationArray*>** methods_parameter_annotations,
  2360                                                  Array<AnnotationArray*>** methods_default_annotations,
  2359                                                Array<AnnotationArray*>** methods_default_annotations,
  2361                                               TRAPS) {
  2360                                                TRAPS) {
  2362   ClassFileStream* cfs = stream();
  2361   ClassFileStream* cfs = stream();
  2363   AnnotationArray* method_annotations = NULL;
  2362   AnnotationArray* method_annotations = NULL;
  2364   AnnotationArray* method_parameter_annotations = NULL;
  2363   AnnotationArray* method_parameter_annotations = NULL;
  2365   AnnotationArray* method_default_annotations = NULL;
  2364   AnnotationArray* method_default_annotations = NULL;
  2366   cfs->guarantee_more(2, CHECK_NULL);  // length
  2365   cfs->guarantee_more(2, CHECK_NULL);  // length
  2448       m->set_vtable_index(index);
  2447       m->set_vtable_index(index);
  2449     }
  2448     }
  2450   }
  2449   }
  2451   // Sort method array by ascending method name (for faster lookups & vtable construction)
  2450   // Sort method array by ascending method name (for faster lookups & vtable construction)
  2452   // Note that the ordering is not alphabetical, see Symbol::fast_compare
  2451   // Note that the ordering is not alphabetical, see Symbol::fast_compare
  2453   Method::sort_methods(methods,
  2452   Method::sort_methods(methods, methods_annotations,
  2454                               methods_annotations,
  2453                        methods_parameter_annotations,
  2455                               methods_parameter_annotations,
  2454                        methods_default_annotations);
  2456                               methods_default_annotations);
       
  2457 
  2455 
  2458   // If JVMTI original method ordering or sharing is enabled construct int
  2456   // If JVMTI original method ordering or sharing is enabled construct int
  2459   // array remembering the original ordering
  2457   // array remembering the original ordering
  2460   if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) {
  2458   if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) {
  2461     Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL);
  2459     Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL);
  2833       cfs->skip_u1(attribute_length, CHECK);
  2831       cfs->skip_u1(attribute_length, CHECK);
  2834     }
  2832     }
  2835   }
  2833   }
  2836   AnnotationArray* annotations = assemble_annotations(loader_data,
  2834   AnnotationArray* annotations = assemble_annotations(loader_data,
  2837                                                       runtime_visible_annotations,
  2835                                                       runtime_visible_annotations,
  2838                                                      runtime_visible_annotations_length,
  2836                                                       runtime_visible_annotations_length,
  2839                                                      runtime_invisible_annotations,
  2837                                                       runtime_invisible_annotations,
  2840                                                      runtime_invisible_annotations_length,
  2838                                                       runtime_invisible_annotations_length,
  2841                                                      CHECK);
  2839                                                       CHECK);
  2842   set_class_annotations(annotations);
  2840   set_class_annotations(annotations);
  2843 
  2841 
  2844   if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
  2842   if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
  2845     u2 num_of_classes = parse_classfile_inner_classes_attribute(
  2843     u2 num_of_classes = parse_classfile_inner_classes_attribute(
  2846                             loader_data,
  2844                             loader_data,
  2882   }
  2880   }
  2883 }
  2881 }
  2884 
  2882 
  2885 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data,
  2883 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data,
  2886                                                        u1* runtime_visible_annotations,
  2884                                                        u1* runtime_visible_annotations,
  2887                                                       int runtime_visible_annotations_length,
  2885                                                        int runtime_visible_annotations_length,
  2888                                                       u1* runtime_invisible_annotations,
  2886                                                        u1* runtime_invisible_annotations,
  2889                                                       int runtime_invisible_annotations_length, TRAPS) {
  2887                                                        int runtime_invisible_annotations_length, TRAPS) {
  2890   AnnotationArray* annotations = NULL;
  2888   AnnotationArray* annotations = NULL;
  2891   if (runtime_visible_annotations != NULL ||
  2889   if (runtime_visible_annotations != NULL ||
  2892       runtime_invisible_annotations != NULL) {
  2890       runtime_invisible_annotations != NULL) {
  2893     annotations = MetadataFactory::new_array<u1>(loader_data,
  2891     annotations = MetadataFactory::new_array<u1>(loader_data,
  2894                                           runtime_visible_annotations_length +
  2892                                           runtime_visible_annotations_length +
  3159     // inside parse_methods inside a nested HandleMark
  3157     // inside parse_methods inside a nested HandleMark
  3160     Array<AnnotationArray*>* methods_annotations = NULL;
  3158     Array<AnnotationArray*>* methods_annotations = NULL;
  3161     Array<AnnotationArray*>* methods_parameter_annotations = NULL;
  3159     Array<AnnotationArray*>* methods_parameter_annotations = NULL;
  3162     Array<AnnotationArray*>* methods_default_annotations = NULL;
  3160     Array<AnnotationArray*>* methods_default_annotations = NULL;
  3163     Array<Method*>* methods = parse_methods(loader_data,
  3161     Array<Method*>* methods = parse_methods(loader_data,
  3164                                               cp, access_flags.is_interface(),
  3162                                             cp, access_flags.is_interface(),
  3165                                            &promoted_flags,
  3163                                             &promoted_flags,
  3166                                            &has_final_method,
  3164                                             &has_final_method,
  3167                                               &methods_annotations,
  3165                                             &methods_annotations,
  3168                                               &methods_parameter_annotations,
  3166                                             &methods_parameter_annotations,
  3169                                               &methods_default_annotations,
  3167                                             &methods_default_annotations,
  3170                                            CHECK_(nullHandle));
  3168                                             CHECK_(nullHandle));
  3171 
  3169 
  3172     // Additional attributes
  3170     // Additional attributes
  3173     ClassAnnotationCollector parsed_annotations;
  3171     ClassAnnotationCollector parsed_annotations;
  3174     parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle));
  3172     parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle));
  3175 
  3173 
  3184         // errors not checked yet.
  3182         // errors not checked yet.
  3185         guarantee_property(sk == vmSymbols::java_lang_Object(),
  3183         guarantee_property(sk == vmSymbols::java_lang_Object(),
  3186                            "Interfaces must have java.lang.Object as superclass in class file %s",
  3184                            "Interfaces must have java.lang.Object as superclass in class file %s",
  3187                            CHECK_(nullHandle));
  3185                            CHECK_(nullHandle));
  3188       }
  3186       }
  3189       Klass* k = SystemDictionary::resolve_super_or_fail(class_name,
  3187       Klass* k = SystemDictionary::resolve_super_or_fail(class_name, sk,
  3190                                                            sk,
  3188                                                          class_loader,
  3191                                                            class_loader,
  3189                                                          protection_domain,
  3192                                                            protection_domain,
  3190                                                          true,
  3193                                                            true,
  3191                                                          CHECK_(nullHandle));
  3194                                                            CHECK_(nullHandle));
       
  3195 
  3192 
  3196       KlassHandle kh (THREAD, k);
  3193       KlassHandle kh (THREAD, k);
  3197       super_klass = instanceKlassHandle(THREAD, kh());
  3194       super_klass = instanceKlassHandle(THREAD, kh());
  3198       if (LinkWellKnownClasses)  // my super class is well known to me
  3195       if (LinkWellKnownClasses)  // my super class is well known to me
  3199         cp->klass_at_put(super_class_index, super_klass()); // eagerly resolve
  3196         cp->klass_at_put(super_class_index, super_klass()); // eagerly resolve
  3220     Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle));
  3217     Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle));
  3221 
  3218 
  3222     // sort methods
  3219     // sort methods
  3223     Array<int>* method_ordering = sort_methods(loader_data,
  3220     Array<int>* method_ordering = sort_methods(loader_data,
  3224                                                methods,
  3221                                                methods,
  3225                                                    methods_annotations,
  3222                                                methods_annotations,
  3226                                                    methods_parameter_annotations,
  3223                                                methods_parameter_annotations,
  3227                                                    methods_default_annotations,
  3224                                                methods_default_annotations,
  3228                                                    CHECK_(nullHandle));
  3225                                                CHECK_(nullHandle));
  3229 
  3226 
  3230     // promote flags from parse_methods() to the klass' flags
  3227     // promote flags from parse_methods() to the klass' flags
  3231     access_flags.add_promoted_flags(promoted_flags.as_int());
  3228     access_flags.add_promoted_flags(promoted_flags.as_int());
  3232 
  3229 
  3233     // Size of Java vtable (in words)
  3230     // Size of Java vtable (in words)
  3589     // We can now create the basic Klass* for this klass
  3586     // We can now create the basic Klass* for this klass
  3590     int total_oop_map_size2 =
  3587     int total_oop_map_size2 =
  3591       InstanceKlass::nonstatic_oop_map_size(total_oop_map_count);
  3588       InstanceKlass::nonstatic_oop_map_size(total_oop_map_count);
  3592 
  3589 
  3593     Klass* ik = InstanceKlass::allocate_instance_klass(loader_data,
  3590     Klass* ik = InstanceKlass::allocate_instance_klass(loader_data,
  3594                                                          vtable_size,
  3591                                                        vtable_size,
  3595                                                          itable_size,
  3592                                                        itable_size,
  3596                                                 static_field_size,
  3593                                                        static_field_size,
  3597                                                          total_oop_map_size2,
  3594                                                        total_oop_map_size2,
  3598                                                          rt,
  3595                                                        rt,
  3599                                                 access_flags,
  3596                                                        access_flags,
  3600                                                          name,
  3597                                                        name,
  3601                                                          super_klass(),
  3598                                                        super_klass(),
  3602                                                          host_klass,
  3599                                                        host_klass,
  3603                                                 CHECK_(nullHandle));
  3600                                                        CHECK_(nullHandle));
  3604 
  3601 
  3605     // Add all classes to our internal class loader list here,
  3602     // Add all classes to our internal class loader list here,
  3606     // including classes in the bootstrap (NULL) class loader.
  3603     // including classes in the bootstrap (NULL) class loader.
  3607     loader_data->add_class(ik);
  3604     loader_data->add_class(ik);
  3608 
  3605