Skip to content

Commit 7c979c1

Browse files
david-beaumontRoger Riggs
authored andcommitted
8374308: ImageBufferCache has no effect and can be removed
Reviewed-by: alanb, rriggs
1 parent 53300b4 commit 7c979c1

File tree

4 files changed

+16
-209
lines changed

4 files changed

+16
-209
lines changed

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -220,14 +220,6 @@ private IntBuffer intBuffer(ByteBuffer buffer, int offset, int size) {
220220
return slice(buffer, offset, size).order(byteOrder).asIntBuffer();
221221
}
222222

223-
public static void releaseByteBuffer(ByteBuffer buffer) {
224-
Objects.requireNonNull(buffer);
225-
226-
if (!MAP_ALL) {
227-
ImageBufferCache.releaseBuffer(buffer);
228-
}
229-
}
230-
231223
public String getName() {
232224
return name;
233225
}
@@ -362,35 +354,34 @@ private ByteBuffer readBuffer(long offset, long size) {
362354
if (offset < 0 || Integer.MAX_VALUE <= offset) {
363355
throw new IndexOutOfBoundsException("Bad offset: " + offset);
364356
}
357+
int checkedOffset = (int) offset;
365358

366359
if (size < 0 || Integer.MAX_VALUE <= size) {
367-
throw new IndexOutOfBoundsException("Bad size: " + size);
360+
throw new IllegalArgumentException("Bad size: " + size);
368361
}
362+
int checkedSize = (int) size;
369363

370364
if (MAP_ALL) {
371-
ByteBuffer buffer = slice(memoryMap, (int)offset, (int)size);
365+
ByteBuffer buffer = slice(memoryMap, checkedOffset, checkedSize);
372366
buffer.order(ByteOrder.BIG_ENDIAN);
373367

374368
return buffer;
375369
} else {
376370
if (channel == null) {
377371
throw new InternalError("Image file channel not open");
378372
}
379-
380-
ByteBuffer buffer = ImageBufferCache.getBuffer(size);
373+
ByteBuffer buffer = ByteBuffer.allocate(checkedSize);
381374
int read;
382375
try {
383-
read = channel.read(buffer, offset);
376+
read = channel.read(buffer, checkedOffset);
384377
buffer.rewind();
385378
} catch (IOException ex) {
386-
ImageBufferCache.releaseBuffer(buffer);
387379
throw new RuntimeException(ex);
388380
}
389381

390-
if (read != size) {
391-
ImageBufferCache.releaseBuffer(buffer);
382+
if (read != checkedSize) {
392383
throw new RuntimeException("Short read: " + read +
393-
" instead of " + size + " bytes");
384+
" instead of " + checkedSize + " bytes");
394385
}
395386

396387
return buffer;
@@ -406,17 +397,12 @@ public byte[] getResource(String name) {
406397

407398
public byte[] getResource(ImageLocation loc) {
408399
ByteBuffer buffer = getResourceBuffer(loc);
409-
410-
if (buffer != null) {
411-
byte[] bytes = getBufferBytes(buffer);
412-
ImageBufferCache.releaseBuffer(buffer);
413-
414-
return bytes;
415-
}
416-
417-
return null;
400+
return buffer != null ? getBufferBytes(buffer) : null;
418401
}
419402

403+
/**
404+
* Returns the content of jimage location in a newly allocated byte buffer.
405+
*/
420406
public ByteBuffer getResourceBuffer(ImageLocation loc) {
421407
Objects.requireNonNull(loc);
422408
long offset = loc.getContentOffset() + indexSize;
@@ -437,10 +423,8 @@ public ByteBuffer getResourceBuffer(ImageLocation loc) {
437423
return readBuffer(offset, uncompressedSize);
438424
} else {
439425
ByteBuffer buffer = readBuffer(offset, compressedSize);
440-
441426
if (buffer != null) {
442427
byte[] bytesIn = getBufferBytes(buffer);
443-
ImageBufferCache.releaseBuffer(buffer);
444428
byte[] bytesOut;
445429

446430
try {

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

Lines changed: 0 additions & 158 deletions
This file was deleted.

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -190,20 +190,7 @@ public byte[] getResource(Node node) throws IOException {
190190
}
191191

192192
/**
193-
* Releases a (possibly cached) {@link ByteBuffer} obtained via
194-
* {@link #getResourceBuffer(Node)}.
195-
*
196-
* <p>Note that no testing is performed to check whether the buffer about
197-
* to be released actually came from a call to {@code getResourceBuffer()}.
198-
*/
199-
public static void releaseByteBuffer(ByteBuffer buffer) {
200-
BasicImageReader.releaseByteBuffer(buffer);
201-
}
202-
203-
/**
204-
* Returns the content of a resource node in a possibly cached byte buffer.
205-
* Callers of this method must call {@link #releaseByteBuffer(ByteBuffer)}
206-
* when they are finished with it.
193+
* Returns the content of a resource node in a newly allocated byte buffer.
207194
*/
208195
public ByteBuffer getResourceBuffer(Node node) {
209196
requireOpen();

src/java.base/share/classes/jdk/internal/module/SystemModuleFinders.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -467,12 +467,6 @@ public Optional<ByteBuffer> read(String name) throws IOException {
467467
.map(reader::getResourceBuffer);
468468
}
469469

470-
@Override
471-
public void release(ByteBuffer bb) {
472-
Objects.requireNonNull(bb);
473-
ImageReader.releaseByteBuffer(bb);
474-
}
475-
476470
@Override
477471
public Stream<String> list() throws IOException {
478472
if (closed)

0 commit comments

Comments
 (0)