1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/c1/c1_ValueType.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,502 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_C1_C1_VALUETYPE_HPP 1.29 +#define SHARE_VM_C1_C1_VALUETYPE_HPP 1.30 + 1.31 +#include "c1/c1_Compilation.hpp" 1.32 +#include "ci/ciConstant.hpp" 1.33 +#include "ci/ciMethodData.hpp" 1.34 + 1.35 +// type hierarchy 1.36 +class ValueType; 1.37 +class VoidType; 1.38 +class IntType; 1.39 +class IntConstant; 1.40 +class IntInterval; 1.41 +class LongType; 1.42 +class LongConstant; 1.43 +class FloatType; 1.44 +class FloatConstant; 1.45 +class DoubleType; 1.46 +class DoubleConstant; 1.47 +class ObjectType; 1.48 +class ObjectConstant; 1.49 +class ArrayType; 1.50 +class ArrayConstant; 1.51 +class InstanceType; 1.52 +class InstanceConstant; 1.53 +class MetadataType; 1.54 +class ClassType; 1.55 +class ClassConstant; 1.56 +class MethodType; 1.57 +class MethodConstant; 1.58 +class MethodDataType; 1.59 +class MethodDataConstant; 1.60 +class AddressType; 1.61 +class AddressConstant; 1.62 +class IllegalType; 1.63 + 1.64 + 1.65 +// predefined types 1.66 +extern VoidType* voidType; 1.67 +extern IntType* intType; 1.68 +extern LongType* longType; 1.69 +extern FloatType* floatType; 1.70 +extern DoubleType* doubleType; 1.71 +extern ObjectType* objectType; 1.72 +extern ArrayType* arrayType; 1.73 +extern InstanceType* instanceType; 1.74 +extern ClassType* classType; 1.75 +extern AddressType* addressType; 1.76 +extern IllegalType* illegalType; 1.77 + 1.78 + 1.79 +// predefined constants 1.80 +extern IntConstant* intZero; 1.81 +extern IntConstant* intOne; 1.82 +extern ObjectConstant* objectNull; 1.83 + 1.84 + 1.85 +// tags 1.86 +enum ValueTag { 1.87 + // all legal tags must come first 1.88 + intTag, 1.89 + longTag, 1.90 + floatTag, 1.91 + doubleTag, 1.92 + objectTag, 1.93 + addressTag, 1.94 + metaDataTag, 1.95 + number_of_legal_tags, 1.96 + // all other tags must follow afterwards 1.97 + voidTag = number_of_legal_tags, 1.98 + illegalTag, 1.99 + number_of_tags 1.100 +}; 1.101 + 1.102 + 1.103 +class ValueType: public CompilationResourceObj { 1.104 + private: 1.105 + const int _size; 1.106 + const ValueTag _tag; 1.107 + ValueType(); 1.108 + protected: 1.109 + ValueType(ValueTag tag, int size): _tag(tag), _size(size) {} 1.110 + 1.111 + public: 1.112 + // initialization 1.113 + static void initialize(Arena* arena); 1.114 + 1.115 + // accessors 1.116 + virtual ValueType* base() const = 0; // the 'canonical' type (e.g., intType for an IntConstant) 1.117 + ValueTag tag() const { return _tag; } // the 'canonical' tag (useful for type matching) 1.118 + int size() const { // the size of an object of the type in words 1.119 + assert(_size > -1, "shouldn't be asking for size"); 1.120 + return _size; 1.121 + } 1.122 + virtual const char tchar() const = 0; // the type 'character' for printing 1.123 + virtual const char* name() const = 0; // the type name for printing 1.124 + virtual bool is_constant() const { return false; } 1.125 + 1.126 + // testers 1.127 + bool is_void() { return tag() == voidTag; } 1.128 + bool is_int() { return tag() == intTag; } 1.129 + bool is_long() { return tag() == longTag; } 1.130 + bool is_float() { return tag() == floatTag; } 1.131 + bool is_double() { return tag() == doubleTag; } 1.132 + bool is_object() { return as_ObjectType() != NULL; } 1.133 + bool is_array() { return as_ArrayType() != NULL; } 1.134 + bool is_instance() { return as_InstanceType() != NULL; } 1.135 + bool is_class() { return as_ClassType() != NULL; } 1.136 + bool is_method() { return as_MethodType() != NULL; } 1.137 + bool is_method_data() { return as_MethodDataType() != NULL; } 1.138 + bool is_address() { return as_AddressType() != NULL; } 1.139 + bool is_illegal() { return tag() == illegalTag; } 1.140 + 1.141 + bool is_int_kind() const { return tag() == intTag || tag() == longTag; } 1.142 + bool is_float_kind() const { return tag() == floatTag || tag() == doubleTag; } 1.143 + bool is_object_kind() const { return tag() == objectTag; } 1.144 + 1.145 + bool is_single_word() const { return _size == 1; } 1.146 + bool is_double_word() const { return _size == 2; } 1.147 + 1.148 + // casting 1.149 + virtual VoidType* as_VoidType() { return NULL; } 1.150 + virtual IntType* as_IntType() { return NULL; } 1.151 + virtual LongType* as_LongType() { return NULL; } 1.152 + virtual FloatType* as_FloatType() { return NULL; } 1.153 + virtual DoubleType* as_DoubleType() { return NULL; } 1.154 + virtual ObjectType* as_ObjectType() { return NULL; } 1.155 + virtual ArrayType* as_ArrayType() { return NULL; } 1.156 + virtual InstanceType* as_InstanceType() { return NULL; } 1.157 + virtual ClassType* as_ClassType() { return NULL; } 1.158 + virtual MetadataType* as_MetadataType() { return NULL; } 1.159 + virtual MethodType* as_MethodType() { return NULL; } 1.160 + virtual MethodDataType* as_MethodDataType() { return NULL; } 1.161 + virtual AddressType* as_AddressType() { return NULL; } 1.162 + virtual IllegalType* as_IllegalType() { return NULL; } 1.163 + 1.164 + virtual IntConstant* as_IntConstant() { return NULL; } 1.165 + virtual LongConstant* as_LongConstant() { return NULL; } 1.166 + virtual FloatConstant* as_FloatConstant() { return NULL; } 1.167 + virtual DoubleConstant* as_DoubleConstant() { return NULL; } 1.168 + virtual ObjectConstant* as_ObjectConstant() { return NULL; } 1.169 + virtual InstanceConstant* as_InstanceConstant(){ return NULL; } 1.170 + virtual ClassConstant* as_ClassConstant() { return NULL; } 1.171 + virtual MethodConstant* as_MethodConstant() { return NULL; } 1.172 + virtual MethodDataConstant* as_MethodDataConstant() { return NULL; } 1.173 + virtual ArrayConstant* as_ArrayConstant() { return NULL; } 1.174 + virtual AddressConstant* as_AddressConstant() { return NULL; } 1.175 + 1.176 + // type operations 1.177 + ValueType* meet(ValueType* y) const; 1.178 + ValueType* join(ValueType* y) const; 1.179 + 1.180 + // debugging 1.181 + void print(outputStream* s = tty) { s->print("%s", name()); } 1.182 +}; 1.183 + 1.184 + 1.185 +class VoidType: public ValueType { 1.186 + public: 1.187 + VoidType(): ValueType(voidTag, 0) {} 1.188 + virtual ValueType* base() const { return voidType; } 1.189 + virtual const char tchar() const { return 'v'; } 1.190 + virtual const char* name() const { return "void"; } 1.191 + virtual VoidType* as_VoidType() { return this; } 1.192 +}; 1.193 + 1.194 + 1.195 +class IntType: public ValueType { 1.196 + public: 1.197 + IntType(): ValueType(intTag, 1) {} 1.198 + virtual ValueType* base() const { return intType; } 1.199 + virtual const char tchar() const { return 'i'; } 1.200 + virtual const char* name() const { return "int"; } 1.201 + virtual IntType* as_IntType() { return this; } 1.202 +}; 1.203 + 1.204 + 1.205 +class IntConstant: public IntType { 1.206 + private: 1.207 + jint _value; 1.208 + 1.209 + public: 1.210 + IntConstant(jint value) { _value = value; } 1.211 + 1.212 + jint value() const { return _value; } 1.213 + 1.214 + virtual bool is_constant() const { return true; } 1.215 + virtual IntConstant* as_IntConstant() { return this; } 1.216 +}; 1.217 + 1.218 + 1.219 +class IntInterval: public IntType { 1.220 + private: 1.221 + jint _beg; 1.222 + jint _end; 1.223 + 1.224 + public: 1.225 + IntInterval(jint beg, jint end) { 1.226 + assert(beg <= end, "illegal interval"); 1.227 + _beg = beg; 1.228 + _end = end; 1.229 + } 1.230 + 1.231 + jint beg() const { return _beg; } 1.232 + jint end() const { return _end; } 1.233 + 1.234 + virtual bool is_interval() const { return true; } 1.235 +}; 1.236 + 1.237 + 1.238 +class LongType: public ValueType { 1.239 + public: 1.240 + LongType(): ValueType(longTag, 2) {} 1.241 + virtual ValueType* base() const { return longType; } 1.242 + virtual const char tchar() const { return 'l'; } 1.243 + virtual const char* name() const { return "long"; } 1.244 + virtual LongType* as_LongType() { return this; } 1.245 +}; 1.246 + 1.247 + 1.248 +class LongConstant: public LongType { 1.249 + private: 1.250 + jlong _value; 1.251 + 1.252 + public: 1.253 + LongConstant(jlong value) { _value = value; } 1.254 + 1.255 + jlong value() const { return _value; } 1.256 + 1.257 + virtual bool is_constant() const { return true; } 1.258 + virtual LongConstant* as_LongConstant() { return this; } 1.259 +}; 1.260 + 1.261 + 1.262 +class FloatType: public ValueType { 1.263 + public: 1.264 + FloatType(): ValueType(floatTag, 1) {} 1.265 + virtual ValueType* base() const { return floatType; } 1.266 + virtual const char tchar() const { return 'f'; } 1.267 + virtual const char* name() const { return "float"; } 1.268 + virtual FloatType* as_FloatType() { return this; } 1.269 +}; 1.270 + 1.271 + 1.272 +class FloatConstant: public FloatType { 1.273 + private: 1.274 + jfloat _value; 1.275 + 1.276 + public: 1.277 + FloatConstant(jfloat value) { _value = value; } 1.278 + 1.279 + jfloat value() const { return _value; } 1.280 + 1.281 + virtual bool is_constant() const { return true; } 1.282 + virtual FloatConstant* as_FloatConstant() { return this; } 1.283 +}; 1.284 + 1.285 + 1.286 +class DoubleType: public ValueType { 1.287 + public: 1.288 + DoubleType(): ValueType(doubleTag, 2) {} 1.289 + virtual ValueType* base() const { return doubleType; } 1.290 + virtual const char tchar() const { return 'd'; } 1.291 + virtual const char* name() const { return "double"; } 1.292 + virtual DoubleType* as_DoubleType() { return this; } 1.293 +}; 1.294 + 1.295 + 1.296 +class DoubleConstant: public DoubleType { 1.297 + private: 1.298 + jdouble _value; 1.299 + 1.300 + public: 1.301 + DoubleConstant(jdouble value) { _value = value; } 1.302 + 1.303 + jdouble value() const { return _value; } 1.304 + 1.305 + virtual bool is_constant() const { return true; } 1.306 + virtual DoubleConstant* as_DoubleConstant() { return this; } 1.307 +}; 1.308 + 1.309 + 1.310 +class ObjectType: public ValueType { 1.311 + public: 1.312 + ObjectType(): ValueType(objectTag, 1) {} 1.313 + virtual ValueType* base() const { return objectType; } 1.314 + virtual const char tchar() const { return 'a'; } 1.315 + virtual const char* name() const { return "object"; } 1.316 + virtual ObjectType* as_ObjectType() { return this; } 1.317 + virtual ciObject* constant_value() const { ShouldNotReachHere(); return NULL; } 1.318 + virtual ciType* exact_type() const { return NULL; } 1.319 + bool is_loaded() const; 1.320 + jobject encoding() const; 1.321 +}; 1.322 + 1.323 + 1.324 +class ObjectConstant: public ObjectType { 1.325 + private: 1.326 + ciObject* _value; 1.327 + 1.328 + public: 1.329 + ObjectConstant(ciObject* value) { _value = value; } 1.330 + 1.331 + ciObject* value() const { return _value; } 1.332 + 1.333 + virtual bool is_constant() const { return true; } 1.334 + virtual ObjectConstant* as_ObjectConstant() { return this; } 1.335 + virtual ciObject* constant_value() const; 1.336 + virtual ciType* exact_type() const; 1.337 +}; 1.338 + 1.339 + 1.340 +class ArrayType: public ObjectType { 1.341 + public: 1.342 + virtual ArrayType* as_ArrayType() { return this; } 1.343 +}; 1.344 + 1.345 + 1.346 +class ArrayConstant: public ArrayType { 1.347 + private: 1.348 + ciArray* _value; 1.349 + 1.350 + public: 1.351 + ArrayConstant(ciArray* value) { _value = value; } 1.352 + 1.353 + ciArray* value() const { return _value; } 1.354 + 1.355 + virtual bool is_constant() const { return true; } 1.356 + virtual ArrayConstant* as_ArrayConstant() { return this; } 1.357 + virtual ciObject* constant_value() const; 1.358 + virtual ciType* exact_type() const; 1.359 +}; 1.360 + 1.361 + 1.362 +class InstanceType: public ObjectType { 1.363 + public: 1.364 + virtual InstanceType* as_InstanceType() { return this; } 1.365 +}; 1.366 + 1.367 + 1.368 +class InstanceConstant: public InstanceType { 1.369 + private: 1.370 + ciInstance* _value; 1.371 + 1.372 + public: 1.373 + InstanceConstant(ciInstance* value) { _value = value; } 1.374 + 1.375 + ciInstance* value() const { return _value; } 1.376 + 1.377 + virtual bool is_constant() const { return true; } 1.378 + virtual InstanceConstant* as_InstanceConstant(){ return this; } 1.379 + virtual ciObject* constant_value() const; 1.380 + virtual ciType* exact_type() const; 1.381 +}; 1.382 + 1.383 + 1.384 +class MetadataType: public ValueType { 1.385 + public: 1.386 + MetadataType(): ValueType(metaDataTag, 1) {} 1.387 + virtual ValueType* base() const { return objectType; } 1.388 + virtual const char tchar() const { return 'a'; } 1.389 + virtual const char* name() const { return "object"; } 1.390 + virtual MetadataType* as_MetadataType() { return this; } 1.391 + bool is_loaded() const; 1.392 + jobject encoding() const; 1.393 + virtual ciMetadata* constant_value() const { ShouldNotReachHere(); return NULL; } 1.394 +}; 1.395 + 1.396 + 1.397 +class ClassType: public MetadataType { 1.398 + public: 1.399 + virtual ClassType* as_ClassType() { return this; } 1.400 +}; 1.401 + 1.402 + 1.403 +class ClassConstant: public ClassType { 1.404 + private: 1.405 + ciInstanceKlass* _value; 1.406 + 1.407 + public: 1.408 + ClassConstant(ciInstanceKlass* value) { _value = value; } 1.409 + 1.410 + ciInstanceKlass* value() const { return _value; } 1.411 + 1.412 + virtual bool is_constant() const { return true; } 1.413 + virtual ClassConstant* as_ClassConstant() { return this; } 1.414 + virtual ciMetadata* constant_value() const { return _value; } 1.415 + virtual ciType* exact_type() const; 1.416 +}; 1.417 + 1.418 + 1.419 +class MethodType: public MetadataType { 1.420 + public: 1.421 + virtual MethodType* as_MethodType() { return this; } 1.422 +}; 1.423 + 1.424 + 1.425 +class MethodConstant: public MethodType { 1.426 + private: 1.427 + ciMethod* _value; 1.428 + 1.429 + public: 1.430 + MethodConstant(ciMethod* value) { _value = value; } 1.431 + 1.432 + ciMethod* value() const { return _value; } 1.433 + 1.434 + virtual bool is_constant() const { return true; } 1.435 + 1.436 + virtual MethodConstant* as_MethodConstant() { return this; } 1.437 + virtual ciMetadata* constant_value() const { return _value; } 1.438 +}; 1.439 + 1.440 + 1.441 +class MethodDataType: public MetadataType { 1.442 + public: 1.443 + virtual MethodDataType* as_MethodDataType() { return this; } 1.444 +}; 1.445 + 1.446 + 1.447 +class MethodDataConstant: public MethodDataType { 1.448 + private: 1.449 + ciMethodData* _value; 1.450 + 1.451 + public: 1.452 + MethodDataConstant(ciMethodData* value) { _value = value; } 1.453 + 1.454 + ciMethodData* value() const { return _value; } 1.455 + 1.456 + virtual bool is_constant() const { return true; } 1.457 + 1.458 + virtual MethodDataConstant* as_MethodDataConstant() { return this; } 1.459 + virtual ciMetadata* constant_value() const { return _value; } 1.460 +}; 1.461 + 1.462 + 1.463 +class AddressType: public ValueType { 1.464 + public: 1.465 + AddressType(): ValueType(addressTag, 1) {} 1.466 + virtual ValueType* base() const { return addressType; } 1.467 + virtual const char tchar() const { return 'r'; } 1.468 + virtual const char* name() const { return "address"; } 1.469 + virtual AddressType* as_AddressType() { return this; } 1.470 +}; 1.471 + 1.472 + 1.473 +class AddressConstant: public AddressType { 1.474 + private: 1.475 + jint _value; 1.476 + 1.477 + public: 1.478 + AddressConstant(jint value) { _value = value; } 1.479 + 1.480 + jint value() const { return _value; } 1.481 + 1.482 + virtual bool is_constant() const { return true; } 1.483 + 1.484 + virtual AddressConstant* as_AddressConstant() { return this; } 1.485 +}; 1.486 + 1.487 + 1.488 +class IllegalType: public ValueType { 1.489 + public: 1.490 + IllegalType(): ValueType(illegalTag, -1) {} 1.491 + virtual ValueType* base() const { return illegalType; } 1.492 + virtual const char tchar() const { return ' '; } 1.493 + virtual const char* name() const { return "illegal"; } 1.494 + virtual IllegalType* as_IllegalType() { return this; } 1.495 +}; 1.496 + 1.497 + 1.498 +// conversion between ValueTypes, BasicTypes, and ciConstants 1.499 +ValueType* as_ValueType(BasicType type); 1.500 +ValueType* as_ValueType(ciConstant value); 1.501 +BasicType as_BasicType(ValueType* type); 1.502 + 1.503 +inline ValueType* as_ValueType(ciType* type) { return as_ValueType(type->basic_type()); } 1.504 + 1.505 +#endif // SHARE_VM_C1_C1_VALUETYPE_HPP