author | jjg |
Mon, 24 Jan 2011 16:38:56 -0800 | |
changeset 8223 | 638daa596494 |
parent 5847 | 1908176fd6e3 |
child 8422 | b2ac1acf3937 |
permissions | -rw-r--r-- |
1208 | 1 |
/* |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
5847
diff
changeset
|
2 |
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
1208 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
1208 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
1208 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
1208 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.file; |
|
27 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.util.List; |
|
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
5847
diff
changeset
|
31 |
import java.util.Map; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
5847
diff
changeset
|
32 |
import java.util.concurrent.ConcurrentHashMap; |
1208 | 33 |
|
34 |
import com.sun.tools.javac.util.Context; |
|
35 |
||
36 |
/** |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
37 |
* Caching implementation of FSInfo. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
38 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
41 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
42 |
* deletion without notice.</b> |
1208 | 43 |
*/ |
44 |
public class CacheFSInfo extends FSInfo { |
|
45 |
||
46 |
/** |
|
47 |
* Register a Context.Factory to create a singleton CacheFSInfo. |
|
48 |
*/ |
|
49 |
public static void preRegister(final Context context) { |
|
50 |
context.put(FSInfo.class, new Context.Factory<FSInfo>() { |
|
51 |
public FSInfo make() { |
|
52 |
if (singleton == null) |
|
53 |
singleton = new CacheFSInfo(); |
|
54 |
context.put(FSInfo.class, singleton); |
|
55 |
return singleton; |
|
56 |
} |
|
57 |
}); |
|
58 |
} |
|
59 |
||
60 |
static CacheFSInfo singleton; |
|
61 |
||
62 |
public void clearCache() { |
|
63 |
cache.clear(); |
|
64 |
} |
|
65 |
||
66 |
@Override |
|
67 |
public File getCanonicalFile(File file) { |
|
68 |
Entry e = getEntry(file); |
|
69 |
return e.canonicalFile; |
|
70 |
} |
|
71 |
||
72 |
@Override |
|
73 |
public boolean exists(File file) { |
|
74 |
Entry e = getEntry(file); |
|
75 |
return e.exists; |
|
76 |
} |
|
77 |
||
78 |
@Override |
|
79 |
public boolean isDirectory(File file) { |
|
80 |
Entry e = getEntry(file); |
|
81 |
return e.isDirectory; |
|
82 |
} |
|
83 |
||
84 |
@Override |
|
85 |
public boolean isFile(File file) { |
|
86 |
Entry e = getEntry(file); |
|
87 |
return e.isFile; |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
public List<File> getJarClassPath(File file) throws IOException { |
|
92 |
// don't bother to lock the cache, because it is thread-safe, and |
|
93 |
// because the worst that can happen would be to create two identical |
|
94 |
// jar class paths together and have one overwrite the other. |
|
95 |
Entry e = getEntry(file); |
|
96 |
if (e.jarClassPath == null) |
|
97 |
e.jarClassPath = super.getJarClassPath(file); |
|
98 |
return e.jarClassPath; |
|
99 |
} |
|
100 |
||
101 |
private Entry getEntry(File file) { |
|
102 |
// don't bother to lock the cache, because it is thread-safe, and |
|
103 |
// because the worst that can happen would be to create two identical |
|
104 |
// entries together and have one overwrite the other. |
|
105 |
Entry e = cache.get(file); |
|
106 |
if (e == null) { |
|
107 |
e = new Entry(); |
|
108 |
e.canonicalFile = super.getCanonicalFile(file); |
|
109 |
e.exists = super.exists(file); |
|
110 |
e.isDirectory = super.isDirectory(file); |
|
111 |
e.isFile = super.isFile(file); |
|
112 |
cache.put(file, e); |
|
113 |
} |
|
114 |
return e; |
|
115 |
} |
|
116 |
||
117 |
// could also be a Map<File,SoftReference<Entry>> ? |
|
118 |
private Map<File,Entry> cache = new ConcurrentHashMap<File,Entry>(); |
|
119 |
||
120 |
private static class Entry { |
|
121 |
File canonicalFile; |
|
122 |
boolean exists; |
|
123 |
boolean isFile; |
|
124 |
boolean isDirectory; |
|
125 |
List<File> jarClassPath; |
|
126 |
} |
|
127 |
} |