comparison src/share/vm/prims/jvmtiRedefineClasses.cpp @ 4731:4ceaf61479fc

7122253: Instrumentation.retransformClasses() leaks class bytes Summary: Change ClassFileParser::parseClassFile() to use the instanceKlass:_cached_class_file_bytes field to avoid leaking the cache. Reviewed-by: coleenp, acorn, poonam
author dcubed
date Thu, 22 Dec 2011 12:50:42 -0800
parents e6b1331a51d2
children f7c4174b33ba
comparison
equal deleted inserted replaced
4719:d532160c55f7 4731:4ceaf61479fc
852 instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop); 852 instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
853 Symbol* the_class_sym = the_class->name(); 853 Symbol* the_class_sym = the_class->name();
854 854
855 // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark 855 // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
856 RC_TRACE_WITH_THREAD(0x00000001, THREAD, 856 RC_TRACE_WITH_THREAD(0x00000001, THREAD,
857 ("loading name=%s (avail_mem=" UINT64_FORMAT "K)", 857 ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
858 the_class->external_name(), os::available_memory() >> 10)); 858 the_class->external_name(), _class_load_kind,
859 os::available_memory() >> 10));
859 860
860 ClassFileStream st((u1*) _class_defs[i].class_bytes, 861 ClassFileStream st((u1*) _class_defs[i].class_bytes,
861 _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__"); 862 _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
862 863
863 // Parse the stream. 864 // Parse the stream.
3203 3204
3204 // The class file bytes from before any retransformable agents mucked 3205 // The class file bytes from before any retransformable agents mucked
3205 // with them was cached on the scratch class, move to the_class. 3206 // with them was cached on the scratch class, move to the_class.
3206 // Note: we still want to do this if nothing needed caching since it 3207 // Note: we still want to do this if nothing needed caching since it
3207 // should get cleared in the_class too. 3208 // should get cleared in the_class too.
3208 the_class->set_cached_class_file(scratch_class->get_cached_class_file_bytes(), 3209 if (the_class->get_cached_class_file_bytes() == 0) {
3209 scratch_class->get_cached_class_file_len()); 3210 // the_class doesn't have a cache yet so copy it
3211 the_class->set_cached_class_file(
3212 scratch_class->get_cached_class_file_bytes(),
3213 scratch_class->get_cached_class_file_len());
3214 }
3215 #ifndef PRODUCT
3216 else {
3217 assert(the_class->get_cached_class_file_bytes() ==
3218 scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
3219 assert(the_class->get_cached_class_file_len() ==
3220 scratch_class->get_cached_class_file_len(), "cache lens must match");
3221 }
3222 #endif
3210 3223
3211 // Replace inner_classes 3224 // Replace inner_classes
3212 typeArrayOop old_inner_classes = the_class->inner_classes(); 3225 typeArrayOop old_inner_classes = the_class->inner_classes();
3213 the_class->set_inner_classes(scratch_class->inner_classes()); 3226 the_class->set_inner_classes(scratch_class->inner_classes());
3214 scratch_class->set_inner_classes(old_inner_classes); 3227 scratch_class->set_inner_classes(old_inner_classes);