src/share/vm/ci/ciInstance.cpp

changeset 435
a61af66fc99e
child 1577
4ce7240d622c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciInstance.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * Copyright 1999-2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_ciInstance.cpp.incl"
    1.30 +
    1.31 +// ciInstance
    1.32 +//
    1.33 +// This class represents an instanceOop in the HotSpot virtual
    1.34 +// machine.
    1.35 +
    1.36 +// ------------------------------------------------------------------
    1.37 +// ciObject::java_mirror_type
    1.38 +ciType* ciInstance::java_mirror_type() {
    1.39 +  VM_ENTRY_MARK;
    1.40 +  oop m = get_oop();
    1.41 +  // Return NULL if it is not java.lang.Class.
    1.42 +  if (m == NULL || m->klass() != SystemDictionary::class_klass()) {
    1.43 +    return NULL;
    1.44 +  }
    1.45 +  // Return either a primitive type or a klass.
    1.46 +  if (java_lang_Class::is_primitive(m)) {
    1.47 +    return ciType::make(java_lang_Class::primitive_type(m));
    1.48 +  } else {
    1.49 +    klassOop k = java_lang_Class::as_klassOop(m);
    1.50 +    assert(k != NULL, "");
    1.51 +    return CURRENT_THREAD_ENV->get_object(k)->as_klass();
    1.52 +  }
    1.53 +}
    1.54 +
    1.55 +// ------------------------------------------------------------------
    1.56 +// ciInstance::field_value
    1.57 +//
    1.58 +// Constant value of a field.
    1.59 +ciConstant ciInstance::field_value(ciField* field) {
    1.60 +  assert(is_loaded() &&
    1.61 +         field->holder()->is_loaded() &&
    1.62 +         klass()->is_subclass_of(field->holder()),
    1.63 +         "invalid access");
    1.64 +  VM_ENTRY_MARK;
    1.65 +  ciConstant result;
    1.66 +  oop obj = get_oop();
    1.67 +  assert(obj != NULL, "bad oop");
    1.68 +  BasicType field_btype = field->type()->basic_type();
    1.69 +  int offset = field->offset();
    1.70 +
    1.71 +  switch(field_btype) {
    1.72 +  case T_BYTE:
    1.73 +    return ciConstant(field_btype, obj->byte_field(offset));
    1.74 +    break;
    1.75 +  case T_CHAR:
    1.76 +    return ciConstant(field_btype, obj->char_field(offset));
    1.77 +    break;
    1.78 +  case T_SHORT:
    1.79 +    return ciConstant(field_btype, obj->short_field(offset));
    1.80 +    break;
    1.81 +  case T_BOOLEAN:
    1.82 +    return ciConstant(field_btype, obj->bool_field(offset));
    1.83 +    break;
    1.84 +  case T_INT:
    1.85 +    return ciConstant(field_btype, obj->int_field(offset));
    1.86 +    break;
    1.87 +  case T_FLOAT:
    1.88 +    return ciConstant(obj->float_field(offset));
    1.89 +    break;
    1.90 +  case T_DOUBLE:
    1.91 +    return ciConstant(obj->double_field(offset));
    1.92 +    break;
    1.93 +  case T_LONG:
    1.94 +    return ciConstant(obj->long_field(offset));
    1.95 +    break;
    1.96 +  case T_OBJECT:
    1.97 +  case T_ARRAY:
    1.98 +    {
    1.99 +      oop o = obj->obj_field(offset);
   1.100 +
   1.101 +      // A field will be "constant" if it is known always to be
   1.102 +      // a non-null reference to an instance of a particular class,
   1.103 +      // or to a particular array.  This can happen even if the instance
   1.104 +      // or array is not perm.  In such a case, an "unloaded" ciArray
   1.105 +      // or ciInstance is created.  The compiler may be able to use
   1.106 +      // information about the object's class (which is exact) or length.
   1.107 +
   1.108 +      if (o == NULL) {
   1.109 +        return ciConstant(field_btype, ciNullObject::make());
   1.110 +      } else {
   1.111 +        return ciConstant(field_btype, CURRENT_ENV->get_object(o));
   1.112 +      }
   1.113 +    }
   1.114 +  }
   1.115 +  ShouldNotReachHere();
   1.116 +  // to shut up the compiler
   1.117 +  return ciConstant();
   1.118 +}
   1.119 +
   1.120 +// ------------------------------------------------------------------
   1.121 +// ciInstance::field_value_by_offset
   1.122 +//
   1.123 +// Constant value of a field at the specified offset.
   1.124 +ciConstant ciInstance::field_value_by_offset(int field_offset) {
   1.125 +  ciInstanceKlass* ik = klass()->as_instance_klass();
   1.126 +  ciField* field = ik->get_field_by_offset(field_offset, false);
   1.127 +  return field_value(field);
   1.128 +}
   1.129 +
   1.130 +// ------------------------------------------------------------------
   1.131 +// ciInstance::print_impl
   1.132 +//
   1.133 +// Implementation of the print method.
   1.134 +void ciInstance::print_impl(outputStream* st) {
   1.135 +  st->print(" type=");
   1.136 +  klass()->print(st);
   1.137 +}

mercurial