1.1 --- a/src/share/vm/prims/jvmtiTagMap.cpp Fri Aug 31 16:39:35 2012 -0700 1.2 +++ b/src/share/vm/prims/jvmtiTagMap.cpp Sat Sep 01 13:25:18 2012 -0400 1.3 @@ -533,17 +533,6 @@ 1.4 } 1.5 } 1.6 1.7 -// If the object is a java.lang.Class then return the klassOop, 1.8 -// otherwise return the original object 1.9 -static inline oop klassOop_if_java_lang_Class(oop o) { 1.10 - if (o->klass() == SystemDictionary::Class_klass()) { 1.11 - if (!java_lang_Class::is_primitive(o)) { 1.12 - o = (oop)java_lang_Class::as_klassOop(o); 1.13 - assert(o != NULL, "class for non-primitive mirror must exist"); 1.14 - } 1.15 - } 1.16 - return o; 1.17 -} 1.18 1.19 // A CallbackWrapper is a support class for querying and tagging an object 1.20 // around a callback to a profiler. The constructor does pre-callback 1.21 @@ -567,7 +556,6 @@ 1.22 oop _o; 1.23 jlong _obj_size; 1.24 jlong _obj_tag; 1.25 - klassOop _klass; // the object's class 1.26 jlong _klass_tag; 1.27 1.28 protected: 1.29 @@ -581,8 +569,8 @@ 1.30 assert(Thread::current()->is_VM_thread() || tag_map->is_locked(), 1.31 "MT unsafe or must be VM thread"); 1.32 1.33 - // for Classes the klassOop is tagged 1.34 - _o = klassOop_if_java_lang_Class(o); 1.35 + // object to tag 1.36 + _o = o; 1.37 1.38 // object size 1.39 _obj_size = (jlong)_o->size() * wordSize; 1.40 @@ -596,14 +584,9 @@ 1.41 _obj_tag = (_entry == NULL) ? 0 : _entry->tag(); 1.42 1.43 // get the class and the class's tag value 1.44 - if (_o == o) { 1.45 - _klass = _o->klass(); 1.46 - } else { 1.47 - // if the object represents a runtime class then use the 1.48 - // tag for java.lang.Class 1.49 - _klass = SystemDictionary::Class_klass(); 1.50 - } 1.51 - _klass_tag = tag_for(tag_map, _klass); 1.52 + assert(SystemDictionary::Class_klass()->oop_is_instanceMirror(), "Is not?"); 1.53 + 1.54 + _klass_tag = tag_for(tag_map, _o->klass()->java_mirror()); 1.55 } 1.56 1.57 ~CallbackWrapper() { 1.58 @@ -613,7 +596,6 @@ 1.59 inline jlong* obj_tag_p() { return &_obj_tag; } 1.60 inline jlong obj_size() const { return _obj_size; } 1.61 inline jlong obj_tag() const { return _obj_tag; } 1.62 - inline klassOop klass() const { return _klass; } 1.63 inline jlong klass_tag() const { return _klass_tag; } 1.64 }; 1.65 1.66 @@ -686,8 +668,7 @@ 1.67 _referrer_klass_tag = klass_tag(); 1.68 _referrer_tag_p = obj_tag_p(); 1.69 } else { 1.70 - // for Classes the klassOop is tagged 1.71 - _referrer = klassOop_if_java_lang_Class(referrer); 1.72 + _referrer = referrer; 1.73 // record the context 1.74 _referrer_hashmap = tag_map->hashmap(); 1.75 _referrer_entry = _referrer_hashmap->find(_referrer); 1.76 @@ -697,10 +678,7 @@ 1.77 _referrer_tag_p = &_referrer_obj_tag; 1.78 1.79 // get referrer class tag. 1.80 - klassOop k = (_referrer == referrer) ? // Check if referrer is a class... 1.81 - _referrer->klass() // No, just get its class 1.82 - : SystemDictionary::Class_klass(); // Yes, its class is Class 1.83 - _referrer_klass_tag = tag_for(tag_map, k); 1.84 + _referrer_klass_tag = tag_for(tag_map, _referrer->klass()->java_mirror()); 1.85 } 1.86 } 1.87 1.88 @@ -732,9 +710,6 @@ 1.89 // resolve the object 1.90 oop o = JNIHandles::resolve_non_null(object); 1.91 1.92 - // for Classes we tag the klassOop 1.93 - o = klassOop_if_java_lang_Class(o); 1.94 - 1.95 // see if the object is already tagged 1.96 JvmtiTagHashmap* hashmap = _hashmap; 1.97 JvmtiTagHashmapEntry* entry = hashmap->find(o); 1.98 @@ -767,8 +742,7 @@ 1.99 // resolve the object 1.100 oop o = JNIHandles::resolve_non_null(object); 1.101 1.102 - // for Classes get the tag from the klassOop 1.103 - return tag_for(this, klassOop_if_java_lang_Class(o)); 1.104 + return tag_for(this, o); 1.105 } 1.106 1.107 1.108 @@ -816,7 +790,7 @@ 1.109 ClassFieldDescriptor* field_at(int i) { return _fields->at(i); } 1.110 1.111 // functions to create maps of static or instance fields 1.112 - static ClassFieldMap* create_map_of_static_fields(klassOop k); 1.113 + static ClassFieldMap* create_map_of_static_fields(Klass* k); 1.114 static ClassFieldMap* create_map_of_instance_fields(oop obj); 1.115 }; 1.116 1.117 @@ -840,7 +814,7 @@ 1.118 // Returns a heap allocated ClassFieldMap to describe the static fields 1.119 // of the given class. 1.120 // 1.121 -ClassFieldMap* ClassFieldMap::create_map_of_static_fields(klassOop k) { 1.122 +ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) { 1.123 HandleMark hm; 1.124 instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k); 1.125 1.126 @@ -889,7 +863,7 @@ 1.127 } 1.128 1.129 // Helper class used to cache a ClassFileMap for the instance fields of 1.130 -// a cache. A JvmtiCachedClassFieldMap can be cached by an instanceKlass during 1.131 +// a cache. A JvmtiCachedClassFieldMap can be cached by an InstanceKlass during 1.132 // heap iteration and avoid creating a field map for each object in the heap 1.133 // (only need to create the map when the first instance of a class is encountered). 1.134 // 1.135 @@ -905,12 +879,12 @@ 1.136 JvmtiCachedClassFieldMap(ClassFieldMap* field_map); 1.137 ~JvmtiCachedClassFieldMap(); 1.138 1.139 - static GrowableArray<instanceKlass*>* _class_list; 1.140 - static void add_to_class_list(instanceKlass* ik); 1.141 + static GrowableArray<InstanceKlass*>* _class_list; 1.142 + static void add_to_class_list(InstanceKlass* ik); 1.143 1.144 public: 1.145 // returns the field map for a given object (returning map cached 1.146 - // by instanceKlass if possible 1.147 + // by InstanceKlass if possible 1.148 static ClassFieldMap* get_map_of_instance_fields(oop obj); 1.149 1.150 // removes the field map from all instanceKlasses - should be 1.151 @@ -921,7 +895,7 @@ 1.152 static int cached_field_map_count(); 1.153 }; 1.154 1.155 -GrowableArray<instanceKlass*>* JvmtiCachedClassFieldMap::_class_list; 1.156 +GrowableArray<InstanceKlass*>* JvmtiCachedClassFieldMap::_class_list; 1.157 1.158 JvmtiCachedClassFieldMap::JvmtiCachedClassFieldMap(ClassFieldMap* field_map) { 1.159 _field_map = field_map; 1.160 @@ -955,23 +929,23 @@ 1.161 bool ClassFieldMapCacheMark::_is_active; 1.162 1.163 1.164 -// record that the given instanceKlass is caching a field map 1.165 -void JvmtiCachedClassFieldMap::add_to_class_list(instanceKlass* ik) { 1.166 +// record that the given InstanceKlass is caching a field map 1.167 +void JvmtiCachedClassFieldMap::add_to_class_list(InstanceKlass* ik) { 1.168 if (_class_list == NULL) { 1.169 _class_list = new (ResourceObj::C_HEAP, mtInternal) 1.170 - GrowableArray<instanceKlass*>(initial_class_count, true); 1.171 + GrowableArray<InstanceKlass*>(initial_class_count, true); 1.172 } 1.173 _class_list->push(ik); 1.174 } 1.175 1.176 // returns the instance field map for the given object 1.177 -// (returns field map cached by the instanceKlass if possible) 1.178 +// (returns field map cached by the InstanceKlass if possible) 1.179 ClassFieldMap* JvmtiCachedClassFieldMap::get_map_of_instance_fields(oop obj) { 1.180 assert(Thread::current()->is_VM_thread(), "must be VMThread"); 1.181 assert(ClassFieldMapCacheMark::is_active(), "ClassFieldMapCacheMark not active"); 1.182 1.183 - klassOop k = obj->klass(); 1.184 - instanceKlass* ik = instanceKlass::cast(k); 1.185 + Klass* k = obj->klass(); 1.186 + InstanceKlass* ik = InstanceKlass::cast(k); 1.187 1.188 // return cached map if possible 1.189 JvmtiCachedClassFieldMap* cached_map = ik->jvmti_cached_class_field_map(); 1.190 @@ -992,7 +966,7 @@ 1.191 assert(Thread::current()->is_VM_thread(), "must be VMThread"); 1.192 if (_class_list != NULL) { 1.193 for (int i = 0; i < _class_list->length(); i++) { 1.194 - instanceKlass* ik = _class_list->at(i); 1.195 + InstanceKlass* ik = _class_list->at(i); 1.196 JvmtiCachedClassFieldMap* cached_map = ik->jvmti_cached_class_field_map(); 1.197 assert(cached_map != NULL, "should not be NULL"); 1.198 ik->set_jvmti_cached_class_field_map(NULL); 1.199 @@ -1131,8 +1105,7 @@ 1.200 if (java_lang_Class::is_primitive(obj)) { 1.201 return 0; 1.202 } 1.203 - klassOop k = java_lang_Class::as_klassOop(obj); 1.204 - Klass* klass = k->klass_part(); 1.205 + Klass* klass = java_lang_Class::as_Klass(obj); 1.206 1.207 // ignore classes for object and type arrays 1.208 if (!klass->oop_is_instance()) { 1.209 @@ -1140,13 +1113,13 @@ 1.210 } 1.211 1.212 // ignore classes which aren't linked yet 1.213 - instanceKlass* ik = instanceKlass::cast(k); 1.214 + InstanceKlass* ik = InstanceKlass::cast(klass); 1.215 if (!ik->is_linked()) { 1.216 return 0; 1.217 } 1.218 1.219 // get the field map 1.220 - ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(k); 1.221 + ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(klass); 1.222 1.223 // invoke the callback for each static primitive field 1.224 for (int i=0; i<field_map->field_count(); i++) { 1.225 @@ -1162,7 +1135,7 @@ 1.226 1.227 // get offset and field value 1.228 int offset = field->field_offset(); 1.229 - address addr = (address)k + offset; 1.230 + address addr = (address)klass + offset; 1.231 jvalue value; 1.232 copy_to_jvalue(&value, addr, value_type); 1.233 1.234 @@ -1265,14 +1238,6 @@ 1.235 // consider using safe_object_iterate() which avoids perm gen 1.236 // objects that may contain bad references. 1.237 Universe::heap()->object_iterate(_blk); 1.238 - 1.239 - // when sharing is enabled we must iterate over the shared spaces 1.240 - if (UseSharedSpaces) { 1.241 - GenCollectedHeap* gch = GenCollectedHeap::heap(); 1.242 - CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen(); 1.243 - gen->ro_space()->object_iterate(_blk); 1.244 - gen->rw_space()->object_iterate(_blk); 1.245 - } 1.246 } 1.247 1.248 }; 1.249 @@ -1545,14 +1510,7 @@ 1.250 for (int i=0; i<_tag_count; i++) { 1.251 if (_tags[i] == entry->tag()) { 1.252 oop o = entry->object(); 1.253 - assert(o != NULL, "sanity check"); 1.254 - 1.255 - // the mirror is tagged 1.256 - if (o->is_klass()) { 1.257 - klassOop k = (klassOop)o; 1.258 - o = Klass::cast(k)->java_mirror(); 1.259 - } 1.260 - 1.261 + assert(o != NULL && Universe::heap()->is_in_reserved(o), "sanity check"); 1.262 jobject ref = JNIHandles::make_local(JavaThread::current(), o); 1.263 _object_results->append(ref); 1.264 _tag_results->append((uint64_t)entry->tag()); 1.265 @@ -1695,14 +1653,6 @@ 1.266 set_needs_reset(true); 1.267 } 1.268 1.269 - // When sharing is enabled we need to restore the headers of the objects 1.270 - // in the readwrite space too. 1.271 - if (UseSharedSpaces) { 1.272 - GenCollectedHeap* gch = GenCollectedHeap::heap(); 1.273 - CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen(); 1.274 - gen->rw_space()->object_iterate(&blk); 1.275 - } 1.276 - 1.277 // now restore the interesting headers 1.278 for (int i = 0; i < _saved_oop_stack->length(); i++) { 1.279 oop o = _saved_oop_stack->at(i); 1.280 @@ -2069,7 +2019,7 @@ 1.281 if (referrer == context->last_referrer()) { 1.282 referrer_tag = context->last_referrer_tag(); 1.283 } else { 1.284 - referrer_tag = tag_for(tag_map(), klassOop_if_java_lang_Class(referrer)); 1.285 + referrer_tag = tag_for(tag_map(), referrer); 1.286 } 1.287 1.288 // do the callback 1.289 @@ -2604,24 +2554,13 @@ 1.290 1.291 jvmtiHeapReferenceKind kind = root_kind(); 1.292 1.293 - // many roots are Klasses so we use the java mirror 1.294 - if (o->is_klass()) { 1.295 - klassOop k = (klassOop)o; 1.296 - o = Klass::cast(k)->java_mirror(); 1.297 - if (o == NULL) { 1.298 - // Classes without mirrors don't correspond to real Java 1.299 - // classes so just ignore them. 1.300 - return; 1.301 - } 1.302 - } else { 1.303 - 1.304 + assert(Universe::heap()->is_in_reserved(o), "should be impossible"); 1.305 // SystemDictionary::always_strong_oops_do reports the application 1.306 // class loader as a root. We want this root to be reported as 1.307 // a root kind of "OTHER" rather than "SYSTEM_CLASS". 1.308 if (o->is_instance() && root_kind() == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) { 1.309 kind = JVMTI_HEAP_REFERENCE_OTHER; 1.310 } 1.311 - } 1.312 1.313 // some objects are ignored - in the case of simple 1.314 // roots it's mostly Symbol*s that we are skipping 1.315 @@ -2733,7 +2672,7 @@ 1.316 // iterate over the various object types 1.317 inline bool iterate_over_array(oop o); 1.318 inline bool iterate_over_type_array(oop o); 1.319 - inline bool iterate_over_class(klassOop o); 1.320 + inline bool iterate_over_class(oop o); 1.321 inline bool iterate_over_object(oop o); 1.322 1.323 // root collection 1.324 @@ -2807,10 +2746,6 @@ 1.325 // each element in the array 1.326 inline bool VM_HeapWalkOperation::iterate_over_array(oop o) { 1.327 objArrayOop array = objArrayOop(o); 1.328 - if (array->klass() == Universe::systemObjArrayKlassObj()) { 1.329 - // filtered out 1.330 - return true; 1.331 - } 1.332 1.333 // array reference to its class 1.334 oop mirror = objArrayKlass::cast(array->klass())->java_mirror(); 1.335 @@ -2836,7 +2771,7 @@ 1.336 1.337 // a type array references its class 1.338 inline bool VM_HeapWalkOperation::iterate_over_type_array(oop o) { 1.339 - klassOop k = o->klass(); 1.340 + Klass* k = o->klass(); 1.341 oop mirror = Klass::cast(k)->java_mirror(); 1.342 if (!CallbackInvoker::report_class_reference(o, mirror)) { 1.343 return false; 1.344 @@ -2852,7 +2787,7 @@ 1.345 } 1.346 1.347 // verify that a static oop field is in range 1.348 -static inline bool verify_static_oop(instanceKlass* ik, 1.349 +static inline bool verify_static_oop(InstanceKlass* ik, 1.350 oop mirror, int offset) { 1.351 address obj_p = (address)mirror + offset; 1.352 address start = (address)instanceMirrorKlass::start_of_static_fields(mirror); 1.353 @@ -2868,12 +2803,12 @@ 1.354 1.355 // a class references its super class, interfaces, class loader, ... 1.356 // and finally its static fields 1.357 -inline bool VM_HeapWalkOperation::iterate_over_class(klassOop k) { 1.358 +inline bool VM_HeapWalkOperation::iterate_over_class(oop java_class) { 1.359 int i; 1.360 - Klass* klass = klassOop(k)->klass_part(); 1.361 + Klass* klass = java_lang_Class::as_Klass(java_class); 1.362 1.363 if (klass->oop_is_instance()) { 1.364 - instanceKlass* ik = instanceKlass::cast(k); 1.365 + InstanceKlass* ik = InstanceKlass::cast(klass); 1.366 1.367 // ignore the class if it's has been initialized yet 1.368 if (!ik->is_linked()) { 1.369 @@ -2884,7 +2819,7 @@ 1.370 oop mirror = klass->java_mirror(); 1.371 1.372 // super (only if something more interesting than java.lang.Object) 1.373 - klassOop java_super = ik->java_super(); 1.374 + Klass* java_super = ik->java_super(); 1.375 if (java_super != NULL && java_super != SystemDictionary::Object_klass()) { 1.376 oop super = Klass::cast(java_super)->java_mirror(); 1.377 if (!CallbackInvoker::report_superclass_reference(mirror, super)) { 1.378 @@ -2918,13 +2853,15 @@ 1.379 1.380 // references from the constant pool 1.381 { 1.382 - const constantPoolOop pool = ik->constants(); 1.383 + ConstantPool* const pool = ik->constants(); 1.384 for (int i = 1; i < pool->length(); i++) { 1.385 constantTag tag = pool->tag_at(i).value(); 1.386 if (tag.is_string() || tag.is_klass()) { 1.387 oop entry; 1.388 if (tag.is_string()) { 1.389 entry = pool->resolved_string_at(i); 1.390 + // If the entry is non-null it it resolved. 1.391 + if (entry == NULL) continue; 1.392 assert(java_lang_String::is_instance(entry), "must be string"); 1.393 } else { 1.394 entry = Klass::cast(pool->resolved_klass_at(i))->java_mirror(); 1.395 @@ -2939,9 +2876,9 @@ 1.396 // interfaces 1.397 // (These will already have been reported as references from the constant pool 1.398 // but are specified by IterateOverReachableObjects and must be reported). 1.399 - objArrayOop interfaces = ik->local_interfaces(); 1.400 + Array<Klass*>* interfaces = ik->local_interfaces(); 1.401 for (i = 0; i < interfaces->length(); i++) { 1.402 - oop interf = Klass::cast((klassOop)interfaces->obj_at(i))->java_mirror(); 1.403 + oop interf = Klass::cast((Klass*)interfaces->at(i))->java_mirror(); 1.404 if (interf == NULL) { 1.405 continue; 1.406 } 1.407 @@ -2952,7 +2889,7 @@ 1.408 1.409 // iterate over the static fields 1.410 1.411 - ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(k); 1.412 + ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(klass); 1.413 for (i=0; i<field_map->field_count(); i++) { 1.414 ClassFieldDescriptor* field = field_map->field_at(i); 1.415 char type = field->field_type(); 1.416 @@ -3003,12 +2940,8 @@ 1.417 oop fld_o = o->obj_field(field->field_offset()); 1.418 // ignore any objects that aren't visible to profiler 1.419 if (fld_o != NULL && ServiceUtil::visible_oop(fld_o)) { 1.420 - // reflection code may have a reference to a klassOop. 1.421 - // - see sun.reflect.UnsafeStaticFieldAccessorImpl and sun.misc.Unsafe 1.422 - if (fld_o->is_klass()) { 1.423 - klassOop k = (klassOop)fld_o; 1.424 - fld_o = Klass::cast(k)->java_mirror(); 1.425 - } 1.426 + assert(Universe::heap()->is_in_reserved(fld_o), "unsafe code should not " 1.427 + "have references to Klass* anymore"); 1.428 int slot = field->field_index(); 1.429 if (!CallbackInvoker::report_field_reference(o, fld_o, slot)) { 1.430 return false; 1.431 @@ -3058,6 +2991,7 @@ 1.432 // Preloaded classes and loader from the system dictionary 1.433 blk.set_kind(JVMTI_HEAP_REFERENCE_SYSTEM_CLASS); 1.434 SystemDictionary::always_strong_oops_do(&blk); 1.435 + ClassLoaderDataGraph::always_strong_oops_do(&blk, NULL, false); 1.436 if (blk.stopped()) { 1.437 return false; 1.438 } 1.439 @@ -3213,10 +3147,9 @@ 1.440 // instance 1.441 if (o->is_instance()) { 1.442 if (o->klass() == SystemDictionary::Class_klass()) { 1.443 - o = klassOop_if_java_lang_Class(o); 1.444 - if (o->is_klass()) { 1.445 + if (!java_lang_Class::is_primitive(o)) { 1.446 // a java.lang.Class 1.447 - return iterate_over_class(klassOop(o)); 1.448 + return iterate_over_class(o); 1.449 } 1.450 } else { 1.451 return iterate_over_object(o);