Search in sources :

Example 1 with FixedValue

use of net.sf.cglib.proxy.FixedValue in project byte-buddy by raphw.

the class ClassByImplementationBenchmark method benchmarkCglib.

/**
     * Performs a benchmark of an interface implementation using cglib.
     *
     * @return The created instance, in order to avoid JIT removal.
     */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[] { baseClass }) {

        @Override
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {

                    @Override
                    public Object loadObject() throws Exception {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) CallbackHelper(net.sf.cglib.proxy.CallbackHelper) FixedValue(net.sf.cglib.proxy.FixedValue) StubMethod(net.bytebuddy.implementation.StubMethod) Method(java.lang.reflect.Method) ExampleInterface(net.bytebuddy.benchmark.specimen.ExampleInterface)

Aggregations

Method (java.lang.reflect.Method)1 ExampleInterface (net.bytebuddy.benchmark.specimen.ExampleInterface)1 StubMethod (net.bytebuddy.implementation.StubMethod)1 CallbackHelper (net.sf.cglib.proxy.CallbackHelper)1 Enhancer (net.sf.cglib.proxy.Enhancer)1 FixedValue (net.sf.cglib.proxy.FixedValue)1