156 for (int i = 0; i < _class_count; i++) { |
156 for (int i = 0; i < _class_count; i++) { |
157 if (_scratch_classes[i] != NULL) { |
157 if (_scratch_classes[i] != NULL) { |
158 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data(); |
158 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data(); |
159 // Free the memory for this class at class unloading time. Not before |
159 // Free the memory for this class at class unloading time. Not before |
160 // because CMS might think this is still live. |
160 // because CMS might think this is still live. |
|
161 InstanceKlass* ik = get_ik(_class_defs[i].klass); |
|
162 if (ik->get_cached_class_file() == _scratch_classes[i]->get_cached_class_file()) { |
|
163 // Don't double-free cached_class_file copied from the original class if error. |
|
164 _scratch_classes[i]->set_cached_class_file(NULL); |
|
165 } |
161 cld->add_to_deallocate_list(InstanceKlass::cast(_scratch_classes[i])); |
166 cld->add_to_deallocate_list(InstanceKlass::cast(_scratch_classes[i])); |
162 } |
167 } |
163 } |
168 } |
164 // Free os::malloc allocated memory in load_new_class_version. |
169 // Free os::malloc allocated memory in load_new_class_version. |
165 os::free(_scratch_classes); |
170 os::free(_scratch_classes); |
3944 |
3949 |
3945 // The class file bytes from before any retransformable agents mucked |
3950 // The class file bytes from before any retransformable agents mucked |
3946 // with them was cached on the scratch class, move to the_class. |
3951 // with them was cached on the scratch class, move to the_class. |
3947 // Note: we still want to do this if nothing needed caching since it |
3952 // Note: we still want to do this if nothing needed caching since it |
3948 // should get cleared in the_class too. |
3953 // should get cleared in the_class too. |
3949 if (the_class->get_cached_class_file_bytes() == 0) { |
3954 if (the_class->get_cached_class_file() == 0) { |
3950 // the_class doesn't have a cache yet so copy it |
3955 // the_class doesn't have a cache yet so copy it |
3951 the_class->set_cached_class_file(scratch_class->get_cached_class_file()); |
3956 the_class->set_cached_class_file(scratch_class->get_cached_class_file()); |
3952 } |
3957 } |
3953 else if (scratch_class->get_cached_class_file_bytes() != |
3958 else if (scratch_class->get_cached_class_file() != |
3954 the_class->get_cached_class_file_bytes()) { |
3959 the_class->get_cached_class_file()) { |
3955 // The same class can be present twice in the scratch classes list or there |
3960 // The same class can be present twice in the scratch classes list or there |
3956 // are multiple concurrent RetransformClasses calls on different threads. |
3961 // are multiple concurrent RetransformClasses calls on different threads. |
3957 // In such cases we have to deallocate scratch_class cached_class_file. |
3962 // In such cases we have to deallocate scratch_class cached_class_file. |
3958 os::free(scratch_class->get_cached_class_file()); |
3963 os::free(scratch_class->get_cached_class_file()); |
3959 } |
3964 } |