src/share/vm/oops/oopsHierarchy.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/oopsHierarchy.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,216 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_OOPS_OOPSHIERARCHY_HPP
    1.29 +#define SHARE_VM_OOPS_OOPSHIERARCHY_HPP
    1.30 +
    1.31 +#include "runtime/globals.hpp"
    1.32 +#include "utilities/globalDefinitions.hpp"
    1.33 +
    1.34 +// OBJECT hierarchy
    1.35 +// This hierarchy is a representation hierarchy, i.e. if A is a superclass
    1.36 +// of B, A's representation is a prefix of B's representation.
    1.37 +
    1.38 +typedef juint narrowOop; // Offset instead of address for an oop within a java object
    1.39 +
    1.40 +// If compressed klass pointers then use narrowKlass.
    1.41 +typedef juint  narrowKlass;
    1.42 +
    1.43 +typedef void* OopOrNarrowOopStar;
    1.44 +typedef class   markOopDesc*                markOop;
    1.45 +
    1.46 +#ifndef CHECK_UNHANDLED_OOPS
    1.47 +
    1.48 +typedef class oopDesc*                            oop;
    1.49 +typedef class   instanceOopDesc*            instanceOop;
    1.50 +typedef class   arrayOopDesc*                    arrayOop;
    1.51 +typedef class     objArrayOopDesc*            objArrayOop;
    1.52 +typedef class     typeArrayOopDesc*            typeArrayOop;
    1.53 +
    1.54 +#else
    1.55 +
    1.56 +// When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
    1.57 +// carefully chosen set of constructors and conversion operators to go
    1.58 +// to and from the underlying oopDesc pointer type.
    1.59 +//
    1.60 +// Because oop and its subclasses <type>Oop are class types, arbitrary
    1.61 +// conversions are not accepted by the compiler.  Applying a cast to
    1.62 +// an oop will cause the best matched conversion operator to be
    1.63 +// invoked returning the underlying oopDesc* type if appropriate.
    1.64 +// No copy constructors, explicit user conversions or operators of
    1.65 +// numerical type should be defined within the oop class. Most C++
    1.66 +// compilers will issue a compile time error concerning the overloading
    1.67 +// ambiguity between operators of numerical and pointer types. If
    1.68 +// a conversion to or from an oop to a numerical type is needed,
    1.69 +// use the inline template methods, cast_*_oop, defined below.
    1.70 +//
    1.71 +// Converting NULL to oop to Handle implicit is no longer accepted by the
    1.72 +// compiler because there are too many steps in the conversion.  Use Handle()
    1.73 +// instead, which generates less code anyway.
    1.74 +
    1.75 +class Thread;
    1.76 +class PromotedObject;
    1.77 +
    1.78 +
    1.79 +class oop {
    1.80 +  oopDesc* _o;
    1.81 +
    1.82 +  void register_oop();
    1.83 +  void unregister_oop();
    1.84 +
    1.85 +  // friend class markOop;
    1.86 +public:
    1.87 +  void set_obj(const void* p)         {
    1.88 +    raw_set_obj(p);
    1.89 +    if (CheckUnhandledOops) register_oop();
    1.90 +  }
    1.91 +  void raw_set_obj(const void* p)     { _o = (oopDesc*)p; }
    1.92 +
    1.93 +  oop()                               { set_obj(NULL); }
    1.94 +  oop(const oop& o)                   { set_obj(o.obj()); }
    1.95 +  oop(const volatile oop& o)          { set_obj(o.obj()); }
    1.96 +  oop(const void* p)                  { set_obj(p); }
    1.97 +  ~oop()                              {
    1.98 +    if (CheckUnhandledOops) unregister_oop();
    1.99 +  }
   1.100 +
   1.101 +  oopDesc* obj()  const volatile      { return _o; }
   1.102 +
   1.103 +  // General access
   1.104 +  oopDesc*  operator->() const        { return obj(); }
   1.105 +  bool operator==(const oop o) const  { return obj() == o.obj(); }
   1.106 +  bool operator==(void *p) const      { return obj() == p; }
   1.107 +  bool operator!=(const volatile oop o) const  { return obj() != o.obj(); }
   1.108 +  bool operator!=(void *p) const      { return obj() != p; }
   1.109 +
   1.110 +  bool operator<(oop o) const         { return obj() < o.obj(); }
   1.111 +  bool operator>(oop o) const         { return obj() > o.obj(); }
   1.112 +  bool operator<=(oop o) const        { return obj() <= o.obj(); }
   1.113 +  bool operator>=(oop o) const        { return obj() >= o.obj(); }
   1.114 +  bool operator!() const              { return !obj(); }
   1.115 +
   1.116 +  // Assignment
   1.117 +  oop& operator=(const oop& o)                            { _o = o.obj(); return *this; }
   1.118 +#ifndef SOLARIS
   1.119 +  volatile oop& operator=(const oop& o) volatile          { _o = o.obj(); return *this; }
   1.120 +#endif
   1.121 +  volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; }
   1.122 +
   1.123 +  // Explict user conversions
   1.124 +  operator void* () const             { return (void *)obj(); }
   1.125 +#ifndef SOLARIS
   1.126 +  operator void* () const volatile    { return (void *)obj(); }
   1.127 +#endif
   1.128 +  operator HeapWord* () const         { return (HeapWord*)obj(); }
   1.129 +  operator oopDesc* () const          { return obj(); }
   1.130 +  operator intptr_t* () const         { return (intptr_t*)obj(); }
   1.131 +  operator PromotedObject* () const   { return (PromotedObject*)obj(); }
   1.132 +  operator markOop () const           { return markOop(obj()); }
   1.133 +
   1.134 +  operator address   () const         { return (address)obj(); }
   1.135 +
   1.136 +  // from javaCalls.cpp
   1.137 +  operator jobject () const           { return (jobject)obj(); }
   1.138 +  // from javaClasses.cpp
   1.139 +  operator JavaThread* () const       { return (JavaThread*)obj(); }
   1.140 +
   1.141 +#ifndef _LP64
   1.142 +  // from jvm.cpp
   1.143 +  operator jlong* () const            { return (jlong*)obj(); }
   1.144 +#endif
   1.145 +
   1.146 +  // from parNewGeneration and other things that want to get to the end of
   1.147 +  // an oop for stuff (like ObjArrayKlass.cpp)
   1.148 +  operator oop* () const              { return (oop *)obj(); }
   1.149 +};
   1.150 +
   1.151 +#define DEF_OOP(type)                                                      \
   1.152 +   class type##OopDesc;                                                    \
   1.153 +   class type##Oop : public oop {                                          \
   1.154 +     public:                                                               \
   1.155 +       type##Oop() : oop() {}                                              \
   1.156 +       type##Oop(const oop& o) : oop(o) {}                                 \
   1.157 +       type##Oop(const volatile oop& o) : oop(o) {}                        \
   1.158 +       type##Oop(const void* p) : oop(p) {}                                \
   1.159 +       operator type##OopDesc* () const { return (type##OopDesc*)obj(); }  \
   1.160 +       type##OopDesc* operator->() const {                                 \
   1.161 +            return (type##OopDesc*)obj();                                  \
   1.162 +       }                                                                   \
   1.163 +       type##Oop& operator=(const type##Oop& o) {                          \
   1.164 +            oop::operator=(o);                                             \
   1.165 +            return *this;                                                  \
   1.166 +       }                                                                   \
   1.167 +       NOT_SOLARIS(                                                        \
   1.168 +       volatile type##Oop& operator=(const type##Oop& o) volatile {        \
   1.169 +            (void)const_cast<oop&>(oop::operator=(o));                     \
   1.170 +            return *this;                                                  \
   1.171 +       })                                                                  \
   1.172 +       volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\
   1.173 +            (void)const_cast<oop&>(oop::operator=(o));                     \
   1.174 +            return *this;                                                  \
   1.175 +       }                                                                   \
   1.176 +   };
   1.177 +
   1.178 +DEF_OOP(instance);
   1.179 +DEF_OOP(array);
   1.180 +DEF_OOP(objArray);
   1.181 +DEF_OOP(typeArray);
   1.182 +
   1.183 +#endif // CHECK_UNHANDLED_OOPS
   1.184 +
   1.185 +// For CHECK_UNHANDLED_OOPS, it is ambiguous C++ behavior to have the oop
   1.186 +// structure contain explicit user defined conversions of both numerical
   1.187 +// and pointer type. Define inline methods to provide the numerical conversions.
   1.188 +template <class T> inline oop cast_to_oop(T value) {
   1.189 +  return (oop)(CHECK_UNHANDLED_OOPS_ONLY((void *))(value));
   1.190 +}
   1.191 +template <class T> inline T cast_from_oop(oop o) {
   1.192 +  return (T)(CHECK_UNHANDLED_OOPS_ONLY((void*))o);
   1.193 +}
   1.194 +
   1.195 +// The metadata hierarchy is separate from the oop hierarchy
   1.196 +
   1.197 +//      class MetaspaceObj
   1.198 +class   ConstMethod;
   1.199 +class   ConstantPoolCache;
   1.200 +class   MethodData;
   1.201 +//      class Metadata
   1.202 +class   Method;
   1.203 +class   ConstantPool;
   1.204 +//      class CHeapObj
   1.205 +class   CompiledICHolder;
   1.206 +
   1.207 +
   1.208 +// The klass hierarchy is separate from the oop hierarchy.
   1.209 +
   1.210 +class Klass;
   1.211 +class   InstanceKlass;
   1.212 +class     InstanceMirrorKlass;
   1.213 +class     InstanceClassLoaderKlass;
   1.214 +class     InstanceRefKlass;
   1.215 +class   ArrayKlass;
   1.216 +class     ObjArrayKlass;
   1.217 +class     TypeArrayKlass;
   1.218 +
   1.219 +#endif // SHARE_VM_OOPS_OOPSHIERARCHY_HPP

mercurial