< prev index next >

src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.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


 232 
 233     public ByteOrder getByteOrder() {
 234         return byteOrder;
 235     }
 236 
 237     public Path getImagePath() {
 238         return imagePath;
 239     }
 240 
 241     @Override
 242     public void close() throws IOException {
 243         if (channel != null) {
 244             channel.close();
 245         }
 246     }
 247 
 248     public ImageStringsReader getStrings() {
 249         return stringsReader;
 250     }
 251 
 252     public ImageLocation findLocation(String mn, String rn) {
 253         Objects.requireNonNull(mn);
 254         Objects.requireNonNull(rn);

















 255 
 256         return findLocation("/" + mn + "/" + rn);



 257     }
 258 
 259     public synchronized ImageLocation findLocation(String name) {
 260         Objects.requireNonNull(name);
 261         // Details of the algorithm used here can be found in
 262         // jdk.tools.jlink.internal.PerfectHashBuilder.
 263         byte[] bytes = ImageStringsReader.mutf8FromString(name);
 264         int count = header.getTableLength();
 265         int index = redirect.get(ImageStringsReader.hashCode(bytes) % count);
 266 
 267         if (index < 0) {
 268             // index is twos complement of location attributes index.
 269             index = -index - 1;
 270         } else if (index > 0) {
 271             // index is hash seed needed to compute location attributes index.
 272             index = ImageStringsReader.hashCode(bytes, index) % count;
 273         } else {
 274             // No entry.
 275             return null;
 276         }
 277 
 278         long[] attributes = getAttributes(offsets.get(index));
 279 
 280         ImageLocation imageLocation = new ImageLocation(attributes, stringsReader);
 281 
 282         if (!imageLocation.verify(name)) {
 283             return null;
 284         }
 285 
 286         return imageLocation;
 287     }
 288 
 289     public String[] getEntryNames() {
 290         int[] attributeOffsets = new int[offsets.capacity()];
 291         offsets.get(attributeOffsets);
 292         return IntStream.of(attributeOffsets)
 293                         .filter(o -> o != 0)
 294                         .mapToObj(o -> ImageLocation.readFrom(this, o).getFullName())
 295                         .sorted()
 296                         .toArray(String[]::new);
 297     }
 298 
 299     ImageLocation getLocation(int offset) {
 300         return ImageLocation.readFrom(this, offset);
 301     }
 302 
 303     public long[] getAttributes(int offset) {
 304         if (offset < 0 || offset >= locations.limit()) {
 305             throw new IndexOutOfBoundsException("offset");
 306         }




 232 
 233     public ByteOrder getByteOrder() {
 234         return byteOrder;
 235     }
 236 
 237     public Path getImagePath() {
 238         return imagePath;
 239     }
 240 
 241     @Override
 242     public void close() throws IOException {
 243         if (channel != null) {
 244             channel.close();
 245         }
 246     }
 247 
 248     public ImageStringsReader getStrings() {
 249         return stringsReader;
 250     }
 251 
 252     public synchronized ImageLocation findLocation(String module, String name) {
 253         Objects.requireNonNull(module);
 254         Objects.requireNonNull(name);
 255         // Details of the algorithm used here can be found in
 256         // jdk.tools.jlink.internal.PerfectHashBuilder.
 257         int count = header.getTableLength();
 258         int index = redirect.get(ImageStringsReader.hashCode(module, name) % count);
 259 
 260         if (index < 0) {
 261             // index is twos complement of location attributes index.
 262             index = -index - 1;
 263         } else if (index > 0) {
 264             // index is hash seed needed to compute location attributes index.
 265             index = ImageStringsReader.hashCode(module, name, index) % count;
 266         } else {
 267             // No entry.
 268             return null;
 269         }
 270 
 271         long[] attributes = getAttributes(offsets.get(index));
 272 
 273         if (!ImageLocation.verify(module, name, attributes, stringsReader)) {
 274             return null;
 275         }
 276         return new ImageLocation(attributes, stringsReader);
 277     }
 278 
 279     public synchronized ImageLocation findLocation(String name) {
 280         Objects.requireNonNull(name);
 281         // Details of the algorithm used here can be found in
 282         // jdk.tools.jlink.internal.PerfectHashBuilder.

 283         int count = header.getTableLength();
 284         int index = redirect.get(ImageStringsReader.hashCode(name) % count);
 285 
 286         if (index < 0) {
 287             // index is twos complement of location attributes index.
 288             index = -index - 1;
 289         } else if (index > 0) {
 290             // index is hash seed needed to compute location attributes index.
 291             index = ImageStringsReader.hashCode(name, index) % count;
 292         } else {
 293             // No entry.
 294             return null;
 295         }
 296 
 297         long[] attributes = getAttributes(offsets.get(index));
 298 
 299         if (!ImageLocation.verify(name, attributes, stringsReader)) {


 300             return null;
 301         }
 302         return new ImageLocation(attributes, stringsReader);

 303     }
 304 
 305     public String[] getEntryNames() {
 306         int[] attributeOffsets = new int[offsets.capacity()];
 307         offsets.get(attributeOffsets);
 308         return IntStream.of(attributeOffsets)
 309                         .filter(o -> o != 0)
 310                         .mapToObj(o -> ImageLocation.readFrom(this, o).getFullName())
 311                         .sorted()
 312                         .toArray(String[]::new);
 313     }
 314 
 315     ImageLocation getLocation(int offset) {
 316         return ImageLocation.readFrom(this, offset);
 317     }
 318 
 319     public long[] getAttributes(int offset) {
 320         if (offset < 0 || offset >= locations.limit()) {
 321             throw new IndexOutOfBoundsException("offset");
 322         }


< prev index next >