1 /* 2 * Copyright (c) 2000, 2004, 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 */ 24 25 package sun.jvm.hotspot.oops; 26 27 import java.io.*; 28 import sun.jvm.hotspot.runtime.BasicType; 29 import sun.jvm.hotspot.utilities.*; 30 31 public class FieldType { 32 33 private Symbol signature; 34 private char first; 35 36 public FieldType(Symbol signature) { 37 this.signature = signature; 38 this.first = (char) signature.getByteAt(0); 39 if (Assert.ASSERTS_ENABLED) { 40 switch (this.first) { 41 case 'B': 42 case 'C': 43 case 'D': 44 case 'F': 45 case 'I': 46 case 'J': 47 case 'S': 48 case 'Z': 49 case 'L': 50 case '[': 51 break; // Ok. signature char known 52 default: 53 Assert.that(false, "Unknown char in field signature \"" + signature.asString() + "\": " + this.first); 54 } 55 } 56 } 57 58 public boolean isOop() { return isObject() || isArray(); } 59 public boolean isByte() { return first == 'B'; } 60 public boolean isChar() { return first == 'C'; } 61 public boolean isDouble() { return first == 'D'; } 62 public boolean isFloat() { return first == 'F'; } 63 public boolean isInt() { return first == 'I'; } 64 public boolean isLong() { return first == 'J'; } 65 public boolean isShort() { return first == 'S'; } 66 public boolean isBoolean() { return first == 'Z'; } 67 public boolean isObject() { return first == 'L'; } 68 public boolean isArray() { return first == '['; } 69 70 public static class ArrayInfo { 71 private int dimension; 72 private int elementBasicType; // See BasicType.java 73 // FIXME: consider adding name of element class 74 75 public ArrayInfo(int dimension, int elementBasicType) { 76 this.dimension = dimension; 77 this.elementBasicType = elementBasicType; 78 } 79 80 public int dimension() { return dimension; } 81 /** See BasicType.java */ 82 public int elementBasicType() { return elementBasicType; } 83 } 84 85 /** Only valid for T_ARRAY; throws unspecified exception otherwise */ 86 public ArrayInfo getArrayInfo() { 87 int index = 1; 88 int dim = 1; 89 index = skipOptionalSize(signature, index); 90 while (signature.getByteAt(index) == '[') { 91 index++; 92 dim++; 93 skipOptionalSize(signature, index); 94 } 95 int elementType = BasicType.charToType((char) signature.getByteAt(index)); 96 return new ArrayInfo(dim, elementType); 97 } 98 99 private int skipOptionalSize(Symbol sig, int index) { 100 byte c = sig.getByteAt(index); 101 while (c >= '0' && c <= '9') { 102 ++index; 103 c = sig.getByteAt(index); 104 } 105 return index; 106 } 107 }