001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksey V. Yantsen
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 12.23.2004
026: */package org.apache.harmony.jpda.tests.framework.jdwp;
027:
028: import org.apache.harmony.jpda.tests.framework.TestErrorException;
029:
030: /**
031: * This class provides types length for VM-independent and VM-dependent types.
032: */
033: public class TypesLengths {
034:
035: // Type IDs
036: public static final byte BYTE_ID = 1;
037:
038: public static final byte BOOLEAN_ID = 2;
039:
040: public static final byte INT_ID = 3;
041:
042: public static final byte LONG_ID = 4;
043:
044: public static final byte SHORT_ID = 5;
045:
046: public static final byte FLOAT_ID = 6;
047:
048: public static final byte DOUBLE_ID = 7;
049:
050: public static final byte VOID_ID = 8;
051:
052: public static final byte OBJECT_ID = 9;
053:
054: public static final byte ARRAY_ID = 10;
055:
056: public static final byte STRING_ID = 11;
057:
058: public static final byte THREAD_ID = 12;
059:
060: public static final byte THREADGROUP_ID = 13;
061:
062: public static final byte METHOD_ID = 14;
063:
064: public static final byte FIELD_ID = 15;
065:
066: public static final byte FRAME_ID = 16;
067:
068: public static final byte LOCATION_ID = 17;
069:
070: public static final byte REFERENCE_TYPE_ID = 18;
071:
072: public static final byte CLASS_ID = 19;
073:
074: public static final byte CLASSLOADER_ID = 20;
075:
076: public static final byte CLASSOBJECT_ID = 21;
077:
078: public static final byte CHAR_ID = 22;
079:
080: // Type lengths in bytes (VM-independent)
081:
082: private static int byteLength = 1;
083:
084: private static int booleanLength = 1;
085:
086: private static int intLength = 4;
087:
088: private static int longLength = 8;
089:
090: private static int shortLength = 2;
091:
092: private static int floatLength = 4;
093:
094: private static int doubleLength = 8;
095:
096: private static int voidLength = 0;
097:
098: private static int charLength = 2;
099:
100: // Type lengths in bytes (VM-dependent)
101:
102: private static int objectLength;
103:
104: private static int arrayLength;
105:
106: private static int stringLength;
107:
108: private static int threadLength;
109:
110: private static int threadGroupLength;
111:
112: private static int methodLength;
113:
114: private static int fieldLength;
115:
116: private static int frameLength;
117:
118: private static int locationLength;
119:
120: private static int referenceLength;
121:
122: private static int classLength;
123:
124: private static int classLoaderLength;
125:
126: private static int classObjectLength;
127:
128: /**
129: * Gets types length for type ID.
130: *
131: * @param typeID
132: * Type ID
133: * @return type length
134: */
135: public static int getTypeLength(byte typeID)
136: throws TestErrorException {
137: switch (typeID) {
138: case BYTE_ID: {
139: return byteLength;
140: }
141: case BOOLEAN_ID: {
142: return booleanLength;
143: }
144: case INT_ID: {
145: return intLength;
146: }
147: case LONG_ID: {
148: return longLength;
149: }
150: case SHORT_ID: {
151: return shortLength;
152: }
153: case FLOAT_ID: {
154: return floatLength;
155: }
156: case DOUBLE_ID: {
157: return doubleLength;
158: }
159: case VOID_ID: {
160: return voidLength;
161: }
162: case OBJECT_ID: {
163: return objectLength;
164: }
165: case ARRAY_ID: {
166: return arrayLength;
167: }
168: case STRING_ID: {
169: return stringLength;
170: }
171: case THREAD_ID: {
172: return threadLength;
173: }
174: case THREADGROUP_ID: {
175: return threadGroupLength;
176: }
177: case METHOD_ID: {
178: return methodLength;
179: }
180: case FIELD_ID: {
181: return fieldLength;
182: }
183: case FRAME_ID: {
184: return frameLength;
185: }
186: case LOCATION_ID: {
187: return locationLength;
188: }
189: case REFERENCE_TYPE_ID: {
190: return referenceLength;
191: }
192: case CLASS_ID: {
193: return classLength;
194: }
195: case CLASSLOADER_ID: {
196: return classLoaderLength;
197: }
198: case CLASSOBJECT_ID: {
199: return classObjectLength;
200: }
201: case CHAR_ID: {
202: return charLength;
203: }
204: default:
205: throw new TestErrorException("Unexpected type ID: "
206: + typeID);
207: }
208: }
209:
210: /**
211: * Sets types length for type ID
212: *
213: * @param typeID Type ID
214: * @param typeLength type length
215: */
216: public static void setTypeLength(byte typeID, int typeLength)
217: throws TestErrorException {
218: switch (typeID) {
219: case BYTE_ID: {
220: byteLength = typeLength;
221: return;
222: }
223: case BOOLEAN_ID: {
224: booleanLength = typeLength;
225: return;
226: }
227: case INT_ID: {
228: intLength = typeLength;
229: return;
230: }
231: case LONG_ID: {
232: longLength = typeLength;
233: return;
234: }
235: case SHORT_ID: {
236: shortLength = typeLength;
237: return;
238: }
239: case FLOAT_ID: {
240: floatLength = typeLength;
241: return;
242: }
243: case DOUBLE_ID: {
244: doubleLength = typeLength;
245: return;
246: }
247: case VOID_ID: {
248: voidLength = typeLength;
249: return;
250: }
251: case OBJECT_ID: {
252: objectLength = typeLength;
253: return;
254: }
255: case ARRAY_ID: {
256: arrayLength = typeLength;
257: return;
258: }
259: case STRING_ID: {
260: stringLength = typeLength;
261: return;
262: }
263: case THREAD_ID: {
264: threadLength = typeLength;
265: return;
266: }
267: case THREADGROUP_ID: {
268: threadGroupLength = typeLength;
269: return;
270: }
271: case METHOD_ID: {
272: methodLength = typeLength;
273: return;
274: }
275: case FIELD_ID: {
276: fieldLength = typeLength;
277: return;
278: }
279: case FRAME_ID: {
280: frameLength = typeLength;
281: return;
282: }
283: case LOCATION_ID: {
284: locationLength = typeLength;
285: return;
286: }
287: case REFERENCE_TYPE_ID: {
288: referenceLength = typeLength;
289: return;
290: }
291: case CLASS_ID: {
292: classLength = typeLength;
293: return;
294: }
295: case CLASSLOADER_ID: {
296: classLoaderLength = typeLength;
297: return;
298: }
299: case CLASSOBJECT_ID: {
300: classObjectLength = typeLength;
301: return;
302: }
303: case CHAR_ID: {
304: classObjectLength = charLength;
305: return;
306: }
307: default:
308: throw new TestErrorException("Unexpected type ID: "
309: + typeID);
310: }
311: }
312: }
|