author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
1 |
/* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
4 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
10 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
16 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
20 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
23 |
* questions. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
24 |
*/ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
25 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
27 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
28 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
29 |
import com.sun.tools.javac.util.Context; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
30 |
import java.io.File; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
31 |
import java.io.IOException; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
32 |
import java.util.ArrayList; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
33 |
import java.util.HashMap; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
34 |
import java.util.Iterator; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
35 |
import java.util.List; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
36 |
import java.util.Map; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
37 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
38 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
39 |
/** A cache for ZipFileIndex objects. */ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
40 |
public class ZipFileIndexCache { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
41 |
|
22163 | 42 |
private final Map<File, ZipFileIndex> map = new HashMap<>(); |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
43 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
44 |
/** Get a shared instance of the cache. */ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
45 |
private static ZipFileIndexCache sharedInstance; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
46 |
public synchronized static ZipFileIndexCache getSharedInstance() { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
47 |
if (sharedInstance == null) |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
48 |
sharedInstance = new ZipFileIndexCache(); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
49 |
return sharedInstance; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
50 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
51 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
52 |
/** Get a context-specific instance of a cache. */ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
53 |
public static ZipFileIndexCache instance(Context context) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
54 |
ZipFileIndexCache instance = context.get(ZipFileIndexCache.class); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
55 |
if (instance == null) |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
56 |
context.put(ZipFileIndexCache.class, instance = new ZipFileIndexCache()); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
57 |
return instance; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
58 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
59 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
60 |
/** |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
61 |
* Returns a list of all ZipFileIndex entries |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
62 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
63 |
* @return A list of ZipFileIndex entries, or an empty list |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
64 |
*/ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
65 |
public List<ZipFileIndex> getZipFileIndexes() { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
66 |
return getZipFileIndexes(false); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
67 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
68 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
69 |
/** |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
70 |
* Returns a list of all ZipFileIndex entries |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
71 |
* |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
72 |
* @param openedOnly If true it returns a list of only opened ZipFileIndex entries, otherwise |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
73 |
* all ZipFileEntry(s) are included into the list. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
74 |
* @return A list of ZipFileIndex entries, or an empty list |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
75 |
*/ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
76 |
public synchronized List<ZipFileIndex> getZipFileIndexes(boolean openedOnly) { |
22163 | 77 |
List<ZipFileIndex> zipFileIndexes = new ArrayList<>(); |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
78 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
79 |
zipFileIndexes.addAll(map.values()); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
80 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
81 |
if (openedOnly) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
82 |
for(ZipFileIndex elem : zipFileIndexes) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
83 |
if (!elem.isOpen()) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
84 |
zipFileIndexes.remove(elem); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
85 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
86 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
87 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
88 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
89 |
return zipFileIndexes; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
90 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
91 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
92 |
public synchronized ZipFileIndex getZipFileIndex(File zipFile, |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
93 |
RelativeDirectory symbolFilePrefix, |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
94 |
boolean useCache, String cacheLocation, |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
95 |
boolean writeIndex) throws IOException { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
96 |
ZipFileIndex zi = getExistingZipIndex(zipFile); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
97 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
98 |
if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
99 |
zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex, |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
100 |
useCache, cacheLocation); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
101 |
map.put(zipFile, zi); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
102 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
103 |
return zi; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
104 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
105 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
106 |
public synchronized ZipFileIndex getExistingZipIndex(File zipFile) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
107 |
return map.get(zipFile); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
108 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
109 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
110 |
public synchronized void clearCache() { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
111 |
map.clear(); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
112 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
113 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
114 |
public synchronized void clearCache(long timeNotUsed) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
8223
diff
changeset
|
115 |
for (File cachedFile : map.keySet()) { |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
116 |
ZipFileIndex cachedZipIndex = map.get(cachedFile); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
117 |
if (cachedZipIndex != null) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
118 |
long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
119 |
if (timeToTest < cachedZipIndex.lastReferenceTimeStamp || // Overflow... |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
8223
diff
changeset
|
120 |
System.currentTimeMillis() > timeToTest) { |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
121 |
map.remove(cachedFile); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
122 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
123 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
124 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
125 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
126 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
127 |
public synchronized void removeFromCache(File file) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
128 |
map.remove(file); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
129 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
130 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
131 |
/** Sets already opened list of ZipFileIndexes from an outside client |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
132 |
* of the compiler. This functionality should be used in a non-batch clients of the compiler. |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
133 |
*/ |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
134 |
public synchronized void setOpenedIndexes(List<ZipFileIndex>indexes) throws IllegalStateException { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
135 |
if (map.isEmpty()) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
136 |
String msg = |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
137 |
"Setting opened indexes should be called only when the ZipFileCache is empty. " |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
138 |
+ "Call JavacFileManager.flush() before calling this method."; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
139 |
throw new IllegalStateException(msg); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
140 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
141 |
|
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
142 |
for (ZipFileIndex zfi : indexes) { |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
143 |
map.put(zfi.zipFile, zfi); |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
144 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
145 |
} |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
diff
changeset
|
146 |
} |