Skip to content

Commit

Permalink
LDEV-3723 - limit sync to threads wanna modify the pagesource
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 11, 2023
1 parent 64ad7a5 commit 10bcb41
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
66 changes: 37 additions & 29 deletions core/src/main/java/lucee/runtime/PageSourceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public PageSource getParent() {
}

@Override
public synchronized Page loadPage(PageContext pc, boolean forceReload) throws PageException {
public Page loadPage(PageContext pc, boolean forceReload) throws PageException {
if (forceReload) pcn.reset();

Page page = pcn.page;
Expand All @@ -229,7 +229,7 @@ public synchronized Page loadPage(PageContext pc, boolean forceReload) throws Pa
}

@Override
public synchronized Page loadPageThrowTemplateException(PageContext pc, boolean forceReload, Page defaultValue) throws TemplateException {
public Page loadPageThrowTemplateException(PageContext pc, boolean forceReload, Page defaultValue) throws TemplateException {
if (forceReload) pcn.reset();

Page page = pcn.page;
Expand All @@ -247,7 +247,7 @@ public synchronized Page loadPageThrowTemplateException(PageContext pc, boolean
}

@Override
public synchronized Page loadPage(PageContext pc, boolean forceReload, Page defaultValue) {
public Page loadPage(PageContext pc, boolean forceReload, Page defaultValue) {
if (forceReload) pcn.reset();

Page page = pcn.page;
Expand Down Expand Up @@ -278,17 +278,19 @@ public synchronized Page loadPage(PageContext pc, boolean forceReload, Page defa
private Page loadArchive(Page page) {
if (!mapping.hasArchive()) return null;
if (page != null && page.getLoadType() == LOAD_ARCHIVE) return page;
try {
Class clazz = mapping.getArchiveClass(getClassName());
page = newInstance(clazz);
page.setPageSource(this);
page.setLoadType(LOAD_ARCHIVE);
pcn.set(page);
return page;
}
catch (Exception e) {
// MUST print.e(e); is there a better way?
return null;
synchronized (this) {
try {
Class clazz = mapping.getArchiveClass(getClassName());
page = newInstance(clazz);
page.setPageSource(this);
page.setLoadType(LOAD_ARCHIVE);
pcn.set(page);
return page;
}
catch (Exception e) {
// MUST print.e(e); is there a better way?
return null;
}
}
}

Expand All @@ -315,27 +317,33 @@ private Page loadPhysical(PageContext pc, Page page) throws TemplateException {
if (page != null) {
// if(page!=null && !recompileAlways) {
if (srcLastModified != page.getSourceLastModified()) {
// same size, maybe the content has not changed?
boolean same = false;
if (page instanceof PagePro && ((PagePro) page).getSourceLength() == srcFile.length()) {
PagePro pp = (PagePro) page;
try {
same = pp.getHash() == PageSourceCode.toString(this, config.getTemplateCharset()).hashCode();
}
catch (IOException e) {
}
synchronized (this) {
if (srcLastModified != page.getSourceLastModified()) {
// same size, maybe the content has not changed?
boolean same = false;
if (page instanceof PagePro && ((PagePro) page).getSourceLength() == srcFile.length()) {
PagePro pp = (PagePro) page;
try {
same = pp.getHash() == PageSourceCode.toString(this, config.getTemplateCharset()).hashCode();
}
catch (IOException e) {
}

}
if (!same) {
LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "recompile [" + getDisplayPath() + "] because loaded page has changed");
pcn.set(page = compile(config, mapping.getClassRootDirectory(), page, false, pc.ignoreScopes()));
page.setPageSource(this);
}
if (!same) {
LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "recompile [" + getDisplayPath() + "] because loaded page has changed");
pcn.set(page = compile(config, mapping.getClassRootDirectory(), page, false, pc.ignoreScopes()));
page.setPageSource(this);
}
}
}
}
page.setLoadType(LOAD_PHYSICAL);
pci.setPageUsed(page);
return page;
}
// page doesn't exist
else {
synchronized (this) {
Resource classRootDir = mapping.getClassRootDirectory();
Resource classFile = classRootDir.getRealResource(getJavaName() + ".class");
boolean isNew = false;
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="5.4.3.6-SNAPSHOT"/>
<property name="version" value="5.4.3.7-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.4.3.6-SNAPSHOT</version>
<version>5.4.3.7-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 10bcb41

Please sign in to comment.