annotate src/share/vm/runtime/handles.hpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents c89f86385056
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 665
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // In order to preserve oops during garbage collection, they should be
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // allocated and passed around via Handles within the VM. A handle is
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // simply an extra indirection allocated in a thread local handle area.
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // A handle is a ValueObj, so it can be passed around as a value, can
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // be used as a parameter w/o using &-passing, and can be returned as a
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // return value.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // oop parameters and return types should be Handles whenever feasible.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Handles are declared in a straight-forward manner, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 //
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // oop obj = ...;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Handle h1(obj); // allocate new handle
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Handle h2(thread, obj); // faster allocation when current thread is known
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Handle h3; // declare handle only, no allocation occurs
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // ...
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // h3 = h1; // make h3 refer to same indirection as h1
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // oop obj2 = h2(); // get handle value
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // h1->print(); // invoking operation on oop
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Handles are specialized for different oop types to provide extra type
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // information and avoid unnecessary casting. For each oop type xxxOop
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // there is a corresponding handle called xxxHandle, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 //
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // oop Handle
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // methodOop methodHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // instanceOop instanceHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
54 //
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // For klassOops, it is often useful to model the Klass hierarchy in order
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // to get access to the klass_part without casting. For each xxxKlass there
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // is a corresponding handle called xxxKlassHandle, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // klassOop Klass KlassHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // klassOop methodKlass methodKlassHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // klassOop instanceKlass instanceKlassHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
62 //
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Base class for all handles. Provides overloading of frequently
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // used operators for ease of use.
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 class Handle VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 oop* _handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Constructors
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Handle() { _handle = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 Handle(oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #ifndef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
81 Handle(Thread* thread, oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Don't inline body with assert for current thread
a61af66fc99e Initial load
duke
parents:
diff changeset
84 Handle(Thread* thread, oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 #endif // ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // General access
a61af66fc99e Initial load
duke
parents:
diff changeset
88 oop operator () () const { return obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 oop operator -> () const { return non_null_obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 bool operator == (oop o) const { return obj() == o; }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 bool operator == (const Handle& h) const { return obj() == h.obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Null checks
a61af66fc99e Initial load
duke
parents:
diff changeset
94 bool is_null() const { return _handle == NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 bool not_null() const { return _handle != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void print() { obj()->print(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Direct interface, use very sparingly.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 Handle(oop *handle, bool dummy) { _handle = handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // since duplicates is only valid as long as original handle is alive.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 oop* raw_value() { return _handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 };
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Base class for Handles containing klassOops. Provides overloading of frequently
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // used operators for ease of use and typed access to the Klass part.
a61af66fc99e Initial load
duke
parents:
diff changeset
115 class KlassHandle: public Handle {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
117 klassOop obj() const { return (klassOop)Handle::obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 klassOop non_null_obj() const { return (klassOop)Handle::non_null_obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Klass* as_klass() const { return non_null_obj()->klass_part(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Constructors
a61af66fc99e Initial load
duke
parents:
diff changeset
123 KlassHandle () : Handle() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
124 KlassHandle (oop obj) : Handle(obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 KlassHandle (Klass* kl) : Handle(kl ? kl->as_klassOop() : (klassOop)NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(SharedSkipVerify || is_null() || obj()->is_klass(), "not a klassOop");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Faster versions passing Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
132 KlassHandle (Thread* thread, oop obj) : Handle(thread, obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 KlassHandle (Thread *thread, Klass* kl)
a61af66fc99e Initial load
duke
parents:
diff changeset
136 : Handle(thread, kl ? kl->as_klassOop() : (klassOop)NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert(is_null() || obj()->is_klass(), "not a klassOop");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
140 // Direct interface, use very sparingly.
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
141 // Used by SystemDictionaryHandles to create handles on existing WKKs.
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
142 // The obj of such a klass handle may be null, because the handle is formed
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
143 // during system bootstrapping.
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
144 KlassHandle(klassOop *handle, bool dummy) : Handle((oop*)handle, dummy) {
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
145 assert(SharedSkipVerify || is_null() || obj() == NULL || obj()->is_klass(), "not a klassOop");
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
146 }
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
147
0
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // General access
a61af66fc99e Initial load
duke
parents:
diff changeset
149 klassOop operator () () const { return obj(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 Klass* operator -> () const { return as_klass(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 };
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Specific Handles for different oop types
a61af66fc99e Initial load
duke
parents:
diff changeset
156 #define DEF_HANDLE(type, is_a) \
a61af66fc99e Initial load
duke
parents:
diff changeset
157 class type##Handle; \
a61af66fc99e Initial load
duke
parents:
diff changeset
158 class type##Handle: public Handle { \
a61af66fc99e Initial load
duke
parents:
diff changeset
159 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
160 type##Oop obj() const { return (type##Oop)Handle::obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
161 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
162 \
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
164 /* Constructors */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
165 type##Handle () : Handle() {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
166 type##Handle (type##Oop obj) : Handle((oop)obj) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(SharedSkipVerify || is_null() || ((oop)obj)->is_a(), \
a61af66fc99e Initial load
duke
parents:
diff changeset
168 "illegal type"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
170 type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
171 assert(SharedSkipVerify || is_null() || ((oop)obj)->is_a(), "illegal type"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
173 \
a61af66fc99e Initial load
duke
parents:
diff changeset
174 /* Special constructor, use sparingly */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
175 type##Handle (type##Oop *handle, bool dummy) : Handle((oop*)handle, dummy) {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
176 \
a61af66fc99e Initial load
duke
parents:
diff changeset
177 /* Operators for ease of use */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
178 type##Oop operator () () const { return obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
179 type##Oop operator -> () const { return non_null_obj(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
180 };
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 DEF_HANDLE(instance , is_instance )
a61af66fc99e Initial load
duke
parents:
diff changeset
184 DEF_HANDLE(method , is_method )
a61af66fc99e Initial load
duke
parents:
diff changeset
185 DEF_HANDLE(constMethod , is_constMethod )
a61af66fc99e Initial load
duke
parents:
diff changeset
186 DEF_HANDLE(methodData , is_methodData )
a61af66fc99e Initial load
duke
parents:
diff changeset
187 DEF_HANDLE(array , is_array )
a61af66fc99e Initial load
duke
parents:
diff changeset
188 DEF_HANDLE(constantPool , is_constantPool )
a61af66fc99e Initial load
duke
parents:
diff changeset
189 DEF_HANDLE(constantPoolCache, is_constantPoolCache)
a61af66fc99e Initial load
duke
parents:
diff changeset
190 DEF_HANDLE(objArray , is_objArray )
a61af66fc99e Initial load
duke
parents:
diff changeset
191 DEF_HANDLE(typeArray , is_typeArray )
a61af66fc99e Initial load
duke
parents:
diff changeset
192 DEF_HANDLE(symbol , is_symbol )
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Specific KlassHandles for different Klass types
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 #define DEF_KLASS_HANDLE(type, is_a) \
a61af66fc99e Initial load
duke
parents:
diff changeset
198 class type##Handle : public KlassHandle { \
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
200 /* Constructors */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
201 type##Handle () : KlassHandle() {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
202 type##Handle (klassOop obj) : KlassHandle(obj) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(SharedSkipVerify || is_null() || obj->klass_part()->is_a(), \
a61af66fc99e Initial load
duke
parents:
diff changeset
204 "illegal type"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
205 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
206 type##Handle (Thread* thread, klassOop obj) : KlassHandle(thread, obj) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
207 assert(SharedSkipVerify || is_null() || obj->klass_part()->is_a(), \
a61af66fc99e Initial load
duke
parents:
diff changeset
208 "illegal type"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
209 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
210 \
a61af66fc99e Initial load
duke
parents:
diff changeset
211 /* Access to klass part */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
212 type* operator -> () const { return (type*)obj()->klass_part(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
213 \
a61af66fc99e Initial load
duke
parents:
diff changeset
214 static type##Handle cast(KlassHandle h) { return type##Handle(h()); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
215 \
a61af66fc99e Initial load
duke
parents:
diff changeset
216 };
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 DEF_KLASS_HANDLE(instanceKlass , oop_is_instance_slow )
a61af66fc99e Initial load
duke
parents:
diff changeset
220 DEF_KLASS_HANDLE(methodKlass , oop_is_method )
a61af66fc99e Initial load
duke
parents:
diff changeset
221 DEF_KLASS_HANDLE(constMethodKlass , oop_is_constMethod )
a61af66fc99e Initial load
duke
parents:
diff changeset
222 DEF_KLASS_HANDLE(klassKlass , oop_is_klass )
a61af66fc99e Initial load
duke
parents:
diff changeset
223 DEF_KLASS_HANDLE(arrayKlassKlass , oop_is_arrayKlass )
a61af66fc99e Initial load
duke
parents:
diff changeset
224 DEF_KLASS_HANDLE(objArrayKlassKlass , oop_is_objArrayKlass )
a61af66fc99e Initial load
duke
parents:
diff changeset
225 DEF_KLASS_HANDLE(typeArrayKlassKlass , oop_is_typeArrayKlass)
a61af66fc99e Initial load
duke
parents:
diff changeset
226 DEF_KLASS_HANDLE(arrayKlass , oop_is_array )
a61af66fc99e Initial load
duke
parents:
diff changeset
227 DEF_KLASS_HANDLE(typeArrayKlass , oop_is_typeArray_slow)
a61af66fc99e Initial load
duke
parents:
diff changeset
228 DEF_KLASS_HANDLE(objArrayKlass , oop_is_objArray_slow )
a61af66fc99e Initial load
duke
parents:
diff changeset
229 DEF_KLASS_HANDLE(symbolKlass , oop_is_symbol )
a61af66fc99e Initial load
duke
parents:
diff changeset
230 DEF_KLASS_HANDLE(constantPoolKlass , oop_is_constantPool )
a61af66fc99e Initial load
duke
parents:
diff changeset
231 DEF_KLASS_HANDLE(constantPoolCacheKlass, oop_is_constantPool )
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // Thread local handle area
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 class HandleArea: public Arena {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 friend class HandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 friend class NoHandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 friend class ResetNoHandleMark;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int _handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 int _no_handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
245 HandleArea* _prev; // link to outer (older) area
a61af66fc99e Initial load
duke
parents:
diff changeset
246 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
248 HandleArea(HandleArea* prev) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 debug_only(_handle_mark_nesting = 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 debug_only(_no_handle_mark_nesting = 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 _prev = prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // Handle allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
255 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
256 oop* real_allocate_handle(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
258 oop* handle = (oop*) (UseMallocOnly ? internal_malloc_4(oopSize) : Amalloc_4(oopSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
259 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
260 oop* handle = (oop*) Amalloc_4(oopSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
262 *handle = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 return handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
266 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
267 oop* allocate_handle(oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
269 oop* allocate_handle(oop obj) { return real_allocate_handle(obj); }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // Garbage collection support
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Number of handles in use
a61af66fc99e Initial load
duke
parents:
diff changeset
276 size_t used() const { return Arena::used() / oopSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 debug_only(bool no_handle_mark_active() { return _no_handle_mark_nesting > 0; })
a61af66fc99e Initial load
duke
parents:
diff changeset
279 };
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // Handles are allocated in a (growable) thread local handle area. Deallocation
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // is managed using a HandleMark. It should normally not be necessary to use
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // HandleMarks manually.
a61af66fc99e Initial load
duke
parents:
diff changeset
286 //
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // A HandleMark constructor will record the current handle area top, and the
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // desctructor will reset the top, destroying all handles allocated in between.
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // The following code will therefore NOT work:
a61af66fc99e Initial load
duke
parents:
diff changeset
290 //
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Handle h;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // h = Handle(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // h()->print(); // WRONG, h destroyed by HandleMark destructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
297 //
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // If h has to be preserved, it can be converted to an oop or a local JNI handle
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // across the HandleMark boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // The base class of HandleMark should have been StackObj but we also heap allocate
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // a HandleMark when a thread is created.
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 class HandleMark {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
306 Thread *_thread; // thread that owns this mark
a61af66fc99e Initial load
duke
parents:
diff changeset
307 HandleArea *_area; // saved handle area
a61af66fc99e Initial load
duke
parents:
diff changeset
308 Chunk *_chunk; // saved arena chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
309 char *_hwm, *_max; // saved arena info
a61af66fc99e Initial load
duke
parents:
diff changeset
310 NOT_PRODUCT(size_t _size_in_bytes;) // size of handle area
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // Link to previous active HandleMark in thread
a61af66fc99e Initial load
duke
parents:
diff changeset
312 HandleMark* _previous_handle_mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 void initialize(Thread* thread); // common code for constructors
a61af66fc99e Initial load
duke
parents:
diff changeset
315 void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 HandleMark* previous_handle_mark() const { return _previous_handle_mark; }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
319 HandleMark(); // see handles_inline.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
320 HandleMark(Thread* thread) { initialize(thread); }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 ~HandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Functions used by HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // called in the constructor of HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void push();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // called in the destructor of HandleMarkCleaner
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void pop_and_restore();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 };
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 //------------------------------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // A NoHandleMark stack object will verify that no handles are allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // in its scope. Enabled in debug mode only.
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 class NoHandleMark: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
336 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
337 NoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 ~NoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
339 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
340 NoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
341 ~NoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
342 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
343 };
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 class ResetNoHandleMark: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 int _no_handle_mark_nesting;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
349 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
350 ResetNoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 ~ResetNoHandleMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
352 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
353 ResetNoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
354 ~ResetNoHandleMark() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
355 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
356 };