hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 15935 50da9e5eb858
parent 15930 b684d8cc0108
child 16667 f0c0139a2125
child 16611 6807a703dd6b
equal deleted inserted replaced
15934:104ff83451f1 15935:50da9e5eb858
   163 
   163 
   164 #endif //  ndef DTRACE_ENABLED
   164 #endif //  ndef DTRACE_ENABLED
   165 
   165 
   166 volatile int InstanceKlass::_total_instanceKlass_count = 0;
   166 volatile int InstanceKlass::_total_instanceKlass_count = 0;
   167 
   167 
   168 Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data,
   168 InstanceKlass* InstanceKlass::allocate_instance_klass(
       
   169                                               ClassLoaderData* loader_data,
   169                                               int vtable_len,
   170                                               int vtable_len,
   170                                               int itable_len,
   171                                               int itable_len,
   171                                               int static_field_size,
   172                                               int static_field_size,
   172                                               int nonstatic_oop_map_size,
   173                                               int nonstatic_oop_map_size,
   173                                               ReferenceType rt,
   174                                               ReferenceType rt,
   205     ik = new (loader_data, size, THREAD) InstanceRefKlass(
   206     ik = new (loader_data, size, THREAD) InstanceRefKlass(
   206         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
   207         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
   207         access_flags, is_anonymous);
   208         access_flags, is_anonymous);
   208   }
   209   }
   209 
   210 
       
   211   // Check for pending exception before adding to the loader data and incrementing
       
   212   // class count.  Can get OOM here.
       
   213   if (HAS_PENDING_EXCEPTION) {
       
   214     return NULL;
       
   215   }
       
   216 
       
   217   // Add all classes to our internal class loader list here,
       
   218   // including classes in the bootstrap (NULL) class loader.
       
   219   loader_data->add_class(ik);
       
   220 
   210   Atomic::inc(&_total_instanceKlass_count);
   221   Atomic::inc(&_total_instanceKlass_count);
   211   return ik;
   222   return ik;
   212 }
   223 }
       
   224 
       
   225 
       
   226 // copy method ordering from resource area to Metaspace
       
   227 void InstanceKlass::copy_method_ordering(intArray* m, TRAPS) {
       
   228   if (m != NULL) {
       
   229     // allocate a new array and copy contents (memcpy?)
       
   230     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
       
   231     for (int i = 0; i < m->length(); i++) {
       
   232       _method_ordering->at_put(i, m->at(i));
       
   233     }
       
   234   } else {
       
   235     _method_ordering = Universe::the_empty_int_array();
       
   236   }
       
   237 }
       
   238 
   213 
   239 
   214 InstanceKlass::InstanceKlass(int vtable_len,
   240 InstanceKlass::InstanceKlass(int vtable_len,
   215                              int itable_len,
   241                              int itable_len,
   216                              int static_field_size,
   242                              int static_field_size,
   217                              int nonstatic_oop_map_size,
   243                              int nonstatic_oop_map_size,
   221   No_Safepoint_Verifier no_safepoint; // until k becomes parsable
   247   No_Safepoint_Verifier no_safepoint; // until k becomes parsable
   222 
   248 
   223   int iksize = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
   249   int iksize = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
   224                                    access_flags.is_interface(), is_anonymous);
   250                                    access_flags.is_interface(), is_anonymous);
   225 
   251 
   226   // The sizes of these these three variables are used for determining the
       
   227   // size of the instanceKlassOop. It is critical that these are set to the right
       
   228   // sizes before the first GC, i.e., when we allocate the mirror.
       
   229   set_vtable_length(vtable_len);
   252   set_vtable_length(vtable_len);
   230   set_itable_length(itable_len);
   253   set_itable_length(itable_len);
   231   set_static_field_size(static_field_size);
   254   set_static_field_size(static_field_size);
   232   set_nonstatic_oop_map_size(nonstatic_oop_map_size);
   255   set_nonstatic_oop_map_size(nonstatic_oop_map_size);
   233   set_access_flags(access_flags);
   256   set_access_flags(access_flags);
   286   // size.
   309   // size.
   287   set_layout_helper(Klass::instance_layout_helper(0, true));
   310   set_layout_helper(Klass::instance_layout_helper(0, true));
   288 }
   311 }
   289 
   312 
   290 
   313 
       
   314 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
       
   315                                        Array<Method*>* methods) {
       
   316   if (methods != NULL && methods != Universe::the_empty_method_array()) {
       
   317     for (int i = 0; i < methods->length(); i++) {
       
   318       Method* method = methods->at(i);
       
   319       if (method == NULL) continue;  // maybe null if error processing
       
   320       // Only want to delete methods that are not executing for RedefineClasses.
       
   321       // The previous version will point to them so they're not totally dangling
       
   322       assert (!method->on_stack(), "shouldn't be called with methods on stack");
       
   323       MetadataFactory::free_metadata(loader_data, method);
       
   324     }
       
   325     MetadataFactory::free_array<Method*>(loader_data, methods);
       
   326   }
       
   327 }
       
   328 
       
   329 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
       
   330                                           Klass* super_klass,
       
   331                                           Array<Klass*>* local_interfaces,
       
   332                                           Array<Klass*>* transitive_interfaces) {
       
   333   // Only deallocate transitive interfaces if not empty, same as super class
       
   334   // or same as local interfaces.  See code in parseClassFile.
       
   335   Array<Klass*>* ti = transitive_interfaces;
       
   336   if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) {
       
   337     // check that the interfaces don't come from super class
       
   338     Array<Klass*>* sti = (super_klass == NULL) ? NULL :
       
   339                     InstanceKlass::cast(super_klass)->transitive_interfaces();
       
   340     if (ti != sti) {
       
   341       MetadataFactory::free_array<Klass*>(loader_data, ti);
       
   342     }
       
   343   }
       
   344 
       
   345   // local interfaces can be empty
       
   346   if (local_interfaces != Universe::the_empty_klass_array()) {
       
   347     MetadataFactory::free_array<Klass*>(loader_data, local_interfaces);
       
   348   }
       
   349 }
       
   350 
   291 // This function deallocates the metadata and C heap pointers that the
   351 // This function deallocates the metadata and C heap pointers that the
   292 // InstanceKlass points to.
   352 // InstanceKlass points to.
   293 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
   353 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
   294 
   354 
   295   // Orphan the mirror first, CMS thinks it's still live.
   355   // Orphan the mirror first, CMS thinks it's still live.
   296   java_lang_Class::set_klass(java_mirror(), NULL);
   356   if (java_mirror() != NULL) {
       
   357     java_lang_Class::set_klass(java_mirror(), NULL);
       
   358   }
   297 
   359 
   298   // Need to take this class off the class loader data list.
   360   // Need to take this class off the class loader data list.
   299   loader_data->remove_class(this);
   361   loader_data->remove_class(this);
   300 
   362 
   301   // The array_klass for this class is created later, after error handling.
   363   // The array_klass for this class is created later, after error handling.
   306 
   368 
   307   // Release C heap allocated data that this might point to, which includes
   369   // Release C heap allocated data that this might point to, which includes
   308   // reference counting symbol names.
   370   // reference counting symbol names.
   309   release_C_heap_structures();
   371   release_C_heap_structures();
   310 
   372 
   311   Array<Method*>* ms = methods();
   373   deallocate_methods(loader_data, methods());
   312   if (ms != Universe::the_empty_method_array()) {
       
   313     for (int i = 0; i <= methods()->length() -1 ; i++) {
       
   314       Method* method = methods()->at(i);
       
   315       // Only want to delete methods that are not executing for RedefineClasses.
       
   316       // The previous version will point to them so they're not totally dangling
       
   317       assert (!method->on_stack(), "shouldn't be called with methods on stack");
       
   318       MetadataFactory::free_metadata(loader_data, method);
       
   319     }
       
   320     MetadataFactory::free_array<Method*>(loader_data, methods());
       
   321   }
       
   322   set_methods(NULL);
   374   set_methods(NULL);
   323 
   375 
   324   if (method_ordering() != Universe::the_empty_int_array()) {
   376   if (method_ordering() != Universe::the_empty_int_array()) {
   325     MetadataFactory::free_array<int>(loader_data, method_ordering());
   377     MetadataFactory::free_array<int>(loader_data, method_ordering());
   326   }
   378   }
   333       secondary_supers() != transitive_interfaces()) {
   385       secondary_supers() != transitive_interfaces()) {
   334     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
   386     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
   335   }
   387   }
   336   set_secondary_supers(NULL);
   388   set_secondary_supers(NULL);
   337 
   389 
   338   // Only deallocate transitive interfaces if not empty, same as super class
   390   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
   339   // or same as local interfaces.   See code in parseClassFile.
       
   340   Array<Klass*>* ti = transitive_interfaces();
       
   341   if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) {
       
   342     // check that the interfaces don't come from super class
       
   343     Array<Klass*>* sti = (super() == NULL) ? NULL :
       
   344        InstanceKlass::cast(super())->transitive_interfaces();
       
   345     if (ti != sti) {
       
   346       MetadataFactory::free_array<Klass*>(loader_data, ti);
       
   347     }
       
   348   }
       
   349   set_transitive_interfaces(NULL);
   391   set_transitive_interfaces(NULL);
   350 
       
   351   // local interfaces can be empty
       
   352   Array<Klass*>* li = local_interfaces();
       
   353   if (li != Universe::the_empty_klass_array()) {
       
   354     MetadataFactory::free_array<Klass*>(loader_data, li);
       
   355   }
       
   356   set_local_interfaces(NULL);
   392   set_local_interfaces(NULL);
   357 
   393 
   358   MetadataFactory::free_array<jushort>(loader_data, fields());
   394   MetadataFactory::free_array<jushort>(loader_data, fields());
   359   set_fields(NULL, 0);
   395   set_fields(NULL, 0);
   360 
   396 
   361   // If a method from a redefined class is using this constant pool, don't
   397   // If a method from a redefined class is using this constant pool, don't
   362   // delete it, yet.  The new class's previous version will point to this.
   398   // delete it, yet.  The new class's previous version will point to this.
   363   assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
   399   if (constants() != NULL) {
   364   MetadataFactory::free_metadata(loader_data, constants());
   400     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
   365   set_constants(NULL);
   401     MetadataFactory::free_metadata(loader_data, constants());
       
   402     set_constants(NULL);
       
   403   }
   366 
   404 
   367   if (inner_classes() != Universe::the_empty_short_array()) {
   405   if (inner_classes() != Universe::the_empty_short_array()) {
   368     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
   406     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
   369   }
   407   }
   370   set_inner_classes(NULL);
   408   set_inner_classes(NULL);