aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "c1/c1_ValueType.hpp" aoqi@0: #include "ci/ciArray.hpp" aoqi@0: #include "ci/ciInstance.hpp" aoqi@0: #include "ci/ciNullObject.hpp" aoqi@0: aoqi@0: aoqi@0: // predefined types aoqi@0: VoidType* voidType = NULL; aoqi@0: IntType* intType = NULL; aoqi@0: LongType* longType = NULL; aoqi@0: FloatType* floatType = NULL; aoqi@0: DoubleType* doubleType = NULL; aoqi@0: ObjectType* objectType = NULL; aoqi@0: ArrayType* arrayType = NULL; aoqi@0: InstanceType* instanceType = NULL; aoqi@0: ClassType* classType = NULL; aoqi@0: AddressType* addressType = NULL; aoqi@0: IllegalType* illegalType = NULL; aoqi@0: aoqi@0: aoqi@0: // predefined constants aoqi@0: IntConstant* intZero = NULL; aoqi@0: IntConstant* intOne = NULL; aoqi@0: ObjectConstant* objectNull = NULL; aoqi@0: aoqi@0: aoqi@0: void ValueType::initialize(Arena* arena) { aoqi@0: // Note: Must initialize all types for each compilation aoqi@0: // as they are allocated within a ResourceMark! aoqi@0: aoqi@0: // types aoqi@0: voidType = new (arena) VoidType(); aoqi@0: intType = new (arena) IntType(); aoqi@0: longType = new (arena) LongType(); aoqi@0: floatType = new (arena) FloatType(); aoqi@0: doubleType = new (arena) DoubleType(); aoqi@0: objectType = new (arena) ObjectType(); aoqi@0: arrayType = new (arena) ArrayType(); aoqi@0: instanceType = new (arena) InstanceType(); aoqi@0: classType = new (arena) ClassType(); aoqi@0: addressType = new (arena) AddressType(); aoqi@0: illegalType = new (arena) IllegalType(); aoqi@0: aoqi@0: intZero = new (arena) IntConstant(0); aoqi@0: intOne = new (arena) IntConstant(1); aoqi@0: objectNull = new (arena) ObjectConstant(ciNullObject::make()); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: ValueType* ValueType::meet(ValueType* y) const { aoqi@0: // incomplete & conservative solution for now - fix this! aoqi@0: assert(tag() == y->tag(), "types must match"); aoqi@0: return base(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ValueType* ValueType::join(ValueType* y) const { aoqi@0: Unimplemented(); aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ciType* ObjectConstant::exact_type() const { aoqi@0: ciObject* c = constant_value(); aoqi@0: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; aoqi@0: } aoqi@0: ciType* ArrayConstant::exact_type() const { aoqi@0: ciObject* c = constant_value(); aoqi@0: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; aoqi@0: } aoqi@0: ciType* InstanceConstant::exact_type() const { aoqi@0: ciObject* c = constant_value(); aoqi@0: return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; aoqi@0: } aoqi@0: ciType* ClassConstant::exact_type() const { aoqi@0: return Compilation::current()->env()->Class_klass(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: jobject ObjectType::encoding() const { aoqi@0: assert(is_constant(), "must be"); aoqi@0: return constant_value()->constant_encoding(); aoqi@0: } aoqi@0: aoqi@0: bool ObjectType::is_loaded() const { aoqi@0: assert(is_constant(), "must be"); aoqi@0: return constant_value()->is_loaded(); aoqi@0: } aoqi@0: aoqi@0: bool MetadataType::is_loaded() const { aoqi@0: assert(is_constant(), "must be"); aoqi@0: return constant_value()->is_loaded(); aoqi@0: } aoqi@0: aoqi@0: ciObject* ObjectConstant::constant_value() const { return _value; } aoqi@0: ciObject* ArrayConstant::constant_value() const { return _value; } aoqi@0: ciObject* InstanceConstant::constant_value() const { return _value; } aoqi@0: aoqi@0: ValueType* as_ValueType(BasicType type) { aoqi@0: switch (type) { aoqi@0: case T_VOID : return voidType; aoqi@0: case T_BYTE : // fall through aoqi@0: case T_CHAR : // fall through aoqi@0: case T_SHORT : // fall through aoqi@0: case T_BOOLEAN: // fall through aoqi@0: case T_INT : return intType; aoqi@0: case T_LONG : return longType; aoqi@0: case T_FLOAT : return floatType; aoqi@0: case T_DOUBLE : return doubleType; aoqi@0: case T_ARRAY : return arrayType; aoqi@0: case T_OBJECT : return objectType; aoqi@0: case T_ADDRESS: return addressType; aoqi@0: case T_ILLEGAL: return illegalType; aoqi@0: } aoqi@0: ShouldNotReachHere(); aoqi@0: return illegalType; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ValueType* as_ValueType(ciConstant value) { aoqi@0: switch (value.basic_type()) { aoqi@0: case T_BYTE : // fall through aoqi@0: case T_CHAR : // fall through aoqi@0: case T_SHORT : // fall through aoqi@0: case T_BOOLEAN: // fall through aoqi@0: case T_INT : return new IntConstant (value.as_int ()); aoqi@0: case T_LONG : return new LongConstant (value.as_long ()); aoqi@0: case T_FLOAT : return new FloatConstant (value.as_float ()); aoqi@0: case T_DOUBLE : return new DoubleConstant(value.as_double()); aoqi@0: case T_ARRAY : // fall through (ciConstant doesn't have an array accessor) aoqi@0: case T_OBJECT : return new ObjectConstant(value.as_object()); aoqi@0: } aoqi@0: ShouldNotReachHere(); aoqi@0: return illegalType; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: BasicType as_BasicType(ValueType* type) { aoqi@0: switch (type->tag()) { aoqi@0: case voidTag: return T_VOID; aoqi@0: case intTag: return T_INT; aoqi@0: case longTag: return T_LONG; aoqi@0: case floatTag: return T_FLOAT; aoqi@0: case doubleTag: return T_DOUBLE; aoqi@0: case objectTag: return T_OBJECT; aoqi@0: case metaDataTag:return T_METADATA; aoqi@0: case addressTag: return T_ADDRESS; aoqi@0: case illegalTag: return T_ILLEGAL; aoqi@0: } aoqi@0: ShouldNotReachHere(); aoqi@0: return T_ILLEGAL; aoqi@0: }