use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.Label in project hibernate-orm by hibernate.
the class InlineDirtyCheckingHandler method apply.
@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
// if (arg != field) {
methodVisitor.visitVarInsn(Type.getType(persistentField.getType().asErasure().getDescriptor()).getOpcode(Opcodes.ILOAD), 1);
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
if (persistentField.getDeclaringType().asErasure().equals(managedCtClass)) {
methodVisitor.visitFieldInsn(Opcodes.GETFIELD, persistentField.getDeclaringType().asErasure().getInternalName(), persistentField.getName(), persistentField.getDescriptor());
} else {
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, persistentField.getDeclaringType().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentField.getName(), Type.getMethodDescriptor(Type.getType(persistentField.getDescriptor())), false);
}
int branchCode;
if (persistentField.getType().isPrimitive()) {
if (persistentField.getType().represents(long.class)) {
methodVisitor.visitInsn(Opcodes.LCMP);
} else if (persistentField.getType().represents(float.class)) {
methodVisitor.visitInsn(Opcodes.FCMPL);
} else if (persistentField.getType().represents(double.class)) {
methodVisitor.visitInsn(Opcodes.DCMPL);
} else {
methodVisitor.visitInsn(Opcodes.ISUB);
}
branchCode = Opcodes.IFEQ;
} else {
methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(EqualsHelper.class), "areEqual", Type.getMethodDescriptor(Type.getType(boolean.class), Type.getType(Object.class), Type.getType(Object.class)), false);
branchCode = Opcodes.IFNE;
}
Label skip = new Label();
methodVisitor.visitJumpInsn(branchCode, skip);
// this.$$_hibernate_trackChange(fieldName)
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
methodVisitor.visitLdcInsn(persistentField.getName());
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, managedCtClass.getInternalName(), EnhancerConstants.TRACKER_CHANGER_NAME, Type.getMethodDescriptor(Type.getType(void.class), Type.getType(String.class)), false);
// }
methodVisitor.visitLabel(skip);
if (implementationContext.getClassFileVersion().isAtLeast(ClassFileVersion.JAVA_V6)) {
methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
}
return new Size(1 + 2 * persistentField.getType().asErasure().getStackSize().getSize(), instrumentedMethod.getStackSize());
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.Label in project powermock by powermock.
the class ConditionalStateStackManipulation method apply.
@Override
public Size apply(final MethodVisitor mv, final Context implementationContext) {
Size size = new Size(0, 0);
Label proceed = new Label();
Label exit = new Label();
size = size.aggregate(condition.apply(mv, implementationContext));
mv.visitJumpInsn(Opcodes.IFEQ, proceed);
size = size.aggregate(action.apply(mv, implementationContext));
mv.visitJumpInsn(Opcodes.GOTO, exit);
mv.visitLabel(proceed);
mv.visitFrame(Opcodes.F_FULL, frame.localSize(), frame.locals(), 0, null);
size = size.aggregate(otherwise.apply(mv, implementationContext));
mv.visitLabel(exit);
mv.visitFrame(Opcodes.F_FULL, 0, null, 0, null);
return size;
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.Label in project curiostack by curioswitch.
the class DoWrite method apply.
@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
Map<String, FieldDescription> fieldsByName = CodeGenUtil.fieldsByName(implementationContext);
List<StackManipulation> stackManipulations = new ArrayList<>();
final StackManipulation getDefaultInstance;
try {
getDefaultInstance = invoke(messageClass.getDeclaredMethod("getDefaultInstance"));
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Could not find getDefaultInstance on a Message class.");
}
LocalVariables<LocalVariable> locals = LocalVariables.builderForMethod(instrumentedMethod, LocalVariable.values()).add(Iterator.class, LocalVariable.iterator).add(Map.Entry.class, LocalVariable.entry).build();
stackManipulations.add(locals.initialize());
// based on the includeDefaults parameter.
for (FieldDescriptor f : CodeGenUtil.sorted(descriptor.getFields())) {
ProtoFieldInfo field = new ProtoFieldInfo(f, prototype);
StackManipulation getValue = new StackManipulation.Compound(locals.load(LocalVariable.message), invoke(field.getValueMethod()));
Label afterSerializeField = new Label();
// }
if (!includeDefaults || // one-of).
field.isInOneof() || // a message has itself as a sub-field.
(field.descriptor().isOptional() && field.valueJavaType() == JavaType.MESSAGE)) {
stackManipulations.add(checkDefaultValue(field, locals, getValue, getDefaultInstance, afterSerializeField));
}
stackManipulations.addAll(Arrays.asList(locals.load(LocalVariable.gen), FieldAccess.forField(fieldsByName.get(CodeGenUtil.fieldNameForSerializedFieldName(field))).read(), JsonGenerator_writeFieldName_SerializableString));
// gen.writeEndObject();
if (field.isMapField()) {
final StackManipulation keyToString;
switch(field.mapKeyField().descriptor().getType()) {
case INT32:
case SINT32:
case SFIXED32:
keyToString = Integer_toString;
break;
case INT64:
case SINT64:
case SFIXED64:
keyToString = Long_toString;
break;
case BOOL:
keyToString = Boolean_toString;
break;
case UINT32:
case FIXED32:
keyToString = new StackManipulation.Compound(SerializeSupport_normalizeUnsignedInt32, Long_toString);
break;
case UINT64:
case FIXED64:
keyToString = SerializeSupport_normalizeUnsignedInt64;
break;
case STRING:
keyToString = Trivial.INSTANCE;
break;
default:
throw new IllegalStateException("Unexpected map key type: " + field.mapKeyField().descriptor().getType());
}
final Label loopStart = new Label();
final Label loopEnd = new Label();
final StackManipulation printValue = printValue(fieldsByName, field);
final StackManipulation printMapFieldValue = new StackManipulation.Compound(locals.load(LocalVariable.gen), JsonGenerator_writeStartObject, getValue, IntegerConstant.forValue(sortingMapKeys), IntegerConstant.forValue(field.mapKeyField().valueType() == Type.STRING), SerializeSupport_mapIterator, locals.store(LocalVariable.iterator), new SetJumpTargetLabel(loopStart), locals.load(LocalVariable.iterator), Iterator_hasNext, new IfFalse(loopEnd), locals.load(LocalVariable.iterator), Iterator_next, TypeCasting.to(new ForLoadedType(Entry.class)), locals.store(LocalVariable.entry), locals.load(LocalVariable.gen), locals.load(LocalVariable.entry), Map_Entry_getKey, unbox(field.mapKeyField()), keyToString, JsonGenerator_writeFieldName_String, locals.load(LocalVariable.entry), Map_Entry_getValue, unbox(field.valueField()), locals.load(LocalVariable.gen), printValue, new Goto(loopStart), new SetJumpTargetLabel(loopEnd), locals.load(LocalVariable.gen), JsonGenerator_writeEndObject);
stackManipulations.add(printMapFieldValue);
} else {
// Simply calls the SerializeSupport method that prints out this field. Any iteration will
// be handled there.
//
// e.g.,
// SerializeSupport.printUnsignedInt32(message.getFoo());
// SerializeSupport.printRepeatedString(message.getBar());
final StackManipulation printValue = printValue(fieldsByName, field);
stackManipulations.addAll(Arrays.asList(getValue, locals.load(LocalVariable.gen), printValue));
}
stackManipulations.add(new SetJumpTargetLabel(afterSerializeField));
}
stackManipulations.add(MethodReturn.VOID);
StackManipulation.Size operandStackSize = new StackManipulation.Compound(stackManipulations).apply(methodVisitor, implementationContext);
return new Size(operandStackSize.getMaximalSize(), locals.stackSize());
}
Aggregations