hotspot/test/gc/g1/humongousObjects/TestObjectCollected.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 40631 ed82623d7831
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
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
package gc.g1.humongousObjects;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    25
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    26
import gc.testlibrary.Helpers;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    27
import jdk.test.lib.Asserts;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    28
import sun.hotspot.WhiteBox;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    29
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    30
import java.lang.ref.Reference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    31
import java.lang.ref.ReferenceQueue;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    32
import java.lang.ref.SoftReference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    33
import java.lang.ref.WeakReference;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    34
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
 * @test TestObjectCollected
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    37
 * @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
    38
 * actual object behavior
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
    39
 * @requires vm.gc.G1
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39414
diff changeset
    40
 * @library /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 35206
diff changeset
    41
 * @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
    42
 * @modules java.management
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    43
 * @build sun.hotspot.WhiteBox
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    44
 * @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
    45
 *             sun.hotspot.WhiteBox$WhiteBoxPermission
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    46
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    47
 * @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
    48
 *                   -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
    49
 *                   -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
    50
 *                    gc.g1.humongousObjects.TestObjectCollected
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    51
 */
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
 * 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
    56
 * actual object behavior.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * 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
    61
 */
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
public class TestObjectCollected {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    64
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    65
     * 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
    66
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    67
    private enum GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    68
        YOUNG_CG {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    69
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    70
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    71
                WHITE_BOX.youngGC();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    72
            }
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
        FULL_GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    75
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    76
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    77
                System.gc();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    78
            }
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
        CMC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    81
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    82
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    83
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    84
                WHITE_BOX.g1StartConcMarkCycle();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    85
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    86
            }
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
        FULL_GC_MEMORY_PRESSURE {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    89
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    90
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    91
                WHITE_BOX.fullGC();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    92
            }
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
        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
    95
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    96
        public abstract void provoke();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    97
    }
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
     * 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
   101
     * 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
   102
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   103
    private enum REF_FACTORY {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   104
        WEAK {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   105
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   106
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   107
                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
   108
            }
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
        SOFT {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   111
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   112
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   113
                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
   114
            }
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
        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
   118
        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
   119
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
         * Factory method
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   122
         *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   123
         * @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
   124
         */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   125
        public abstract Reference<byte[]> create();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   126
    }
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
    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
   130
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
     * Does actual testing:
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   133
     * Gets a reference
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   134
     * 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
   135
     * Calls gc of provided type
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   136
     * 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
   137
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   138
    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
   139
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   140
        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
   141
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   142
        Reference reference = ref.create();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   143
        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
   144
        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
   145
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   146
        //Sanity checks
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   147
        boolean isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   148
        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
   149
        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
   150
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
        Asserts.assertEquals(isRefNulled, false,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   153
                "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
   154
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   155
        Asserts.assertEquals(isRegionFree, false,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   156
                "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
   157
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   158
        Asserts.assertEquals(isRegionHumongous, true,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   159
                "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
   160
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   161
        gc.provoke();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   162
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   163
        isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   164
        isRegionHumongous = WHITE_BOX.g1BelongsToHumongousRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   165
        isRegionFree = WHITE_BOX.g1BelongsToFreeRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   166
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   167
        boolean isObjCollected = isRegionFree || !isRegionHumongous;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   168
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   169
        Asserts.assertEquals(isRefNulled, isObjCollected,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   170
                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
   171
                                + "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
   172
                                + "%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
   173
                                + "\treference.get() returned %snull\n"
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   174
                                + "\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
   175
                        reference.getClass().getSimpleName(),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   176
                        (isRefNulled ? "" : "not "),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   177
                        (isObjCollected ? "" : " not")));
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   178
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   179
        System.out.println("Passed");
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   180
    }
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
     * Entry point
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   184
     *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   185
     * @param args not used
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   186
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   187
    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
   188
        // Full gc - System.gc()
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   189
        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
   190
        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
   191
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   192
        // 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
   193
        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
   194
        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
   195
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   196
        // Young gc
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   197
        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
   198
        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
   199
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   200
        // Concurrent mark cycle
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   201
        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
   202
        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
   203
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   204
}