提交 53d0efd6 编写于 作者: J jjh

6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux

Summary: Fixed JavacFileManager to not treat a non-existant pathname as a directory.
Reviewed-by: jjg
上级 a343ff5e
......@@ -266,50 +266,16 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
System.out.println(message);
}
/**
* Insert all files in subdirectory `subdirectory' of `directory' which end
* in one of the extensions in `extensions' into packageSym.
* Insert all files in subdirectory subdirectory of directory directory
* which match fileKinds into resultList
*/
private void listDirectory(File directory,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> l) {
Archive archive = archives.get(directory);
boolean isFile = fsInfo.isFile(directory);
if (archive != null || isFile) {
if (archive == null) {
try {
archive = openArchive(directory);
} catch (IOException ex) {
log.error("error.reading.file",
directory, getMessage(ex));
return;
}
}
List<String> files = archive.getFiles(subdirectory);
if (files != null) {
for (String file; !files.isEmpty(); files = files.tail) {
file = files.head;
if (isValidFile(file, fileKinds)) {
l.append(archive.getFileObject(subdirectory, file));
}
}
}
if (recurse) {
for (RelativeDirectory s: archive.getSubdirectories()) {
if (subdirectory.contains(s)) {
// Because the archive map is a flat list of directories,
// the enclosing loop will pick up all child subdirectories.
// Therefore, there is no need to recurse deeper.
listDirectory(directory, s, fileKinds, false, l);
}
}
}
} else {
ListBuffer<JavaFileObject> resultList) {
File d = subdirectory.getFile(directory);
if (!caseMapCheck(d, subdirectory))
return;
......@@ -329,18 +295,86 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
new RelativeDirectory(subdirectory, fname),
fileKinds,
recurse,
l);
resultList);
}
} else {
if (isValidFile(fname, fileKinds)) {
JavaFileObject fe =
new RegularFileObject(this, fname, new File(d, fname));
l.append(fe);
resultList.append(fe);
}
}
}
}
/**
* Insert all files in subdirectory subdirectory of archive archive
* which match fileKinds into resultList
*/
private void listArchive(Archive archive,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> resultList) {
// Get the files directly in the subdir
List<String> files = archive.getFiles(subdirectory);
if (files != null) {
for (; !files.isEmpty(); files = files.tail) {
String file = files.head;
if (isValidFile(file, fileKinds)) {
resultList.append(archive.getFileObject(subdirectory, file));
}
}
}
if (recurse) {
for (RelativeDirectory s: archive.getSubdirectories()) {
if (subdirectory.contains(s)) {
// Because the archive map is a flat list of directories,
// the enclosing loop will pick up all child subdirectories.
// Therefore, there is no need to recurse deeper.
listArchive(archive, s, fileKinds, false, resultList);
}
}
}
}
/**
* container is a directory, a zip file, or a non-existant path.
* Insert all files in subdirectory subdirectory of container which
* match fileKinds into resultList
*/
private void listContainer(File container,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> resultList) {
Archive archive = archives.get(container);
if (archive == null) {
// archives are not created for directories.
if (fsInfo.isDirectory(container)) {
listDirectory(container,
subdirectory,
fileKinds,
recurse,
resultList);
return;
}
// Not a directory; either a file or non-existant, create the archive
try {
archive = openArchive(container);
} catch (IOException ex) {
log.error("error.reading.file",
container, getMessage(ex));
return;
}
}
listArchive(archive,
subdirectory,
fileKinds,
recurse,
resultList);
}
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) {
JavaFileObject.Kind kind = getKind(s);
......@@ -434,11 +468,9 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
private static final RelativeDirectory symbolFilePrefix
= new RelativeDirectory("META-INF/sym/rt.jar/");
/** Open a new zip file directory.
/** Open a new zip file directory, and cache it.
*/
protected Archive openArchive(File zipFileName) throws IOException {
Archive archive = archives.get(zipFileName);
if (archive == null) {
File origZipFileName = zipFileName;
if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) {
File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
......@@ -452,6 +484,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
zipFileName = file;
}
Archive archive;
try {
ZipFile zdir = null;
......@@ -499,8 +532,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
preindexCacheLocation,
options.isSet("writezipindexfiles")));
}
}
else {
} else {
if (!useZipFileIndex) {
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix);
}
......@@ -522,7 +554,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
}
archives.put(origZipFileName, archive);
}
return archive;
}
......@@ -589,8 +620,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
for (File directory : path)
listDirectory(directory, subdirectory, kinds, recurse, results);
listContainer(directory, subdirectory, kinds, recurse, results);
return results.toList();
}
......@@ -659,19 +689,22 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
return null;
for (File dir: path) {
if (dir.isDirectory()) {
Archive a = archives.get(dir);
if (a == null) {
if (fsInfo.isDirectory(dir)) {
File f = name.getFile(dir);
if (f.exists())
return new RegularFileObject(this, f);
} else {
Archive a = openArchive(dir);
continue;
}
// Not a directory, create the archive
a = openArchive(dir);
}
// Process the archive
if (a.contains(name)) {
return a.getFileObject(name.dirname(), name.basename());
}
}
}
return null;
}
......
......@@ -286,9 +286,8 @@ public class Paths {
}
public void addFile(File file, boolean warn) {
File canonFile = fsInfo.getCanonicalFile(file);
if (contains(file) || canonicalValues.contains(canonFile)) {
/* Discard duplicates and avoid infinite recursion */
if (contains(file)) {
// discard duplicates
return;
}
......@@ -298,7 +297,17 @@ public class Paths {
log.warning(Lint.LintCategory.PATH,
"path.element.not.found", file);
}
} else if (fsInfo.isFile(file)) {
super.add(file);
return;
}
File canonFile = fsInfo.getCanonicalFile(file);
if (canonicalValues.contains(canonFile)) {
/* Discard duplicates and avoid infinite recursion */
return;
}
if (fsInfo.isFile(file)) {
/* File is an ordinary file. */
if (!isArchive(file)) {
/* Not a recognized extension; open it to see if
......@@ -322,11 +331,11 @@ public class Paths {
}
/* Now what we have left is either a directory or a file name
confirming to archive naming convention */
conforming to archive naming convention */
super.add(file);
canonicalValues.add(canonFile);
if (expandJarClassPaths && fsInfo.exists(file) && fsInfo.isFile(file))
if (expandJarClassPaths && fsInfo.isFile(file))
addJarClassPath(file, warn);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册