comparison src/share/vm/classfile/classFileParser.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 05de27e852c4 5b58979183f9
comparison
equal deleted inserted replaced
4719:d532160c55f7 4731:4ceaf61479fc
43 #include "oops/klassOop.hpp" 43 #include "oops/klassOop.hpp"
44 #include "oops/klassVtable.hpp" 44 #include "oops/klassVtable.hpp"
45 #include "oops/methodOop.hpp" 45 #include "oops/methodOop.hpp"
46 #include "oops/symbol.hpp" 46 #include "oops/symbol.hpp"
47 #include "prims/jvmtiExport.hpp" 47 #include "prims/jvmtiExport.hpp"
48 #include "prims/jvmtiThreadState.hpp"
48 #include "runtime/javaCalls.hpp" 49 #include "runtime/javaCalls.hpp"
49 #include "runtime/perfData.hpp" 50 #include "runtime/perfData.hpp"
50 #include "runtime/reflection.hpp" 51 #include "runtime/reflection.hpp"
51 #include "runtime/signature.hpp" 52 #include "runtime/signature.hpp"
52 #include "runtime/timer.hpp" 53 #include "runtime/timer.hpp"
2637 KlassHandle host_klass, 2638 KlassHandle host_klass,
2638 GrowableArray<Handle>* cp_patches, 2639 GrowableArray<Handle>* cp_patches,
2639 TempNewSymbol& parsed_name, 2640 TempNewSymbol& parsed_name,
2640 bool verify, 2641 bool verify,
2641 TRAPS) { 2642 TRAPS) {
2642 // So that JVMTI can cache class file in the state before retransformable agents 2643 // When a retransformable agent is attached, JVMTI caches the
2643 // have modified it 2644 // class bytes that existed before the first retransformation.
2645 // If RedefineClasses() was used before the retransformable
2646 // agent attached, then the cached class bytes may not be the
2647 // original class bytes.
2644 unsigned char *cached_class_file_bytes = NULL; 2648 unsigned char *cached_class_file_bytes = NULL;
2645 jint cached_class_file_length; 2649 jint cached_class_file_length;
2646 2650
2647 ClassFileStream* cfs = stream(); 2651 ClassFileStream* cfs = stream();
2648 // Timing 2652 // Timing
2658 2662
2659 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; 2663 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
2660 _max_bootstrap_specifier_index = -1; 2664 _max_bootstrap_specifier_index = -1;
2661 2665
2662 if (JvmtiExport::should_post_class_file_load_hook()) { 2666 if (JvmtiExport::should_post_class_file_load_hook()) {
2667 // Get the cached class file bytes (if any) from the
2668 // class that is being redefined.
2669 JvmtiThreadState *state = JvmtiThreadState::state_for(jt);
2670 KlassHandle *h_class_being_redefined =
2671 state->get_class_being_redefined();
2672 if (h_class_being_redefined != NULL) {
2673 instanceKlassHandle ikh_class_being_redefined =
2674 instanceKlassHandle(THREAD, (*h_class_being_redefined)());
2675 cached_class_file_bytes =
2676 ikh_class_being_redefined->get_cached_class_file_bytes();
2677 cached_class_file_length =
2678 ikh_class_being_redefined->get_cached_class_file_len();
2679 }
2680
2663 unsigned char* ptr = cfs->buffer(); 2681 unsigned char* ptr = cfs->buffer();
2664 unsigned char* end_ptr = cfs->buffer() + cfs->length(); 2682 unsigned char* end_ptr = cfs->buffer() + cfs->length();
2665 2683
2666 JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain, 2684 JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
2667 &ptr, &end_ptr, 2685 &ptr, &end_ptr,