duke@435: /* duke@435: * Copyright 1997-2007 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: // OBJECT hierarchy duke@435: // This hierarchy is a representation hierarchy, i.e. if A is a superclass duke@435: // of B, A's representation is a prefix of B's representation. duke@435: coleenp@548: typedef juint narrowOop; // Offset instead of address for an oop within a java object coleenp@548: typedef class klassOopDesc* wideKlassOop; // to keep SA happy and unhandled oop coleenp@548: // detector happy. coleenp@548: duke@435: #ifndef CHECK_UNHANDLED_OOPS duke@435: coleenp@548: typedef class oopDesc* oop; duke@435: typedef class instanceOopDesc* instanceOop; coleenp@548: typedef class methodOopDesc* methodOop; coleenp@548: typedef class constMethodOopDesc* constMethodOop; coleenp@548: typedef class methodDataOopDesc* methodDataOop; coleenp@548: typedef class arrayOopDesc* arrayOop; coleenp@548: typedef class objArrayOopDesc* objArrayOop; coleenp@548: typedef class typeArrayOopDesc* typeArrayOop; coleenp@548: typedef class constantPoolOopDesc* constantPoolOop; coleenp@548: typedef class constantPoolCacheOopDesc* constantPoolCacheOop; coleenp@548: typedef class symbolOopDesc* symbolOop; coleenp@548: typedef class klassOopDesc* klassOop; coleenp@548: typedef class markOopDesc* markOop; duke@435: typedef class compiledICHolderOopDesc* compiledICHolderOop; duke@435: duke@435: #else duke@435: duke@435: duke@435: // When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a duke@435: // carefully chosen set of constructors and conversion operators to go duke@435: // to and from the underlying oopDesc pointer type. duke@435: // duke@435: // Because oop and its subclasses Oop are class types, arbitrary duke@435: // conversions are not accepted by the compiler, and you may get a message duke@435: // about overloading ambiguity (between long and int is common when converting duke@435: // from a constant in 64 bit mode), or unable to convert from type to 'oop'. duke@435: // Applying a cast to one of these conversion operators first will get to the duke@435: // underlying oopDesc* type if appropriate. duke@435: // Converting NULL to oop to Handle implicit is no longer accepted by the duke@435: // compiler because there are too many steps in the conversion. Use Handle() duke@435: // instead, which generates less code anyway. duke@435: duke@435: class Thread; duke@435: typedef class markOopDesc* markOop; duke@435: class PromotedObject; duke@435: duke@435: duke@435: class oop { duke@435: oopDesc* _o; duke@435: duke@435: void register_oop(); duke@435: void unregister_oop(); duke@435: duke@435: // friend class markOop; duke@435: public: duke@435: void set_obj(const void* p) { duke@435: raw_set_obj(p); duke@435: if (CheckUnhandledOops) register_oop(); duke@435: } duke@435: void raw_set_obj(const void* p) { _o = (oopDesc*)p; } duke@435: duke@435: oop() { set_obj(NULL); } duke@435: oop(const volatile oop& o) { set_obj(o.obj()); } duke@435: oop(const void* p) { set_obj(p); } duke@435: oop(intptr_t i) { set_obj((void *)i); } duke@435: #ifdef _LP64 duke@435: oop(int i) { set_obj((void *)i); } duke@435: #endif duke@435: ~oop() { duke@435: if (CheckUnhandledOops) unregister_oop(); duke@435: } duke@435: duke@435: oopDesc* obj() const volatile { return _o; } duke@435: duke@435: // General access duke@435: oopDesc* operator->() const { return obj(); } duke@435: bool operator==(const oop o) const { return obj() == o.obj(); } duke@435: bool operator==(void *p) const { return obj() == p; } duke@435: bool operator!=(const oop o) const { return obj() != o.obj(); } duke@435: bool operator!=(void *p) const { return obj() != p; } duke@435: bool operator==(intptr_t p) const { return obj() == (oopDesc*)p; } duke@435: bool operator!=(intptr_t p) const { return obj() != (oopDesc*)p; } duke@435: duke@435: bool operator<(oop o) const { return obj() < o.obj(); } duke@435: bool operator>(oop o) const { return obj() > o.obj(); } duke@435: bool operator<=(oop o) const { return obj() <= o.obj(); } duke@435: bool operator>=(oop o) const { return obj() >= o.obj(); } duke@435: bool operator!() const { return !obj(); } duke@435: duke@435: // Cast duke@435: operator void* () const { return (void *)obj(); } duke@435: operator HeapWord* () const { return (HeapWord*)obj(); } duke@435: operator oopDesc* () const { return obj(); } duke@435: operator intptr_t* () const { return (intptr_t*)obj(); } duke@435: operator PromotedObject* () const { return (PromotedObject*)obj(); } duke@435: operator markOop () const { return markOop(obj()); } duke@435: duke@435: operator address () const { return (address)obj(); } duke@435: operator intptr_t () const { return (intptr_t)obj(); } duke@435: duke@435: // from javaCalls.cpp duke@435: operator jobject () const { return (jobject)obj(); } duke@435: // from javaClasses.cpp duke@435: operator JavaThread* () const { return (JavaThread*)obj(); } duke@435: // from jvm.cpp duke@435: operator jlong* () const { return (jlong*)obj(); } duke@435: duke@435: // from parNewGeneration and other things that want to get to the end of duke@435: // an oop for stuff (like constMethodKlass.cpp, objArrayKlass.cpp) duke@435: operator oop* () const { return (oop *)obj(); } duke@435: }; duke@435: duke@435: #define DEF_OOP(type) \ duke@435: class type##OopDesc; \ duke@435: class type##Oop : public oop { \ duke@435: public: \ duke@435: type##Oop() : oop() {} \ duke@435: type##Oop(const volatile oop& o) : oop(o) {} \ duke@435: type##Oop(const void* p) : oop(p) {} \ duke@435: operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \ duke@435: type##OopDesc* operator->() const { \ duke@435: return (type##OopDesc*)obj(); \ duke@435: } \ duke@435: }; \ duke@435: duke@435: DEF_OOP(instance); duke@435: DEF_OOP(method); duke@435: DEF_OOP(methodData); duke@435: DEF_OOP(array); duke@435: DEF_OOP(constMethod); duke@435: DEF_OOP(constantPool); duke@435: DEF_OOP(constantPoolCache); duke@435: DEF_OOP(objArray); duke@435: DEF_OOP(typeArray); duke@435: DEF_OOP(symbol); duke@435: DEF_OOP(klass); duke@435: DEF_OOP(compiledICHolder); duke@435: duke@435: #endif // CHECK_UNHANDLED_OOPS duke@435: duke@435: // The klass hierarchy is separate from the oop hierarchy. duke@435: duke@435: class Klass; duke@435: class instanceKlass; duke@435: class instanceRefKlass; duke@435: class methodKlass; duke@435: class constMethodKlass; duke@435: class methodDataKlass; duke@435: class klassKlass; duke@435: class instanceKlassKlass; duke@435: class arrayKlassKlass; duke@435: class objArrayKlassKlass; duke@435: class typeArrayKlassKlass; duke@435: class arrayKlass; duke@435: class objArrayKlass; duke@435: class typeArrayKlass; coleenp@548: class constantPoolKlass; coleenp@548: class constantPoolCacheKlass; coleenp@548: class symbolKlass; duke@435: class compiledICHolderKlass;