ciObject.cpp revision 989
0N/A/*
0N/A * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_ciObject.cpp.incl"
0N/A
0N/A// ciObject
0N/A//
0N/A// This class represents an oop in the HotSpot virtual machine.
0N/A// Its subclasses are structured in a hierarchy which mirrors
0N/A// an aggregate of the VM's oop and klass hierarchies (see
0N/A// oopHierarchy.hpp). Each instance of ciObject holds a handle
0N/A// to a corresponding oop on the VM side and provides routines
0N/A// for accessing the information in its oop. By using the ciObject
0N/A// hierarchy for accessing oops in the VM, the compiler ensures
0N/A// that it is safe with respect to garbage collection; that is,
0N/A// GC and compilation can proceed independently without
0N/A// interference.
0N/A//
0N/A// Within the VM, the oop and klass hierarchies are separate.
0N/A// The compiler interface does not preserve this separation --
0N/A// the distinction between `klassOop' and `Klass' are not
0N/A// reflected in the interface and instead the Klass hierarchy
0N/A// is directly modeled as the subclasses of ciKlass.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::ciObject
0N/AciObject::ciObject(oop o) {
0N/A ASSERT_IN_VM;
0N/A if (ciObjectFactory::is_initialized()) {
0N/A _handle = JNIHandles::make_local(o);
0N/A } else {
0N/A _handle = JNIHandles::make_global(o);
0N/A }
0N/A _klass = NULL;
0N/A _ident = 0;
0N/A init_flags_from(o);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::ciObject
0N/A//
0N/AciObject::ciObject(Handle h) {
0N/A ASSERT_IN_VM;
0N/A if (ciObjectFactory::is_initialized()) {
0N/A _handle = JNIHandles::make_local(h());
0N/A } else {
0N/A _handle = JNIHandles::make_global(h);
0N/A }
0N/A _klass = NULL;
0N/A _ident = 0;
0N/A init_flags_from(h());
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::ciObject
0N/A//
0N/A// Unloaded klass/method variant. `klass' is the klass of the unloaded
0N/A// klass/method, if that makes sense.
0N/AciObject::ciObject(ciKlass* klass) {
0N/A ASSERT_IN_VM;
0N/A assert(klass != NULL, "must supply klass");
0N/A _handle = NULL;
0N/A _klass = klass;
0N/A _ident = 0;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::ciObject
0N/A//
0N/A// NULL variant. Used only by ciNullObject.
0N/AciObject::ciObject() {
0N/A ASSERT_IN_VM;
0N/A _handle = NULL;
0N/A _klass = NULL;
0N/A _ident = 0;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::klass
0N/A//
0N/A// Get the ciKlass of this ciObject.
0N/AciKlass* ciObject::klass() {
0N/A if (_klass == NULL) {
0N/A if (_handle == NULL) {
0N/A // When both _klass and _handle are NULL, we are dealing
0N/A // with the distinguished instance of ciNullObject.
0N/A // No one should ask it for its klass.
0N/A assert(is_null_object(), "must be null object");
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A }
0N/A
0N/A GUARDED_VM_ENTRY(
0N/A oop o = get_oop();
0N/A _klass = CURRENT_ENV->get_object(o->klass())->as_klass();
0N/A );
0N/A }
0N/A return _klass;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::set_ident
0N/A//
0N/A// Set the unique identity number of a ciObject.
0N/Avoid ciObject::set_ident(uint id) {
0N/A assert((_ident >> FLAG_BITS) == 0, "must only initialize once");
0N/A assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big");
0N/A _ident = _ident + (id << FLAG_BITS);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::ident
0N/A//
0N/A// Report the unique identity number of a ciObject.
0N/Auint ciObject::ident() {
0N/A uint id = _ident >> FLAG_BITS;
0N/A assert(id != 0, "must be initialized");
0N/A return id;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::equals
0N/A//
0N/A// Are two ciObjects equal?
0N/Abool ciObject::equals(ciObject* obj) {
0N/A return (this == obj);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::hash
0N/A//
0N/A// A hash value for the convenience of compilers.
0N/A//
0N/A// Implementation note: we use the address of the ciObject as the
0N/A// basis for the hash. Use the _ident field, which is well-behaved.
0N/Aint ciObject::hash() {
0N/A return ident() * 31;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::constant_encoding
0N/A//
0N/A// The address which the compiler should embed into the
0N/A// generated code to represent this oop. This address
0N/A// is not the true address of the oop -- it will get patched
0N/A// during nmethod creation.
0N/A//
0N/A//
0N/A//
0N/A// Implementation note: we use the handle as the encoding. The
0N/A// nmethod constructor resolves the handle and patches in the oop.
0N/A//
0N/A// This method should be changed to return an generified address
0N/A// to discourage use of the JNI handle.
0N/Ajobject ciObject::constant_encoding() {
0N/A assert(is_null_object() || handle() != NULL, "cannot embed null pointer");
0N/A assert(can_be_constant(), "oop must be NULL or perm");
0N/A return handle();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::can_be_constant
0N/Abool ciObject::can_be_constant() {
0N/A if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant
0N/A return handle() == NULL || !is_scavengable();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::should_be_constant()
0N/Abool ciObject::should_be_constant() {
0N/A if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant
0N/A return handle() == NULL || !is_scavengable();
0N/A}
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::print
0N/A//
0N/A// Print debugging output about this ciObject.
0N/A//
0N/A// Implementation note: dispatch to the virtual print_impl behavior
0N/A// for this ciObject.
0N/Avoid ciObject::print(outputStream* st) {
0N/A st->print("<%s", type_string());
0N/A GUARDED_VM_ENTRY(print_impl(st);)
0N/A st->print(" ident=%d %s%s address=0x%x>", ident(),
0N/A is_perm() ? "PERM" : "",
0N/A is_scavengable() ? "SCAVENGABLE" : "",
0N/A (address)this);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::print_oop
0N/A//
0N/A// Print debugging output about the oop this ciObject represents.
0N/Avoid ciObject::print_oop(outputStream* st) {
0N/A if (is_null_object()) {
0N/A st->print_cr("NULL");
0N/A } else if (!is_loaded()) {
0N/A st->print_cr("UNLOADED");
0N/A } else {
0N/A GUARDED_VM_ENTRY(get_oop()->print_on(st);)
0N/A }
0N/A}
0N/A