diff --git a/core/src/main/java/lucee/runtime/MappingImpl.java b/core/src/main/java/lucee/runtime/MappingImpl.java index 0969e020ce..ed88664eb7 100755 --- a/core/src/main/java/lucee/runtime/MappingImpl.java +++ b/core/src/main/java/lucee/runtime/MappingImpl.java @@ -23,7 +23,6 @@ import java.io.Serializable; import java.lang.instrument.UnmodifiableClassException; import java.lang.ref.SoftReference; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -248,9 +247,7 @@ private PhysicalClassLoader touchPhysicalClassLoader(boolean forComponent) throw } else if ((forComponent ? pclCFC : pclCFM).getSize(true) > (forComponent ? MAX_SIZE_CFC : MAX_SIZE_CFM)) { PhysicalClassLoader pcl = forComponent ? pclCFC : pclCFM; - synchronized (pageSourcePool) { - pageSourcePool.clearPages(pcl); - } + pageSourcePool.clearPages(pcl); pcl.clear(); if (forComponent) pclCFC = new PhysicalClassLoader(config, getClassRootDirectory()); else pclCFM = new PhysicalClassLoader(config, getClassRootDirectory()); @@ -294,21 +291,15 @@ public Class getPhysicalClass(String className, byte[] code) throws IOExcepti * @param cl */ public void clearPages(ClassLoader cl) { - synchronized (pageSourcePool) { - pageSourcePool.clearPages(cl); - } + pageSourcePool.clearPages(cl); } public void clearUnused(Config config) { - synchronized (pageSourcePool) { - pageSourcePool.clearUnused(config); - } + pageSourcePool.clearUnused(config); } public void resetPages(ClassLoader cl) { - synchronized (pageSourcePool) { - pageSourcePool.resetPages(cl); - } + pageSourcePool.resetPages(cl); } @Override @@ -400,49 +391,31 @@ else if (realPath.startsWith("./")) { @Override public PageSource getPageSource(String path, boolean isOut) { - synchronized (pageSourcePool) { - PageSource source = pageSourcePool.getPageSource(path, true); - if (source != null) return source; + PageSource source = pageSourcePool.getPageSource(path, true); + if (source != null) return source; - PageSourceImpl newSource = new PageSourceImpl(this, path, isOut); - pageSourcePool.setPage(path, newSource); + PageSourceImpl newSource = new PageSourceImpl(this, path, isOut); + pageSourcePool.setPage(path, newSource); - return newSource;// new PageSource(this,path); - } + return newSource;// new PageSource(this,path); } // to not delete,used for argus monitor! public PageSourcePool getPageSourcePool() { - synchronized (pageSourcePool) { - return pageSourcePool; - } + return pageSourcePool; } public Array getDisplayPathes(Array arr) throws PageException { - synchronized (pageSourcePool) { - String[] keys = pageSourcePool.keys(); - PageSourceImpl ps; - for (int y = 0; y < keys.length; y++) { - ps = (PageSourceImpl) pageSourcePool.getPageSource(keys[y], false); - if (ps != null && ps.isLoad()) arr.append(ps.getDisplayPath()); - } - return arr; + List values = pageSourcePool.values(true); + for (PageSource ps: values) { + if (ps != null) arr.append(ps.getDisplayPath()); } + return arr; + } public List getPageSources(boolean loaded) { - List list = new ArrayList<>(); - synchronized (pageSourcePool) { - String[] keys = pageSourcePool.keys(); - PageSourceImpl ps; - for (int y = 0; y < keys.length; y++) { - ps = (PageSourceImpl) pageSourcePool.getPageSource(keys[y], false); - if (ps != null) { - if (!loaded || ps.isLoad()) list.add(ps); - } - } - } - return list; + return pageSourcePool.values(loaded); } @Override @@ -599,9 +572,7 @@ public int getListenerType() { } public void flush() { - synchronized (pageSourcePool) { - pageSourcePool.clear(); - } + pageSourcePool.clear(); } public SerMapping toSerMapping() { diff --git a/core/src/main/java/lucee/runtime/PageSourcePool.java b/core/src/main/java/lucee/runtime/PageSourcePool.java index c036560893..9e2d954f5d 100644 --- a/core/src/main/java/lucee/runtime/PageSourcePool.java +++ b/core/src/main/java/lucee/runtime/PageSourcePool.java @@ -19,8 +19,11 @@ package lucee.runtime; import java.lang.ref.SoftReference; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -66,9 +69,12 @@ public PageSourcePool() { */ public PageSource getPageSource(String key, boolean updateAccesTime) { // DO NOT CHANGE INTERFACE (used by Argus Monitor) SoftReference tmp = pageSources.get(key.toLowerCase()); - PageSource ps = tmp == null ? null : tmp.get(); - if (ps == null) return null; - if (updateAccesTime) ps.setLastAccessTime(); + if (tmp == null) return null; + PageSource ps = tmp.get(); + if (ps == null) { + pageSources.remove(key.toLowerCase()); + return null; + } return ps; } @@ -103,6 +109,19 @@ public String[] keys() { return set.toArray(new String[set.size()]); } + public List values(boolean loaded) { + List vals = new ArrayList<>(); + if (pageSources == null) return vals; + + PageSource ps; + for (SoftReference sr: pageSources.values()) { + ps = sr.get(); + if (ps != null && (!loaded || ((PageSourceImpl) ps).isLoad())) vals.add(ps); + + } + return vals; + } + /** * removes a page from the page pool * @@ -144,20 +163,30 @@ public boolean flushPage(String key) { * @return returns the size of the pool */ public int size() { - return pageSources.size(); + int size = 0; + + for (Entry> entry: pageSources.entrySet()) { + if (entry.getValue().get() != null) size++; + else { + pageSources.remove(entry.getKey()); + } + } + return size; } /** * @return returns if pool is empty or not */ public boolean isEmpty() { - return pageSources.isEmpty(); + return size() > 0; } /** * clear unused pages from page pool */ + public void clearUnused(Config config) { + if (size() > maxSize) { LogUtil.log(config, Log.LEVEL_INFO, PageSourcePool.class.getName(), "PagePool size [" + size() + "] has exceeded max size [" + maxSize + "]. Clearing unused..."); String[] keys = keys(); @@ -184,6 +213,8 @@ public void clearUnused(Config config) { @Override public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { maxlevel--; + + size(); // calling size because it get rid of all the blanks Iterator> it = pageSources.values().iterator(); DumpTable table = new DumpTable("#FFCC00", "#FFFF00", "#000000"); @@ -207,36 +238,34 @@ public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties * @param cl */ public void clearPages(ClassLoader cl) { - Iterator> it = this.pageSources.values().iterator(); - PageSourceImpl psi; - SoftReference sr; - while (it.hasNext()) { - sr = it.next(); - psi = sr == null ? null : (PageSourceImpl) sr.get(); - if (psi == null) continue; - if (cl != null) psi.clear(cl); - else psi.clear(); - } + clearResetPages(cl, true); } public void resetPages(ClassLoader cl) { - Iterator> it = this.pageSources.values().iterator(); + clearResetPages(cl, false); + } + + public void clear() { + clearResetPages(null, true); + } + + private void clearResetPages(ClassLoader cl, boolean clear) { PageSourceImpl psi; SoftReference sr; - while (it.hasNext()) { - sr = it.next(); + for (Entry> entry: pageSources.entrySet()) { + sr = entry.getValue(); psi = sr == null ? null : (PageSourceImpl) sr.get(); - if (psi == null) continue; + if (psi == null) { + if (sr != null) pageSources.remove(entry.getKey()); + continue; + } + if (cl != null) psi.clear(cl); + else if (clear) psi.clear(); else psi.resetLoaded(); } } - public void clear() { - clearPages(null); - // pageSources.clear(); - } - public int getMaxSize() { return maxSize; } diff --git a/loader/build.xml b/loader/build.xml index 9d58a84a93..2cf69effca 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 96e216467d..9a5a192bb9 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.0.0.534-SNAPSHOT + 6.0.0.535-SNAPSHOT jar Lucee Loader Build