< prev index next >

src/share/vm/classfile/classFileParser.cpp

Print this page




3867 
3868   // Constant pool
3869   constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
3870 
3871   int cp_size = cp->length();
3872 
3873   cfs->guarantee_more(8, CHECK_(nullHandle));  // flags, this_class, super_class, infs_len
3874 
3875   // Access flags
3876   AccessFlags access_flags;
3877   jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
3878 
3879   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
3880     // Set abstract bit for old class files for backward compatibility
3881     flags |= JVM_ACC_ABSTRACT;
3882   }
3883   verify_legal_class_modifiers(flags, CHECK_(nullHandle));
3884   access_flags.set_flags(flags);
3885 
3886   // This class and superclass
3887   u2 this_class_index = cfs->get_u2_fast();
3888   check_property(
3889     valid_cp_range(this_class_index, cp_size) &&
3890       cp->tag_at(this_class_index).is_unresolved_klass(),
3891     "Invalid this class index %u in constant pool in class file %s",
3892     this_class_index, CHECK_(nullHandle));
3893 
3894   Symbol*  class_name  = cp->unresolved_klass_at(this_class_index);
3895   assert(class_name != NULL, "class_name can't be null");
3896 
3897   // It's important to set parsed_name *before* resolving the super class.
3898   // (it's used for cleanup by the caller if parsing fails)
3899   parsed_name = class_name;
3900   // parsed_name is returned and can be used if there's an error, so add to
3901   // its reference count.  Caller will decrement the refcount.
3902   parsed_name->increment_refcount();
3903 
3904   // Update _class_name which could be null previously to be class_name
3905   _class_name = class_name;
3906 
3907   // Don't need to check whether this class name is legal or not.
3908   // It has been checked when constant pool is parsed.
3909   // However, make sure it is not an array type.
3910   if (_need_verify) {
3911     guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
3912                        "Bad class name in class file %s",
3913                        CHECK_(nullHandle));
3914   }


4105     assert(this_klass->size_helper() == info.instance_size, "correct size_helper");
4106     // Not yet: supers are done below to support the new subtype-checking fields
4107     //this_klass->set_super(super_klass());
4108     this_klass->set_class_loader_data(loader_data);
4109     this_klass->set_nonstatic_field_size(info.nonstatic_field_size);
4110     this_klass->set_has_nonstatic_fields(info.has_nonstatic_fields);
4111     this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]);
4112 
4113     apply_parsed_class_metadata(this_klass, java_fields_count, CHECK_NULL);
4114 
4115     if (has_final_method) {
4116       this_klass->set_has_final_method();
4117     }
4118     this_klass->copy_method_ordering(method_ordering, CHECK_NULL);
4119     // The InstanceKlass::_methods_jmethod_ids cache
4120     // is managed on the assumption that the initial cache
4121     // size is equal to the number of methods in the class. If
4122     // that changes, then InstanceKlass::idnum_can_increment()
4123     // has to be changed accordingly.
4124     this_klass->set_initial_method_idnum(methods->length());
4125     this_klass->set_name(cp->klass_name_at(this_class_index));
4126     if (is_anonymous())  // I am well known to myself
4127       cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve
4128 
4129     this_klass->set_minor_version(minor_version);
4130     this_klass->set_major_version(major_version);
4131     this_klass->set_has_default_methods(has_default_methods);
4132     this_klass->set_declares_default_methods(declares_default_methods);
4133 
4134     if (!host_klass.is_null()) {
4135       assert (this_klass->is_anonymous(), "should be the same");
4136       this_klass->set_host_klass(host_klass());
4137     }
4138 
4139     // Set up Method*::intrinsic_id as soon as we know the names of methods.
4140     // (We used to do this lazily, but now we query it in Rewriter,
4141     // which is eagerly done for every method, so we might as well do it now,
4142     // when everything is fresh in memory.)
4143     if (Method::klass_id_for_intrinsics(this_klass()) != vmSymbols::NO_SID) {
4144       for (int j = 0; j < methods->length(); j++) {
4145         methods->at(j)->init_intrinsic_id();
4146       }
4147     }


