8285407: Improve Xalan supports

Reviewed-by: naoto, lancea, ahgross, rhalade
This commit is contained in:
Joe Wang 2022-05-13 02:02:26 +00:00 committed by Henry Jen
parent d0a2f13dea
commit 5d1c44871a
2 changed files with 26 additions and 8 deletions

View File

@ -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
@ -26,6 +25,7 @@ import java.io.DataOutputStream;
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
@ -37,6 +37,7 @@ import com.sun.org.apache.bcel.internal.Const;
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @LastModified: May 2022
*/
public class ConstantPool implements Cloneable, Node {
@ -222,8 +223,16 @@ public class ConstantPool implements Cloneable, Node {
* @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);
}

View File

@ -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
@ -50,10 +50,10 @@ import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8;
* 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;
@ -83,7 +83,7 @@ public class ConstantPoolGen {
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);
@ -212,9 +212,18 @@ public class 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);
}