comparison src/share/vm/oops/instanceKlass.cpp @ 8883:b9a918201d47

Merge with hsx25
author Gilles Duboscq <duboscq@ssw.jku.at>
date Sat, 06 Apr 2013 20:04:06 +0200
parents 5fc51c1ecdeb 46f6f063b272
children 89e4d67fdd2a
comparison
equal deleted inserted replaced
8660:d47b52b0ff68 8883:b9a918201d47
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,
218 ReferenceType rt, 244 ReferenceType rt,
219 AccessFlags access_flags, 245 AccessFlags access_flags,
220 bool is_anonymous) { 246 bool is_anonymous) {
221 No_Safepoint_Verifier no_safepoint; // until k becomes parsable 247 No_Safepoint_Verifier no_safepoint; // until k becomes parsable
222 248
223 int size = 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 252 set_vtable_length(vtable_len);
227 // size of the instanceKlassOop. It is critical that these are set to the right 253 set_itable_length(itable_len);
228 // sizes before the first GC, i.e., when we allocate the mirror. 254 set_static_field_size(static_field_size);
229 this->set_vtable_length(vtable_len); 255 set_nonstatic_oop_map_size(nonstatic_oop_map_size);
230 this->set_itable_length(itable_len); 256 set_access_flags(access_flags);
231 this->set_static_field_size(static_field_size); 257 _misc_flags = 0; // initialize to zero
232 this->set_nonstatic_oop_map_size(nonstatic_oop_map_size); 258 set_is_anonymous(is_anonymous);
233 this->set_access_flags(access_flags); 259 assert(size() == iksize, "wrong size for object");
234 this->set_is_anonymous(is_anonymous); 260
235 assert(this->size() == size, "wrong size for object"); 261 set_array_klasses(NULL);
236 262 set_methods(NULL);
237 this->set_array_klasses(NULL); 263 set_method_ordering(NULL);
238 this->set_methods(NULL); 264 set_local_interfaces(NULL);
239 this->set_method_ordering(NULL); 265 set_transitive_interfaces(NULL);
240 this->set_local_interfaces(NULL); 266 init_implementor();
241 this->set_transitive_interfaces(NULL); 267 set_fields(NULL, 0);
242 this->init_implementor(); 268 set_constants(NULL);
243 this->set_fields(NULL, 0); 269 set_class_loader_data(NULL);
244 this->set_constants(NULL); 270 set_protection_domain(NULL);
245 this->set_class_loader_data(NULL); 271 set_signers(NULL);
246 this->set_protection_domain(NULL); 272 set_source_file_name(NULL);
247 this->set_signers(NULL); 273 set_source_debug_extension(NULL, 0);
248 this->set_source_file_name(NULL); 274 set_array_name(NULL);
249 this->set_source_debug_extension(NULL, 0); 275 set_inner_classes(NULL);
250 this->set_array_name(NULL); 276 set_static_oop_field_count(0);
251 this->set_inner_classes(NULL); 277 set_nonstatic_field_size(0);
252 this->set_static_oop_field_count(0); 278 set_is_marked_dependent(false);
253 this->set_nonstatic_field_size(0); 279 set_init_state(InstanceKlass::allocated);
254 this->set_is_marked_dependent(false); 280 set_init_thread(NULL);
255 this->set_init_state(InstanceKlass::allocated); 281 set_init_lock(NULL);
256 this->set_init_thread(NULL); 282 set_reference_type(rt);
257 this->set_init_lock(NULL); 283 set_oop_map_cache(NULL);
258 this->set_reference_type(rt); 284 set_jni_ids(NULL);
259 this->set_oop_map_cache(NULL); 285 set_osr_nmethods_head(NULL);
260 this->set_jni_ids(NULL); 286 set_breakpoints(NULL);
261 this->set_osr_nmethods_head(NULL); 287 init_previous_versions();
262 this->set_breakpoints(NULL); 288 set_generic_signature(NULL);
263 this->init_previous_versions(); 289 release_set_methods_jmethod_ids(NULL);
264 this->set_generic_signature(NULL); 290 release_set_methods_cached_itable_indices(NULL);
265 this->release_set_methods_jmethod_ids(NULL); 291 set_annotations(NULL);
266 this->release_set_methods_cached_itable_indices(NULL); 292 set_jvmti_cached_class_field_map(NULL);
267 this->set_annotations(NULL); 293 set_initial_method_idnum(0);
268 this->set_jvmti_cached_class_field_map(NULL); 294 _dependencies = NULL;
269 this->set_initial_method_idnum(0); 295 set_jvmti_cached_class_field_map(NULL);
296 set_cached_class_file(NULL, 0);
297 set_initial_method_idnum(0);
298 set_minor_version(0);
299 set_major_version(0);
300 NOT_PRODUCT(_verify_count = 0;)
270 301
271 // initialize the non-header words to zero 302 // initialize the non-header words to zero
272 intptr_t* p = (intptr_t*)this; 303 intptr_t* p = (intptr_t*)this;
273 for (int index = InstanceKlass::header_size(); index < size; index++) { 304 for (int index = InstanceKlass::header_size(); index < iksize; index++) {
274 p[index] = NULL_WORD; 305 p[index] = NULL_WORD;
275 } 306 }
276 307
277 // Set temporary value until parseClassFile updates it with the real instance 308 // Set temporary value until parseClassFile updates it with the real instance
278 // size. 309 // size.
279 this->set_layout_helper(Klass::instance_layout_helper(0, true)); 310 set_layout_helper(Klass::instance_layout_helper(0, true));
280 } 311 }
281 312
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 }
282 350
283 // This function deallocates the metadata and C heap pointers that the 351 // This function deallocates the metadata and C heap pointers that the
284 // InstanceKlass points to. 352 // InstanceKlass points to.
285 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { 353 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
286 354
287 // Orphan the mirror first, CMS thinks it's still live. 355 // Orphan the mirror first, CMS thinks it's still live.
288 java_lang_Class::set_klass(java_mirror(), NULL); 356 if (java_mirror() != NULL) {
357 java_lang_Class::set_klass(java_mirror(), NULL);
358 }
289 359
290 // Need to take this class off the class loader data list. 360 // Need to take this class off the class loader data list.
291 loader_data->remove_class(this); 361 loader_data->remove_class(this);
292 362
293 // 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.
298 368
299 // 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
300 // reference counting symbol names. 370 // reference counting symbol names.
301 release_C_heap_structures(); 371 release_C_heap_structures();
302 372
303 Array<Method*>* ms = methods(); 373 deallocate_methods(loader_data, methods());
304 if (ms != Universe::the_empty_method_array()) {
305 for (int i = 0; i <= methods()->length() -1 ; i++) {
306 Method* method = methods()->at(i);
307 // Only want to delete methods that are not executing for RedefineClasses.
308 // The previous version will point to them so they're not totally dangling
309 assert (!method->on_stack(), "shouldn't be called with methods on stack");
310 MetadataFactory::free_metadata(loader_data, method);
311 }
312 MetadataFactory::free_array<Method*>(loader_data, methods());
313 }
314 set_methods(NULL); 374 set_methods(NULL);
315 375
316 if (method_ordering() != Universe::the_empty_int_array()) { 376 if (method_ordering() != Universe::the_empty_int_array()) {
317 MetadataFactory::free_array<int>(loader_data, method_ordering()); 377 MetadataFactory::free_array<int>(loader_data, method_ordering());
318 } 378 }
325 secondary_supers() != transitive_interfaces()) { 385 secondary_supers() != transitive_interfaces()) {
326 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers()); 386 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
327 } 387 }
328 set_secondary_supers(NULL); 388 set_secondary_supers(NULL);
329 389
330 // Only deallocate transitive interfaces if not empty, same as super class 390 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
331 // or same as local interfaces. See code in parseClassFile.
332 Array<Klass*>* ti = transitive_interfaces();
333 if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) {
334 // check that the interfaces don't come from super class
335 Array<Klass*>* sti = (super() == NULL) ? NULL :
336 InstanceKlass::cast(super())->transitive_interfaces();
337 if (ti != sti) {
338 MetadataFactory::free_array<Klass*>(loader_data, ti);
339 }
340 }
341 set_transitive_interfaces(NULL); 391 set_transitive_interfaces(NULL);
342
343 // local interfaces can be empty
344 Array<Klass*>* li = local_interfaces();
345 if (li != Universe::the_empty_klass_array()) {
346 MetadataFactory::free_array<Klass*>(loader_data, li);
347 }
348 set_local_interfaces(NULL); 392 set_local_interfaces(NULL);
349 393
350 MetadataFactory::free_array<jushort>(loader_data, fields()); 394 MetadataFactory::free_array<jushort>(loader_data, fields());
351 set_fields(NULL, 0); 395 set_fields(NULL, 0);
352 396
353 // 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
354 // 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.
355 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); 399 if (constants() != NULL) {
356 MetadataFactory::free_metadata(loader_data, constants()); 400 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
357 set_constants(NULL); 401 MetadataFactory::free_metadata(loader_data, constants());
402 set_constants(NULL);
403 }
358 404
359 if (inner_classes() != Universe::the_empty_short_array()) { 405 if (inner_classes() != Universe::the_empty_short_array()) {
360 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); 406 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
361 } 407 }
362 set_inner_classes(NULL); 408 set_inner_classes(NULL);
2168 if (ClassUnloading) { 2214 if (ClassUnloading) {
2169 Klass* impl = implementor(); 2215 Klass* impl = implementor();
2170 if (impl != NULL) { 2216 if (impl != NULL) {
2171 if (!impl->is_loader_alive(is_alive)) { 2217 if (!impl->is_loader_alive(is_alive)) {
2172 // remove this guy 2218 // remove this guy
2173 *adr_implementor() = NULL; 2219 Klass** klass = adr_implementor();
2220 assert(klass != NULL, "null klass");
2221 if (klass != NULL) {
2222 *klass = NULL;
2223 }
2174 } 2224 }
2175 } 2225 }
2176 } 2226 }
2177 } 2227 }
2178 } 2228 }
2179 2229
2180 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) { 2230 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
2181 #if defined(COMPILER2) || defined(GRAAL)
2182 // Currently only used by C2 and Graal
2183 for (int m = 0; m < methods()->length(); m++) { 2231 for (int m = 0; m < methods()->length(); m++) {
2184 MethodData* mdo = methods()->at(m)->method_data(); 2232 MethodData* mdo = methods()->at(m)->method_data();
2185 if (mdo != NULL) { 2233 if (mdo != NULL) {
2186 for (ProfileData* data = mdo->first_data(); 2234 for (ProfileData* data = mdo->first_data();
2187 mdo->is_valid(data); 2235 mdo->is_valid(data);
2188 data = mdo->next_data(data)) { 2236 data = mdo->next_data(data)) {
2189 data->clean_weak_klass_links(is_alive); 2237 data->clean_weak_klass_links(is_alive);
2190 } 2238 }
2191 } 2239 }
2192 } 2240 }
2193 #else
2194 #ifdef ASSERT
2195 // Verify that we haven't started to use MDOs for C1.
2196 for (int m = 0; m < methods()->length(); m++) {
2197 MethodData* mdo = methods()->at(m)->method_data();
2198 assert(mdo == NULL, "Didn't expect C1 to use MDOs");
2199 }
2200 #endif // ASSERT
2201 #endif // !COMPILER2
2202 } 2241 }
2203 2242
2204 2243
2205 static void remove_unshareable_in_class(Klass* k) { 2244 static void remove_unshareable_in_class(Klass* k) {
2206 // remove klass's unshareable info 2245 // remove klass's unshareable info
2779 st->cr(); 2818 st->cr();
2780 } 2819 }
2781 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); 2820 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr();
2782 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); 2821 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr();
2783 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); 2822 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr();
2784 st->print(BULLET"init_lock: "); ((oop)init_lock())->print_value_on(st); st->cr(); 2823 st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr();
2785 if (source_file_name() != NULL) { 2824 if (source_file_name() != NULL) {
2786 st->print(BULLET"source file: "); 2825 st->print(BULLET"source file: ");
2787 source_file_name()->print_value_on(st); 2826 source_file_name()->print_value_on(st);
2788 st->cr(); 2827 st->cr();
2789 } 2828 }
2909 java_lang_invoke_MethodType::print_signature(obj, st); 2948 java_lang_invoke_MethodType::print_signature(obj, st);
2910 st->cr(); 2949 st->cr();
2911 } 2950 }
2912 } 2951 }
2913 2952
2914 #endif 2953 #endif //PRODUCT
2915 2954
2916 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) { 2955 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
2917 st->print("a "); 2956 st->print("a ");
2918 name()->print_value_on(st); 2957 name()->print_value_on(st);
2919 obj->print_address_on(st); 2958 obj->print_address_on(st);