src/share/vm/ci/ciObject.cpp

changeset 435
a61af66fc99e
child 1424
148e5441d916
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciObject.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,215 @@
     1.4 +/*
     1.5 + * Copyright 1999-2007 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/_ciObject.cpp.incl"
    1.30 +
    1.31 +// ciObject
    1.32 +//
    1.33 +// This class represents an oop in the HotSpot virtual machine.
    1.34 +// Its subclasses are structured in a hierarchy which mirrors
    1.35 +// an aggregate of the VM's oop and klass hierarchies (see
    1.36 +// oopHierarchy.hpp).  Each instance of ciObject holds a handle
    1.37 +// to a corresponding oop on the VM side and provides routines
    1.38 +// for accessing the information in its oop.  By using the ciObject
    1.39 +// hierarchy for accessing oops in the VM, the compiler ensures
    1.40 +// that it is safe with respect to garbage collection; that is,
    1.41 +// GC and compilation can proceed independently without
    1.42 +// interference.
    1.43 +//
    1.44 +// Within the VM, the oop and klass hierarchies are separate.
    1.45 +// The compiler interface does not preserve this separation --
    1.46 +// the distinction between `klassOop' and `Klass' are not
    1.47 +// reflected in the interface and instead the Klass hierarchy
    1.48 +// is directly modeled as the subclasses of ciKlass.
    1.49 +
    1.50 +// ------------------------------------------------------------------
    1.51 +// ciObject::ciObject
    1.52 +ciObject::ciObject(oop o) {
    1.53 +  ASSERT_IN_VM;
    1.54 +  if (ciObjectFactory::is_initialized()) {
    1.55 +    _handle = JNIHandles::make_local(o);
    1.56 +  } else {
    1.57 +    _handle = JNIHandles::make_global(o);
    1.58 +  }
    1.59 +  _klass = NULL;
    1.60 +  _ident = 0;
    1.61 +}
    1.62 +
    1.63 +// ------------------------------------------------------------------
    1.64 +// ciObject::ciObject
    1.65 +//
    1.66 +ciObject::ciObject(Handle h) {
    1.67 +  ASSERT_IN_VM;
    1.68 +  if (ciObjectFactory::is_initialized()) {
    1.69 +    _handle = JNIHandles::make_local(h());
    1.70 +  } else {
    1.71 +    _handle = JNIHandles::make_global(h);
    1.72 +  }
    1.73 +  _klass = NULL;
    1.74 +  _ident = 0;
    1.75 +}
    1.76 +
    1.77 +// ------------------------------------------------------------------
    1.78 +// ciObject::ciObject
    1.79 +//
    1.80 +// Unloaded klass/method variant.  `klass' is the klass of the unloaded
    1.81 +// klass/method, if that makes sense.
    1.82 +ciObject::ciObject(ciKlass* klass) {
    1.83 +  ASSERT_IN_VM;
    1.84 +  assert(klass != NULL, "must supply klass");
    1.85 +  _handle = NULL;
    1.86 +  _klass = klass;
    1.87 +  _ident = 0;
    1.88 +}
    1.89 +
    1.90 +// ------------------------------------------------------------------
    1.91 +// ciObject::ciObject
    1.92 +//
    1.93 +// NULL variant.  Used only by ciNullObject.
    1.94 +ciObject::ciObject() {
    1.95 +  ASSERT_IN_VM;
    1.96 +  _handle = NULL;
    1.97 +  _klass = NULL;
    1.98 +  _ident = 0;
    1.99 +}
   1.100 +
   1.101 +// ------------------------------------------------------------------
   1.102 +// ciObject::klass
   1.103 +//
   1.104 +// Get the ciKlass of this ciObject.
   1.105 +ciKlass* ciObject::klass() {
   1.106 +  if (_klass == NULL) {
   1.107 +    if (_handle == NULL) {
   1.108 +      // When both _klass and _handle are NULL, we are dealing
   1.109 +      // with the distinguished instance of ciNullObject.
   1.110 +      // No one should ask it for its klass.
   1.111 +      assert(is_null_object(), "must be null object");
   1.112 +      ShouldNotReachHere();
   1.113 +      return NULL;
   1.114 +    }
   1.115 +
   1.116 +    GUARDED_VM_ENTRY(
   1.117 +      oop o = get_oop();
   1.118 +      _klass = CURRENT_ENV->get_object(o->klass())->as_klass();
   1.119 +    );
   1.120 +  }
   1.121 +  return _klass;
   1.122 +}
   1.123 +
   1.124 +// ------------------------------------------------------------------
   1.125 +// ciObject::set_ident
   1.126 +//
   1.127 +// Set the unique identity number of a ciObject.
   1.128 +void ciObject::set_ident(uint id) {
   1.129 +  assert((_ident >> FLAG_BITS) == 0, "must only initialize once");
   1.130 +  assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big");
   1.131 +  _ident = _ident + (id << FLAG_BITS);
   1.132 +}
   1.133 +
   1.134 +// ------------------------------------------------------------------
   1.135 +// ciObject::ident
   1.136 +//
   1.137 +// Report the unique identity number of a ciObject.
   1.138 +uint ciObject::ident() {
   1.139 +  uint id = _ident >> FLAG_BITS;
   1.140 +  assert(id != 0, "must be initialized");
   1.141 +  return id;
   1.142 +}
   1.143 +
   1.144 +// ------------------------------------------------------------------
   1.145 +// ciObject::equals
   1.146 +//
   1.147 +// Are two ciObjects equal?
   1.148 +bool ciObject::equals(ciObject* obj) {
   1.149 +  return (this == obj);
   1.150 +}
   1.151 +
   1.152 +// ------------------------------------------------------------------
   1.153 +// ciObject::hash
   1.154 +//
   1.155 +// A hash value for the convenience of compilers.
   1.156 +//
   1.157 +// Implementation note: we use the address of the ciObject as the
   1.158 +// basis for the hash.  Use the _ident field, which is well-behaved.
   1.159 +int ciObject::hash() {
   1.160 +  return ident() * 31;
   1.161 +}
   1.162 +
   1.163 +// ------------------------------------------------------------------
   1.164 +// ciObject::encoding
   1.165 +//
   1.166 +// The address which the compiler should embed into the
   1.167 +// generated code to represent this oop.  This address
   1.168 +// is not the true address of the oop -- it will get patched
   1.169 +// during nmethod creation.
   1.170 +//
   1.171 +//
   1.172 +//
   1.173 +// Implementation note: we use the handle as the encoding.  The
   1.174 +// nmethod constructor resolves the handle and patches in the oop.
   1.175 +//
   1.176 +// This method should be changed to return an generified address
   1.177 +// to discourage use of the JNI handle.
   1.178 +jobject ciObject::encoding() {
   1.179 +  assert(is_null_object() || handle() != NULL, "cannot embed null pointer");
   1.180 +  assert(has_encoding(), "oop must be NULL or perm");
   1.181 +  return handle();
   1.182 +}
   1.183 +
   1.184 +// ------------------------------------------------------------------
   1.185 +// ciObject::has_encoding
   1.186 +bool ciObject::has_encoding() {
   1.187 +  return handle() == NULL || is_perm();
   1.188 +}
   1.189 +
   1.190 +
   1.191 +// ------------------------------------------------------------------
   1.192 +// ciObject::print
   1.193 +//
   1.194 +// Print debugging output about this ciObject.
   1.195 +//
   1.196 +// Implementation note: dispatch to the virtual print_impl behavior
   1.197 +// for this ciObject.
   1.198 +void ciObject::print(outputStream* st) {
   1.199 +  st->print("<%s", type_string());
   1.200 +  GUARDED_VM_ENTRY(print_impl(st);)
   1.201 +  st->print(" ident=%d %s address=0x%x>", ident(),
   1.202 +        is_perm() ? "PERM" : "",
   1.203 +        (address)this);
   1.204 +}
   1.205 +
   1.206 +// ------------------------------------------------------------------
   1.207 +// ciObject::print_oop
   1.208 +//
   1.209 +// Print debugging output about the oop this ciObject represents.
   1.210 +void ciObject::print_oop(outputStream* st) {
   1.211 +  if (is_null_object()) {
   1.212 +    st->print_cr("NULL");
   1.213 +  } else if (!is_loaded()) {
   1.214 +    st->print_cr("UNLOADED");
   1.215 +  } else {
   1.216 +    GUARDED_VM_ENTRY(get_oop()->print_on(st);)
   1.217 +  }
   1.218 +}

mercurial