test/hotspot/jtreg/vmTestbase/vm/gc/containers/CollectionContainer.java
author iignatyev
Thu, 17 May 2018 14:52:47 -0700
changeset 50168 2f59dc95847d
permissions -rw-r--r--
8199370: [TESTBUG] Open source vm testbase GC tests Reviewed-by: erikj, ihse, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50168
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     1
/*
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     4
 *
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     8
 *
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    14
 *
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    18
 *
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    21
 * questions.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    22
 */
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    23
package vm.gc.containers;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    24
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    25
import java.util.Collection;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    26
import java.util.Iterator;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    27
import nsk.share.gc.gp.GarbageProducer;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    28
import nsk.share.gc.gp.MemoryStrategy;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    29
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    30
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    31
/*
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    32
 * This class updates collection by removal of random elements
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    33
 * via iterator and adding the same number of elements.
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    34
 */
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    35
class CollectionContainer extends TypicalContainer {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    36
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    37
    Collection collection;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    38
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    39
    public CollectionContainer(Collection collection, long maximumSize,
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    40
            GarbageProducer garbageProducer, MemoryStrategy memoryStrategy, Speed speed) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    41
        super(maximumSize, garbageProducer, memoryStrategy, speed);
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    42
        this.collection = collection;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    43
    }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    44
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    45
    @Override
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    46
    public void initialize() {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    47
        for (int i = 0; i < count; i++) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    48
            if (!stresser.continueExecution()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    49
                return;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    50
            }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    51
            collection.add(garbageProducer.create(size));
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    52
        }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    53
    }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    54
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    55
    @Override
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    56
    public void update() {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    57
        Iterator iter = collection.iterator();
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    58
        int i = 0;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    59
        while (iter.hasNext()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    60
            Object obj = iter.next();
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    61
            if (i++ / 100 < speed.getValue()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    62
                if (!stresser.continueExecution()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    63
                    return;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    64
                }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    65
                iter.remove();
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    66
                garbageProducer.validate(obj);
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    67
            }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    68
        }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    69
        while (i != 0) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    70
            if (i-- / 100 < speed.getValue()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    71
                if (!stresser.continueExecution()) {
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    72
                    return;
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    73
                }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    74
                collection.add(garbageProducer.create(size));
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    75
            }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    76
        }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    77
    }
2f59dc95847d 8199370: [TESTBUG] Open source vm testbase GC tests
iignatyev
parents:
diff changeset
    78
}