private void buildCopyStack( List<StackManipulation> stack, int iterations, Method getMethod, Method putMethod, long stride) throws NoSuchFieldException, NoSuchMethodException { final Field unsafeField = UnsafeCopier.class.getDeclaredField("unsafe"); final StackManipulation copyStack = new StackManipulation.Compound( // unsafe.putLong(dest, destOffset, unsafe.getLong(src)); MethodVariableAccess.REFERENCE.loadOffset(0), // ALOAD 0 this FieldAccess.forField(new FieldDescription.ForLoadedField(unsafeField)) .getter(), // GETFIELD MethodVariableAccess.REFERENCE.loadOffset(1), // ALOAD 1 dest MethodVariableAccess.LONG.loadOffset(4), // LLOAD 4 destOffset MethodVariableAccess.REFERENCE.loadOffset(0), // ALOAD 0 this FieldAccess.forField(new FieldDescription.ForLoadedField(unsafeField)) .getter(), // GETFIELD MethodVariableAccess.LONG.loadOffset(2), // LLOAD 2 src MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(getMethod)), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(putMethod))); final StackManipulation incrementStack = new StackManipulation.Compound( // destOffset += 8; src += 8; MethodVariableAccess.LONG.loadOffset(4), // LLOAD 4 destOffset LongConstant.forValue(stride), // LDC 8 strideWidth LongAdd.INSTANCE, // LADD MethodVariableStore.LONG.storeOffset(4), // LSTORE 4 MethodVariableAccess.LONG.loadOffset(2), // LLOAD 2 src LongConstant.forValue(stride), // LDC 8 strideWidth LongAdd.INSTANCE, // LADD MethodVariableStore.LONG.storeOffset(2) // LSTORE 2 ); for (int i = 0; i < iterations; i++) { stack.add(copyStack); stack.add(incrementStack); } }
private void buildSetupStack(List<StackManipulation> stack) throws NoSuchFieldException, NoSuchMethodException { final StackManipulation setupStack = new StackManipulation.Compound( LongConstant.forValue(offset), // LDC offset MethodVariableStore.LONG.storeOffset(4) // LSTORE 4 ); stack.add(setupStack); }