duke@435: /* hseigel@5528: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_OOPS_OOPSHIERARCHY_HPP stefank@2314: #define SHARE_VM_OOPS_OOPSHIERARCHY_HPP stefank@2314: stefank@2314: #include "runtime/globals.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: 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 hseigel@5528: hseigel@5528: // If compressed klass pointers then use narrowKlass. hseigel@5528: typedef juint narrowKlass; hseigel@5528: ysr@1280: typedef void* OopOrNarrowOopStar; coleenp@4037: typedef class markOopDesc* markOop; 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 arrayOopDesc* arrayOop; coleenp@548: typedef class objArrayOopDesc* objArrayOop; coleenp@548: typedef class typeArrayOopDesc* typeArrayOop; duke@435: duke@435: #else 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 hseigel@5784: // conversions are not accepted by the compiler. Applying a cast to hseigel@5784: // an oop will cause the best matched conversion operator to be hseigel@5784: // invoked returning the underlying oopDesc* type if appropriate. hseigel@5784: // No copy constructors, explicit user conversions or operators of hseigel@5784: // numerical type should be defined within the oop class. Most C++ hseigel@5784: // compilers will issue a compile time error concerning the overloading hseigel@5784: // ambiguity between operators of numerical and pointer types. If hseigel@5784: // a conversion to or from an oop to a numerical type is needed, hseigel@5784: // use the inline template methods, cast_*_oop, defined below. hseigel@5784: // 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: 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); } hseigel@5784: oop(const oop& o) { set_obj(o.obj()); } duke@435: oop(const volatile oop& o) { set_obj(o.obj()); } duke@435: oop(const void* p) { set_obj(p); } 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; } coleenp@4037: bool operator!=(const volatile oop o) const { return obj() != o.obj(); } duke@435: bool operator!=(void *p) const { return obj() != 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: hseigel@5784: // Assignment hseigel@5784: oop& operator=(const oop& o) { _o = o.obj(); return *this; } hseigel@5784: #ifndef SOLARIS hseigel@5784: volatile oop& operator=(const oop& o) volatile { _o = o.obj(); return *this; } hseigel@5784: #endif hseigel@5784: volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; } hseigel@5784: hseigel@5784: // Explict user conversions duke@435: operator void* () const { return (void *)obj(); } hseigel@5784: #ifndef SOLARIS hseigel@5784: operator void* () const volatile { return (void *)obj(); } hseigel@5784: #endif 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: 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(); } xlu@948: xlu@948: #ifndef _LP64 duke@435: // from jvm.cpp duke@435: operator jlong* () const { return (jlong*)obj(); } xlu@948: #endif duke@435: duke@435: // from parNewGeneration and other things that want to get to the end of coleenp@4142: // an oop for stuff (like 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() {} \ hseigel@5784: type##Oop(const oop& o) : oop(o) {} \ 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: } \ hseigel@5784: type##Oop& operator=(const type##Oop& o) { \ hseigel@5784: oop::operator=(o); \ hseigel@5784: return *this; \ hseigel@5784: } \ hseigel@5784: NOT_SOLARIS( \ hseigel@5784: volatile type##Oop& operator=(const type##Oop& o) volatile { \ hseigel@5784: (void)const_cast(oop::operator=(o)); \ hseigel@5784: return *this; \ hseigel@5784: }) \ hseigel@5784: volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\ hseigel@5784: (void)const_cast(oop::operator=(o)); \ hseigel@5784: return *this; \ hseigel@5784: } \ coleenp@4037: }; duke@435: duke@435: DEF_OOP(instance); duke@435: DEF_OOP(array); duke@435: DEF_OOP(objArray); duke@435: DEF_OOP(typeArray); duke@435: duke@435: #endif // CHECK_UNHANDLED_OOPS duke@435: hseigel@5784: // For CHECK_UNHANDLED_OOPS, it is ambiguous C++ behavior to have the oop hseigel@5784: // structure contain explicit user defined conversions of both numerical hseigel@5784: // and pointer type. Define inline methods to provide the numerical conversions. hseigel@5784: template inline oop cast_to_oop(T value) { hseigel@5784: return (oop)(CHECK_UNHANDLED_OOPS_ONLY((void *))(value)); hseigel@5784: } hseigel@5784: template inline T cast_from_oop(oop o) { hseigel@5784: return (T)(CHECK_UNHANDLED_OOPS_ONLY((void*))o); hseigel@5784: } hseigel@5784: coleenp@4037: // The metadata hierarchy is separate from the oop hierarchy coleenp@4037: coleenp@4037: // class MetaspaceObj coleenp@4037: class ConstMethod; coleenp@4037: class ConstantPoolCache; coleenp@4037: class MethodData; coleenp@4037: // class Metadata coleenp@4037: class Method; coleenp@4037: class ConstantPool; coleenp@4037: // class CHeapObj coleenp@4037: class CompiledICHolder; coleenp@4037: coleenp@4037: duke@435: // The klass hierarchy is separate from the oop hierarchy. duke@435: duke@435: class Klass; coleenp@4037: class InstanceKlass; coleenp@4047: class InstanceMirrorKlass; coleenp@4047: class InstanceClassLoaderKlass; coleenp@4047: class InstanceRefKlass; coleenp@4142: class ArrayKlass; coleenp@4142: class ObjArrayKlass; coleenp@4142: class TypeArrayKlass; stefank@2314: stefank@2314: #endif // SHARE_VM_OOPS_OOPSHIERARCHY_HPP