Mercurial > hg > graal-compiler
comparison src/share/vm/oops/instanceKlass.cpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | 1d7922586cf6 |
children | fa6e618671d7 |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
32 #include "gc_interface/collectedHeap.inline.hpp" | 32 #include "gc_interface/collectedHeap.inline.hpp" |
33 #include "interpreter/oopMapCache.hpp" | 33 #include "interpreter/oopMapCache.hpp" |
34 #include "interpreter/rewriter.hpp" | 34 #include "interpreter/rewriter.hpp" |
35 #include "jvmtifiles/jvmti.h" | 35 #include "jvmtifiles/jvmti.h" |
36 #include "memory/genOopClosures.inline.hpp" | 36 #include "memory/genOopClosures.inline.hpp" |
37 #include "memory/metadataFactory.hpp" | |
37 #include "memory/oopFactory.hpp" | 38 #include "memory/oopFactory.hpp" |
38 #include "memory/permGen.hpp" | |
39 #include "oops/fieldStreams.hpp" | 39 #include "oops/fieldStreams.hpp" |
40 #include "oops/instanceClassLoaderKlass.hpp" | |
40 #include "oops/instanceKlass.hpp" | 41 #include "oops/instanceKlass.hpp" |
41 #include "oops/instanceMirrorKlass.hpp" | 42 #include "oops/instanceMirrorKlass.hpp" |
42 #include "oops/instanceOop.hpp" | 43 #include "oops/instanceOop.hpp" |
43 #include "oops/methodOop.hpp" | 44 #include "oops/klass.inline.hpp" |
44 #include "oops/objArrayKlassKlass.hpp" | 45 #include "oops/method.hpp" |
45 #include "oops/oop.inline.hpp" | 46 #include "oops/oop.inline.hpp" |
46 #include "oops/symbol.hpp" | 47 #include "oops/symbol.hpp" |
47 #include "prims/jvmtiExport.hpp" | 48 #include "prims/jvmtiExport.hpp" |
48 #include "prims/jvmtiRedefineClassesTrace.hpp" | 49 #include "prims/jvmtiRedefineClassesTrace.hpp" |
49 #include "runtime/fieldDescriptor.hpp" | 50 #include "runtime/fieldDescriptor.hpp" |
63 #endif | 64 #endif |
64 #ifdef TARGET_OS_FAMILY_bsd | 65 #ifdef TARGET_OS_FAMILY_bsd |
65 # include "thread_bsd.inline.hpp" | 66 # include "thread_bsd.inline.hpp" |
66 #endif | 67 #endif |
67 #ifndef SERIALGC | 68 #ifndef SERIALGC |
69 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" | |
68 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" | 70 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
69 #include "gc_implementation/g1/g1OopClosures.inline.hpp" | 71 #include "gc_implementation/g1/g1OopClosures.inline.hpp" |
70 #include "gc_implementation/g1/g1RemSet.inline.hpp" | 72 #include "gc_implementation/g1/g1RemSet.inline.hpp" |
71 #include "gc_implementation/g1/heapRegionSeq.inline.hpp" | 73 #include "gc_implementation/g1/heapRegionSeq.inline.hpp" |
72 #include "gc_implementation/parNew/parOopClosures.inline.hpp" | 74 #include "gc_implementation/parNew/parOopClosures.inline.hpp" |
75 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" | |
73 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" | 76 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" |
74 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" | 77 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" |
75 #include "oops/oop.pcgc.inline.hpp" | 78 #include "oops/oop.pcgc.inline.hpp" |
76 #endif | 79 #endif |
77 #ifdef COMPILER1 | 80 #ifdef COMPILER1 |
166 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) | 169 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) |
167 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) | 170 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) |
168 | 171 |
169 #endif // ndef DTRACE_ENABLED | 172 #endif // ndef DTRACE_ENABLED |
170 | 173 |
171 bool instanceKlass::should_be_initialized() const { | 174 Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data, |
175 int vtable_len, | |
176 int itable_len, | |
177 int static_field_size, | |
178 int nonstatic_oop_map_size, | |
179 ReferenceType rt, | |
180 AccessFlags access_flags, | |
181 Symbol* name, | |
182 Klass* super_klass, | |
183 KlassHandle host_klass, | |
184 TRAPS) { | |
185 | |
186 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, | |
187 access_flags.is_interface(), | |
188 !host_klass.is_null()); | |
189 | |
190 // Allocation | |
191 InstanceKlass* ik; | |
192 if (rt == REF_NONE) { | |
193 if (name == vmSymbols::java_lang_Class()) { | |
194 ik = new (loader_data, size, THREAD) instanceMirrorKlass( | |
195 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, | |
196 access_flags, !host_klass.is_null()); | |
197 } else if (name == vmSymbols::java_lang_ClassLoader() || | |
198 (SystemDictionary::ClassLoader_klass_loaded() && | |
199 super_klass != NULL && | |
200 super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) { | |
201 ik = new (loader_data, size, THREAD) instanceClassLoaderKlass( | |
202 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, | |
203 access_flags, !host_klass.is_null()); | |
204 } else { | |
205 // normal class | |
206 ik = new (loader_data, size, THREAD) InstanceKlass( | |
207 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, | |
208 access_flags, !host_klass.is_null()); | |
209 } | |
210 } else { | |
211 // reference klass | |
212 ik = new (loader_data, size, THREAD) instanceRefKlass( | |
213 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, | |
214 access_flags, !host_klass.is_null()); | |
215 } | |
216 | |
217 return ik; | |
218 } | |
219 | |
220 InstanceKlass::InstanceKlass(int vtable_len, | |
221 int itable_len, | |
222 int static_field_size, | |
223 int nonstatic_oop_map_size, | |
224 ReferenceType rt, | |
225 AccessFlags access_flags, | |
226 bool is_anonymous) { | |
227 No_Safepoint_Verifier no_safepoint; // until k becomes parsable | |
228 | |
229 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, | |
230 access_flags.is_interface(), is_anonymous); | |
231 | |
232 // The sizes of these these three variables are used for determining the | |
233 // size of the instanceKlassOop. It is critical that these are set to the right | |
234 // sizes before the first GC, i.e., when we allocate the mirror. | |
235 this->set_vtable_length(vtable_len); | |
236 this->set_itable_length(itable_len); | |
237 this->set_static_field_size(static_field_size); | |
238 this->set_nonstatic_oop_map_size(nonstatic_oop_map_size); | |
239 this->set_access_flags(access_flags); | |
240 this->set_is_anonymous(is_anonymous); | |
241 assert(this->size() == size, "wrong size for object"); | |
242 | |
243 this->set_array_klasses(NULL); | |
244 this->set_methods(NULL); | |
245 this->set_method_ordering(NULL); | |
246 this->set_local_interfaces(NULL); | |
247 this->set_transitive_interfaces(NULL); | |
248 this->init_implementor(); | |
249 this->set_fields(NULL, 0); | |
250 this->set_constants(NULL); | |
251 this->set_class_loader_data(NULL); | |
252 this->set_protection_domain(NULL); | |
253 this->set_signers(NULL); | |
254 this->set_source_file_name(NULL); | |
255 this->set_source_debug_extension(NULL, 0); | |
256 this->set_array_name(NULL); | |
257 this->set_inner_classes(NULL); | |
258 this->set_static_oop_field_count(0); | |
259 this->set_nonstatic_field_size(0); | |
260 this->set_is_marked_dependent(false); | |
261 this->set_init_state(InstanceKlass::allocated); | |
262 this->set_init_thread(NULL); | |
263 this->set_init_lock(NULL); | |
264 this->set_reference_type(rt); | |
265 this->set_oop_map_cache(NULL); | |
266 this->set_jni_ids(NULL); | |
267 this->set_osr_nmethods_head(NULL); | |
268 this->set_breakpoints(NULL); | |
269 this->init_previous_versions(); | |
270 this->set_generic_signature(NULL); | |
271 this->release_set_methods_jmethod_ids(NULL); | |
272 this->release_set_methods_cached_itable_indices(NULL); | |
273 this->set_annotations(NULL); | |
274 this->set_jvmti_cached_class_field_map(NULL); | |
275 this->set_initial_method_idnum(0); | |
276 | |
277 // initialize the non-header words to zero | |
278 intptr_t* p = (intptr_t*)this; | |
279 for (int index = InstanceKlass::header_size(); index < size; index++) { | |
280 p[index] = NULL_WORD; | |
281 } | |
282 | |
283 // Set temporary value until parseClassFile updates it with the real instance | |
284 // size. | |
285 this->set_layout_helper(Klass::instance_layout_helper(0, true)); | |
286 } | |
287 | |
288 | |
289 // This function deallocates the metadata and C heap pointers that the | |
290 // InstanceKlass points to. | |
291 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { | |
292 | |
293 // Orphan the mirror first, CMS thinks it's still live. | |
294 java_lang_Class::set_klass(java_mirror(), NULL); | |
295 | |
296 // Need to take this class off the class loader data list. | |
297 loader_data->remove_class(this); | |
298 | |
299 // The array_klass for this class is created later, after error handling. | |
300 // For class redefinition, we keep the original class so this scratch class | |
301 // doesn't have an array class. Either way, assert that there is nothing | |
302 // to deallocate. | |
303 assert(array_klasses() == NULL, "array classes shouldn't be created for this class yet"); | |
304 | |
305 // Release C heap allocated data that this might point to, which includes | |
306 // reference counting symbol names. | |
307 release_C_heap_structures(); | |
308 | |
309 Array<Method*>* ms = methods(); | |
310 if (ms != Universe::the_empty_method_array()) { | |
311 for (int i = 0; i <= methods()->length() -1 ; i++) { | |
312 Method* method = methods()->at(i); | |
313 // Only want to delete methods that are not executing for RedefineClasses. | |
314 // The previous version will point to them so they're not totally dangling | |
315 assert (!method->on_stack(), "shouldn't be called with methods on stack"); | |
316 MetadataFactory::free_metadata(loader_data, method); | |
317 } | |
318 MetadataFactory::free_array<Method*>(loader_data, methods()); | |
319 } | |
320 set_methods(NULL); | |
321 | |
322 if (method_ordering() != Universe::the_empty_int_array()) { | |
323 MetadataFactory::free_array<int>(loader_data, method_ordering()); | |
324 } | |
325 set_method_ordering(NULL); | |
326 | |
327 // This array is in Klass, but remove it with the InstanceKlass since | |
328 // this place would be the only caller and it can share memory with transitive | |
329 // interfaces. | |
330 if (secondary_supers() != Universe::the_empty_klass_array() && | |
331 secondary_supers() != transitive_interfaces()) { | |
332 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers()); | |
333 } | |
334 set_secondary_supers(NULL); | |
335 | |
336 // Only deallocate transitive interfaces if not empty, same as super class | |
337 // or same as local interfaces. See code in parseClassFile. | |
338 Array<Klass*>* ti = transitive_interfaces(); | |
339 if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) { | |
340 // check that the interfaces don't come from super class | |
341 Array<Klass*>* sti = (super() == NULL) ? NULL : | |
342 InstanceKlass::cast(super())->transitive_interfaces(); | |
343 if (ti != sti) { | |
344 MetadataFactory::free_array<Klass*>(loader_data, ti); | |
345 } | |
346 } | |
347 set_transitive_interfaces(NULL); | |
348 | |
349 // local interfaces can be empty | |
350 Array<Klass*>* li = local_interfaces(); | |
351 if (li != Universe::the_empty_klass_array()) { | |
352 MetadataFactory::free_array<Klass*>(loader_data, li); | |
353 } | |
354 set_local_interfaces(NULL); | |
355 | |
356 MetadataFactory::free_array<jushort>(loader_data, fields()); | |
357 set_fields(NULL, 0); | |
358 | |
359 // If a method from a redefined class is using this constant pool, don't | |
360 // delete it, yet. The new class's previous version will point to this. | |
361 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); | |
362 MetadataFactory::free_metadata(loader_data, constants()); | |
363 set_constants(NULL); | |
364 | |
365 if (inner_classes() != Universe::the_empty_short_array()) { | |
366 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); | |
367 } | |
368 set_inner_classes(NULL); | |
369 | |
370 // Null out Java heap objects, although these won't be walked to keep | |
371 // alive once this InstanceKlass is deallocated. | |
372 set_protection_domain(NULL); | |
373 set_signers(NULL); | |
374 set_init_lock(NULL); | |
375 set_annotations(NULL); | |
376 } | |
377 | |
378 volatile oop InstanceKlass::init_lock() const { | |
379 volatile oop lock = _init_lock; // read once | |
380 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state | |
381 "only fully initialized state can have a null lock"); | |
382 return lock; | |
383 } | |
384 | |
385 // Set the initialization lock to null so the object can be GC'ed. Any racing | |
386 // threads to get this lock will see a null lock and will not lock. | |
387 // That's okay because they all check for initialized state after getting | |
388 // the lock and return. | |
389 void InstanceKlass::fence_and_clear_init_lock() { | |
390 // make sure previous stores are all done, notably the init_state. | |
391 OrderAccess::storestore(); | |
392 klass_oop_store(&_init_lock, NULL); | |
393 assert(!is_not_initialized(), "class must be initialized now"); | |
394 } | |
395 | |
396 | |
397 bool InstanceKlass::should_be_initialized() const { | |
172 return !is_initialized(); | 398 return !is_initialized(); |
173 } | 399 } |
174 | 400 |
175 klassVtable* instanceKlass::vtable() const { | 401 klassVtable* InstanceKlass::vtable() const { |
176 return new klassVtable(as_klassOop(), start_of_vtable(), vtable_length() / vtableEntry::size()); | 402 return new klassVtable(this, start_of_vtable(), vtable_length() / vtableEntry::size()); |
177 } | 403 } |
178 | 404 |
179 klassItable* instanceKlass::itable() const { | 405 klassItable* InstanceKlass::itable() const { |
180 return new klassItable(as_klassOop()); | 406 return new klassItable(instanceKlassHandle(this)); |
181 } | 407 } |
182 | 408 |
183 void instanceKlass::eager_initialize(Thread *thread) { | 409 void InstanceKlass::eager_initialize(Thread *thread) { |
184 if (!EagerInitialization) return; | 410 if (!EagerInitialization) return; |
185 | 411 |
186 if (this->is_not_initialized()) { | 412 if (this->is_not_initialized()) { |
187 // abort if the the class has a class initializer | 413 // abort if the the class has a class initializer |
188 if (this->class_initializer() != NULL) return; | 414 if (this->class_initializer() != NULL) return; |
189 | 415 |
190 // abort if it is java.lang.Object (initialization is handled in genesis) | 416 // abort if it is java.lang.Object (initialization is handled in genesis) |
191 klassOop super = this->super(); | 417 Klass* super = this->super(); |
192 if (super == NULL) return; | 418 if (super == NULL) return; |
193 | 419 |
194 // abort if the super class should be initialized | 420 // abort if the super class should be initialized |
195 if (!instanceKlass::cast(super)->is_initialized()) return; | 421 if (!InstanceKlass::cast(super)->is_initialized()) return; |
196 | 422 |
197 // call body to expose the this pointer | 423 // call body to expose the this pointer |
198 instanceKlassHandle this_oop(thread, this->as_klassOop()); | 424 instanceKlassHandle this_oop(thread, this); |
199 eager_initialize_impl(this_oop); | 425 eager_initialize_impl(this_oop); |
200 } | 426 } |
201 } | 427 } |
202 | 428 |
203 | 429 |
204 void instanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { | 430 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
205 EXCEPTION_MARK; | 431 EXCEPTION_MARK; |
206 ObjectLocker ol(this_oop, THREAD); | 432 volatile oop init_lock = this_oop->init_lock(); |
433 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); | |
207 | 434 |
208 // abort if someone beat us to the initialization | 435 // abort if someone beat us to the initialization |
209 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() | 436 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
210 | 437 |
211 ClassState old_state = this_oop->init_state(); | 438 ClassState old_state = this_oop->init_state(); |
220 if( old_state != this_oop->_init_state ) | 447 if( old_state != this_oop->_init_state ) |
221 this_oop->set_init_state (old_state); | 448 this_oop->set_init_state (old_state); |
222 } else { | 449 } else { |
223 // linking successfull, mark class as initialized | 450 // linking successfull, mark class as initialized |
224 this_oop->set_init_state (fully_initialized); | 451 this_oop->set_init_state (fully_initialized); |
452 this_oop->fence_and_clear_init_lock(); | |
225 // trace | 453 // trace |
226 if (TraceClassInitialization) { | 454 if (TraceClassInitialization) { |
227 ResourceMark rm(THREAD); | 455 ResourceMark rm(THREAD); |
228 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); | 456 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); |
229 } | 457 } |
232 | 460 |
233 | 461 |
234 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization | 462 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization |
235 // process. The step comments refers to the procedure described in that section. | 463 // process. The step comments refers to the procedure described in that section. |
236 // Note: implementation moved to static method to expose the this pointer. | 464 // Note: implementation moved to static method to expose the this pointer. |
237 void instanceKlass::initialize(TRAPS) { | 465 void InstanceKlass::initialize(TRAPS) { |
238 if (this->should_be_initialized()) { | 466 if (this->should_be_initialized()) { |
239 HandleMark hm(THREAD); | 467 HandleMark hm(THREAD); |
240 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); | 468 instanceKlassHandle this_oop(THREAD, this); |
241 initialize_impl(this_oop, CHECK); | 469 initialize_impl(this_oop, CHECK); |
242 // Note: at this point the class may be initialized | 470 // Note: at this point the class may be initialized |
243 // OR it may be in the state of being initialized | 471 // OR it may be in the state of being initialized |
244 // in case of recursive initialization! | 472 // in case of recursive initialization! |
245 } else { | 473 } else { |
246 assert(is_initialized(), "sanity check"); | 474 assert(is_initialized(), "sanity check"); |
247 } | 475 } |
248 } | 476 } |
249 | 477 |
250 | 478 |
251 bool instanceKlass::verify_code( | 479 bool InstanceKlass::verify_code( |
252 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { | 480 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
253 // 1) Verify the bytecodes | 481 // 1) Verify the bytecodes |
254 Verifier::Mode mode = | 482 Verifier::Mode mode = |
255 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; | 483 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
256 return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false); | 484 return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false); |
258 | 486 |
259 | 487 |
260 // Used exclusively by the shared spaces dump mechanism to prevent | 488 // Used exclusively by the shared spaces dump mechanism to prevent |
261 // classes mapped into the shared regions in new VMs from appearing linked. | 489 // classes mapped into the shared regions in new VMs from appearing linked. |
262 | 490 |
263 void instanceKlass::unlink_class() { | 491 void InstanceKlass::unlink_class() { |
264 assert(is_linked(), "must be linked"); | 492 assert(is_linked(), "must be linked"); |
265 _init_state = loaded; | 493 _init_state = loaded; |
266 } | 494 } |
267 | 495 |
268 void instanceKlass::link_class(TRAPS) { | 496 void InstanceKlass::link_class(TRAPS) { |
269 assert(is_loaded(), "must be loaded"); | 497 assert(is_loaded(), "must be loaded"); |
270 if (!is_linked()) { | 498 if (!is_linked()) { |
271 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); | 499 HandleMark hm(THREAD); |
500 instanceKlassHandle this_oop(THREAD, this); | |
272 link_class_impl(this_oop, true, CHECK); | 501 link_class_impl(this_oop, true, CHECK); |
273 } | 502 } |
274 } | 503 } |
275 | 504 |
276 // Called to verify that a class can link during initialization, without | 505 // Called to verify that a class can link during initialization, without |
277 // throwing a VerifyError. | 506 // throwing a VerifyError. |
278 bool instanceKlass::link_class_or_fail(TRAPS) { | 507 bool InstanceKlass::link_class_or_fail(TRAPS) { |
279 assert(is_loaded(), "must be loaded"); | 508 assert(is_loaded(), "must be loaded"); |
280 if (!is_linked()) { | 509 if (!is_linked()) { |
281 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); | 510 HandleMark hm(THREAD); |
511 instanceKlassHandle this_oop(THREAD, this); | |
282 link_class_impl(this_oop, false, CHECK_false); | 512 link_class_impl(this_oop, false, CHECK_false); |
283 } | 513 } |
284 return is_linked(); | 514 return is_linked(); |
285 } | 515 } |
286 | 516 |
287 bool instanceKlass::link_class_impl( | 517 bool InstanceKlass::link_class_impl( |
288 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { | 518 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
289 // check for error state | 519 // check for error state |
290 if (this_oop->is_in_error_state()) { | 520 if (this_oop->is_in_error_state()) { |
291 ResourceMark rm(THREAD); | 521 ResourceMark rm(THREAD); |
292 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), | 522 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
319 | 549 |
320 link_class_impl(super, throw_verifyerror, CHECK_false); | 550 link_class_impl(super, throw_verifyerror, CHECK_false); |
321 } | 551 } |
322 | 552 |
323 // link all interfaces implemented by this class before linking this class | 553 // link all interfaces implemented by this class before linking this class |
324 objArrayHandle interfaces (THREAD, this_oop->local_interfaces()); | 554 Array<Klass*>* interfaces = this_oop->local_interfaces(); |
325 int num_interfaces = interfaces->length(); | 555 int num_interfaces = interfaces->length(); |
326 for (int index = 0; index < num_interfaces; index++) { | 556 for (int index = 0; index < num_interfaces; index++) { |
327 HandleMark hm(THREAD); | 557 HandleMark hm(THREAD); |
328 instanceKlassHandle ih(THREAD, klassOop(interfaces->obj_at(index))); | 558 instanceKlassHandle ih(THREAD, interfaces->at(index)); |
329 link_class_impl(ih, throw_verifyerror, CHECK_false); | 559 link_class_impl(ih, throw_verifyerror, CHECK_false); |
330 } | 560 } |
331 | 561 |
332 // in case the class is linked in the process of linking its superclasses | 562 // in case the class is linked in the process of linking its superclasses |
333 if (this_oop->is_linked()) { | 563 if (this_oop->is_linked()) { |
343 jt->get_thread_stat()->perf_timers_addr(), | 573 jt->get_thread_stat()->perf_timers_addr(), |
344 PerfClassTraceTime::CLASS_LINK); | 574 PerfClassTraceTime::CLASS_LINK); |
345 | 575 |
346 // verification & rewriting | 576 // verification & rewriting |
347 { | 577 { |
348 ObjectLocker ol(this_oop, THREAD); | 578 volatile oop init_lock = this_oop->init_lock(); |
579 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); | |
349 // rewritten will have been set if loader constraint error found | 580 // rewritten will have been set if loader constraint error found |
350 // on an earlier link attempt | 581 // on an earlier link attempt |
351 // don't verify or rewrite if already rewritten | 582 // don't verify or rewrite if already rewritten |
583 | |
352 if (!this_oop->is_linked()) { | 584 if (!this_oop->is_linked()) { |
353 if (!this_oop->is_rewritten()) { | 585 if (!this_oop->is_rewritten()) { |
354 { | 586 { |
355 // Timer includes any side effects of class verification (resolution, | 587 // Timer includes any side effects of class verification (resolution, |
356 // etc), but not recursive entry into verify_code(). | 588 // etc), but not recursive entry into verify_code(). |
380 // relocate jsrs and link methods after they are all rewritten | 612 // relocate jsrs and link methods after they are all rewritten |
381 this_oop->relocate_and_link_methods(CHECK_false); | 613 this_oop->relocate_and_link_methods(CHECK_false); |
382 | 614 |
383 // Initialize the vtable and interface table after | 615 // Initialize the vtable and interface table after |
384 // methods have been rewritten since rewrite may | 616 // methods have been rewritten since rewrite may |
385 // fabricate new methodOops. | 617 // fabricate new Method*s. |
386 // also does loader constraint checking | 618 // also does loader constraint checking |
387 if (!this_oop()->is_shared()) { | 619 if (!this_oop()->is_shared()) { |
388 ResourceMark rm(THREAD); | 620 ResourceMark rm(THREAD); |
389 this_oop->vtable()->initialize_vtable(true, CHECK_false); | 621 this_oop->vtable()->initialize_vtable(true, CHECK_false); |
390 this_oop->itable()->initialize_itable(true, CHECK_false); | 622 this_oop->itable()->initialize_itable(true, CHECK_false); |
410 | 642 |
411 | 643 |
412 // Rewrite the byte codes of all of the methods of a class. | 644 // Rewrite the byte codes of all of the methods of a class. |
413 // The rewriter must be called exactly once. Rewriting must happen after | 645 // The rewriter must be called exactly once. Rewriting must happen after |
414 // verification but before the first method of the class is executed. | 646 // verification but before the first method of the class is executed. |
415 void instanceKlass::rewrite_class(TRAPS) { | 647 void InstanceKlass::rewrite_class(TRAPS) { |
416 assert(is_loaded(), "must be loaded"); | 648 assert(is_loaded(), "must be loaded"); |
417 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); | 649 instanceKlassHandle this_oop(THREAD, this); |
418 if (this_oop->is_rewritten()) { | 650 if (this_oop->is_rewritten()) { |
419 assert(this_oop()->is_shared(), "rewriting an unshared class?"); | 651 assert(this_oop()->is_shared(), "rewriting an unshared class?"); |
420 return; | 652 return; |
421 } | 653 } |
422 Rewriter::rewrite(this_oop, CHECK); | 654 Rewriter::rewrite(this_oop, CHECK); |
424 } | 656 } |
425 | 657 |
426 // Now relocate and link method entry points after class is rewritten. | 658 // Now relocate and link method entry points after class is rewritten. |
427 // This is outside is_rewritten flag. In case of an exception, it can be | 659 // This is outside is_rewritten flag. In case of an exception, it can be |
428 // executed more than once. | 660 // executed more than once. |
429 void instanceKlass::relocate_and_link_methods(TRAPS) { | 661 void InstanceKlass::relocate_and_link_methods(TRAPS) { |
430 assert(is_loaded(), "must be loaded"); | 662 assert(is_loaded(), "must be loaded"); |
431 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); | 663 instanceKlassHandle this_oop(THREAD, this); |
432 Rewriter::relocate_and_link(this_oop, CHECK); | 664 Rewriter::relocate_and_link(this_oop, CHECK); |
433 } | 665 } |
434 | 666 |
435 | 667 |
436 void instanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { | 668 void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { |
437 // Make sure klass is linked (verified) before initialization | 669 // Make sure klass is linked (verified) before initialization |
438 // A class could already be verified, since it has been reflected upon. | 670 // A class could already be verified, since it has been reflected upon. |
439 this_oop->link_class(CHECK); | 671 this_oop->link_class(CHECK); |
440 | 672 |
441 DTRACE_CLASSINIT_PROBE(required, instanceKlass::cast(this_oop()), -1); | 673 DTRACE_CLASSINIT_PROBE(required, InstanceKlass::cast(this_oop()), -1); |
442 | 674 |
443 bool wait = false; | 675 bool wait = false; |
444 | 676 |
445 // refer to the JVM book page 47 for description of steps | 677 // refer to the JVM book page 47 for description of steps |
446 // Step 1 | 678 // Step 1 |
447 { ObjectLocker ol(this_oop, THREAD); | 679 { |
680 volatile oop init_lock = this_oop->init_lock(); | |
681 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); | |
448 | 682 |
449 Thread *self = THREAD; // it's passed the current thread | 683 Thread *self = THREAD; // it's passed the current thread |
450 | 684 |
451 // Step 2 | 685 // Step 2 |
452 // If we were to use wait() instead of waitInterruptibly() then | 686 // If we were to use wait() instead of waitInterruptibly() then |
457 ol.waitUninterruptibly(CHECK); | 691 ol.waitUninterruptibly(CHECK); |
458 } | 692 } |
459 | 693 |
460 // Step 3 | 694 // Step 3 |
461 if (this_oop->is_being_initialized() && this_oop->is_reentrant_initialization(self)) { | 695 if (this_oop->is_being_initialized() && this_oop->is_reentrant_initialization(self)) { |
462 DTRACE_CLASSINIT_PROBE_WAIT(recursive, instanceKlass::cast(this_oop()), -1,wait); | 696 DTRACE_CLASSINIT_PROBE_WAIT(recursive, InstanceKlass::cast(this_oop()), -1,wait); |
463 return; | 697 return; |
464 } | 698 } |
465 | 699 |
466 // Step 4 | 700 // Step 4 |
467 if (this_oop->is_initialized()) { | 701 if (this_oop->is_initialized()) { |
468 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, instanceKlass::cast(this_oop()), -1,wait); | 702 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, InstanceKlass::cast(this_oop()), -1,wait); |
469 return; | 703 return; |
470 } | 704 } |
471 | 705 |
472 // Step 5 | 706 // Step 5 |
473 if (this_oop->is_in_error_state()) { | 707 if (this_oop->is_in_error_state()) { |
474 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, instanceKlass::cast(this_oop()), -1,wait); | 708 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, InstanceKlass::cast(this_oop()), -1,wait); |
475 ResourceMark rm(THREAD); | 709 ResourceMark rm(THREAD); |
476 const char* desc = "Could not initialize class "; | 710 const char* desc = "Could not initialize class "; |
477 const char* className = this_oop->external_name(); | 711 const char* className = this_oop->external_name(); |
478 size_t msglen = strlen(desc) + strlen(className) + 1; | 712 size_t msglen = strlen(desc) + strlen(className) + 1; |
479 char* message = NEW_RESOURCE_ARRAY(char, msglen); | 713 char* message = NEW_RESOURCE_ARRAY(char, msglen); |
490 this_oop->set_init_state(being_initialized); | 724 this_oop->set_init_state(being_initialized); |
491 this_oop->set_init_thread(self); | 725 this_oop->set_init_thread(self); |
492 } | 726 } |
493 | 727 |
494 // Step 7 | 728 // Step 7 |
495 klassOop super_klass = this_oop->super(); | 729 Klass* super_klass = this_oop->super(); |
496 if (super_klass != NULL && !this_oop->is_interface() && Klass::cast(super_klass)->should_be_initialized()) { | 730 if (super_klass != NULL && !this_oop->is_interface() && Klass::cast(super_klass)->should_be_initialized()) { |
497 Klass::cast(super_klass)->initialize(THREAD); | 731 Klass::cast(super_klass)->initialize(THREAD); |
498 | 732 |
499 if (HAS_PENDING_EXCEPTION) { | 733 if (HAS_PENDING_EXCEPTION) { |
500 Handle e(THREAD, PENDING_EXCEPTION); | 734 Handle e(THREAD, PENDING_EXCEPTION); |
502 { | 736 { |
503 EXCEPTION_MARK; | 737 EXCEPTION_MARK; |
504 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads | 738 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads |
505 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below | 739 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below |
506 } | 740 } |
507 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, instanceKlass::cast(this_oop()), -1,wait); | 741 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_oop()), -1,wait); |
508 THROW_OOP(e()); | 742 THROW_OOP(e()); |
509 } | 743 } |
510 } | 744 } |
511 | 745 |
512 // Step 8 | 746 // Step 8 |
513 { | 747 { |
514 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); | 748 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
515 JavaThread* jt = (JavaThread*)THREAD; | 749 JavaThread* jt = (JavaThread*)THREAD; |
516 DTRACE_CLASSINIT_PROBE_WAIT(clinit, instanceKlass::cast(this_oop()), -1,wait); | 750 DTRACE_CLASSINIT_PROBE_WAIT(clinit, InstanceKlass::cast(this_oop()), -1,wait); |
517 // Timer includes any side effects of class initialization (resolution, | 751 // Timer includes any side effects of class initialization (resolution, |
518 // etc), but not recursive entry into call_class_initializer(). | 752 // etc), but not recursive entry into call_class_initializer(). |
519 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), | 753 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
520 ClassLoader::perf_class_init_selftime(), | 754 ClassLoader::perf_class_init_selftime(), |
521 ClassLoader::perf_classes_inited(), | 755 ClassLoader::perf_classes_inited(), |
539 { | 773 { |
540 EXCEPTION_MARK; | 774 EXCEPTION_MARK; |
541 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); | 775 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
542 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below | 776 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
543 } | 777 } |
544 DTRACE_CLASSINIT_PROBE_WAIT(error, instanceKlass::cast(this_oop()), -1,wait); | 778 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait); |
545 if (e->is_a(SystemDictionary::Error_klass())) { | 779 if (e->is_a(SystemDictionary::Error_klass())) { |
546 THROW_OOP(e()); | 780 THROW_OOP(e()); |
547 } else { | 781 } else { |
548 JavaCallArguments args(e); | 782 JavaCallArguments args(e); |
549 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), | 783 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
550 vmSymbols::throwable_void_signature(), | 784 vmSymbols::throwable_void_signature(), |
551 &args); | 785 &args); |
552 } | 786 } |
553 } | 787 } |
554 DTRACE_CLASSINIT_PROBE_WAIT(end, instanceKlass::cast(this_oop()), -1,wait); | 788 DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_oop()), -1,wait); |
555 } | 789 } |
556 | 790 |
557 | 791 |
558 // Note: implementation moved to static method to expose the this pointer. | 792 // Note: implementation moved to static method to expose the this pointer. |
559 void instanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { | 793 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
560 instanceKlassHandle kh(THREAD, this->as_klassOop()); | 794 instanceKlassHandle kh(THREAD, this); |
561 set_initialization_state_and_notify_impl(kh, state, CHECK); | 795 set_initialization_state_and_notify_impl(kh, state, CHECK); |
562 } | 796 } |
563 | 797 |
564 void instanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { | 798 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
565 ObjectLocker ol(this_oop, THREAD); | 799 volatile oop init_lock = this_oop->init_lock(); |
800 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); | |
566 this_oop->set_init_state(state); | 801 this_oop->set_init_state(state); |
802 this_oop->fence_and_clear_init_lock(); | |
567 ol.notify_all(CHECK); | 803 ol.notify_all(CHECK); |
568 } | 804 } |
569 | 805 |
570 // The embedded _implementor field can only record one implementor. | 806 // The embedded _implementor field can only record one implementor. |
571 // When there are more than one implementors, the _implementor field | 807 // When there are more than one implementors, the _implementor field |
572 // is set to the interface klassOop itself. Following are the possible | 808 // is set to the interface Klass* itself. Following are the possible |
573 // values for the _implementor field: | 809 // values for the _implementor field: |
574 // NULL - no implementor | 810 // NULL - no implementor |
575 // implementor klassOop - one implementor | 811 // implementor Klass* - one implementor |
576 // self - more than one implementor | 812 // self - more than one implementor |
577 // | 813 // |
578 // The _implementor field only exists for interfaces. | 814 // The _implementor field only exists for interfaces. |
579 void instanceKlass::add_implementor(klassOop k) { | 815 void InstanceKlass::add_implementor(Klass* k) { |
580 assert(Compile_lock->owned_by_self(), ""); | 816 assert(Compile_lock->owned_by_self(), ""); |
581 assert(is_interface(), "not interface"); | 817 assert(is_interface(), "not interface"); |
582 // Filter out my subinterfaces. | 818 // Filter out my subinterfaces. |
583 // (Note: Interfaces are never on the subklass list.) | 819 // (Note: Interfaces are never on the subklass list.) |
584 if (instanceKlass::cast(k)->is_interface()) return; | 820 if (InstanceKlass::cast(k)->is_interface()) return; |
585 | 821 |
586 // Filter out subclasses whose supers already implement me. | 822 // Filter out subclasses whose supers already implement me. |
587 // (Note: CHA must walk subclasses of direct implementors | 823 // (Note: CHA must walk subclasses of direct implementors |
588 // in order to locate indirect implementors.) | 824 // in order to locate indirect implementors.) |
589 klassOop sk = instanceKlass::cast(k)->super(); | 825 Klass* sk = InstanceKlass::cast(k)->super(); |
590 if (sk != NULL && instanceKlass::cast(sk)->implements_interface(as_klassOop())) | 826 if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this)) |
591 // We only need to check one immediate superclass, since the | 827 // We only need to check one immediate superclass, since the |
592 // implements_interface query looks at transitive_interfaces. | 828 // implements_interface query looks at transitive_interfaces. |
593 // Any supers of the super have the same (or fewer) transitive_interfaces. | 829 // Any supers of the super have the same (or fewer) transitive_interfaces. |
594 return; | 830 return; |
595 | 831 |
596 klassOop ik = implementor(); | 832 Klass* ik = implementor(); |
597 if (ik == NULL) { | 833 if (ik == NULL) { |
598 set_implementor(k); | 834 set_implementor(k); |
599 } else if (ik != this->as_klassOop()) { | 835 } else if (ik != this) { |
600 // There is already an implementor. Use itself as an indicator of | 836 // There is already an implementor. Use itself as an indicator of |
601 // more than one implementors. | 837 // more than one implementors. |
602 set_implementor(this->as_klassOop()); | 838 set_implementor(this); |
603 } | 839 } |
604 | 840 |
605 // The implementor also implements the transitive_interfaces | 841 // The implementor also implements the transitive_interfaces |
606 for (int index = 0; index < local_interfaces()->length(); index++) { | 842 for (int index = 0; index < local_interfaces()->length(); index++) { |
607 instanceKlass::cast(klassOop(local_interfaces()->obj_at(index)))->add_implementor(k); | 843 InstanceKlass::cast(local_interfaces()->at(index))->add_implementor(k); |
608 } | 844 } |
609 } | 845 } |
610 | 846 |
611 void instanceKlass::init_implementor() { | 847 void InstanceKlass::init_implementor() { |
612 if (is_interface()) { | 848 if (is_interface()) { |
613 set_implementor(NULL); | 849 set_implementor(NULL); |
614 } | 850 } |
615 } | 851 } |
616 | 852 |
617 | 853 |
618 void instanceKlass::process_interfaces(Thread *thread) { | 854 void InstanceKlass::process_interfaces(Thread *thread) { |
619 // link this class into the implementors list of every interface it implements | 855 // link this class into the implementors list of every interface it implements |
620 KlassHandle this_as_oop (thread, this->as_klassOop()); | 856 Klass* this_as_klass_oop = this; |
621 for (int i = local_interfaces()->length() - 1; i >= 0; i--) { | 857 for (int i = local_interfaces()->length() - 1; i >= 0; i--) { |
622 assert(local_interfaces()->obj_at(i)->is_klass(), "must be a klass"); | 858 assert(local_interfaces()->at(i)->is_klass(), "must be a klass"); |
623 instanceKlass* interf = instanceKlass::cast(klassOop(local_interfaces()->obj_at(i))); | 859 InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i)); |
624 assert(interf->is_interface(), "expected interface"); | 860 assert(interf->is_interface(), "expected interface"); |
625 interf->add_implementor(this_as_oop()); | 861 interf->add_implementor(this_as_klass_oop); |
626 } | 862 } |
627 } | 863 } |
628 | 864 |
629 bool instanceKlass::can_be_primary_super_slow() const { | 865 bool InstanceKlass::can_be_primary_super_slow() const { |
630 if (is_interface()) | 866 if (is_interface()) |
631 return false; | 867 return false; |
632 else | 868 else |
633 return Klass::can_be_primary_super_slow(); | 869 return Klass::can_be_primary_super_slow(); |
634 } | 870 } |
635 | 871 |
636 objArrayOop instanceKlass::compute_secondary_supers(int num_extra_slots, TRAPS) { | 872 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots) { |
637 // The secondaries are the implemented interfaces. | 873 // The secondaries are the implemented interfaces. |
638 instanceKlass* ik = instanceKlass::cast(as_klassOop()); | 874 InstanceKlass* ik = InstanceKlass::cast(this); |
639 objArrayHandle interfaces (THREAD, ik->transitive_interfaces()); | 875 Array<Klass*>* interfaces = ik->transitive_interfaces(); |
640 int num_secondaries = num_extra_slots + interfaces->length(); | 876 int num_secondaries = num_extra_slots + interfaces->length(); |
641 if (num_secondaries == 0) { | 877 if (num_secondaries == 0) { |
642 return Universe::the_empty_system_obj_array(); | 878 // Must share this for correct bootstrapping! |
879 set_secondary_supers(Universe::the_empty_klass_array()); | |
880 return NULL; | |
643 } else if (num_extra_slots == 0) { | 881 } else if (num_extra_slots == 0) { |
644 return interfaces(); | 882 // The secondary super list is exactly the same as the transitive interfaces. |
883 // Redefine classes has to be careful not to delete this! | |
884 set_secondary_supers(interfaces); | |
885 return NULL; | |
645 } else { | 886 } else { |
646 // a mix of both | 887 // Copy transitive interfaces to a temporary growable array to be constructed |
647 objArrayOop secondaries = oopFactory::new_system_objArray(num_secondaries, CHECK_NULL); | 888 // into the secondary super list with extra slots. |
889 GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length()); | |
648 for (int i = 0; i < interfaces->length(); i++) { | 890 for (int i = 0; i < interfaces->length(); i++) { |
649 secondaries->obj_at_put(num_extra_slots+i, interfaces->obj_at(i)); | 891 secondaries->push(interfaces->at(i)); |
650 } | 892 } |
651 return secondaries; | 893 return secondaries; |
652 } | 894 } |
653 } | 895 } |
654 | 896 |
655 bool instanceKlass::compute_is_subtype_of(klassOop k) { | 897 bool InstanceKlass::compute_is_subtype_of(Klass* k) { |
656 if (Klass::cast(k)->is_interface()) { | 898 if (Klass::cast(k)->is_interface()) { |
657 return implements_interface(k); | 899 return implements_interface(k); |
658 } else { | 900 } else { |
659 return Klass::compute_is_subtype_of(k); | 901 return Klass::compute_is_subtype_of(k); |
660 } | 902 } |
661 } | 903 } |
662 | 904 |
663 bool instanceKlass::implements_interface(klassOop k) const { | 905 bool InstanceKlass::implements_interface(Klass* k) const { |
664 if (as_klassOop() == k) return true; | 906 if (this == k) return true; |
665 assert(Klass::cast(k)->is_interface(), "should be an interface class"); | 907 assert(Klass::cast(k)->is_interface(), "should be an interface class"); |
666 for (int i = 0; i < transitive_interfaces()->length(); i++) { | 908 for (int i = 0; i < transitive_interfaces()->length(); i++) { |
667 if (transitive_interfaces()->obj_at(i) == k) { | 909 if (transitive_interfaces()->at(i) == k) { |
668 return true; | 910 return true; |
669 } | 911 } |
670 } | 912 } |
671 return false; | 913 return false; |
672 } | 914 } |
673 | 915 |
674 objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) { | 916 objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPS) { |
675 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); | 917 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
676 if (length > arrayOopDesc::max_array_length(T_OBJECT)) { | 918 if (length > arrayOopDesc::max_array_length(T_OBJECT)) { |
677 report_java_out_of_memory("Requested array size exceeds VM limit"); | 919 report_java_out_of_memory("Requested array size exceeds VM limit"); |
678 JvmtiExport::post_array_size_exhausted(); | 920 JvmtiExport::post_array_size_exhausted(); |
679 THROW_OOP_0(Universe::out_of_memory_error_array_size()); | 921 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
680 } | 922 } |
681 int size = objArrayOopDesc::object_size(length); | 923 int size = objArrayOopDesc::object_size(length); |
682 klassOop ak = array_klass(n, CHECK_NULL); | 924 Klass* ak = array_klass(n, CHECK_NULL); |
683 KlassHandle h_ak (THREAD, ak); | 925 KlassHandle h_ak (THREAD, ak); |
684 objArrayOop o = | 926 objArrayOop o = |
685 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); | 927 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); |
686 return o; | 928 return o; |
687 } | 929 } |
688 | 930 |
689 instanceOop instanceKlass::register_finalizer(instanceOop i, TRAPS) { | 931 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) { |
690 if (TraceFinalizerRegistration) { | 932 if (TraceFinalizerRegistration) { |
691 tty->print("Registered "); | 933 tty->print("Registered "); |
692 i->print_value_on(tty); | 934 i->print_value_on(tty); |
693 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i); | 935 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i); |
694 } | 936 } |
699 methodHandle mh (THREAD, Universe::finalizer_register_method()); | 941 methodHandle mh (THREAD, Universe::finalizer_register_method()); |
700 JavaCalls::call(&result, mh, &args, CHECK_NULL); | 942 JavaCalls::call(&result, mh, &args, CHECK_NULL); |
701 return h_i(); | 943 return h_i(); |
702 } | 944 } |
703 | 945 |
704 instanceOop instanceKlass::allocate_instance(TRAPS) { | 946 instanceOop InstanceKlass::allocate_instance(TRAPS) { |
705 assert(!oop_is_instanceMirror(), "wrong allocation path"); | |
706 bool has_finalizer_flag = has_finalizer(); // Query before possible GC | 947 bool has_finalizer_flag = has_finalizer(); // Query before possible GC |
707 int size = size_helper(); // Query before forming handle. | 948 int size = size_helper(); // Query before forming handle. |
708 | 949 |
709 KlassHandle h_k(THREAD, as_klassOop()); | 950 KlassHandle h_k(THREAD, this); |
710 | 951 |
711 instanceOop i; | 952 instanceOop i; |
712 | 953 |
713 i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL); | 954 i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL); |
714 if (has_finalizer_flag && !RegisterFinalizersAtInit) { | 955 if (has_finalizer_flag && !RegisterFinalizersAtInit) { |
715 i = register_finalizer(i, CHECK_NULL); | 956 i = register_finalizer(i, CHECK_NULL); |
716 } | 957 } |
717 return i; | 958 return i; |
718 } | 959 } |
719 | 960 |
720 instanceOop instanceKlass::allocate_permanent_instance(TRAPS) { | 961 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) { |
721 // Finalizer registration occurs in the Object.<init> constructor | |
722 // and constructors normally aren't run when allocating perm | |
723 // instances so simply disallow finalizable perm objects. This can | |
724 // be relaxed if a need for it is found. | |
725 assert(!has_finalizer(), "perm objects not allowed to have finalizers"); | |
726 assert(!oop_is_instanceMirror(), "wrong allocation path"); | |
727 int size = size_helper(); // Query before forming handle. | |
728 KlassHandle h_k(THREAD, as_klassOop()); | |
729 instanceOop i = (instanceOop) | |
730 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); | |
731 return i; | |
732 } | |
733 | |
734 void instanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) { | |
735 if (is_interface() || is_abstract()) { | 962 if (is_interface() || is_abstract()) { |
736 ResourceMark rm(THREAD); | 963 ResourceMark rm(THREAD); |
737 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() | 964 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
738 : vmSymbols::java_lang_InstantiationException(), external_name()); | 965 : vmSymbols::java_lang_InstantiationException(), external_name()); |
739 } | 966 } |
740 if (as_klassOop() == SystemDictionary::Class_klass()) { | 967 if (this == SystemDictionary::Class_klass()) { |
741 ResourceMark rm(THREAD); | 968 ResourceMark rm(THREAD); |
742 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError() | 969 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError() |
743 : vmSymbols::java_lang_IllegalAccessException(), external_name()); | 970 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
744 } | 971 } |
745 } | 972 } |
746 | 973 |
747 klassOop instanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { | 974 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
748 instanceKlassHandle this_oop(THREAD, as_klassOop()); | 975 instanceKlassHandle this_oop(THREAD, this); |
749 return array_klass_impl(this_oop, or_null, n, THREAD); | 976 return array_klass_impl(this_oop, or_null, n, THREAD); |
750 } | 977 } |
751 | 978 |
752 klassOop instanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { | 979 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { |
753 if (this_oop->array_klasses() == NULL) { | 980 if (this_oop->array_klasses() == NULL) { |
754 if (or_null) return NULL; | 981 if (or_null) return NULL; |
755 | 982 |
756 ResourceMark rm; | 983 ResourceMark rm; |
757 JavaThread *jt = (JavaThread *)THREAD; | 984 JavaThread *jt = (JavaThread *)THREAD; |
760 MutexLocker mc(Compile_lock, THREAD); // for vtables | 987 MutexLocker mc(Compile_lock, THREAD); // for vtables |
761 MutexLocker ma(MultiArray_lock, THREAD); | 988 MutexLocker ma(MultiArray_lock, THREAD); |
762 | 989 |
763 // Check if update has already taken place | 990 // Check if update has already taken place |
764 if (this_oop->array_klasses() == NULL) { | 991 if (this_oop->array_klasses() == NULL) { |
765 objArrayKlassKlass* oakk = | 992 Klass* k = objArrayKlass::allocate_objArray_klass(this_oop->class_loader_data(), 1, this_oop, CHECK_NULL); |
766 (objArrayKlassKlass*)Universe::objArrayKlassKlassObj()->klass_part(); | |
767 | |
768 klassOop k = oakk->allocate_objArray_klass(1, this_oop, CHECK_NULL); | |
769 this_oop->set_array_klasses(k); | 993 this_oop->set_array_klasses(k); |
770 } | 994 } |
771 } | 995 } |
772 } | 996 } |
773 // _this will always be set at this point | 997 // _this will always be set at this point |
774 objArrayKlass* oak = (objArrayKlass*)this_oop->array_klasses()->klass_part(); | 998 objArrayKlass* oak = (objArrayKlass*)this_oop->array_klasses(); |
775 if (or_null) { | 999 if (or_null) { |
776 return oak->array_klass_or_null(n); | 1000 return oak->array_klass_or_null(n); |
777 } | 1001 } |
778 return oak->array_klass(n, CHECK_NULL); | 1002 return oak->array_klass(n, CHECK_NULL); |
779 } | 1003 } |
780 | 1004 |
781 klassOop instanceKlass::array_klass_impl(bool or_null, TRAPS) { | 1005 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) { |
782 return array_klass_impl(or_null, 1, THREAD); | 1006 return array_klass_impl(or_null, 1, THREAD); |
783 } | 1007 } |
784 | 1008 |
785 void instanceKlass::call_class_initializer(TRAPS) { | 1009 void InstanceKlass::call_class_initializer(TRAPS) { |
786 instanceKlassHandle ik (THREAD, as_klassOop()); | 1010 instanceKlassHandle ik (THREAD, this); |
787 call_class_initializer_impl(ik, THREAD); | 1011 call_class_initializer_impl(ik, THREAD); |
788 } | 1012 } |
789 | 1013 |
790 static int call_class_initializer_impl_counter = 0; // for debugging | 1014 static int call_class_initializer_impl_counter = 0; // for debugging |
791 | 1015 |
792 methodOop instanceKlass::class_initializer() { | 1016 Method* InstanceKlass::class_initializer() { |
793 methodOop clinit = find_method( | 1017 Method* clinit = find_method( |
794 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); | 1018 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
795 if (clinit != NULL && clinit->has_valid_initializer_flags()) { | 1019 if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
796 return clinit; | 1020 return clinit; |
797 } | 1021 } |
798 return NULL; | 1022 return NULL; |
799 } | 1023 } |
800 | 1024 |
801 void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { | 1025 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { |
802 methodHandle h_method(THREAD, this_oop->class_initializer()); | 1026 methodHandle h_method(THREAD, this_oop->class_initializer()); |
803 assert(!this_oop->is_initialized(), "we cannot initialize twice"); | 1027 assert(!this_oop->is_initialized(), "we cannot initialize twice"); |
804 if (TraceClassInitialization) { | 1028 if (TraceClassInitialization) { |
805 tty->print("%d Initializing ", call_class_initializer_impl_counter++); | 1029 tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
806 this_oop->name()->print_value(); | 1030 this_oop->name()->print_value(); |
812 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) | 1036 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |
813 } | 1037 } |
814 } | 1038 } |
815 | 1039 |
816 | 1040 |
817 void instanceKlass::mask_for(methodHandle method, int bci, | 1041 void InstanceKlass::mask_for(methodHandle method, int bci, |
818 InterpreterOopMap* entry_for) { | 1042 InterpreterOopMap* entry_for) { |
819 // Dirty read, then double-check under a lock. | 1043 // Dirty read, then double-check under a lock. |
820 if (_oop_map_cache == NULL) { | 1044 if (_oop_map_cache == NULL) { |
821 // Otherwise, allocate a new one. | 1045 // Otherwise, allocate a new one. |
822 MutexLocker x(OopMapCacheAlloc_lock); | 1046 MutexLocker x(OopMapCacheAlloc_lock); |
828 // _oop_map_cache is constant after init; lookup below does is own locking. | 1052 // _oop_map_cache is constant after init; lookup below does is own locking. |
829 _oop_map_cache->lookup(method, bci, entry_for); | 1053 _oop_map_cache->lookup(method, bci, entry_for); |
830 } | 1054 } |
831 | 1055 |
832 | 1056 |
833 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { | 1057 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
834 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { | 1058 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
835 Symbol* f_name = fs.name(); | 1059 Symbol* f_name = fs.name(); |
836 Symbol* f_sig = fs.signature(); | 1060 Symbol* f_sig = fs.signature(); |
837 if (f_name == name && f_sig == sig) { | 1061 if (f_name == name && f_sig == sig) { |
838 fd->initialize(as_klassOop(), fs.index()); | 1062 fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); |
839 return true; | 1063 return true; |
840 } | 1064 } |
841 } | 1065 } |
842 return false; | 1066 return false; |
843 } | 1067 } |
844 | 1068 |
845 | 1069 |
846 void instanceKlass::shared_symbols_iterate(SymbolClosure* closure) { | 1070 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
847 Klass::shared_symbols_iterate(closure); | |
848 closure->do_symbol(&_generic_signature); | |
849 closure->do_symbol(&_source_file_name); | |
850 | |
851 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { | |
852 int name_index = fs.name_index(); | |
853 closure->do_symbol(constants()->symbol_at_addr(name_index)); | |
854 int sig_index = fs.signature_index(); | |
855 closure->do_symbol(constants()->symbol_at_addr(sig_index)); | |
856 } | |
857 } | |
858 | |
859 | |
860 klassOop instanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { | |
861 const int n = local_interfaces()->length(); | 1071 const int n = local_interfaces()->length(); |
862 for (int i = 0; i < n; i++) { | 1072 for (int i = 0; i < n; i++) { |
863 klassOop intf1 = klassOop(local_interfaces()->obj_at(i)); | 1073 Klass* intf1 = local_interfaces()->at(i); |
864 assert(Klass::cast(intf1)->is_interface(), "just checking type"); | 1074 assert(Klass::cast(intf1)->is_interface(), "just checking type"); |
865 // search for field in current interface | 1075 // search for field in current interface |
866 if (instanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { | 1076 if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { |
867 assert(fd->is_static(), "interface field must be static"); | 1077 assert(fd->is_static(), "interface field must be static"); |
868 return intf1; | 1078 return intf1; |
869 } | 1079 } |
870 // search for field in direct superinterfaces | 1080 // search for field in direct superinterfaces |
871 klassOop intf2 = instanceKlass::cast(intf1)->find_interface_field(name, sig, fd); | 1081 Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd); |
872 if (intf2 != NULL) return intf2; | 1082 if (intf2 != NULL) return intf2; |
873 } | 1083 } |
874 // otherwise field lookup fails | 1084 // otherwise field lookup fails |
875 return NULL; | 1085 return NULL; |
876 } | 1086 } |
877 | 1087 |
878 | 1088 |
879 klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { | 1089 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
880 // search order according to newest JVM spec (5.4.3.2, p.167). | 1090 // search order according to newest JVM spec (5.4.3.2, p.167). |
881 // 1) search for field in current klass | 1091 // 1) search for field in current klass |
882 if (find_local_field(name, sig, fd)) { | 1092 if (find_local_field(name, sig, fd)) { |
883 return as_klassOop(); | 1093 return const_cast<InstanceKlass*>(this); |
884 } | 1094 } |
885 // 2) search for field recursively in direct superinterfaces | 1095 // 2) search for field recursively in direct superinterfaces |
886 { klassOop intf = find_interface_field(name, sig, fd); | 1096 { Klass* intf = find_interface_field(name, sig, fd); |
887 if (intf != NULL) return intf; | 1097 if (intf != NULL) return intf; |
888 } | 1098 } |
889 // 3) apply field lookup recursively if superclass exists | 1099 // 3) apply field lookup recursively if superclass exists |
890 { klassOop supr = super(); | 1100 { Klass* supr = super(); |
891 if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, fd); | 1101 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, fd); |
892 } | 1102 } |
893 // 4) otherwise field lookup fails | 1103 // 4) otherwise field lookup fails |
894 return NULL; | 1104 return NULL; |
895 } | 1105 } |
896 | 1106 |
897 | 1107 |
898 klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { | 1108 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { |
899 // search order according to newest JVM spec (5.4.3.2, p.167). | 1109 // search order according to newest JVM spec (5.4.3.2, p.167). |
900 // 1) search for field in current klass | 1110 // 1) search for field in current klass |
901 if (find_local_field(name, sig, fd)) { | 1111 if (find_local_field(name, sig, fd)) { |
902 if (fd->is_static() == is_static) return as_klassOop(); | 1112 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this); |
903 } | 1113 } |
904 // 2) search for field recursively in direct superinterfaces | 1114 // 2) search for field recursively in direct superinterfaces |
905 if (is_static) { | 1115 if (is_static) { |
906 klassOop intf = find_interface_field(name, sig, fd); | 1116 Klass* intf = find_interface_field(name, sig, fd); |
907 if (intf != NULL) return intf; | 1117 if (intf != NULL) return intf; |
908 } | 1118 } |
909 // 3) apply field lookup recursively if superclass exists | 1119 // 3) apply field lookup recursively if superclass exists |
910 { klassOop supr = super(); | 1120 { Klass* supr = super(); |
911 if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, is_static, fd); | 1121 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd); |
912 } | 1122 } |
913 // 4) otherwise field lookup fails | 1123 // 4) otherwise field lookup fails |
914 return NULL; | 1124 return NULL; |
915 } | 1125 } |
916 | 1126 |
917 | 1127 |
918 bool instanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { | 1128 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
919 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { | 1129 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
920 if (fs.offset() == offset) { | 1130 if (fs.offset() == offset) { |
921 fd->initialize(as_klassOop(), fs.index()); | 1131 fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); |
922 if (fd->is_static() == is_static) return true; | 1132 if (fd->is_static() == is_static) return true; |
923 } | 1133 } |
924 } | 1134 } |
925 return false; | 1135 return false; |
926 } | 1136 } |
927 | 1137 |
928 | 1138 |
929 bool instanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { | 1139 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
930 klassOop klass = as_klassOop(); | 1140 Klass* klass = const_cast<InstanceKlass*>(this); |
931 while (klass != NULL) { | 1141 while (klass != NULL) { |
932 if (instanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { | 1142 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { |
933 return true; | 1143 return true; |
934 } | 1144 } |
935 klass = Klass::cast(klass)->super(); | 1145 klass = Klass::cast(klass)->super(); |
936 } | 1146 } |
937 return false; | 1147 return false; |
938 } | 1148 } |
939 | 1149 |
940 | 1150 |
941 void instanceKlass::methods_do(void f(methodOop method)) { | 1151 void InstanceKlass::methods_do(void f(Method* method)) { |
942 int len = methods()->length(); | 1152 int len = methods()->length(); |
943 for (int index = 0; index < len; index++) { | 1153 for (int index = 0; index < len; index++) { |
944 methodOop m = methodOop(methods()->obj_at(index)); | 1154 Method* m = methods()->at(index); |
945 assert(m->is_method(), "must be method"); | 1155 assert(m->is_method(), "must be method"); |
946 f(m); | 1156 f(m); |
947 } | 1157 } |
948 } | 1158 } |
949 | 1159 |
950 | 1160 |
951 void instanceKlass::do_local_static_fields(FieldClosure* cl) { | 1161 void InstanceKlass::do_local_static_fields(FieldClosure* cl) { |
952 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { | 1162 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
953 if (fs.access_flags().is_static()) { | 1163 if (fs.access_flags().is_static()) { |
954 fieldDescriptor fd; | 1164 fieldDescriptor fd; |
955 fd.initialize(as_klassOop(), fs.index()); | 1165 fd.initialize(this, fs.index()); |
956 cl->do_field(&fd); | 1166 cl->do_field(&fd); |
957 } | 1167 } |
958 } | 1168 } |
959 } | 1169 } |
960 | 1170 |
961 | 1171 |
962 void instanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { | 1172 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { |
963 instanceKlassHandle h_this(THREAD, as_klassOop()); | 1173 instanceKlassHandle h_this(THREAD, this); |
964 do_local_static_fields_impl(h_this, f, CHECK); | 1174 do_local_static_fields_impl(h_this, f, CHECK); |
965 } | 1175 } |
966 | 1176 |
967 | 1177 |
968 void instanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { | 1178 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { |
969 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { | 1179 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { |
970 if (fs.access_flags().is_static()) { | 1180 if (fs.access_flags().is_static()) { |
971 fieldDescriptor fd; | 1181 fieldDescriptor fd; |
972 fd.initialize(this_oop(), fs.index()); | 1182 fd.initialize(this_oop(), fs.index()); |
973 f(&fd, CHECK); | 1183 f(&fd, CHECK); |
978 | 1188 |
979 static int compare_fields_by_offset(int* a, int* b) { | 1189 static int compare_fields_by_offset(int* a, int* b) { |
980 return a[0] - b[0]; | 1190 return a[0] - b[0]; |
981 } | 1191 } |
982 | 1192 |
983 void instanceKlass::do_nonstatic_fields(FieldClosure* cl) { | 1193 void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) { |
984 instanceKlass* super = superklass(); | 1194 InstanceKlass* super = superklass(); |
985 if (super != NULL) { | 1195 if (super != NULL) { |
986 super->do_nonstatic_fields(cl); | 1196 super->do_nonstatic_fields(cl); |
987 } | 1197 } |
988 fieldDescriptor fd; | 1198 fieldDescriptor fd; |
989 int length = java_fields_count(); | 1199 int length = java_fields_count(); |
990 // In DebugInfo nonstatic fields are sorted by offset. | 1200 // In DebugInfo nonstatic fields are sorted by offset. |
991 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass); | 1201 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass); |
992 int j = 0; | 1202 int j = 0; |
993 for (int i = 0; i < length; i += 1) { | 1203 for (int i = 0; i < length; i += 1) { |
994 fd.initialize(as_klassOop(), i); | 1204 fd.initialize(this, i); |
995 if (!fd.is_static()) { | 1205 if (!fd.is_static()) { |
996 fields_sorted[j + 0] = fd.offset(); | 1206 fields_sorted[j + 0] = fd.offset(); |
997 fields_sorted[j + 1] = i; | 1207 fields_sorted[j + 1] = i; |
998 j += 2; | 1208 j += 2; |
999 } | 1209 } |
1001 if (j > 0) { | 1211 if (j > 0) { |
1002 length = j; | 1212 length = j; |
1003 // _sort_Fn is defined in growableArray.hpp. | 1213 // _sort_Fn is defined in growableArray.hpp. |
1004 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); | 1214 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); |
1005 for (int i = 0; i < length; i += 2) { | 1215 for (int i = 0; i < length; i += 2) { |
1006 fd.initialize(as_klassOop(), fields_sorted[i + 1]); | 1216 fd.initialize(this, fields_sorted[i + 1]); |
1007 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); | 1217 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); |
1008 cl->do_field(&fd); | 1218 cl->do_field(&fd); |
1009 } | 1219 } |
1010 } | 1220 } |
1011 FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass); | 1221 FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass); |
1012 } | 1222 } |
1013 | 1223 |
1014 | 1224 |
1015 void instanceKlass::array_klasses_do(void f(klassOop k)) { | 1225 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) { |
1226 if (array_klasses() != NULL) | |
1227 arrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD); | |
1228 } | |
1229 | |
1230 void InstanceKlass::array_klasses_do(void f(Klass* k)) { | |
1016 if (array_klasses() != NULL) | 1231 if (array_klasses() != NULL) |
1017 arrayKlass::cast(array_klasses())->array_klasses_do(f); | 1232 arrayKlass::cast(array_klasses())->array_klasses_do(f); |
1018 } | 1233 } |
1019 | 1234 |
1020 | 1235 |
1021 void instanceKlass::with_array_klasses_do(void f(klassOop k)) { | 1236 void InstanceKlass::with_array_klasses_do(void f(Klass* k)) { |
1022 f(as_klassOop()); | 1237 f(this); |
1023 array_klasses_do(f); | 1238 array_klasses_do(f); |
1024 } | 1239 } |
1025 | 1240 |
1026 #ifdef ASSERT | 1241 #ifdef ASSERT |
1027 static int linear_search(objArrayOop methods, Symbol* name, Symbol* signature) { | 1242 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1028 int len = methods->length(); | 1243 int len = methods->length(); |
1029 for (int index = 0; index < len; index++) { | 1244 for (int index = 0; index < len; index++) { |
1030 methodOop m = (methodOop)(methods->obj_at(index)); | 1245 Method* m = methods->at(index); |
1031 assert(m->is_method(), "must be method"); | 1246 assert(m->is_method(), "must be method"); |
1032 if (m->signature() == signature && m->name() == name) { | 1247 if (m->signature() == signature && m->name() == name) { |
1033 return index; | 1248 return index; |
1034 } | 1249 } |
1035 } | 1250 } |
1036 return -1; | 1251 return -1; |
1037 } | 1252 } |
1038 #endif | 1253 #endif |
1039 | 1254 |
1040 methodOop instanceKlass::find_method(Symbol* name, Symbol* signature) const { | 1255 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1041 return instanceKlass::find_method(methods(), name, signature); | 1256 return InstanceKlass::find_method(methods(), name, signature); |
1042 } | 1257 } |
1043 | 1258 |
1044 methodOop instanceKlass::find_method(objArrayOop methods, Symbol* name, Symbol* signature) { | 1259 Method* InstanceKlass::find_method(Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1045 int len = methods->length(); | 1260 int len = methods->length(); |
1046 // methods are sorted, so do binary search | 1261 // methods are sorted, so do binary search |
1047 int l = 0; | 1262 int l = 0; |
1048 int h = len - 1; | 1263 int h = len - 1; |
1049 while (l <= h) { | 1264 while (l <= h) { |
1050 int mid = (l + h) >> 1; | 1265 int mid = (l + h) >> 1; |
1051 methodOop m = (methodOop)methods->obj_at(mid); | 1266 Method* m = methods->at(mid); |
1052 assert(m->is_method(), "must be method"); | 1267 assert(m->is_method(), "must be method"); |
1053 int res = m->name()->fast_compare(name); | 1268 int res = m->name()->fast_compare(name); |
1054 if (res == 0) { | 1269 if (res == 0) { |
1055 // found matching name; do linear search to find matching signature | 1270 // found matching name; do linear search to find matching signature |
1056 // first, quick check for common case | 1271 // first, quick check for common case |
1057 if (m->signature() == signature) return m; | 1272 if (m->signature() == signature) return m; |
1058 // search downwards through overloaded methods | 1273 // search downwards through overloaded methods |
1059 int i; | 1274 int i; |
1060 for (i = mid - 1; i >= l; i--) { | 1275 for (i = mid - 1; i >= l; i--) { |
1061 methodOop m = (methodOop)methods->obj_at(i); | 1276 Method* m = methods->at(i); |
1062 assert(m->is_method(), "must be method"); | 1277 assert(m->is_method(), "must be method"); |
1063 if (m->name() != name) break; | 1278 if (m->name() != name) break; |
1064 if (m->signature() == signature) return m; | 1279 if (m->signature() == signature) return m; |
1065 } | 1280 } |
1066 // search upwards | 1281 // search upwards |
1067 for (i = mid + 1; i <= h; i++) { | 1282 for (i = mid + 1; i <= h; i++) { |
1068 methodOop m = (methodOop)methods->obj_at(i); | 1283 Method* m = methods->at(i); |
1069 assert(m->is_method(), "must be method"); | 1284 assert(m->is_method(), "must be method"); |
1070 if (m->name() != name) break; | 1285 if (m->name() != name) break; |
1071 if (m->signature() == signature) return m; | 1286 if (m->signature() == signature) return m; |
1072 } | 1287 } |
1073 // not found | 1288 // not found |
1087 assert(index == -1, err_msg("binary search should have found entry %d", index)); | 1302 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1088 #endif | 1303 #endif |
1089 return NULL; | 1304 return NULL; |
1090 } | 1305 } |
1091 | 1306 |
1092 methodOop instanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { | 1307 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1093 klassOop klass = as_klassOop(); | 1308 Klass* klass = const_cast<InstanceKlass*>(this); |
1094 while (klass != NULL) { | 1309 while (klass != NULL) { |
1095 methodOop method = instanceKlass::cast(klass)->find_method(name, signature); | 1310 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); |
1096 if (method != NULL) return method; | 1311 if (method != NULL) return method; |
1097 klass = instanceKlass::cast(klass)->super(); | 1312 klass = InstanceKlass::cast(klass)->super(); |
1098 } | 1313 } |
1099 return NULL; | 1314 return NULL; |
1100 } | 1315 } |
1101 | 1316 |
1102 // lookup a method in all the interfaces that this class implements | 1317 // lookup a method in all the interfaces that this class implements |
1103 methodOop instanceKlass::lookup_method_in_all_interfaces(Symbol* name, | 1318 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
1104 Symbol* signature) const { | 1319 Symbol* signature) const { |
1105 objArrayOop all_ifs = instanceKlass::cast(as_klassOop())->transitive_interfaces(); | 1320 Array<Klass*>* all_ifs = transitive_interfaces(); |
1106 int num_ifs = all_ifs->length(); | 1321 int num_ifs = all_ifs->length(); |
1107 instanceKlass *ik = NULL; | 1322 InstanceKlass *ik = NULL; |
1108 for (int i = 0; i < num_ifs; i++) { | 1323 for (int i = 0; i < num_ifs; i++) { |
1109 ik = instanceKlass::cast(klassOop(all_ifs->obj_at(i))); | 1324 ik = InstanceKlass::cast(all_ifs->at(i)); |
1110 methodOop m = ik->lookup_method(name, signature); | 1325 Method* m = ik->lookup_method(name, signature); |
1111 if (m != NULL) { | 1326 if (m != NULL) { |
1112 return m; | 1327 return m; |
1113 } | 1328 } |
1114 } | 1329 } |
1115 return NULL; | 1330 return NULL; |
1116 } | 1331 } |
1117 | 1332 |
1118 /* jni_id_for_impl for jfieldIds only */ | 1333 /* jni_id_for_impl for jfieldIds only */ |
1119 JNIid* instanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) { | 1334 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) { |
1120 MutexLocker ml(JfieldIdCreation_lock); | 1335 MutexLocker ml(JfieldIdCreation_lock); |
1121 // Retry lookup after we got the lock | 1336 // Retry lookup after we got the lock |
1122 JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset); | 1337 JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset); |
1123 if (probe == NULL) { | 1338 if (probe == NULL) { |
1124 // Slow case, allocate new static field identifier | 1339 // Slow case, allocate new static field identifier |
1125 probe = new JNIid(this_oop->as_klassOop(), offset, this_oop->jni_ids()); | 1340 probe = new JNIid(this_oop(), offset, this_oop->jni_ids()); |
1126 this_oop->set_jni_ids(probe); | 1341 this_oop->set_jni_ids(probe); |
1127 } | 1342 } |
1128 return probe; | 1343 return probe; |
1129 } | 1344 } |
1130 | 1345 |
1131 | 1346 |
1132 /* jni_id_for for jfieldIds only */ | 1347 /* jni_id_for for jfieldIds only */ |
1133 JNIid* instanceKlass::jni_id_for(int offset) { | 1348 JNIid* InstanceKlass::jni_id_for(int offset) { |
1134 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset); | 1349 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset); |
1135 if (probe == NULL) { | 1350 if (probe == NULL) { |
1136 probe = jni_id_for_impl(this->as_klassOop(), offset); | 1351 probe = jni_id_for_impl(this, offset); |
1137 } | 1352 } |
1138 return probe; | 1353 return probe; |
1139 } | 1354 } |
1140 | 1355 |
1141 u2 instanceKlass::enclosing_method_data(int offset) { | 1356 u2 InstanceKlass::enclosing_method_data(int offset) { |
1142 typeArrayOop inner_class_list = inner_classes(); | 1357 Array<jushort>* inner_class_list = inner_classes(); |
1143 if (inner_class_list == NULL) { | 1358 if (inner_class_list == NULL) { |
1144 return 0; | 1359 return 0; |
1145 } | 1360 } |
1146 int length = inner_class_list->length(); | 1361 int length = inner_class_list->length(); |
1147 if (length % inner_class_next_offset == 0) { | 1362 if (length % inner_class_next_offset == 0) { |
1148 return 0; | 1363 return 0; |
1149 } else { | 1364 } else { |
1150 int index = length - enclosing_method_attribute_size; | 1365 int index = length - enclosing_method_attribute_size; |
1151 typeArrayHandle inner_class_list_h(inner_class_list); | |
1152 assert(offset < enclosing_method_attribute_size, "invalid offset"); | 1366 assert(offset < enclosing_method_attribute_size, "invalid offset"); |
1153 return inner_class_list_h->ushort_at(index + offset); | 1367 return inner_class_list->at(index + offset); |
1154 } | 1368 } |
1155 } | 1369 } |
1156 | 1370 |
1157 void instanceKlass::set_enclosing_method_indices(u2 class_index, | 1371 void InstanceKlass::set_enclosing_method_indices(u2 class_index, |
1158 u2 method_index) { | 1372 u2 method_index) { |
1159 typeArrayOop inner_class_list = inner_classes(); | 1373 Array<jushort>* inner_class_list = inner_classes(); |
1160 assert (inner_class_list != NULL, "_inner_classes list is not set up"); | 1374 assert (inner_class_list != NULL, "_inner_classes list is not set up"); |
1161 int length = inner_class_list->length(); | 1375 int length = inner_class_list->length(); |
1162 if (length % inner_class_next_offset == enclosing_method_attribute_size) { | 1376 if (length % inner_class_next_offset == enclosing_method_attribute_size) { |
1163 int index = length - enclosing_method_attribute_size; | 1377 int index = length - enclosing_method_attribute_size; |
1164 typeArrayHandle inner_class_list_h(inner_class_list); | 1378 inner_class_list->at_put( |
1165 inner_class_list_h->ushort_at_put( | |
1166 index + enclosing_method_class_index_offset, class_index); | 1379 index + enclosing_method_class_index_offset, class_index); |
1167 inner_class_list_h->ushort_at_put( | 1380 inner_class_list->at_put( |
1168 index + enclosing_method_method_index_offset, method_index); | 1381 index + enclosing_method_method_index_offset, method_index); |
1169 } | 1382 } |
1170 } | 1383 } |
1171 | 1384 |
1172 // Lookup or create a jmethodID. | 1385 // Lookup or create a jmethodID. |
1173 // This code is called by the VMThread and JavaThreads so the | 1386 // This code is called by the VMThread and JavaThreads so the |
1174 // locking has to be done very carefully to avoid deadlocks | 1387 // locking has to be done very carefully to avoid deadlocks |
1175 // and/or other cache consistency problems. | 1388 // and/or other cache consistency problems. |
1176 // | 1389 // |
1177 jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) { | 1390 jmethodID InstanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) { |
1178 size_t idnum = (size_t)method_h->method_idnum(); | 1391 size_t idnum = (size_t)method_h->method_idnum(); |
1179 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); | 1392 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
1180 size_t length = 0; | 1393 size_t length = 0; |
1181 jmethodID id = NULL; | 1394 jmethodID id = NULL; |
1182 | 1395 |
1243 | 1456 |
1244 // allocate a new jmethodID that might be used | 1457 // allocate a new jmethodID that might be used |
1245 jmethodID new_id = NULL; | 1458 jmethodID new_id = NULL; |
1246 if (method_h->is_old() && !method_h->is_obsolete()) { | 1459 if (method_h->is_old() && !method_h->is_obsolete()) { |
1247 // The method passed in is old (but not obsolete), we need to use the current version | 1460 // The method passed in is old (but not obsolete), we need to use the current version |
1248 methodOop current_method = ik_h->method_with_idnum((int)idnum); | 1461 Method* current_method = ik_h->method_with_idnum((int)idnum); |
1249 assert(current_method != NULL, "old and but not obsolete, so should exist"); | 1462 assert(current_method != NULL, "old and but not obsolete, so should exist"); |
1250 methodHandle current_method_h(current_method == NULL? method_h() : current_method); | 1463 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), current_method); |
1251 new_id = JNIHandles::make_jmethod_id(current_method_h); | |
1252 } else { | 1464 } else { |
1253 // It is the current version of the method or an obsolete method, | 1465 // It is the current version of the method or an obsolete method, |
1254 // use the version passed in | 1466 // use the version passed in |
1255 new_id = JNIHandles::make_jmethod_id(method_h); | 1467 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), method_h()); |
1256 } | 1468 } |
1257 | 1469 |
1258 if (Threads::number_of_threads() == 0 || | 1470 if (Threads::number_of_threads() == 0 || |
1259 SafepointSynchronize::is_at_safepoint()) { | 1471 SafepointSynchronize::is_at_safepoint()) { |
1260 // we're single threaded or at a safepoint - no locking needed | 1472 // we're single threaded or at a safepoint - no locking needed |
1271 if (to_dealloc_jmeths != NULL) { | 1483 if (to_dealloc_jmeths != NULL) { |
1272 FreeHeap(to_dealloc_jmeths); | 1484 FreeHeap(to_dealloc_jmeths); |
1273 } | 1485 } |
1274 // free up the new ID since it wasn't needed | 1486 // free up the new ID since it wasn't needed |
1275 if (to_dealloc_id != NULL) { | 1487 if (to_dealloc_id != NULL) { |
1276 JNIHandles::destroy_jmethod_id(to_dealloc_id); | 1488 Method::destroy_jmethod_id(ik_h->class_loader_data(), to_dealloc_id); |
1277 } | 1489 } |
1278 } | 1490 } |
1279 return id; | 1491 return id; |
1280 } | 1492 } |
1281 | 1493 |
1283 // Common code to fetch the jmethodID from the cache or update the | 1495 // Common code to fetch the jmethodID from the cache or update the |
1284 // cache with the new jmethodID. This function should never do anything | 1496 // cache with the new jmethodID. This function should never do anything |
1285 // that causes the caller to go to a safepoint or we can deadlock with | 1497 // that causes the caller to go to a safepoint or we can deadlock with |
1286 // the VMThread or have cache consistency issues. | 1498 // the VMThread or have cache consistency issues. |
1287 // | 1499 // |
1288 jmethodID instanceKlass::get_jmethod_id_fetch_or_update( | 1500 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update( |
1289 instanceKlassHandle ik_h, size_t idnum, jmethodID new_id, | 1501 instanceKlassHandle ik_h, size_t idnum, jmethodID new_id, |
1290 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, | 1502 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, |
1291 jmethodID** to_dealloc_jmeths_p) { | 1503 jmethodID** to_dealloc_jmeths_p) { |
1292 assert(new_id != NULL, "sanity check"); | 1504 assert(new_id != NULL, "sanity check"); |
1293 assert(to_dealloc_id_p != NULL, "sanity check"); | 1505 assert(to_dealloc_id_p != NULL, "sanity check"); |
1335 | 1547 |
1336 | 1548 |
1337 // Common code to get the jmethodID cache length and the jmethodID | 1549 // Common code to get the jmethodID cache length and the jmethodID |
1338 // value at index idnum if there is one. | 1550 // value at index idnum if there is one. |
1339 // | 1551 // |
1340 void instanceKlass::get_jmethod_id_length_value(jmethodID* cache, | 1552 void InstanceKlass::get_jmethod_id_length_value(jmethodID* cache, |
1341 size_t idnum, size_t *length_p, jmethodID* id_p) { | 1553 size_t idnum, size_t *length_p, jmethodID* id_p) { |
1342 assert(cache != NULL, "sanity check"); | 1554 assert(cache != NULL, "sanity check"); |
1343 assert(length_p != NULL, "sanity check"); | 1555 assert(length_p != NULL, "sanity check"); |
1344 assert(id_p != NULL, "sanity check"); | 1556 assert(id_p != NULL, "sanity check"); |
1345 | 1557 |
1352 } | 1564 } |
1353 } | 1565 } |
1354 | 1566 |
1355 | 1567 |
1356 // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles | 1568 // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles |
1357 jmethodID instanceKlass::jmethod_id_or_null(methodOop method) { | 1569 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) { |
1358 size_t idnum = (size_t)method->method_idnum(); | 1570 size_t idnum = (size_t)method->method_idnum(); |
1359 jmethodID* jmeths = methods_jmethod_ids_acquire(); | 1571 jmethodID* jmeths = methods_jmethod_ids_acquire(); |
1360 size_t length; // length assigned as debugging crumb | 1572 size_t length; // length assigned as debugging crumb |
1361 jmethodID id = NULL; | 1573 jmethodID id = NULL; |
1362 if (jmeths != NULL && // If there is a cache | 1574 if (jmeths != NULL && // If there is a cache |
1366 return id; | 1578 return id; |
1367 } | 1579 } |
1368 | 1580 |
1369 | 1581 |
1370 // Cache an itable index | 1582 // Cache an itable index |
1371 void instanceKlass::set_cached_itable_index(size_t idnum, int index) { | 1583 void InstanceKlass::set_cached_itable_index(size_t idnum, int index) { |
1372 int* indices = methods_cached_itable_indices_acquire(); | 1584 int* indices = methods_cached_itable_indices_acquire(); |
1373 int* to_dealloc_indices = NULL; | 1585 int* to_dealloc_indices = NULL; |
1374 | 1586 |
1375 // We use a double-check locking idiom here because this cache is | 1587 // We use a double-check locking idiom here because this cache is |
1376 // performance sensitive. In the normal system, this cache only | 1588 // performance sensitive. In the normal system, this cache only |
1436 } | 1648 } |
1437 } | 1649 } |
1438 | 1650 |
1439 | 1651 |
1440 // Retrieve a cached itable index | 1652 // Retrieve a cached itable index |
1441 int instanceKlass::cached_itable_index(size_t idnum) { | 1653 int InstanceKlass::cached_itable_index(size_t idnum) { |
1442 int* indices = methods_cached_itable_indices_acquire(); | 1654 int* indices = methods_cached_itable_indices_acquire(); |
1443 if (indices != NULL && ((size_t)indices[0]) > idnum) { | 1655 if (indices != NULL && ((size_t)indices[0]) > idnum) { |
1444 // indices exist and are long enough, retrieve possible cached | 1656 // indices exist and are long enough, retrieve possible cached |
1445 return indices[idnum+1]; | 1657 return indices[idnum+1]; |
1446 } | 1658 } |
1451 // | 1663 // |
1452 // Walk the list of dependent nmethods searching for nmethods which | 1664 // Walk the list of dependent nmethods searching for nmethods which |
1453 // are dependent on the changes that were passed in and mark them for | 1665 // are dependent on the changes that were passed in and mark them for |
1454 // deoptimization. Returns the number of nmethods found. | 1666 // deoptimization. Returns the number of nmethods found. |
1455 // | 1667 // |
1456 int instanceKlass::mark_dependent_nmethods(DepChange& changes) { | 1668 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) { |
1457 assert_locked_or_safepoint(CodeCache_lock); | 1669 assert_locked_or_safepoint(CodeCache_lock); |
1458 int found = 0; | 1670 int found = 0; |
1459 nmethodBucket* b = _dependencies; | 1671 nmethodBucket* b = _dependencies; |
1460 while (b != NULL) { | 1672 while (b != NULL) { |
1461 nmethod* nm = b->get_nmethod(); | 1673 nmethod* nm = b->get_nmethod(); |
1483 // Add an nmethodBucket to the list of dependencies for this nmethod. | 1695 // Add an nmethodBucket to the list of dependencies for this nmethod. |
1484 // It's possible that an nmethod has multiple dependencies on this klass | 1696 // It's possible that an nmethod has multiple dependencies on this klass |
1485 // so a count is kept for each bucket to guarantee that creation and | 1697 // so a count is kept for each bucket to guarantee that creation and |
1486 // deletion of dependencies is consistent. | 1698 // deletion of dependencies is consistent. |
1487 // | 1699 // |
1488 void instanceKlass::add_dependent_nmethod(nmethod* nm) { | 1700 void InstanceKlass::add_dependent_nmethod(nmethod* nm) { |
1489 assert_locked_or_safepoint(CodeCache_lock); | 1701 assert_locked_or_safepoint(CodeCache_lock); |
1490 nmethodBucket* b = _dependencies; | 1702 nmethodBucket* b = _dependencies; |
1491 nmethodBucket* last = NULL; | 1703 nmethodBucket* last = NULL; |
1492 while (b != NULL) { | 1704 while (b != NULL) { |
1493 if (nm == b->get_nmethod()) { | 1705 if (nm == b->get_nmethod()) { |
1504 // Decrement count of the nmethod in the dependency list and remove | 1716 // Decrement count of the nmethod in the dependency list and remove |
1505 // the bucket competely when the count goes to 0. This method must | 1717 // the bucket competely when the count goes to 0. This method must |
1506 // find a corresponding bucket otherwise there's a bug in the | 1718 // find a corresponding bucket otherwise there's a bug in the |
1507 // recording of dependecies. | 1719 // recording of dependecies. |
1508 // | 1720 // |
1509 void instanceKlass::remove_dependent_nmethod(nmethod* nm) { | 1721 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) { |
1510 assert_locked_or_safepoint(CodeCache_lock); | 1722 assert_locked_or_safepoint(CodeCache_lock); |
1511 nmethodBucket* b = _dependencies; | 1723 nmethodBucket* b = _dependencies; |
1512 nmethodBucket* last = NULL; | 1724 nmethodBucket* last = NULL; |
1513 while (b != NULL) { | 1725 while (b != NULL) { |
1514 if (nm == b->get_nmethod()) { | 1726 if (nm == b->get_nmethod()) { |
1532 ShouldNotReachHere(); | 1744 ShouldNotReachHere(); |
1533 } | 1745 } |
1534 | 1746 |
1535 | 1747 |
1536 #ifndef PRODUCT | 1748 #ifndef PRODUCT |
1537 void instanceKlass::print_dependent_nmethods(bool verbose) { | 1749 void InstanceKlass::print_dependent_nmethods(bool verbose) { |
1538 nmethodBucket* b = _dependencies; | 1750 nmethodBucket* b = _dependencies; |
1539 int idx = 0; | 1751 int idx = 0; |
1540 while (b != NULL) { | 1752 while (b != NULL) { |
1541 nmethod* nm = b->get_nmethod(); | 1753 nmethod* nm = b->get_nmethod(); |
1542 tty->print("[%d] count=%d { ", idx++, b->count()); | 1754 tty->print("[%d] count=%d { ", idx++, b->count()); |
1551 b = b->next(); | 1763 b = b->next(); |
1552 } | 1764 } |
1553 } | 1765 } |
1554 | 1766 |
1555 | 1767 |
1556 bool instanceKlass::is_dependent_nmethod(nmethod* nm) { | 1768 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) { |
1557 nmethodBucket* b = _dependencies; | 1769 nmethodBucket* b = _dependencies; |
1558 while (b != NULL) { | 1770 while (b != NULL) { |
1559 if (nm == b->get_nmethod()) { | 1771 if (nm == b->get_nmethod()) { |
1560 return true; | 1772 return true; |
1561 } | 1773 } |
1563 } | 1775 } |
1564 return false; | 1776 return false; |
1565 } | 1777 } |
1566 #endif //PRODUCT | 1778 #endif //PRODUCT |
1567 | 1779 |
1780 | |
1781 // Garbage collection | |
1782 | |
1783 void InstanceKlass::oops_do(OopClosure* cl) { | |
1784 Klass::oops_do(cl); | |
1785 | |
1786 cl->do_oop(adr_protection_domain()); | |
1787 cl->do_oop(adr_signers()); | |
1788 cl->do_oop(adr_init_lock()); | |
1789 | |
1790 // Don't walk the arrays since they are walked from the ClassLoaderData objects. | |
1791 } | |
1568 | 1792 |
1569 #ifdef ASSERT | 1793 #ifdef ASSERT |
1570 template <class T> void assert_is_in(T *p) { | 1794 template <class T> void assert_is_in(T *p) { |
1571 T heap_oop = oopDesc::load_heap_oop(p); | 1795 T heap_oop = oopDesc::load_heap_oop(p); |
1572 if (!oopDesc::is_null(heap_oop)) { | 1796 if (!oopDesc::is_null(heap_oop)) { |
1576 } | 1800 } |
1577 template <class T> void assert_is_in_closed_subset(T *p) { | 1801 template <class T> void assert_is_in_closed_subset(T *p) { |
1578 T heap_oop = oopDesc::load_heap_oop(p); | 1802 T heap_oop = oopDesc::load_heap_oop(p); |
1579 if (!oopDesc::is_null(heap_oop)) { | 1803 if (!oopDesc::is_null(heap_oop)) { |
1580 oop o = oopDesc::decode_heap_oop_not_null(heap_oop); | 1804 oop o = oopDesc::decode_heap_oop_not_null(heap_oop); |
1581 assert(Universe::heap()->is_in_closed_subset(o), "should be in closed"); | 1805 assert(Universe::heap()->is_in_closed_subset(o), |
1806 err_msg("should be in closed *p " INTPTR_FORMAT " " INTPTR_FORMAT, (address)p, (address)o)); | |
1582 } | 1807 } |
1583 } | 1808 } |
1584 template <class T> void assert_is_in_reserved(T *p) { | 1809 template <class T> void assert_is_in_reserved(T *p) { |
1585 T heap_oop = oopDesc::load_heap_oop(p); | 1810 T heap_oop = oopDesc::load_heap_oop(p); |
1586 if (!oopDesc::is_null(heap_oop)) { | 1811 if (!oopDesc::is_null(heap_oop)) { |
1730 ++map; \ | 1955 ++map; \ |
1731 } \ | 1956 } \ |
1732 } \ | 1957 } \ |
1733 } | 1958 } |
1734 | 1959 |
1735 void instanceKlass::oop_follow_contents(oop obj) { | 1960 void InstanceKlass::oop_follow_contents(oop obj) { |
1736 assert(obj != NULL, "can't follow the content of NULL object"); | 1961 assert(obj != NULL, "can't follow the content of NULL object"); |
1737 obj->follow_header(); | 1962 MarkSweep::follow_klass(obj->klass()); |
1738 InstanceKlass_OOP_MAP_ITERATE( \ | 1963 InstanceKlass_OOP_MAP_ITERATE( \ |
1739 obj, \ | 1964 obj, \ |
1740 MarkSweep::mark_and_push(p), \ | 1965 MarkSweep::mark_and_push(p), \ |
1741 assert_is_in_closed_subset) | 1966 assert_is_in_closed_subset) |
1742 } | 1967 } |
1743 | 1968 |
1744 #ifndef SERIALGC | 1969 #ifndef SERIALGC |
1745 void instanceKlass::oop_follow_contents(ParCompactionManager* cm, | 1970 void InstanceKlass::oop_follow_contents(ParCompactionManager* cm, |
1746 oop obj) { | 1971 oop obj) { |
1747 assert(obj != NULL, "can't follow the content of NULL object"); | 1972 assert(obj != NULL, "can't follow the content of NULL object"); |
1748 obj->follow_header(cm); | 1973 PSParallelCompact::follow_klass(cm, obj->klass()); |
1974 // Only mark the header and let the scan of the meta-data mark | |
1975 // everything else. | |
1749 InstanceKlass_OOP_MAP_ITERATE( \ | 1976 InstanceKlass_OOP_MAP_ITERATE( \ |
1750 obj, \ | 1977 obj, \ |
1751 PSParallelCompact::mark_and_push(cm, p), \ | 1978 PSParallelCompact::mark_and_push(cm, p), \ |
1752 assert_is_in) | 1979 assert_is_in) |
1753 } | 1980 } |
1754 #endif // SERIALGC | 1981 #endif // SERIALGC |
1755 | 1982 |
1756 // closure's do_header() method dicates whether the given closure should be | 1983 // closure's do_metadata() method dictates whether the given closure should be |
1757 // applied to the klass ptr in the object header. | 1984 // applied to the klass ptr in the object header. |
1985 | |
1986 #define if_do_metadata_checked(closure, nv_suffix) \ | |
1987 /* Make sure the non-virtual and the virtual versions match. */ \ | |
1988 assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \ | |
1989 "Inconsistency in do_metadata"); \ | |
1990 if (closure->do_metadata##nv_suffix()) | |
1758 | 1991 |
1759 #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ | 1992 #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
1760 \ | 1993 \ |
1761 int instanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ | 1994 int InstanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
1762 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ | 1995 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
1763 /* header */ \ | 1996 /* header */ \ |
1764 if (closure->do_header()) { \ | 1997 if_do_metadata_checked(closure, nv_suffix) { \ |
1765 obj->oop_iterate_header(closure); \ | 1998 closure->do_klass##nv_suffix(obj->klass()); \ |
1766 } \ | 1999 } \ |
1767 InstanceKlass_OOP_MAP_ITERATE( \ | 2000 InstanceKlass_OOP_MAP_ITERATE( \ |
1768 obj, \ | 2001 obj, \ |
1769 SpecializationStats:: \ | 2002 SpecializationStats:: \ |
1770 record_do_oop_call##nv_suffix(SpecializationStats::ik); \ | 2003 record_do_oop_call##nv_suffix(SpecializationStats::ik); \ |
1774 } | 2007 } |
1775 | 2008 |
1776 #ifndef SERIALGC | 2009 #ifndef SERIALGC |
1777 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ | 2010 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ |
1778 \ | 2011 \ |
1779 int instanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \ | 2012 int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \ |
1780 OopClosureType* closure) { \ | 2013 OopClosureType* closure) { \ |
1781 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \ | 2014 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \ |
1782 /* header */ \ | 2015 /* header */ \ |
1783 if (closure->do_header()) { \ | 2016 if_do_metadata_checked(closure, nv_suffix) { \ |
1784 obj->oop_iterate_header(closure); \ | 2017 closure->do_klass##nv_suffix(obj->klass()); \ |
1785 } \ | 2018 } \ |
1786 /* instance variables */ \ | 2019 /* instance variables */ \ |
1787 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ | 2020 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
1788 obj, \ | 2021 obj, \ |
1789 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\ | 2022 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\ |
1793 } | 2026 } |
1794 #endif // !SERIALGC | 2027 #endif // !SERIALGC |
1795 | 2028 |
1796 #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ | 2029 #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ |
1797 \ | 2030 \ |
1798 int instanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ | 2031 int InstanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ |
1799 OopClosureType* closure, \ | 2032 OopClosureType* closure, \ |
1800 MemRegion mr) { \ | 2033 MemRegion mr) { \ |
1801 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ | 2034 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
1802 if (closure->do_header()) { \ | 2035 if_do_metadata_checked(closure, nv_suffix) { \ |
1803 obj->oop_iterate_header(closure, mr); \ | 2036 if (mr.contains(obj)) { \ |
2037 closure->do_klass##nv_suffix(obj->klass()); \ | |
2038 } \ | |
1804 } \ | 2039 } \ |
1805 InstanceKlass_BOUNDED_OOP_MAP_ITERATE( \ | 2040 InstanceKlass_BOUNDED_OOP_MAP_ITERATE( \ |
1806 obj, mr.start(), mr.end(), \ | 2041 obj, mr.start(), mr.end(), \ |
1807 (closure)->do_oop##nv_suffix(p), \ | 2042 (closure)->do_oop##nv_suffix(p), \ |
1808 assert_is_in_closed_subset) \ | 2043 assert_is_in_closed_subset) \ |
1816 #ifndef SERIALGC | 2051 #ifndef SERIALGC |
1817 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) | 2052 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
1818 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) | 2053 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
1819 #endif // !SERIALGC | 2054 #endif // !SERIALGC |
1820 | 2055 |
1821 int instanceKlass::oop_adjust_pointers(oop obj) { | 2056 int InstanceKlass::oop_adjust_pointers(oop obj) { |
1822 int size = size_helper(); | 2057 int size = size_helper(); |
1823 InstanceKlass_OOP_MAP_ITERATE( \ | 2058 InstanceKlass_OOP_MAP_ITERATE( \ |
1824 obj, \ | 2059 obj, \ |
1825 MarkSweep::adjust_pointer(p), \ | 2060 MarkSweep::adjust_pointer(p), \ |
1826 assert_is_in) | 2061 assert_is_in) |
1827 obj->adjust_header(); | 2062 MarkSweep::adjust_klass(obj->klass()); |
1828 return size; | 2063 return size; |
1829 } | 2064 } |
1830 | 2065 |
1831 #ifndef SERIALGC | 2066 #ifndef SERIALGC |
1832 void instanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { | 2067 void InstanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
1833 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ | 2068 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
1834 obj, \ | 2069 obj, \ |
1835 if (PSScavenge::should_scavenge(p)) { \ | 2070 if (PSScavenge::should_scavenge(p)) { \ |
1836 pm->claim_or_forward_depth(p); \ | 2071 pm->claim_or_forward_depth(p); \ |
1837 }, \ | 2072 }, \ |
1838 assert_nothing ) | 2073 assert_nothing ) |
1839 } | 2074 } |
1840 | 2075 |
1841 int instanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { | 2076 int InstanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
2077 int size = size_helper(); | |
1842 InstanceKlass_OOP_MAP_ITERATE( \ | 2078 InstanceKlass_OOP_MAP_ITERATE( \ |
1843 obj, \ | 2079 obj, \ |
1844 PSParallelCompact::adjust_pointer(p), \ | 2080 PSParallelCompact::adjust_pointer(p), \ |
1845 assert_nothing) | 2081 assert_is_in) |
1846 return size_helper(); | 2082 obj->update_header(cm); |
2083 return size; | |
1847 } | 2084 } |
1848 | 2085 |
1849 #endif // SERIALGC | 2086 #endif // SERIALGC |
1850 | 2087 |
1851 // This klass is alive but the implementor link is not followed/updated. | 2088 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) { |
1852 // Subklass and sibling links are handled by Klass::follow_weak_klass_links | 2089 assert(is_loader_alive(is_alive), "this klass should be live"); |
1853 | |
1854 void instanceKlass::follow_weak_klass_links( | |
1855 BoolObjectClosure* is_alive, OopClosure* keep_alive) { | |
1856 assert(is_alive->do_object_b(as_klassOop()), "this oop should be live"); | |
1857 | |
1858 if (is_interface()) { | 2090 if (is_interface()) { |
1859 if (ClassUnloading) { | 2091 if (ClassUnloading) { |
1860 klassOop impl = implementor(); | 2092 Klass* impl = implementor(); |
1861 if (impl != NULL) { | 2093 if (impl != NULL) { |
1862 if (!is_alive->do_object_b(impl)) { | 2094 if (!impl->is_loader_alive(is_alive)) { |
1863 // remove this guy | 2095 // remove this guy |
1864 *adr_implementor() = NULL; | 2096 *adr_implementor() = NULL; |
1865 } | 2097 } |
1866 } | 2098 } |
1867 } else { | 2099 } |
1868 assert(adr_implementor() != NULL, "just checking"); | 2100 } |
1869 keep_alive->do_oop(adr_implementor()); | 2101 } |
1870 } | 2102 |
1871 } | 2103 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) { |
1872 | 2104 #ifdef COMPILER2 |
1873 Klass::follow_weak_klass_links(is_alive, keep_alive); | 2105 // Currently only used by C2. |
1874 } | 2106 for (int m = 0; m < methods()->length(); m++) { |
1875 | 2107 MethodData* mdo = methods()->at(m)->method_data(); |
1876 void instanceKlass::remove_unshareable_info() { | 2108 if (mdo != NULL) { |
2109 for (ProfileData* data = mdo->first_data(); | |
2110 mdo->is_valid(data); | |
2111 data = mdo->next_data(data)) { | |
2112 data->clean_weak_klass_links(is_alive); | |
2113 } | |
2114 } | |
2115 } | |
2116 #else | |
2117 #ifdef ASSERT | |
2118 // Verify that we haven't started to use MDOs for C1. | |
2119 for (int m = 0; m < methods()->length(); m++) { | |
2120 MethodData* mdo = methods()->at(m)->method_data(); | |
2121 assert(mdo == NULL, "Didn't expect C1 to use MDOs"); | |
2122 } | |
2123 #endif // ASSERT | |
2124 #endif // !COMPILER2 | |
2125 } | |
2126 | |
2127 | |
2128 static void remove_unshareable_in_class(Klass* k) { | |
2129 // remove klass's unshareable info | |
2130 k->remove_unshareable_info(); | |
2131 } | |
2132 | |
2133 void InstanceKlass::remove_unshareable_info() { | |
1877 Klass::remove_unshareable_info(); | 2134 Klass::remove_unshareable_info(); |
2135 // Unlink the class | |
2136 if (is_linked()) { | |
2137 unlink_class(); | |
2138 } | |
1878 init_implementor(); | 2139 init_implementor(); |
1879 } | 2140 |
1880 | 2141 constants()->remove_unshareable_info(); |
1881 static void clear_all_breakpoints(methodOop m) { | 2142 |
2143 for (int i = 0; i < methods()->length(); i++) { | |
2144 Method* m = methods()->at(i); | |
2145 m->remove_unshareable_info(); | |
2146 } | |
2147 | |
2148 // Need to reinstate when reading back the class. | |
2149 set_init_lock(NULL); | |
2150 | |
2151 // do array classes also. | |
2152 array_klasses_do(remove_unshareable_in_class); | |
2153 } | |
2154 | |
2155 void restore_unshareable_in_class(Klass* k, TRAPS) { | |
2156 k->restore_unshareable_info(CHECK); | |
2157 } | |
2158 | |
2159 void InstanceKlass::restore_unshareable_info(TRAPS) { | |
2160 Klass::restore_unshareable_info(CHECK); | |
2161 instanceKlassHandle ik(THREAD, this); | |
2162 | |
2163 Array<Method*>* methods = ik->methods(); | |
2164 int num_methods = methods->length(); | |
2165 for (int index2 = 0; index2 < num_methods; ++index2) { | |
2166 methodHandle m(THREAD, methods->at(index2)); | |
2167 m()->link_method(m, CHECK); | |
2168 } | |
2169 if (JvmtiExport::has_redefined_a_class()) { | |
2170 // Reinitialize vtable because RedefineClasses may have changed some | |
2171 // entries in this vtable for super classes so the CDS vtable might | |
2172 // point to old or obsolete entries. RedefineClasses doesn't fix up | |
2173 // vtables in the shared system dictionary, only the main one. | |
2174 // It also redefines the itable too so fix that too. | |
2175 ResourceMark rm(THREAD); | |
2176 ik->vtable()->initialize_vtable(false, CHECK); | |
2177 ik->itable()->initialize_itable(false, CHECK); | |
2178 } | |
2179 | |
2180 // Allocate a simple java object for a lock. | |
2181 // This needs to be a java object because during class initialization | |
2182 // it can be held across a java call. | |
2183 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); | |
2184 Handle h(THREAD, (oop)r); | |
2185 ik->set_init_lock(h()); | |
2186 | |
2187 // restore constant pool resolved references | |
2188 ik->constants()->restore_unshareable_info(CHECK); | |
2189 | |
2190 ik->array_klasses_do(restore_unshareable_in_class, CHECK); | |
2191 } | |
2192 | |
2193 static void clear_all_breakpoints(Method* m) { | |
1882 m->clear_all_breakpoints(); | 2194 m->clear_all_breakpoints(); |
1883 } | 2195 } |
1884 | 2196 |
1885 void instanceKlass::release_C_heap_structures() { | 2197 void InstanceKlass::release_C_heap_structures() { |
1886 // Deallocate oop map cache | 2198 // Deallocate oop map cache |
1887 if (_oop_map_cache != NULL) { | 2199 if (_oop_map_cache != NULL) { |
1888 delete _oop_map_cache; | 2200 delete _oop_map_cache; |
1889 _oop_map_cache = NULL; | 2201 _oop_map_cache = NULL; |
1890 } | 2202 } |
1941 if (_name != NULL) _name->decrement_refcount(); | 2253 if (_name != NULL) _name->decrement_refcount(); |
1942 // unreference array name derived from this class name (arrays of an unloaded | 2254 // unreference array name derived from this class name (arrays of an unloaded |
1943 // class can't be referenced anymore). | 2255 // class can't be referenced anymore). |
1944 if (_array_name != NULL) _array_name->decrement_refcount(); | 2256 if (_array_name != NULL) _array_name->decrement_refcount(); |
1945 if (_source_file_name != NULL) _source_file_name->decrement_refcount(); | 2257 if (_source_file_name != NULL) _source_file_name->decrement_refcount(); |
1946 // walk constant pool and decrement symbol reference counts | |
1947 _constants->unreference_symbols(); | |
1948 | |
1949 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension, mtClass); | 2258 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension, mtClass); |
1950 } | 2259 } |
1951 | 2260 |
1952 void instanceKlass::set_source_file_name(Symbol* n) { | 2261 void InstanceKlass::set_source_file_name(Symbol* n) { |
1953 _source_file_name = n; | 2262 _source_file_name = n; |
1954 if (_source_file_name != NULL) _source_file_name->increment_refcount(); | 2263 if (_source_file_name != NULL) _source_file_name->increment_refcount(); |
1955 } | 2264 } |
1956 | 2265 |
1957 void instanceKlass::set_source_debug_extension(char* array, int length) { | 2266 void InstanceKlass::set_source_debug_extension(char* array, int length) { |
1958 if (array == NULL) { | 2267 if (array == NULL) { |
1959 _source_debug_extension = NULL; | 2268 _source_debug_extension = NULL; |
1960 } else { | 2269 } else { |
1961 // Adding one to the attribute length in order to store a null terminator | 2270 // Adding one to the attribute length in order to store a null terminator |
1962 // character could cause an overflow because the attribute length is | 2271 // character could cause an overflow because the attribute length is |
1970 sde[length] = '\0'; | 2279 sde[length] = '\0'; |
1971 _source_debug_extension = sde; | 2280 _source_debug_extension = sde; |
1972 } | 2281 } |
1973 } | 2282 } |
1974 | 2283 |
1975 address instanceKlass::static_field_addr(int offset) { | 2284 address InstanceKlass::static_field_addr(int offset) { |
1976 return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror()); | 2285 return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror()); |
1977 } | 2286 } |
1978 | 2287 |
1979 | 2288 |
1980 const char* instanceKlass::signature_name() const { | 2289 const char* InstanceKlass::signature_name() const { |
1981 const char* src = (const char*) (name()->as_C_string()); | 2290 const char* src = (const char*) (name()->as_C_string()); |
1982 const int src_length = (int)strlen(src); | 2291 const int src_length = (int)strlen(src); |
1983 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3); | 2292 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3); |
1984 int src_index = 0; | 2293 int src_index = 0; |
1985 int dest_index = 0; | 2294 int dest_index = 0; |
1991 dest[dest_index] = '\0'; | 2300 dest[dest_index] = '\0'; |
1992 return dest; | 2301 return dest; |
1993 } | 2302 } |
1994 | 2303 |
1995 // different verisons of is_same_class_package | 2304 // different verisons of is_same_class_package |
1996 bool instanceKlass::is_same_class_package(klassOop class2) { | 2305 bool InstanceKlass::is_same_class_package(Klass* class2) { |
1997 klassOop class1 = as_klassOop(); | 2306 Klass* class1 = this; |
1998 oop classloader1 = instanceKlass::cast(class1)->class_loader(); | 2307 oop classloader1 = InstanceKlass::cast(class1)->class_loader(); |
1999 Symbol* classname1 = Klass::cast(class1)->name(); | 2308 Symbol* classname1 = Klass::cast(class1)->name(); |
2000 | 2309 |
2001 if (Klass::cast(class2)->oop_is_objArray()) { | 2310 if (Klass::cast(class2)->oop_is_objArray()) { |
2002 class2 = objArrayKlass::cast(class2)->bottom_klass(); | 2311 class2 = objArrayKlass::cast(class2)->bottom_klass(); |
2003 } | 2312 } |
2004 oop classloader2; | 2313 oop classloader2; |
2005 if (Klass::cast(class2)->oop_is_instance()) { | 2314 if (Klass::cast(class2)->oop_is_instance()) { |
2006 classloader2 = instanceKlass::cast(class2)->class_loader(); | 2315 classloader2 = InstanceKlass::cast(class2)->class_loader(); |
2007 } else { | 2316 } else { |
2008 assert(Klass::cast(class2)->oop_is_typeArray(), "should be type array"); | 2317 assert(Klass::cast(class2)->oop_is_typeArray(), "should be type array"); |
2009 classloader2 = NULL; | 2318 classloader2 = NULL; |
2010 } | 2319 } |
2011 Symbol* classname2 = Klass::cast(class2)->name(); | 2320 Symbol* classname2 = Klass::cast(class2)->name(); |
2012 | 2321 |
2013 return instanceKlass::is_same_class_package(classloader1, classname1, | 2322 return InstanceKlass::is_same_class_package(classloader1, classname1, |
2014 classloader2, classname2); | 2323 classloader2, classname2); |
2015 } | 2324 } |
2016 | 2325 |
2017 bool instanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) { | 2326 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) { |
2018 klassOop class1 = as_klassOop(); | 2327 Klass* class1 = this; |
2019 oop classloader1 = instanceKlass::cast(class1)->class_loader(); | 2328 oop classloader1 = InstanceKlass::cast(class1)->class_loader(); |
2020 Symbol* classname1 = Klass::cast(class1)->name(); | 2329 Symbol* classname1 = Klass::cast(class1)->name(); |
2021 | 2330 |
2022 return instanceKlass::is_same_class_package(classloader1, classname1, | 2331 return InstanceKlass::is_same_class_package(classloader1, classname1, |
2023 classloader2, classname2); | 2332 classloader2, classname2); |
2024 } | 2333 } |
2025 | 2334 |
2026 // return true if two classes are in the same package, classloader | 2335 // return true if two classes are in the same package, classloader |
2027 // and classname information is enough to determine a class's package | 2336 // and classname information is enough to determine a class's package |
2028 bool instanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1, | 2337 bool InstanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1, |
2029 oop class_loader2, Symbol* class_name2) { | 2338 oop class_loader2, Symbol* class_name2) { |
2030 if (class_loader1 != class_loader2) { | 2339 if (class_loader1 != class_loader2) { |
2031 return false; | 2340 return false; |
2032 } else if (class_name1 == class_name2) { | 2341 } else if (class_name1 == class_name2) { |
2033 return true; // skip painful bytewise comparison | 2342 return true; // skip painful bytewise comparison |
2078 } | 2387 } |
2079 | 2388 |
2080 // Returns true iff super_method can be overridden by a method in targetclassname | 2389 // Returns true iff super_method can be overridden by a method in targetclassname |
2081 // See JSL 3rd edition 8.4.6.1 | 2390 // See JSL 3rd edition 8.4.6.1 |
2082 // Assumes name-signature match | 2391 // Assumes name-signature match |
2083 // "this" is instanceKlass of super_method which must exist | 2392 // "this" is InstanceKlass of super_method which must exist |
2084 // note that the instanceKlass of the method in the targetclassname has not always been created yet | 2393 // note that the InstanceKlass of the method in the targetclassname has not always been created yet |
2085 bool instanceKlass::is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { | 2394 bool InstanceKlass::is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { |
2086 // Private methods can not be overridden | 2395 // Private methods can not be overridden |
2087 if (super_method->is_private()) { | 2396 if (super_method->is_private()) { |
2088 return false; | 2397 return false; |
2089 } | 2398 } |
2090 // If super method is accessible, then override | 2399 // If super method is accessible, then override |
2096 assert(super_method->is_package_private(), "must be package private"); | 2405 assert(super_method->is_package_private(), "must be package private"); |
2097 return(is_same_class_package(targetclassloader(), targetclassname)); | 2406 return(is_same_class_package(targetclassloader(), targetclassname)); |
2098 } | 2407 } |
2099 | 2408 |
2100 /* defined for now in jvm.cpp, for historical reasons *-- | 2409 /* defined for now in jvm.cpp, for historical reasons *-- |
2101 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle self, | 2410 Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle self, |
2102 Symbol*& simple_name_result, TRAPS) { | 2411 Symbol*& simple_name_result, TRAPS) { |
2103 ... | 2412 ... |
2104 } | 2413 } |
2105 */ | 2414 */ |
2106 | 2415 |
2107 // tell if two classes have the same enclosing class (at package level) | 2416 // tell if two classes have the same enclosing class (at package level) |
2108 bool instanceKlass::is_same_package_member_impl(instanceKlassHandle class1, | 2417 bool InstanceKlass::is_same_package_member_impl(instanceKlassHandle class1, |
2109 klassOop class2_oop, TRAPS) { | 2418 Klass* class2_oop, TRAPS) { |
2110 if (class2_oop == class1->as_klassOop()) return true; | 2419 if (class2_oop == class1()) return true; |
2111 if (!Klass::cast(class2_oop)->oop_is_instance()) return false; | 2420 if (!Klass::cast(class2_oop)->oop_is_instance()) return false; |
2112 instanceKlassHandle class2(THREAD, class2_oop); | 2421 instanceKlassHandle class2(THREAD, class2_oop); |
2113 | 2422 |
2114 // must be in same package before we try anything else | 2423 // must be in same package before we try anything else |
2115 if (!class1->is_same_class_package(class2->class_loader(), class2->name())) | 2424 if (!class1->is_same_class_package(class2->class_loader(), class2->name())) |
2121 for (;;) { | 2430 for (;;) { |
2122 // As we walk along, look for equalities between outer1 and class2. | 2431 // As we walk along, look for equalities between outer1 and class2. |
2123 // Eventually, the walks will terminate as outer1 stops | 2432 // Eventually, the walks will terminate as outer1 stops |
2124 // at the top-level class around the original class. | 2433 // at the top-level class around the original class. |
2125 bool ignore_inner_is_member; | 2434 bool ignore_inner_is_member; |
2126 klassOop next = outer1->compute_enclosing_class(&ignore_inner_is_member, | 2435 Klass* next = outer1->compute_enclosing_class(&ignore_inner_is_member, |
2127 CHECK_false); | 2436 CHECK_false); |
2128 if (next == NULL) break; | 2437 if (next == NULL) break; |
2129 if (next == class2()) return true; | 2438 if (next == class2()) return true; |
2130 outer1 = instanceKlassHandle(THREAD, next); | 2439 outer1 = instanceKlassHandle(THREAD, next); |
2131 } | 2440 } |
2132 | 2441 |
2133 // Now do the same for class2. | 2442 // Now do the same for class2. |
2134 instanceKlassHandle outer2 = class2; | 2443 instanceKlassHandle outer2 = class2; |
2135 for (;;) { | 2444 for (;;) { |
2136 bool ignore_inner_is_member; | 2445 bool ignore_inner_is_member; |
2137 klassOop next = outer2->compute_enclosing_class(&ignore_inner_is_member, | 2446 Klass* next = outer2->compute_enclosing_class(&ignore_inner_is_member, |
2138 CHECK_false); | 2447 CHECK_false); |
2139 if (next == NULL) break; | 2448 if (next == NULL) break; |
2140 // Might as well check the new outer against all available values. | 2449 // Might as well check the new outer against all available values. |
2141 if (next == class1()) return true; | 2450 if (next == class1()) return true; |
2142 if (next == outer1()) return true; | 2451 if (next == outer1()) return true; |
2147 // two classes, we know they are in separate package members. | 2456 // two classes, we know they are in separate package members. |
2148 return false; | 2457 return false; |
2149 } | 2458 } |
2150 | 2459 |
2151 | 2460 |
2152 jint instanceKlass::compute_modifier_flags(TRAPS) const { | 2461 jint InstanceKlass::compute_modifier_flags(TRAPS) const { |
2153 klassOop k = as_klassOop(); | |
2154 jint access = access_flags().as_int(); | 2462 jint access = access_flags().as_int(); |
2155 | 2463 |
2156 // But check if it happens to be member class. | 2464 // But check if it happens to be member class. |
2157 instanceKlassHandle ik(THREAD, k); | 2465 instanceKlassHandle ik(THREAD, this); |
2158 InnerClassesIterator iter(ik); | 2466 InnerClassesIterator iter(ik); |
2159 for (; !iter.done(); iter.next()) { | 2467 for (; !iter.done(); iter.next()) { |
2160 int ioff = iter.inner_class_info_index(); | 2468 int ioff = iter.inner_class_info_index(); |
2161 // Inner class attribute can be zero, skip it. | 2469 // Inner class attribute can be zero, skip it. |
2162 // Strange but true: JVM spec. allows null inner class refs. | 2470 // Strange but true: JVM spec. allows null inner class refs. |
2173 } | 2481 } |
2174 // Remember to strip ACC_SUPER bit | 2482 // Remember to strip ACC_SUPER bit |
2175 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS; | 2483 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS; |
2176 } | 2484 } |
2177 | 2485 |
2178 jint instanceKlass::jvmti_class_status() const { | 2486 jint InstanceKlass::jvmti_class_status() const { |
2179 jint result = 0; | 2487 jint result = 0; |
2180 | 2488 |
2181 if (is_linked()) { | 2489 if (is_linked()) { |
2182 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED; | 2490 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED; |
2183 } | 2491 } |
2190 result |= JVMTI_CLASS_STATUS_ERROR; | 2498 result |= JVMTI_CLASS_STATUS_ERROR; |
2191 } | 2499 } |
2192 return result; | 2500 return result; |
2193 } | 2501 } |
2194 | 2502 |
2195 methodOop instanceKlass::method_at_itable(klassOop holder, int index, TRAPS) { | 2503 Method* InstanceKlass::method_at_itable(Klass* holder, int index, TRAPS) { |
2196 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); | 2504 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); |
2197 int method_table_offset_in_words = ioe->offset()/wordSize; | 2505 int method_table_offset_in_words = ioe->offset()/wordSize; |
2198 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) | 2506 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) |
2199 / itableOffsetEntry::size(); | 2507 / itableOffsetEntry::size(); |
2200 | 2508 |
2201 for (int cnt = 0 ; ; cnt ++, ioe ++) { | 2509 for (int cnt = 0 ; ; cnt ++, ioe ++) { |
2202 // If the interface isn't implemented by the receiver class, | 2510 // If the interface isn't implemented by the receiver class, |
2203 // the VM should throw IncompatibleClassChangeError. | 2511 // the VM should throw IncompatibleClassChangeError. |
2204 if (cnt >= nof_interfaces) { | 2512 if (cnt >= nof_interfaces) { |
2205 THROW_0(vmSymbols::java_lang_IncompatibleClassChangeError()); | 2513 THROW_NULL(vmSymbols::java_lang_IncompatibleClassChangeError()); |
2206 } | 2514 } |
2207 | 2515 |
2208 klassOop ik = ioe->interface_klass(); | 2516 Klass* ik = ioe->interface_klass(); |
2209 if (ik == holder) break; | 2517 if (ik == holder) break; |
2210 } | 2518 } |
2211 | 2519 |
2212 itableMethodEntry* ime = ioe->first_method_entry(as_klassOop()); | 2520 itableMethodEntry* ime = ioe->first_method_entry(this); |
2213 methodOop m = ime[index].method(); | 2521 Method* m = ime[index].method(); |
2214 if (m == NULL) { | 2522 if (m == NULL) { |
2215 THROW_0(vmSymbols::java_lang_AbstractMethodError()); | 2523 THROW_NULL(vmSymbols::java_lang_AbstractMethodError()); |
2216 } | 2524 } |
2217 return m; | 2525 return m; |
2218 } | 2526 } |
2219 | 2527 |
2220 // On-stack replacement stuff | 2528 // On-stack replacement stuff |
2221 void instanceKlass::add_osr_nmethod(nmethod* n) { | 2529 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2222 // only one compilation can be active | 2530 // only one compilation can be active |
2223 NEEDS_CLEANUP | 2531 NEEDS_CLEANUP |
2224 // This is a short non-blocking critical region, so the no safepoint check is ok. | 2532 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2225 OsrList_lock->lock_without_safepoint_check(); | 2533 OsrList_lock->lock_without_safepoint_check(); |
2226 assert(n->is_osr_method(), "wrong kind of nmethod"); | 2534 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2227 n->set_osr_link(osr_nmethods_head()); | 2535 n->set_osr_link(osr_nmethods_head()); |
2228 set_osr_nmethods_head(n); | 2536 set_osr_nmethods_head(n); |
2229 // Raise the highest osr level if necessary | 2537 // Raise the highest osr level if necessary |
2230 if (TieredCompilation) { | 2538 if (TieredCompilation) { |
2231 methodOop m = n->method(); | 2539 Method* m = n->method(); |
2232 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); | 2540 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
2233 } | 2541 } |
2234 // Remember to unlock again | 2542 // Remember to unlock again |
2235 OsrList_lock->unlock(); | 2543 OsrList_lock->unlock(); |
2236 | 2544 |
2244 } | 2552 } |
2245 } | 2553 } |
2246 } | 2554 } |
2247 | 2555 |
2248 | 2556 |
2249 void instanceKlass::remove_osr_nmethod(nmethod* n) { | 2557 void InstanceKlass::remove_osr_nmethod(nmethod* n) { |
2250 // This is a short non-blocking critical region, so the no safepoint check is ok. | 2558 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2251 OsrList_lock->lock_without_safepoint_check(); | 2559 OsrList_lock->lock_without_safepoint_check(); |
2252 assert(n->is_osr_method(), "wrong kind of nmethod"); | 2560 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2253 nmethod* last = NULL; | 2561 nmethod* last = NULL; |
2254 nmethod* cur = osr_nmethods_head(); | 2562 nmethod* cur = osr_nmethods_head(); |
2255 int max_level = CompLevel_none; // Find the max comp level excluding n | 2563 int max_level = CompLevel_none; // Find the max comp level excluding n |
2256 methodOop m = n->method(); | 2564 Method* m = n->method(); |
2257 // Search for match | 2565 // Search for match |
2258 while(cur != NULL && cur != n) { | 2566 while(cur != NULL && cur != n) { |
2259 if (TieredCompilation) { | 2567 if (TieredCompilation) { |
2260 // Find max level before n | 2568 // Find max level before n |
2261 max_level = MAX2(max_level, cur->comp_level()); | 2569 max_level = MAX2(max_level, cur->comp_level()); |
2285 } | 2593 } |
2286 // Remember to unlock again | 2594 // Remember to unlock again |
2287 OsrList_lock->unlock(); | 2595 OsrList_lock->unlock(); |
2288 } | 2596 } |
2289 | 2597 |
2290 nmethod* instanceKlass::lookup_osr_nmethod(const methodOop m, int bci, int comp_level, bool match_level) const { | 2598 nmethod* InstanceKlass::lookup_osr_nmethod(Method* const m, int bci, int comp_level, bool match_level) const { |
2291 // This is a short non-blocking critical region, so the no safepoint check is ok. | 2599 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2292 OsrList_lock->lock_without_safepoint_check(); | 2600 OsrList_lock->lock_without_safepoint_check(); |
2293 nmethod* osr = osr_nmethods_head(); | 2601 nmethod* osr = osr_nmethods_head(); |
2294 nmethod* best = NULL; | 2602 nmethod* best = NULL; |
2295 while (osr != NULL) { | 2603 while (osr != NULL) { |
2327 } | 2635 } |
2328 return NULL; | 2636 return NULL; |
2329 } | 2637 } |
2330 | 2638 |
2331 // ----------------------------------------------------------------------------------------------------- | 2639 // ----------------------------------------------------------------------------------------------------- |
2640 // Printing | |
2641 | |
2332 #ifndef PRODUCT | 2642 #ifndef PRODUCT |
2333 | 2643 |
2334 // Printing | |
2335 | |
2336 #define BULLET " - " | 2644 #define BULLET " - " |
2645 | |
2646 static const char* state_names[] = { | |
2647 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" | |
2648 }; | |
2649 | |
2650 void InstanceKlass::print_on(outputStream* st) const { | |
2651 assert(is_klass(), "must be klass"); | |
2652 Klass::print_on(st); | |
2653 | |
2654 st->print(BULLET"instance size: %d", size_helper()); st->cr(); | |
2655 st->print(BULLET"klass size: %d", size()); st->cr(); | |
2656 st->print(BULLET"access: "); access_flags().print_on(st); st->cr(); | |
2657 st->print(BULLET"state: "); st->print_cr(state_names[_init_state]); | |
2658 st->print(BULLET"name: "); name()->print_value_on(st); st->cr(); | |
2659 st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr(); | |
2660 st->print(BULLET"sub: "); | |
2661 Klass* sub = subklass(); | |
2662 int n; | |
2663 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) { | |
2664 if (n < MaxSubklassPrintSize) { | |
2665 sub->print_value_on(st); | |
2666 st->print(" "); | |
2667 } | |
2668 } | |
2669 if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize); | |
2670 st->cr(); | |
2671 | |
2672 if (is_interface()) { | |
2673 st->print_cr(BULLET"nof implementors: %d", nof_implementors()); | |
2674 if (nof_implementors() == 1) { | |
2675 st->print_cr(BULLET"implementor: "); | |
2676 st->print(" "); | |
2677 implementor()->print_value_on(st); | |
2678 st->cr(); | |
2679 } | |
2680 } | |
2681 | |
2682 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); | |
2683 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); | |
2684 if (Verbose) { | |
2685 Array<Method*>* method_array = methods(); | |
2686 for(int i = 0; i < method_array->length(); i++) { | |
2687 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); | |
2688 } | |
2689 } | |
2690 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr(); | |
2691 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); | |
2692 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); | |
2693 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr(); | |
2694 if (class_loader_data() != NULL) { | |
2695 st->print(BULLET"class loader data: "); | |
2696 class_loader_data()->print_value_on(st); | |
2697 st->cr(); | |
2698 } | |
2699 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); | |
2700 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); | |
2701 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); | |
2702 st->print(BULLET"init_lock: "); ((oop)init_lock())->print_value_on(st); st->cr(); | |
2703 if (source_file_name() != NULL) { | |
2704 st->print(BULLET"source file: "); | |
2705 source_file_name()->print_value_on(st); | |
2706 st->cr(); | |
2707 } | |
2708 if (source_debug_extension() != NULL) { | |
2709 st->print(BULLET"source debug extension: "); | |
2710 st->print("%s", source_debug_extension()); | |
2711 st->cr(); | |
2712 } | |
2713 st->print(BULLET"annotations: "); annotations()->print_value_on(st); st->cr(); | |
2714 { | |
2715 ResourceMark rm; | |
2716 // PreviousVersionInfo objects returned via PreviousVersionWalker | |
2717 // contain a GrowableArray of handles. We have to clean up the | |
2718 // GrowableArray _after_ the PreviousVersionWalker destructor | |
2719 // has destroyed the handles. | |
2720 { | |
2721 bool have_pv = false; | |
2722 PreviousVersionWalker pvw((InstanceKlass*)this); | |
2723 for (PreviousVersionInfo * pv_info = pvw.next_previous_version(); | |
2724 pv_info != NULL; pv_info = pvw.next_previous_version()) { | |
2725 if (!have_pv) | |
2726 st->print(BULLET"previous version: "); | |
2727 have_pv = true; | |
2728 pv_info->prev_constant_pool_handle()()->print_value_on(st); | |
2729 } | |
2730 if (have_pv) st->cr(); | |
2731 } // pvw is cleaned up | |
2732 } // rm is cleaned up | |
2733 | |
2734 if (generic_signature() != NULL) { | |
2735 st->print(BULLET"generic signature: "); | |
2736 generic_signature()->print_value_on(st); | |
2737 st->cr(); | |
2738 } | |
2739 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr(); | |
2740 st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr(); | |
2741 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable()); st->cr(); | |
2742 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr(); | |
2743 st->print_cr(BULLET"---- static fields (%d words):", static_field_size()); | |
2744 FieldPrinter print_static_field(st); | |
2745 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field); | |
2746 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size()); | |
2747 FieldPrinter print_nonstatic_field(st); | |
2748 ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field); | |
2749 | |
2750 st->print(BULLET"non-static oop maps: "); | |
2751 OopMapBlock* map = start_of_nonstatic_oop_maps(); | |
2752 OopMapBlock* end_map = map + nonstatic_oop_map_count(); | |
2753 while (map < end_map) { | |
2754 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1)); | |
2755 map++; | |
2756 } | |
2757 st->cr(); | |
2758 } | |
2759 | |
2760 #endif //PRODUCT | |
2761 | |
2762 void InstanceKlass::print_value_on(outputStream* st) const { | |
2763 assert(is_klass(), "must be klass"); | |
2764 name()->print_value_on(st); | |
2765 } | |
2766 | |
2767 #ifndef PRODUCT | |
2337 | 2768 |
2338 void FieldPrinter::do_field(fieldDescriptor* fd) { | 2769 void FieldPrinter::do_field(fieldDescriptor* fd) { |
2339 _st->print(BULLET); | 2770 _st->print(BULLET); |
2340 if (_obj == NULL) { | 2771 if (_obj == NULL) { |
2341 fd->print_on(_st); | 2772 fd->print_on(_st); |
2345 _st->cr(); | 2776 _st->cr(); |
2346 } | 2777 } |
2347 } | 2778 } |
2348 | 2779 |
2349 | 2780 |
2350 void instanceKlass::oop_print_on(oop obj, outputStream* st) { | 2781 void InstanceKlass::oop_print_on(oop obj, outputStream* st) { |
2351 Klass::oop_print_on(obj, st); | 2782 Klass::oop_print_on(obj, st); |
2352 | 2783 |
2353 if (as_klassOop() == SystemDictionary::String_klass()) { | 2784 if (this == SystemDictionary::String_klass()) { |
2354 typeArrayOop value = java_lang_String::value(obj); | 2785 typeArrayOop value = java_lang_String::value(obj); |
2355 juint offset = java_lang_String::offset(obj); | 2786 juint offset = java_lang_String::offset(obj); |
2356 juint length = java_lang_String::length(obj); | 2787 juint length = java_lang_String::length(obj); |
2357 if (value != NULL && | 2788 if (value != NULL && |
2358 value->is_typeArray() && | 2789 value->is_typeArray() && |
2368 | 2799 |
2369 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); | 2800 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); |
2370 FieldPrinter print_field(st, obj); | 2801 FieldPrinter print_field(st, obj); |
2371 do_nonstatic_fields(&print_field); | 2802 do_nonstatic_fields(&print_field); |
2372 | 2803 |
2373 if (as_klassOop() == SystemDictionary::Class_klass()) { | 2804 if (this == SystemDictionary::Class_klass()) { |
2374 st->print(BULLET"signature: "); | 2805 st->print(BULLET"signature: "); |
2375 java_lang_Class::print_signature(obj, st); | 2806 java_lang_Class::print_signature(obj, st); |
2376 st->cr(); | 2807 st->cr(); |
2377 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); | 2808 Klass* mirrored_klass = java_lang_Class::as_Klass(obj); |
2378 st->print(BULLET"fake entry for mirror: "); | 2809 st->print(BULLET"fake entry for mirror: "); |
2379 mirrored_klass->print_value_on(st); | 2810 mirrored_klass->print_value_on_maybe_null(st); |
2380 st->cr(); | 2811 st->cr(); |
2381 st->print(BULLET"fake entry resolved_constructor: "); | 2812 st->print(BULLET"fake entry resolved_constructor: "); |
2382 methodOop ctor = java_lang_Class::resolved_constructor(obj); | 2813 Method* ctor = java_lang_Class::resolved_constructor(obj); |
2383 ctor->print_value_on(st); | 2814 ctor->print_value_on_maybe_null(st); |
2384 klassOop array_klass = java_lang_Class::array_klass(obj); | 2815 Klass* array_klass = java_lang_Class::array_klass(obj); |
2385 st->cr(); | 2816 st->cr(); |
2386 st->print(BULLET"fake entry for array: "); | 2817 st->print(BULLET"fake entry for array: "); |
2387 array_klass->print_value_on(st); | 2818 array_klass->print_value_on_maybe_null(st); |
2388 st->cr(); | 2819 st->cr(); |
2389 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); | 2820 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); |
2390 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); | 2821 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); |
2391 klassOop real_klass = java_lang_Class::as_klassOop(obj); | 2822 Klass* real_klass = java_lang_Class::as_Klass(obj); |
2392 if (real_klass != NULL && real_klass->klass_part()->oop_is_instance()) { | 2823 if (real_klass != NULL && real_klass->oop_is_instance()) { |
2393 instanceKlass::cast(real_klass)->do_local_static_fields(&print_field); | 2824 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field); |
2394 } | 2825 } |
2395 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { | 2826 } else if (this == SystemDictionary::MethodType_klass()) { |
2396 st->print(BULLET"signature: "); | 2827 st->print(BULLET"signature: "); |
2397 java_lang_invoke_MethodType::print_signature(obj, st); | 2828 java_lang_invoke_MethodType::print_signature(obj, st); |
2398 st->cr(); | 2829 st->cr(); |
2399 } | 2830 } |
2400 } | 2831 } |
2401 | 2832 |
2402 #endif //PRODUCT | 2833 #endif //PRODUCT |
2403 | 2834 |
2404 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { | 2835 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
2405 st->print("a "); | 2836 st->print("a "); |
2406 name()->print_value_on(st); | 2837 name()->print_value_on(st); |
2407 obj->print_address_on(st); | 2838 obj->print_address_on(st); |
2408 if (as_klassOop() == SystemDictionary::String_klass() | 2839 if (this == SystemDictionary::String_klass() |
2409 && java_lang_String::value(obj) != NULL) { | 2840 && java_lang_String::value(obj) != NULL) { |
2410 ResourceMark rm; | 2841 ResourceMark rm; |
2411 int len = java_lang_String::length(obj); | 2842 int len = java_lang_String::length(obj); |
2412 int plen = (len < 24 ? len : 12); | 2843 int plen = (len < 24 ? len : 12); |
2413 char* str = java_lang_String::as_utf8_string(obj, 0, plen); | 2844 char* str = java_lang_String::as_utf8_string(obj, 0, plen); |
2414 st->print(" = \"%s\"", str); | 2845 st->print(" = \"%s\"", str); |
2415 if (len > plen) | 2846 if (len > plen) |
2416 st->print("...[%d]", len); | 2847 st->print("...[%d]", len); |
2417 } else if (as_klassOop() == SystemDictionary::Class_klass()) { | 2848 } else if (this == SystemDictionary::Class_klass()) { |
2418 klassOop k = java_lang_Class::as_klassOop(obj); | 2849 Klass* k = java_lang_Class::as_Klass(obj); |
2419 st->print(" = "); | 2850 st->print(" = "); |
2420 if (k != NULL) { | 2851 if (k != NULL) { |
2421 k->print_value_on(st); | 2852 k->print_value_on(st); |
2422 } else { | 2853 } else { |
2423 const char* tname = type2name(java_lang_Class::primitive_type(obj)); | 2854 const char* tname = type2name(java_lang_Class::primitive_type(obj)); |
2424 st->print("%s", tname ? tname : "type?"); | 2855 st->print("%s", tname ? tname : "type?"); |
2425 } | 2856 } |
2426 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { | 2857 } else if (this == SystemDictionary::MethodType_klass()) { |
2427 st->print(" = "); | 2858 st->print(" = "); |
2428 java_lang_invoke_MethodType::print_signature(obj, st); | 2859 java_lang_invoke_MethodType::print_signature(obj, st); |
2429 } else if (java_lang_boxing_object::is_instance(obj)) { | 2860 } else if (java_lang_boxing_object::is_instance(obj)) { |
2430 st->print(" = "); | 2861 st->print(" = "); |
2431 java_lang_boxing_object::print(obj, st); | 2862 java_lang_boxing_object::print(obj, st); |
2432 } else if (as_klassOop() == SystemDictionary::LambdaForm_klass()) { | 2863 } else if (this == SystemDictionary::LambdaForm_klass()) { |
2433 oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj); | 2864 oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj); |
2434 if (vmentry != NULL) { | 2865 if (vmentry != NULL) { |
2435 st->print(" => "); | 2866 st->print(" => "); |
2436 vmentry->print_value_on(st); | 2867 vmentry->print_value_on(st); |
2437 } | 2868 } |
2438 } else if (as_klassOop() == SystemDictionary::MemberName_klass()) { | 2869 } else if (this == SystemDictionary::MemberName_klass()) { |
2439 oop vmtarget = java_lang_invoke_MemberName::vmtarget(obj); | 2870 Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj); |
2440 if (vmtarget != NULL) { | 2871 if (vmtarget != NULL) { |
2441 st->print(" = "); | 2872 st->print(" = "); |
2442 vmtarget->print_value_on(st); | 2873 vmtarget->print_value_on(st); |
2443 } else { | 2874 } else { |
2444 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st); | 2875 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st); |
2446 java_lang_invoke_MemberName::name(obj)->print_value_on(st); | 2877 java_lang_invoke_MemberName::name(obj)->print_value_on(st); |
2447 } | 2878 } |
2448 } | 2879 } |
2449 } | 2880 } |
2450 | 2881 |
2451 const char* instanceKlass::internal_name() const { | 2882 const char* InstanceKlass::internal_name() const { |
2452 return external_name(); | 2883 return external_name(); |
2453 } | 2884 } |
2454 | 2885 |
2455 // Verification | 2886 // Verification |
2456 | 2887 |
2457 class VerifyFieldClosure: public OopClosure { | 2888 class VerifyFieldClosure: public OopClosure { |
2458 protected: | 2889 protected: |
2459 template <class T> void do_oop_work(T* p) { | 2890 template <class T> void do_oop_work(T* p) { |
2460 guarantee(Universe::heap()->is_in_closed_subset(p), "should be in heap"); | |
2461 oop obj = oopDesc::load_decode_heap_oop(p); | 2891 oop obj = oopDesc::load_decode_heap_oop(p); |
2462 if (!obj->is_oop_or_null()) { | 2892 if (!obj->is_oop_or_null()) { |
2463 tty->print_cr("Failed: " PTR_FORMAT " -> " PTR_FORMAT, p, (address)obj); | 2893 tty->print_cr("Failed: " PTR_FORMAT " -> " PTR_FORMAT, p, (address)obj); |
2464 Universe::print(); | 2894 Universe::print(); |
2465 guarantee(false, "boom"); | 2895 guarantee(false, "boom"); |
2468 public: | 2898 public: |
2469 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } | 2899 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } |
2470 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } | 2900 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } |
2471 }; | 2901 }; |
2472 | 2902 |
2473 void instanceKlass::oop_verify_on(oop obj, outputStream* st) { | 2903 void InstanceKlass::verify_on(outputStream* st) { |
2904 Klass::verify_on(st); | |
2905 Thread *thread = Thread::current(); | |
2906 | |
2907 #ifndef PRODUCT | |
2908 // Avoid redundant verifies | |
2909 if (_verify_count == Universe::verify_count()) return; | |
2910 _verify_count = Universe::verify_count(); | |
2911 #endif | |
2912 // Verify that klass is present in SystemDictionary | |
2913 if (is_loaded() && !is_anonymous()) { | |
2914 Symbol* h_name = name(); | |
2915 SystemDictionary::verify_obj_klass_present(h_name, class_loader_data()); | |
2916 } | |
2917 | |
2918 // Verify static fields | |
2919 VerifyFieldClosure blk; | |
2920 | |
2921 // Verify vtables | |
2922 if (is_linked()) { | |
2923 ResourceMark rm(thread); | |
2924 // $$$ This used to be done only for m/s collections. Doing it | |
2925 // always seemed a valid generalization. (DLD -- 6/00) | |
2926 vtable()->verify(st); | |
2927 } | |
2928 | |
2929 // Verify first subklass | |
2930 if (subklass_oop() != NULL) { | |
2931 guarantee(subklass_oop()->is_metadata(), "should be in metaspace"); | |
2932 guarantee(subklass_oop()->is_klass(), "should be klass"); | |
2933 } | |
2934 | |
2935 // Verify siblings | |
2936 Klass* super = this->super(); | |
2937 Klass* sib = next_sibling(); | |
2938 if (sib != NULL) { | |
2939 if (sib == this) { | |
2940 fatal(err_msg("subclass points to itself " PTR_FORMAT, sib)); | |
2941 } | |
2942 | |
2943 guarantee(sib->is_metadata(), "should be in metaspace"); | |
2944 guarantee(sib->is_klass(), "should be klass"); | |
2945 guarantee(sib->super() == super, "siblings should have same superklass"); | |
2946 } | |
2947 | |
2948 // Verify implementor fields | |
2949 Klass* im = implementor(); | |
2950 if (im != NULL) { | |
2951 guarantee(is_interface(), "only interfaces should have implementor set"); | |
2952 guarantee(im->is_klass(), "should be klass"); | |
2953 guarantee(!Klass::cast(im)->is_interface() || im == this, | |
2954 "implementors cannot be interfaces"); | |
2955 } | |
2956 | |
2957 // Verify local interfaces | |
2958 if (local_interfaces()) { | |
2959 Array<Klass*>* local_interfaces = this->local_interfaces(); | |
2960 for (int j = 0; j < local_interfaces->length(); j++) { | |
2961 Klass* e = local_interfaces->at(j); | |
2962 guarantee(e->is_klass() && Klass::cast(e)->is_interface(), "invalid local interface"); | |
2963 } | |
2964 } | |
2965 | |
2966 // Verify transitive interfaces | |
2967 if (transitive_interfaces() != NULL) { | |
2968 Array<Klass*>* transitive_interfaces = this->transitive_interfaces(); | |
2969 for (int j = 0; j < transitive_interfaces->length(); j++) { | |
2970 Klass* e = transitive_interfaces->at(j); | |
2971 guarantee(e->is_klass() && Klass::cast(e)->is_interface(), "invalid transitive interface"); | |
2972 } | |
2973 } | |
2974 | |
2975 // Verify methods | |
2976 if (methods() != NULL) { | |
2977 Array<Method*>* methods = this->methods(); | |
2978 for (int j = 0; j < methods->length(); j++) { | |
2979 guarantee(methods->at(j)->is_metadata(), "should be in metaspace"); | |
2980 guarantee(methods->at(j)->is_method(), "non-method in methods array"); | |
2981 } | |
2982 for (int j = 0; j < methods->length() - 1; j++) { | |
2983 Method* m1 = methods->at(j); | |
2984 Method* m2 = methods->at(j + 1); | |
2985 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly"); | |
2986 } | |
2987 } | |
2988 | |
2989 // Verify method ordering | |
2990 if (method_ordering() != NULL) { | |
2991 Array<int>* method_ordering = this->method_ordering(); | |
2992 int length = method_ordering->length(); | |
2993 if (JvmtiExport::can_maintain_original_method_order() || | |
2994 (UseSharedSpaces && length != 0)) { | |
2995 guarantee(length == methods()->length(), "invalid method ordering length"); | |
2996 jlong sum = 0; | |
2997 for (int j = 0; j < length; j++) { | |
2998 int original_index = method_ordering->at(j); | |
2999 guarantee(original_index >= 0, "invalid method ordering index"); | |
3000 guarantee(original_index < length, "invalid method ordering index"); | |
3001 sum += original_index; | |
3002 } | |
3003 // Verify sum of indices 0,1,...,length-1 | |
3004 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); | |
3005 } else { | |
3006 guarantee(length == 0, "invalid method ordering length"); | |
3007 } | |
3008 } | |
3009 | |
3010 // Verify JNI static field identifiers | |
3011 if (jni_ids() != NULL) { | |
3012 jni_ids()->verify(this); | |
3013 } | |
3014 | |
3015 // Verify other fields | |
3016 if (array_klasses() != NULL) { | |
3017 guarantee(array_klasses()->is_metadata(), "should be in metaspace"); | |
3018 guarantee(array_klasses()->is_klass(), "should be klass"); | |
3019 } | |
3020 if (constants() != NULL) { | |
3021 guarantee(constants()->is_metadata(), "should be in metaspace"); | |
3022 guarantee(constants()->is_constantPool(), "should be constant pool"); | |
3023 } | |
3024 if (protection_domain() != NULL) { | |
3025 guarantee(protection_domain()->is_oop(), "should be oop"); | |
3026 } | |
3027 if (host_klass() != NULL) { | |
3028 guarantee(host_klass()->is_metadata(), "should be in metaspace"); | |
3029 guarantee(host_klass()->is_klass(), "should be klass"); | |
3030 } | |
3031 if (signers() != NULL) { | |
3032 guarantee(signers()->is_objArray(), "should be obj array"); | |
3033 } | |
3034 } | |
3035 | |
3036 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) { | |
2474 Klass::oop_verify_on(obj, st); | 3037 Klass::oop_verify_on(obj, st); |
2475 VerifyFieldClosure blk; | 3038 VerifyFieldClosure blk; |
2476 oop_oop_iterate(obj, &blk); | 3039 obj->oop_iterate_no_header(&blk); |
2477 } | 3040 } |
3041 | |
2478 | 3042 |
2479 // JNIid class for jfieldIDs only | 3043 // JNIid class for jfieldIDs only |
2480 // Note to reviewers: | 3044 // Note to reviewers: |
2481 // These JNI functions are just moved over to column 1 and not changed | 3045 // These JNI functions are just moved over to column 1 and not changed |
2482 // in the compressed oops workspace. | 3046 // in the compressed oops workspace. |
2483 JNIid::JNIid(klassOop holder, int offset, JNIid* next) { | 3047 JNIid::JNIid(Klass* holder, int offset, JNIid* next) { |
2484 _holder = holder; | 3048 _holder = holder; |
2485 _offset = offset; | 3049 _offset = offset; |
2486 _next = next; | 3050 _next = next; |
2487 debug_only(_is_static_field_id = false;) | 3051 debug_only(_is_static_field_id = false;) |
2488 } | 3052 } |
2495 current = current->next(); | 3059 current = current->next(); |
2496 } | 3060 } |
2497 return NULL; | 3061 return NULL; |
2498 } | 3062 } |
2499 | 3063 |
2500 void JNIid::oops_do(OopClosure* f) { | |
2501 for (JNIid* cur = this; cur != NULL; cur = cur->next()) { | |
2502 f->do_oop(cur->holder_addr()); | |
2503 } | |
2504 } | |
2505 | |
2506 void JNIid::deallocate(JNIid* current) { | 3064 void JNIid::deallocate(JNIid* current) { |
2507 while (current != NULL) { | 3065 while (current != NULL) { |
2508 JNIid* next = current->next(); | 3066 JNIid* next = current->next(); |
2509 delete current; | 3067 delete current; |
2510 current = next; | 3068 current = next; |
2511 } | 3069 } |
2512 } | 3070 } |
2513 | 3071 |
2514 | 3072 |
2515 void JNIid::verify(klassOop holder) { | 3073 void JNIid::verify(Klass* holder) { |
2516 int first_field_offset = instanceMirrorKlass::offset_of_static_fields(); | 3074 int first_field_offset = instanceMirrorKlass::offset_of_static_fields(); |
2517 int end_field_offset; | 3075 int end_field_offset; |
2518 end_field_offset = first_field_offset + (instanceKlass::cast(holder)->static_field_size() * wordSize); | 3076 end_field_offset = first_field_offset + (InstanceKlass::cast(holder)->static_field_size() * wordSize); |
2519 | 3077 |
2520 JNIid* current = this; | 3078 JNIid* current = this; |
2521 while (current != NULL) { | 3079 while (current != NULL) { |
2522 guarantee(current->holder() == holder, "Invalid klass in JNIid"); | 3080 guarantee(current->holder() == holder, "Invalid klass in JNIid"); |
2523 #ifdef ASSERT | 3081 #ifdef ASSERT |
2530 } | 3088 } |
2531 } | 3089 } |
2532 | 3090 |
2533 | 3091 |
2534 #ifdef ASSERT | 3092 #ifdef ASSERT |
2535 void instanceKlass::set_init_state(ClassState state) { | 3093 void InstanceKlass::set_init_state(ClassState state) { |
2536 bool good_state = as_klassOop()->is_shared() ? (_init_state <= state) | 3094 bool good_state = is_shared() ? (_init_state <= state) |
2537 : (_init_state < state); | 3095 : (_init_state < state); |
2538 assert(good_state || state == allocated, "illegal state transition"); | 3096 assert(good_state || state == allocated, "illegal state transition"); |
2539 _init_state = (u1)state; | 3097 _init_state = (u1)state; |
2540 } | 3098 } |
2541 #endif | 3099 #endif |
2542 | 3100 |
2543 | 3101 |
2544 // RedefineClasses() support for previous versions: | 3102 // RedefineClasses() support for previous versions: |
2545 | 3103 |
2546 // Add an information node that contains weak references to the | 3104 // Purge previous versions |
3105 static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) { | |
3106 if (ik->previous_versions() != NULL) { | |
3107 // This klass has previous versions so see what we can cleanup | |
3108 // while it is safe to do so. | |
3109 | |
3110 int deleted_count = 0; // leave debugging breadcrumbs | |
3111 int live_count = 0; | |
3112 ClassLoaderData* loader_data = ik->class_loader_data() == NULL ? | |
3113 ClassLoaderData::the_null_class_loader_data() : | |
3114 ik->class_loader_data(); | |
3115 | |
3116 // RC_TRACE macro has an embedded ResourceMark | |
3117 RC_TRACE(0x00000200, ("purge: %s: previous version length=%d", | |
3118 ik->external_name(), ik->previous_versions()->length())); | |
3119 | |
3120 for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) { | |
3121 // check the previous versions array | |
3122 PreviousVersionNode * pv_node = ik->previous_versions()->at(i); | |
3123 ConstantPool* cp_ref = pv_node->prev_constant_pool(); | |
3124 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); | |
3125 | |
3126 ConstantPool* pvcp = cp_ref; | |
3127 if (!pvcp->on_stack()) { | |
3128 // If the constant pool isn't on stack, none of the methods | |
3129 // are executing. Delete all the methods, the constant pool and | |
3130 // and this previous version node. | |
3131 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); | |
3132 if (method_refs != NULL) { | |
3133 for (int j = method_refs->length() - 1; j >= 0; j--) { | |
3134 Method* method = method_refs->at(j); | |
3135 assert(method != NULL, "method ref was unexpectedly cleared"); | |
3136 method_refs->remove_at(j); | |
3137 // method will be freed with associated class. | |
3138 } | |
3139 } | |
3140 // Remove the constant pool | |
3141 delete pv_node; | |
3142 // Since we are traversing the array backwards, we don't have to | |
3143 // do anything special with the index. | |
3144 ik->previous_versions()->remove_at(i); | |
3145 deleted_count++; | |
3146 continue; | |
3147 } else { | |
3148 RC_TRACE(0x00000200, ("purge: previous version @%d is alive", i)); | |
3149 assert(pvcp->pool_holder() != NULL, "Constant pool with no holder"); | |
3150 guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack"); | |
3151 live_count++; | |
3152 } | |
3153 | |
3154 // At least one method is live in this previous version, clean out | |
3155 // the others or mark them as obsolete. | |
3156 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); | |
3157 if (method_refs != NULL) { | |
3158 RC_TRACE(0x00000200, ("purge: previous methods length=%d", | |
3159 method_refs->length())); | |
3160 for (int j = method_refs->length() - 1; j >= 0; j--) { | |
3161 Method* method = method_refs->at(j); | |
3162 assert(method != NULL, "method ref was unexpectedly cleared"); | |
3163 | |
3164 // Remove the emcp method if it's not executing | |
3165 // If it's been made obsolete by a redefinition of a non-emcp | |
3166 // method, mark it as obsolete but leave it to clean up later. | |
3167 if (!method->on_stack()) { | |
3168 method_refs->remove_at(j); | |
3169 } else if (emcp_method_count == 0) { | |
3170 method->set_is_obsolete(); | |
3171 } else { | |
3172 // RC_TRACE macro has an embedded ResourceMark | |
3173 RC_TRACE(0x00000200, | |
3174 ("purge: %s(%s): prev method @%d in version @%d is alive", | |
3175 method->name()->as_C_string(), | |
3176 method->signature()->as_C_string(), j, i)); | |
3177 } | |
3178 } | |
3179 } | |
3180 } | |
3181 assert(ik->previous_versions()->length() == live_count, "sanity check"); | |
3182 RC_TRACE(0x00000200, | |
3183 ("purge: previous version stats: live=%d, deleted=%d", live_count, | |
3184 deleted_count)); | |
3185 } | |
3186 } | |
3187 | |
3188 // External interface for use during class unloading. | |
3189 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) { | |
3190 // Call with >0 emcp methods since they are not currently being redefined. | |
3191 purge_previous_versions_internal(ik, 1); | |
3192 } | |
3193 | |
3194 | |
3195 // Potentially add an information node that contains pointers to the | |
2547 // interesting parts of the previous version of the_class. | 3196 // interesting parts of the previous version of the_class. |
2548 // This is also where we clean out any unused weak references. | 3197 // This is also where we clean out any unused references. |
2549 // Note that while we delete nodes from the _previous_versions | 3198 // Note that while we delete nodes from the _previous_versions |
2550 // array, we never delete the array itself until the klass is | 3199 // array, we never delete the array itself until the klass is |
2551 // unloaded. The has_been_redefined() query depends on that fact. | 3200 // unloaded. The has_been_redefined() query depends on that fact. |
2552 // | 3201 // |
2553 void instanceKlass::add_previous_version(instanceKlassHandle ikh, | 3202 void InstanceKlass::add_previous_version(instanceKlassHandle ikh, |
2554 BitMap* emcp_methods, int emcp_method_count) { | 3203 BitMap* emcp_methods, int emcp_method_count) { |
2555 assert(Thread::current()->is_VM_thread(), | 3204 assert(Thread::current()->is_VM_thread(), |
2556 "only VMThread can add previous versions"); | 3205 "only VMThread can add previous versions"); |
2557 | 3206 |
2558 if (_previous_versions == NULL) { | 3207 if (_previous_versions == NULL) { |
2561 // won't be redefined much. | 3210 // won't be redefined much. |
2562 _previous_versions = new (ResourceObj::C_HEAP, mtClass) | 3211 _previous_versions = new (ResourceObj::C_HEAP, mtClass) |
2563 GrowableArray<PreviousVersionNode *>(2, true); | 3212 GrowableArray<PreviousVersionNode *>(2, true); |
2564 } | 3213 } |
2565 | 3214 |
3215 ConstantPool* cp_ref = ikh->constants(); | |
3216 | |
2566 // RC_TRACE macro has an embedded ResourceMark | 3217 // RC_TRACE macro has an embedded ResourceMark |
2567 RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d", | 3218 RC_TRACE(0x00000400, ("adding previous version ref for %s @%d, EMCP_cnt=%d " |
2568 ikh->external_name(), _previous_versions->length(), emcp_method_count)); | 3219 "on_stack=%d", |
2569 constantPoolHandle cp_h(ikh->constants()); | 3220 ikh->external_name(), _previous_versions->length(), emcp_method_count, |
2570 jobject cp_ref; | 3221 cp_ref->on_stack())); |
2571 if (cp_h->is_shared()) { | 3222 |
2572 // a shared ConstantPool requires a regular reference; a weak | 3223 // If the constant pool for this previous version of the class |
2573 // reference would be collectible | 3224 // is not marked as being on the stack, then none of the methods |
2574 cp_ref = JNIHandles::make_global(cp_h); | 3225 // in this previous version of the class are on the stack so |
2575 } else { | 3226 // we don't need to create a new PreviousVersionNode. However, |
2576 cp_ref = JNIHandles::make_weak_global(cp_h); | 3227 // we still need to examine older previous versions below. |
2577 } | 3228 Array<Method*>* old_methods = ikh->methods(); |
3229 | |
3230 if (cp_ref->on_stack()) { | |
2578 PreviousVersionNode * pv_node = NULL; | 3231 PreviousVersionNode * pv_node = NULL; |
2579 objArrayOop old_methods = ikh->methods(); | |
2580 | |
2581 if (emcp_method_count == 0) { | 3232 if (emcp_method_count == 0) { |
2582 // non-shared ConstantPool gets a weak reference | 3233 // non-shared ConstantPool gets a reference |
2583 pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL); | 3234 pv_node = new PreviousVersionNode(cp_ref, !cp_ref->is_shared(), NULL); |
2584 RC_TRACE(0x00000400, | 3235 RC_TRACE(0x00000400, |
2585 ("add: all methods are obsolete; flushing any EMCP weak refs")); | 3236 ("add: all methods are obsolete; flushing any EMCP refs")); |
2586 } else { | 3237 } else { |
2587 int local_count = 0; | 3238 int local_count = 0; |
2588 GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass) | 3239 GrowableArray<Method*>* method_refs = new (ResourceObj::C_HEAP, mtClass) |
2589 GrowableArray<jweak>(emcp_method_count, true); | 3240 GrowableArray<Method*>(emcp_method_count, true); |
2590 for (int i = 0; i < old_methods->length(); i++) { | 3241 for (int i = 0; i < old_methods->length(); i++) { |
2591 if (emcp_methods->at(i)) { | 3242 if (emcp_methods->at(i)) { |
2592 // this old method is EMCP so save a weak ref | 3243 // this old method is EMCP. Save it only if it's on the stack |
2593 methodOop old_method = (methodOop) old_methods->obj_at(i); | 3244 Method* old_method = old_methods->at(i); |
2594 methodHandle old_method_h(old_method); | 3245 if (old_method->on_stack()) { |
2595 jweak method_ref = JNIHandles::make_weak_global(old_method_h); | 3246 method_refs->append(old_method); |
2596 method_refs->append(method_ref); | 3247 } |
2597 if (++local_count >= emcp_method_count) { | 3248 if (++local_count >= emcp_method_count) { |
2598 // no more EMCP methods so bail out now | 3249 // no more EMCP methods so bail out now |
2599 break; | 3250 break; |
2600 } | 3251 } |
2601 } | 3252 } |
2602 } | 3253 } |
2603 // non-shared ConstantPool gets a weak reference | 3254 // non-shared ConstantPool gets a reference |
2604 pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs); | 3255 pv_node = new PreviousVersionNode(cp_ref, !cp_ref->is_shared(), method_refs); |
2605 } | 3256 } |
2606 | 3257 // append new previous version. |
2607 _previous_versions->append(pv_node); | 3258 _previous_versions->append(pv_node); |
2608 | 3259 } |
2609 // Using weak references allows the interesting parts of previous | 3260 |
2610 // classes to be GC'ed when they are no longer needed. Since the | 3261 // Since the caller is the VMThread and we are at a safepoint, this |
2611 // caller is the VMThread and we are at a safepoint, this is a good | 3262 // is a good time to clear out unused references. |
2612 // time to clear out unused weak references. | |
2613 | 3263 |
2614 RC_TRACE(0x00000400, ("add: previous version length=%d", | 3264 RC_TRACE(0x00000400, ("add: previous version length=%d", |
2615 _previous_versions->length())); | 3265 _previous_versions->length())); |
2616 | 3266 |
2617 // skip the last entry since we just added it | 3267 // Purge previous versions not executing on the stack |
2618 for (int i = _previous_versions->length() - 2; i >= 0; i--) { | 3268 purge_previous_versions_internal(this, emcp_method_count); |
2619 // check the previous versions array for a GC'ed weak refs | |
2620 pv_node = _previous_versions->at(i); | |
2621 cp_ref = pv_node->prev_constant_pool(); | |
2622 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); | |
2623 if (cp_ref == NULL) { | |
2624 delete pv_node; | |
2625 _previous_versions->remove_at(i); | |
2626 // Since we are traversing the array backwards, we don't have to | |
2627 // do anything special with the index. | |
2628 continue; // robustness | |
2629 } | |
2630 | |
2631 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); | |
2632 if (cp == NULL) { | |
2633 // this entry has been GC'ed so remove it | |
2634 delete pv_node; | |
2635 _previous_versions->remove_at(i); | |
2636 // Since we are traversing the array backwards, we don't have to | |
2637 // do anything special with the index. | |
2638 continue; | |
2639 } else { | |
2640 RC_TRACE(0x00000400, ("add: previous version @%d is alive", i)); | |
2641 } | |
2642 | |
2643 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); | |
2644 if (method_refs != NULL) { | |
2645 RC_TRACE(0x00000400, ("add: previous methods length=%d", | |
2646 method_refs->length())); | |
2647 for (int j = method_refs->length() - 1; j >= 0; j--) { | |
2648 jweak method_ref = method_refs->at(j); | |
2649 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | |
2650 if (method_ref == NULL) { | |
2651 method_refs->remove_at(j); | |
2652 // Since we are traversing the array backwards, we don't have to | |
2653 // do anything special with the index. | |
2654 continue; // robustness | |
2655 } | |
2656 | |
2657 methodOop method = (methodOop)JNIHandles::resolve(method_ref); | |
2658 if (method == NULL || emcp_method_count == 0) { | |
2659 // This method entry has been GC'ed or the current | |
2660 // RedefineClasses() call has made all methods obsolete | |
2661 // so remove it. | |
2662 JNIHandles::destroy_weak_global(method_ref); | |
2663 method_refs->remove_at(j); | |
2664 } else { | |
2665 // RC_TRACE macro has an embedded ResourceMark | |
2666 RC_TRACE(0x00000400, | |
2667 ("add: %s(%s): previous method @%d in version @%d is alive", | |
2668 method->name()->as_C_string(), method->signature()->as_C_string(), | |
2669 j, i)); | |
2670 } | |
2671 } | |
2672 } | |
2673 } | |
2674 | 3269 |
2675 int obsolete_method_count = old_methods->length() - emcp_method_count; | 3270 int obsolete_method_count = old_methods->length() - emcp_method_count; |
2676 | 3271 |
2677 if (emcp_method_count != 0 && obsolete_method_count != 0 && | 3272 if (emcp_method_count != 0 && obsolete_method_count != 0 && |
2678 _previous_versions->length() > 1) { | 3273 _previous_versions->length() > 0) { |
2679 // We have a mix of obsolete and EMCP methods. If there is more | 3274 // We have a mix of obsolete and EMCP methods so we have to |
2680 // than the previous version that we just added, then we have to | |
2681 // clear out any matching EMCP method entries the hard way. | 3275 // clear out any matching EMCP method entries the hard way. |
2682 int local_count = 0; | 3276 int local_count = 0; |
2683 for (int i = 0; i < old_methods->length(); i++) { | 3277 for (int i = 0; i < old_methods->length(); i++) { |
2684 if (!emcp_methods->at(i)) { | 3278 if (!emcp_methods->at(i)) { |
2685 // only obsolete methods are interesting | 3279 // only obsolete methods are interesting |
2686 methodOop old_method = (methodOop) old_methods->obj_at(i); | 3280 Method* old_method = old_methods->at(i); |
2687 Symbol* m_name = old_method->name(); | 3281 Symbol* m_name = old_method->name(); |
2688 Symbol* m_signature = old_method->signature(); | 3282 Symbol* m_signature = old_method->signature(); |
2689 | 3283 |
2690 // skip the last entry since we just added it | 3284 // we might not have added the last entry |
2691 for (int j = _previous_versions->length() - 2; j >= 0; j--) { | 3285 for (int j = _previous_versions->length() - 1; j >= 0; j--) { |
2692 // check the previous versions array for a GC'ed weak refs | 3286 // check the previous versions array for non executing obsolete methods |
2693 pv_node = _previous_versions->at(j); | 3287 PreviousVersionNode * pv_node = _previous_versions->at(j); |
2694 cp_ref = pv_node->prev_constant_pool(); | 3288 |
2695 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); | 3289 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
2696 if (cp_ref == NULL) { | |
2697 delete pv_node; | |
2698 _previous_versions->remove_at(j); | |
2699 // Since we are traversing the array backwards, we don't have to | |
2700 // do anything special with the index. | |
2701 continue; // robustness | |
2702 } | |
2703 | |
2704 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); | |
2705 if (cp == NULL) { | |
2706 // this entry has been GC'ed so remove it | |
2707 delete pv_node; | |
2708 _previous_versions->remove_at(j); | |
2709 // Since we are traversing the array backwards, we don't have to | |
2710 // do anything special with the index. | |
2711 continue; | |
2712 } | |
2713 | |
2714 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); | |
2715 if (method_refs == NULL) { | 3290 if (method_refs == NULL) { |
2716 // We have run into a PreviousVersion generation where | 3291 // We have run into a PreviousVersion generation where |
2717 // all methods were made obsolete during that generation's | 3292 // all methods were made obsolete during that generation's |
2718 // RedefineClasses() operation. At the time of that | 3293 // RedefineClasses() operation. At the time of that |
2719 // operation, all EMCP methods were flushed so we don't | 3294 // operation, all EMCP methods were flushed so we don't |
2724 // from an empty method_refs for the current generation. | 3299 // from an empty method_refs for the current generation. |
2725 break; | 3300 break; |
2726 } | 3301 } |
2727 | 3302 |
2728 for (int k = method_refs->length() - 1; k >= 0; k--) { | 3303 for (int k = method_refs->length() - 1; k >= 0; k--) { |
2729 jweak method_ref = method_refs->at(k); | 3304 Method* method = method_refs->at(k); |
2730 assert(method_ref != NULL, | 3305 |
2731 "weak method ref was unexpectedly cleared"); | 3306 if (!method->is_obsolete() && |
2732 if (method_ref == NULL) { | 3307 method->name() == m_name && |
2733 method_refs->remove_at(k); | |
2734 // Since we are traversing the array backwards, we don't | |
2735 // have to do anything special with the index. | |
2736 continue; // robustness | |
2737 } | |
2738 | |
2739 methodOop method = (methodOop)JNIHandles::resolve(method_ref); | |
2740 if (method == NULL) { | |
2741 // this method entry has been GC'ed so skip it | |
2742 JNIHandles::destroy_weak_global(method_ref); | |
2743 method_refs->remove_at(k); | |
2744 continue; | |
2745 } | |
2746 | |
2747 if (method->name() == m_name && | |
2748 method->signature() == m_signature) { | 3308 method->signature() == m_signature) { |
2749 // The current RedefineClasses() call has made all EMCP | 3309 // The current RedefineClasses() call has made all EMCP |
2750 // versions of this method obsolete so mark it as obsolete | 3310 // versions of this method obsolete so mark it as obsolete |
2751 // and remove the weak ref. | 3311 // and remove the reference. |
2752 RC_TRACE(0x00000400, | 3312 RC_TRACE(0x00000400, |
2753 ("add: %s(%s): flush obsolete method @%d in version @%d", | 3313 ("add: %s(%s): flush obsolete method @%d in version @%d", |
2754 m_name->as_C_string(), m_signature->as_C_string(), k, j)); | 3314 m_name->as_C_string(), m_signature->as_C_string(), k, j)); |
2755 | 3315 |
2756 method->set_is_obsolete(); | 3316 method->set_is_obsolete(); |
2757 JNIHandles::destroy_weak_global(method_ref); | 3317 // Leave obsolete methods on the previous version list to |
2758 method_refs->remove_at(k); | 3318 // clean up later. |
2759 break; | 3319 break; |
2760 } | 3320 } |
2761 } | 3321 } |
2762 | 3322 |
2763 // The previous loop may not find a matching EMCP method, but | 3323 // The previous loop may not find a matching EMCP method, but |
2764 // that doesn't mean that we can optimize and not go any | 3324 // that doesn't mean that we can optimize and not go any |
2765 // further back in the PreviousVersion generations. The EMCP | 3325 // further back in the PreviousVersion generations. The EMCP |
2766 // method for this generation could have already been GC'ed, | 3326 // method for this generation could have already been deleted, |
2767 // but there still may be an older EMCP method that has not | 3327 // but there still may be an older EMCP method that has not |
2768 // been GC'ed. | 3328 // been deleted. |
2769 } | 3329 } |
2770 | 3330 |
2771 if (++local_count >= obsolete_method_count) { | 3331 if (++local_count >= obsolete_method_count) { |
2772 // no more obsolete methods so bail out now | 3332 // no more obsolete methods so bail out now |
2773 break; | 3333 break; |
2776 } | 3336 } |
2777 } | 3337 } |
2778 } // end add_previous_version() | 3338 } // end add_previous_version() |
2779 | 3339 |
2780 | 3340 |
2781 // Determine if instanceKlass has a previous version. | 3341 // Determine if InstanceKlass has a previous version. |
2782 bool instanceKlass::has_previous_version() const { | 3342 bool InstanceKlass::has_previous_version() const { |
2783 if (_previous_versions == NULL) { | 3343 return (_previous_versions != NULL && _previous_versions->length() > 0); |
2784 // no previous versions array so answer is easy | |
2785 return false; | |
2786 } | |
2787 | |
2788 for (int i = _previous_versions->length() - 1; i >= 0; i--) { | |
2789 // Check the previous versions array for an info node that hasn't | |
2790 // been GC'ed | |
2791 PreviousVersionNode * pv_node = _previous_versions->at(i); | |
2792 | |
2793 jobject cp_ref = pv_node->prev_constant_pool(); | |
2794 assert(cp_ref != NULL, "cp reference was unexpectedly cleared"); | |
2795 if (cp_ref == NULL) { | |
2796 continue; // robustness | |
2797 } | |
2798 | |
2799 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); | |
2800 if (cp != NULL) { | |
2801 // we have at least one previous version | |
2802 return true; | |
2803 } | |
2804 | |
2805 // We don't have to check the method refs. If the constant pool has | |
2806 // been GC'ed then so have the methods. | |
2807 } | |
2808 | |
2809 // all of the underlying nodes' info has been GC'ed | |
2810 return false; | |
2811 } // end has_previous_version() | 3344 } // end has_previous_version() |
2812 | 3345 |
2813 methodOop instanceKlass::method_with_idnum(int idnum) { | 3346 |
2814 methodOop m = NULL; | 3347 Method* InstanceKlass::method_with_idnum(int idnum) { |
3348 Method* m = NULL; | |
2815 if (idnum < methods()->length()) { | 3349 if (idnum < methods()->length()) { |
2816 m = (methodOop) methods()->obj_at(idnum); | 3350 m = methods()->at(idnum); |
2817 } | 3351 } |
2818 if (m == NULL || m->method_idnum() != idnum) { | 3352 if (m == NULL || m->method_idnum() != idnum) { |
2819 for (int index = 0; index < methods()->length(); ++index) { | 3353 for (int index = 0; index < methods()->length(); ++index) { |
2820 m = (methodOop) methods()->obj_at(index); | 3354 m = methods()->at(index); |
2821 if (m->method_idnum() == idnum) { | 3355 if (m->method_idnum() == idnum) { |
2822 return m; | 3356 return m; |
2823 } | 3357 } |
2824 } | 3358 } |
2825 } | 3359 } |
2826 return m; | 3360 return m; |
2827 } | 3361 } |
2828 | 3362 |
2829 | 3363 |
2830 // Set the annotation at 'idnum' to 'anno'. | |
2831 // We don't want to create or extend the array if 'anno' is NULL, since that is the | |
2832 // default value. However, if the array exists and is long enough, we must set NULL values. | |
2833 void instanceKlass::set_methods_annotations_of(int idnum, typeArrayOop anno, objArrayOop* md_p) { | |
2834 objArrayOop md = *md_p; | |
2835 if (md != NULL && md->length() > idnum) { | |
2836 md->obj_at_put(idnum, anno); | |
2837 } else if (anno != NULL) { | |
2838 // create the array | |
2839 int length = MAX2(idnum+1, (int)_idnum_allocated_count); | |
2840 md = oopFactory::new_system_objArray(length, Thread::current()); | |
2841 if (*md_p != NULL) { | |
2842 // copy the existing entries | |
2843 for (int index = 0; index < (*md_p)->length(); index++) { | |
2844 md->obj_at_put(index, (*md_p)->obj_at(index)); | |
2845 } | |
2846 } | |
2847 set_annotations(md, md_p); | |
2848 md->obj_at_put(idnum, anno); | |
2849 } // if no array and idnum isn't included there is nothing to do | |
2850 } | |
2851 | |
2852 // Construct a PreviousVersionNode entry for the array hung off | 3364 // Construct a PreviousVersionNode entry for the array hung off |
2853 // the instanceKlass. | 3365 // the InstanceKlass. |
2854 PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool, | 3366 PreviousVersionNode::PreviousVersionNode(ConstantPool* prev_constant_pool, |
2855 bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) { | 3367 bool prev_cp_is_weak, GrowableArray<Method*>* prev_EMCP_methods) { |
2856 | 3368 |
2857 _prev_constant_pool = prev_constant_pool; | 3369 _prev_constant_pool = prev_constant_pool; |
2858 _prev_cp_is_weak = prev_cp_is_weak; | 3370 _prev_cp_is_weak = prev_cp_is_weak; |
2859 _prev_EMCP_methods = prev_EMCP_methods; | 3371 _prev_EMCP_methods = prev_EMCP_methods; |
2860 } | 3372 } |
2861 | 3373 |
2862 | 3374 |
2863 // Destroy a PreviousVersionNode | 3375 // Destroy a PreviousVersionNode |
2864 PreviousVersionNode::~PreviousVersionNode() { | 3376 PreviousVersionNode::~PreviousVersionNode() { |
2865 if (_prev_constant_pool != NULL) { | 3377 if (_prev_constant_pool != NULL) { |
2866 if (_prev_cp_is_weak) { | 3378 _prev_constant_pool = NULL; |
2867 JNIHandles::destroy_weak_global(_prev_constant_pool); | |
2868 } else { | |
2869 JNIHandles::destroy_global(_prev_constant_pool); | |
2870 } | |
2871 } | 3379 } |
2872 | 3380 |
2873 if (_prev_EMCP_methods != NULL) { | 3381 if (_prev_EMCP_methods != NULL) { |
2874 for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) { | |
2875 jweak method_ref = _prev_EMCP_methods->at(i); | |
2876 if (method_ref != NULL) { | |
2877 JNIHandles::destroy_weak_global(method_ref); | |
2878 } | |
2879 } | |
2880 delete _prev_EMCP_methods; | 3382 delete _prev_EMCP_methods; |
2881 } | 3383 } |
2882 } | 3384 } |
2883 | 3385 |
2884 | 3386 |
2885 // Construct a PreviousVersionInfo entry | 3387 // Construct a PreviousVersionInfo entry |
2886 PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) { | 3388 PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) { |
2887 _prev_constant_pool_handle = constantPoolHandle(); // NULL handle | 3389 _prev_constant_pool_handle = constantPoolHandle(); // NULL handle |
2888 _prev_EMCP_method_handles = NULL; | 3390 _prev_EMCP_method_handles = NULL; |
2889 | 3391 |
2890 jobject cp_ref = pv_node->prev_constant_pool(); | 3392 ConstantPool* cp = pv_node->prev_constant_pool(); |
2891 assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared"); | 3393 assert(cp != NULL, "constant pool ref was unexpectedly cleared"); |
2892 if (cp_ref == NULL) { | 3394 if (cp == NULL) { |
2893 return; // robustness | 3395 return; // robustness |
2894 } | 3396 } |
2895 | 3397 |
2896 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); | 3398 // make the ConstantPool* safe to return |
2897 if (cp == NULL) { | |
2898 // Weak reference has been GC'ed. Since the constant pool has been | |
2899 // GC'ed, the methods have also been GC'ed. | |
2900 return; | |
2901 } | |
2902 | |
2903 // make the constantPoolOop safe to return | |
2904 _prev_constant_pool_handle = constantPoolHandle(cp); | 3399 _prev_constant_pool_handle = constantPoolHandle(cp); |
2905 | 3400 |
2906 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); | 3401 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
2907 if (method_refs == NULL) { | 3402 if (method_refs == NULL) { |
2908 // the instanceKlass did not have any EMCP methods | 3403 // the InstanceKlass did not have any EMCP methods |
2909 return; | 3404 return; |
2910 } | 3405 } |
2911 | 3406 |
2912 _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10); | 3407 _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10); |
2913 | 3408 |
2914 int n_methods = method_refs->length(); | 3409 int n_methods = method_refs->length(); |
2915 for (int i = 0; i < n_methods; i++) { | 3410 for (int i = 0; i < n_methods; i++) { |
2916 jweak method_ref = method_refs->at(i); | 3411 Method* method = method_refs->at(i); |
2917 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | 3412 assert (method != NULL, "method has been cleared"); |
2918 if (method_ref == NULL) { | 3413 if (method == NULL) { |
2919 continue; // robustness | 3414 continue; // robustness |
2920 } | 3415 } |
2921 | 3416 // make the Method* safe to return |
2922 methodOop method = (methodOop)JNIHandles::resolve(method_ref); | |
2923 if (method == NULL) { | |
2924 // this entry has been GC'ed so skip it | |
2925 continue; | |
2926 } | |
2927 | |
2928 // make the methodOop safe to return | |
2929 _prev_EMCP_method_handles->append(methodHandle(method)); | 3417 _prev_EMCP_method_handles->append(methodHandle(method)); |
2930 } | 3418 } |
2931 } | 3419 } |
2932 | 3420 |
2933 | 3421 |
2937 // don't have to delete it. | 3425 // don't have to delete it. |
2938 } | 3426 } |
2939 | 3427 |
2940 | 3428 |
2941 // Construct a helper for walking the previous versions array | 3429 // Construct a helper for walking the previous versions array |
2942 PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) { | 3430 PreviousVersionWalker::PreviousVersionWalker(InstanceKlass *ik) { |
2943 _previous_versions = ik->previous_versions(); | 3431 _previous_versions = ik->previous_versions(); |
2944 _current_index = 0; | 3432 _current_index = 0; |
2945 // _hm needs no initialization | 3433 // _hm needs no initialization |
2946 _current_p = NULL; | 3434 _current_p = NULL; |
2947 } | 3435 } |
2979 PreviousVersionNode * pv_node = _previous_versions->at(_current_index++); | 3467 PreviousVersionNode * pv_node = _previous_versions->at(_current_index++); |
2980 PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass) | 3468 PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP, mtClass) |
2981 PreviousVersionInfo(pv_node); | 3469 PreviousVersionInfo(pv_node); |
2982 | 3470 |
2983 constantPoolHandle cp_h = pv_info->prev_constant_pool_handle(); | 3471 constantPoolHandle cp_h = pv_info->prev_constant_pool_handle(); |
2984 if (cp_h.is_null()) { | 3472 assert (!cp_h.is_null(), "null cp found in previous version"); |
2985 delete pv_info; | 3473 |
2986 | 3474 // The caller will need to delete pv_info when they are done with it. |
2987 // The underlying node's info has been GC'ed so try the next one. | |
2988 // We don't have to check the methods. If the constant pool has | |
2989 // GC'ed then so have the methods. | |
2990 continue; | |
2991 } | |
2992 | |
2993 // Found a node with non GC'ed info so return it. The caller will | |
2994 // need to delete pv_info when they are done with it. | |
2995 _current_p = pv_info; | 3475 _current_p = pv_info; |
2996 return pv_info; | 3476 return pv_info; |
2997 } | 3477 } |
2998 | 3478 |
2999 // all of the underlying nodes' info has been GC'ed | 3479 // all of the underlying nodes' info has been deleted |
3000 return NULL; | 3480 return NULL; |
3001 } // end next_previous_version() | 3481 } // end next_previous_version() |