Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/gc/containers/DequeueContainer.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.Deque;25import nsk.share.gc.gp.GarbageProducer;26import nsk.share.gc.gp.MemoryStrategy;2728/*29* The dequeue container update remove a first or last30* elements from queue and add the same number of elements.31*32*/33class DequeueContainer extends TypicalContainer {3435Deque queue;36boolean isLIFO;37int threadsCount;3839public DequeueContainer(Deque queue, long maximumSize,40GarbageProducer garbageProducer, MemoryStrategy memoryStrategy, Speed speed,41int threadsCount) {42super(maximumSize, garbageProducer, memoryStrategy, speed);43this.threadsCount = threadsCount;44this.queue = queue;45}4647public void initialize() {48for (int i = 0; i < count; i++) {49if (!stresser.continueExecution()) {50return;51}52queue.add(garbageProducer.create(size));53}54}5556@Override57public void update() {58for (int i = 0; i < count * speed.getValue() / (threadsCount * 100); i++) {59if (!stresser.continueExecution()) {60return;61}62Object obj = null;63if (isLIFO) {64obj = queue.removeFirst();65} else {66obj = queue.removeLast();67}68garbageProducer.validate(obj);69}70for (int i = 0; i < count * speed.getValue() / (threadsCount * 100); i++) {71if (!stresser.continueExecution()) {72return;73}74queue.addFirst(garbageProducer.create(size));75}76isLIFO = !isLIFO;77}78}798081