Search in sources :

Example 6 with ExampleClass

use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.

the class ClassByExtensionBenchmarkTest method testByteBuddySpecializedClassCreation.

@Test
public void testByteBuddySpecializedClassCreation() throws Exception {
    ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddySpecialized();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)));
    assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS));
    assertThat(classByExtensionBenchmark.benchmarkByteBuddySpecialized().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass())));
    assertReturnValues(instance);
}
Also used : ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) Test(org.junit.Test)

Example 7 with ExampleClass

use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.

the class ClassByExtensionBenchmark method benchmarkJavassist.

/**
     * Performs a benchmark of a class extension using javassist proxies.
     *
     * @return The created instance, in order to avoid JIT removal.
     * @throws java.lang.Exception If the invocation causes an exception.
     */
@Benchmark
public ExampleClass benchmarkJavassist() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory() {

        @Override
        protected ClassLoader getClassLoader() {
            return newClassLoader();
        }
    };
    proxyFactory.setUseCache(false);
    proxyFactory.setSuperclass(baseClass);
    proxyFactory.setFilter(new MethodFilter() {

        public boolean isHandled(Method method) {
            return method.getDeclaringClass() == baseClass;
        }
    });
    @SuppressWarnings("unchecked") Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
    ((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {

        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
            return proceed.invoke(self, args);
        }
    });
    return (ExampleClass) instance;
}
Also used : MethodHandler(javassist.util.proxy.MethodHandler) ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) ProxyFactory(javassist.util.proxy.ProxyFactory) MethodFilter(javassist.util.proxy.MethodFilter) Method(java.lang.reflect.Method)

Example 8 with ExampleClass

use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.

the class ClassByExtensionBenchmarkTest method testByteBuddyWithProxiesClassCreation.

@Test
public void testByteBuddyWithProxiesClassCreation() throws Exception {
    ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithProxy();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)));
    assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS));
    assertThat(classByExtensionBenchmark.benchmarkByteBuddyWithProxy().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass())));
    assertReturnValues(instance);
}
Also used : ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) Test(org.junit.Test)

Example 9 with ExampleClass

use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.

the class ClassByExtensionBenchmarkTest method testByteBuddyWithProxiesClassCreationWithTypePool.

@Test
public void testByteBuddyWithProxiesClassCreationWithTypePool() throws Exception {
    ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithProxyWithTypePool();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)));
    assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS));
    assertThat(classByExtensionBenchmark.benchmarkByteBuddyWithProxy().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass())));
    assertReturnValues(instance);
}
Also used : ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) Test(org.junit.Test)

Example 10 with ExampleClass

use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.

the class ClassByExtensionBenchmarkTest method testByteBuddyWithPrefixClassCreationWithTypePool.

@Test
public void testByteBuddyWithPrefixClassCreationWithTypePool() throws Exception {
    ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithPrefixWithTypePool();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)));
    assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS));
    assertThat(classByExtensionBenchmark.benchmarkByteBuddyWithProxy().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass())));
    assertReturnValues(instance);
}
Also used : ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) ExampleClass(net.bytebuddy.benchmark.specimen.ExampleClass) Test(org.junit.Test)

Aggregations

ExampleClass (net.bytebuddy.benchmark.specimen.ExampleClass)17 Test (org.junit.Test)16 Method (java.lang.reflect.Method)1 MethodFilter (javassist.util.proxy.MethodFilter)1 MethodHandler (javassist.util.proxy.MethodHandler)1 ProxyFactory (javassist.util.proxy.ProxyFactory)1