}
public ClassFile getClassFile2() {
+ return getClassFile3(true);
+ }
+
+ public ClassFile getClassFile3(boolean doCompress) {
ClassFile cfile = classfile;
if (cfile != null)
return cfile;
- classPool.compress();
+ if (doCompress)
+ classPool.compress();
+
if (rawClassfile != null) {
try {
- classfile = new ClassFile(new DataInputStream(
- new ByteArrayInputStream(rawClassfile)));
+ ClassFile cf = new ClassFile(new DataInputStream(
+ new ByteArrayInputStream(rawClassfile)));
rawClassfile = null;
getCount = GET_THRESHOLD;
- return classfile;
+ return setClassFile(cf);
}
catch (IOException e) {
throw new RuntimeException(e.toString(), e);
+ cf.getName() + " found in "
+ qualifiedName.replace('.', '/') + ".class");
- classfile = cf;
- return cf;
+ return setClassFile(cf);
}
catch (NotFoundException e) {
throw new RuntimeException(e.toString(), e);
* for saving memory space.
*/
private synchronized void saveClassFile() {
- /* getMembers() and releaseClassFile() are also synchronized.
+ /* getMembers() and removeClassFile() are also synchronized.
*/
if (classfile == null || hasMemberCache() != null)
return;
classfile = null;
}
+ /**
+ * Updates {@code classfile} if it is null.
+ */
+ private synchronized ClassFile setClassFile(ClassFile cf) {
+ if (classfile == null)
+ classfile = cf;
+
+ return classfile;
+ }
+
public ClassPool getClassPool() { return classPool; }
void setClassPool(ClassPool cp) { classPool = cp; }
* Returns null if members are not cached.
*/
protected CtMember.Cache hasMemberCache() {
- if (memberCache != null)
- return (CtMember.Cache)memberCache.get();
+ WeakReference cache = memberCache;
+ if (cache != null)
+ return (CtMember.Cache)cache.get();
else
return null;
}
}
private void makeFieldCache(CtMember.Cache cache) {
- List list = getClassFile2().getFields();
+ List list = getClassFile3(false).getFields();
int n = list.size();
for (int i = 0; i < n; ++i) {
FieldInfo finfo = (FieldInfo)list.get(i);
}
private void makeBehaviorCache(CtMember.Cache cache) {
- List list = getClassFile2().getMethods();
+ List list = getClassFile3(false).getMethods();
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo)list.get(i);