duke@435: /* coleenp@4037: * Copyright (c) 1999, 2012, 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: #include "precompiled.hpp" stefank@2314: #include "c1/c1_ValueType.hpp" stefank@2314: #include "ci/ciArray.hpp" stefank@2314: #include "ci/ciInstance.hpp" stefank@2314: #include "ci/ciNullObject.hpp" duke@435: duke@435: duke@435: // predefined types duke@435: VoidType* voidType = NULL; duke@435: IntType* intType = NULL; duke@435: LongType* longType = NULL; duke@435: FloatType* floatType = NULL; duke@435: DoubleType* doubleType = NULL; duke@435: ObjectType* objectType = NULL; duke@435: ArrayType* arrayType = NULL; duke@435: InstanceType* instanceType = NULL; duke@435: ClassType* classType = NULL; duke@435: AddressType* addressType = NULL; duke@435: IllegalType* illegalType = NULL; duke@435: duke@435: duke@435: // predefined constants duke@435: IntConstant* intZero = NULL; duke@435: IntConstant* intOne = NULL; duke@435: ObjectConstant* objectNull = NULL; duke@435: duke@435: iveresov@1939: void ValueType::initialize(Arena* arena) { duke@435: // Note: Must initialize all types for each compilation duke@435: // as they are allocated within a ResourceMark! duke@435: duke@435: // types iveresov@1939: voidType = new (arena) VoidType(); iveresov@1939: intType = new (arena) IntType(); iveresov@1939: longType = new (arena) LongType(); iveresov@1939: floatType = new (arena) FloatType(); iveresov@1939: doubleType = new (arena) DoubleType(); iveresov@1939: objectType = new (arena) ObjectType(); iveresov@1939: arrayType = new (arena) ArrayType(); iveresov@1939: instanceType = new (arena) InstanceType(); iveresov@1939: classType = new (arena) ClassType(); iveresov@1939: addressType = new (arena) AddressType(); iveresov@1939: illegalType = new (arena) IllegalType(); duke@435: iveresov@1939: intZero = new (arena) IntConstant(0); iveresov@1939: intOne = new (arena) IntConstant(1); iveresov@1939: objectNull = new (arena) ObjectConstant(ciNullObject::make()); duke@435: }; duke@435: duke@435: duke@435: ValueType* ValueType::meet(ValueType* y) const { duke@435: // incomplete & conservative solution for now - fix this! duke@435: assert(tag() == y->tag(), "types must match"); duke@435: return base(); duke@435: } duke@435: duke@435: duke@435: ValueType* ValueType::join(ValueType* y) const { duke@435: Unimplemented(); duke@435: return NULL; duke@435: } duke@435: duke@435: twisti@3969: ciType* ObjectConstant::exact_type() const { twisti@3969: ciObject* c = constant_value(); twisti@3969: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; twisti@3969: } twisti@3969: ciType* ArrayConstant::exact_type() const { twisti@3969: ciObject* c = constant_value(); twisti@3969: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; twisti@3969: } twisti@3969: ciType* InstanceConstant::exact_type() const { twisti@3969: ciObject* c = constant_value(); twisti@3969: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; twisti@3969: } twisti@3969: ciType* ClassConstant::exact_type() const { coleenp@4037: return Compilation::current()->env()->Class_klass(); twisti@3969: } twisti@3969: duke@435: coleenp@4037: jobject ObjectType::encoding() const { coleenp@4037: assert(is_constant(), "must be"); coleenp@4037: return constant_value()->constant_encoding(); coleenp@4037: } coleenp@4037: coleenp@4037: bool ObjectType::is_loaded() const { coleenp@4037: assert(is_constant(), "must be"); coleenp@4037: return constant_value()->is_loaded(); coleenp@4037: } coleenp@4037: coleenp@4037: bool MetadataType::is_loaded() const { coleenp@4037: assert(is_constant(), "must be"); coleenp@4037: return constant_value()->is_loaded(); coleenp@4037: } coleenp@4037: coleenp@4037: ciObject* ObjectConstant::constant_value() const { return _value; } coleenp@4037: ciObject* ArrayConstant::constant_value() const { return _value; } coleenp@4037: ciObject* InstanceConstant::constant_value() const { return _value; } coleenp@4037: duke@435: ValueType* as_ValueType(BasicType type) { duke@435: switch (type) { duke@435: case T_VOID : return voidType; duke@435: case T_BYTE : // fall through duke@435: case T_CHAR : // fall through duke@435: case T_SHORT : // fall through duke@435: case T_BOOLEAN: // fall through duke@435: case T_INT : return intType; duke@435: case T_LONG : return longType; duke@435: case T_FLOAT : return floatType; duke@435: case T_DOUBLE : return doubleType; duke@435: case T_ARRAY : return arrayType; duke@435: case T_OBJECT : return objectType; duke@435: case T_ADDRESS: return addressType; duke@435: case T_ILLEGAL: return illegalType; duke@435: } duke@435: ShouldNotReachHere(); duke@435: return illegalType; duke@435: } duke@435: duke@435: duke@435: ValueType* as_ValueType(ciConstant value) { duke@435: switch (value.basic_type()) { duke@435: case T_BYTE : // fall through duke@435: case T_CHAR : // fall through duke@435: case T_SHORT : // fall through duke@435: case T_BOOLEAN: // fall through duke@435: case T_INT : return new IntConstant (value.as_int ()); duke@435: case T_LONG : return new LongConstant (value.as_long ()); duke@435: case T_FLOAT : return new FloatConstant (value.as_float ()); duke@435: case T_DOUBLE : return new DoubleConstant(value.as_double()); duke@435: case T_ARRAY : // fall through (ciConstant doesn't have an array accessor) duke@435: case T_OBJECT : return new ObjectConstant(value.as_object()); duke@435: } duke@435: ShouldNotReachHere(); duke@435: return illegalType; duke@435: } duke@435: duke@435: duke@435: BasicType as_BasicType(ValueType* type) { duke@435: switch (type->tag()) { duke@435: case voidTag: return T_VOID; duke@435: case intTag: return T_INT; duke@435: case longTag: return T_LONG; duke@435: case floatTag: return T_FLOAT; duke@435: case doubleTag: return T_DOUBLE; duke@435: case objectTag: return T_OBJECT; roland@4051: case metaDataTag:return T_METADATA; duke@435: case addressTag: return T_ADDRESS; duke@435: case illegalTag: return T_ILLEGAL; duke@435: } duke@435: ShouldNotReachHere(); duke@435: return T_ILLEGAL; duke@435: }