< prev index next >

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

Print this page

 595       if (scratch_i != *merge_cp_length_p) {
 596         // The new entry in *merge_cp_p is at a different index than
 597         // the new entry in scratch_cp so we need to map the index values.
 598         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 599       }
 600       (*merge_cp_length_p)++;
 601     } break;
 602 
 603     // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
 604     // ClassIndex
 605     case JVM_CONSTANT_ClassIndex: // fall through
 606 
 607     // Invalid is used as the tag for the second constant pool entry
 608     // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
 609     // not be seen by itself.
 610     case JVM_CONSTANT_Invalid: // fall through
 611 
 612     // At this stage, String could be here, but not StringIndex
 613     case JVM_CONSTANT_StringIndex: // fall through
 614 
 615     // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
 616     // here
 617     case JVM_CONSTANT_UnresolvedClassInError: // fall through
 618 
 619     default:
 620     {
 621       // leave a breadcrumb
 622       jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
 623       ShouldNotReachHere();
 624     } break;
 625   } // end switch tag value
 626 } // end append_entry()
 627 
 628 
 629 u2 VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
 630       int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p) {
 631 
 632   int new_ref_i = ref_i;
 633   bool match = (ref_i < *merge_cp_length_p) &&
 634                scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i);
 635 
 636   if (!match) {

1921 bool VM_RedefineClasses::rewrite_cp_refs(InstanceKlass* scratch_class) {
1922 
1923   // rewrite constant pool references in the nest attributes:
1924   if (!rewrite_cp_refs_in_nest_attributes(scratch_class)) {
1925     // propagate failure back to caller
1926     return false;
1927   }
1928 
1929   // rewrite constant pool references in the Record attribute:
1930   if (!rewrite_cp_refs_in_record_attribute(scratch_class)) {
1931     // propagate failure back to caller
1932     return false;
1933   }
1934 
1935   // rewrite constant pool references in the PermittedSubclasses attribute:
1936   if (!rewrite_cp_refs_in_permitted_subclasses_attribute(scratch_class)) {
1937     // propagate failure back to caller
1938     return false;
1939   }
1940 






1941   // rewrite constant pool references in the methods:
1942   if (!rewrite_cp_refs_in_methods(scratch_class)) {
1943     // propagate failure back to caller
1944     return false;
1945   }
1946 
1947   // rewrite constant pool references in the class_annotations:
1948   if (!rewrite_cp_refs_in_class_annotations(scratch_class)) {
1949     // propagate failure back to caller
1950     return false;
1951   }
1952 
1953   // rewrite constant pool references in the fields_annotations:
1954   if (!rewrite_cp_refs_in_fields_annotations(scratch_class)) {
1955     // propagate failure back to caller
1956     return false;
1957   }
1958 
1959   // rewrite constant pool references in the methods_annotations:
1960   if (!rewrite_cp_refs_in_methods_annotations(scratch_class)) {

2069         }
2070       }
2071     }
2072   }
2073   return true;
2074 }
2075 
2076 // Rewrite constant pool references in the PermittedSubclasses attribute.
2077 bool VM_RedefineClasses::rewrite_cp_refs_in_permitted_subclasses_attribute(
2078        InstanceKlass* scratch_class) {
2079 
2080   Array<u2>* permitted_subclasses = scratch_class->permitted_subclasses();
2081   assert(permitted_subclasses != nullptr, "unexpected null permitted_subclasses");
2082   for (int i = 0; i < permitted_subclasses->length(); i++) {
2083     u2 cp_index = permitted_subclasses->at(i);
2084     permitted_subclasses->at_put(i, find_new_index(cp_index));
2085   }
2086   return true;
2087 }
2088 













