@Test
  public void codeDelegationListSize() {
    System.setProperty("jol.magicFieldOffset", "true");

    TransactionTestFixture preparedTx =
        prepareTransaction(
            TransactionType.DELEGATE_CODE,
            0,
            Wei.of(500),
            Wei.ZERO,
            0,
            0,
            BlobType.KZG_PROOF,
            List.of(CODE_DELEGATION_SENDER_1));
    Transaction txDelegateCode = preparedTx.createTransaction(KEYS1);
    BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
    txDelegateCode.writeTo(rlpOut);

    txDelegateCode =
        Transaction.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)).detachedCopy();
    System.out.println(txDelegateCode.getSender());
    System.out.println(txDelegateCode.getHash());
    System.out.println(txDelegateCode.getSize());

    final var optCD = txDelegateCode.getCodeDelegationList();

    final ClassLayout optionalClassLayout = ClassLayout.parseInstance(optCD);
    System.out.println(optionalClassLayout.toPrintable());
    System.out.println("Optional size: " + optionalClassLayout.instanceSize());

    final ClassLayout listClassLayout = ClassLayout.parseInstance(optCD.get());
    System.out.println(listClassLayout.toPrintable());
    System.out.println(
        "Optional + list size: "
            + (optionalClassLayout.instanceSize() + listClassLayout.instanceSize()));

    assertThat(optionalClassLayout.instanceSize() + listClassLayout.instanceSize())
        .isEqualTo(OPTIONAL_CODE_DELEGATION_LIST_SHALLOW_SIZE);

    final CodeDelegation codeDelegation = optCD.get().get(0);

    long cdSize = sizeOfField(codeDelegation, "storageKeys.elementData[");

    System.out.println("CodeDelegation container size: " + cdSize);

    assertThat(cdSize).isEqualTo(CODE_DELEGATION_ENTRY_SIZE);
  }
Field which value is dynamic and can only be calculated at runtime
ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java