Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/metaspace/stressHierarchy/common/StressHierarchyBaseClass.java
41161 views
1
/*
2
* Copyright (c) 2013, 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 metaspace.stressHierarchy.common;
24
25
import java.net.MalformedURLException;
26
27
import vm.share.gc.TriggerUnloadingByFillingMetaspace;
28
import vm.share.gc.TriggerUnloadingHelper;
29
import vm.share.gc.TriggerUnloadingWithWhiteBox;
30
31
import metaspace.stressHierarchy.common.classloader.tree.Node;
32
import metaspace.stressHierarchy.common.classloader.tree.Tree;
33
import metaspace.stressHierarchy.common.exceptions.GotWrongOOMEException;
34
import metaspace.stressHierarchy.common.exceptions.TimeIsOverException;
35
import metaspace.stressHierarchy.common.generateHierarchy.GenerateHierarchyHelper;
36
import metaspace.stressHierarchy.common.generateHierarchy.GenerateHierarchyHelper.Type;
37
import metaspace.stressHierarchy.common.generateHierarchy.NodeDescriptor;
38
import metaspace.stressHierarchy.common.generateHierarchy.TreeDescriptor;
39
import nsk.share.test.ExecutionController;
40
import nsk.share.test.Stresser;
41
import nsk.share.test.TestBase;
42
43
44
/**
45
* Superclass for StressHierarchy* tests. It provides util methods to create and load
46
* classes hierarchy and perform checks.
47
*/
48
abstract public class StressHierarchyBaseClass extends TestBase {
49
50
protected static String[] args;
51
52
protected TriggerUnloadingHelper triggerUnloadingHelper = new TriggerUnloadingWithWhiteBox(); //default helper
53
54
protected PerformChecksHelper performChecksHelper = null;
55
56
private int treeDepth;
57
58
private int minLevelSize;
59
60
private int maxLevelSize;
61
62
private Type hierarchyType;
63
64
public void run() {
65
try {
66
int attemptsLimit = -1; // -1 means using default value defined in PerformChecksHelper
67
long unloadingPause = -1; // -1 means the same
68
int pausesLimit = -1; // -1 means the same
69
70
for (int ind = 0; ind < args.length; ind++ ) {
71
if ("-triggerUnloadingByFillingMetaspace".equals(args[ind])) {
72
log.info("using TriggerUnloadingByFillingMetaspace");
73
triggerUnloadingHelper = new TriggerUnloadingByFillingMetaspace();
74
} else if ("-treeDepth".equals(args[ind])) {
75
this.treeDepth = Integer.parseInt(args[ind + 1]);
76
} else if ("-minLevelSize".equals(args[ind])) {
77
this.minLevelSize = Integer.parseInt(args[ind + 1]);
78
} else if ("-maxLevelSize".equals(args[ind])) {
79
this.maxLevelSize = Integer.parseInt(args[ind + 1]);
80
} else if ("-attemptsLimit".equals(args[ind])) {
81
attemptsLimit = Integer.valueOf(args[ind + 1]);
82
} else if ("-unloadingPause".equals(args[ind])) {
83
unloadingPause = Long.valueOf(args[ind + 1]);
84
} else if ("-pausesLimit".equals(args[ind])) {
85
pausesLimit = Integer.valueOf(args[ind + 1]);
86
} else if ("-hierarchyType".equals(args[ind])) {
87
String s = args[ind + 1];
88
hierarchyType = Type.CLASSES.toString().equals(s) ? Type.CLASSES :
89
(Type.INTERFACES.toString().equals(s) ? Type.INTERFACES : Type.MIXED);
90
System.out.println("hierarchyType = " + hierarchyType);
91
} else if (args[ind].startsWith("-") && !args[ind].equals("-stressTime")) {
92
throw new RuntimeException("Unknown option " + args[ind]);
93
}
94
}
95
performChecksHelper = new PerformChecksHelper(triggerUnloadingHelper, attemptsLimit, unloadingPause, pausesLimit);
96
log.info("treeDepth=" + treeDepth + ", minLevelSize=" + minLevelSize + ", maxLevelSize=" + maxLevelSize + ", hierarchyType=" + hierarchyType +
97
", triggerUnloadingHelper.getClass().getName()=" + triggerUnloadingHelper.getClass().getName());
98
99
long startTimeStamp = System.currentTimeMillis();
100
ExecutionController stresser = new Stresser(args);
101
stresser.start(1);
102
TreeDescriptor treeDescriptor = GenerateHierarchyHelper.generateHierarchy(treeDepth, minLevelSize, maxLevelSize, hierarchyType);
103
Tree tree = buildTree(treeDescriptor);
104
System.out.println("Generating took " + ((System.currentTimeMillis() - startTimeStamp)/1000) +" sec");
105
106
performChecksHelper.setStresser(stresser);
107
108
runTestLogic(tree, stresser);
109
110
System.out.println("Whole test took " + ((System.currentTimeMillis() - startTimeStamp)/1000/60.0) +" min");
111
log.info("Test PASSED");
112
} catch (GotWrongOOMEException e) {
113
log.info("GotWrongOOMEExc: " + e.getMessage());
114
log.info("Got wrong type of OOME. We are passing test as it breaks test logic. We have dedicated test configurations" +
115
" for each OOME type provoking class unloading, that's why we are not missing test coverage here.");
116
} catch (OutOfMemoryError e) {
117
log.info("Got OOME.");
118
} catch (TimeIsOverException e) {
119
log.info("Time is over. That's okay. Passing test");
120
} catch (Throwable throwable) {
121
//Throw runtime exception. nsk framework will catch it, log and set appropriate exit code
122
log.error("Test failed. Exception catched.");
123
throwable.printStackTrace();
124
throw new RuntimeException(throwable);
125
}
126
}
127
128
abstract protected void runTestLogic(Tree tree, ExecutionController stresser) throws Throwable;
129
130
private Tree buildTree(TreeDescriptor treeDescriptor) throws MalformedURLException,
131
ClassNotFoundException, InstantiationException,
132
IllegalAccessException {
133
log.info("Create tree");
134
Tree tree = new Tree();
135
for (NodeDescriptor nodeDescriptor : treeDescriptor.nodeDescriptorList) {
136
tree.addNode(nodeDescriptor);
137
}
138
139
log.info("Load classes and instantiate objects");
140
for (Node node : tree.getNodes()) {
141
node.loadClasses();
142
node.instantiateObjects();
143
}
144
return tree;
145
}
146
147
}
148
149