Skip to content

Commit 0ab513b

Browse files
committed
HHH-19571 Make AccessOptimizer bytecode generation deterministic
1 parent 22ea56f commit 0ab513b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Iterator;
1919
import java.util.List;
2020
import java.util.Map;
21-
import java.util.concurrent.Callable;
2221

2322
import org.hibernate.HibernateException;
2423
import org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl;
@@ -184,7 +183,7 @@ public ReflectionOptimizer getReflectionOptimizer(
184183
.method( setPropertyValuesMethodName )
185184
.intercept( new Implementation.Simple( new SetPropertyValues( clazz, getterNames, setters ) ) )
186185
.method( getPropertyNamesMethodName )
187-
.intercept( MethodCall.call( new CloningPropertyCall( getterNames ) ) )
186+
.intercept( new Implementation.Simple( new GetPropertyNames( getterNames ) ) )
188187
);
189188

190189
try {
@@ -251,7 +250,7 @@ public ReflectionOptimizer getReflectionOptimizer(
251250
.method( setPropertyValuesMethodName )
252251
.intercept( new Implementation.Simple( new SetPropertyValues( clazz, propertyNames, setters ) ) )
253252
.method( getPropertyNamesMethodName )
254-
.intercept( MethodCall.call( new CloningPropertyCall( propertyNames ) ) )
253+
.intercept( new Implementation.Simple( new GetPropertyNames( propertyNames ) ) )
255254
);
256255

257256
try {
@@ -1293,17 +1292,29 @@ private static Constructor<?> findConstructor(Class<?> clazz) {
12931292
}
12941293
}
12951294

1296-
public static class CloningPropertyCall implements Callable<String[]> {
1295+
public static class GetPropertyNames implements ByteCodeAppender {
12971296

12981297
private final String[] propertyNames;
12991298

1300-
private CloningPropertyCall(String[] propertyNames) {
1299+
private GetPropertyNames(String[] propertyNames) {
13011300
this.propertyNames = propertyNames;
13021301
}
13031302

13041303
@Override
1305-
public String[] call() {
1306-
return propertyNames.clone();
1304+
public Size apply(
1305+
MethodVisitor methodVisitor,
1306+
Implementation.Context implementationContext,
1307+
MethodDescription instrumentedMethod) {
1308+
methodVisitor.visitLdcInsn( propertyNames.length );
1309+
methodVisitor.visitTypeInsn( Opcodes.ANEWARRAY, Type.getInternalName( String.class ) );
1310+
for ( int i = 0; i < propertyNames.length; i++ ) {
1311+
methodVisitor.visitInsn( Opcodes.DUP );
1312+
methodVisitor.visitLdcInsn( i );
1313+
methodVisitor.visitLdcInsn( propertyNames[i] );
1314+
methodVisitor.visitInsn( Opcodes.AASTORE );
1315+
}
1316+
methodVisitor.visitInsn( Opcodes.ARETURN );
1317+
return new Size( 4, instrumentedMethod.getStackSize() + 1 );
13071318
}
13081319
}
13091320

0 commit comments

Comments
 (0)