149 for (int i = 0; i < _class_count; i++) { |
149 for (int i = 0; i < _class_count; i++) { |
150 if (_scratch_classes[i] != NULL) { |
150 if (_scratch_classes[i] != NULL) { |
151 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data(); |
151 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data(); |
152 // Free the memory for this class at class unloading time. Not before |
152 // Free the memory for this class at class unloading time. Not before |
153 // because CMS might think this is still live. |
153 // because CMS might think this is still live. |
|
154 InstanceKlass* ik = get_ik(_class_defs[i].klass); |
|
155 if (ik->get_cached_class_file() == ((InstanceKlass*)_scratch_classes[i])->get_cached_class_file()) { |
|
156 // Don't double-free cached_class_file copied from the original class if error. |
|
157 ((InstanceKlass*)_scratch_classes[i])->set_cached_class_file(NULL); |
|
158 } |
154 cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]); |
159 cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]); |
155 } |
160 } |
156 } |
161 } |
157 // Free os::malloc allocated memory in load_new_class_version. |
162 // Free os::malloc allocated memory in load_new_class_version. |
158 os::free(_scratch_classes); |
163 os::free(_scratch_classes); |
4017 |
4022 |
4018 // The class file bytes from before any retransformable agents mucked |
4023 // The class file bytes from before any retransformable agents mucked |
4019 // with them was cached on the scratch class, move to the_class. |
4024 // with them was cached on the scratch class, move to the_class. |
4020 // Note: we still want to do this if nothing needed caching since it |
4025 // Note: we still want to do this if nothing needed caching since it |
4021 // should get cleared in the_class too. |
4026 // should get cleared in the_class too. |
4022 if (the_class->get_cached_class_file_bytes() == 0) { |
4027 if (the_class->get_cached_class_file() == 0) { |
4023 // the_class doesn't have a cache yet so copy it |
4028 // the_class doesn't have a cache yet so copy it |
4024 the_class->set_cached_class_file(scratch_class->get_cached_class_file()); |
4029 the_class->set_cached_class_file(scratch_class->get_cached_class_file()); |
4025 } |
4030 } |
4026 else if (scratch_class->get_cached_class_file_bytes() != |
4031 else if (scratch_class->get_cached_class_file() != |
4027 the_class->get_cached_class_file_bytes()) { |
4032 the_class->get_cached_class_file()) { |
4028 // The same class can be present twice in the scratch classes list or there |
4033 // The same class can be present twice in the scratch classes list or there |
4029 // are multiple concurrent RetransformClasses calls on different threads. |
4034 // are multiple concurrent RetransformClasses calls on different threads. |
4030 // In such cases we have to deallocate scratch_class cached_class_file. |
4035 // In such cases we have to deallocate scratch_class cached_class_file. |
4031 os::free(scratch_class->get_cached_class_file()); |
4036 os::free(scratch_class->get_cached_class_file()); |
4032 } |
4037 } |