HHH-2875 : cglib+asm repackage;

HHH-2506 : make javassist the default bytecode provider

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14682 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-05-21 20:13:20 +00:00
parent d7b7cabf79
commit 544e93a305
14 changed files with 54 additions and 73 deletions

View File

@ -63,17 +63,11 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cglib</groupId> <groupId>org.hibernate</groupId>
<artifactId>cglib</artifactId> <artifactId>hibernate-cglib-repack</artifactId>
<version>2.1_3</version> <version>2.1_3</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
<version>1.5.3</version>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,9 +2,8 @@ package org.hibernate.bytecode.cglib;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.PropertyAccessException; import org.hibernate.PropertyAccessException;
import net.sf.cglib.beans.BulkBean; import org.hibernate.repackage.cglib.beans.BulkBean;
import net.sf.cglib.beans.BulkBeanException; import org.hibernate.repackage.cglib.beans.BulkBeanException;
import net.sf.cglib.reflect.FastClass;
import java.io.Serializable; import java.io.Serializable;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;

View File

@ -2,15 +2,9 @@ package org.hibernate.bytecode.cglib;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import net.sf.cglib.beans.BulkBean; import org.hibernate.repackage.cglib.beans.BulkBean;
import net.sf.cglib.beans.BulkBeanException; import org.hibernate.repackage.cglib.beans.BulkBeanException;
import net.sf.cglib.reflect.FastClass; import org.hibernate.repackage.cglib.reflect.FastClass;
import net.sf.cglib.transform.ClassFilter;
import net.sf.cglib.transform.ClassTransformer;
import net.sf.cglib.transform.ClassTransformerFactory;
import net.sf.cglib.transform.TransformingClassLoader;
import net.sf.cglib.transform.impl.InterceptFieldFilter;
import net.sf.cglib.transform.impl.InterceptFieldTransformer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.BytecodeProvider;
@ -18,7 +12,6 @@ import org.hibernate.bytecode.ProxyFactoryFactory;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.util.FieldFilter;
import org.hibernate.util.StringHelper; import org.hibernate.util.StringHelper;
import org.objectweb.asm.Type;
/** /**
* Bytecode provider implementation for CGLIB. * Bytecode provider implementation for CGLIB.
@ -29,6 +22,10 @@ public class BytecodeProviderImpl implements BytecodeProvider {
private static final Logger log = LoggerFactory.getLogger( BytecodeProviderImpl.class ); private static final Logger log = LoggerFactory.getLogger( BytecodeProviderImpl.class );
public BytecodeProviderImpl() {
log.warn( "The CGLIB BytecodeProvider impl is considered deprecated and not recommended for use" );
}
public ProxyFactoryFactory getProxyFactoryFactory() { public ProxyFactoryFactory getProxyFactoryFactory() {
return new ProxyFactoryFactoryImpl(); return new ProxyFactoryFactoryImpl();
} }

View File

@ -6,25 +6,25 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import net.sf.cglib.transform.ClassTransformer; import org.hibernate.repackage.cglib.transform.ClassTransformer;
import net.sf.cglib.transform.TransformingClassGenerator; import org.hibernate.repackage.cglib.transform.TransformingClassGenerator;
import net.sf.cglib.transform.ClassReaderGenerator; import org.hibernate.repackage.cglib.transform.ClassReaderGenerator;
import net.sf.cglib.transform.impl.InterceptFieldEnabled; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled;
import net.sf.cglib.transform.impl.InterceptFieldFilter; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldFilter;
import net.sf.cglib.transform.impl.InterceptFieldTransformer; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldTransformer;
import net.sf.cglib.core.ClassNameReader; import org.hibernate.repackage.cglib.core.ClassNameReader;
import net.sf.cglib.core.DebuggingClassWriter; import org.hibernate.repackage.cglib.core.DebuggingClassWriter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.hibernate.bytecode.AbstractClassTransformerImpl; import org.hibernate.bytecode.AbstractClassTransformerImpl;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.util.FieldFilter;
import org.hibernate.bytecode.util.ClassFilter; import org.hibernate.bytecode.util.ClassFilter;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.objectweb.asm.Attribute; import org.hibernate.repackage.cglib.asm.Attribute;
import org.objectweb.asm.Type; import org.hibernate.repackage.cglib.asm.Type;
import org.objectweb.asm.ClassReader; import org.hibernate.repackage.cglib.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.hibernate.repackage.cglib.asm.ClassWriter;
import org.objectweb.asm.attrs.Attributes; import org.hibernate.repackage.cglib.asm.attrs.Attributes;
/** /**
* Enhance the classes allowing them to implements InterceptFieldEnabled * Enhance the classes allowing them to implements InterceptFieldEnabled

View File

@ -1,7 +1,7 @@
package org.hibernate.bytecode.cglib; package org.hibernate.bytecode.cglib;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.ReflectionOptimizer;
import net.sf.cglib.reflect.FastClass; import org.hibernate.repackage.cglib.reflect.FastClass;
import org.hibernate.InstantiationException; import org.hibernate.InstantiationException;
import java.io.Serializable; import java.io.Serializable;

View File

@ -6,13 +6,13 @@ import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory; import org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import net.sf.cglib.proxy.Enhancer; import org.hibernate.repackage.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.CallbackFilter; import org.hibernate.repackage.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.MethodInterceptor; import org.hibernate.repackage.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; import org.hibernate.repackage.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.NoOp; import org.hibernate.repackage.cglib.proxy.NoOp;
import net.sf.cglib.proxy.Callback; import org.hibernate.repackage.cglib.proxy.Callback;
import net.sf.cglib.proxy.Factory; import org.hibernate.repackage.cglib.proxy.Factory;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;

View File

@ -681,9 +681,8 @@ public final class Environment {
return (String) ISOLATION_LEVELS.get( new Integer(isolation) ); return (String) ISOLATION_LEVELS.get( new Integer(isolation) );
} }
public static BytecodeProvider buildBytecodeProvider(Properties properties) { public static BytecodeProvider buildBytecodeProvider(Properties properties) {
String provider = PropertiesHelper.getString( Environment.BYTECODE_PROVIDER, properties, "cglib" ); String provider = PropertiesHelper.getString( BYTECODE_PROVIDER, properties, "javassist" );
log.info( "Bytecode provider name : " + provider ); log.info( "Bytecode provider name : " + provider );
return buildBytecodeProvider( provider ); return buildBytecodeProvider( provider );
} }
@ -695,10 +694,9 @@ public final class Environment {
else if ( "cglib".equals( providerName ) ) { else if ( "cglib".equals( providerName ) ) {
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl(); return new org.hibernate.bytecode.cglib.BytecodeProviderImpl();
} }
else {
log.warn( "unrecognized bytecode provider [" + providerName + "], using cglib by default" ); log.warn( "unrecognized bytecode provider [" + providerName + "], using javassist by default" );
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl(); return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
}
} }
} }

View File

@ -26,7 +26,7 @@ public class FieldInterceptionHelper {
public static boolean isInstrumented(Class entityClass) { public static boolean isInstrumented(Class entityClass) {
Class[] definedInterfaces = entityClass.getInterfaces(); Class[] definedInterfaces = entityClass.getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) { for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) if ( "org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() )
|| "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) { || "org.hibernate.bytecode.javassist.FieldHandled".equals( definedInterfaces[i].getName() ) ) {
return true; return true;
} }
@ -44,7 +44,7 @@ public class FieldInterceptionHelper {
} }
Class[] definedInterfaces = entity.getClass().getInterfaces(); Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) { for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) { if ( "org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) {
// we have a CGLIB enhanced entity // we have a CGLIB enhanced entity
return CGLIBHelper.extractFieldInterceptor( entity ); return CGLIBHelper.extractFieldInterceptor( entity );
} }
@ -64,7 +64,7 @@ public class FieldInterceptionHelper {
if ( entity != null ) { if ( entity != null ) {
Class[] definedInterfaces = entity.getClass().getInterfaces(); Class[] definedInterfaces = entity.getClass().getInterfaces();
for ( int i = 0; i < definedInterfaces.length; i++ ) { for ( int i = 0; i < definedInterfaces.length; i++ ) {
if ( "net.sf.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) { if ( "org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled".equals( definedInterfaces[i].getName() ) ) {
// we have a CGLIB enhanced entity // we have a CGLIB enhanced entity
return CGLIBHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session ); return CGLIBHelper.injectFieldInterceptor( entity, entityName, uninitializedFieldNames, session );
} }

View File

@ -2,7 +2,7 @@ package org.hibernate.intercept.cglib;
import org.hibernate.intercept.FieldInterceptor; import org.hibernate.intercept.FieldInterceptor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import net.sf.cglib.transform.impl.InterceptFieldEnabled; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled;
import java.util.Set; import java.util.Set;

View File

@ -4,7 +4,7 @@ package org.hibernate.intercept.cglib;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import net.sf.cglib.transform.impl.InterceptFieldCallback; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldCallback;
import org.hibernate.intercept.AbstractFieldInterceptor; import org.hibernate.intercept.AbstractFieldInterceptor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
@ -25,9 +25,9 @@ public final class FieldInterceptorImpl extends AbstractFieldInterceptor impleme
/** /**
* Package-protected constructor * Package-protected constructor
* *
* @param session * @param session The Hibernate session
* @param uninitializedFields * @param uninitializedFields Names of the fields we need to initialize on load
* @param entityName * @param entityName The entity name to which we are being bound
*/ */
FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) { FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) {
super( session, uninitializedFields, entityName ); super( session, uninitializedFields, entityName );

View File

@ -5,11 +5,11 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import net.sf.cglib.proxy.Callback; import org.hibernate.repackage.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter; import org.hibernate.repackage.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer; import org.hibernate.repackage.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler; import org.hibernate.repackage.cglib.proxy.InvocationHandler;
import net.sf.cglib.proxy.NoOp; import org.hibernate.repackage.cglib.proxy.NoOp;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LazyInitializationException; import org.hibernate.LazyInitializationException;

View File

@ -6,12 +6,12 @@ import org.hibernate.bytecode.util.ClassDescriptor;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl; import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
import org.hibernate.bytecode.ClassTransformer; import org.hibernate.bytecode.ClassTransformer;
import org.hibernate.tool.instrument.BasicInstrumentationTask; import org.hibernate.tool.instrument.BasicInstrumentationTask;
import org.objectweb.asm.ClassReader; import org.hibernate.repackage.cglib.asm.ClassReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import net.sf.cglib.core.ClassNameReader; import org.hibernate.repackage.cglib.core.ClassNameReader;
import net.sf.cglib.transform.impl.InterceptFieldEnabled; import org.hibernate.repackage.cglib.transform.impl.InterceptFieldEnabled;
/** /**
* An Ant task for instrumenting persistent classes in order to enable * An Ant task for instrumenting persistent classes in order to enable

View File

@ -34,15 +34,10 @@
<version>3.4.GA</version> <version>3.4.GA</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cglib</groupId> <groupId>org.hibernate</groupId>
<artifactId>cglib</artifactId> <artifactId>hibernate-cglib-repack</artifactId>
<version>2.1_3</version> <version>2.1_3</version>
</dependency> </dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
<version>1.5.3</version>
</dependency>
<!-- optional dom4j dependency; needed here for dom4j (de)serialization --> <!-- optional dom4j dependency; needed here for dom4j (de)serialization -->
<dependency> <dependency>
<groupId>jaxen</groupId> <groupId>jaxen</groupId>

View File

@ -7,10 +7,8 @@ import org.hibernate.proxy.*;
import org.hibernate.test.bytecode.*; import org.hibernate.test.bytecode.*;
import junit.framework.*; import junit.framework.*;
import java.text.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import net.sf.cglib.proxy.*;
/** /**
* Test that the static thread local callback object is cleared out of the proxy class after instantiated. * Test that the static thread local callback object is cleared out of the proxy class after instantiated.