annotate agent/src/share/classes/sun/jvm/hotspot/runtime/SignatureIterator.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 bc32f286fae0
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: 1385
diff changeset
2 * Copyright (c) 2001, 2010, 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: 1385
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
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: 1385
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.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 /** <P> SignatureIterators iterate over a Java signature (or parts of it).
a61af66fc99e Initial load
duke
parents:
diff changeset
30 (Syntax according to: "The Java Virtual Machine Specification" by
a61af66fc99e Initial load
duke
parents:
diff changeset
31 Tim Lindholm & Frank Yellin; section 4.3 Descriptors; p. 89ff.) </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 <P> Example: Iterating over
a61af66fc99e Initial load
duke
parents:
diff changeset
34 <PRE>
a61af66fc99e Initial load
duke
parents:
diff changeset
35 ([Lfoo;D)I
a61af66fc99e Initial load
duke
parents:
diff changeset
36 0123456789
a61af66fc99e Initial load
duke
parents:
diff changeset
37 </PRE>
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 using </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 <PRE>
a61af66fc99e Initial load
duke
parents:
diff changeset
42 iterateParameters() calls: do_array(2, 7); do_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 iterateReturntype() calls: do_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 iterate() calls: do_array(2, 7); do_double(); do_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 is_returnType() is: false ; false ; true
a61af66fc99e Initial load
duke
parents:
diff changeset
47 </PRE>
a61af66fc99e Initial load
duke
parents:
diff changeset
48 */
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public abstract class SignatureIterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 protected Symbol _signature; // the signature to iterate over
a61af66fc99e Initial load
duke
parents:
diff changeset
52 protected int _index; // the current character index (only valid during iteration)
a61af66fc99e Initial load
duke
parents:
diff changeset
53 protected int _parameter_index; // the current parameter index (0 outside iteration phase)
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 protected void expect(char c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (_signature.getByteAt(_index) != (byte) c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 throw new RuntimeException("expecting '" + c + "'");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 protected void skipOptionalSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 byte c = _signature.getByteAt(_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 while ('0' <= c && c <= '9') {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 c = _signature.getByteAt(++_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // returns the parameter size in words (0 for void)
a61af66fc99e Initial load
duke
parents:
diff changeset
68 protected int parseType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 switch(_signature.getByteAt(_index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 case 'B': doByte (); _index++; return BasicTypeSize.getTByteSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 case 'C': doChar (); _index++; return BasicTypeSize.getTCharSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 case 'D': doDouble(); _index++; return BasicTypeSize.getTDoubleSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 case 'F': doFloat (); _index++; return BasicTypeSize.getTFloatSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 case 'I': doInt (); _index++; return BasicTypeSize.getTIntSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case 'J': doLong (); _index++; return BasicTypeSize.getTLongSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 case 'S': doShort (); _index++; return BasicTypeSize.getTShortSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 case 'Z': doBool (); _index++; return BasicTypeSize.getTBooleanSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case 'V':
a61af66fc99e Initial load
duke
parents:
diff changeset
79 {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (!isReturnType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 throw new RuntimeException("illegal parameter type V (void)");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 doVoid(); _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return BasicTypeSize.getTVoidSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
88 {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int begin = ++_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 while (_signature.getByteAt(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 doObject(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return BasicTypeSize.getTObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
95 {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 int begin = ++_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 skipOptionalSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 while (_signature.getByteAt(_index) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 skipOptionalSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (_signature.getByteAt(_index) == 'L') {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 while (_signature.getByteAt(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 doArray(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return BasicTypeSize.getTArraySize();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
111 throw new RuntimeException("Should not reach here: char " + (char)_signature.getByteAt(_index) + " @ " + _index + " in " + _signature.asString());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 protected void checkSignatureEnd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (_index < _signature.getLength()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 System.err.println("too many chars in signature");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 _signature.printValueOn(System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 System.err.println(" @ " + _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public SignatureIterator(Symbol signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 _signature = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 //
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
128 //
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // dispatches once for field signatures
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public void dispatchField() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // no '(', just one (field) type
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 parseType();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 checkSignatureEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // iterates over parameters only
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public void iterateParameters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
145 while (_signature.getByteAt(_index) != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 _parameter_index += parseType();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
149 _parameter_index = 0; // so isReturnType() is false outside iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // iterates over returntype only
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public void iterateReturntype() {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Ignore parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
157 while (_signature.getByteAt(_index) != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 parseType();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 checkSignatureEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _parameter_index = 0; // so isReturnType() is false outside iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // iterates over whole signature
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public void iterate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
174 while (_signature.getByteAt(_index) != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _parameter_index += parseType();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 parseType();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 checkSignatureEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 _parameter_index = 0; // so isReturnType() is false outside iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Returns the word index of the current parameter; returns a negative value at the return type
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public int parameterIndex() { return _parameter_index; }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 public boolean isReturnType() { return (parameterIndex() < 0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // Basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public abstract void doBool ();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public abstract void doChar ();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 public abstract void doFloat ();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public abstract void doDouble();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public abstract void doByte ();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 public abstract void doShort ();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public abstract void doInt ();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 public abstract void doLong ();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public abstract void doVoid ();
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Object types (begin indexes the first character of the entry, end
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // indexes the first character after the entry)
a61af66fc99e Initial load
duke
parents:
diff changeset
202 public abstract void doObject(int begin, int end);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 public abstract void doArray (int begin, int end);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }