67 _class_defs = class_defs; |
67 _class_defs = class_defs; |
68 _class_load_kind = class_load_kind; |
68 _class_load_kind = class_load_kind; |
69 _res = JVMTI_ERROR_NONE; |
69 _res = JVMTI_ERROR_NONE; |
70 } |
70 } |
71 |
71 |
|
72 static inline InstanceKlass* get_ik(jclass def) { |
|
73 oop mirror = JNIHandles::resolve_non_null(def); |
|
74 return InstanceKlass::cast(java_lang_Class::as_Klass(mirror)); |
|
75 } |
|
76 |
|
77 // If any of the classes are being redefined, wait |
|
78 // Parallel constant pool merging leads to indeterminate constant pools. |
|
79 void VM_RedefineClasses::lock_classes() { |
|
80 MutexLocker ml(RedefineClasses_lock); |
|
81 bool has_redefined; |
|
82 do { |
|
83 has_redefined = false; |
|
84 // Go through classes each time until none are being redefined. |
|
85 for (int i = 0; i < _class_count; i++) { |
|
86 if (get_ik(_class_defs[i].klass)->is_being_redefined()) { |
|
87 RedefineClasses_lock->wait(); |
|
88 has_redefined = true; |
|
89 break; // for loop |
|
90 } |
|
91 } |
|
92 } while (has_redefined); |
|
93 for (int i = 0; i < _class_count; i++) { |
|
94 get_ik(_class_defs[i].klass)->set_is_being_redefined(true); |
|
95 } |
|
96 RedefineClasses_lock->notify_all(); |
|
97 } |
|
98 |
|
99 void VM_RedefineClasses::unlock_classes() { |
|
100 MutexLocker ml(RedefineClasses_lock); |
|
101 for (int i = 0; i < _class_count; i++) { |
|
102 assert(get_ik(_class_defs[i].klass)->is_being_redefined(), |
|
103 "should be being redefined to get here"); |
|
104 get_ik(_class_defs[i].klass)->set_is_being_redefined(false); |
|
105 } |
|
106 RedefineClasses_lock->notify_all(); |
|
107 } |
|
108 |
72 bool VM_RedefineClasses::doit_prologue() { |
109 bool VM_RedefineClasses::doit_prologue() { |
73 if (_class_count == 0) { |
110 if (_class_count == 0) { |
74 _res = JVMTI_ERROR_NONE; |
111 _res = JVMTI_ERROR_NONE; |
75 return false; |
112 return false; |
76 } |
113 } |
89 } |
126 } |
90 if (_class_defs[i].class_bytes == NULL) { |
127 if (_class_defs[i].class_bytes == NULL) { |
91 _res = JVMTI_ERROR_NULL_POINTER; |
128 _res = JVMTI_ERROR_NULL_POINTER; |
92 return false; |
129 return false; |
93 } |
130 } |
|
131 |
|
132 oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass); |
|
133 // classes for primitives and arrays cannot be redefined |
|
134 // check here so following code can assume these classes are InstanceKlass |
|
135 if (!is_modifiable_class(mirror)) { |
|
136 _res = JVMTI_ERROR_UNMODIFIABLE_CLASS; |
|
137 return false; |
|
138 } |
94 } |
139 } |
95 |
140 |
96 // Start timer after all the sanity checks; not quite accurate, but |
141 // Start timer after all the sanity checks; not quite accurate, but |
97 // better than adding a bunch of stop() calls. |
142 // better than adding a bunch of stop() calls. |
98 if (log_is_enabled(Info, redefine, class, timer)) { |
143 if (log_is_enabled(Info, redefine, class, timer)) { |
99 _timer_vm_op_prologue.start(); |
144 _timer_vm_op_prologue.start(); |
100 } |
145 } |
101 |
146 |
|
147 lock_classes(); |
102 // We first load new class versions in the prologue, because somewhere down the |
148 // We first load new class versions in the prologue, because somewhere down the |
103 // call chain it is required that the current thread is a Java thread. |
149 // call chain it is required that the current thread is a Java thread. |
104 _res = load_new_class_versions(Thread::current()); |
150 _res = load_new_class_versions(Thread::current()); |
105 if (_res != JVMTI_ERROR_NONE) { |
151 if (_res != JVMTI_ERROR_NONE) { |
106 // free any successfully created classes, since none are redefined |
152 // free any successfully created classes, since none are redefined |
172 } |
219 } |
173 #endif |
220 #endif |
174 } |
221 } |
175 |
222 |
176 void VM_RedefineClasses::doit_epilogue() { |
223 void VM_RedefineClasses::doit_epilogue() { |
|
224 unlock_classes(); |
|
225 |
177 // Free os::malloc allocated memory. |
226 // Free os::malloc allocated memory. |
178 os::free(_scratch_classes); |
227 os::free(_scratch_classes); |
179 |
228 |
180 // Reset the_class_oop to null for error printing. |
229 // Reset the_class_oop to null for error printing. |
181 _the_class_oop = NULL; |
230 _the_class_oop = NULL; |
957 for (int i = 0; i < _class_count; i++) { |
1006 for (int i = 0; i < _class_count; i++) { |
958 // Create HandleMark so that any handles created while loading new class |
1007 // Create HandleMark so that any handles created while loading new class |
959 // versions are deleted. Constant pools are deallocated while merging |
1008 // versions are deleted. Constant pools are deallocated while merging |
960 // constant pools |
1009 // constant pools |
961 HandleMark hm(THREAD); |
1010 HandleMark hm(THREAD); |
962 |
1011 instanceKlassHandle the_class(THREAD, get_ik(_class_defs[i].klass)); |
963 oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass); |
|
964 // classes for primitives cannot be redefined |
|
965 if (!is_modifiable_class(mirror)) { |
|
966 return JVMTI_ERROR_UNMODIFIABLE_CLASS; |
|
967 } |
|
968 Klass* the_class_oop = java_lang_Class::as_Klass(mirror); |
|
969 instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop); |
|
970 Symbol* the_class_sym = the_class->name(); |
1012 Symbol* the_class_sym = the_class->name(); |
971 |
1013 |
972 log_debug(redefine, class, load) |
1014 log_debug(redefine, class, load) |
973 ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)", |
1015 ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)", |
974 the_class->external_name(), _class_load_kind, os::available_memory() >> 10); |
1016 the_class->external_name(), _class_load_kind, os::available_memory() >> 10); |
3755 |
3797 |
3756 if (log_is_enabled(Info, redefine, class, timer)) { |
3798 if (log_is_enabled(Info, redefine, class, timer)) { |
3757 _timer_rsc_phase1.start(); |
3799 _timer_rsc_phase1.start(); |
3758 } |
3800 } |
3759 |
3801 |
3760 instanceKlassHandle scratch_class(scratch_class_oop); |
3802 instanceKlassHandle scratch_class(THREAD, scratch_class_oop); |
3761 |
3803 instanceKlassHandle the_class(THREAD, get_ik(the_jclass)); |
3762 oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass); |
|
3763 Klass* the_class_oop = java_lang_Class::as_Klass(the_class_mirror); |
|
3764 instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop); |
|
3765 |
3804 |
3766 // Remove all breakpoints in methods of this class |
3805 // Remove all breakpoints in methods of this class |
3767 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); |
3806 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); |
3768 jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop); |
3807 jvmti_breakpoints.clearall_in_class_at_safepoint(the_class()); |
3769 |
3808 |
3770 // Deoptimize all compiled code that depends on this class |
3809 // Deoptimize all compiled code that depends on this class |
3771 flush_dependent_code(the_class, THREAD); |
3810 flush_dependent_code(the_class, THREAD); |
3772 |
3811 |
3773 _old_methods = the_class->methods(); |
3812 _old_methods = the_class->methods(); |
3774 _new_methods = scratch_class->methods(); |
3813 _new_methods = scratch_class->methods(); |
3775 _the_class_oop = the_class_oop; |
3814 _the_class_oop = the_class(); |
3776 compute_added_deleted_matching_methods(); |
3815 compute_added_deleted_matching_methods(); |
3777 update_jmethod_ids(); |
3816 update_jmethod_ids(); |
3778 |
3817 |
3779 // Attach new constant pool to the original klass. The original |
3818 // Attach new constant pool to the original klass. The original |
3780 // klass still refers to the old constant pool (for now). |
3819 // klass still refers to the old constant pool (for now). |
4000 // increment the classRedefinedCount field in the_class and in any |
4039 // increment the classRedefinedCount field in the_class and in any |
4001 // direct and indirect subclasses of the_class |
4040 // direct and indirect subclasses of the_class |
4002 increment_class_counter((InstanceKlass *)the_class(), THREAD); |
4041 increment_class_counter((InstanceKlass *)the_class(), THREAD); |
4003 log_info(redefine, class, load) |
4042 log_info(redefine, class, load) |
4004 ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)", |
4043 ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)", |
4005 the_class->external_name(), java_lang_Class::classRedefinedCount(the_class_mirror), os::available_memory() >> 10); |
4044 the_class->external_name(), java_lang_Class::classRedefinedCount(the_class->java_mirror()), os::available_memory() >> 10); |
4006 Events::log_redefinition(THREAD, "redefined class name=%s, count=%d", |
4045 Events::log_redefinition(THREAD, "redefined class name=%s, count=%d", |
4007 the_class->external_name(), |
4046 the_class->external_name(), |
4008 java_lang_Class::classRedefinedCount(the_class_mirror)); |
4047 java_lang_Class::classRedefinedCount(the_class->java_mirror())); |
4009 |
4048 |
4010 } |
4049 } |
4011 _timer_rsc_phase2.stop(); |
4050 _timer_rsc_phase2.stop(); |
4012 } // end redefine_single_class() |
4051 } // end redefine_single_class() |
4013 |
4052 |