duke@435: /* duke@435: * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // ciObject duke@435: // duke@435: // This class represents an oop in the HotSpot virtual machine. duke@435: // Its subclasses are structured in a hierarchy which mirrors duke@435: // an aggregate of the VM's oop and klass hierarchies (see duke@435: // oopHierarchy.hpp). Each instance of ciObject holds a handle duke@435: // to a corresponding oop on the VM side and provides routines duke@435: // for accessing the information in its oop. By using the ciObject duke@435: // hierarchy for accessing oops in the VM, the compiler ensures duke@435: // that it is safe with respect to garbage collection; that is, duke@435: // GC and compilation can proceed independently without duke@435: // interference. duke@435: // duke@435: // Within the VM, the oop and klass hierarchies are separate. duke@435: // The compiler interface does not preserve this separation -- duke@435: // the distinction between `klassOop' and `Klass' are not duke@435: // reflected in the interface and instead the Klass hierarchy duke@435: // is directly modeled as the subclasses of ciKlass. duke@435: class ciObject : public ResourceObj { duke@435: CI_PACKAGE_ACCESS duke@435: friend class ciEnv; duke@435: duke@435: private: duke@435: // A JNI handle referring to an oop in the VM. This duke@435: // handle may, in a small set of cases, correctly be NULL. duke@435: jobject _handle; duke@435: ciKlass* _klass; duke@435: uint _ident; duke@435: jrose@1424: enum { FLAG_BITS = 2 }; duke@435: enum { jrose@1424: PERM_FLAG = 1, jrose@1424: SCAVENGABLE_FLAG = 2 duke@435: }; duke@435: protected: duke@435: ciObject(); duke@435: ciObject(oop o); duke@435: ciObject(Handle h); duke@435: ciObject(ciKlass* klass); duke@435: duke@435: jobject handle() const { return _handle; } duke@435: // Get the VM oop that this object holds. duke@435: oop get_oop() const { duke@435: assert(_handle != NULL, "null oop"); duke@435: return JNIHandles::resolve_non_null(_handle); duke@435: } duke@435: jrose@1424: void init_flags_from(oop x) { jrose@1424: int flags = 0; jrose@1424: if (x != NULL) { jrose@1424: if (x->is_perm()) jrose@1424: flags |= PERM_FLAG; jrose@1424: if (x->is_scavengable()) jrose@1424: flags |= SCAVENGABLE_FLAG; jrose@1424: } jrose@1424: _ident |= flags; duke@435: } duke@435: duke@435: // Virtual behavior of the print() method. duke@435: virtual void print_impl(outputStream* st) {} duke@435: duke@435: virtual const char* type_string() { return "ciObject"; } duke@435: duke@435: void set_ident(uint id); duke@435: public: duke@435: // The klass of this ciObject. duke@435: ciKlass* klass(); duke@435: duke@435: // A number unique to this object. duke@435: uint ident(); duke@435: duke@435: // Are two ciObjects equal? duke@435: bool equals(ciObject* obj); duke@435: duke@435: // A hash value for the convenience of compilers. duke@435: int hash(); duke@435: jrose@1424: // Tells if this oop has an encoding as a constant. jrose@1424: // True if is_scavengable is false. jrose@1424: // Also true if ScavengeRootsInCode is non-zero. duke@435: // If it does not have an encoding, the compiler is responsible for duke@435: // making other arrangements for dealing with the oop. jrose@1424: // See ciEnv::make_array jrose@1424: bool can_be_constant(); jrose@1424: jrose@1424: // Tells if this oop should be made a constant. jrose@1424: // True if is_scavengable is false or ScavengeRootsInCode > 1. jrose@1424: bool should_be_constant(); duke@435: duke@435: // Is this object guaranteed to be in the permanent part of the heap? duke@435: // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant. duke@435: // If the answer is false, no guarantees are made. duke@435: bool is_perm() { return (_ident & PERM_FLAG) != 0; } duke@435: jrose@1424: // Might this object possibly move during a scavenge operation? jrose@1424: // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. jrose@1424: bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } jrose@1424: duke@435: // The address which the compiler should embed into the duke@435: // generated code to represent this oop. This address duke@435: // is not the true address of the oop -- it will get patched duke@435: // during nmethod creation. duke@435: // duke@435: // Usage note: no address arithmetic allowed. Oop must duke@435: // be registered with the oopRecorder. jrose@1424: jobject constant_encoding(); duke@435: duke@435: // What kind of ciObject is this? duke@435: virtual bool is_null_object() const { return false; } twisti@1572: virtual bool is_cpcache() const { return false; } duke@435: virtual bool is_instance() { return false; } duke@435: virtual bool is_method() { return false; } duke@435: virtual bool is_method_data() { return false; } duke@435: virtual bool is_array() { return false; } duke@435: virtual bool is_obj_array() { return false; } duke@435: virtual bool is_type_array() { return false; } duke@435: virtual bool is_symbol() { return false; } duke@435: virtual bool is_type() { return false; } duke@435: virtual bool is_return_address() { return false; } duke@435: virtual bool is_klass() { return false; } duke@435: virtual bool is_instance_klass() { return false; } duke@435: virtual bool is_method_klass() { return false; } duke@435: virtual bool is_array_klass() { return false; } duke@435: virtual bool is_obj_array_klass() { return false; } duke@435: virtual bool is_type_array_klass() { return false; } duke@435: virtual bool is_symbol_klass() { return false; } duke@435: virtual bool is_klass_klass() { return false; } duke@435: virtual bool is_instance_klass_klass() { return false; } duke@435: virtual bool is_array_klass_klass() { return false; } duke@435: virtual bool is_obj_array_klass_klass() { return false; } duke@435: virtual bool is_type_array_klass_klass() { return false; } duke@435: duke@435: // Is this a type or value which has no associated class? duke@435: // It is true of primitive types and null objects. duke@435: virtual bool is_classless() const { return false; } duke@435: duke@435: // Is this ciObject a Java Language Object? That is, duke@435: // is the ciObject an instance or an array duke@435: virtual bool is_java_object() { return false; } duke@435: duke@435: // Does this ciObject represent a Java Language class? duke@435: // That is, is the ciObject an instanceKlass or arrayKlass? duke@435: virtual bool is_java_klass() { return false; } duke@435: duke@435: // Is this ciObject the ciInstanceKlass representing duke@435: // java.lang.Object()? duke@435: virtual bool is_java_lang_Object() { return false; } duke@435: duke@435: // Does this ciObject refer to a real oop in the VM? duke@435: // duke@435: // Note: some ciObjects refer to oops which have yet to be duke@435: // created. We refer to these as "unloaded". Specifically, duke@435: // there are unloaded ciMethods, ciObjArrayKlasses, and duke@435: // ciInstanceKlasses. By convention the ciNullObject is duke@435: // considered loaded, and primitive types are considered loaded. duke@435: bool is_loaded() const { duke@435: return handle() != NULL || is_classless(); duke@435: } duke@435: duke@435: // Subclass casting with assertions. duke@435: ciNullObject* as_null_object() { duke@435: assert(is_null_object(), "bad cast"); duke@435: return (ciNullObject*)this; duke@435: } twisti@1572: ciCPCache* as_cpcache() { twisti@1572: assert(is_cpcache(), "bad cast"); twisti@1572: return (ciCPCache*) this; twisti@1572: } duke@435: ciInstance* as_instance() { duke@435: assert(is_instance(), "bad cast"); duke@435: return (ciInstance*)this; duke@435: } duke@435: ciMethod* as_method() { duke@435: assert(is_method(), "bad cast"); duke@435: return (ciMethod*)this; duke@435: } duke@435: ciMethodData* as_method_data() { duke@435: assert(is_method_data(), "bad cast"); duke@435: return (ciMethodData*)this; duke@435: } duke@435: ciArray* as_array() { duke@435: assert(is_array(), "bad cast"); duke@435: return (ciArray*)this; duke@435: } duke@435: ciObjArray* as_obj_array() { duke@435: assert(is_obj_array(), "bad cast"); duke@435: return (ciObjArray*)this; duke@435: } duke@435: ciTypeArray* as_type_array() { duke@435: assert(is_type_array(), "bad cast"); duke@435: return (ciTypeArray*)this; duke@435: } duke@435: ciSymbol* as_symbol() { duke@435: assert(is_symbol(), "bad cast"); duke@435: return (ciSymbol*)this; duke@435: } duke@435: ciType* as_type() { duke@435: assert(is_type(), "bad cast"); duke@435: return (ciType*)this; duke@435: } duke@435: ciReturnAddress* as_return_address() { duke@435: assert(is_return_address(), "bad cast"); duke@435: return (ciReturnAddress*)this; duke@435: } duke@435: ciKlass* as_klass() { duke@435: assert(is_klass(), "bad cast"); duke@435: return (ciKlass*)this; duke@435: } duke@435: ciInstanceKlass* as_instance_klass() { duke@435: assert(is_instance_klass(), "bad cast"); duke@435: return (ciInstanceKlass*)this; duke@435: } duke@435: ciMethodKlass* as_method_klass() { duke@435: assert(is_method_klass(), "bad cast"); duke@435: return (ciMethodKlass*)this; duke@435: } duke@435: ciArrayKlass* as_array_klass() { duke@435: assert(is_array_klass(), "bad cast"); duke@435: return (ciArrayKlass*)this; duke@435: } duke@435: ciObjArrayKlass* as_obj_array_klass() { duke@435: assert(is_obj_array_klass(), "bad cast"); duke@435: return (ciObjArrayKlass*)this; duke@435: } duke@435: ciTypeArrayKlass* as_type_array_klass() { duke@435: assert(is_type_array_klass(), "bad cast"); duke@435: return (ciTypeArrayKlass*)this; duke@435: } duke@435: ciSymbolKlass* as_symbol_klass() { duke@435: assert(is_symbol_klass(), "bad cast"); duke@435: return (ciSymbolKlass*)this; duke@435: } duke@435: ciKlassKlass* as_klass_klass() { duke@435: assert(is_klass_klass(), "bad cast"); duke@435: return (ciKlassKlass*)this; duke@435: } duke@435: ciInstanceKlassKlass* as_instance_klass_klass() { duke@435: assert(is_instance_klass_klass(), "bad cast"); duke@435: return (ciInstanceKlassKlass*)this; duke@435: } duke@435: ciArrayKlassKlass* as_array_klass_klass() { duke@435: assert(is_array_klass_klass(), "bad cast"); duke@435: return (ciArrayKlassKlass*)this; duke@435: } duke@435: ciObjArrayKlassKlass* as_obj_array_klass_klass() { duke@435: assert(is_obj_array_klass_klass(), "bad cast"); duke@435: return (ciObjArrayKlassKlass*)this; duke@435: } duke@435: ciTypeArrayKlassKlass* as_type_array_klass_klass() { duke@435: assert(is_type_array_klass_klass(), "bad cast"); duke@435: return (ciTypeArrayKlassKlass*)this; duke@435: } duke@435: duke@435: // Print debugging output about this ciObject. duke@435: void print(outputStream* st = tty); duke@435: duke@435: // Print debugging output about the oop this ciObject represents. duke@435: void print_oop(outputStream* st = tty); duke@435: };