oopsHierarchy.hpp revision 1472:c18cbe5936b8
1227972Stheraven/*
2227972Stheraven * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3227972Stheraven * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4227972Stheraven *
5227972Stheraven * This code is free software; you can redistribute it and/or modify it
6227972Stheraven * under the terms of the GNU General Public License version 2 only, as
7227972Stheraven * published by the Free Software Foundation.
8227972Stheraven *
9227972Stheraven * This code is distributed in the hope that it will be useful, but WITHOUT
10227972Stheraven * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11227972Stheraven * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12227972Stheraven * version 2 for more details (a copy is included in the LICENSE file that
13227972Stheraven * accompanied this code).
14227972Stheraven *
15227972Stheraven * You should have received a copy of the GNU General Public License version
16227972Stheraven * 2 along with this work; if not, write to the Free Software Foundation,
17227972Stheraven * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18227972Stheraven *
19227972Stheraven * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20227972Stheraven * or visit www.oracle.com if you need additional information or have any
21227972Stheraven * questions.
22227972Stheraven *
23227972Stheraven */
24227972Stheraven
25227972Stheraven// OBJECT hierarchy
26227972Stheraven// This hierarchy is a representation hierarchy, i.e. if A is a superclass
27227972Stheraven// of B, A's representation is a prefix of B's representation.
28227972Stheraven
29227972Stheraventypedef juint narrowOop; // Offset instead of address for an oop within a java object
30227972Stheraventypedef class klassOopDesc* wideKlassOop; // to keep SA happy and unhandled oop
31227972Stheraven                                          // detector happy.
32227972Stheraventypedef void* OopOrNarrowOopStar;
33227972Stheraven
34227972Stheraven#ifndef CHECK_UNHANDLED_OOPS
35227972Stheraven
36227972Stheraventypedef class oopDesc*                            oop;
37227972Stheraventypedef class   instanceOopDesc*            instanceOop;
38227972Stheraventypedef class   methodOopDesc*                    methodOop;
39227972Stheraventypedef class   constMethodOopDesc*            constMethodOop;
40227972Stheraventypedef class   methodDataOopDesc*            methodDataOop;
41227972Stheraventypedef class   arrayOopDesc*                    arrayOop;
42227972Stheraventypedef class     objArrayOopDesc*            objArrayOop;
43227972Stheraventypedef class     typeArrayOopDesc*            typeArrayOop;
44227972Stheraventypedef class   constantPoolOopDesc*            constantPoolOop;
45227972Stheraventypedef class   constantPoolCacheOopDesc*   constantPoolCacheOop;
46227972Stheraventypedef class   symbolOopDesc*                    symbolOop;
47227972Stheraventypedef class   klassOopDesc*                    klassOop;
48227972Stheraventypedef class   markOopDesc*                    markOop;
49227972Stheraventypedef class   compiledICHolderOopDesc*    compiledICHolderOop;
50227972Stheraven
51227972Stheraven#else
52227972Stheraven
53227972Stheraven
54227972Stheraven// When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
55227972Stheraven// carefully chosen set of constructors and conversion operators to go
56227972Stheraven// to and from the underlying oopDesc pointer type.
57227972Stheraven//
58227972Stheraven// Because oop and its subclasses <type>Oop are class types, arbitrary
59227972Stheraven// conversions are not accepted by the compiler, and you may get a message
60227972Stheraven// about overloading ambiguity (between long and int is common when converting
61227972Stheraven// from a constant in 64 bit mode), or unable to convert from type to 'oop'.
62227972Stheraven// Applying a cast to one of these conversion operators first will get to the
63227972Stheraven// underlying oopDesc* type if appropriate.
64227972Stheraven// Converting NULL to oop to Handle implicit is no longer accepted by the
65227972Stheraven// compiler because there are too many steps in the conversion.  Use Handle()
66227972Stheraven// instead, which generates less code anyway.
67227972Stheraven
68227972Stheravenclass Thread;
69227972Stheraventypedef class   markOopDesc*                markOop;
70227972Stheravenclass PromotedObject;
71227972Stheraven
72227972Stheraven
73227972Stheravenclass oop {
74227972Stheraven  oopDesc* _o;
75227972Stheraven
76227972Stheraven  void register_oop();
77227972Stheraven  void unregister_oop();
78227972Stheraven
79227972Stheraven  // friend class markOop;
80227972Stheravenpublic:
81227972Stheraven  void set_obj(const void* p)         {
82227972Stheraven    raw_set_obj(p);
83261645Sdim    if (CheckUnhandledOops) register_oop();
84227972Stheraven  }
85227972Stheraven  void raw_set_obj(const void* p)     { _o = (oopDesc*)p; }
86227972Stheraven
87227972Stheraven  oop()                               { set_obj(NULL); }
88227972Stheraven  oop(const volatile oop& o)          { set_obj(o.obj()); }
89227972Stheraven  oop(const void* p)                  { set_obj(p); }
90227972Stheraven  oop(intptr_t i)                     { set_obj((void *)i); }
91227972Stheraven#ifdef _LP64
92227972Stheraven  oop(int i)                          { set_obj((void *)i); }
93227972Stheraven#endif
94227972Stheraven  ~oop()                              {
95227972Stheraven    if (CheckUnhandledOops) unregister_oop();
96227972Stheraven  }
97227972Stheraven
98227972Stheraven  oopDesc* obj()  const volatile      { return _o; }
99227972Stheraven
100227972Stheraven  // General access
101227972Stheraven  oopDesc*  operator->() const        { return obj(); }
102227972Stheraven  bool operator==(const oop o) const  { return obj() == o.obj(); }
103227972Stheraven  bool operator==(void *p) const      { return obj() == p; }
104227972Stheraven  bool operator!=(const oop o) const  { return obj() != o.obj(); }
105227972Stheraven  bool operator!=(void *p) const      { return obj() != p; }
106227972Stheraven  bool operator==(intptr_t p) const   { return obj() == (oopDesc*)p; }
107227972Stheraven  bool operator!=(intptr_t p) const   { return obj() != (oopDesc*)p; }
108227972Stheraven
109227972Stheraven  bool operator<(oop o) const         { return obj() < o.obj(); }
110227972Stheraven  bool operator>(oop o) const         { return obj() > o.obj(); }
111227972Stheraven  bool operator<=(oop o) const        { return obj() <= o.obj(); }
112227972Stheraven  bool operator>=(oop o) const        { return obj() >= o.obj(); }
113227972Stheraven  bool operator!() const              { return !obj(); }
114227972Stheraven
115227972Stheraven  // Cast
116227972Stheraven  operator void* () const             { return (void *)obj(); }
117227972Stheraven  operator HeapWord* () const         { return (HeapWord*)obj(); }
118227972Stheraven  operator oopDesc* () const          { return obj(); }
119227972Stheraven  operator intptr_t* () const         { return (intptr_t*)obj(); }
120227972Stheraven  operator PromotedObject* () const   { return (PromotedObject*)obj(); }
121227972Stheraven  operator markOop () const           { return markOop(obj()); }
122227972Stheraven
123227972Stheraven  operator address   () const         { return (address)obj(); }
124227972Stheraven  operator intptr_t () const          { return (intptr_t)obj(); }
125227972Stheraven
126227972Stheraven  // from javaCalls.cpp
127227972Stheraven  operator jobject () const           { return (jobject)obj(); }
128227972Stheraven  // from javaClasses.cpp
129227972Stheraven  operator JavaThread* () const       { return (JavaThread*)obj(); }
130227972Stheraven
131227972Stheraven#ifndef _LP64
132227972Stheraven  // from jvm.cpp
133227972Stheraven  operator jlong* () const            { return (jlong*)obj(); }
134227972Stheraven#endif
135227972Stheraven
136227972Stheraven  // from parNewGeneration and other things that want to get to the end of
137227972Stheraven  // an oop for stuff (like constMethodKlass.cpp, objArrayKlass.cpp)
138227972Stheraven  operator oop* () const              { return (oop *)obj(); }
139227972Stheraven};
140227972Stheraven
141227972Stheraven#define DEF_OOP(type)                                                      \
142227972Stheraven   class type##OopDesc;                                                    \
143227972Stheraven   class type##Oop : public oop {                                          \
144227972Stheraven     public:                                                               \
145227972Stheraven       type##Oop() : oop() {}                                              \
146227972Stheraven       type##Oop(const volatile oop& o) : oop(o) {}                        \
147227972Stheraven       type##Oop(const void* p) : oop(p) {}                                \
148227972Stheraven       operator type##OopDesc* () const { return (type##OopDesc*)obj(); }  \
149227972Stheraven       type##OopDesc* operator->() const {                                 \
150227972Stheraven            return (type##OopDesc*)obj();                                  \
151227972Stheraven       }                                                                   \
152227972Stheraven   };                                                                      \
153227972Stheraven
154227972StheravenDEF_OOP(instance);
155227972StheravenDEF_OOP(method);
156227972StheravenDEF_OOP(methodData);
157227972StheravenDEF_OOP(array);
158227972StheravenDEF_OOP(constMethod);
159227972StheravenDEF_OOP(constantPool);
160227972StheravenDEF_OOP(constantPoolCache);
161227972StheravenDEF_OOP(objArray);
162227972StheravenDEF_OOP(typeArray);
163227972StheravenDEF_OOP(symbol);
164227972StheravenDEF_OOP(klass);
165227972StheravenDEF_OOP(compiledICHolder);
166227972Stheraven
167227972Stheraven#endif // CHECK_UNHANDLED_OOPS
168227972Stheraven
169227972Stheraven// The klass hierarchy is separate from the oop hierarchy.
170227972Stheraven
171class Klass;
172class   instanceKlass;
173class     instanceRefKlass;
174class   methodKlass;
175class   constMethodKlass;
176class   methodDataKlass;
177class   klassKlass;
178class     instanceKlassKlass;
179class     arrayKlassKlass;
180class       objArrayKlassKlass;
181class       typeArrayKlassKlass;
182class   arrayKlass;
183class     objArrayKlass;
184class     typeArrayKlass;
185class   constantPoolKlass;
186class   constantPoolCacheKlass;
187class   symbolKlass;
188class   compiledICHolderKlass;
189