Mercurial > hg > openjdk > jdk6 > langtools
changeset 121:8eb53e0c5dc9
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
Reviewed-by: jjg
author | jjh |
---|---|
date | Sun, 27 Mar 2011 09:31:59 -0700 |
parents | e5b59e1e2b1e |
children | f8c147836597 |
files | src/share/classes/com/sun/tools/javac/file/JavacFileManager.java src/share/classes/com/sun/tools/javac/file/Paths.java |
diffstat | 2 files changed, 183 insertions(+), 141 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Sun Mar 27 09:31:59 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Sun Mar 27 09:31:59 2011 -0700 @@ -262,82 +262,116 @@ 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); + ListBuffer<JavaFileObject> resultList) { + File d = subdirectory.getFile(directory); + if (!caseMapCheck(d, subdirectory)) + return; - boolean isFile = fsInfo.isFile(directory); + File[] files = d.listFiles(); + if (files == null) + return; - if (archive != null || isFile) { - if (archive == null) { - try { - archive = openArchive(directory); - } catch (IOException ex) { - log.error("error.reading.file", - directory, getMessage(ex)); - return; - } - } + if (sortFiles != null) + Arrays.sort(files, sortFiles); - 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)); - } + for (File f: files) { + String fname = f.getName(); + if (f.isDirectory()) { + if (recurse && SourceVersion.isIdentifier(fname)) { + listDirectory(directory, + new RelativeDirectory(subdirectory, fname), + fileKinds, + recurse, + resultList); } - } - 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 { - File d = subdirectory.getFile(directory); - if (!caseMapCheck(d, subdirectory)) - return; - - File[] files = d.listFiles(); - if (files == null) - return; - - if (sortFiles != null) - Arrays.sort(files, sortFiles); - - for (File f: files) { - String fname = f.getName(); - if (f.isDirectory()) { - if (recurse && SourceVersion.isIdentifier(fname)) { - listDirectory(directory, - new RelativeDirectory(subdirectory, fname), - fileKinds, - recurse, - l); - } - } else { - if (isValidFile(fname, fileKinds)) { - JavaFileObject fe = - new RegularFileObject(this, fname, new File(d, fname)); - l.append(fe); - } + } else { + if (isValidFile(fname, fileKinds)) { + JavaFileObject fe = + new RegularFileObject(this, fname, new File(d, fname)); + 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); return fileKinds.contains(kind); @@ -430,95 +464,92 @@ 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} - if (new File(file.getName()).equals(new File("jre"))) - file = file.getParentFile(); - // file == ${jdk.home} - for (String name : symbolFileLocation) - file = new File(file, name); - // file == ${jdk.home}/lib/ct.sym - if (file.exists()) - zipFileName = file; - } + File origZipFileName = zipFileName; + if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) { + File file = zipFileName.getParentFile().getParentFile(); // ${java.home} + if (new File(file.getName()).equals(new File("jre"))) + file = file.getParentFile(); + // file == ${jdk.home} + for (String name : symbolFileLocation) + file = new File(file, name); + // file == ${jdk.home}/lib/ct.sym + if (file.exists()) + zipFileName = file; + } - try { + Archive archive; + try { - ZipFile zdir = null; + ZipFile zdir = null; - boolean usePreindexedCache = false; - String preindexCacheLocation = null; + boolean usePreindexedCache = false; + String preindexCacheLocation = null; - if (!useZipFileIndex) { - zdir = new ZipFile(zipFileName); - } - else { - usePreindexedCache = options.get("usezipindex") != null; - preindexCacheLocation = options.get("java.io.tmpdir"); - String optCacheLoc = options.get("cachezipindexdir"); + if (!useZipFileIndex) { + zdir = new ZipFile(zipFileName); + } + else { + usePreindexedCache = options.get("usezipindex") != null; + preindexCacheLocation = options.get("java.io.tmpdir"); + String optCacheLoc = options.get("cachezipindexdir"); - if (optCacheLoc != null && optCacheLoc.length() != 0) { - if (optCacheLoc.startsWith("\"")) { - if (optCacheLoc.endsWith("\"")) { - optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1); - } - else { - optCacheLoc = optCacheLoc.substring(1); - } + if (optCacheLoc != null && optCacheLoc.length() != 0) { + if (optCacheLoc.startsWith("\"")) { + if (optCacheLoc.endsWith("\"")) { + optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1); + } + else { + optCacheLoc = optCacheLoc.substring(1); } + } - File cacheDir = new File(optCacheLoc); - if (cacheDir.exists() && cacheDir.canWrite()) { - preindexCacheLocation = optCacheLoc; - if (!preindexCacheLocation.endsWith("/") && - !preindexCacheLocation.endsWith(File.separator)) { - preindexCacheLocation += File.separator; - } + File cacheDir = new File(optCacheLoc); + if (cacheDir.exists() && cacheDir.canWrite()) { + preindexCacheLocation = optCacheLoc; + if (!preindexCacheLocation.endsWith("/") && + !preindexCacheLocation.endsWith(File.separator)) { + preindexCacheLocation += File.separator; } } } + } - if (origZipFileName == zipFileName) { - if (!useZipFileIndex) { - archive = new ZipArchive(this, zdir); - } else { - archive = new ZipFileIndexArchive(this, + if (origZipFileName == zipFileName) { + if (!useZipFileIndex) { + archive = new ZipArchive(this, zdir); + } else { + archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, null, usePreindexedCache, preindexCacheLocation, options.get("writezipindexfiles") != null)); - } + } + } else { + if (!useZipFileIndex) { + archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); } else { - if (!useZipFileIndex) { - archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); - } - else { - archive = new ZipFileIndexArchive(this, + archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, symbolFilePrefix, usePreindexedCache, preindexCacheLocation, options.get("writezipindexfiles") != null)); - } } - } catch (FileNotFoundException ex) { - archive = new MissingArchive(zipFileName); - } catch (IOException ex) { - if (zipFileName.exists()) - log.error("error.reading.file", zipFileName, getMessage(ex)); - archive = new MissingArchive(zipFileName); } + } catch (FileNotFoundException ex) { + archive = new MissingArchive(zipFileName); + } catch (IOException ex) { + if (zipFileName.exists()) + log.error("error.reading.file", zipFileName, getMessage(ex)); + archive = new MissingArchive(zipFileName); + } - archives.put(origZipFileName, archive); - } + archives.put(origZipFileName, archive); return archive; } @@ -585,8 +616,7 @@ 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(); } @@ -655,19 +685,22 @@ return null; for (File dir: path) { - if (dir.isDirectory()) { - File f = name.getFile(dir); - if (f.exists()) - return new RegularFileObject(this, f); - } else { - Archive a = openArchive(dir); - if (a.contains(name)) { - return a.getFileObject(name.dirname(), name.basename()); + 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); + 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; }
--- a/src/share/classes/com/sun/tools/javac/file/Paths.java Sun Mar 27 09:31:59 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java Sun Mar 27 09:31:59 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -272,9 +272,8 @@ } 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; } @@ -282,7 +281,17 @@ /* No such file or directory exists */ if (warn) log.warning("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 @@ -302,11 +311,11 @@ } /* 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); }