< prev index next >

src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java

Print this page
rev 16767 : 8175561: Memory churn in jimage code affects startup after resource encapsulation changes
Reviewed-by: jlaskey
rev 16768 : imported patch imgstr_oneup


 130      * ImageStrings to test if strings at an offset match the name region.
 131      */
 132     static boolean verify(String name, final long[] attributes,
 133             final ImageStrings strings) {
 134         Objects.requireNonNull(name);
 135         final int length = name.length();
 136         int index = 0;
 137         int moduleOffset = (int)attributes[ATTRIBUTE_MODULE];
 138         if (moduleOffset != 0) {
 139             String module = strings.get(moduleOffset);
 140             final int moduleLen = module.length();
 141             index = moduleLen + 1;
 142             if (length <= index
 143                     || name.charAt(0) != '/'
 144                     || !name.regionMatches(1, module, 0, moduleLen)
 145                     || name.charAt(index++) != '/') {
 146                 return false;
 147             }
 148         }
 149 
 150         int parentOffset = (int)attributes[ATTRIBUTE_PARENT];




















 151         if (parentOffset != 0) {
 152             String parent = strings.get(parentOffset);
 153             final int parentLen = parent.length();
 154             if (!name.regionMatches(index, parent, 0, parentLen)) {
 155                 return false;
 156             }
 157             index += parentLen;
 158             if (length <= index || name.charAt(index++) != '/') {
 159                 return false;
 160             }
 161         }
 162 
 163         String base = strings.get((int)attributes[ATTRIBUTE_BASE]);
 164         final int baseLen = base.length();
 165         if (!name.regionMatches(index, base, 0, baseLen)) {
 166             return false;
 167         }
 168         index += baseLen;
 169 
 170         int extOffset = (int)attributes[ATTRIBUTE_EXTENSION];
 171         if (extOffset != 0) {
 172             String extension = strings.get(extOffset);
 173             int extLen = extension.length();
 174             if (length <= index
 175                     || name.charAt(index++) != '.'
 176                     || !name.regionMatches(index, extension, 0, extLen)) {
 177                 return false;
 178             }
 179             index += extLen;
 180         }
 181         return length == index;
 182     }
 183 
 184     long getAttribute(int kind) {
 185         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
 186             throw new InternalError(
 187                 "Invalid jimage attribute kind: " + kind);
 188         }
 189 
 190         return attributes[kind];




 130      * ImageStrings to test if strings at an offset match the name region.
 131      */
 132     static boolean verify(String name, final long[] attributes,
 133             final ImageStrings strings) {
 134         Objects.requireNonNull(name);
 135         final int length = name.length();
 136         int index = 0;
 137         int moduleOffset = (int)attributes[ATTRIBUTE_MODULE];
 138         if (moduleOffset != 0) {
 139             String module = strings.get(moduleOffset);
 140             final int moduleLen = module.length();
 141             index = moduleLen + 1;
 142             if (length <= index
 143                     || name.charAt(0) != '/'
 144                     || !name.regionMatches(1, module, 0, moduleLen)
 145                     || name.charAt(index++) != '/') {
 146                 return false;
 147             }
 148         }
 149 
 150         return verifyName(name, index, length, attributes, strings);
 151     }
 152 
 153     static boolean verify(String module, String name,
 154                 final long[] attributes, final ImageStrings strings) {
 155         Objects.requireNonNull(module);
 156         Objects.requireNonNull(name);
 157         int moduleOffset = (int)attributes[ATTRIBUTE_MODULE];
 158         if (moduleOffset != 0) {
 159             if (!module.equals(strings.get(moduleOffset))) {
 160                 return false;
 161             }
 162         }
 163 
 164         return verifyName(name, 0, name.length(), attributes, strings);
 165     }
 166 
 167     private static boolean verifyName(String name, int index, final int length,
 168             final long[] attributes, final ImageStrings strings) {
 169 
 170         int parentOffset = (int) attributes[ATTRIBUTE_PARENT];
 171         if (parentOffset != 0) {
 172             String parent = strings.get(parentOffset);
 173             final int parentLen = parent.length();
 174             if (!name.regionMatches(index, parent, 0, parentLen)) {
 175                 return false;
 176             }
 177             index += parentLen;
 178             if (length <= index || name.charAt(index++) != '/') {
 179                 return false;
 180             }
 181         }
 182         String base = strings.get((int) attributes[ATTRIBUTE_BASE]);

 183         final int baseLen = base.length();
 184         if (!name.regionMatches(index, base, 0, baseLen)) {
 185             return false;
 186         }
 187         index += baseLen;
 188         int extOffset = (int) attributes[ATTRIBUTE_EXTENSION];

 189         if (extOffset != 0) {
 190             String extension = strings.get(extOffset);
 191             int extLen = extension.length();
 192             if (length <= index
 193                     || name.charAt(index++) != '.'
 194                     || !name.regionMatches(index, extension, 0, extLen)) {
 195                 return false;
 196             }
 197             index += extLen;
 198         }
 199         return length == index;
 200     }
 201 
 202     long getAttribute(int kind) {
 203         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
 204             throw new InternalError(
 205                 "Invalid jimage attribute kind: " + kind);
 206         }
 207 
 208         return attributes[kind];


< prev index next >