Search in sources :

Example 1 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class Union method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if (accessor != null) {
        return accessor.getValue(main.getReducedValueAccelerated(ctx, thisValue, factory), thisValue, factory);
    } else {
        try {
            AccessorOptimizer o = OptimizerFactory.getThreadAccessorOptimizer();
            accessor = o.optimizeAccessor(getCurrentThreadParserContext(), expr, start, offset, main.getReducedValueAccelerated(ctx, thisValue, factory), thisValue, factory, false, main.getEgressType());
            return o.getResultOptPass();
        } finally {
            OptimizerFactory.clearThreadAccessorOptimizer();
        }
    }
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Example 2 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class LiteralDeepPropertyNode method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if (accessor != null) {
        return accessor.getValue(literal, thisValue, factory);
    } else {
        try {
            AccessorOptimizer aO = getThreadAccessorOptimizer();
            accessor = aO.optimizeAccessor(getCurrentThreadParserContext(), expr, start, offset, literal, thisValue, factory, false, null);
            return aO.getResultOptPass();
        } finally {
            OptimizerFactory.clearThreadAccessorOptimizer();
        }
    }
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer) OptimizerFactory.getThreadAccessorOptimizer(org.mvel2.optimizers.OptimizerFactory.getThreadAccessorOptimizer)

Example 3 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class OptimizerFactory method setDefaultOptimizer.

public static void setDefaultOptimizer(String name) {
    try {
        //noinspection unchecked
        AccessorOptimizer ao = accessorCompilers.get(defaultOptimizer = name);
        ao.init();
        setThreadAccessorOptimizer(ao.getClass());
    } catch (Exception e) {
        throw new RuntimeException("unable to instantiate accessor compiler", e);
    }
}
Also used : ASMAccessorOptimizer(org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer) ReflectiveAccessorOptimizer(org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer)

Example 4 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class DynamicSetAccessor method optimize.

private Object optimize(Object ctx, Object elCtx, VariableResolverFactory variableResolverFactory, Object value) {
    if (DynamicOptimizer.isOverloaded()) {
        DynamicOptimizer.enforceTenureLimit();
    }
    AccessorOptimizer ao = OptimizerFactory.getAccessorCompiler("ASM");
    _accessor = ao.optimizeSetAccessor(context, property, start, offset, ctx, elCtx, variableResolverFactory, false, value, value != null ? value.getClass() : Object.class);
    assert _accessor != null;
    return value;
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Example 5 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class ASTNode method optimize.

private Object optimize(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if ((fields & DEOP) != 0) {
        fields ^= DEOP;
    }
    AccessorOptimizer optimizer;
    Object retVal = null;
    if ((fields & NOJIT) != 0 || factory != null && factory.isResolveable(nameCache)) {
        optimizer = getAccessorCompiler(SAFE_REFLECTIVE);
    } else {
        optimizer = getDefaultAccessorCompiler();
    }
    ParserContext pCtx;
    if ((fields & PCTX_STORED) != 0) {
        pCtx = (ParserContext) literal;
    } else {
        pCtx = new ParserContext(new ParserConfiguration(getInjectedImports(factory), null));
    }
    try {
        pCtx.optimizationNotify();
        setAccessor(optimizer.optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, egressType));
    } catch (OptimizationNotSupported ne) {
        setAccessor((optimizer = getAccessorCompiler(SAFE_REFLECTIVE)).optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, null));
    }
    if (accessor == null) {
        return get(expr, start, offset, ctx, factory, thisValue);
    }
    if (retVal == null) {
        retVal = optimizer.getResultOptPass();
    }
    if (egressType == null) {
        egressType = optimizer.getEgressType();
    }
    return retVal;
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer) ParserContext(org.mvel2.ParserContext) OptimizationNotSupported(org.mvel2.optimizers.OptimizationNotSupported) ParserConfiguration(org.mvel2.ParserConfiguration)

Aggregations

AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)7 ParserContext (org.mvel2.ParserContext)2 OptimizerFactory.getThreadAccessorOptimizer (org.mvel2.optimizers.OptimizerFactory.getThreadAccessorOptimizer)2 CompileException (org.mvel2.CompileException)1 ParserConfiguration (org.mvel2.ParserConfiguration)1 OptimizationNotSupported (org.mvel2.optimizers.OptimizationNotSupported)1 ASMAccessorOptimizer (org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer)1 ReflectiveAccessorOptimizer (org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer)1