594 if (scratch_i != *merge_cp_length_p) {
595 // The new entry in *merge_cp_p is at a different index than
596 // the new entry in scratch_cp so we need to map the index values.
597 map_index(scratch_cp, scratch_i, *merge_cp_length_p);
598 }
599 (*merge_cp_length_p)++;
600 } break;
601
602 // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
603 // ClassIndex
604 case JVM_CONSTANT_ClassIndex: // fall through
605
606 // Invalid is used as the tag for the second constant pool entry
607 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
608 // not be seen by itself.
609 case JVM_CONSTANT_Invalid: // fall through
610
611 // At this stage, String could be here, but not StringIndex
612 case JVM_CONSTANT_StringIndex: // fall through
613
614 // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
615 // here
616 case JVM_CONSTANT_UnresolvedClassInError: // fall through
617
618 default:
619 {
620 // leave a breadcrumb
621 jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
622 ShouldNotReachHere();
623 } break;
624 } // end switch tag value
625 } // end append_entry()
626
627
628 u2 VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
629 int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p) {
630
631 int new_ref_i = ref_i;
632 bool match = (ref_i < *merge_cp_length_p) &&
633 scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i);
634
635 if (!match) {
1919 bool VM_RedefineClasses::rewrite_cp_refs(InstanceKlass* scratch_class) {
1920
1921 // rewrite constant pool references in the nest attributes:
1922 if (!rewrite_cp_refs_in_nest_attributes(scratch_class)) {
1923 // propagate failure back to caller
1924 return false;
1925 }
1926
1927 // rewrite constant pool references in the Record attribute:
1928 if (!rewrite_cp_refs_in_record_attribute(scratch_class)) {
1929 // propagate failure back to caller
1930 return false;
1931 }
1932
1933 // rewrite constant pool references in the PermittedSubclasses attribute:
1934 if (!rewrite_cp_refs_in_permitted_subclasses_attribute(scratch_class)) {
1935 // propagate failure back to caller
1936 return false;
1937 }
1938
1939 // rewrite constant pool references in the methods:
1940 if (!rewrite_cp_refs_in_methods(scratch_class)) {
1941 // propagate failure back to caller
1942 return false;
1943 }
1944
1945 // rewrite constant pool references in the class_annotations:
1946 if (!rewrite_cp_refs_in_class_annotations(scratch_class)) {
1947 // propagate failure back to caller
1948 return false;
1949 }
1950
1951 // rewrite constant pool references in the fields_annotations:
1952 if (!rewrite_cp_refs_in_fields_annotations(scratch_class)) {
1953 // propagate failure back to caller
1954 return false;
1955 }
1956
1957 // rewrite constant pool references in the methods_annotations:
1958 if (!rewrite_cp_refs_in_methods_annotations(scratch_class)) {
2067 }
2068 }
2069 }
2070 }
2071 return true;
2072 }
2073
2074 // Rewrite constant pool references in the PermittedSubclasses attribute.
2075 bool VM_RedefineClasses::rewrite_cp_refs_in_permitted_subclasses_attribute(
2076 InstanceKlass* scratch_class) {
2077
2078 Array<u2>* permitted_subclasses = scratch_class->permitted_subclasses();
2079 assert(permitted_subclasses != nullptr, "unexpected null permitted_subclasses");
2080 for (int i = 0; i < permitted_subclasses->length(); i++) {
2081 u2 cp_index = permitted_subclasses->at(i);
2082 permitted_subclasses->at_put(i, find_new_index(cp_index));
2083 }
2084 return true;
2085 }
2086
2087 // Rewrite constant pool references in the methods.
2088 bool VM_RedefineClasses::rewrite_cp_refs_in_methods(InstanceKlass* scratch_class) {
2089
2090 Array<Method*>* methods = scratch_class->methods();
2091
2092 if (methods == nullptr || methods->length() == 0) {
2093 // no methods so nothing to do
2094 return true;
2095 }
2096
2097 JavaThread* THREAD = JavaThread::current(); // For exception macros.
2098 ExceptionMark em(THREAD);
2099
2100 // rewrite constant pool references in the methods:
2101 for (int i = methods->length() - 1; i >= 0; i--) {
2102 methodHandle method(THREAD, methods->at(i));
2103 methodHandle new_method;
2104 rewrite_cp_refs_in_method(method, &new_method, THREAD);
2105 if (!new_method.is_null()) {
2106 // the method has been replaced so save the new method version
|
594 if (scratch_i != *merge_cp_length_p) {
595 // The new entry in *merge_cp_p is at a different index than
596 // the new entry in scratch_cp so we need to map the index values.
597 map_index(scratch_cp, scratch_i, *merge_cp_length_p);
598 }
599 (*merge_cp_length_p)++;
600 } break;
601
602 // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
603 // ClassIndex
604 case JVM_CONSTANT_ClassIndex: // fall through
605
606 // Invalid is used as the tag for the second constant pool entry
607 // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
608 // not be seen by itself.
609 case JVM_CONSTANT_Invalid: // fall through
610
611 // At this stage, String could be here, but not StringIndex
612 case JVM_CONSTANT_StringIndex: // fall through
613
614 // At this stage JVM_CONSTANT_UnresolvedClassInError should not be here
615 case JVM_CONSTANT_UnresolvedClassInError: // fall through
616
617 default:
618 {
619 // leave a breadcrumb
620 jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
621 ShouldNotReachHere();
622 } break;
623 } // end switch tag value
624 } // end append_entry()
625
626
627 u2 VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
628 int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p) {
629
630 int new_ref_i = ref_i;
631 bool match = (ref_i < *merge_cp_length_p) &&
632 scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i);
633
634 if (!match) {
1918 bool VM_RedefineClasses::rewrite_cp_refs(InstanceKlass* scratch_class) {
1919
1920 // rewrite constant pool references in the nest attributes:
1921 if (!rewrite_cp_refs_in_nest_attributes(scratch_class)) {
1922 // propagate failure back to caller
1923 return false;
1924 }
1925
1926 // rewrite constant pool references in the Record attribute:
1927 if (!rewrite_cp_refs_in_record_attribute(scratch_class)) {
1928 // propagate failure back to caller
1929 return false;
1930 }
1931
1932 // rewrite constant pool references in the PermittedSubclasses attribute:
1933 if (!rewrite_cp_refs_in_permitted_subclasses_attribute(scratch_class)) {
1934 // propagate failure back to caller
1935 return false;
1936 }
1937
1938 // rewrite constant pool references in the LoadableDescriptors attribute:
1939 if (!rewrite_cp_refs_in_loadable_descriptors_attribute(scratch_class)) {
1940 // propagate failure back to caller
1941 return false;
1942 }
1943
1944 // rewrite constant pool references in the methods:
1945 if (!rewrite_cp_refs_in_methods(scratch_class)) {
1946 // propagate failure back to caller
1947 return false;
1948 }
1949
1950 // rewrite constant pool references in the class_annotations:
1951 if (!rewrite_cp_refs_in_class_annotations(scratch_class)) {
1952 // propagate failure back to caller
1953 return false;
1954 }
1955
1956 // rewrite constant pool references in the fields_annotations:
1957 if (!rewrite_cp_refs_in_fields_annotations(scratch_class)) {
1958 // propagate failure back to caller
1959 return false;
1960 }
1961
1962 // rewrite constant pool references in the methods_annotations:
1963 if (!rewrite_cp_refs_in_methods_annotations(scratch_class)) {
2072 }
2073 }
2074 }
2075 }
2076 return true;
2077 }
2078
2079 // Rewrite constant pool references in the PermittedSubclasses attribute.
2080 bool VM_RedefineClasses::rewrite_cp_refs_in_permitted_subclasses_attribute(
2081 InstanceKlass* scratch_class) {
2082
2083 Array<u2>* permitted_subclasses = scratch_class->permitted_subclasses();
2084 assert(permitted_subclasses != nullptr, "unexpected null permitted_subclasses");
2085 for (int i = 0; i < permitted_subclasses->length(); i++) {
2086 u2 cp_index = permitted_subclasses->at(i);
2087 permitted_subclasses->at_put(i, find_new_index(cp_index));
2088 }
2089 return true;
2090 }
2091
2092 // Rewrite constant pool references in the LoadableDescriptors attribute.
2093 bool VM_RedefineClasses::rewrite_cp_refs_in_loadable_descriptors_attribute(
2094 InstanceKlass* scratch_class) {
2095
2096 Array<u2>* loadable_descriptors = scratch_class->loadable_descriptors();
2097 assert(loadable_descriptors != nullptr, "unexpected null loadable_descriptors");
2098 for (int i = 0; i < loadable_descriptors->length(); i++) {
2099 u2 cp_index = loadable_descriptors->at(i);
2100 loadable_descriptors->at_put(i, find_new_index(cp_index));
2101 }
2102 return true;
2103 }
2104
2105 // Rewrite constant pool references in the methods.
2106 bool VM_RedefineClasses::rewrite_cp_refs_in_methods(InstanceKlass* scratch_class) {
2107
2108 Array<Method*>* methods = scratch_class->methods();
2109
2110 if (methods == nullptr || methods->length() == 0) {
2111 // no methods so nothing to do
2112 return true;
2113 }
2114
2115 JavaThread* THREAD = JavaThread::current(); // For exception macros.
2116 ExceptionMark em(THREAD);
2117
2118 // rewrite constant pool references in the methods:
2119 for (int i = methods->length() - 1; i >= 0; i--) {
2120 methodHandle method(THREAD, methods->at(i));
2121 methodHandle new_method;
2122 rewrite_cp_refs_in_method(method, &new_method, THREAD);
2123 if (!new_method.is_null()) {
2124 // the method has been replaced so save the new method version
|