< 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     }


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


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


5283         return NULL;
5284       }
5285       case JVM_SIGNATURE_ARRAY:
5286         array_dim++;
5287         if (array_dim > 255) {
5288           // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions.
5289           classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0);
5290         }
5291         // The rest of what's there better be a legal signature
5292         signature++;
5293         length--;
5294         void_ok = false;
5295         break;
5296 
5297       default:
5298         return NULL;
5299     }
5300   }
5301   return NULL;
5302 }
























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     }


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


5285         return NULL;
5286       }
5287       case JVM_SIGNATURE_ARRAY:
5288         array_dim++;
5289         if (array_dim > 255) {
5290           // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions.
5291           classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0);
5292         }
5293         // The rest of what's there better be a legal signature
5294         signature++;
5295         length--;
5296         void_ok = false;
5297         break;
5298 
5299       default:
5300         return NULL;
5301     }
5302   }
5303   return NULL;
5304 }
5305 
5306 #if INCLUDE_JFR
5307 
5308 // Caller responsible for ResourceMark
5309 // clone stream with rewound position
5310 ClassFileStream* ClassFileParser::clone_stream() const {
5311   assert(_stream != NULL, "invariant");
5312 
5313   return _stream->clone();
5314 }
5315 
5316 void ClassFileParser::set_klass_to_deallocate(InstanceKlass* klass) {
5317 #ifdef ASSERT
5318   if (klass != NULL) {
5319     assert(NULL == _klass, "leaking?");
5320   }
5321 #endif
5322 
5323   _klass = klass;
5324 }
5325 
5326 #endif // INCLUDE_JFR
< prev index next >