Permalink
Browse files

HHH-7773 - Backout HHH-7544 (Pull Request 379)

  • Loading branch information...
1 parent 25036b0 commit 3489b71dcac0d2c611ba6cea57096af99a8f0ab9 @stliu stliu committed Nov 11, 2012
View
19 ...e-core/src/main/java/org/hibernate/bytecode/buildtime/internal/JavassistInstrumenter.java
@@ -25,13 +25,9 @@
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.util.Set;
-import javassist.ClassClassPath;
-import javassist.ClassPool;
import javassist.bytecode.ClassFile;
import org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter;
@@ -48,7 +44,6 @@
*
* @author Steve Ebersole
* @author Muga Nishizawa
- * @author Dustin Schultz
*/
public class JavassistInstrumenter extends AbstractInstrumenter {
@@ -75,20 +70,6 @@ protected ClassTransformer getClassTransformer(ClassDescriptor descriptor, Set c
return provider.getTransformer( CLASS_FILTER, new CustomFieldFilter( descriptor, classNames ) );
}
}
-
- @Override
- public void execute(Set<File> files) {
- ClassPool cp = ClassPool.getDefault();
- cp.insertClassPath(new ClassClassPath(this.getClass()));
- try {
- for (File file : files) {
- cp.makeClass(new FileInputStream(file));
- }
- } catch (IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- super.execute(files);
- }
private static class CustomClassDescriptor implements ClassDescriptor {
private final byte[] bytes;
View
38 hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldTransformer.java
@@ -32,7 +32,6 @@
import java.util.List;
import javassist.CannotCompileException;
-import javassist.ClassPool;
import javassist.bytecode.AccessFlag;
import javassist.bytecode.BadBytecode;
import javassist.bytecode.Bytecode;
@@ -44,16 +43,13 @@
import javassist.bytecode.FieldInfo;
import javassist.bytecode.MethodInfo;
import javassist.bytecode.Opcode;
-import javassist.bytecode.StackMapTable;
-import javassist.bytecode.stackmap.MapMaker;
/**
* The thing that handles actual class enhancement in regards to
* intercepting field accesses.
*
* @author Muga Nishizawa
* @author Steve Ebersole
- * @author Dustin Schultz
*/
public class FieldTransformer {
@@ -134,7 +130,7 @@ private void addFieldHandlerField(ClassFile classfile)
}
private void addGetFieldHandlerMethod(ClassFile classfile)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
@@ -152,13 +148,11 @@ private void addGetFieldHandlerMethod(ClassFile classfile)
code.addOpcode(Opcode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
- StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
- minfo.getCodeAttribute().setAttribute(smt);
classfile.addMethod(minfo);
}
private void addSetFieldHandlerMethod(ClassFile classfile)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
@@ -178,8 +172,6 @@ private void addSetFieldHandlerMethod(ClassFile classfile)
code.addOpcode(Opcode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
- StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
- minfo.getCodeAttribute().setAttribute(smt);
classfile.addMethod(minfo);
}
@@ -193,7 +185,7 @@ private void addFieldHandledInterface(ClassFile classfile) {
}
private void addReadWriteMethods(ClassFile classfile)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
List fields = classfile.getFields();
for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
FieldInfo finfo = (FieldInfo) field_iter.next();
@@ -213,7 +205,7 @@ private void addReadWriteMethods(ClassFile classfile)
}
private void addReadMethod(ClassFile classfile, FieldInfo finfo)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
String desc = "()" + finfo.getDescriptor();
@@ -262,13 +254,11 @@ private void addReadMethod(ClassFile classfile, FieldInfo finfo)
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
- StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
- minfo.getCodeAttribute().setAttribute(smt);
classfile.addMethod(minfo);
}
private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
String desc = "(" + finfo.getDescriptor() + ")V";
@@ -330,13 +320,11 @@ private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
- StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
- minfo.getCodeAttribute().setAttribute(smt);
classfile.addMethod(minfo);
}
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
- throws CannotCompileException, BadBytecode {
+ throws CannotCompileException {
List methods = classfile.getMethods();
for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
MethodInfo minfo = (MethodInfo) method_iter.next();
@@ -353,13 +341,15 @@ private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
}
CodeIterator iter = codeAttr.iterator();
while (iter.hasNext()) {
- int pos = iter.next();
- pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
- pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);
+ try {
+ int pos = iter.next();
+ pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
+ pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);
+ } catch ( BadBytecode e ){
+ throw new CannotCompileException( e );
+ }
+
}
-
- StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
- minfo.getCodeAttribute().setAttribute(smt);
}
}

0 comments on commit 3489b71

Please sign in to comment.