4245       if (this_klass->java_super() != NULL) {
4246         tty->print("RESOLVE %s %s (super)\n", from, InstanceKlass::cast(this_klass->java_super())->external_name());
4247       }
4248       // print out each of the interface classes referred to by this class.
4249       Array<Klass*>* local_interfaces = this_klass->local_interfaces();
4250       if (local_interfaces != NULL) {
4251         int length = local_interfaces->length();
4252         for (int i = 0; i < length; i++) {
4253           Klass* k = local_interfaces->at(i);
4254           InstanceKlass* to_class = InstanceKlass::cast(k);
4255           const char * to = to_class->external_name();
4256           tty->print("RESOLVE %s %s (interface)\n", from, to);
4257         }
4258       }
4259     }
4260 
4261     // preserve result across HandleMark
4262     preserve_this_klass = this_klass();
4263   }
4264 


4265   // Create new handle outside HandleMark (might be needed for
4266   // Extended Class Redefinition)
4267   instanceKlassHandle this_klass (THREAD, preserve_this_klass);
4268   debug_only(this_klass->verify();)
4269 
4270   // Clear class if no error has occurred so destructor doesn't deallocate it
4271   _klass = NULL;
4272   return this_klass;
4273 }
4274 
4275 // Destructor to clean up if there's an error
4276 ClassFileParser::~ClassFileParser() {
4277   MetadataFactory::free_metadata(_loader_data, _cp);
4278   MetadataFactory::free_array<u2>(_loader_data, _fields);
4279 
4280   // Free methods
4281   InstanceKlass::deallocate_methods(_loader_data, _methods);
4282 
4283   // beware of the Universe::empty_blah_array!!
4284   if (_inner_classes != Universe::the_empty_short_array()) {


5256         return NULL;
5257       }
5258       case JVM_SIGNATURE_ARRAY:
5259         array_dim++;
5260         if (array_dim > 255) {
5261           // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions.
5262           classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0);
5263         }
5264         // The rest of what's there better be a legal signature
5265         signature++;
5266         length--;
5267         void_ok = false;
5268         break;
5269 
5270       default:
5271         return NULL;
5272     }
5273   }
5274   return NULL;
5275 }
























3867 
3868   // Constant pool
3869   constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
3870 
3871   int cp_size = cp->length();
3872 
3873   cfs->guarantee_more(8, CHECK_(nullHandle));  // flags, this_class, super_class, infs_len
3874 
3875   // Access flags
3876   AccessFlags access_flags;
3877   jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
3878 
3879   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
3880     // Set abstract bit for old class files for backward compatibility
3881     flags |= JVM_ACC_ABSTRACT;
3882   }
3883   verify_legal_class_modifiers(flags, CHECK_(nullHandle));
3884   access_flags.set_flags(flags);
3885 
3886   // This class and superclass
3887   _this_class_index = cfs->get_u2_fast();
3888   check_property(
3889     valid_cp_range(_this_class_index, cp_size) &&
3890       cp->tag_at(_this_class_index).is_unresolved_klass(),
3891     "Invalid this class index %u in constant pool in class file %s",
3892     _this_class_index, CHECK_(nullHandle));
3893 
3894   Symbol*  class_name  = cp->unresolved_klass_at(_this_class_index);
3895   assert(class_name != NULL, "class_name can't be null");
3896 
3897   // It's important to set parsed_name *before* resolving the super class.
3898   // (it's used for cleanup by the caller if parsing fails)
3899   parsed_name = class_name;
3900   // parsed_name is returned and can be used if there's an error, so add to
3901   // its reference count.  Caller will decrement the refcount.
3902   parsed_name->increment_refcount();
3903 
3904   // Update _class_name which could be null previously to be class_name
3905   _class_name = class_name;
3906 
3907   // Don't need to check whether this class name is legal or not.
3908   // It has been checked when constant pool is parsed.
3909   // However, make sure it is not an array type.
3910   if (_need_verify) {
3911     guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
3912                        "Bad class name in class file %s",
3913                        CHECK_(nullHandle));
3914   }


