Skip to content

Commit

Permalink
inital version switching from reflection to ASM bytecode genration
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Mar 22, 2024
1 parent 5bf1317 commit 01717be
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 76 deletions.
2 changes: 1 addition & 1 deletion ant/build-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<property name="extHibernate" value="FAD1E8CB-4F45-4184-86359145767C29DE;version=5.4.29.27-BETA"/>

<property name="stableLoader" value="lucee-5.3.7.48"/>
<property name="javaVersionCoreDefault" value="21"/>
<property name="javaVersionCoreDefault" value="11"/>
<property name="javaVersionAgent" value="11"/>
<property name="javaVersionLoader" value="11"/>
<property name="cdnUrl" value="https://cdn.lucee.org/"/>
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.Md5;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.commons.lang.SerializableObject;
import lucee.commons.lang.StringUtil;
import lucee.commons.lang.types.RefBoolean;
import lucee.commons.net.IPRange;
Expand Down Expand Up @@ -175,6 +176,7 @@ public abstract class ConfigImpl extends ConfigBase implements ConfigPro {
private int mode = MODE_CUSTOM;

private final Map<String, PhysicalClassLoader> rpcClassLoaders = new ConcurrentHashMap<String, PhysicalClassLoader>();
private PhysicalClassLoader directClassLoader;
private Map<String, DataSource> datasources = new HashMap<String, DataSource>();
private Map<String, CacheConnection> caches = new HashMap<String, CacheConnection>();

Expand Down Expand Up @@ -2252,6 +2254,23 @@ public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) thro
return rpccl;
}

private static final Object dclt = new SerializableObject();

public PhysicalClassLoader getDirectClassLoader(boolean reload) throws IOException {
if (directClassLoader == null || reload) {
synchronized (dclt) {
if (directClassLoader == null || reload) {
Resource dir = getClassDirectory().getRealResource("direct/");
if (!dir.exists()) {
ResourceUtil.createDirectoryEL(dir, true);
}
directClassLoader = new PhysicalClassLoader(this, dir, null);
}
}
}
return directClassLoader;
}

private String toKey(ClassLoader[] parents) {
if (parents == null || parents.length == 0) return "orphan";

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lucee.commons.io.res.util.ResourceClassLoader;
import lucee.commons.lang.CharSet;
import lucee.commons.lang.ClassException;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.commons.lang.types.RefBoolean;
import lucee.runtime.CIPage;
import lucee.runtime.Mapping;
Expand Down Expand Up @@ -377,4 +378,6 @@ public Resource[] getResources(PageContext pc, Mapping[] mappings, String realPa
public boolean getFormUrlAsStruct();

public int getReturnFormat();

public PhysicalClassLoader getDirectClassLoader(boolean reload) throws IOException;
}
6 changes: 6 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigWebImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import lucee.commons.io.res.Resource;
import lucee.commons.io.res.ResourcesImpl.ResourceProviderFactory;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.runtime.config.gateway.GatewayMap;
import lucee.runtime.exp.PageException;
import lucee.runtime.writer.CFMLWriter;
Expand Down Expand Up @@ -778,6 +779,11 @@ public java.lang.ClassLoader getRPCClassLoader(boolean arg0, java.lang.ClassLoad
return instance.getRPCClassLoader(arg0, arg1);
}

@Override
public PhysicalClassLoader getDirectClassLoader(boolean reload) throws IOException {
return instance.getDirectClassLoader(reload);
}

@Override
public lucee.runtime.config.MockPool getDatasourceConnectionPool() {
return instance.getDatasourceConnectionPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import lucee.commons.io.res.util.ResourceUtil;
import lucee.commons.lang.CharSet;
import lucee.commons.lang.ClassException;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.commons.lang.types.RefBoolean;
import lucee.commons.lock.KeyLock;
import lucee.runtime.CFMLFactory;
Expand Down Expand Up @@ -708,6 +709,11 @@ public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) thro
return cs.getRPCClassLoader(reload, parents);
}

@Override
public PhysicalClassLoader getDirectClassLoader(boolean reload) throws IOException {
return cs.getDirectClassLoader(reload);
}

