hotspot/test/gc/g1/humongousObjects/TestObjectCollected.java
author ctornqvi
Fri, 19 Aug 2016 10:06:30 -0400
changeset 40631 ed82623d7831
parent 39414 4adf52148100
child 41705 332239c052cc
permissions -rw-r--r--
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder Reviewed-by: coleenp, gtriantafill, mseledtsov, iignatyev, dholmes, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35206
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     1
/*
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
35206
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     4
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     8
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    14
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    18
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    21
 * questions.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    22
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    23
 */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    24
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    25
package gc.g1.humongousObjects;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    26
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    27
import gc.testlibrary.Helpers;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    28
import jdk.test.lib.Asserts;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    29
import sun.hotspot.WhiteBox;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    30
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    31
import java.lang.ref.Reference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    32
import java.lang.ref.ReferenceQueue;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    33
import java.lang.ref.SoftReference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    34
import java.lang.ref.WeakReference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    35
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    36
/**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    37
 * @test TestObjectCollected
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    38
 * @summary checks that after different type of GCs weak/soft references to humongous object behave correspondingly to
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    39
 * actual object behavior
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
    40
 * @requires vm.gc.G1
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39414
diff changeset
    41
 * @library /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 35206
diff changeset
    42
 * @modules java.base/jdk.internal.misc
35206
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    43
 * @modules java.management
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    44
 * @build sun.hotspot.WhiteBox
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    45
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    46
 *             sun.hotspot.WhiteBox$WhiteBoxPermission
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    47
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    48
 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    49
 *                   -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xms200m -Xmx200m -Xlog:gc
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    50
 *                   -XX:InitiatingHeapOccupancyPercent=100 -XX:G1HeapRegionSize=1M -Xlog:gc=info:file=TestObjectCollected.gc.log
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    51
 *                    gc.g1.humongousObjects.TestObjectCollected
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    52
 */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    53
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    54
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    55
/**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    56
 * Test checks that after different type of GCs weak/soft references to humongous object behave correspondingly to
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    57
 * actual object behavior.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    58
 * So if object was collected, reference.get() should return null and vice versa
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    59
 * Since we check humongous objects after such an object is collected the region where it was allocated becomes free
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    60
 * or/and change type to non-humongous. Two WhiteBox method were used - first returns if a region containing certain
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    61
 * address is free and second - if a region containing certain address is humongous
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    62
 */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    63
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    64
public class TestObjectCollected {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    65
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    66
     * Provides methods to initiate GC of requested type
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    67
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    68
    private enum GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    69
        YOUNG_CG {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    70
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    71
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    72
                WHITE_BOX.youngGC();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    73
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    74
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    75
        FULL_GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    76
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    77
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    78
                System.gc();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    79
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    80
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    81
        CMC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    82
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    83
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    84
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    85
                WHITE_BOX.g1StartConcMarkCycle();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    86
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    87
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    88
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    89
        FULL_GC_MEMORY_PRESSURE {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    90
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    91
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    92
                WHITE_BOX.fullGC();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    93
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    94
        };
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    95
        private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    96
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    97
        public abstract void provoke();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    98
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    99
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   100
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   101
     * Factory for weak and soft references.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   102
     * Allocates byte array of ALLOCATION_SIZE and returns weak/soft reference on it.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   103
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   104
    private enum REF_FACTORY {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   105
        WEAK {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   106
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   107
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   108
                return new WeakReference<>(new byte[ALLOCATION_SIZE], referenceQueqe);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   109
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   110
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   111
        SOFT {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   112
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   113
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   114
                return new SoftReference<>(new byte[ALLOCATION_SIZE], referenceQueqe);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   115
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   116
        };
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   117
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   118
        private static final ReferenceQueue<byte[]> referenceQueqe = new ReferenceQueue<>();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   119
        private static final int ALLOCATION_SIZE = WhiteBox.getWhiteBox().g1RegionSize() * 2 / 3;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   120
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   121
        /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   122
         * Factory method
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   123
         *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   124
         * @return weak/soft reference on byte array of ALLOCATION_SIZE
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   125
         */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   126
        public abstract Reference<byte[]> create();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   127
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   128
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   129
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   130
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   131
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   132
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   133
     * Does actual testing:
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   134
     * Gets a reference
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   135
     * Gets address of referenced object using WB method
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   136
     * Calls gc of provided type
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   137
     * Checks that object was/was not deleted using WB methods.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   138
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   139
    public static void doTesting(GC gc, REF_FACTORY ref) {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   140
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   141
        System.out.println(String.format("Testing %s reference behavior after %s", ref.name(), gc.name()));
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   142
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   143
        Reference reference = ref.create();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   144
        Asserts.assertNotNull(reference, "Test Bug: failed to allocate reference");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   145
        long adr = WHITE_BOX.getObjectAddress(reference.get());
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   146
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   147
        //Sanity checks
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   148
        boolean isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   149
        boolean isRegionHumongous = WHITE_BOX.g1BelongsToHumongousRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   150
        boolean isRegionFree = WHITE_BOX.g1BelongsToFreeRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   151
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   152
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   153
        Asserts.assertEquals(isRefNulled, false,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   154
                "We just allocated an object but reference.get() already returned null");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   155
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   156
        Asserts.assertEquals(isRegionFree, false,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   157
                "We just allocated an object but WB returns that allocation region is still considered free");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   158
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   159
        Asserts.assertEquals(isRegionHumongous, true,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   160
                "We just allocated a humongous object but WB returns that allocation region is not humongous");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   161
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   162
        gc.provoke();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   163
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   164
        isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   165
        isRegionHumongous = WHITE_BOX.g1BelongsToHumongousRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   166
        isRegionFree = WHITE_BOX.g1BelongsToFreeRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   167
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   168
        boolean isObjCollected = isRegionFree || !isRegionHumongous;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   169
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   170
        Asserts.assertEquals(isRefNulled, isObjCollected,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   171
                String.format("There is an inconsistensy between reference and white box "
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   172
                                + "method behavior - one considers object referenced with "
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   173
                                + "%s type collected and another doesn't!\n"
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   174
                                + "\treference.get() returned %snull\n"
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   175
                                + "\tWhiteBox methods returned that object was%s collected",
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   176
                        reference.getClass().getSimpleName(),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   177
                        (isRefNulled ? "" : "not "),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   178
                        (isObjCollected ? "" : " not")));
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   179
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   180
        System.out.println("Passed");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   181
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   182
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   183
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   184
     * Entry point
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   185
     *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   186
     * @param args not used
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   187
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   188
    public static void main(String[] args) {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   189
        // Full gc - System.gc()
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   190
        TestObjectCollected.doTesting(GC.FULL_GC, REF_FACTORY.WEAK);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   191
        TestObjectCollected.doTesting(GC.FULL_GC, REF_FACTORY.SOFT);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   192
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   193
        // Full gc with memory pressure - WB.fullGC() emulates that no memory left
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   194
        TestObjectCollected.doTesting(GC.FULL_GC_MEMORY_PRESSURE, REF_FACTORY.WEAK);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   195
        TestObjectCollected.doTesting(GC.FULL_GC_MEMORY_PRESSURE, REF_FACTORY.SOFT);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   196
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   197
        // Young gc
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   198
        TestObjectCollected.doTesting(GC.YOUNG_CG, REF_FACTORY.WEAK);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   199
        TestObjectCollected.doTesting(GC.YOUNG_CG, REF_FACTORY.SOFT);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   200
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   201
        // Concurrent mark cycle
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   202
        TestObjectCollected.doTesting(GC.CMC, REF_FACTORY.WEAK);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   203
        TestObjectCollected.doTesting(GC.CMC, REF_FACTORY.SOFT);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   204
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   205
}