Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SmapStratum.java
41162 views
1
/*
2
* Copyright (c) 2007, 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 nsk.share.jdi.sde;
24
25
import java.util.ArrayList;
26
import java.util.List;
27
28
/**
29
* Represents the line and file mappings associated with a JSR-045
30
* "stratum".
31
*/
32
public class SmapStratum
33
{
34
35
//*********************************************************************
36
// Class for storing LineInfo data
37
38
/**
39
* Represents a single LineSection in an SMAP, associated with
40
* a particular stratum.
41
*/
42
public static class LineInfo {
43
private int inputStartLine = -1;
44
private int outputStartLine = -1;
45
private int lineFileID = 0;
46
private int inputLineCount = 1;
47
private int outputLineIncrement = 1;
48
private boolean lineFileIDSet = false;
49
50
/** Sets InputStartLine. */
51
public void setInputStartLine(int inputStartLine) {
52
if (inputStartLine < 0)
53
throw new IllegalArgumentException("" + inputStartLine);
54
this.inputStartLine = inputStartLine;
55
}
56
57
/** Sets OutputStartLine. */
58
public void setOutputStartLine(int outputStartLine) {
59
if (outputStartLine < 0)
60
throw new IllegalArgumentException("" + outputStartLine);
61
this.outputStartLine = outputStartLine;
62
}
63
64
/**
65
* Sets lineFileID. Should be called only when different from
66
* that of prior LineInfo object (in any given context) or 0
67
* if the current LineInfo has no (logical) predecessor.
68
* <tt>LineInfo</tt> will print this file number no matter what.
69
*/
70
public void setLineFileID(int lineFileID) {
71
if (lineFileID < 0)
72
throw new IllegalArgumentException("" + lineFileID);
73
this.lineFileID = lineFileID;
74
this.lineFileIDSet = true;
75
}
76
77
/** Sets InputLineCount. */
78
public void setInputLineCount(int inputLineCount) {
79
if (inputLineCount < 0)
80
throw new IllegalArgumentException("" + inputLineCount);
81
this.inputLineCount = inputLineCount;
82
}
83
84
/** Sets OutputLineIncrement. */
85
public void setOutputLineIncrement(int outputLineIncrement) {
86
if (outputLineIncrement < 0)
87
throw new IllegalArgumentException("" + outputLineIncrement);
88
this.outputLineIncrement = outputLineIncrement;
89
}
90
91
/**
92
* Retrieves the current LineInfo as a String, print all values
93
* only when appropriate (but LineInfoID if and only if it's been
94
* specified, as its necessity is sensitive to context).
95
*/
96
public String getString() {
97
if (inputStartLine == -1 || outputStartLine == -1)
98
throw new IllegalStateException();
99
StringBuffer out = new StringBuffer();
100
out.append(inputStartLine);
101
if (lineFileIDSet)
102
out.append("#" + lineFileID);
103
if (inputLineCount != 1)
104
out.append("," + inputLineCount);
105
out.append(":" + outputStartLine);
106
if (outputLineIncrement != 1)
107
out.append("," + outputLineIncrement);
108
out.append('\n');
109
return out.toString();
110
}
111
112
public String toString() {
113
return getString();
114
}
115
}
116
117
//*********************************************************************
118
// Private state
119
120
private String stratumName;
121
private List<String> fileNameList;
122
private List<String> filePathList;
123
private List<LineInfo> lineData;
124
private int lastFileID;
125
126
//*********************************************************************
127
// Constructor
128
129
/**
130
* Constructs a new SmapStratum object for the given stratum name
131
* (e.g., JSP).
132
*
133
* @param stratumName the name of the stratum (e.g., JSP)
134
*/
135
public SmapStratum(String stratumName) {
136
this.stratumName = stratumName;
137
fileNameList = new ArrayList<String>();
138
filePathList = new ArrayList<String>();
139
lineData = new ArrayList<LineInfo>();
140
lastFileID = 0;
141
}
142
143
//*********************************************************************
144
// Methods to add mapping information
145
146
/**
147
* Adds record of a new file, by filename.
148
*
149
* @param filename the filename to add, unqualified by path.
150
*/
151
public void addFile(String filename) {
152
addFile(filename, filename);
153
}
154
155
/**
156
* Adds record of a new file, by filename and path. The path
157
* may be relative to a source compilation path.
158
*
159
* @param filename the filename to add, unqualified by path
160
* @param filePath the path for the filename, potentially relative
161
* to a source compilation path
162
*/
163
public void addFile(String filename, String filePath) {
164
int pathIndex = filePathList.indexOf(filePath);
165
if (pathIndex == -1) {
166
fileNameList.add(filename);
167
filePathList.add(filePath);
168
}
169
}
170
171
/**
172
* Adds complete information about a simple line mapping. Specify
173
* all the fields in this method; the back-end machinery takes care
174
* of printing only those that are necessary in the final SMAP.
175
* (My view is that fields are optional primarily for spatial efficiency,
176
* not for programmer convenience. Could always add utility methods
177
* later.)
178
*
179
* @param inputStartLine starting line in the source file
180
* (SMAP <tt>InputStartLine</tt>)
181
* @param inputFileName the filepath (or name) from which the input comes
182
* (yields SMAP <tt>LineFileID</tt>) Use unqualified names
183
* carefully, and only when they uniquely identify a file.
184
* @param inputLineCount the number of lines in the input to map
185
* (SMAP <tt>LineFileCount</tt>)
186
* @param outputStartLine starting line in the output file
187
* (SMAP <tt>OutputStartLine</tt>)
188
* @param outputLineIncrement number of output lines to map to each
189
* input line (SMAP <tt>OutputLineIncrement</tt>). <i>Given the
190
* fact that the name starts with "output", I continuously have
191
* the subconscious urge to call this field
192
* <tt>OutputLineExcrement</tt>.</i>
193
*/
194
public void addLineData(
195
int inputStartLine,
196
String inputFileName,
197
int inputLineCount,
198
int outputStartLine,
199
int outputLineIncrement) {
200
// check the input - what are you doing here??
201
int fileIndex = fileNameList.indexOf(inputFileName);
202
if (fileIndex == -1) // still
203
throw new IllegalArgumentException(
204
"inputFileName: " + inputFileName);
205
206
//Jasper incorrectly SMAPs certain Nodes, giving them an
207
//outputStartLine of 0. This can cause a fatal error in
208
//optimizeLineSection, making it impossible for Jasper to
209
//compile the JSP. Until we can fix the underlying
210
//SMAPping problem, we simply ignore the flawed SMAP entries.
211
if (outputStartLine == 0)
212
return;
213
214
// build the LineInfo
215
LineInfo li = new LineInfo();
216
li.setInputStartLine(inputStartLine);
217
li.setInputLineCount(inputLineCount);
218
li.setOutputStartLine(outputStartLine);
219
li.setOutputLineIncrement(outputLineIncrement);
220
if (fileIndex != lastFileID)
221
li.setLineFileID(fileIndex);
222
lastFileID = fileIndex;
223
224
// save it
225
lineData.add(li);
226
}
227
228
//*********************************************************************
229
// Methods to retrieve information
230
231
/**
232
* Returns the name of the stratum.
233
*/
234
public String getStratumName() {
235
return stratumName;
236
}
237
238
/**
239
* Returns the given stratum as a String: a StratumSection,
240
* followed by at least one FileSection and at least one LineSection.
241
*/
242
public String getString() {
243
// check state and initialize buffer
244
if (fileNameList.size() == 0 || lineData.size() == 0)
245
return null;
246
247
StringBuffer out = new StringBuffer();
248
249
// print StratumSection
250
out.append("*S " + stratumName + "\n");
251
252
// print FileSection
253
out.append("*F\n");
254
int bound = fileNameList.size();
255
for (int i = 0; i < bound; i++) {
256
if (filePathList.get(i) != null) {
257
out.append("+ " + i + " " + fileNameList.get(i) + "\n");
258
// Source paths must be relative, not absolute, so we
259
// remove the leading "/", if one exists.
260
String filePath = (String)filePathList.get(i);
261
if (filePath.startsWith("/")) {
262
filePath = filePath.substring(1);
263
}
264
out.append(filePath + "\n");
265
} else {
266
out.append(i + " " + fileNameList.get(i) + "\n");
267
}
268
}
269
270
// print LineSection
271
out.append("*L\n");
272
bound = lineData.size();
273
for (int i = 0; i < bound; i++) {
274
LineInfo li = (LineInfo)lineData.get(i);
275
out.append(li.getString());
276
}
277
278
return out.toString();
279
}
280
281
public String toString() {
282
return getString();
283
}
284
285
}
286
287