@Override
public Resource getCacheDir() {
return cs.getCacheDir();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
import lucee.runtime.video.VideoUtil;
import lucee.runtime.video.VideoUtilImpl;
import lucee.servlet.http.HTTPServletImpl;
import lucee.transformer.direct.DirectCallEngine;

/**
* The CFMl Engine
Expand Down Expand Up @@ -931,6 +932,7 @@ private ConfigServerImpl getConfigServerImpl(ConfigServerImpl existing, boolean
}
try {
Resource context = getSeverContextConfigDirectory(factory);
DirectCallEngine.getInstance(context);
ConfigServerImpl tmp = ConfigServerFactory.newInstance(this, initContextes, contextes, context, existing, essentialOnly);
if (essentialOnly) {
return tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@
package lucee.runtime.functions.struct;

import lucee.runtime.PageContext;
import lucee.runtime.exp.FunctionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.BIF;
import lucee.runtime.ext.function.Function;
import lucee.runtime.op.Caster;
import lucee.runtime.type.Struct;

public class JsonStruct implements Function {
public class JsonStruct extends BIF implements Function {

private static final long serialVersionUID = 3030769464899375329L;

public static Struct call(PageContext pc, Object[] objArr) throws PageException {
return Struct_._call(objArr, "invalid argument for JSON struct, only named arguments are allowed like {name:\"value\",name2:\"value2\"}", Struct.TYPE_LINKED);

}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length < 1 || args.length > 1) throw new FunctionException(pc, "JsonStruct", 1, 1, args.length);
return Struct_._call(Caster.toNativeArray(args[0]), "invalid argument for JSON struct, only named arguments are allowed like {name:\"value\",name2:\"value2\"}",
Struct.TYPE_LINKED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@
package lucee.runtime.functions.struct;

import lucee.runtime.PageContext;
import lucee.runtime.exp.FunctionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.BIF;
import lucee.runtime.ext.function.Function;
import lucee.runtime.op.Caster;
import lucee.runtime.type.Struct;

public class LiteralStruct implements Function {
public class LiteralStruct extends BIF implements Function {

private static final long serialVersionUID = 3030769464899375329L;

public static Struct call(PageContext pc, Object[] objArr) throws PageException {
return Struct_._call(objArr, "invalid argument for literal struct, only named arguments are allowed like {name:\"value\",name2:\"value2\"}", -1);
}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length < 1 || args.length > 1) throw new FunctionException(pc, "LiteralStruct", 1, 1, args.length);
return Struct_._call(Caster.toNativeArray(args[0]), "invalid argument for literal struct, only named arguments are allowed like {name:\"value\",name2:\"value2\"}", -1);
}
}
47 changes: 30 additions & 17 deletions core/src/main/java/lucee/runtime/java/JavaObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.List;

import lucee.print;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.runtime.PageContext;
Expand Down Expand Up @@ -104,12 +105,12 @@ public Object get(PageContext pc, String propertyName) throws PageException {
try {
return mi.invoke(null);
}
catch (IllegalAccessException e) {
throw Caster.toPageException(e);
}
catch (InvocationTargetException e) {
throw Caster.toPageException(e.getTargetException());
}
catch (Exception e) {
throw Caster.toPageException(e);
}
}
}
// male Instance
Expand Down Expand Up @@ -144,13 +145,18 @@ public Object get(PageContext pc, String propertyName, Object defaultValue) {
// Getter
MethodInstance mi = Reflector.getGetterEL(clazz, propertyName);
if (mi != null) {
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
try {
return mi.invoke(null);
}
catch (Exception e) {
try {
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
try {
return mi.invoke(null);
}
catch (Exception e) {
}
}
}
catch (PageException e) {
return defaultValue;
}
}
try {
return variableUtil(pc).get(pc, init(), propertyName, defaultValue);
Expand Down Expand Up @@ -191,12 +197,12 @@ public Object set(PageContext pc, Collection.Key propertyName, Object value) thr
try {
return mi.invoke(null);
}
catch (IllegalAccessException e) {
throw Caster.toPageException(e);
}
catch (InvocationTargetException e) {
throw Caster.toPageException(e.getTargetException());
}
catch (Exception e) {
throw Caster.toPageException(e);
}
}
}

Expand Down Expand Up @@ -224,12 +230,12 @@ public Object setEL(PageContext pc, Collection.Key propertyName, Object value) {
// Getter
MethodInstance mi = Reflector.getSetter(clazz, propertyName.getString(), value, null);
if (mi != null) {
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
try {
try {
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
return mi.invoke(null);
}
catch (Exception e) {
}
}
catch (Exception e) {
}
}

Expand Down Expand Up @@ -259,7 +265,8 @@ else if (isInit) {

try {
// get method
MethodInstance mi = Reflector.getMethodInstance(this, clazz, KeyImpl.init(methodName), arguments);
// if ("toHexString".equals(methodName)) print.ds();
MethodInstance mi = Reflector.getMethodInstance(clazz, KeyImpl.init(methodName), arguments);
// call static method if exist
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
return mi.invoke(null);
Expand All @@ -270,14 +277,20 @@ else if (isInit) {
}

// invoke constructor and call instance method
return mi.invoke(init());
Object obj = init();
return mi.invoke(obj);
}
catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if (target instanceof PageException) throw (PageException) target;
throw Caster.toPageException(e.getTargetException());
}
catch (Exception e) {
print.e("------------------------------");
print.e(methodName);
print.e(clazz.getName());
print.e(arguments);

throw Caster.toPageException(e);
}
}
Expand Down
Loading

0 comments on commit 01717be

Please sign in to comment.