Skip to content

Commit

Permalink
8285407: Improve Xalan supports
Browse files Browse the repository at this point in the history
Reviewed-by: naoto, lancea, ahgross, rhalade
  • Loading branch information
JoeWang-Java authored and slowhog committed Jul 19, 2022
1 parent d0a2f13 commit 5d1c448
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
@@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -26,6 +25,7 @@
import java.io.IOException;

import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;

/**
* This class represents the constant pool, i.e., a table of constants, of
Expand All @@ -37,6 +37,7 @@
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @LastModified: May 2022
*/
public class ConstantPool implements Cloneable, Node {

Expand Down Expand Up @@ -222,8 +223,16 @@ public String constantToString( final int index, final byte tag ) throws ClassFo
* @throws IOException
*/
public void dump( final DataOutputStream file ) throws IOException {
file.writeShort(constantPool.length);
for (int i = 1; i < constantPool.length; i++) {
/*
* Constants over the size of the constant pool shall not be written out.
* 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;

file.writeShort(size);
for (int i = 1; i < size; i++) {
if (constantPool[i] != null) {
constantPool[i].dump(file);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -50,10 +50,10 @@
* JVM and that Double and Long constants need two slots.
*
* @see Constant
* @LastModified: May 2021
* @LastModified: May 2022
*/
public class ConstantPoolGen {

public static final int CONSTANT_POOL_SIZE = 65536;
private static final int DEFAULT_BUFFER_SIZE = 256;
private int size;
private Constant[] constants;
Expand Down Expand Up @@ -83,7 +83,7 @@ private static class Index {
public ConstantPoolGen(final Constant[] cs) {
final StringBuilder sb = new StringBuilder(DEFAULT_BUFFER_SIZE);

size = Math.max(DEFAULT_BUFFER_SIZE, cs.length + 64);
size = Math.min(Math.max(DEFAULT_BUFFER_SIZE, cs.length + 64), CONSTANT_POOL_SIZE);
constants = new Constant[size];

System.arraycopy(cs, 0, constants, 0, cs.length);
Expand Down Expand Up @@ -212,9 +212,18 @@ public ConstantPoolGen() {
/** Resize internal array of constants.
*/
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));
}

if (index + 3 >= size) {
final Constant[] cs = constants;
size *= 2;
// the constant array shall not exceed the size of the constant pool
size = Math.min(size, CONSTANT_POOL_SIZE);
constants = new Constant[size];
System.arraycopy(cs, 0, constants, 0, index);
}
Expand Down

0 comments on commit 5d1c448

Please sign in to comment.