1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
95 if (CheckUnhandledOops) unregister_oop();
96 }
97
98 oopDesc* obj() const volatile { return _o; }
99
100 // General access
101 oopDesc* operator->() const { return obj(); }
102 bool operator==(const oop o) const { return obj() == o.obj(); }
103 bool operator==(void *p) const { return obj() == p; }
104 bool operator!=(const volatile oop o) const { return obj() != o.obj(); }
105 bool operator!=(void *p) const { return obj() != p; }
106
107 bool operator<(oop o) const { return obj() < o.obj(); }
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!() const { return !obj(); }
112
113 // Assignment
114 oop& operator=(const oop& o) { _o = o.obj(); return *this; }
115 #ifndef SOLARIS
116 volatile oop& operator=(const oop& o) volatile { _o = o.obj(); return *this; }
117 #endif
118 volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; }
119
120 // Explict user conversions
121 operator void* () const { return (void *)obj(); }
122 #ifndef SOLARIS
123 operator void* () const volatile { return (void *)obj(); }
124 #endif
125 operator HeapWord* () const { return (HeapWord*)obj(); }
126 operator oopDesc* () const { return obj(); }
127 operator intptr_t* () const { return (intptr_t*)obj(); }
128 operator PromotedObject* () const { return (PromotedObject*)obj(); }
129 operator markOop () const { return markOop(obj()); }
130
131 operator address () const { return (address)obj(); }
132
133 // from javaCalls.cpp
134 operator jobject () const { return (jobject)obj(); }
135 // from javaClasses.cpp
136 operator JavaThread* () const { return (JavaThread*)obj(); }
137
138 #ifndef _LP64
139 // from jvm.cpp
140 operator jlong* () const { return (jlong*)obj(); }
141 #endif
142
143 // from parNewGeneration and other things that want to get to the end of
144 // an oop for stuff (like ObjArrayKlass.cpp)
145 operator oop* () const { return (oop *)obj(); }
146 };
147
148 #define DEF_OOP(type) \
149 class type##OopDesc; \
150 class type##Oop : public oop { \
151 public: \
152 type##Oop() : oop() {} \
153 type##Oop(const oop& o) : oop(o) {} \
154 type##Oop(const volatile oop& o) : oop(o) {} \
155 type##Oop(const void* p) : oop(p) {} \
156 operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \
157 type##OopDesc* operator->() const { \
158 return (type##OopDesc*)obj(); \
159 } \
160 type##Oop& operator=(const type##Oop& o) { \
161 oop::operator=(o); \
162 return *this; \
163 } \
164 NOT_SOLARIS( \
165 volatile type##Oop& operator=(const type##Oop& o) volatile { \
166 (void)const_cast<oop&>(oop::operator=(o)); \
167 return *this; \
168 }) \
169 volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\
170 (void)const_cast<oop&>(oop::operator=(o)); \
171 return *this; \
172 } \
173 };
174
175 DEF_OOP(instance);
176 DEF_OOP(array);
177 DEF_OOP(objArray);
178 DEF_OOP(typeArray);
179
180 #endif // CHECK_UNHANDLED_OOPS
181
182 // For CHECK_UNHANDLED_OOPS, it is ambiguous C++ behavior to have the oop
183 // structure contain explicit user defined conversions of both numerical
184 // and pointer type. Define inline methods to provide the numerical conversions.
185 template <class T> inline oop cast_to_oop(T value) {
186 return (oop)(CHECK_UNHANDLED_OOPS_ONLY((void *))(value));
187 }
188 template <class T> inline T cast_from_oop(oop o) {
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
95 if (CheckUnhandledOops) unregister_oop();
96 }
97
98 oopDesc* obj() const volatile { return _o; }
99
100 // General access
101 oopDesc* operator->() const { return obj(); }
102 bool operator==(const oop o) const { return obj() == o.obj(); }
103 bool operator==(void *p) const { return obj() == p; }
104 bool operator!=(const volatile oop o) const { return obj() != o.obj(); }
105 bool operator!=(void *p) const { return obj() != p; }
106
107 bool operator<(oop o) const { return obj() < o.obj(); }
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!() const { return !obj(); }
112
113 // Assignment
114 oop& operator=(const oop& o) { _o = o.obj(); return *this; }
115 volatile oop& operator=(const oop& o) volatile { _o = o.obj(); return *this; }
116 volatile oop& operator=(const volatile oop& o) volatile { _o = o.obj(); return *this; }
117
118 // Explict user conversions
119 operator void* () const { return (void *)obj(); }
120 #ifndef SOLARIS
121 operator void* () const volatile { return (void *)obj(); }
122 #endif
123 operator HeapWord* () const { return (HeapWord*)obj(); }
124 operator oopDesc* () const volatile { return obj(); }
125 operator intptr_t* () const { return (intptr_t*)obj(); }
126 operator PromotedObject* () const { return (PromotedObject*)obj(); }
127 operator markOop () const { return markOop(obj()); }
128 operator address () const { return (address)obj(); }
129
130 // from javaCalls.cpp
131 operator jobject () const { return (jobject)obj(); }
132 // from javaClasses.cpp
133 operator JavaThread* () const { return (JavaThread*)obj(); }
134
135 #ifndef _LP64
136 // from jvm.cpp
137 operator jlong* () const { return (jlong*)obj(); }
138 #endif
139
140 // from parNewGeneration and other things that want to get to the end of
141 // an oop for stuff (like ObjArrayKlass.cpp)
142 operator oop* () const { return (oop *)obj(); }
143 };
144
145 #define DEF_OOP(type) \
146 class type##OopDesc; \
147 class type##Oop : public oop { \
148 public: \
149 type##Oop() : oop() {} \
150 type##Oop(const oop& o) : oop(o) {} \
151 type##Oop(const volatile oop& o) : oop(o) {} \
152 type##Oop(const void* p) : oop(p) {} \
153 operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \
154 type##OopDesc* operator->() const { \
155 return (type##OopDesc*)obj(); \
156 } \
157 type##Oop& operator=(const type##Oop& o) { \
158 oop::operator=(o); \
159 return *this; \
160 } \
161 volatile type##Oop& operator=(const type##Oop& o) volatile { \
162 (void)const_cast<oop&>(oop::operator=(o)); \
163 return *this; \
164 } \
165 volatile type##Oop& operator=(const volatile type##Oop& o) volatile {\
166 (void)const_cast<oop&>(oop::operator=(o)); \
167 return *this; \
168 } \
169 };
170
171 DEF_OOP(instance);
172 DEF_OOP(array);
173 DEF_OOP(objArray);
174 DEF_OOP(typeArray);
175
176 #endif // CHECK_UNHANDLED_OOPS
177
178 // For CHECK_UNHANDLED_OOPS, it is ambiguous C++ behavior to have the oop
179 // structure contain explicit user defined conversions of both numerical
180 // and pointer type. Define inline methods to provide the numerical conversions.
181 template <class T> inline oop cast_to_oop(T value) {
182 return (oop)(CHECK_UNHANDLED_OOPS_ONLY((void *))(value));
183 }
184 template <class T> inline T cast_from_oop(oop o) {
|