src/share/vm/c1/c1_ValueType.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4051
8a02ca5e5576
parent 0
f90c822e73f8
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_ValueType.hpp"
aoqi@0 27 #include "ci/ciArray.hpp"
aoqi@0 28 #include "ci/ciInstance.hpp"
aoqi@0 29 #include "ci/ciNullObject.hpp"
aoqi@0 30
aoqi@0 31
aoqi@0 32 // predefined types
aoqi@0 33 VoidType* voidType = NULL;
aoqi@0 34 IntType* intType = NULL;
aoqi@0 35 LongType* longType = NULL;
aoqi@0 36 FloatType* floatType = NULL;
aoqi@0 37 DoubleType* doubleType = NULL;
aoqi@0 38 ObjectType* objectType = NULL;
aoqi@0 39 ArrayType* arrayType = NULL;
aoqi@0 40 InstanceType* instanceType = NULL;
aoqi@0 41 ClassType* classType = NULL;
aoqi@0 42 AddressType* addressType = NULL;
aoqi@0 43 IllegalType* illegalType = NULL;
aoqi@0 44
aoqi@0 45
aoqi@0 46 // predefined constants
aoqi@0 47 IntConstant* intZero = NULL;
aoqi@0 48 IntConstant* intOne = NULL;
aoqi@0 49 ObjectConstant* objectNull = NULL;
aoqi@0 50
aoqi@0 51
aoqi@0 52 void ValueType::initialize(Arena* arena) {
aoqi@0 53 // Note: Must initialize all types for each compilation
aoqi@0 54 // as they are allocated within a ResourceMark!
aoqi@0 55
aoqi@0 56 // types
aoqi@0 57 voidType = new (arena) VoidType();
aoqi@0 58 intType = new (arena) IntType();
aoqi@0 59 longType = new (arena) LongType();
aoqi@0 60 floatType = new (arena) FloatType();
aoqi@0 61 doubleType = new (arena) DoubleType();
aoqi@0 62 objectType = new (arena) ObjectType();
aoqi@0 63 arrayType = new (arena) ArrayType();
aoqi@0 64 instanceType = new (arena) InstanceType();
aoqi@0 65 classType = new (arena) ClassType();
aoqi@0 66 addressType = new (arena) AddressType();
aoqi@0 67 illegalType = new (arena) IllegalType();
aoqi@0 68
aoqi@0 69 intZero = new (arena) IntConstant(0);
aoqi@0 70 intOne = new (arena) IntConstant(1);
aoqi@0 71 objectNull = new (arena) ObjectConstant(ciNullObject::make());
aoqi@0 72 };
aoqi@0 73
aoqi@0 74
aoqi@0 75 ValueType* ValueType::meet(ValueType* y) const {
aoqi@0 76 // incomplete & conservative solution for now - fix this!
aoqi@0 77 assert(tag() == y->tag(), "types must match");
aoqi@0 78 return base();
aoqi@0 79 }
aoqi@0 80
aoqi@0 81
aoqi@0 82 ValueType* ValueType::join(ValueType* y) const {
aoqi@0 83 Unimplemented();
aoqi@0 84 return NULL;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87
aoqi@0 88 ciType* ObjectConstant::exact_type() const {
aoqi@0 89 ciObject* c = constant_value();
aoqi@0 90 return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
aoqi@0 91 }
aoqi@0 92 ciType* ArrayConstant::exact_type() const {
aoqi@0 93 ciObject* c = constant_value();
aoqi@0 94 return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
aoqi@0 95 }
aoqi@0 96 ciType* InstanceConstant::exact_type() const {
aoqi@0 97 ciObject* c = constant_value();
aoqi@0 98 return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
aoqi@0 99 }
aoqi@0 100 ciType* ClassConstant::exact_type() const {
aoqi@0 101 return Compilation::current()->env()->Class_klass();
aoqi@0 102 }
aoqi@0 103
aoqi@0 104
aoqi@0 105 jobject ObjectType::encoding() const {
aoqi@0 106 assert(is_constant(), "must be");
aoqi@0 107 return constant_value()->constant_encoding();
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 bool ObjectType::is_loaded() const {
aoqi@0 111 assert(is_constant(), "must be");
aoqi@0 112 return constant_value()->is_loaded();
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 bool MetadataType::is_loaded() const {
aoqi@0 116 assert(is_constant(), "must be");
aoqi@0 117 return constant_value()->is_loaded();
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 ciObject* ObjectConstant::constant_value() const { return _value; }
aoqi@0 121 ciObject* ArrayConstant::constant_value() const { return _value; }
aoqi@0 122 ciObject* InstanceConstant::constant_value() const { return _value; }
aoqi@0 123
aoqi@0 124 ValueType* as_ValueType(BasicType type) {
aoqi@0 125 switch (type) {
aoqi@0 126 case T_VOID : return voidType;
aoqi@0 127 case T_BYTE : // fall through
aoqi@0 128 case T_CHAR : // fall through
aoqi@0 129 case T_SHORT : // fall through
aoqi@0 130 case T_BOOLEAN: // fall through
aoqi@0 131 case T_INT : return intType;
aoqi@0 132 case T_LONG : return longType;
aoqi@0 133 case T_FLOAT : return floatType;
aoqi@0 134 case T_DOUBLE : return doubleType;
aoqi@0 135 case T_ARRAY : return arrayType;
aoqi@0 136 case T_OBJECT : return objectType;
aoqi@0 137 case T_ADDRESS: return addressType;
aoqi@0 138 case T_ILLEGAL: return illegalType;
aoqi@0 139 }
aoqi@0 140 ShouldNotReachHere();
aoqi@0 141 return illegalType;
aoqi@0 142 }
aoqi@0 143
aoqi@0 144
aoqi@0 145 ValueType* as_ValueType(ciConstant value) {
aoqi@0 146 switch (value.basic_type()) {
aoqi@0 147 case T_BYTE : // fall through
aoqi@0 148 case T_CHAR : // fall through
aoqi@0 149 case T_SHORT : // fall through
aoqi@0 150 case T_BOOLEAN: // fall through
aoqi@0 151 case T_INT : return new IntConstant (value.as_int ());
aoqi@0 152 case T_LONG : return new LongConstant (value.as_long ());
aoqi@0 153 case T_FLOAT : return new FloatConstant (value.as_float ());
aoqi@0 154 case T_DOUBLE : return new DoubleConstant(value.as_double());
aoqi@0 155 case T_ARRAY : // fall through (ciConstant doesn't have an array accessor)
aoqi@0 156 case T_OBJECT : return new ObjectConstant(value.as_object());
aoqi@0 157 }
aoqi@0 158 ShouldNotReachHere();
aoqi@0 159 return illegalType;
aoqi@0 160 }
aoqi@0 161
aoqi@0 162
aoqi@0 163 BasicType as_BasicType(ValueType* type) {
aoqi@0 164 switch (type->tag()) {
aoqi@0 165 case voidTag: return T_VOID;
aoqi@0 166 case intTag: return T_INT;
aoqi@0 167 case longTag: return T_LONG;
aoqi@0 168 case floatTag: return T_FLOAT;
aoqi@0 169 case doubleTag: return T_DOUBLE;
aoqi@0 170 case objectTag: return T_OBJECT;
aoqi@0 171 case metaDataTag:return T_METADATA;
aoqi@0 172 case addressTag: return T_ADDRESS;
aoqi@0 173 case illegalTag: return T_ILLEGAL;
aoqi@0 174 }
aoqi@0 175 ShouldNotReachHere();
aoqi@0 176 return T_ILLEGAL;
aoqi@0 177 }

mercurial