Skip to content

Commit

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

Reviewed-by: mbaesken
  • Loading branch information
GoeLin committed Jan 25, 2023
1 parent ba956c5 commit a34f2d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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
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

5 comments on commit a34f2d3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member Author

@GoeLin GoeLin commented on a34f2d3 Jan 25, 2023

Choose a reason for hiding this comment

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

/backport jkd11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a34f2d3 Jan 25, 2023

Choose a reason for hiding this comment

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

@GoeLin The target repository jkd11u-dev is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk12u, openjdk/jdk13u, openjdk/jdk13u-dev, openjdk/jdk14u, openjdk/jdk15u, openjdk/jdk15u-dev, openjdk/jdk16u, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk19u, openjdk/jdk20, openjdk/jdk20u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/shenandoah-jdk8u, openjdk/shenandoah-jdk8u-dev.
Supplying the organization/group prefix is optional.

@GoeLin
Copy link
Member Author

@GoeLin GoeLin commented on a34f2d3 Jan 25, 2023

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a34f2d3 Jan 25, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-a34f2d37 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a34f2d37 from the openjdk/jdk17u-dev repository.

The commit being backported was authored by Goetz Lindenmaier on 25 Jan 2023 and was reviewed by Matthias Baesken.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-a34f2d37:GoeLin-backport-a34f2d37
$ git checkout GoeLin-backport-a34f2d37
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-a34f2d37

Please sign in to comment.