oopsHierarchy.hpp revision 579:0fbdb4381b99
1/*
2 * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25// OBJECT hierarchy
26// This hierarchy is a representation hierarchy, i.e. if A is a superclass
27// of B, A's representation is a prefix of B's representation.
28
29typedef juint narrowOop; // Offset instead of address for an oop within a java object
30typedef class klassOopDesc* wideKlassOop; // to keep SA happy and unhandled oop
31                                          // detector happy.
32
33#ifndef CHECK_UNHANDLED_OOPS
34
35typedef class oopDesc*                            oop;
36typedef class   instanceOopDesc*            instanceOop;
37typedef class   methodOopDesc*                    methodOop;
38typedef class   constMethodOopDesc*            constMethodOop;
39typedef class   methodDataOopDesc*            methodDataOop;
40typedef class   arrayOopDesc*                    arrayOop;
41typedef class     objArrayOopDesc*            objArrayOop;
42typedef class     typeArrayOopDesc*            typeArrayOop;
43typedef class   constantPoolOopDesc*            constantPoolOop;
44typedef class   constantPoolCacheOopDesc*   constantPoolCacheOop;
45typedef class   symbolOopDesc*                    symbolOop;
46typedef class   klassOopDesc*                    klassOop;
47typedef class   markOopDesc*                    markOop;
48typedef class   compiledICHolderOopDesc*    compiledICHolderOop;
49
50#else
51
52
53// When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
54// carefully chosen set of constructors and conversion operators to go
55// to and from the underlying oopDesc pointer type.
56//
57// Because oop and its subclasses <type>Oop are class types, arbitrary
58// conversions are not accepted by the compiler, and you may get a message
59// about overloading ambiguity (between long and int is common when converting
60// from a constant in 64 bit mode), or unable to convert from type to 'oop'.
61// Applying a cast to one of these conversion operators first will get to the
62// underlying oopDesc* type if appropriate.
63// Converting NULL to oop to Handle implicit is no longer accepted by the
64// compiler because there are too many steps in the conversion.  Use Handle()
65// instead, which generates less code anyway.
66
67class Thread;
68typedef class   markOopDesc*                markOop;
69class PromotedObject;
70
71
72class oop {
73  oopDesc* _o;
74
75  void register_oop();
76  void unregister_oop();
77
78  // friend class markOop;
79public:
80  void set_obj(const void* p)         {
81    raw_set_obj(p);
82    if (CheckUnhandledOops) register_oop();
83  }
84  void raw_set_obj(const void* p)     { _o = (oopDesc*)p; }
85
86  oop()                               { set_obj(NULL); }
87  oop(const volatile oop& o)          { set_obj(o.obj()); }
88  oop(const void* p)                  { set_obj(p); }
89  oop(intptr_t i)                     { set_obj((void *)i); }
90#ifdef _LP64
91  oop(int i)                          { set_obj((void *)i); }
92#endif
93  ~oop()                              {
94    if (CheckUnhandledOops) unregister_oop();
95  }
96
97  oopDesc* obj()  const volatile      { return _o; }
98
99  // General access
100  oopDesc*  operator->() const        { return obj(); }
101  bool operator==(const oop o) const  { return obj() == o.obj(); }
102  bool operator==(void *p) const      { return obj() == p; }
103  bool operator!=(const oop o) const  { return obj() != o.obj(); }
104  bool operator!=(void *p) const      { return obj() != p; }
105  bool operator==(intptr_t p) const   { return obj() == (oopDesc*)p; }
106  bool operator!=(intptr_t p) const   { return obj() != (oopDesc*)p; }
107
108  bool operator<(oop o) const         { return obj() < o.obj(); }
109  bool operator>(oop o) const         { return obj() > o.obj(); }
110  bool operator<=(oop o) const        { return obj() <= o.obj(); }
111  bool operator>=(oop o) const        { return obj() >= o.obj(); }
112  bool operator!() const              { return !obj(); }
113
114  // Cast
115  operator void* () const             { return (void *)obj(); }
116  operator HeapWord* () const         { return (HeapWord*)obj(); }
117  operator oopDesc* () const          { return obj(); }
118  operator intptr_t* () const         { return (intptr_t*)obj(); }
119  operator PromotedObject* () const   { return (PromotedObject*)obj(); }
120  operator markOop () const           { return markOop(obj()); }
121
122  operator address   () const         { return (address)obj(); }
123  operator intptr_t () const          { return (intptr_t)obj(); }
124
125  // from javaCalls.cpp
126  operator jobject () const           { return (jobject)obj(); }
127  // from javaClasses.cpp
128  operator JavaThread* () const       { return (JavaThread*)obj(); }
129
130#ifndef _LP64
131  // from jvm.cpp
132  operator jlong* () const            { return (jlong*)obj(); }
133#endif
134
135  // from parNewGeneration and other things that want to get to the end of
136  // an oop for stuff (like constMethodKlass.cpp, objArrayKlass.cpp)
137  operator oop* () const              { return (oop *)obj(); }
138};
139
140#define DEF_OOP(type)                                                      \
141   class type##OopDesc;                                                    \
142   class type##Oop : public oop {                                          \
143     public:                                                               \
144       type##Oop() : oop() {}                                              \
145       type##Oop(const volatile oop& o) : oop(o) {}                        \
146       type##Oop(const void* p) : oop(p) {}                                \
147       operator type##OopDesc* () const { return (type##OopDesc*)obj(); }  \
148       type##OopDesc* operator->() const {                                 \
149            return (type##OopDesc*)obj();                                  \
150       }                                                                   \
151   };                                                                      \
152
153DEF_OOP(instance);
154DEF_OOP(method);
155DEF_OOP(methodData);
156DEF_OOP(array);
157DEF_OOP(constMethod);
158DEF_OOP(constantPool);
159DEF_OOP(constantPoolCache);
160DEF_OOP(objArray);
161DEF_OOP(typeArray);
162DEF_OOP(symbol);
163DEF_OOP(klass);
164DEF_OOP(compiledICHolder);
165
166#endif // CHECK_UNHANDLED_OOPS
167
168// The klass hierarchy is separate from the oop hierarchy.
169
170class Klass;
171class   instanceKlass;
172class     instanceRefKlass;
173class   methodKlass;
174class   constMethodKlass;
175class   methodDataKlass;
176class   klassKlass;
177class     instanceKlassKlass;
178class     arrayKlassKlass;
179class       objArrayKlassKlass;
180class       typeArrayKlassKlass;
181class   arrayKlass;
182class     objArrayKlass;
183class     typeArrayKlass;
184class   constantPoolKlass;
185class   constantPoolCacheKlass;
186class   symbolKlass;
187class   compiledICHolderKlass;
188