src/share/vm/oops/oopsHierarchy.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OOPS_OOPSHIERARCHY_HPP
aoqi@0 26 #define SHARE_VM_OOPS_OOPSHIERARCHY_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/globals.hpp"
aoqi@0 29 #include "utilities/globalDefinitions.hpp"
aoqi@0 30
aoqi@0 31 // OBJECT hierarchy
aoqi@0 32 // This hierarchy is a representation hierarchy, i.e. if A is a superclass
aoqi@0 33 // of B, A's representation is a prefix of B's representation.
aoqi@0 34
aoqi@0 35 typedef juint narrowOop; // Offset instead of address for an oop within a java object
aoqi@0 36
aoqi@0 37 // If compressed klass pointers then use narrowKlass.
aoqi@0 38 typedef juint narrowKlass;
aoqi@0 39
aoqi@0 40 typedef void* OopOrNarrowOopStar;
aoqi@0 41 typedef class markOopDesc* markOop;
aoqi@0 42
aoqi@0 43 #ifndef CHECK_UNHANDLED_OOPS
aoqi@0 44
aoqi@0 45 typedef class oopDesc* oop;
aoqi@0 46 typedef class instanceOopDesc* instanceOop;
aoqi@0 47 typedef class arrayOopDesc* arrayOop;
aoqi@0 48 typedef class objArrayOopDesc* objArrayOop;
aoqi@0 49 typedef class typeArrayOopDesc* typeArrayOop;
aoqi@0 50
aoqi@0 51 #else
aoqi@0 52
aoqi@0 53 // When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
aoqi@0 54 // carefully chosen set of constructors and conversion operators to go
aoqi@0 55 // to and from the underlying oopDesc pointer type.
aoqi@0 56 //
aoqi@0 57 // Because oop and its subclasses <type>Oop are class types, arbitrary
aoqi@0 58 // conversions are not accepted by the compiler. Applying a cast to
aoqi@0 59 // an oop will cause the best matched conversion operator to be
aoqi@0 60 // invoked returning the underlying oopDesc* type if appropriate.
aoqi@0 61 // No copy constructors, explicit user conversions or operators of
aoqi@0 62 // numerical type should be defined within the oop class. Most C++
aoqi@0 63 // compilers will issue a compile time error concerning the overloading
aoqi@0 64 // ambiguity between operators of numerical and pointer types. If
aoqi@0 65 // a conversion to or from an oop to a numerical type is needed,
aoqi@0 66 // use the inline template methods, cast_*_oop, defined below.
aoqi@0 67 //
aoqi@0 68 // Converting NULL to oop to Handle implicit is no longer accepted by the
aoqi@0 69 // compiler because there are too many steps in the conversion. Use Handle()
aoqi@0 70 // instead, which generates less code anyway.
aoqi@0 71
aoqi@0 72 class Thread;
aoqi@0 73 class PromotedObject;
aoqi@0 74
aoqi@0 75
aoqi@0 76 class oop {
aoqi@0 77 oopDesc* _o;
aoqi@0 78
aoqi@0 79 void register_oop();
aoqi@0 80 void unregister_oop();
aoqi@0 81
aoqi@0 82 // friend class markOop;
aoqi@0 83 public:
aoqi@0 84 void set_obj(const void* p) {
aoqi@0 85 raw_set_obj(p);
aoqi@0 86 if (CheckUnhandledOops) register_oop();
aoqi@0 87 }
aoqi@0 88 void raw_set_obj(const void* p) { _o = (oopDesc*)p; }
aoqi@0 89
aoqi@0 90 oop() { set_obj(NULL); }
aoqi@0 91 oop(const oop& o) { set_obj(o.obj()); }
aoqi@0 92 oop(const volatile oop& o) { set_obj(o.obj()); }
aoqi@0 93 oop(const void* p) { set_obj(p); }
aoqi@0 94 ~oop() {
aoqi@0 95 if (CheckUnhandledOops) unregister_oop();
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 oopDesc* obj() const volatile { return _o; }
aoqi@0 99
aoqi@0 100 // General access
aoqi@0 101 oopDesc* operator->() const { return obj(); }
aoqi@0 102 bool operator==(const oop o) const { return obj() == o.obj(); }
aoqi@0 103 bool operator==(void *p) const { return obj() == p; }
aoqi@0 104 bool operator!=(const volatile oop o) const { return obj() != o.obj(); }
aoqi@0 105 bool operator!=(void *p) const { return obj() != p; }
aoqi@0 106
aoqi@0 107 bool operator<(oop o) const { return obj() < o.obj(); }
aoqi@0 108 bool operator>(oop o) const { return obj() > o.obj(); }
aoqi@0 109 bool operator<=(oop o) const { return obj() <= o.obj(); }
aoqi@0 110 bool operator>=(oop o) const { return obj() >= o.obj(); }
aoqi@0 111 bool operator!() const { return !obj(); }
aoqi@0 112
aoqi@0 113 // Assignment
aoqi@0 114 oop& operator=(const oop& o) { _o = o.obj(); return *this; }
aoqi@0 115 #ifndef SOLARIS
aoqi@0 116 volatile oop& operator=(const oop& o) volatile { _o = o.obj(); return *this; }
aoqi@0 117 #endif
aoqi@0 118 volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; }
aoqi@0 119
aoqi@0 120 // Explict user conversions
aoqi@0 121 operator void* () const { return (void *)obj(); }
aoqi@0 122 #ifndef SOLARIS
aoqi@0 123 operator void* () const volatile { return (void *)obj(); }
aoqi@0 124 #endif
aoqi@0 125 operator HeapWord* () const { return (HeapWord*)obj(); }
aoqi@0 126 operator oopDesc* () const { return obj(); }
aoqi@0 127 operator intptr_t* () const { return (intptr_t*)obj(); }
aoqi@0 128 operator PromotedObject* () const { return (PromotedObject*)obj(); }
aoqi@0 129 operator markOop () const { return markOop(obj()); }
aoqi@0 130
aoqi@0 131 operator address () const { return (address)obj(); }
aoqi@0 132
aoqi@0 133 // from javaCalls.cpp
aoqi@0 134 operator jobject () const { return (jobject)obj(); }
aoqi@0 135 // from javaClasses.cpp
aoqi@0 136 operator JavaThread* () const { return (JavaThread*)obj(); }
aoqi@0 137
aoqi@0 138 #ifndef _LP64
aoqi@0 139 // from jvm.cpp
aoqi@0 140 operator jlong* () const { return (jlong*)obj(); }
aoqi@0 141 #endif
aoqi@0 142
aoqi@0 143 // from parNewGeneration and other things that want to get to the end of
aoqi@0 144 // an oop for stuff (like ObjArrayKlass.cpp)
aoqi@0 145 operator oop* () const { return (oop *)obj(); }
aoqi@0 146 };
aoqi@0 147
aoqi@0 148 #define DEF_OOP(type) \
aoqi@0 149 class type##OopDesc; \
aoqi@0 150 class type##Oop : public oop { \
aoqi@0 151 public: \
aoqi@0 152 type##Oop() : oop() {} \
aoqi@0 153 type##Oop(const oop& o) : oop(o) {} \
aoqi@0 154 type##Oop(const volatile oop& o) : oop(o) {} \
aoqi@0 155 type##Oop(const void* p) : oop(p) {} \
aoqi@0 156 operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \
aoqi@0 157 type##OopDesc* operator->() const { \
aoqi@0 158 return (type##OopDesc*)obj(); \
aoqi@0 159 } \
aoqi@0 160 type##Oop& operator=(const type##Oop& o) { \
aoqi@0 161 oop::operator=(o); \
aoqi@0 162 return *this; \
aoqi@0 163 } \
aoqi@0 164 NOT_SOLARIS( \
aoqi@0 165 volatile type##Oop& operator=(const type##Oop& o) volatile { \
aoqi@0 166 (void)const_cast<oop&>(oop::operator=(o)); \
aoqi@0 167 return *this; \
aoqi@0 168 }) \
aoqi@0 169 volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\
aoqi@0 170 (void)const_cast<oop&>(oop::operator=(o)); \
aoqi@0 171 return *this; \
aoqi@0 172 } \
aoqi@0 173 };
aoqi@0 174
aoqi@0 175 DEF_OOP(instance);
aoqi@0 176 DEF_OOP(array);
aoqi@0 177 DEF_OOP(objArray);
aoqi@0 178 DEF_OOP(typeArray);
aoqi@0 179
aoqi@0 180 #endif // CHECK_UNHANDLED_OOPS
aoqi@0 181
aoqi@0 182 // For CHECK_UNHANDLED_OOPS, it is ambiguous C++ behavior to have the oop
aoqi@0 183 // structure contain explicit user defined conversions of both numerical
aoqi@0 184 // and pointer type. Define inline methods to provide the numerical conversions.
aoqi@0 185 template <class T> inline oop cast_to_oop(T value) {
aoqi@0 186 return (oop)(CHECK_UNHANDLED_OOPS_ONLY((void *))(value));
aoqi@0 187 }
aoqi@0 188 template <class T> inline T cast_from_oop(oop o) {
aoqi@0 189 return (T)(CHECK_UNHANDLED_OOPS_ONLY((void*))o);
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 // The metadata hierarchy is separate from the oop hierarchy
aoqi@0 193
aoqi@0 194 // class MetaspaceObj
aoqi@0 195 class ConstMethod;
aoqi@0 196 class ConstantPoolCache;
aoqi@0 197 class MethodData;
aoqi@0 198 // class Metadata
aoqi@0 199 class Method;
aoqi@0 200 class ConstantPool;
aoqi@0 201 // class CHeapObj
aoqi@0 202 class CompiledICHolder;
aoqi@0 203
aoqi@0 204
aoqi@0 205 // The klass hierarchy is separate from the oop hierarchy.
aoqi@0 206
aoqi@0 207 class Klass;
aoqi@0 208 class InstanceKlass;
aoqi@0 209 class InstanceMirrorKlass;
aoqi@0 210 class InstanceClassLoaderKlass;
aoqi@0 211 class InstanceRefKlass;
aoqi@0 212 class ArrayKlass;
aoqi@0 213 class ObjArrayKlass;
aoqi@0 214 class TypeArrayKlass;
aoqi@0 215
aoqi@0 216 #endif // SHARE_VM_OOPS_OOPSHIERARCHY_HPP

mercurial