2089 // Rewrite constant pool references in the methods.
2090 bool VM_RedefineClasses::rewrite_cp_refs_in_methods(InstanceKlass* scratch_class) {
2091 
2092   Array<Method*>* methods = scratch_class->methods();
2093 
2094   if (methods == nullptr || methods->length() == 0) {
2095     // no methods so nothing to do
2096     return true;
2097   }
2098 
2099   JavaThread* THREAD = JavaThread::current(); // For exception macros.
2100   ExceptionMark em(THREAD);
2101 
2102   // rewrite constant pool references in the methods:
2103   for (int i = methods->length() - 1; i >= 0; i--) {
2104     methodHandle method(THREAD, methods->at(i));
2105     methodHandle new_method;
2106     rewrite_cp_refs_in_method(method, &new_method, THREAD);
2107     if (!new_method.is_null()) {
2108       // the method has been replaced so save the new method version

 595       if (scratch_i != *merge_cp_length_p) {
 596         // The new entry in *merge_cp_p is at a different index than
 597         // the new entry in scratch_cp so we need to map the index values.
 598         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 599       }
 600       (*merge_cp_length_p)++;
 601     } break;
 602 
 603     // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
 604     // ClassIndex
 605     case JVM_CONSTANT_ClassIndex: // fall through
 606 
 607     // Invalid is used as the tag for the second constant pool entry
 608     // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
 609     // not be seen by itself.
 610     case JVM_CONSTANT_Invalid: // fall through
 611 
 612     // At this stage, String could be here, but not StringIndex
 613     case JVM_CONSTANT_StringIndex: // fall through
 614 
 615     // At this stage JVM_CONSTANT_UnresolvedClassInError should not be 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) {

1920 bool VM_RedefineClasses::rewrite_cp_refs(InstanceKlass* scratch_class) {
1921 
1922   // rewrite constant pool references in the nest attributes:
1923   if (!rewrite_cp_refs_in_nest_attributes(scratch_class)) {
1924     // propagate failure back to caller
1925     return false;
1926   }
1927 
1928   // rewrite constant pool references in the Record attribute:
1929   if (!rewrite_cp_refs_in_record_attribute(scratch_class)) {
1930     // propagate failure back to caller
1931     return false;
1932   }
1933 
1934   // rewrite constant pool references in the PermittedSubclasses attribute:
1935   if (!rewrite_cp_refs_in_permitted_subclasses_attribute(scratch_class)) {
1936     // propagate failure back to caller
1937     return false;
1938   }
1939 
1940   // rewrite constant pool references in the LoadableDescriptors attribute:
1941   if (!rewrite_cp_refs_in_loadable_descriptors_attribute(scratch_class)) {
1942     // propagate failure back to caller
1943     return false;
1944   }
1945 
1946   // rewrite constant pool references in the methods:
1947   if (!rewrite_cp_refs_in_methods(scratch_class)) {
1948     // propagate failure back to caller
1949     return false;
1950   }
1951 
1952   // rewrite constant pool references in the class_annotations:
1953   if (!rewrite_cp_refs_in_class_annotations(scratch_class)) {
1954     // propagate failure back to caller
1955     return false;
1956   }
1957 
1958   // rewrite constant pool references in the fields_annotations:
1959   if (!rewrite_cp_refs_in_fields_annotations(scratch_class)) {
1960     // propagate failure back to caller
1961     return false;
1962   }
1963 
1964   // rewrite constant pool references in the methods_annotations:
1965   if (!rewrite_cp_refs_in_methods_annotations(scratch_class)) {

2074         }
2075       }
2076     }
2077   }
2078   return true;
2079 }
2080 
2081 // Rewrite constant pool references in the PermittedSubclasses attribute.
2082 bool VM_RedefineClasses::rewrite_cp_refs_in_permitted_subclasses_attribute(
2083        InstanceKlass* scratch_class) {
2084 
2085   Array<u2>* permitted_subclasses = scratch_class->permitted_subclasses();
2086   assert(permitted_subclasses != nullptr, "unexpected null permitted_subclasses");
2087   for (int i = 0; i < permitted_subclasses->length(); i++) {
2088     u2 cp_index = permitted_subclasses->at(i);
2089     permitted_subclasses->at_put(i, find_new_index(cp_index));
2090   }
2091   return true;
2092 }
2093 
2094 // Rewrite constant pool references in the LoadableDescriptors attribute.
2095 bool VM_RedefineClasses::rewrite_cp_refs_in_loadable_descriptors_attribute(
2096        InstanceKlass* scratch_class) {
2097 
2098   Array<u2>* loadable_descriptors = scratch_class->loadable_descriptors();
2099   assert(loadable_descriptors != nullptr, "unexpected null loadable_descriptors");
2100   for (int i = 0; i < loadable_descriptors->length(); i++) {
2101     u2 cp_index = loadable_descriptors->at(i);
2102     loadable_descriptors->at_put(i, find_new_index(cp_index));
2103   }
2104   return true;
2105 }
2106 
2107 // Rewrite constant pool references in the methods.
2108 bool VM_RedefineClasses::rewrite_cp_refs_in_methods(InstanceKlass* scratch_class) {
2109 
2110   Array<Method*>* methods = scratch_class->methods();
2111 
2112   if (methods == nullptr || methods->length() == 0) {
2113     // no methods so nothing to do
2114     return true;
2115   }
2116 
2117   JavaThread* THREAD = JavaThread::current(); // For exception macros.
2118   ExceptionMark em(THREAD);
2119 
2120   // rewrite constant pool references in the methods:
2121   for (int i = methods->length() - 1; i >= 0; i--) {
2122     methodHandle method(THREAD, methods->at(i));
2123     methodHandle new_method;
2124     rewrite_cp_refs_in_method(method, &new_method, THREAD);
2125     if (!new_method.is_null()) {
2126       // the method has been replaced so save the new method version
< prev index next >