Skip to content

Commit

Permalink
8300773: Address the inconsistency between the constant array and poo…
Browse files Browse the repository at this point in the history
…l size

Backport-of: a34f2d3728c077d1dbdfa313f1bf29629fbc32f6
  • Loading branch information
GoeLin committed Feb 1, 2023
1 parent b10ad19 commit 8547c80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @LastModified: May 2022
* @LastModified: June 2022
*/
public class ConstantPool implements Cloneable, Node {

Expand Down Expand Up @@ -228,8 +228,8 @@ public void dump( final DataOutputStream file ) throws IOException {
* This is a redundant measure as the ConstantPoolGen should have already
* reported an error back in the situation.
*/
int size = constantPool.length < ConstantPoolGen.CONSTANT_POOL_SIZE - 1 ?
constantPool.length : ConstantPoolGen.CONSTANT_POOL_SIZE - 1;
int size = constantPool.length < ConstantPoolGen.CONSTANT_POOL_SIZE ?
constantPool.length : ConstantPoolGen.CONSTANT_POOL_SIZE;

file.writeShort(size);
for (int i = 1; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
* JVM and that Double and Long constants need two slots.
*
* @see Constant
* @LastModified: May 2022
* @LastModified: June 2022
*/
public class ConstantPoolGen {
public static final int CONSTANT_POOL_SIZE = 65536;
public static final int CONSTANT_POOL_SIZE = 65535;
private static final int DEFAULT_BUFFER_SIZE = 256;
private int size;
private Constant[] constants;
Expand Down Expand Up @@ -81,6 +81,19 @@ private static class Index {
* @param cs array of given constants, new ones will be appended
*/
public ConstantPoolGen(final Constant[] cs) {
/*
* To be logically/programmatically correct, the size of the constant pool
* shall not exceed the size limit as the code below does a copy and then
* walk through the whole array.
* This is however, not used by XSLT (or the java.xml implementation),
* and only happens when BCELifier is called (see BCELifier).
*/
if (cs.length > CONSTANT_POOL_SIZE) {
throw new RuntimeException("The number of constants " + cs.length
+ " is over the size limit of the constant pool: "
+ CONSTANT_POOL_SIZE);
}

final StringBuilder sb = new StringBuilder(DEFAULT_BUFFER_SIZE);

size = Math.min(Math.max(DEFAULT_BUFFER_SIZE, cs.length + 64), CONSTANT_POOL_SIZE);
Expand Down Expand Up @@ -215,8 +228,8 @@ protected void adjustSize() {
// 3 extra spaces are needed as some entries may take 3 slots
if (index + 3 >= CONSTANT_POOL_SIZE) {
throw new RuntimeException("The number of constants " + (index + 3)
+ " is over the size of the constant pool: "
+ (CONSTANT_POOL_SIZE - 1));
+ " is over the size limit of the constant pool: "
+ CONSTANT_POOL_SIZE);
}

if (index + 3 >= size) {
Expand Down

1 comment on commit 8547c80

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.