From 0d2a967fc38ee354227ddb873299b2745781c104 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Sun, 11 Nov 2012 23:26:53 +0800 Subject: [PATCH] HHH-7773 - Backout HHH-7544 (Pull Request 379) --- .../internal/JavassistInstrumenter.java | 19 ---------- .../internal/javassist/FieldTransformer.java | 38 +++++++------------ 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/buildtime/internal/JavassistInstrumenter.java b/hibernate-core/src/main/java/org/hibernate/bytecode/buildtime/internal/JavassistInstrumenter.java index e3c4bd8513..1182ed9d18 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/buildtime/internal/JavassistInstrumenter.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/buildtime/internal/JavassistInstrumenter.java @@ -25,13 +25,9 @@ package org.hibernate.bytecode.buildtime.internal; 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 @@ import org.hibernate.bytecode.spi.ClassTransformer; * * @author Steve Ebersole * @author Muga Nishizawa - * @author Dustin Schultz */ public class JavassistInstrumenter extends AbstractInstrumenter { @@ -75,20 +70,6 @@ public class JavassistInstrumenter extends AbstractInstrumenter { return provider.getTransformer( CLASS_FILTER, new CustomFieldFilter( descriptor, classNames ) ); } } - - @Override - public void execute(Set 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; diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldTransformer.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldTransformer.java index 300238fee4..2e547c3627 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldTransformer.java @@ -32,7 +32,6 @@ import java.util.Iterator; import java.util.List; import javassist.CannotCompileException; -import javassist.ClassPool; import javassist.bytecode.AccessFlag; import javassist.bytecode.BadBytecode; import javassist.bytecode.Bytecode; @@ -44,8 +43,6 @@ import javassist.bytecode.Descriptor; 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 @@ -53,7 +50,6 @@ import javassist.bytecode.stackmap.MapMaker; * * @author Muga Nishizawa * @author Steve Ebersole - * @author Dustin Schultz */ public class FieldTransformer { @@ -134,7 +130,7 @@ public class FieldTransformer { } 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 @@ public class FieldTransformer { 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 @@ public class FieldTransformer { 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 @@ public class FieldTransformer { } 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 @@ public class FieldTransformer { } 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 @@ public class FieldTransformer { 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 @@ public class FieldTransformer { 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 @@ public class FieldTransformer { } 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); } }