HHH-7773 - Backout HHH-7544 (Pull Request 379)
This commit is contained in:
parent
0251d13adc
commit
0d2a967fc3
|
@ -25,13 +25,9 @@ package org.hibernate.bytecode.buildtime.internal;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javassist.ClassClassPath;
|
|
||||||
import javassist.ClassPool;
|
|
||||||
import javassist.bytecode.ClassFile;
|
import javassist.bytecode.ClassFile;
|
||||||
|
|
||||||
import org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter;
|
import org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter;
|
||||||
|
@ -48,7 +44,6 @@ import org.hibernate.bytecode.spi.ClassTransformer;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Muga Nishizawa
|
* @author Muga Nishizawa
|
||||||
* @author Dustin Schultz
|
|
||||||
*/
|
*/
|
||||||
public class JavassistInstrumenter extends AbstractInstrumenter {
|
public class JavassistInstrumenter extends AbstractInstrumenter {
|
||||||
|
|
||||||
|
@ -75,20 +70,6 @@ public class JavassistInstrumenter extends AbstractInstrumenter {
|
||||||
return provider.getTransformer( CLASS_FILTER, new CustomFieldFilter( descriptor, classNames ) );
|
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 static class CustomClassDescriptor implements ClassDescriptor {
|
||||||
private final byte[] bytes;
|
private final byte[] bytes;
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javassist.CannotCompileException;
|
import javassist.CannotCompileException;
|
||||||
import javassist.ClassPool;
|
|
||||||
import javassist.bytecode.AccessFlag;
|
import javassist.bytecode.AccessFlag;
|
||||||
import javassist.bytecode.BadBytecode;
|
import javassist.bytecode.BadBytecode;
|
||||||
import javassist.bytecode.Bytecode;
|
import javassist.bytecode.Bytecode;
|
||||||
|
@ -44,8 +43,6 @@ import javassist.bytecode.Descriptor;
|
||||||
import javassist.bytecode.FieldInfo;
|
import javassist.bytecode.FieldInfo;
|
||||||
import javassist.bytecode.MethodInfo;
|
import javassist.bytecode.MethodInfo;
|
||||||
import javassist.bytecode.Opcode;
|
import javassist.bytecode.Opcode;
|
||||||
import javassist.bytecode.StackMapTable;
|
|
||||||
import javassist.bytecode.stackmap.MapMaker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The thing that handles actual class enhancement in regards to
|
* The thing that handles actual class enhancement in regards to
|
||||||
|
@ -53,7 +50,6 @@ import javassist.bytecode.stackmap.MapMaker;
|
||||||
*
|
*
|
||||||
* @author Muga Nishizawa
|
* @author Muga Nishizawa
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Dustin Schultz
|
|
||||||
*/
|
*/
|
||||||
public class FieldTransformer {
|
public class FieldTransformer {
|
||||||
|
|
||||||
|
@ -134,7 +130,7 @@ public class FieldTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGetFieldHandlerMethod(ClassFile classfile)
|
private void addGetFieldHandlerMethod(ClassFile classfile)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
ConstPool cp = classfile.getConstPool();
|
ConstPool cp = classfile.getConstPool();
|
||||||
int this_class_index = cp.getThisClassInfo();
|
int this_class_index = cp.getThisClassInfo();
|
||||||
MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
|
MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
|
||||||
|
@ -152,13 +148,11 @@ public class FieldTransformer {
|
||||||
code.addOpcode(Opcode.ARETURN);
|
code.addOpcode(Opcode.ARETURN);
|
||||||
minfo.setCodeAttribute(code.toCodeAttribute());
|
minfo.setCodeAttribute(code.toCodeAttribute());
|
||||||
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
||||||
StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
|
|
||||||
minfo.getCodeAttribute().setAttribute(smt);
|
|
||||||
classfile.addMethod(minfo);
|
classfile.addMethod(minfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSetFieldHandlerMethod(ClassFile classfile)
|
private void addSetFieldHandlerMethod(ClassFile classfile)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
ConstPool cp = classfile.getConstPool();
|
ConstPool cp = classfile.getConstPool();
|
||||||
int this_class_index = cp.getThisClassInfo();
|
int this_class_index = cp.getThisClassInfo();
|
||||||
MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
|
MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
|
||||||
|
@ -178,8 +172,6 @@ public class FieldTransformer {
|
||||||
code.addOpcode(Opcode.RETURN);
|
code.addOpcode(Opcode.RETURN);
|
||||||
minfo.setCodeAttribute(code.toCodeAttribute());
|
minfo.setCodeAttribute(code.toCodeAttribute());
|
||||||
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
||||||
StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
|
|
||||||
minfo.getCodeAttribute().setAttribute(smt);
|
|
||||||
classfile.addMethod(minfo);
|
classfile.addMethod(minfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +185,7 @@ public class FieldTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addReadWriteMethods(ClassFile classfile)
|
private void addReadWriteMethods(ClassFile classfile)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
List fields = classfile.getFields();
|
List fields = classfile.getFields();
|
||||||
for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
|
for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
|
||||||
FieldInfo finfo = (FieldInfo) field_iter.next();
|
FieldInfo finfo = (FieldInfo) field_iter.next();
|
||||||
|
@ -213,7 +205,7 @@ public class FieldTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addReadMethod(ClassFile classfile, FieldInfo finfo)
|
private void addReadMethod(ClassFile classfile, FieldInfo finfo)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
ConstPool cp = classfile.getConstPool();
|
ConstPool cp = classfile.getConstPool();
|
||||||
int this_class_index = cp.getThisClassInfo();
|
int this_class_index = cp.getThisClassInfo();
|
||||||
String desc = "()" + finfo.getDescriptor();
|
String desc = "()" + finfo.getDescriptor();
|
||||||
|
@ -262,13 +254,11 @@ public class FieldTransformer {
|
||||||
|
|
||||||
minfo.setCodeAttribute(code.toCodeAttribute());
|
minfo.setCodeAttribute(code.toCodeAttribute());
|
||||||
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
||||||
StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
|
|
||||||
minfo.getCodeAttribute().setAttribute(smt);
|
|
||||||
classfile.addMethod(minfo);
|
classfile.addMethod(minfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
|
private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
ConstPool cp = classfile.getConstPool();
|
ConstPool cp = classfile.getConstPool();
|
||||||
int this_class_index = cp.getThisClassInfo();
|
int this_class_index = cp.getThisClassInfo();
|
||||||
String desc = "(" + finfo.getDescriptor() + ")V";
|
String desc = "(" + finfo.getDescriptor() + ")V";
|
||||||
|
@ -330,13 +320,11 @@ public class FieldTransformer {
|
||||||
|
|
||||||
minfo.setCodeAttribute(code.toCodeAttribute());
|
minfo.setCodeAttribute(code.toCodeAttribute());
|
||||||
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
minfo.setAccessFlags(AccessFlag.PUBLIC);
|
||||||
StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
|
|
||||||
minfo.getCodeAttribute().setAttribute(smt);
|
|
||||||
classfile.addMethod(minfo);
|
classfile.addMethod(minfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
|
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
|
||||||
throws CannotCompileException, BadBytecode {
|
throws CannotCompileException {
|
||||||
List methods = classfile.getMethods();
|
List methods = classfile.getMethods();
|
||||||
for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
|
for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
|
||||||
MethodInfo minfo = (MethodInfo) method_iter.next();
|
MethodInfo minfo = (MethodInfo) method_iter.next();
|
||||||
|
@ -353,13 +341,15 @@ public class FieldTransformer {
|
||||||
}
|
}
|
||||||
CodeIterator iter = codeAttr.iterator();
|
CodeIterator iter = codeAttr.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
int pos = iter.next();
|
try {
|
||||||
pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
|
int pos = iter.next();
|
||||||
pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue