Skip to content

Commit

Permalink
LDEV-4817 - improve BytecodeFactory cache
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Mar 13, 2024
1 parent 601c7e9 commit 0d1f7ca
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 30 deletions.
3 changes: 0 additions & 3 deletions core/src/main/java/lucee/transformer/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.math.BigDecimal;

import lucee.runtime.config.Config;
import lucee.runtime.exp.PageException;
import lucee.transformer.expression.ExprBoolean;
import lucee.transformer.expression.ExprInt;
Expand Down Expand Up @@ -182,8 +181,6 @@ public abstract class Factory {

public abstract void registerKey(Context bc, Expression name, boolean doUpperCase) throws TransformerException;

public abstract Config getConfig();

public static boolean canRegisterKey(Expression name) {
return name instanceof LitString;
}
Expand Down
26 changes: 15 additions & 11 deletions core/src/main/java/lucee/transformer/bytecode/BytecodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package lucee.transformer.bytecode;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand Down Expand Up @@ -79,10 +81,20 @@ public class BytecodeFactory extends FactoryBase {

private static final Type KEY_CONSTANTS = Type.getType(KeyConstants.class);

private static BytecodeFactory instance;
private static Map<String, BytecodeFactory> instances = new ConcurrentHashMap<>();

public static Factory getInstance(Config config) {
if (instance == null) instance = new BytecodeFactory(config == null ? ThreadLocalPageContext.getConfig() : config);
if (config == null) config = ThreadLocalPageContext.getConfig();
String key = config.hashCode() + ":" + config.getIdentification().getId();
BytecodeFactory instance = instances.get(key);
if (instance == null) {
synchronized (instances) {
instance = instances.get(key);
if (instance == null) {
instances.put(key, instance = new BytecodeFactory());
}
}
}
return instance;
}

Expand All @@ -93,16 +105,13 @@ public static Factory getInstance(Config config) {
private final LitNumber NUMBER_ZERO;
private final LitNumber NUMBER_ONE;

private final Config config;

public BytecodeFactory(Config config) {
public BytecodeFactory() {
TRUE = createLitBoolean(true);
FALSE = createLitBoolean(false);
EMPTY = createLitString("");
NULL = Null.getSingleInstance(this);
NUMBER_ZERO = createLitNumber(0);
NUMBER_ONE = createLitNumber(1);
this.config = config;
}

@Override
Expand Down Expand Up @@ -340,11 +349,6 @@ public void registerKey(Context c, Expression name, boolean doUpperCase) throws
return;
}

@Override
public Config getConfig() {
return config;
}

@Override
public Expression createStruct() {
return new EmptyStruct(this);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/lucee/transformer/cfml/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class Data {
private Body parent;
public ExprTransformer transformer;

public Data(Factory factory, Page page, SourceCode srcCode, EvaluatorPool ep, TransfomerSettings settings, TagLib[][] tlibs, FunctionLib[] flibs, TagLibTag[] scriptTags,
boolean allowLowerThan) {
public Data(Factory factory, Config config, Page page, SourceCode srcCode, EvaluatorPool ep, TransfomerSettings settings, TagLib[][] tlibs, FunctionLib[] flibs,
TagLibTag[] scriptTags, boolean allowLowerThan) {
this.page = page;
this.srcCode = srcCode;
this.settings = settings;
Expand All @@ -67,7 +67,7 @@ public Data(Factory factory, Page page, SourceCode srcCode, EvaluatorPool ep, Tr
this.scriptTags = scriptTags;
this.ep = ep;
this.factory = factory;
this.config = factory.getConfig();
this.config = config;
this.allowLowerThan = allowLowerThan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws E
transformer = tagLib.getExprTransfomer();
Page page = ASMUtil.getAncestorPage(null, tag);
ConfigPro config = (ConfigPro) page.getConfig();
Data data = new Data(BytecodeFactory.getInstance(config), page, new SourceCode(null, text, false, page.getSourceCode().getDialect()), new EvaluatorPool(),
Data data = new Data(BytecodeFactory.getInstance(config), config, page, new SourceCode(null, text, false, page.getSourceCode().getDialect()), new EvaluatorPool(),
new TransfomerSettings(page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase(),
page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getHandleUnQuotedAttrValueAsString(), page.ignoreScopes),
null, flibs, config.getCoreTagLib(page.getSourceCode().getDialect()).getScriptTags(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ public Page transform(Factory factory, ConfigPro config, SourceCode sc, TagLib[]
Page page = new Page(factory, config, sc, null, ConfigWebUtil.getEngine(config).getInfo().getFullVersionInfo(), sourceLastModified, sc.getWriteLog(),
sc.getDialect() == CFMLEngine.DIALECT_LUCEE || config.getSuppressWSBeforeArg(), config.getDefaultFunctionOutput(), returnValue, ignoreScope);

TransfomerSettings settings = new TransfomerSettings(dnuc, sc.getDialect() == CFMLEngine.DIALECT_CFML && factory.getConfig().getHandleUnQuotedAttrValueAsString(),
ignoreScope);
Data data = new Data(factory, page, sc, new EvaluatorPool(), settings, _tlibs, flibs, config.getCoreTagLib(sc.getDialect()).getScriptTags(), false);
TransfomerSettings settings = new TransfomerSettings(dnuc, sc.getDialect() == CFMLEngine.DIALECT_CFML && config.getHandleUnQuotedAttrValueAsString(), ignoreScope);
Data data = new Data(factory, config, page, sc, new EvaluatorPool(), settings, _tlibs, flibs, config.getCoreTagLib(sc.getDialect()).getScriptTags(), false);
transform(data, page);
return page;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,4 @@ public void registerKey(Context bc, Expression name, boolean doUpperCase) throws
// TODO Auto-generated method stub

}

@Override
public Config getConfig() {
// TODO Auto-generated method stub
return null;
}

}
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="6.0.1.80-SNAPSHOT"/>
<property name="version" value="6.0.1.81-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>6.0.1.80-SNAPSHOT</version>
<version>6.0.1.81-SNAPSHOT</version>
<packaging>jar</packaging>

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

0 comments on commit 0d1f7ca

Please sign in to comment.