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