8232734: [TESTBUG] avoid using JDK symbols in ExtraSymbols.symbols.txt

Reviewed-by: ccheung
This commit is contained in:
Ioi Lam 2019-11-04 12:36:54 -08:00
parent 3561b4ed50
commit 1721476038
3 changed files with 89 additions and 10829 deletions

View File

@ -34,6 +34,7 @@
import java.io.*;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.cds.CDSTestUtils;
public class ExtraSymbols {
static final String CDS_LOGGING = "-Xlog:cds,cds+hashtables";
@ -46,10 +47,9 @@ public class ExtraSymbols {
checkOutput(output);
int numEntries1 = numOfEntries(output);
// 2. Dump an archive with extra symbols. All symbols in
// ExtraSymbols.symbols.txt are valid. Dumping should succeed.
// 2. Dump an archive with lots of extra symbols.
output = TestCommon.dump(appJar, TestCommon.list("Hello"), CDS_LOGGING,
"-XX:SharedArchiveConfigFile=" + TestCommon.getSourceFile("ExtraSymbols.symbols.txt"));
"-XX:SharedArchiveConfigFile=" + makeLotsExtraSymbols());
checkOutput(output);
int numEntries2 = numOfEntries(output);
if (numEntries2 <= numEntries1) {
@ -86,4 +86,30 @@ public class ExtraSymbols {
output.shouldContain("Shared symbol table stats -------- base:");
output.shouldHaveExitValue(0);
}
static String makeLotsExtraSymbols() throws Exception {
String fileName = "LotsExtraSymbols.txt";
File f = new File(fileName);
try (FileWriter fw = new FileWriter(f)) {
fw.write("VERSION: 1.0\n");
fw.write("@SECTION: Symbol\n");
appendSymbol(fw, "This file is auto-generated by test/hotspot/jtreg/runtime/cds/appcds/ExtraSymbols.java. Do not edit.");
appendSymbol(fw, "Hello");
appendSymbol(fw, ""); // empty string
appendSymbol(fw, "Hello_\u0001"); // <128 escaping with \x
appendSymbol(fw, "Hello_\u00ff"); // <256 escaping with \x
appendSymbol(fw, "Hello_\u1234"); // >= 256 escaping with \x
appendSymbol(fw, "Hello_\uffff"); // >= 256 escaping with \x
for (int i = 0; i < 10000; i++) {
appendSymbol(fw, "NewSymbol" + Integer.toString(i));
}
}
return fileName;
}
private static void appendSymbol(FileWriter fw, String symbol) throws Exception {
fw.write(CDSTestUtils.formatArchiveConfigSymbol(symbol));
fw.write("\n");
}
}

File diff suppressed because one or more lines are too long

View File

@ -601,4 +601,64 @@ public class CDSTestUtils {
ps.close();
fos.close();
}
// Format a line that defines an extra symbol in the file specify by -XX:SharedArchiveConfigFile=<file>
public static String formatArchiveConfigSymbol(String symbol) {
int refCount = -1; // This is always -1 in the current HotSpot implementation.
if (isAsciiPrintable(symbol)) {
return symbol.length() + " " + refCount + ": " + symbol;
} else {
StringBuilder sb = new StringBuilder();
int utf8_length = escapeArchiveConfigString(sb, symbol);
return utf8_length + " " + refCount + ": " + sb.toString();
}
}
// This method generates the same format as HashtableTextDump::put_utf8() in HotSpot,
// to be used by -XX:SharedArchiveConfigFile=<file>.
private static int escapeArchiveConfigString(StringBuilder sb, String s) {
byte arr[];
try {
arr = s.getBytes("UTF8");
} catch (java.io.UnsupportedEncodingException e) {
throw new RuntimeException("Unexpected", e);
}
for (int i = 0; i < arr.length; i++) {
char ch = (char)(arr[i] & 0xff);
if (isAsciiPrintable(ch)) {
sb.append(ch);
} else if (ch == '\t') {
sb.append("\\t");
} else if (ch == '\r') {
sb.append("\\r");
} else if (ch == '\n') {
sb.append("\\n");
} else if (ch == '\\') {
sb.append("\\\\");
} else {
String hex = Integer.toHexString(ch);
if (ch < 16) {
sb.append("\\x0");
} else {
sb.append("\\x");
}
sb.append(hex);
}
}
return arr.length;
}
private static boolean isAsciiPrintable(String s) {
for (int i = 0; i < s.length(); i++) {
if (!isAsciiPrintable(s.charAt(i))) {
return false;
}
}
return true;
}
private static boolean isAsciiPrintable(char ch) {
return ch >= 32 && ch < 127;
}
}