1 /*
2  * Copyright (c) 2008, 2019, 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 
24 package jit.graph;
25 
26 import jdk.test.lib.Utils;
27 
28 import java.lang.reflect.InvocationTargetException;
29 import java.util.Random;
30 import java.util.Vector;
31 
32 class test3 extends test1 {
33 
34     private final int[] MethodID = {Globals.MethodID_Array[3], Globals.MethodID_Array[4]};
35     private static Random loopNumGen = new Random(Utils.SEED);
36 
37     private final int maxLoops = 10;
38     private int localNumLoops = loopNumGen.nextInt(maxLoops);
39 
selfRecursion(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)40     public void selfRecursion(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)
41             throws InvocationTargetException {
42         Globals.appendSumToSummationVector(MethodID[1], summation);
43 
44         if (CGT.shouldFinish()) {
45             return;
46         }
47 
48         if (Globals.VERBOSE) {
49             System.out.println("test3.selfRecursion");
50         }
51 
52         if ((functionDepth.longValue() <= 0) && (staticFunctionDepth.intValue() <= 0)) {
53             return;
54         }
55 
56         MethodData methodCallStr;
57         Long numFcalls;
58         Integer staticFcalls;
59         // make a static call
60         if (staticFunctionDepth.intValue() > 0) {
61             numFcalls = functionDepth;
62             staticFcalls = new Integer(staticFunctionDepth.intValue() - 1);
63             methodCallStr = Globals.returnNextStaticMethod(MethodID[1]);
64         } else if (localNumLoops > 0) { // make a recursive call
65             numFcalls = new Long(functionDepth.longValue() - 1);
66             staticFcalls = staticFunctionDepth;
67             Globals.addFunctionIDToVector(MethodID[1], ID);
68             localNumLoops--;
69             selfRecursion(summation, ID, numFcalls, staticFcalls);
70             return;
71         } else { // make a random call
72             numFcalls = new Long(functionDepth.longValue() - 1);
73             staticFcalls = staticFunctionDepth;
74             methodCallStr = Globals.nextRandomMethod();
75 
76             // get ready for the next call to this method
77             localNumLoops = loopNumGen.nextInt(maxLoops);
78         }
79         Globals.addFunctionIDToVector(methodCallStr.id, ID);
80         Globals.callMethod(methodCallStr, summation, ID, numFcalls, staticFcalls);
81 
82     }
83 
callMe(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)84     public void callMe(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)
85             throws InvocationTargetException {
86         Globals.appendSumToSummationVector(MethodID[0], summation);
87 
88         if (CGT.shouldFinish()) {
89             return;
90         }
91 
92         if (Globals.VERBOSE) {
93             System.out.println("test3.callMe");
94         }
95 
96         if ((functionDepth.longValue() <= 0) && (staticFunctionDepth.intValue() <= 0)) {
97             return;
98         }
99         MethodData methodCallStr;
100         Long numFcalls;
101         Integer staticFcalls;
102         if (staticFunctionDepth.intValue() > 0) {
103             numFcalls = functionDepth;
104             staticFcalls = new Integer(staticFunctionDepth.intValue() - 1);
105             methodCallStr = Globals.returnNextStaticMethod(MethodID[0]);
106         } else {
107             numFcalls = new Long(functionDepth.longValue() - 1);
108             staticFcalls = staticFunctionDepth;
109             methodCallStr = Globals.nextRandomMethod();
110         }
111         Globals.addFunctionIDToVector(methodCallStr.id, ID);
112         Globals.callMethod(methodCallStr, summation, ID, numFcalls, staticFcalls);
113     }
114 }
115