hotspot/test/gc/g1/humongousObjects/TestObjectCollected.java
author dfazunen
Fri, 24 Jun 2016 19:52:31 +0400
changeset 39414 4adf52148100
parent 38152 80e5da81fb2c
child 40631 ed82623d7831
permissions -rw-r--r--
8160088: update hotspot tests depending on GC to use @requires vm.gc.X Reviewed-by: iignatyev, mchernov, dholmes
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
35206
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    41
 * @library /testlibrary /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
 *        gc.testlibrary.Helpers
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    46
 *        gc.g1.humongousObjects.TestObjectCollected
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 driver ClassFileInstaller sun.hotspot.WhiteBox
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    49
 *             sun.hotspot.WhiteBox$WhiteBoxPermission
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    50
 *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    51
 * @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
    52
 *                   -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
    53
 *                   -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
    54
 *                    gc.g1.humongousObjects.TestObjectCollected
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
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    57
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    58
/**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    59
 * 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
    60
 * actual object behavior.
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    61
 * 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
    62
 * 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
    63
 * 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
    64
 * 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
    65
 */
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
public class TestObjectCollected {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    68
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    69
     * 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
    70
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    71
    private enum GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    72
        YOUNG_CG {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    73
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    74
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    75
                WHITE_BOX.youngGC();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    76
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    77
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    78
        FULL_GC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    79
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    80
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    81
                System.gc();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    82
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    83
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    84
        CMC {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    85
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    86
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    87
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    88
                WHITE_BOX.g1StartConcMarkCycle();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    89
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    90
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    91
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    92
        FULL_GC_MEMORY_PRESSURE {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    93
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    94
            public void provoke() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    95
                WHITE_BOX.fullGC();
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
        };
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
    98
        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
    99
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   100
        public abstract void provoke();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   101
    }
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
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   104
     * 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
   105
     * 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
   106
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   107
    private enum REF_FACTORY {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   108
        WEAK {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   109
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   110
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   111
                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
   112
            }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   113
        },
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   114
        SOFT {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   115
            @Override
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   116
            public Reference<byte[]> create() {
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   117
                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
   118
            }
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
        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
   122
        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
   123
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
         * Factory method
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
         * @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
   128
         */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   129
        public abstract Reference<byte[]> create();
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
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   133
    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
   134
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   135
    /**
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   136
     * Does actual testing:
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   137
     * Gets a reference
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   138
     * 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
   139
     * Calls gc of provided type
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   140
     * 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
   141
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   142
    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
   143
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   144
        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
   145
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   146
        Reference reference = ref.create();
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   147
        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
   148
        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
   149
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   150
        //Sanity checks
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   151
        boolean isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   152
        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
   153
        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
   154
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(isRefNulled, 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 reference.get() already returned null");
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(isRegionFree, false,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   160
                "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
   161
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   162
        Asserts.assertEquals(isRegionHumongous, true,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   163
                "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
   164
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   165
        gc.provoke();
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
        isRefNulled = (reference.get() == null);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   168
        isRegionHumongous = WHITE_BOX.g1BelongsToHumongousRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   169
        isRegionFree = WHITE_BOX.g1BelongsToFreeRegion(adr);
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   170
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   171
        boolean isObjCollected = isRegionFree || !isRegionHumongous;
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   172
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   173
        Asserts.assertEquals(isRefNulled, isObjCollected,
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   174
                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
   175
                                + "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
   176
                                + "%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
   177
                                + "\treference.get() returned %snull\n"
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   178
                                + "\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
   179
                        reference.getClass().getSimpleName(),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   180
                        (isRefNulled ? "" : "not "),
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   181
                        (isObjCollected ? "" : " not")));
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
        System.out.println("Passed");
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
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
     * Entry point
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   188
     *
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   189
     * @param args not used
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   190
     */
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   191
    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
   192
        // Full gc - System.gc()
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, 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, 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
        // 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
   197
        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
   198
        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
   199
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   200
        // Young gc
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   201
        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
   202
        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
   203
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   204
        // Concurrent mark cycle
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   205
        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
   206
        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
   207
    }
aaf0f36a013a 8132723: Add tests which check that soft references to humongous objects should work correctly
kzhaldyb
parents:
diff changeset
   208
}