use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class ASMAccessorOptimizer method _initJIT.
/**
* Does all the boilerplate for initiating the JIT.
*/
private void _initJIT() {
if (isAdvancedDebugging()) {
buildLog = new StringAppender();
}
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
synchronized (Runtime.getRuntime()) {
cw.visit(OPCODES_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className = "ASMAccessorImpl_" + valueOf(cw.hashCode()).replaceAll("\\-", "_") + (System.currentTimeMillis() / 10) + ((int) Math.random() * 100), null, "java/lang/Object", new String[] { NAMESPACE + "compiler/Accessor" });
}
MethodVisitor m = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
m.visitCode();
m.visitVarInsn(Opcodes.ALOAD, 0);
m.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
m.visitInsn(RETURN);
m.visitMaxs(1, 1);
m.visitEnd();
(mv = cw.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/Object;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;)Ljava/lang/Object;", null, null)).visitCode();
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class ASMAccessorOptimizer method writeOutNullHandler.
private void writeOutNullHandler(Member member, int type) {
assert debug("DUP");
mv.visitInsn(DUP);
Label j = new Label();
assert debug("IFNONNULL : jump");
mv.visitJumpInsn(IFNONNULL, j);
assert debug("POP");
mv.visitInsn(POP);
assert debug("ALOAD 0");
mv.visitVarInsn(ALOAD, 0);
if (type == 0) {
this.propNull = true;
assert debug("GETFIELD 'nullPropertyHandler'");
mv.visitFieldInsn(GETFIELD, className, "nullPropertyHandler", "L" + NAMESPACE + "integration/PropertyHandler;");
} else {
this.methNull = true;
assert debug("GETFIELD 'nullMethodHandler'");
mv.visitFieldInsn(GETFIELD, className, "nullMethodHandler", "L" + NAMESPACE + "integration/PropertyHandler;");
}
assert debug("LDC '" + member.getName() + "'");
mv.visitLdcInsn(member.getName());
assert debug("ALOAD 1");
mv.visitVarInsn(ALOAD, 1);
assert debug("ALOAD 3");
mv.visitVarInsn(ALOAD, 3);
assert debug("INVOKEINTERFACE PropertyHandler.getProperty");
mv.visitMethodInsn(INVOKEINTERFACE, NAMESPACE + "integration/PropertyHandler", "getProperty", "(Ljava/lang/String;Ljava/lang/Object;L" + NAMESPACE + "integration/VariableResolverFactory;)Ljava/lang/Object;");
assert debug("LABEL:jump");
mv.visitLabel(j);
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class ReflectiveAccessorOptimizer method compileConstructor.
@SuppressWarnings({ "WeakerAccess" })
public AccessorNode compileConstructor(char[] expression, Object ctx, VariableResolverFactory vars) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
String[] cnsRes = captureContructorAndResidual(expression, start, length);
List<char[]> constructorParms = parseMethodOrConstructor(cnsRes[0].toCharArray());
if (constructorParms != null) {
String s = new String(subset(expression, 0, ArrayTools.findFirst('(', start, length, expression)));
Class cls = ParseTools.findClass(vars, s, pCtx);
ExecutableStatement[] cStmts = new ExecutableStatement[constructorParms.size()];
for (int i = 0; i < constructorParms.size(); i++) {
cStmts[i] = (ExecutableStatement) subCompileExpression(constructorParms.get(i), pCtx);
}
Object[] parms = new Object[constructorParms.size()];
for (int i = 0; i < constructorParms.size(); i++) {
parms[i] = cStmts[i].getValue(ctx, vars);
}
Constructor cns = getBestConstructorCandidate(parms, cls, pCtx.isStrongTyping());
if (cns == null) {
StringBuilder error = new StringBuilder();
for (int i = 0; i < parms.length; i++) {
error.append(parms[i].getClass().getName());
if (i + 1 < parms.length)
error.append(", ");
}
throw new CompileException("unable to find constructor: " + cls.getName() + "(" + error.toString() + ")", this.expr, this.start);
}
for (int i = 0; i < parms.length; i++) {
// noinspection unchecked
parms[i] = convert(parms[i], cns.getParameterTypes()[i]);
}
AccessorNode ca = new ConstructorAccessor(cns, cStmts);
if (cnsRes.length > 1) {
ReflectiveAccessorOptimizer compiledOptimizer = new ReflectiveAccessorOptimizer(pCtx, cnsRes[1].toCharArray(), 0, cnsRes[1].length(), cns.newInstance(parms), ctx, vars);
compiledOptimizer.ingressType = cns.getDeclaringClass();
compiledOptimizer.setRootNode(ca);
compiledOptimizer.compileGetChain();
ca = compiledOptimizer.getRootNode();
this.val = compiledOptimizer.getResultOptPass();
}
return ca;
} else {
Constructor<?> cns = Class.forName(new String(expression), true, Thread.currentThread().getContextClassLoader()).getConstructor(EMPTYCLS);
AccessorNode ca = new ConstructorAccessor(cns, null);
if (cnsRes.length > 1) {
// noinspection NullArgumentToVariableArgMethod
ReflectiveAccessorOptimizer compiledOptimizer = new ReflectiveAccessorOptimizer(getCurrentThreadParserContext(), cnsRes[1].toCharArray(), 0, cnsRes[1].length(), cns.newInstance(null), ctx, vars);
compiledOptimizer.setRootNode(ca);
compiledOptimizer.compileGetChain();
ca = compiledOptimizer.getRootNode();
this.val = compiledOptimizer.getResultOptPass();
}
return ca;
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class DynamicFunctionAccessor method getValue.
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
Object[] parms = null;
Function function = (Function) ctx;
if (parameters != null && parameters.length != 0) {
parms = new Object[parameters.length];
for (int i = 0; i < parms.length; i++) {
parms[i] = parameters[i].getValue(ctx, elCtx, variableFactory);
}
}
if (nextNode != null) {
return nextNode.getValue(function.call(ctx, elCtx, variableFactory, parms), elCtx, variableFactory);
} else {
return function.call(ctx, elCtx, variableFactory, parms);
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class BaseVariableResolverFactory method appendFactory.
public void appendFactory(VariableResolverFactory resolverFactory) {
if (nextFactory == null) {
nextFactory = resolverFactory;
} else {
VariableResolverFactory vrf = nextFactory;
while (vrf.getNextFactory() != null) {
vrf = vrf.getNextFactory();
}
vrf.setNextFactory(nextFactory);
}
}
Aggregations