HHH-13097 Cache a static ByteBuddy matcher

This commit is contained in:
Guillaume Smet 2018-11-13 17:11:28 +01:00 committed by Gail Badner
parent 38e48ef0bc
commit af519e3c12
1 changed files with 6 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import org.hibernate.internal.CoreMessageLogger;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.field.FieldDescription;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.modifier.Visibility;
@ -39,12 +40,15 @@ import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.jar.asm.Type;
import net.bytebuddy.matcher.ElementMatcher.Junction;
import net.bytebuddy.pool.TypePool;
final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper {
private static final CoreMessageLogger log = CoreLogging.messageLogger( PersistentAttributeTransformer.class );
private static final Junction<MethodDescription> NOT_HIBERNATE_GENERATED = not( nameStartsWith( "$$_hibernate_" ) );
private final TypeDescription managedCtClass;
private final ByteBuddyEnhancementContext enhancementContext;
@ -172,7 +176,7 @@ final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDecla
DynamicType.Builder<?> applyTo(DynamicType.Builder<?> builder, boolean accessor) {
boolean compositeOwner = false;
builder = builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().invokable( not( nameStartsWith( "$$_hibernate_" ) ), this ) );
builder = builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().invokable( NOT_HIBERNATE_GENERATED, this ) );
for ( AnnotatedFieldDescription enhancedField : enhancedFields ) {
builder = builder
.defineMethod(
@ -254,7 +258,7 @@ final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDecla
DynamicType.Builder<?> applyExtended(DynamicType.Builder<?> builder) {
AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper enhancer = new FieldAccessEnhancer( managedCtClass, enhancementContext, classPool );
return builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().invokable( not( nameStartsWith( "$$_hibernate_" ) ), enhancer ) );
return builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().invokable( NOT_HIBERNATE_GENERATED, enhancer ) );
}
private static class FieldMethodReader implements ByteCodeAppender {