4105     assert(this_klass->size_helper() == info.instance_size, "correct size_helper");
4106     // Not yet: supers are done below to support the new subtype-checking fields
4107     //this_klass->set_super(super_klass());
4108     this_klass->set_class_loader_data(loader_data);
4109     this_klass->set_nonstatic_field_size(info.nonstatic_field_size);
4110     this_klass->set_has_nonstatic_fields(info.has_nonstatic_fields);
4111     this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]);
4112 
4113     apply_parsed_class_metadata(this_klass, java_fields_count, CHECK_NULL);
4114 
4115     if (has_final_method) {
4116       this_klass->set_has_final_method();
4117     }
4118     this_klass->copy_method_ordering(method_ordering, CHECK_NULL);
4119     // The InstanceKlass::_methods_jmethod_ids cache
4120     // is managed on the assumption that the initial cache
4121     // size is equal to the number of methods in the class. If
4122     // that changes, then InstanceKlass::idnum_can_increment()
4123     // has to be changed accordingly.
4124     this_klass->set_initial_method_idnum(methods->length());
4125     this_klass->set_name(cp->klass_name_at(_this_class_index));
4126     if (is_anonymous())  // I am well known to myself
4127       cp->klass_at_put(_this_class_index, this_klass()); // eagerly resolve
4128 
4129     this_klass->set_minor_version(minor_version);
4130     this_klass->set_major_version(major_version);
4131     this_klass->set_has_default_methods(has_default_methods);
4132     this_klass->set_declares_default_methods(declares_default_methods);
4133 
4134     if (!host_klass.is_null()) {
4135       assert (this_klass->is_anonymous(), "should be the same");
4136       this_klass->set_host_klass(host_klass());
4137     }
4138 
4139     // Set up Method*::intrinsic_id as soon as we know the names of methods.
4140     // (We used to do this lazily, but now we query it in Rewriter,
4141     // which is eagerly done for every method, so we might as well do it now,
4142     // when everything is fresh in memory.)
4143     if (Method::klass_id_for_intrinsics(this_klass()) != vmSymbols::NO_SID) {
4144       for (int j = 0; j < methods->length(); j++) {
4145         methods->at(j)->init_intrinsic_id();
4146       }
4147     }


4245       if (this_klass->java_super() != NULL) {
4246         tty->print("RESOLVE %s %s (super)\n", from, InstanceKlass::cast(this_klass->java_super())->external_name());
4247       }
4248       // print out each of the interface classes referred to by this class.
4249       Array<Klass*>* local_interfaces = this_klass->local_interfaces();
4250       if (local_interfaces != NULL) {
4251         int length = local_interfaces->length();
4252         for (int i = 0; i < length; i++) {
4253           Klass* k = local_interfaces->at(i);
4254           InstanceKlass* to_class = InstanceKlass::cast(k);
4255           const char * to = to_class->external_name();
4256           tty->print("RESOLVE %s %s (interface)\n", from, to);
4257         }
4258       }
4259     }
4260 
4261     // preserve result across HandleMark
4262     preserve_this_klass = this_klass();
4263   }
4264 
4265   JFR_ONLY(INIT_ID(preserve_this_klass);)
4266 
4267   // Create new handle outside HandleMark (might be needed for
4268   // Extended Class Redefinition)
4269   instanceKlassHandle this_klass (THREAD, preserve_this_klass);
4270   debug_only(this_klass->verify();)
4271 
4272   // Clear class if no error has occurred so destructor doesn't deallocate it
4273   _klass = NULL;
4274   return this_klass;
4275 }
4276 
4277 // Destructor to clean up if there's an error
4278 ClassFileParser::~ClassFileParser() {
4279   MetadataFactory::free_metadata(_loader_data, _cp);
4280   MetadataFactory::free_array<u2>(_loader_data, _fields);
4281 
4282   // Free methods
4283   InstanceKlass::deallocate_methods(_loader_data, _methods);
4284 
4285   // beware of the Universe::empty_blah_array!!
4286   if (_inner_classes != Universe::the_empty_short_array()) {


5258         return NULL;
5259       }
5260       case JVM_SIGNATURE_ARRAY:
5261         array_dim++;
5262         if (array_dim > 255) {
5263           // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions.
5264           classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0);
5265         }
5266         // The rest of what's there better be a legal signature
5267         signature++;
5268         length--;
5269         void_ok = false;
5270         break;
5271 
5272       default:
5273         return NULL;
5274     }
5275   }
5276   return NULL;
5277 }
5278 
5279 #if INCLUDE_JFR
5280 
5281 // Caller responsible for ResourceMark
5282 // clone stream with rewound position
5283 ClassFileStream* ClassFileParser::clone_stream() const {
5284   assert(_stream != NULL, "invariant");
5285 
5286   return _stream->clone();
5287 }
5288 
5289 void ClassFileParser::set_klass_to_deallocate(InstanceKlass* klass) {
5290 #ifdef ASSERT
5291   if (klass != NULL) {
5292     assert(NULL == _klass, "leaking?");
5293   }
5294 #endif
5295 
5296   _klass = klass;
5297 }
5298 
5299 #endif // INCLUDE_JFR
< prev index next >