File: CGT.java

package info (click to toggle)
openjdk-25 25.0.1%2B8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 825,408 kB
  • sloc: java: 5,585,680; cpp: 1,333,948; xml: 1,321,242; ansic: 488,034; asm: 404,003; objc: 21,088; sh: 15,106; javascript: 13,265; python: 8,319; makefile: 2,518; perl: 357; awk: 351; pascal: 103; exp: 83; sed: 72; jsp: 24
file content (239 lines) | stat: -rw-r--r-- 9,816 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package jit.graph;

import jdk.test.lib.Utils;
import jtreg.SkippedException;
import nsk.share.TestFailure;
import nsk.share.test.StressOptions;

import java.lang.reflect.InvocationTargetException;
import java.util.Vector;

public class CGT {
    private static StressOptions stressOptions = new StressOptions();
    private static String ClistPath = "";
    private static long finishTime;

    private final Vector summation = new Vector(100000);
    private final Vector idList = new Vector(100000);

    public CGT(String[] args) {
        parse(args);
        Globals.initialize(ClistPath);
        outputStats(args);
    }

    public static void main(String[] args) {
        stressOptions.parseCommandLine(args);
        new CGT(args).run();
    }

    public void outputStats(String[] args) {
        System.out.println("CGT command line options:");
        for (String arg : args) {
            System.out.println("# " + arg);
        }

        System.out.println();

        System.out.println("CGT parameters");
        System.out.println("Seed: " + Utils.SEED);
        System.out.println("Number of Random Loop iterations: " + Globals.RANDOM_LOOP);
        System.out.println("Number of Static Loop iterations: " + Globals.STATIC_LOOP);
        System.out.println("Max number of Methods in the Graph: " + Globals.NUM_TEST_CLASSES);
        System.out.println("Verbose function calls: " + Globals.VERBOSE);

        System.out.println();
    }

    public void run() {
        finishTime = System.currentTimeMillis() + stressOptions.getTime() * 1000;
        Long numFcalls = Globals.RANDOM_LOOP - 1;
        Integer staticFcalls = Globals.STATIC_LOOP;
        MethodData methodCallStr = Globals.nextRandomMethod();
        Globals.addFunctionIDToVector(methodCallStr.id, idList);
        Throwable invocationExcept;

        try {
            methodCallStr.nextMethod.invoke(methodCallStr.instance, summation, idList, numFcalls, staticFcalls);
        } catch (IllegalAccessException e) {
            throw new TestFailure("Illegal Access Exception", e);
        } catch (InvocationTargetException e) {
            System.out.println("Invocation Target Exception");
            invocationExcept = e.getTargetException();
            System.out.println(invocationExcept);
            if (invocationExcept.getClass() == e.getClass()) {
                System.out.println("Processing Exception Invocation Target Exception");
                while (invocationExcept.getClass() == e.getClass()) {
                    invocationExcept = ((InvocationTargetException) invocationExcept).getTargetException();
                }
                System.out.println(invocationExcept);
            }
            if (invocationExcept instanceof StackOverflowError) {
                throw new SkippedException("stack overflow: skipping verification.", invocationExcept);
            } else if (invocationExcept instanceof OutOfMemoryError) {
                throw new SkippedException("test devoured heap ;), skipping verification.", invocationExcept);
            } else {
                throw new TestFailure(invocationExcept);
            }
        }

        verify();
    }

    private void verify() {
        long oldsum = 0;
        long newsum;
        System.out.println("begin call stack validation");
        if (summation.size() != idList.size()) {
            throw new TestFailure("Vector Length's Do Not Match, VERIFY ERROR : Summation Element Count = " + summation.size() + " ID Element Count = " + idList.size());
        }
        long vectorSize = summation.size();

        while (!summation.isEmpty()) {
            if (CGT.shouldFinish()) {
                throw new SkippedException("skipping verification due to timeout");
            }

            newsum = (Long) summation.firstElement();
            summation.removeElementAt(0);

            int functionID = (Integer) idList.firstElement();
            idList.removeElementAt(0);

            if ((newsum - oldsum) != (functionID)) {
                throw new TestFailure("Function Call structure invalid, VERIFY ERROR. Expected = " + (newsum - oldsum) + " Actual = " + functionID);
            }
            oldsum = newsum;
        }

        System.out.println("function call structure validated successfully (" + vectorSize + " calls validated)");
    }

    public static boolean shouldFinish() {
        return System.currentTimeMillis() >= finishTime;
    }

    public void parse(String args[]) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i].toLowerCase();
            switch (arg) {
                case "-help":
                case "-h":
                case "-?": {
                    usage();
                    System.exit(1);
                    break;
                }
                case "-staticloop": {
                    int argIndex = i + 1;
                    if (argIndex < args.length) {
                        try {
                            Globals.STATIC_LOOP = Math.abs(Integer.parseInt(args[argIndex])) * stressOptions.getIterationsFactor();
                        } catch (NumberFormatException e) {
                            usage();
                            throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);
                        }
                        i++;
                    } else {
                        usage();
                        throw new Error("TESTBUG: Improper Argument: " + args[i]);
                    }
                    break;
                }
                case "-randomloop": {
                    int argIndex = i + 1;
                    if (argIndex < args.length) {
                        try {
                            Globals.RANDOM_LOOP = Math.abs(Long.parseLong(args[argIndex])) * stressOptions.getIterationsFactor();
                        } catch (NumberFormatException e) {
                            usage();
                            throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);
                        }
                        i++;
                    } else {
                        usage();
                        throw new Error("TESTBUG: Improper Argument: " + args[i]);

                    }
                    break;
                }
                case "-numtestclass": {
                    int argIndex = i + 1;
                    if (argIndex < args.length) {
                        try {
                            Globals.NUM_TEST_CLASSES = Math.abs(Integer.parseInt(args[argIndex]));
                        } catch (NumberFormatException e) {
                            usage();
                            throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);
                        }
                        i++;
                    } else {
                        usage();
                        throw new Error("TESTBUG: Improper Argument: " + args[i]);
                    }
                    break;
                }
                case "-verbose":
                case "-v": {
                    Globals.VERBOSE = true;
                    break;
                }
                case "-path": {
                    int argIndex = i + 1;
                    if (argIndex < args.length) {
                        ClistPath = args[argIndex];
                        i++;
                    } else {
                        usage();
                        throw new Error("TESTBUG: Improper Argument: " + args[i]);
                    }
                    break;
                }
                default: {
                    if (!arg.startsWith("-stress")) {
                        usage();
                        throw new Error("TESTBUG: Invalid Argument: " + args[i]);
                    }
                }
            }
        }

        if ("".equals(ClistPath)) {
            usage();
            throw new Error("TESTBUG: class list path not defined");
        }
    }

    public void usage() {
        System.out.println("usage: java CGT [options]");
        System.out.println("  -help                               prints out this message");
        System.out.println("  -numTestClass #                     limits the number of \"Test Methods\" to #");
        System.out.println("  -randomcLoop #                      # of random function calls");
        System.out.println("  -staticLoop #                       # of non-random static function calls");
        System.out.println("  -v -verbose                         turn on verbose mode");
        System.out.println("  -path <path to classlist>           required, argument so program can find classes");
    }
}