annotate agent/src/share/classes/sun/jvm/hotspot/jdi/JNITypeParser.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 public class JNITypeParser {
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 static final char SIGNATURE_ENDCLASS = ';';
a61af66fc99e Initial load
duke
parents:
diff changeset
33 static final char SIGNATURE_FUNC = '(';
a61af66fc99e Initial load
duke
parents:
diff changeset
34 static final char SIGNATURE_ENDFUNC = ')';
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private String signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private List typeNameList;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private List signatureList;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private int currentIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 JNITypeParser(String signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 this.signature = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static String typeNameToSignature(String signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 StringBuffer buffer = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int firstIndex = signature.indexOf('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
48 int index = firstIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 while (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 buffer.append('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
51 index = signature.indexOf('[', index + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (firstIndex != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 signature = signature.substring(0, firstIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (signature.equals("boolean")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 buffer.append('Z');
a61af66fc99e Initial load
duke
parents:
diff changeset
60 } else if (signature.equals("byte")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 buffer.append('B');
a61af66fc99e Initial load
duke
parents:
diff changeset
62 } else if (signature.equals("char")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 buffer.append('C');
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } else if (signature.equals("short")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 buffer.append('S');
a61af66fc99e Initial load
duke
parents:
diff changeset
66 } else if (signature.equals("int")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 buffer.append('I');
a61af66fc99e Initial load
duke
parents:
diff changeset
68 } else if (signature.equals("long")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 buffer.append('J');
a61af66fc99e Initial load
duke
parents:
diff changeset
70 } else if (signature.equals("float")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 buffer.append('F');
a61af66fc99e Initial load
duke
parents:
diff changeset
72 } else if (signature.equals("double")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 buffer.append('D');
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 buffer.append('L');
a61af66fc99e Initial load
duke
parents:
diff changeset
76 buffer.append(signature.replace('.', '/'));
a61af66fc99e Initial load
duke
parents:
diff changeset
77 buffer.append(';');
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return buffer.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 String typeName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return (String)typeNameList().get(typeNameList().size()-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 List argumentTypeNames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return typeNameList().subList(0, typeNameList().size() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 String signature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return (String)signatureList().get(signatureList().size()-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 List argumentSignatures() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return signatureList().subList(0, signatureList().size() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 int dimensionCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 String signature = signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 while (signature.charAt(count) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return count;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 String componentSignature(int level) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return signature().substring(level);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private synchronized List signatureList() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (signatureList == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 signatureList = new ArrayList(10);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 String elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 currentIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 while(currentIndex < signature.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 elem = nextSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 signatureList.add(elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (signatureList.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 throw new IllegalArgumentException("Invalid JNI signature '" +
a61af66fc99e Initial load
duke
parents:
diff changeset
125 signature + "'");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return signatureList;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 private synchronized List typeNameList() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (typeNameList == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 typeNameList = new ArrayList(10);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 String elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 currentIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 while(currentIndex < signature.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 elem = nextTypeName();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 typeNameList.add(elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (typeNameList.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 throw new IllegalArgumentException("Invalid JNI signature '" +
a61af66fc99e Initial load
duke
parents:
diff changeset
144 signature + "'");
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return typeNameList;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 private String nextSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 char key = signature.charAt(currentIndex++);
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 switch(key) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return key + nextSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
158 int endClass = signature.indexOf(SIGNATURE_ENDCLASS,
a61af66fc99e Initial load
duke
parents:
diff changeset
159 currentIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 String retVal = signature.substring(currentIndex - 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
161 endClass + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 currentIndex = endClass + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 case 'V':
a61af66fc99e Initial load
duke
parents:
diff changeset
166 case 'Z':
a61af66fc99e Initial load
duke
parents:
diff changeset
167 case 'B':
a61af66fc99e Initial load
duke
parents:
diff changeset
168 case 'C':
a61af66fc99e Initial load
duke
parents:
diff changeset
169 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
170 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
171 case 'J':
a61af66fc99e Initial load
duke
parents:
diff changeset
172 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
173 case 'D':
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return String.valueOf(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 case SIGNATURE_FUNC:
a61af66fc99e Initial load
duke
parents:
diff changeset
177 case SIGNATURE_ENDFUNC:
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return nextSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
181 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
182 "Invalid JNI signature character '" + key + "'");
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 private String nextTypeName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 char key = signature.charAt(currentIndex++);
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 switch(key) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
192 return nextTypeName() + "[]";
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 case 'B':
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return "byte";
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 case 'C':
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return "char";
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
201 int endClass = signature.indexOf(SIGNATURE_ENDCLASS,
a61af66fc99e Initial load
duke
parents:
diff changeset
202 currentIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 String retVal = signature.substring(currentIndex,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 endClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 retVal = retVal.replace('/','.');
a61af66fc99e Initial load
duke
parents:
diff changeset
206 currentIndex = endClass + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return "float";
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 case 'D':
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return "double";
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
216 return "int";
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 case 'J':
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return "long";
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return "short";
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 case 'V':
a61af66fc99e Initial load
duke
parents:
diff changeset
225 return "void";
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 case 'Z':
a61af66fc99e Initial load
duke
parents:
diff changeset
228 return "boolean";
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 case SIGNATURE_ENDFUNC:
a61af66fc99e Initial load
duke
parents:
diff changeset
231 case SIGNATURE_FUNC:
a61af66fc99e Initial load
duke
parents:
diff changeset
232 return nextTypeName();
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
235 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
236 "Invalid JNI signature character '" + key + "'");
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }