src/share/vm/c1/c1_ValueType.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_ValueType.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,421 @@
     1.4 +/*
     1.5 + * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// type hierarchy
    1.29 +class ValueType;
    1.30 +class   VoidType;
    1.31 +class   IntType;
    1.32 +class     IntConstant;
    1.33 +class     IntInterval;
    1.34 +class   LongType;
    1.35 +class     LongConstant;
    1.36 +class   FloatType;
    1.37 +class     FloatConstant;
    1.38 +class   DoubleType;
    1.39 +class     DoubleConstant;
    1.40 +class   ObjectType;
    1.41 +class     ObjectConstant;
    1.42 +class     ArrayType;
    1.43 +class       ArrayConstant;
    1.44 +class     InstanceType;
    1.45 +class       InstanceConstant;
    1.46 +class     ClassType;
    1.47 +class       ClassConstant;
    1.48 +class   AddressType;
    1.49 +class     AddressConstant;
    1.50 +class   IllegalType;
    1.51 +
    1.52 +
    1.53 +// predefined types
    1.54 +extern VoidType*       voidType;
    1.55 +extern IntType*        intType;
    1.56 +extern LongType*       longType;
    1.57 +extern FloatType*      floatType;
    1.58 +extern DoubleType*     doubleType;
    1.59 +extern ObjectType*     objectType;
    1.60 +extern ArrayType*      arrayType;
    1.61 +extern InstanceType*   instanceType;
    1.62 +extern ClassType*      classType;
    1.63 +extern AddressType*    addressType;
    1.64 +extern IllegalType*    illegalType;
    1.65 +
    1.66 +
    1.67 +// predefined constants
    1.68 +extern IntConstant*    intZero;
    1.69 +extern IntConstant*    intOne;
    1.70 +extern ObjectConstant* objectNull;
    1.71 +
    1.72 +
    1.73 +// tags
    1.74 +enum ValueTag {
    1.75 +  // all legal tags must come first
    1.76 +  intTag,
    1.77 +  longTag,
    1.78 +  floatTag,
    1.79 +  doubleTag,
    1.80 +  objectTag,
    1.81 +  addressTag,
    1.82 +  number_of_legal_tags,
    1.83 +  // all other tags must follow afterwards
    1.84 +  voidTag = number_of_legal_tags,
    1.85 +  illegalTag,
    1.86 +  number_of_tags
    1.87 +};
    1.88 +
    1.89 +
    1.90 +class ValueType: public CompilationResourceObj {
    1.91 + private:
    1.92 +  const int _size;
    1.93 +  const ValueTag _tag;
    1.94 +  ValueType();
    1.95 + protected:
    1.96 +  ValueType(ValueTag tag, int size): _tag(tag), _size(size) {}
    1.97 +
    1.98 + public:
    1.99 +  // initialization
   1.100 +  static void initialize();
   1.101 +
   1.102 +  // accessors
   1.103 +  virtual ValueType* base() const                = 0; // the 'canonical' type (e.g., intType for an IntConstant)
   1.104 +  ValueTag tag() const { return _tag; }          // the 'canonical' tag  (useful for type matching)
   1.105 +  int size() const {                             // the size of an object of the type in words
   1.106 +    assert(_size > -1, "shouldn't be asking for size");
   1.107 +    return _size;
   1.108 +  }
   1.109 +  virtual const char tchar() const               = 0; // the type 'character' for printing
   1.110 +  virtual const char* name() const               = 0; // the type name for printing
   1.111 +  virtual bool is_constant() const               { return false; }
   1.112 +
   1.113 +  // testers
   1.114 +  bool is_void()                                 { return tag() == voidTag;   }
   1.115 +  bool is_int()                                  { return tag() == intTag;    }
   1.116 +  bool is_long()                                 { return tag() == longTag;   }
   1.117 +  bool is_float()                                { return tag() == floatTag;  }
   1.118 +  bool is_double()                               { return tag() == doubleTag; }
   1.119 +  bool is_object()                               { return as_ObjectType()   != NULL; }
   1.120 +  bool is_array()                                { return as_ArrayType()    != NULL; }
   1.121 +  bool is_instance()                             { return as_InstanceType() != NULL; }
   1.122 +  bool is_class()                                { return as_ClassType()    != NULL; }
   1.123 +  bool is_address()                              { return as_AddressType()  != NULL; }
   1.124 +  bool is_illegal()                              { return tag() == illegalTag; }
   1.125 +
   1.126 +  bool is_int_kind() const                       { return tag() == intTag || tag() == longTag; }
   1.127 +  bool is_float_kind() const                     { return tag() == floatTag || tag() == doubleTag; }
   1.128 +  bool is_object_kind() const                    { return tag() == objectTag; }
   1.129 +
   1.130 +  bool is_single_word() const                    { return _size == 1; }
   1.131 +  bool is_double_word() const                    { return _size == 2; }
   1.132 +
   1.133 +  // casting
   1.134 +  virtual VoidType*         as_VoidType()        { return NULL; }
   1.135 +  virtual IntType*          as_IntType()         { return NULL; }
   1.136 +  virtual LongType*         as_LongType()        { return NULL; }
   1.137 +  virtual FloatType*        as_FloatType()       { return NULL; }
   1.138 +  virtual DoubleType*       as_DoubleType()      { return NULL; }
   1.139 +  virtual ObjectType*       as_ObjectType()      { return NULL; }
   1.140 +  virtual ArrayType*        as_ArrayType()       { return NULL; }
   1.141 +  virtual InstanceType*     as_InstanceType()    { return NULL; }
   1.142 +  virtual ClassType*        as_ClassType()       { return NULL; }
   1.143 +  virtual AddressType*      as_AddressType()     { return NULL; }
   1.144 +  virtual IllegalType*      as_IllegalType()     { return NULL; }
   1.145 +
   1.146 +  virtual IntConstant*      as_IntConstant()     { return NULL; }
   1.147 +  virtual LongConstant*     as_LongConstant()    { return NULL; }
   1.148 +  virtual FloatConstant*    as_FloatConstant()   { return NULL; }
   1.149 +  virtual DoubleConstant*   as_DoubleConstant()  { return NULL; }
   1.150 +  virtual ObjectConstant*   as_ObjectConstant()  { return NULL; }
   1.151 +  virtual InstanceConstant* as_InstanceConstant(){ return NULL; }
   1.152 +  virtual ClassConstant*    as_ClassConstant()   { return NULL; }
   1.153 +  virtual ArrayConstant*    as_ArrayConstant()   { return NULL; }
   1.154 +  virtual AddressConstant*  as_AddressConstant() { return NULL; }
   1.155 +
   1.156 +  // type operations
   1.157 +  ValueType* meet(ValueType* y) const;
   1.158 +  ValueType* join(ValueType* y) const;
   1.159 +
   1.160 +  // debugging
   1.161 +  void print(outputStream* s = tty)              { s->print(name()); }
   1.162 +};
   1.163 +
   1.164 +
   1.165 +class VoidType: public ValueType {
   1.166 + public:
   1.167 +  VoidType(): ValueType(voidTag, 0) {}
   1.168 +  virtual ValueType* base() const                { return voidType; }
   1.169 +  virtual const char tchar() const               { return 'v'; }
   1.170 +  virtual const char* name() const               { return "void"; }
   1.171 +  virtual VoidType* as_VoidType()                { return this; }
   1.172 +};
   1.173 +
   1.174 +
   1.175 +class IntType: public ValueType {
   1.176 + public:
   1.177 +  IntType(): ValueType(intTag, 1) {}
   1.178 +  virtual ValueType* base() const                { return intType; }
   1.179 +  virtual const char tchar() const               { return 'i'; }
   1.180 +  virtual const char* name() const               { return "int"; }
   1.181 +  virtual IntType* as_IntType()                  { return this; }
   1.182 +};
   1.183 +
   1.184 +
   1.185 +class IntConstant: public IntType {
   1.186 + private:
   1.187 +  jint _value;
   1.188 +
   1.189 + public:
   1.190 +  IntConstant(jint value)                        { _value = value; }
   1.191 +
   1.192 +  jint value() const                             { return _value; }
   1.193 +
   1.194 +  virtual bool is_constant() const               { return true; }
   1.195 +  virtual IntConstant* as_IntConstant()          { return this; }
   1.196 +};
   1.197 +
   1.198 +
   1.199 +class IntInterval: public IntType {
   1.200 + private:
   1.201 +  jint _beg;
   1.202 +  jint _end;
   1.203 +
   1.204 + public:
   1.205 +  IntInterval(jint beg, jint end) {
   1.206 +    assert(beg <= end, "illegal interval");
   1.207 +    _beg = beg;
   1.208 +    _end = end;
   1.209 +  }
   1.210 +
   1.211 +  jint beg() const                               { return _beg; }
   1.212 +  jint end() const                               { return _end; }
   1.213 +
   1.214 +  virtual bool is_interval() const               { return true; }
   1.215 +};
   1.216 +
   1.217 +
   1.218 +class LongType: public ValueType {
   1.219 + public:
   1.220 +  LongType(): ValueType(longTag, 2) {}
   1.221 +  virtual ValueType* base() const                { return longType; }
   1.222 +  virtual const char tchar() const               { return 'l'; }
   1.223 +  virtual const char* name() const               { return "long"; }
   1.224 +  virtual LongType* as_LongType()                { return this; }
   1.225 +};
   1.226 +
   1.227 +
   1.228 +class LongConstant: public LongType {
   1.229 + private:
   1.230 +  jlong _value;
   1.231 +
   1.232 + public:
   1.233 +  LongConstant(jlong value)                      { _value = value; }
   1.234 +
   1.235 +  jlong value() const                            { return _value; }
   1.236 +
   1.237 +  virtual bool is_constant() const               { return true; }
   1.238 +  virtual LongConstant* as_LongConstant()        { return this; }
   1.239 +};
   1.240 +
   1.241 +
   1.242 +class FloatType: public ValueType {
   1.243 + public:
   1.244 +  FloatType(): ValueType(floatTag, 1) {}
   1.245 +  virtual ValueType* base() const                { return floatType; }
   1.246 +  virtual const char tchar() const               { return 'f'; }
   1.247 +  virtual const char* name() const               { return "float"; }
   1.248 +  virtual FloatType* as_FloatType()              { return this; }
   1.249 +};
   1.250 +
   1.251 +
   1.252 +class FloatConstant: public FloatType {
   1.253 + private:
   1.254 +  jfloat _value;
   1.255 +
   1.256 + public:
   1.257 +  FloatConstant(jfloat value)                    { _value = value; }
   1.258 +
   1.259 +  jfloat value() const                           { return _value; }
   1.260 +
   1.261 +  virtual bool is_constant() const               { return true; }
   1.262 +  virtual FloatConstant* as_FloatConstant()      { return this; }
   1.263 +};
   1.264 +
   1.265 +
   1.266 +class DoubleType: public ValueType {
   1.267 + public:
   1.268 +  DoubleType(): ValueType(doubleTag, 2) {}
   1.269 +  virtual ValueType* base() const                { return doubleType; }
   1.270 +  virtual const char tchar() const               { return 'd'; }
   1.271 +  virtual const char* name() const               { return "double"; }
   1.272 +  virtual DoubleType* as_DoubleType()            { return this; }
   1.273 +};
   1.274 +
   1.275 +
   1.276 +class DoubleConstant: public DoubleType {
   1.277 + private:
   1.278 +  jdouble _value;
   1.279 +
   1.280 + public:
   1.281 +  DoubleConstant(jdouble value)                  { _value = value; }
   1.282 +
   1.283 +  jdouble value() const                          { return _value; }
   1.284 +
   1.285 +  virtual bool is_constant() const               { return true; }
   1.286 +  virtual DoubleConstant* as_DoubleConstant()    { return this; }
   1.287 +};
   1.288 +
   1.289 +
   1.290 +class ObjectType: public ValueType {
   1.291 + public:
   1.292 +  ObjectType(): ValueType(objectTag, 1) {}
   1.293 +  virtual ValueType* base() const                { return objectType; }
   1.294 +  virtual const char tchar() const               { return 'a'; }
   1.295 +  virtual const char* name() const               { return "object"; }
   1.296 +  virtual ObjectType* as_ObjectType()            { return this; }
   1.297 +  virtual ciObject* constant_value() const       { ShouldNotReachHere(); return NULL;  }
   1.298 +  bool is_loaded() const;
   1.299 +  jobject encoding() const;
   1.300 +};
   1.301 +
   1.302 +
   1.303 +class ObjectConstant: public ObjectType {
   1.304 + private:
   1.305 +  ciObject* _value;
   1.306 +
   1.307 + public:
   1.308 +  ObjectConstant(ciObject* value)                { _value = value; }
   1.309 +
   1.310 +  ciObject* value() const                        { return _value; }
   1.311 +
   1.312 +  virtual bool is_constant() const               { return true; }
   1.313 +  virtual ObjectConstant* as_ObjectConstant()    { return this; }
   1.314 +  virtual ciObject* constant_value() const;
   1.315 +};
   1.316 +
   1.317 +
   1.318 +class ArrayType: public ObjectType {
   1.319 + public:
   1.320 +  virtual ArrayType* as_ArrayType()              { return this; }
   1.321 +};
   1.322 +
   1.323 +
   1.324 +class ArrayConstant: public ArrayType {
   1.325 + private:
   1.326 +  ciArray* _value;
   1.327 +
   1.328 + public:
   1.329 +  ArrayConstant(ciArray* value)                  { _value = value; }
   1.330 +
   1.331 +  ciArray* value() const                         { return _value; }
   1.332 +
   1.333 +  virtual bool is_constant() const               { return true; }
   1.334 +
   1.335 +  virtual ArrayConstant* as_ArrayConstant()      { return this; }
   1.336 +  virtual ciObject* constant_value() const;
   1.337 +};
   1.338 +
   1.339 +
   1.340 +class InstanceType: public ObjectType {
   1.341 + public:
   1.342 +  virtual InstanceType* as_InstanceType()        { return this; }
   1.343 +};
   1.344 +
   1.345 +
   1.346 +class InstanceConstant: public InstanceType {
   1.347 + private:
   1.348 +  ciInstance* _value;
   1.349 +
   1.350 + public:
   1.351 +  InstanceConstant(ciInstance* value)            { _value = value; }
   1.352 +
   1.353 +  ciInstance* value() const                      { return _value; }
   1.354 +
   1.355 +  virtual bool is_constant() const               { return true; }
   1.356 +
   1.357 +  virtual InstanceConstant* as_InstanceConstant(){ return this; }
   1.358 +  virtual ciObject* constant_value() const;
   1.359 +};
   1.360 +
   1.361 +
   1.362 +class ClassType: public ObjectType {
   1.363 + public:
   1.364 +  virtual ClassType* as_ClassType()              { return this; }
   1.365 +};
   1.366 +
   1.367 +
   1.368 +class ClassConstant: public ClassType {
   1.369 + private:
   1.370 +  ciInstanceKlass* _value;
   1.371 +
   1.372 + public:
   1.373 +  ClassConstant(ciInstanceKlass* value)          { _value = value; }
   1.374 +
   1.375 +  ciInstanceKlass* value() const                 { return _value; }
   1.376 +
   1.377 +  virtual bool is_constant() const               { return true; }
   1.378 +
   1.379 +  virtual ClassConstant* as_ClassConstant()      { return this; }
   1.380 +  virtual ciObject* constant_value() const;
   1.381 +};
   1.382 +
   1.383 +
   1.384 +class AddressType: public ValueType {
   1.385 + public:
   1.386 +  AddressType(): ValueType(addressTag, 1) {}
   1.387 +  virtual ValueType* base() const                { return addressType; }
   1.388 +  virtual const char tchar() const               { return 'r'; }
   1.389 +  virtual const char* name() const               { return "address"; }
   1.390 +  virtual AddressType* as_AddressType()          { return this; }
   1.391 +};
   1.392 +
   1.393 +
   1.394 +class AddressConstant: public AddressType {
   1.395 + private:
   1.396 +  jint _value;
   1.397 +
   1.398 + public:
   1.399 +  AddressConstant(jint value)                    { _value = value; }
   1.400 +
   1.401 +  jint value() const                             { return _value; }
   1.402 +
   1.403 +  virtual bool is_constant() const               { return true; }
   1.404 +
   1.405 +  virtual AddressConstant* as_AddressConstant()  { return this; }
   1.406 +};
   1.407 +
   1.408 +
   1.409 +class IllegalType: public ValueType {
   1.410 + public:
   1.411 +  IllegalType(): ValueType(illegalTag, -1) {}
   1.412 +  virtual ValueType* base() const                { return illegalType; }
   1.413 +  virtual const char tchar() const               { return ' '; }
   1.414 +  virtual const char* name() const               { return "illegal"; }
   1.415 +  virtual IllegalType* as_IllegalType()          { return this; }
   1.416 +};
   1.417 +
   1.418 +
   1.419 +// conversion between ValueTypes, BasicTypes, and ciConstants
   1.420 +ValueType* as_ValueType(BasicType type);
   1.421 +ValueType* as_ValueType(ciConstant value);
   1.422 +BasicType  as_BasicType(ValueType* type);
   1.423 +
   1.424 +inline ValueType* as_ValueType(ciType* type) { return as_ValueType(type->basic_type()); }

mercurial