1 /*
   2  * Copyright (c) 2000, 2001, 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 // ciType
  26 //
  27 // This class represents either a class (T_OBJECT), array (T_ARRAY),
  28 // or one of the primitive types such as T_INT.
  29 class ciType : public ciObject {
  30   CI_PACKAGE_ACCESS
  31   friend class ciKlass;
  32   friend class ciReturnAddress;
  33 
  34 private:
  35   BasicType _basic_type;
  36 
  37   ciType(BasicType t);     // for the primitive types only
  38   ciType(KlassHandle k);   // for subclasses (reference types)
  39   ciType(ciKlass* klass);  // for unloaded types
  40 
  41   const char* type_string() { return "ciType"; }
  42 
  43   void print_impl(outputStream* st);
  44 
  45   // Distinguished instances of primitive ciTypes..
  46   static ciType* _basic_types[T_CONFLICT+1];
  47 
  48 public:
  49   BasicType basic_type() const              { return _basic_type; }
  50 
  51   // Returns true iff the types are identical, or if both are klasses
  52   // and the is_subtype_of relation holds between the klasses.
  53   bool is_subtype_of(ciType* type);
  54 
  55   // Get the instance of java.lang.Class corresponding to this type.
  56   // There are mirrors for instance, array, and primitive types (incl. void).
  57   virtual ciInstance*    java_mirror();
  58 
  59   // Get the class which "boxes" (or "wraps") values of this type.
  60   // Example:  short is boxed by java.lang.Short, etc.
  61   // Returns self if it is a reference type.
  62   // Returns NULL for void, since null is used in such cases.
  63   ciKlass*  box_klass();
  64 
  65   // Returns true if this is not a klass or array (i.e., not a reference type).
  66   bool is_primitive_type() const            { return basic_type() != T_OBJECT && basic_type() != T_ARRAY; }
  67   int size() const                          { return type2size[basic_type()]; }
  68   bool is_void() const                      { return basic_type() == T_VOID; }
  69   bool is_one_word() const                  { return size() == 1; }
  70   bool is_two_word() const                  { return size() == 2; }
  71 
  72   // What kind of ciObject is this?
  73   bool is_type()                            { return true; }
  74   bool is_classless() const                 { return is_primitive_type(); }
  75 
  76   virtual void print_name_on(outputStream* st);
  77   void print_name() {
  78     print_name_on(tty);
  79   }
  80 
  81   static ciType* make(BasicType t);
  82 };
  83 
  84 
  85 // ciReturnAddress
  86 //
  87 // This class represents the type of a specific return address in the
  88 // bytecodes.
  89 class ciReturnAddress : public ciType {
  90   CI_PACKAGE_ACCESS
  91 
  92 private:
  93   // The bci of this return address.
  94   int _bci;
  95 
  96   ciReturnAddress(int bci);
  97 
  98   const char* type_string() { return "ciReturnAddress"; }
  99 
 100   void print_impl(outputStream* st);
 101 
 102 public:
 103   bool is_return_address()  { return true; }
 104 
 105   int  bci() { return _bci; }
 106 
 107   static ciReturnAddress* make(int bci);
 108 };