Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/gc/containers/CollectionContainer.java
41155 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package vm.gc.containers;2324import java.util.Collection;25import java.util.Iterator;26import nsk.share.gc.gp.GarbageProducer;27import nsk.share.gc.gp.MemoryStrategy;282930/*31* This class updates collection by removal of random elements32* via iterator and adding the same number of elements.33*/34class CollectionContainer extends TypicalContainer {3536Collection collection;3738public CollectionContainer(Collection collection, long maximumSize,39GarbageProducer garbageProducer, MemoryStrategy memoryStrategy, Speed speed) {40super(maximumSize, garbageProducer, memoryStrategy, speed);41this.collection = collection;42}4344@Override45public void initialize() {46for (int i = 0; i < count; i++) {47if (!stresser.continueExecution()) {48return;49}50collection.add(garbageProducer.create(size));51}52}5354@Override55public void update() {56Iterator iter = collection.iterator();57int i = 0;58while (iter.hasNext()) {59Object obj = iter.next();60if (i++ / 100 < speed.getValue()) {61if (!stresser.continueExecution()) {62return;63}64iter.remove();65garbageProducer.validate(obj);66}67}68while (i != 0) {69if (i-- / 100 < speed.getValue()) {70if (!stresser.continueExecution()) {71return;72}73collection.add(garbageProducer.create(size));74}75}76}77}787980