1 /* |
|
2 * Copyright (c) 1998, 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 |
|
24 package jit.graph; |
|
25 import java.util.*; |
|
26 import java.lang.*; |
|
27 import java.lang.reflect.*; |
|
28 import nsk.share.TestFailure; |
|
29 |
|
30 class CGTThread extends Thread |
|
31 { |
|
32 private String ThreadName = null; |
|
33 private Vector Sumation = new Vector(100000); |
|
34 private Vector IDlist = new Vector(100000); |
|
35 |
|
36 |
|
37 CGTThread( String name ) |
|
38 { |
|
39 ThreadName = name; |
|
40 setName(name); |
|
41 } |
|
42 |
|
43 |
|
44 public void run() |
|
45 { |
|
46 if (Globals.VERBOSE) |
|
47 System.out.println("\t\t" + Thread.currentThread().getName() + " started"); |
|
48 Long numFcalls = new Long(Globals.RANDOM_LOOP - 1); |
|
49 Integer staticFcalls = new Integer(Globals.STATIC_LOOP); |
|
50 MethodData methodCallStr = Globals.nextRandomMethod(); |
|
51 Globals.addFunctionIDToVector(methodCallStr.id, IDlist); |
|
52 Throwable invocationExcept = null; |
|
53 |
|
54 boolean skipVerify = false; |
|
55 |
|
56 try |
|
57 { |
|
58 methodCallStr.nextMethod.invoke(methodCallStr.instance, new Object []{Sumation, IDlist, numFcalls, staticFcalls}); |
|
59 } |
|
60 catch (IllegalAccessException iax) |
|
61 { |
|
62 throw new TestFailure("Illegal Access Exception"); |
|
63 } |
|
64 catch (InvocationTargetException itx) |
|
65 { |
|
66 System.out.println("Invocation Target Exception"); |
|
67 invocationExcept = itx.getTargetException(); |
|
68 System.out.println(invocationExcept); |
|
69 if (invocationExcept.getClass() == itx.getClass()) |
|
70 { |
|
71 System.out.println("Processing Exception Invocation Target Exception"); |
|
72 while (invocationExcept.getClass() == itx.getClass()) |
|
73 invocationExcept = ((InvocationTargetException)invocationExcept).getTargetException(); |
|
74 System.out.println(invocationExcept); |
|
75 } |
|
76 if (invocationExcept instanceof StackOverflowError) |
|
77 //StackOverFlow is not a failure |
|
78 { |
|
79 System.out.println("Warning: stack overflow: skipping verification..."); |
|
80 skipVerify = true; |
|
81 } |
|
82 else if (invocationExcept instanceof OutOfMemoryError) |
|
83 //OutOfMemoryError is not a failure |
|
84 { |
|
85 System.out.println("Warning: test devoured heap ;), skipping verification..."); |
|
86 skipVerify = true; |
|
87 } |
|
88 else |
|
89 { |
|
90 invocationExcept.printStackTrace(); |
|
91 System.exit(1); |
|
92 } |
|
93 } |
|
94 |
|
95 if( !skipVerify ) |
|
96 verify(Sumation, IDlist); |
|
97 } |
|
98 |
|
99 void verify(Vector Sum, Vector ID) |
|
100 { |
|
101 long oldsum = 0; |
|
102 long newsum; |
|
103 System.out.println(ThreadName + " has begun call stack validation"); |
|
104 if (Sum.size() != ID.size()) |
|
105 { |
|
106 System.out.println("Vector Length's Do Not Match, VERIFY ERROR"); |
|
107 System.out.println("Thread Name: " + ThreadName); |
|
108 throw new TestFailure("Sumation Element Count = " + Sum.size() + " ID Element Count = " +ID.size()); |
|
109 } |
|
110 long vectorSize = Sum.size(); |
|
111 while (!Sum.isEmpty()) |
|
112 { |
|
113 if (CGT.shouldFinish()) |
|
114 { |
|
115 System.out.println(Thread.currentThread().getName() + ": skipping verification due to timeout"); |
|
116 return; |
|
117 } |
|
118 |
|
119 newsum = ((Long)Sum.firstElement()).longValue(); |
|
120 Sum.removeElementAt(0); |
|
121 |
|
122 int functionID = ((Integer)ID.firstElement()).intValue(); |
|
123 ID.removeElementAt(0); |
|
124 |
|
125 if ((newsum - oldsum) != (functionID)) |
|
126 { |
|
127 System.out.println("Function Call structure invalid, VERIFY ERROR"); |
|
128 System.out.println("Thread Name: " + ThreadName); |
|
129 System.out.println("Expected = " +(newsum - oldsum) + " Actual = " +functionID); |
|
130 throw new TestFailure("Test failed."); |
|
131 // System.exit(1); |
|
132 } |
|
133 oldsum = newsum; |
|
134 } |
|
135 Globals.decNumThreads(); |
|
136 System.out.println(ThreadName + "'s function call structure validated succesfully ("+vectorSize+" calls validated)"); |
|
137 } |
|
138 |
|
139 } |
|