< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/BasicType.java

Print this page




   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.runtime;
  26 




  27 /** Encapsulates the BasicType enum in globalDefinitions.hpp in the
  28     VM. */
  29 
  30 public class BasicType {
  31   public static final int tBoolean     = 4;
  32   public static final int tChar        = 5;
  33   public static final int tFloat       = 6;
  34   public static final int tDouble      = 7;
  35   public static final int tByte        = 8;
  36   public static final int tShort       = 9;
  37   public static final int tInt         = 10;
  38   public static final int tLong        = 11;
  39   public static final int tObject      = 12;
  40   public static final int tArray       = 13;
  41   public static final int tVoid        = 14;
  42   public static final int tAddress     = 15;
  43   public static final int tNarrowOop   = 16;
  44   public static final int tMetadata    = 17;
  45   public static final int tNarrowKlass = 18;
  46   public static final int tConflict    = 19;
  47   public static final int tIllegal     = 99;
  48 
  49   public static final BasicType T_BOOLEAN = new BasicType(tBoolean);
  50   public static final BasicType T_CHAR = new BasicType(tChar);
  51   public static final BasicType T_FLOAT = new BasicType(tFloat);
  52   public static final BasicType T_DOUBLE = new BasicType(tDouble);
  53   public static final BasicType T_BYTE = new BasicType(tByte);
  54   public static final BasicType T_SHORT = new BasicType(tShort);
  55   public static final BasicType T_INT = new BasicType(tInt);
  56   public static final BasicType T_LONG = new BasicType(tLong);
  57   public static final BasicType T_OBJECT = new BasicType(tObject);
  58   public static final BasicType T_ARRAY = new BasicType(tArray);
  59   public static final BasicType T_VOID = new BasicType(tVoid);
  60   public static final BasicType T_ADDRESS = new BasicType(tAddress);
  61   public static final BasicType T_NARROWOOP = new BasicType(tNarrowOop);
  62   public static final BasicType T_METADATA = new BasicType(tMetadata);
  63   public static final BasicType T_NARROWKLASS = new BasicType(tNarrowKlass);
  64   public static final BasicType T_CONFLICT = new BasicType(tConflict);
  65   public static final BasicType T_ILLEGAL = new BasicType(tIllegal);







  66 
  67   public static int getTBoolean() {
  68     return tBoolean;
  69   }
  70 
  71   public static int getTChar() {
  72     return tChar;
  73   }
  74 
  75   public static int getTFloat() {
  76     return tFloat;
  77   }
  78 
  79   public static int getTDouble() {
  80     return tDouble;
  81   }
  82 
  83   public static int getTByte() {
  84     return tByte;
  85   }
  86 
  87   public static int getTShort() {
  88     return tShort;
  89   }
  90 
  91   public static int getTInt() {
  92     return tInt;
  93   }
  94 
  95   public static int getTLong() {
  96     return tLong;
  97   }
  98 
  99   public static int getTObject() {
 100     return tObject;
 101   }
 102 
 103   public static int getTArray() {
 104     return tArray;
 105   }
 106 
 107   public static int getTVoid() {
 108     return tVoid;
 109   }
 110 
 111   public static int getTAddress() {
 112     return tAddress;
 113   }
 114 
 115   public static int getTNarrowOop() {
 116     return tNarrowOop;
 117   }
 118 
 119   public static int getTMetadata() {
 120     return tMetadata;
 121   }
 122 
 123   public static int getTNarrowKlass() {
 124     return tNarrowKlass;
 125   }
 126 
 127   /** For stack value type with conflicting contents */
 128   public static int getTConflict() {
 129     return tConflict;
 130   }
 131 
 132   public static int getTIllegal() {
 133     return tIllegal;
 134   }
 135 
 136   public static BasicType intToBasicType(int i) {
 137     switch(i) {
 138       case tBoolean:     return T_BOOLEAN;
 139       case tChar:        return T_CHAR;
 140       case tFloat:       return T_FLOAT;
 141       case tDouble:      return T_DOUBLE;
 142       case tByte:        return T_BYTE;
 143       case tShort:       return T_SHORT;
 144       case tInt:         return T_INT;
 145       case tLong:        return T_LONG;
 146       case tObject:      return T_OBJECT;
 147       case tArray:       return T_ARRAY;
 148       case tVoid:        return T_VOID;
 149       case tAddress:     return T_ADDRESS;
 150       case tNarrowOop:   return T_NARROWOOP;
 151       case tMetadata:    return T_METADATA;
 152       case tNarrowKlass: return T_NARROWKLASS;
 153       default:           return T_ILLEGAL;















 154     }
 155   }
 156 
 157   public static BasicType charToBasicType(char c) {
 158     switch( c ) {
 159     case 'B': return T_BYTE;
 160     case 'C': return T_CHAR;
 161     case 'D': return T_DOUBLE;
 162     case 'F': return T_FLOAT;
 163     case 'I': return T_INT;
 164     case 'J': return T_LONG;
 165     case 'S': return T_SHORT;
 166     case 'Z': return T_BOOLEAN;
 167     case 'V': return T_VOID;
 168     case 'L': return T_OBJECT;
 169     case '[': return T_ARRAY;
 170     }
 171     return T_ILLEGAL;
 172   }
 173 
 174   public static int charToType(char c) {
 175     return charToBasicType(c).getType();
 176   }
 177 




 178   public int getType() {
 179     return type;
 180   }
 181 
 182   public String getName() {
 183     switch (type) {
 184       case tBoolean:     return "boolean";
 185       case tChar:        return "char";
 186       case tFloat:       return "float";
 187       case tDouble:      return "double";
 188       case tByte:        return "byte";
 189       case tShort:       return "short";
 190       case tInt:         return "int";
 191       case tLong:        return "long";
 192       case tObject:      return "object";
 193       case tArray:       return "array";
 194       case tVoid:        return "void";
 195       case tAddress:     return "address";
 196       case tNarrowOop:   return "narrow oop";
 197       case tMetadata:    return "metadata";
 198       case tNarrowKlass: return "narrow klass";
 199       case tConflict:    return "conflict";
 200       default:           return "ILLEGAL TYPE";
















 201     }
 202   }
 203 
 204   //-- Internals only below this point
 205   private BasicType(int type) {
 206     this.type = type;
 207   }
 208 
 209   private int type;
 210 }


   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.runtime;
  26 
  27 import java.util.Observer;
  28 import sun.jvm.hotspot.types.TypeDataBase;
  29 
  30 
  31 /** Encapsulates the BasicType enum in globalDefinitions.hpp in the
  32     VM. */
  33 
  34 public class BasicType {
  35   public static final BasicType T_BOOLEAN = new BasicType();
  36   public static final BasicType T_CHAR = new BasicType();
  37   public static final BasicType T_FLOAT = new BasicType();
  38   public static final BasicType T_DOUBLE = new BasicType();
  39   public static final BasicType T_BYTE = new BasicType();
  40   public static final BasicType T_SHORT = new BasicType();
  41   public static final BasicType T_INT = new BasicType();
  42   public static final BasicType T_LONG = new BasicType();
  43   public static final BasicType T_OBJECT = new BasicType();
  44   public static final BasicType T_ARRAY = new BasicType();
  45   public static final BasicType T_VOID = new BasicType();
  46   public static final BasicType T_ADDRESS = new BasicType();
  47   public static final BasicType T_NARROWOOP = new BasicType();
  48   public static final BasicType T_METADATA = new BasicType();
  49   public static final BasicType T_NARROWKLASS = new BasicType();
  50   public static final BasicType T_CONFLICT = new BasicType();
  51   public static final BasicType T_ILLEGAL = new BasicType();
  52 
  53   static {
  54     VM.registerVMInitializedObserver(
  55         (o, d) -> initialize(VM.getVM().getTypeDataBase()));
  56   }
  57 
  58   private static synchronized void initialize(TypeDataBase db) {
  59     T_BOOLEAN.setType(db.lookupIntConstant("T_BOOLEAN").intValue());
  60     T_CHAR.setType(db.lookupIntConstant("T_CHAR").intValue());
  61     T_FLOAT.setType(db.lookupIntConstant("T_FLOAT").intValue());
  62     T_DOUBLE.setType(db.lookupIntConstant("T_DOUBLE").intValue());
  63     T_BYTE.setType(db.lookupIntConstant("T_BYTE").intValue());
  64     T_SHORT.setType(db.lookupIntConstant("T_SHORT").intValue());
  65     T_INT.setType(db.lookupIntConstant("T_INT").intValue());
  66     T_LONG.setType(db.lookupIntConstant("T_LONG").intValue());
  67     T_OBJECT.setType(db.lookupIntConstant("T_OBJECT").intValue());
  68     T_ARRAY.setType(db.lookupIntConstant("T_ARRAY").intValue());
  69     T_VOID.setType(db.lookupIntConstant("T_VOID").intValue());
  70     T_ADDRESS.setType(db.lookupIntConstant("T_ADDRESS").intValue());
  71     T_NARROWOOP.setType(db.lookupIntConstant("T_NARROWOOP").intValue());
  72     T_METADATA.setType(db.lookupIntConstant("T_METADATA").intValue());
  73     T_NARROWKLASS.setType(db.lookupIntConstant("T_NARROWKLASS").intValue());
  74     T_CONFLICT.setType(db.lookupIntConstant("T_CONFLICT").intValue());
  75     T_ILLEGAL.setType(db.lookupIntConstant("T_ILLEGAL").intValue());
  76   }
  77 
  78   public static int getTBoolean() {
  79     return T_BOOLEAN.getType();
  80   }
  81 
  82   public static int getTChar() {
  83     return T_CHAR.getType();
  84   }
  85 
  86   public static int getTFloat() {
  87     return T_FLOAT.getType();
  88   }
  89 
  90   public static int getTDouble() {
  91     return T_DOUBLE.getType();
  92   }
  93 
  94   public static int getTByte() {
  95     return T_BYTE.getType();
  96   }
  97 
  98   public static int getTShort() {
  99     return T_SHORT.getType();
 100   }
 101 
 102   public static int getTInt() {
 103     return T_INT.getType();
 104   }
 105 
 106   public static int getTLong() {
 107     return T_LONG.getType();
 108   }
 109 
 110   public static int getTObject() {
 111     return T_OBJECT.getType();
 112   }
 113 
 114   public static int getTArray() {
 115     return T_ARRAY.getType();
 116   }
 117 
 118   public static int getTVoid() {
 119     return T_VOID.getType();
 120   }
 121 
 122   public static int getTAddress() {
 123     return T_ADDRESS.getType();
 124   }
 125 
 126   public static int getTNarrowOop() {
 127     return T_NARROWOOP.getType();
 128   }
 129 
 130   public static int getTMetadata() {
 131     return T_METADATA.getType();
 132   }
 133 
 134   public static int getTNarrowKlass() {
 135     return T_NARROWKLASS.getType();
 136   }
 137 
 138   /** For stack value type with conflicting contents */
 139   public static int getTConflict() {
 140     return T_CONFLICT.getType();
 141   }
 142 
 143   public static int getTIllegal() {
 144     return T_ILLEGAL.getType();
 145   }
 146 
 147   public static BasicType intToBasicType(int i) {
 148     if (i == T_BOOLEAN.getType()) {
 149       return T_BOOLEAN;
 150     } else if (i == T_CHAR.getType()) {
 151       return T_CHAR;
 152     } else if (i == T_FLOAT.getType()) {
 153       return T_FLOAT;
 154     } else if (i == T_DOUBLE.getType()) {
 155       return T_DOUBLE;
 156     } else if (i == T_BYTE.getType()) {
 157       return T_BYTE;
 158     } else if (i == T_SHORT.getType()) {
 159       return T_SHORT;
 160     } else if (i == T_INT.getType()) {
 161       return T_INT;
 162     } else if (i == T_LONG.getType()) {
 163       return T_LONG;
 164     } else if (i == T_OBJECT.getType()) {
 165       return T_OBJECT;
 166     } else if (i == T_ARRAY.getType()) {
 167       return T_ARRAY;
 168     } else if (i == T_VOID.getType()) {
 169       return T_VOID;
 170     } else if (i == T_ADDRESS.getType()) {
 171       return T_ADDRESS;
 172     } else if (i == T_NARROWOOP.getType()) {
 173       return T_NARROWOOP;
 174     } else if (i == T_METADATA.getType()) {
 175       return T_METADATA;
 176     } else if (i == T_NARROWKLASS.getType()) {
 177       return T_NARROWKLASS;
 178     } else {
 179       return T_ILLEGAL;
 180     }
 181   }
 182 
 183   public static BasicType charToBasicType(char c) {
 184     switch( c ) {
 185     case 'B': return T_BYTE;
 186     case 'C': return T_CHAR;
 187     case 'D': return T_DOUBLE;
 188     case 'F': return T_FLOAT;
 189     case 'I': return T_INT;
 190     case 'J': return T_LONG;
 191     case 'S': return T_SHORT;
 192     case 'Z': return T_BOOLEAN;
 193     case 'V': return T_VOID;
 194     case 'L': return T_OBJECT;
 195     case '[': return T_ARRAY;
 196     }
 197     return T_ILLEGAL;
 198   }
 199 
 200   public static int charToType(char c) {
 201     return charToBasicType(c).getType();
 202   }
 203 
 204   private void setType(int type) {
 205     this.type = type;
 206   }
 207 
 208   public int getType() {
 209     return type;
 210   }
 211 
 212   public String getName() {
 213     if (type == T_BOOLEAN.getType()) {
 214       return "boolean";
 215     } else if (type == T_CHAR.getType()) {
 216       return "char";
 217     } else if (type == T_FLOAT.getType()) {
 218       return "float";
 219     } else if (type == T_DOUBLE.getType()) {
 220       return "double";
 221     } else if (type == T_BYTE.getType()) {
 222       return "byte";
 223     } else if (type == T_SHORT.getType()) {
 224       return "short";
 225     } else if (type == T_INT.getType()) {
 226       return "int";
 227     } else if (type == T_LONG.getType()) {
 228       return "long";
 229     } else if (type == T_OBJECT.getType()) {
 230       return "object";
 231     } else if (type == T_ARRAY.getType()) {
 232       return "array";
 233     } else if (type == T_VOID.getType()) {
 234       return "void";
 235     } else if (type == T_ADDRESS.getType()) {
 236       return "address";
 237     } else if (type == T_NARROWOOP.getType()) {
 238       return "narrow oop";
 239     } else if (type == T_METADATA.getType()) {
 240       return "metadata";
 241     } else if (type == T_NARROWKLASS.getType()) {
 242       return "narrow klass";
 243     } else if (type == T_CONFLICT.getType()) {
 244       return "conflict";
 245     } else {
 246       return "ILLEGAL TYPE";
 247     }
 248   }
 249 
 250   //-- Internals only below this point
 251   private BasicType() {

 252   }
 253 
 254   private int type;
 255 }
< prev index next >