src/share/vm/ci/ciInstance.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/ci/ciInstance.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, 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 "ci/ciConstant.hpp"
    1.30 +#include "ci/ciField.hpp"
    1.31 +#include "ci/ciInstance.hpp"
    1.32 +#include "ci/ciInstanceKlass.hpp"
    1.33 +#include "ci/ciUtilities.hpp"
    1.34 +#include "classfile/systemDictionary.hpp"
    1.35 +#include "oops/oop.inline.hpp"
    1.36 +
    1.37 +// ciInstance
    1.38 +//
    1.39 +// This class represents an instanceOop in the HotSpot virtual
    1.40 +// machine.
    1.41 +
    1.42 +// ------------------------------------------------------------------
    1.43 +// ciObject::java_mirror_type
    1.44 +ciType* ciInstance::java_mirror_type() {
    1.45 +  VM_ENTRY_MARK;
    1.46 +  oop m = get_oop();
    1.47 +  // Return NULL if it is not java.lang.Class.
    1.48 +  if (m == NULL || m->klass() != SystemDictionary::Class_klass()) {
    1.49 +    return NULL;
    1.50 +  }
    1.51 +  // Return either a primitive type or a klass.
    1.52 +  if (java_lang_Class::is_primitive(m)) {
    1.53 +    return ciType::make(java_lang_Class::primitive_type(m));
    1.54 +  } else {
    1.55 +    Klass* k = java_lang_Class::as_Klass(m);
    1.56 +    assert(k != NULL, "");
    1.57 +    return CURRENT_THREAD_ENV->get_klass(k);
    1.58 +  }
    1.59 +}
    1.60 +
    1.61 +// ------------------------------------------------------------------
    1.62 +// ciInstance::field_value
    1.63 +//
    1.64 +// Constant value of a field.
    1.65 +ciConstant ciInstance::field_value(ciField* field) {
    1.66 +  assert(is_loaded(), "invalid access - must be loaded");
    1.67 +  assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
    1.68 +  assert(klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");
    1.69 +
    1.70 +  VM_ENTRY_MARK;
    1.71 +  ciConstant result;
    1.72 +  Handle obj = get_oop();
    1.73 +  assert(!obj.is_null(), "bad oop");
    1.74 +  BasicType field_btype = field->type()->basic_type();
    1.75 +  int offset = field->offset();
    1.76 +
    1.77 +  switch(field_btype) {
    1.78 +  case T_BYTE:
    1.79 +    return ciConstant(field_btype, obj->byte_field(offset));
    1.80 +    break;
    1.81 +  case T_CHAR:
    1.82 +    return ciConstant(field_btype, obj->char_field(offset));
    1.83 +    break;
    1.84 +  case T_SHORT:
    1.85 +    return ciConstant(field_btype, obj->short_field(offset));
    1.86 +    break;
    1.87 +  case T_BOOLEAN:
    1.88 +    return ciConstant(field_btype, obj->bool_field(offset));
    1.89 +    break;
    1.90 +  case T_INT:
    1.91 +    return ciConstant(field_btype, obj->int_field(offset));
    1.92 +    break;
    1.93 +  case T_FLOAT:
    1.94 +    return ciConstant(obj->float_field(offset));
    1.95 +    break;
    1.96 +  case T_DOUBLE:
    1.97 +    return ciConstant(obj->double_field(offset));
    1.98 +    break;
    1.99 +  case T_LONG:
   1.100 +    return ciConstant(obj->long_field(offset));
   1.101 +    break;
   1.102 +  case T_OBJECT:
   1.103 +  case T_ARRAY:
   1.104 +    {
   1.105 +      oop o = obj->obj_field(offset);
   1.106 +
   1.107 +      // A field will be "constant" if it is known always to be
   1.108 +      // a non-null reference to an instance of a particular class,
   1.109 +      // or to a particular array.  This can happen even if the instance
   1.110 +      // or array is not perm.  In such a case, an "unloaded" ciArray
   1.111 +      // or ciInstance is created.  The compiler may be able to use
   1.112 +      // information about the object's class (which is exact) or length.
   1.113 +
   1.114 +      if (o == NULL) {
   1.115 +        return ciConstant(field_btype, ciNullObject::make());
   1.116 +      } else {
   1.117 +        return ciConstant(field_btype, CURRENT_ENV->get_object(o));
   1.118 +      }
   1.119 +    }
   1.120 +  }
   1.121 +  ShouldNotReachHere();
   1.122 +  // to shut up the compiler
   1.123 +  return ciConstant();
   1.124 +}
   1.125 +
   1.126 +// ------------------------------------------------------------------
   1.127 +// ciInstance::field_value_by_offset
   1.128 +//
   1.129 +// Constant value of a field at the specified offset.
   1.130 +ciConstant ciInstance::field_value_by_offset(int field_offset) {
   1.131 +  ciInstanceKlass* ik = klass()->as_instance_klass();
   1.132 +  ciField* field = ik->get_field_by_offset(field_offset, false);
   1.133 +  if (field == NULL)
   1.134 +    return ciConstant();  // T_ILLEGAL
   1.135 +  return field_value(field);
   1.136 +}
   1.137 +
   1.138 +// ------------------------------------------------------------------
   1.139 +// ciInstance::print_impl
   1.140 +//
   1.141 +// Implementation of the print method.
   1.142 +void ciInstance::print_impl(outputStream* st) {
   1.143 +  st->print(" type=");
   1.144 +  klass()->print(st);
   1.145 +}
   1.146 +
   1.147 +
   1.148 +ciKlass* ciInstance::java_lang_Class_klass() {
   1.149 +  VM_ENTRY_MARK;
   1.150 +  return CURRENT_ENV->get_metadata(java_lang_Class::as_Klass(get_oop()))->as_klass();
   1.151 +}

mercurial