src/share/vm/c1/c1_ValueType.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_ValueType.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,177 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2012, 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 +#include "precompiled.hpp"
    1.29 +#include "c1/c1_ValueType.hpp"
    1.30 +#include "ci/ciArray.hpp"
    1.31 +#include "ci/ciInstance.hpp"
    1.32 +#include "ci/ciNullObject.hpp"
    1.33 +
    1.34 +
    1.35 +// predefined types
    1.36 +VoidType*       voidType     = NULL;
    1.37 +IntType*        intType      = NULL;
    1.38 +LongType*       longType     = NULL;
    1.39 +FloatType*      floatType    = NULL;
    1.40 +DoubleType*     doubleType   = NULL;
    1.41 +ObjectType*     objectType   = NULL;
    1.42 +ArrayType*      arrayType    = NULL;
    1.43 +InstanceType*   instanceType = NULL;
    1.44 +ClassType*      classType    = NULL;
    1.45 +AddressType*    addressType  = NULL;
    1.46 +IllegalType*    illegalType  = NULL;
    1.47 +
    1.48 +
    1.49 +// predefined constants
    1.50 +IntConstant*    intZero      = NULL;
    1.51 +IntConstant*    intOne       = NULL;
    1.52 +ObjectConstant* objectNull   = NULL;
    1.53 +
    1.54 +
    1.55 +void ValueType::initialize(Arena* arena) {
    1.56 +  // Note: Must initialize all types for each compilation
    1.57 +  //       as they are allocated within a ResourceMark!
    1.58 +
    1.59 +  // types
    1.60 +  voidType     = new (arena) VoidType();
    1.61 +  intType      = new (arena) IntType();
    1.62 +  longType     = new (arena) LongType();
    1.63 +  floatType    = new (arena) FloatType();
    1.64 +  doubleType   = new (arena) DoubleType();
    1.65 +  objectType   = new (arena) ObjectType();
    1.66 +  arrayType    = new (arena) ArrayType();
    1.67 +  instanceType = new (arena) InstanceType();
    1.68 +  classType    = new (arena) ClassType();
    1.69 +  addressType  = new (arena) AddressType();
    1.70 +  illegalType  = new (arena) IllegalType();
    1.71 +
    1.72 +  intZero     = new (arena) IntConstant(0);
    1.73 +  intOne      = new (arena) IntConstant(1);
    1.74 +  objectNull  = new (arena) ObjectConstant(ciNullObject::make());
    1.75 +};
    1.76 +
    1.77 +
    1.78 +ValueType* ValueType::meet(ValueType* y) const {
    1.79 +  // incomplete & conservative solution for now - fix this!
    1.80 +  assert(tag() == y->tag(), "types must match");
    1.81 +  return base();
    1.82 +}
    1.83 +
    1.84 +
    1.85 +ValueType* ValueType::join(ValueType* y) const {
    1.86 +  Unimplemented();
    1.87 +  return NULL;
    1.88 +}
    1.89 +
    1.90 +
    1.91 +ciType* ObjectConstant::exact_type() const {
    1.92 +  ciObject* c = constant_value();
    1.93 +  return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
    1.94 +}
    1.95 +ciType* ArrayConstant::exact_type() const {
    1.96 +  ciObject* c = constant_value();
    1.97 +  return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
    1.98 +}
    1.99 +ciType* InstanceConstant::exact_type() const {
   1.100 +  ciObject* c = constant_value();
   1.101 +  return (c != NULL && !c->is_null_object()) ? c->klass() : NULL;
   1.102 +}
   1.103 +ciType* ClassConstant::exact_type() const {
   1.104 +  return Compilation::current()->env()->Class_klass();
   1.105 +}
   1.106 +
   1.107 +
   1.108 +jobject ObjectType::encoding() const {
   1.109 +  assert(is_constant(), "must be");
   1.110 +  return constant_value()->constant_encoding();
   1.111 +}
   1.112 +
   1.113 +bool ObjectType::is_loaded() const {
   1.114 +  assert(is_constant(), "must be");
   1.115 +  return constant_value()->is_loaded();
   1.116 +}
   1.117 +
   1.118 +bool MetadataType::is_loaded() const {
   1.119 +  assert(is_constant(), "must be");
   1.120 +  return constant_value()->is_loaded();
   1.121 +}
   1.122 +
   1.123 +ciObject* ObjectConstant::constant_value() const                   { return _value; }
   1.124 +ciObject* ArrayConstant::constant_value() const                    { return _value; }
   1.125 +ciObject* InstanceConstant::constant_value() const                 { return _value; }
   1.126 +
   1.127 +ValueType* as_ValueType(BasicType type) {
   1.128 +  switch (type) {
   1.129 +    case T_VOID   : return voidType;
   1.130 +    case T_BYTE   : // fall through
   1.131 +    case T_CHAR   : // fall through
   1.132 +    case T_SHORT  : // fall through
   1.133 +    case T_BOOLEAN: // fall through
   1.134 +    case T_INT    : return intType;
   1.135 +    case T_LONG   : return longType;
   1.136 +    case T_FLOAT  : return floatType;
   1.137 +    case T_DOUBLE : return doubleType;
   1.138 +    case T_ARRAY  : return arrayType;
   1.139 +    case T_OBJECT : return objectType;
   1.140 +    case T_ADDRESS: return addressType;
   1.141 +    case T_ILLEGAL: return illegalType;
   1.142 +  }
   1.143 +  ShouldNotReachHere();
   1.144 +  return illegalType;
   1.145 +}
   1.146 +
   1.147 +
   1.148 +ValueType* as_ValueType(ciConstant value) {
   1.149 +  switch (value.basic_type()) {
   1.150 +    case T_BYTE   : // fall through
   1.151 +    case T_CHAR   : // fall through
   1.152 +    case T_SHORT  : // fall through
   1.153 +    case T_BOOLEAN: // fall through
   1.154 +    case T_INT    : return new IntConstant   (value.as_int   ());
   1.155 +    case T_LONG   : return new LongConstant  (value.as_long  ());
   1.156 +    case T_FLOAT  : return new FloatConstant (value.as_float ());
   1.157 +    case T_DOUBLE : return new DoubleConstant(value.as_double());
   1.158 +    case T_ARRAY  : // fall through (ciConstant doesn't have an array accessor)
   1.159 +    case T_OBJECT : return new ObjectConstant(value.as_object());
   1.160 +  }
   1.161 +  ShouldNotReachHere();
   1.162 +  return illegalType;
   1.163 +}
   1.164 +
   1.165 +
   1.166 +BasicType as_BasicType(ValueType* type) {
   1.167 +  switch (type->tag()) {
   1.168 +    case voidTag:    return T_VOID;
   1.169 +    case intTag:     return T_INT;
   1.170 +    case longTag:    return T_LONG;
   1.171 +    case floatTag:   return T_FLOAT;
   1.172 +    case doubleTag:  return T_DOUBLE;
   1.173 +    case objectTag:  return T_OBJECT;
   1.174 +    case metaDataTag:return T_METADATA;
   1.175 +    case addressTag: return T_ADDRESS;
   1.176 +    case illegalTag: return T_ILLEGAL;
   1.177 +  }
   1.178 +  ShouldNotReachHere();
   1.179 +  return T_ILLEGAL;
   1.180 +}

mercurial