package com.fasterxml.jackson.databind;

import com.google.common.testing.GcFinalization;
import org.junit.Assert;
import org.junit.Test;
import org.openjdk.jol.info.GraphLayout;

public class MapperFootprintTest {
    /*
     * Note: this class is run in an isolated execution in surefire. The test is too flaky with all the other tests
     * running in the same JVM.
     */

    @Test
    public void testMapperFootprint() throws InterruptedException {
        // memory footprint limit for the ObjectMapper

        // force gc (see javadoc of GraphLayout.subtract)
        GcFinalization.awaitFullGc();
        // do this calculation twice. If there's a GC in one case, and the subtract call doesn't work well because of
        // this, we can fall back to the other.
        GraphLayout mapperLayoutA = GraphLayout.parseInstance(new ObjectMapper())
                .subtract(GraphLayout.parseInstance(new ObjectMapper()));
        GraphLayout mapperLayoutB = GraphLayout.parseInstance(new ObjectMapper())
                .subtract(GraphLayout.parseInstance(new ObjectMapper()));
        GraphLayout mapperLayout = mapperLayoutA.totalSize() > mapperLayoutB.totalSize() ?
                mapperLayoutB : mapperLayoutA;

        Assert.assertTrue(
                "ObjectMapper memory footprint exceeded limit. Footprint details: " + mapperLayout.toFootprint(),
                mapperLayout.totalSize() < 10000);
    }
}

@@ -1219,16 +1219,56 @@
 youtA;%0A%0A
+        final int maxByteSize = 20_000;%0A
         
@@ -1347,16 +1347,34 @@
 ed limit
+ (%22+maxByteSize+%22)
 . Footpr
@@ -1465,13 +1465,19 @@
 ) %3C 
-10000
+maxByteSize
 );%0A 

Increase max size to check by MapperFootprintTest from 10k to 20k (due to flakiness of test)