1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Aleksey V. Yantsen 21 */ 22 23 /** 24 * Created on 12.23.2004 25 */ 26 package org.apache.harmony.jpda.tests.framework.jdwp; 27 28 import org.apache.harmony.jpda.tests.framework.TestErrorException; 29 30 /** 31 * This class provides types length for VM-independent and VM-dependent types. 32 */ 33 public class TypesLengths { 34 35 // Type IDs 36 public static final byte BYTE_ID = 1; 37 38 public static final byte BOOLEAN_ID = 2; 39 40 public static final byte INT_ID = 3; 41 42 public static final byte LONG_ID = 4; 43 44 public static final byte SHORT_ID = 5; 45 46 public static final byte FLOAT_ID = 6; 47 48 public static final byte DOUBLE_ID = 7; 49 50 public static final byte VOID_ID = 8; 51 52 public static final byte OBJECT_ID = 9; 53 54 public static final byte ARRAY_ID = 10; 55 56 public static final byte STRING_ID = 11; 57 58 public static final byte THREAD_ID = 12; 59 60 public static final byte THREADGROUP_ID = 13; 61 62 public static final byte METHOD_ID = 14; 63 64 public static final byte FIELD_ID = 15; 65 66 public static final byte FRAME_ID = 16; 67 68 public static final byte LOCATION_ID = 17; 69 70 public static final byte REFERENCE_TYPE_ID = 18; 71 72 public static final byte CLASS_ID = 19; 73 74 public static final byte CLASSLOADER_ID = 20; 75 76 public static final byte CLASSOBJECT_ID = 21; 77 78 public static final byte CHAR_ID = 22; 79 80 // Type lengths in bytes (VM-independent) 81 82 private static int byteLength = 1; 83 84 private static int booleanLength = 1; 85 86 private static int intLength = 4; 87 88 private static int longLength = 8; 89 90 private static int shortLength = 2; 91 92 private static int floatLength = 4; 93 94 private static int doubleLength = 8; 95 96 private static int voidLength = 0; 97 98 private static int charLength = 2; 99 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 */ getTypeLength(byte typeID)135 public static int getTypeLength(byte typeID) throws TestErrorException { 136 switch (typeID) { 137 case BYTE_ID: { 138 return byteLength; 139 } 140 case BOOLEAN_ID: { 141 return booleanLength; 142 } 143 case INT_ID: { 144 return intLength; 145 } 146 case LONG_ID: { 147 return longLength; 148 } 149 case SHORT_ID: { 150 return shortLength; 151 } 152 case FLOAT_ID: { 153 return floatLength; 154 } 155 case DOUBLE_ID: { 156 return doubleLength; 157 } 158 case VOID_ID: { 159 return voidLength; 160 } 161 case OBJECT_ID: { 162 return objectLength; 163 } 164 case ARRAY_ID: { 165 return arrayLength; 166 } 167 case STRING_ID: { 168 return stringLength; 169 } 170 case THREAD_ID: { 171 return threadLength; 172 } 173 case THREADGROUP_ID: { 174 return threadGroupLength; 175 } 176 case METHOD_ID: { 177 return methodLength; 178 } 179 case FIELD_ID: { 180 return fieldLength; 181 } 182 case FRAME_ID: { 183 return frameLength; 184 } 185 case LOCATION_ID: { 186 return locationLength; 187 } 188 case REFERENCE_TYPE_ID: { 189 return referenceLength; 190 } 191 case CLASS_ID: { 192 return classLength; 193 } 194 case CLASSLOADER_ID: { 195 return classLoaderLength; 196 } 197 case CLASSOBJECT_ID: { 198 return classObjectLength; 199 } 200 case CHAR_ID: { 201 return charLength; 202 } 203 default: 204 throw new TestErrorException("Unexpected type ID: " + typeID); 205 } 206 } 207 208 /** 209 * Sets types length for type ID 210 * 211 * @param typeID Type ID 212 * @param typeLength type length 213 */ setTypeLength(byte typeID, int typeLength)214 public static void setTypeLength(byte typeID, int typeLength) 215 throws TestErrorException { 216 switch (typeID) { 217 case BYTE_ID: { 218 byteLength = typeLength; 219 return; 220 } 221 case BOOLEAN_ID: { 222 booleanLength = typeLength; 223 return; 224 } 225 case INT_ID: { 226 intLength = typeLength; 227 return; 228 } 229 case LONG_ID: { 230 longLength = typeLength; 231 return; 232 } 233 case SHORT_ID: { 234 shortLength = typeLength; 235 return; 236 } 237 case FLOAT_ID: { 238 floatLength = typeLength; 239 return; 240 } 241 case DOUBLE_ID: { 242 doubleLength = typeLength; 243 return; 244 } 245 case VOID_ID: { 246 voidLength = typeLength; 247 return; 248 } 249 case OBJECT_ID: { 250 objectLength = typeLength; 251 return; 252 } 253 case ARRAY_ID: { 254 arrayLength = typeLength; 255 return; 256 } 257 case STRING_ID: { 258 stringLength = typeLength; 259 return; 260 } 261 case THREAD_ID: { 262 threadLength = typeLength; 263 return; 264 } 265 case THREADGROUP_ID: { 266 threadGroupLength = typeLength; 267 return; 268 } 269 case METHOD_ID: { 270 methodLength = typeLength; 271 return; 272 } 273 case FIELD_ID: { 274 fieldLength = typeLength; 275 return; 276 } 277 case FRAME_ID: { 278 frameLength = typeLength; 279 return; 280 } 281 case LOCATION_ID: { 282 locationLength = typeLength; 283 return; 284 } 285 case REFERENCE_TYPE_ID: { 286 referenceLength = typeLength; 287 return; 288 } 289 case CLASS_ID: { 290 classLength = typeLength; 291 return; 292 } 293 case CLASSLOADER_ID: { 294 classLoaderLength = typeLength; 295 return; 296 } 297 case CLASSOBJECT_ID: { 298 classObjectLength = typeLength; 299 return; 300 } 301 case CHAR_ID: { 302 classObjectLength = charLength; 303 return; 304 } 305 default: 306 throw new TestErrorException("Unexpected type ID: " + typeID); 307 } 308 } 309 } 310