提交 5a68336e 编写于 作者: K kizune

8013155: [pack200] improve performance of pack200

Reviewed-by: ksrini, jrose
上级 2e7d5571
...@@ -146,7 +146,6 @@ class Code extends Attribute.Holder { ...@@ -146,7 +146,6 @@ class Code extends Attribute.Holder {
int verbose = getPackage().verbose; int verbose = getPackage().verbose;
if (verbose > 2) if (verbose > 2)
System.out.println("Reference scan "+this); System.out.println("Reference scan "+this);
Class cls = thisClass();
refs.addAll(Arrays.asList(handler_class)); refs.addAll(Arrays.asList(handler_class));
if (fixups != null) { if (fixups != null) {
fixups.visitRefs(refs); fixups.visitRefs(refs);
......
...@@ -785,53 +785,55 @@ class ConstantPool { ...@@ -785,53 +785,55 @@ class ConstantPool {
return new String(sig); return new String(sig);
} }
static private int skipClassNameChars(String sig, int i) { static private int skipTo(char semi, String sig, int i) {
int len = sig.length(); i = sig.indexOf(semi, i);
for (; i < len; i++) { return (i >= 0) ? i : sig.length();
char ch = sig.charAt(i);
if (ch <= ' ') break;
if (ch >= ';' && ch <= '@') break;
}
return i;
} }
static String[] structureSignature(String sig) { static String[] structureSignature(String sig) {
sig = sig.intern(); int firstl = sig.indexOf('L');
if (firstl < 0) {
int formLen = 0;
int nparts = 1;
for (int i = 0; i < sig.length(); i++) {
char ch = sig.charAt(i);
formLen++;
if (ch == 'L') {
nparts++;
int i2 = skipClassNameChars(sig, i+1);
i = i2-1; // keep the semicolon in the form
int i3 = sig.indexOf('<', i+1);
if (i3 > 0 && i3 < i2)
i = i3-1;
}
}
char[] form = new char[formLen];
if (nparts == 1) {
String[] parts = { sig }; String[] parts = { sig };
return parts; return parts;
} }
String[] parts = new String[nparts]; // Segment the string like sig.split("L\\([^;<]*\\)").
int j = 0; // N.B.: Previous version of this code did a more complex match,
int k = 1; // to next ch < ' ' or ch in [';'..'@']. The only important
for (int i = 0; i < sig.length(); i++) { // characters are ';' and '<', since they are part of the
char ch = sig.charAt(i); // signature syntax.
form[j++] = ch; // Examples:
if (ch == 'L') { // "(Ljava/lang/Object;IJLLoo;)V" => {"(L;IJL;)V", "java/lang/Object", "Loo"}
int i2 = skipClassNameChars(sig, i+1); // "Ljava/util/List<Ljava/lang/String;>;" => {"L<L;>;", "java/util/List", "java/lang/String"}
parts[k++] = sig.substring(i+1, i2); char[] form = null;
i = i2; String[] parts = null;
--i; // keep the semicolon in the form for (int pass = 0; pass <= 1; pass++) {
// pass 0 is a sizing pass, pass 1 packs the arrays
int formPtr = 0;
int partPtr = 1;
int nextsemi = 0, nextangl = 0; // next ';' or '<', or zero, or sigLen
int lastj = 0;
for (int i = firstl + 1, j; i > 0; i = sig.indexOf('L', j) + 1) {
// sig[i-1] is 'L', while sig[j] will be the first ';' or '<' after it
// each part is in sig[i .. j-1]
if (nextsemi < i) nextsemi = skipTo(';', sig, i);
if (nextangl < i) nextangl = skipTo('<', sig, i);
j = (nextsemi < nextangl ? nextsemi : nextangl);
if (pass != 0) {
sig.getChars(lastj, i, form, formPtr);
parts[partPtr] = sig.substring(i, j);
}
formPtr += (i - lastj);
partPtr += 1;
lastj = j;
} }
if (pass != 0) {
sig.getChars(lastj, sig.length(), form, formPtr);
break;
}
formPtr += (sig.length() - lastj);
form = new char[formPtr];
parts = new String[partPtr];
} }
assert(j == formLen);
assert(k == parts.length);
parts[0] = new String(form); parts[0] = new String(form);
//assert(flattenSignature(parts).equals(sig)); //assert(flattenSignature(parts).equals(sig));
return parts; return parts;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册