hotspot/src/share/vm/ci/ciInstance.cpp
author never
Wed, 06 Jan 2010 14:22:39 -0800
changeset 4571 80b553bddc26
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6914300: ciEnv should export all well known classes Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_ciInstance.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// ciInstance
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// This class represents an instanceOop in the HotSpot virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// machine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// ciObject::java_mirror_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
ciType* ciInstance::java_mirror_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  oop m = get_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // Return NULL if it is not java.lang.Class.
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 1
diff changeset
    39
  if (m == NULL || m->klass() != SystemDictionary::Class_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // Return either a primitive type or a klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (java_lang_Class::is_primitive(m)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    return ciType::make(java_lang_Class::primitive_type(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    klassOop k = java_lang_Class::as_klassOop(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    assert(k != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    return CURRENT_THREAD_ENV->get_object(k)->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// ciInstance::field_value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// Constant value of a field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
ciConstant ciInstance::field_value(ciField* field) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  assert(is_loaded() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
         field->holder()->is_loaded() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
         klass()->is_subclass_of(field->holder()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
         "invalid access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ciConstant result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  oop obj = get_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  assert(obj != NULL, "bad oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  BasicType field_btype = field->type()->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int offset = field->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  switch(field_btype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return ciConstant(field_btype, obj->byte_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  case T_CHAR:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return ciConstant(field_btype, obj->char_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  case T_SHORT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return ciConstant(field_btype, obj->short_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    return ciConstant(field_btype, obj->bool_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  case T_INT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return ciConstant(field_btype, obj->int_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  case T_FLOAT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return ciConstant(obj->float_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  case T_DOUBLE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return ciConstant(obj->double_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  case T_LONG:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return ciConstant(obj->long_field(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  case T_ARRAY:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      oop o = obj->obj_field(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      // A field will be "constant" if it is known always to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      // a non-null reference to an instance of a particular class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      // or to a particular array.  This can happen even if the instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      // or array is not perm.  In such a case, an "unloaded" ciArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      // or ciInstance is created.  The compiler may be able to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      // information about the object's class (which is exact) or length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        return ciConstant(field_btype, ciNullObject::make());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        return ciConstant(field_btype, CURRENT_ENV->get_object(o));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // to shut up the compiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return ciConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// ciInstance::field_value_by_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Constant value of a field at the specified offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
ciConstant ciInstance::field_value_by_offset(int field_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  ciInstanceKlass* ik = klass()->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  ciField* field = ik->get_field_by_offset(field_offset, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  return field_value(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// ciInstance::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
void ciInstance::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  st->print(" type=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  klass()->print(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}