< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page




4057     }
4058   }
4059 
4060   // Adjusting non_static_oop_count to take into account not flattened value types;
4061   nonstatic_oop_count += not_flattened_value_types;
4062 
4063   // Total non-static fields count, including every contended field
4064   unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] +
4065                                         fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] +
4066                                         fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_FLATTENABLE];
4067 
4068   const bool super_has_nonstatic_fields =
4069           (_super_klass != NULL && _super_klass->has_nonstatic_fields());
4070   const bool has_nonstatic_fields =
4071     super_has_nonstatic_fields || (nonstatic_fields_count != 0);
4072   const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0;
4073 
4074   if (is_value_type() && (!has_nonstatic_fields)) {
4075     // There are a number of fixes required throughout the type system and JIT
4076     throwValueTypeLimitation(THREAD_AND_LOCATION, "Value Types do not support zero instance size yet");

4077   }
4078 
4079   // Prepare list of oops for oop map generation.
4080   //
4081   // "offset" and "count" lists are describing the set of contiguous oop
4082   // regions. offset[i] is the start of the i-th region, which then has
4083   // count[i] oops following. Before we know how many regions are required,
4084   // we pessimistically allocate the maps to fit all the oops into the
4085   // distinct regions.
4086   //
4087   int super_oop_map_count = (_super_klass == NULL) ? 0 :_super_klass->nonstatic_oop_map_count();
4088   int max_oop_map_count =
4089       super_oop_map_count +
4090       fac->count[NONSTATIC_OOP] +
4091       value_type_oop_map_count +
4092       not_flattened_value_types;
4093 
4094   OopMapBlocksBuilder* nonstatic_oop_maps = new OopMapBlocksBuilder(max_oop_map_count, THREAD);
4095   if (super_oop_map_count > 0) {
4096     nonstatic_oop_maps->initialize_inherited_blocks(_super_klass->start_of_nonstatic_oop_maps(),


4514     print_field_layout(_class_name,
4515           _fields,
4516           cp,
4517           instance_size,
4518           nonstatic_fields_start,
4519           nonstatic_fields_end,
4520           static_fields_end);
4521     nonstatic_oop_maps->print_on(tty);
4522     tty->print("\n");
4523   }
4524 
4525 #endif
4526   // Pass back information needed for InstanceKlass creation
4527   info->oop_map_blocks = nonstatic_oop_maps;
4528   info->instance_size = instance_size;
4529   info->static_field_size = static_field_size;
4530   info->nonstatic_field_size = nonstatic_field_size;
4531   info->has_nonstatic_fields = has_nonstatic_fields;
4532 }
4533 
4534 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) {
4535   assert(ik != NULL, "invariant");
4536 
4537   const Klass* const super = ik->super();
4538 
4539   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4540   // in which case we don't have to register objects as finalizable
4541   if (!_has_empty_finalizer) {
4542     if (_has_finalizer ||
4543         (super != NULL && super->has_finalizer())) {
4544       ik->set_has_finalizer();
4545     }
4546   }
4547 
4548 #ifdef ASSERT
4549   bool f = false;
4550   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4551                                            vmSymbols::void_method_signature());
4552   if (m != NULL && !m->is_empty_method()) {
4553       f = true;
4554   }
4555 
4556   // Spec doesn't prevent agent from redefinition of empty finalizer.
4557   // Despite the fact that it's generally bad idea and redefined finalizer
4558   // will not work as expected we shouldn't abort vm in this case
4559   if (!ik->has_redefined_this_or_super()) {
4560     assert(ik->has_finalizer() == f, "inconsistent has_finalizer");
4561   }
4562 #endif
4563 
4564   // Check if this klass supports the java.lang.Cloneable interface
4565   if (SystemDictionary::Cloneable_klass_loaded()) {
4566     if (ik->is_subtype_of(SystemDictionary::Cloneable_klass())) {




4567       ik->set_is_cloneable();
4568     }
4569   }
4570 
4571   // Check if this klass has a vanilla default constructor
4572   if (super == NULL) {
4573     // java.lang.Object has empty default constructor
4574     ik->set_has_vanilla_constructor();
4575   } else {
4576     if (super->has_vanilla_constructor() &&
4577         _has_vanilla_constructor) {
4578       ik->set_has_vanilla_constructor();
4579     }
4580 #ifdef ASSERT
4581     bool v = false;
4582     if (super->has_vanilla_constructor()) {
4583       const Method* const constructor =
4584         ik->find_method(vmSymbols::object_initializer_name(),
4585                        vmSymbols::void_method_signature());
4586       if (constructor != NULL && constructor->is_vanilla_constructor()) {


5723       (_super_klass != NULL && _super_klass->has_miranda_methods())
5724         // super class exists and this class inherited miranda methods
5725      ) {
5726        ik->set_has_miranda_methods(); // then set a flag
5727   }
5728 
5729   // Fill in information needed to compute superclasses.
5730   ik->initialize_supers(const_cast<InstanceKlass*>(_super_klass), CHECK);
5731 
5732   // Initialize itable offset tables
5733   klassItable::setup_itable_offset_table(ik);
5734 
5735   // Compute transitive closure of interfaces this class implements
5736   // Do final class setup
5737   OopMapBlocksBuilder* oop_map_blocks = _field_info->oop_map_blocks;
5738   if (oop_map_blocks->nonstatic_oop_map_count > 0) {
5739     oop_map_blocks->copy(ik->start_of_nonstatic_oop_maps());
5740   }
5741 
5742   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5743   set_precomputed_flags(ik);
5744 
5745   // check if this class can access its super class
5746   check_super_class_access(ik, CHECK);
5747 
5748   // check if this class can access its superinterfaces
5749   check_super_interface_access(ik, CHECK);
5750 
5751   // check if this class overrides any final method
5752   check_final_method_override(ik, CHECK);
5753 
5754   // reject static interface methods prior to Java 8
5755   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {
5756     check_illegal_static_method(ik, CHECK);
5757   }
5758 
5759   // Obtain this_klass' module entry
5760   ModuleEntry* module_entry = ik->module();
5761   assert(module_entry != NULL, "module_entry should always be set");
5762 
5763   // Obtain java.lang.Module




4057     }
4058   }
4059 
4060   // Adjusting non_static_oop_count to take into account not flattened value types;
4061   nonstatic_oop_count += not_flattened_value_types;
4062 
4063   // Total non-static fields count, including every contended field
4064   unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] +
4065                                         fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] +
4066                                         fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_FLATTENABLE];
4067 
4068   const bool super_has_nonstatic_fields =
4069           (_super_klass != NULL && _super_klass->has_nonstatic_fields());
4070   const bool has_nonstatic_fields =
4071     super_has_nonstatic_fields || (nonstatic_fields_count != 0);
4072   const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0;
4073 
4074   if (is_value_type() && (!has_nonstatic_fields)) {
4075     // There are a number of fixes required throughout the type system and JIT
4076     throwValueTypeLimitation(THREAD_AND_LOCATION, "Value Types do not support zero instance size yet");
4077     return;
4078   }
4079 
4080   // Prepare list of oops for oop map generation.
4081   //
4082   // "offset" and "count" lists are describing the set of contiguous oop
4083   // regions. offset[i] is the start of the i-th region, which then has
4084   // count[i] oops following. Before we know how many regions are required,
4085   // we pessimistically allocate the maps to fit all the oops into the
4086   // distinct regions.
4087   //
4088   int super_oop_map_count = (_super_klass == NULL) ? 0 :_super_klass->nonstatic_oop_map_count();
4089   int max_oop_map_count =
4090       super_oop_map_count +
4091       fac->count[NONSTATIC_OOP] +
4092       value_type_oop_map_count +
4093       not_flattened_value_types;
4094 
4095   OopMapBlocksBuilder* nonstatic_oop_maps = new OopMapBlocksBuilder(max_oop_map_count, THREAD);
4096   if (super_oop_map_count > 0) {
4097     nonstatic_oop_maps->initialize_inherited_blocks(_super_klass->start_of_nonstatic_oop_maps(),


4515     print_field_layout(_class_name,
4516           _fields,
4517           cp,
4518           instance_size,
4519           nonstatic_fields_start,
4520           nonstatic_fields_end,
4521           static_fields_end);
4522     nonstatic_oop_maps->print_on(tty);
4523     tty->print("\n");
4524   }
4525 
4526 #endif
4527   // Pass back information needed for InstanceKlass creation
4528   info->oop_map_blocks = nonstatic_oop_maps;
4529   info->instance_size = instance_size;
4530   info->static_field_size = static_field_size;
4531   info->nonstatic_field_size = nonstatic_field_size;
4532   info->has_nonstatic_fields = has_nonstatic_fields;
4533 }
4534 
4535 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik, TRAPS) {
4536   assert(ik != NULL, "invariant");
4537 
4538   const Klass* const super = ik->super();
4539 
4540   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4541   // in which case we don't have to register objects as finalizable
4542   if (!_has_empty_finalizer) {
4543     if (_has_finalizer ||
4544         (super != NULL && super->has_finalizer())) {
4545       ik->set_has_finalizer();
4546     }
4547   }
4548 
4549 #ifdef ASSERT
4550   bool f = false;
4551   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4552                                            vmSymbols::void_method_signature());
4553   if (m != NULL && !m->is_empty_method()) {
4554       f = true;
4555   }
4556 
4557   // Spec doesn't prevent agent from redefinition of empty finalizer.
4558   // Despite the fact that it's generally bad idea and redefined finalizer
4559   // will not work as expected we shouldn't abort vm in this case
4560   if (!ik->has_redefined_this_or_super()) {
4561     assert(ik->has_finalizer() == f, "inconsistent has_finalizer");
4562   }
4563 #endif
4564 
4565   // Check if this klass supports the java.lang.Cloneable interface
4566   if (SystemDictionary::Cloneable_klass_loaded()) {
4567     if (ik->is_subtype_of(SystemDictionary::Cloneable_klass())) {
4568       if (ik->is_value()) {
4569         throwValueTypeLimitation(THREAD_AND_LOCATION, "Value Types do not support Cloneable");
4570         return;
4571       }
4572       ik->set_is_cloneable();
4573     }
4574   }
4575 
4576   // Check if this klass has a vanilla default constructor
4577   if (super == NULL) {
4578     // java.lang.Object has empty default constructor
4579     ik->set_has_vanilla_constructor();
4580   } else {
4581     if (super->has_vanilla_constructor() &&
4582         _has_vanilla_constructor) {
4583       ik->set_has_vanilla_constructor();
4584     }
4585 #ifdef ASSERT
4586     bool v = false;
4587     if (super->has_vanilla_constructor()) {
4588       const Method* const constructor =
4589         ik->find_method(vmSymbols::object_initializer_name(),
4590                        vmSymbols::void_method_signature());
4591       if (constructor != NULL && constructor->is_vanilla_constructor()) {


5728       (_super_klass != NULL && _super_klass->has_miranda_methods())
5729         // super class exists and this class inherited miranda methods
5730      ) {
5731        ik->set_has_miranda_methods(); // then set a flag
5732   }
5733 
5734   // Fill in information needed to compute superclasses.
5735   ik->initialize_supers(const_cast<InstanceKlass*>(_super_klass), CHECK);
5736 
5737   // Initialize itable offset tables
5738   klassItable::setup_itable_offset_table(ik);
5739 
5740   // Compute transitive closure of interfaces this class implements
5741   // Do final class setup
5742   OopMapBlocksBuilder* oop_map_blocks = _field_info->oop_map_blocks;
5743   if (oop_map_blocks->nonstatic_oop_map_count > 0) {
5744     oop_map_blocks->copy(ik->start_of_nonstatic_oop_maps());
5745   }
5746 
5747   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5748   set_precomputed_flags(ik, CHECK);
5749 
5750   // check if this class can access its super class
5751   check_super_class_access(ik, CHECK);
5752 
5753   // check if this class can access its superinterfaces
5754   check_super_interface_access(ik, CHECK);
5755 
5756   // check if this class overrides any final method
5757   check_final_method_override(ik, CHECK);
5758 
5759   // reject static interface methods prior to Java 8
5760   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {
5761     check_illegal_static_method(ik, CHECK);
5762   }
5763 
5764   // Obtain this_klass' module entry
5765   ModuleEntry* module_entry = ik->module();
5766   assert(module_entry != NULL, "module_entry should always be set");
5767 
5768   // Obtain java.lang.Module


< prev index next >