duke@435: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_C1_C1_VALUETYPE_HPP stefank@2314: #define SHARE_VM_C1_C1_VALUETYPE_HPP stefank@2314: stefank@2314: #include "c1/c1_Compilation.hpp" stefank@2314: #include "ci/ciConstant.hpp" stefank@2314: duke@435: // type hierarchy duke@435: class ValueType; duke@435: class VoidType; duke@435: class IntType; duke@435: class IntConstant; duke@435: class IntInterval; duke@435: class LongType; duke@435: class LongConstant; duke@435: class FloatType; duke@435: class FloatConstant; duke@435: class DoubleType; duke@435: class DoubleConstant; duke@435: class ObjectType; duke@435: class ObjectConstant; duke@435: class ArrayType; duke@435: class ArrayConstant; duke@435: class InstanceType; duke@435: class InstanceConstant; duke@435: class ClassType; duke@435: class ClassConstant; duke@435: class AddressType; duke@435: class AddressConstant; duke@435: class IllegalType; duke@435: duke@435: duke@435: // predefined types duke@435: extern VoidType* voidType; duke@435: extern IntType* intType; duke@435: extern LongType* longType; duke@435: extern FloatType* floatType; duke@435: extern DoubleType* doubleType; duke@435: extern ObjectType* objectType; duke@435: extern ArrayType* arrayType; duke@435: extern InstanceType* instanceType; duke@435: extern ClassType* classType; duke@435: extern AddressType* addressType; duke@435: extern IllegalType* illegalType; duke@435: duke@435: duke@435: // predefined constants duke@435: extern IntConstant* intZero; duke@435: extern IntConstant* intOne; duke@435: extern ObjectConstant* objectNull; duke@435: duke@435: duke@435: // tags duke@435: enum ValueTag { duke@435: // all legal tags must come first duke@435: intTag, duke@435: longTag, duke@435: floatTag, duke@435: doubleTag, duke@435: objectTag, duke@435: addressTag, duke@435: number_of_legal_tags, duke@435: // all other tags must follow afterwards duke@435: voidTag = number_of_legal_tags, duke@435: illegalTag, duke@435: number_of_tags duke@435: }; duke@435: duke@435: duke@435: class ValueType: public CompilationResourceObj { duke@435: private: duke@435: const int _size; duke@435: const ValueTag _tag; duke@435: ValueType(); duke@435: protected: duke@435: ValueType(ValueTag tag, int size): _tag(tag), _size(size) {} duke@435: duke@435: public: duke@435: // initialization iveresov@1939: static void initialize(Arena* arena); duke@435: duke@435: // accessors duke@435: virtual ValueType* base() const = 0; // the 'canonical' type (e.g., intType for an IntConstant) duke@435: ValueTag tag() const { return _tag; } // the 'canonical' tag (useful for type matching) duke@435: int size() const { // the size of an object of the type in words duke@435: assert(_size > -1, "shouldn't be asking for size"); duke@435: return _size; duke@435: } duke@435: virtual const char tchar() const = 0; // the type 'character' for printing duke@435: virtual const char* name() const = 0; // the type name for printing duke@435: virtual bool is_constant() const { return false; } duke@435: duke@435: // testers duke@435: bool is_void() { return tag() == voidTag; } duke@435: bool is_int() { return tag() == intTag; } duke@435: bool is_long() { return tag() == longTag; } duke@435: bool is_float() { return tag() == floatTag; } duke@435: bool is_double() { return tag() == doubleTag; } duke@435: bool is_object() { return as_ObjectType() != NULL; } duke@435: bool is_array() { return as_ArrayType() != NULL; } duke@435: bool is_instance() { return as_InstanceType() != NULL; } duke@435: bool is_class() { return as_ClassType() != NULL; } duke@435: bool is_address() { return as_AddressType() != NULL; } duke@435: bool is_illegal() { return tag() == illegalTag; } duke@435: duke@435: bool is_int_kind() const { return tag() == intTag || tag() == longTag; } duke@435: bool is_float_kind() const { return tag() == floatTag || tag() == doubleTag; } duke@435: bool is_object_kind() const { return tag() == objectTag; } duke@435: duke@435: bool is_single_word() const { return _size == 1; } duke@435: bool is_double_word() const { return _size == 2; } duke@435: duke@435: // casting duke@435: virtual VoidType* as_VoidType() { return NULL; } duke@435: virtual IntType* as_IntType() { return NULL; } duke@435: virtual LongType* as_LongType() { return NULL; } duke@435: virtual FloatType* as_FloatType() { return NULL; } duke@435: virtual DoubleType* as_DoubleType() { return NULL; } duke@435: virtual ObjectType* as_ObjectType() { return NULL; } duke@435: virtual ArrayType* as_ArrayType() { return NULL; } duke@435: virtual InstanceType* as_InstanceType() { return NULL; } duke@435: virtual ClassType* as_ClassType() { return NULL; } duke@435: virtual AddressType* as_AddressType() { return NULL; } duke@435: virtual IllegalType* as_IllegalType() { return NULL; } duke@435: duke@435: virtual IntConstant* as_IntConstant() { return NULL; } duke@435: virtual LongConstant* as_LongConstant() { return NULL; } duke@435: virtual FloatConstant* as_FloatConstant() { return NULL; } duke@435: virtual DoubleConstant* as_DoubleConstant() { return NULL; } duke@435: virtual ObjectConstant* as_ObjectConstant() { return NULL; } duke@435: virtual InstanceConstant* as_InstanceConstant(){ return NULL; } duke@435: virtual ClassConstant* as_ClassConstant() { return NULL; } duke@435: virtual ArrayConstant* as_ArrayConstant() { return NULL; } duke@435: virtual AddressConstant* as_AddressConstant() { return NULL; } duke@435: duke@435: // type operations duke@435: ValueType* meet(ValueType* y) const; duke@435: ValueType* join(ValueType* y) const; duke@435: duke@435: // debugging duke@435: void print(outputStream* s = tty) { s->print(name()); } duke@435: }; duke@435: duke@435: duke@435: class VoidType: public ValueType { duke@435: public: duke@435: VoidType(): ValueType(voidTag, 0) {} duke@435: virtual ValueType* base() const { return voidType; } duke@435: virtual const char tchar() const { return 'v'; } duke@435: virtual const char* name() const { return "void"; } duke@435: virtual VoidType* as_VoidType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class IntType: public ValueType { duke@435: public: duke@435: IntType(): ValueType(intTag, 1) {} duke@435: virtual ValueType* base() const { return intType; } duke@435: virtual const char tchar() const { return 'i'; } duke@435: virtual const char* name() const { return "int"; } duke@435: virtual IntType* as_IntType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class IntConstant: public IntType { duke@435: private: duke@435: jint _value; duke@435: duke@435: public: duke@435: IntConstant(jint value) { _value = value; } duke@435: duke@435: jint value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: virtual IntConstant* as_IntConstant() { return this; } duke@435: }; duke@435: duke@435: duke@435: class IntInterval: public IntType { duke@435: private: duke@435: jint _beg; duke@435: jint _end; duke@435: duke@435: public: duke@435: IntInterval(jint beg, jint end) { duke@435: assert(beg <= end, "illegal interval"); duke@435: _beg = beg; duke@435: _end = end; duke@435: } duke@435: duke@435: jint beg() const { return _beg; } duke@435: jint end() const { return _end; } duke@435: duke@435: virtual bool is_interval() const { return true; } duke@435: }; duke@435: duke@435: duke@435: class LongType: public ValueType { duke@435: public: duke@435: LongType(): ValueType(longTag, 2) {} duke@435: virtual ValueType* base() const { return longType; } duke@435: virtual const char tchar() const { return 'l'; } duke@435: virtual const char* name() const { return "long"; } duke@435: virtual LongType* as_LongType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class LongConstant: public LongType { duke@435: private: duke@435: jlong _value; duke@435: duke@435: public: duke@435: LongConstant(jlong value) { _value = value; } duke@435: duke@435: jlong value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: virtual LongConstant* as_LongConstant() { return this; } duke@435: }; duke@435: duke@435: duke@435: class FloatType: public ValueType { duke@435: public: duke@435: FloatType(): ValueType(floatTag, 1) {} duke@435: virtual ValueType* base() const { return floatType; } duke@435: virtual const char tchar() const { return 'f'; } duke@435: virtual const char* name() const { return "float"; } duke@435: virtual FloatType* as_FloatType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class FloatConstant: public FloatType { duke@435: private: duke@435: jfloat _value; duke@435: duke@435: public: duke@435: FloatConstant(jfloat value) { _value = value; } duke@435: duke@435: jfloat value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: virtual FloatConstant* as_FloatConstant() { return this; } duke@435: }; duke@435: duke@435: duke@435: class DoubleType: public ValueType { duke@435: public: duke@435: DoubleType(): ValueType(doubleTag, 2) {} duke@435: virtual ValueType* base() const { return doubleType; } duke@435: virtual const char tchar() const { return 'd'; } duke@435: virtual const char* name() const { return "double"; } duke@435: virtual DoubleType* as_DoubleType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class DoubleConstant: public DoubleType { duke@435: private: duke@435: jdouble _value; duke@435: duke@435: public: duke@435: DoubleConstant(jdouble value) { _value = value; } duke@435: duke@435: jdouble value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: virtual DoubleConstant* as_DoubleConstant() { return this; } duke@435: }; duke@435: duke@435: duke@435: class ObjectType: public ValueType { duke@435: public: duke@435: ObjectType(): ValueType(objectTag, 1) {} duke@435: virtual ValueType* base() const { return objectType; } duke@435: virtual const char tchar() const { return 'a'; } duke@435: virtual const char* name() const { return "object"; } duke@435: virtual ObjectType* as_ObjectType() { return this; } duke@435: virtual ciObject* constant_value() const { ShouldNotReachHere(); return NULL; } duke@435: bool is_loaded() const; duke@435: jobject encoding() const; duke@435: }; duke@435: duke@435: duke@435: class ObjectConstant: public ObjectType { duke@435: private: duke@435: ciObject* _value; duke@435: duke@435: public: duke@435: ObjectConstant(ciObject* value) { _value = value; } duke@435: duke@435: ciObject* value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: virtual ObjectConstant* as_ObjectConstant() { return this; } duke@435: virtual ciObject* constant_value() const; duke@435: }; duke@435: duke@435: duke@435: class ArrayType: public ObjectType { duke@435: public: duke@435: virtual ArrayType* as_ArrayType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class ArrayConstant: public ArrayType { duke@435: private: duke@435: ciArray* _value; duke@435: duke@435: public: duke@435: ArrayConstant(ciArray* value) { _value = value; } duke@435: duke@435: ciArray* value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: duke@435: virtual ArrayConstant* as_ArrayConstant() { return this; } duke@435: virtual ciObject* constant_value() const; duke@435: }; duke@435: duke@435: duke@435: class InstanceType: public ObjectType { duke@435: public: duke@435: virtual InstanceType* as_InstanceType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class InstanceConstant: public InstanceType { duke@435: private: duke@435: ciInstance* _value; duke@435: duke@435: public: duke@435: InstanceConstant(ciInstance* value) { _value = value; } duke@435: duke@435: ciInstance* value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: duke@435: virtual InstanceConstant* as_InstanceConstant(){ return this; } duke@435: virtual ciObject* constant_value() const; duke@435: }; duke@435: duke@435: duke@435: class ClassType: public ObjectType { duke@435: public: duke@435: virtual ClassType* as_ClassType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class ClassConstant: public ClassType { duke@435: private: duke@435: ciInstanceKlass* _value; duke@435: duke@435: public: duke@435: ClassConstant(ciInstanceKlass* value) { _value = value; } duke@435: duke@435: ciInstanceKlass* value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: duke@435: virtual ClassConstant* as_ClassConstant() { return this; } duke@435: virtual ciObject* constant_value() const; duke@435: }; duke@435: duke@435: duke@435: class AddressType: public ValueType { duke@435: public: duke@435: AddressType(): ValueType(addressTag, 1) {} duke@435: virtual ValueType* base() const { return addressType; } duke@435: virtual const char tchar() const { return 'r'; } duke@435: virtual const char* name() const { return "address"; } duke@435: virtual AddressType* as_AddressType() { return this; } duke@435: }; duke@435: duke@435: duke@435: class AddressConstant: public AddressType { duke@435: private: duke@435: jint _value; duke@435: duke@435: public: duke@435: AddressConstant(jint value) { _value = value; } duke@435: duke@435: jint value() const { return _value; } duke@435: duke@435: virtual bool is_constant() const { return true; } duke@435: duke@435: virtual AddressConstant* as_AddressConstant() { return this; } duke@435: }; duke@435: duke@435: duke@435: class IllegalType: public ValueType { duke@435: public: duke@435: IllegalType(): ValueType(illegalTag, -1) {} duke@435: virtual ValueType* base() const { return illegalType; } duke@435: virtual const char tchar() const { return ' '; } duke@435: virtual const char* name() const { return "illegal"; } duke@435: virtual IllegalType* as_IllegalType() { return this; } duke@435: }; duke@435: duke@435: duke@435: // conversion between ValueTypes, BasicTypes, and ciConstants duke@435: ValueType* as_ValueType(BasicType type); duke@435: ValueType* as_ValueType(ciConstant value); duke@435: BasicType as_BasicType(ValueType* type); duke@435: duke@435: inline ValueType* as_ValueType(ciType* type) { return as_ValueType(type->basic_type()); } stefank@2314: stefank@2314: #endif // SHARE_VM_C1_C1_VALUETYPE_HPP