8285407: Improve Xalan supports

Reviewed-by: mbalao, andrew
Backport-of: fd6385d8c20379c1139f64f5c90d331ad9631097
This commit is contained in:
Aleksei Voitylov 2022-05-30 12:26:00 +00:00 committed by Andrew John Hughes
parent 1f50bcccf2
commit 3dca446d44
2 changed files with 25 additions and 7 deletions

View File

@ -1,6 +1,5 @@
/* /*
* reserved comment block * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -23,6 +22,7 @@ package com.sun.org.apache.bcel.internal.classfile;
import com.sun.org.apache.bcel.internal.Constants; import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import java.io.*; import java.io.*;
/** /**
@ -36,6 +36,7 @@ import java.io.*;
* @see Constant * @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen * @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @LastModified: May 2022
*/ */
public class ConstantPool implements Cloneable, Node, Serializable { public class ConstantPool implements Cloneable, Node, Serializable {
private int constant_pool_count; private int constant_pool_count;
@ -190,9 +191,16 @@ public class ConstantPool implements Cloneable, Node, Serializable {
*/ */
public void dump(DataOutputStream file) throws IOException public void dump(DataOutputStream file) throws IOException
{ {
file.writeShort(constant_pool_count); /*
* 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 = constant_pool_count < ConstantPoolGen.CONSTANT_POOL_SIZE - 1 ?
constant_pool_count : ConstantPoolGen.CONSTANT_POOL_SIZE - 1;
for(int i=1; i < constant_pool_count; i++) file.writeShort(size);
for(int i=1; i < size; i++)
if(constant_pool[i] != null) if(constant_pool[i] != null)
constant_pool[i].dump(file); constant_pool[i].dump(file);
} }

View File

@ -1,6 +1,5 @@
/* /*
* reserved comment block * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -38,8 +37,10 @@ import java.util.HashMap;
* *
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant * @see Constant
* @LastModified: May 2022
*/ */
public class ConstantPoolGen implements java.io.Serializable { public class ConstantPoolGen implements java.io.Serializable {
public static final int CONSTANT_POOL_SIZE = 65536;
protected int size = 1024; // Inital size, sufficient in most cases protected int size = 1024; // Inital size, sufficient in most cases
protected Constant[] constants = new Constant[size]; protected Constant[] constants = new Constant[size];
protected int index = 1; // First entry (0) used by JVM protected int index = 1; // First entry (0) used by JVM
@ -61,7 +62,7 @@ public class ConstantPoolGen implements java.io.Serializable {
*/ */
public ConstantPoolGen(Constant[] cs) { public ConstantPoolGen(Constant[] cs) {
if(cs.length > size) { if(cs.length > size) {
size = cs.length; size = Math.min(cs.length, CONSTANT_POOL_SIZE);
constants = new Constant[size]; constants = new Constant[size];
} }
@ -134,10 +135,19 @@ public class ConstantPoolGen implements java.io.Serializable {
/** Resize internal array of constants. /** Resize internal array of constants.
*/ */
protected void adjustSize() { 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) { if(index + 3 >= size) {
Constant[] cs = constants; Constant[] cs = constants;
size *= 2; 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]; constants = new Constant[size];
System.arraycopy(cs, 0, constants, 0, index); System.arraycopy(cs, 0, constants, 0, index);
} }