author | ysuenaga |
Wed, 10 Aug 2016 21:02:14 -0400 | |
changeset 40356 | df5e8cabdf10 |
parent 29199 | db7ae483ecb2 |
child 46271 | 979ebd346ecf |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
25946
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_HANDLES_HPP |
26 |
#define SHARE_VM_RUNTIME_HANDLES_HPP |
|
27 |
||
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
28 |
#include "oops/oop.hpp" |
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
29 |
#include "oops/oopsHierarchy.hpp" |
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
30 |
|
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
31 |
class InstanceKlass; |
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
32 |
class Klass; |
7397 | 33 |
|
1 | 34 |
//------------------------------------------------------------------------------------------------------------------------ |
35 |
// In order to preserve oops during garbage collection, they should be |
|
36 |
// allocated and passed around via Handles within the VM. A handle is |
|
37 |
// simply an extra indirection allocated in a thread local handle area. |
|
38 |
// |
|
39 |
// A handle is a ValueObj, so it can be passed around as a value, can |
|
40 |
// be used as a parameter w/o using &-passing, and can be returned as a |
|
41 |
// return value. |
|
42 |
// |
|
43 |
// oop parameters and return types should be Handles whenever feasible. |
|
44 |
// |
|
45 |
// Handles are declared in a straight-forward manner, e.g. |
|
46 |
// |
|
47 |
// oop obj = ...; |
|
48 |
// Handle h1(obj); // allocate new handle |
|
49 |
// Handle h2(thread, obj); // faster allocation when current thread is known |
|
50 |
// Handle h3; // declare handle only, no allocation occurs |
|
51 |
// ... |
|
52 |
// h3 = h1; // make h3 refer to same indirection as h1 |
|
53 |
// oop obj2 = h2(); // get handle value |
|
54 |
// h1->print(); // invoking operation on oop |
|
55 |
// |
|
56 |
// Handles are specialized for different oop types to provide extra type |
|
57 |
// information and avoid unnecessary casting. For each oop type xxxOop |
|
58 |
// there is a corresponding handle called xxxHandle, e.g. |
|
59 |
// |
|
60 |
// oop Handle |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
61 |
// Method* methodHandle |
1 | 62 |
// instanceOop instanceHandle |
63 |
||
64 |
//------------------------------------------------------------------------------------------------------------------------ |
|
65 |
// Base class for all handles. Provides overloading of frequently |
|
66 |
// used operators for ease of use. |
|
67 |
||
68 |
class Handle VALUE_OBJ_CLASS_SPEC { |
|
69 |
private: |
|
70 |
oop* _handle; |
|
71 |
||
72 |
protected: |
|
73 |
oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; } |
|
74 |
oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; } |
|
75 |
||
76 |
public: |
|
77 |
// Constructors |
|
78 |
Handle() { _handle = NULL; } |
|
79 |
Handle(oop obj); |
|
80 |
Handle(Thread* thread, oop obj); |
|
81 |
||
82 |
// General access |
|
83 |
oop operator () () const { return obj(); } |
|
84 |
oop operator -> () const { return non_null_obj(); } |
|
85 |
bool operator == (oop o) const { return obj() == o; } |
|
86 |
bool operator == (const Handle& h) const { return obj() == h.obj(); } |
|
87 |
||
88 |
// Null checks |
|
89 |
bool is_null() const { return _handle == NULL; } |
|
90 |
bool not_null() const { return _handle != NULL; } |
|
91 |
||
92 |
// Debugging |
|
93 |
void print() { obj()->print(); } |
|
94 |
||
95 |
// Direct interface, use very sparingly. |
|
96 |
// Used by JavaCalls to quickly convert handles and to create handles static data structures. |
|
97 |
// Constructor takes a dummy argument to prevent unintentional type conversion in C++. |
|
98 |
Handle(oop *handle, bool dummy) { _handle = handle; } |
|
99 |
||
100 |
// Raw handle access. Allows easy duplication of Handles. This can be very unsafe |
|
101 |
// since duplicates is only valid as long as original handle is alive. |
|
102 |
oop* raw_value() { return _handle; } |
|
103 |
static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; } |
|
104 |
}; |
|
105 |
||
106 |
// Specific Handles for different oop types |
|
107 |
#define DEF_HANDLE(type, is_a) \ |
|
108 |
class type##Handle: public Handle { \ |
|
109 |
protected: \ |
|
110 |
type##Oop obj() const { return (type##Oop)Handle::obj(); } \ |
|
111 |
type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \ |
|
112 |
\ |
|
113 |
public: \ |
|
114 |
/* Constructors */ \ |
|
115 |
type##Handle () : Handle() {} \ |
|
116 |
type##Handle (type##Oop obj) : Handle((oop)obj) { \ |
|
14078 | 117 |
assert(is_null() || ((oop)obj)->is_a(), \ |
1 | 118 |
"illegal type"); \ |
119 |
} \ |
|
120 |
type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \ |
|
14078 | 121 |
assert(is_null() || ((oop)obj)->is_a(), "illegal type"); \ |
1 | 122 |
} \ |
123 |
\ |
|
124 |
/* Operators for ease of use */ \ |
|
125 |
type##Oop operator () () const { return obj(); } \ |
|
126 |
type##Oop operator -> () const { return non_null_obj(); } \ |
|
127 |
}; |
|
128 |
||
129 |
||
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
25946
diff
changeset
|
130 |
DEF_HANDLE(instance , is_instance_noinline ) |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
25946
diff
changeset
|
131 |
DEF_HANDLE(array , is_array_noinline ) |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
25946
diff
changeset
|
132 |
DEF_HANDLE(objArray , is_objArray_noinline ) |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
25946
diff
changeset
|
133 |
DEF_HANDLE(typeArray , is_typeArray_noinline ) |
1 | 134 |
|
135 |
//------------------------------------------------------------------------------------------------------------------------ |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
136 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
137 |
// Metadata Handles. Unlike oop Handles these are needed to prevent metadata |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
138 |
// from being reclaimed by RedefineClasses. |
1 | 139 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
140 |
// Specific Handles for different oop types |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
141 |
#define DEF_METADATA_HANDLE(name, type) \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
142 |
class name##Handle; \ |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
19696
diff
changeset
|
143 |
class name##Handle : public StackObj { \ |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
144 |
type* _value; \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
145 |
Thread* _thread; \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
146 |
protected: \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
147 |
type* obj() const { return _value; } \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
148 |
type* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
149 |
\ |
1 | 150 |
public: \ |
151 |
/* Constructors */ \ |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
152 |
name##Handle () : _value(NULL), _thread(NULL) {} \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
153 |
name##Handle (type* obj); \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
154 |
name##Handle (Thread* thread, type* obj); \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
155 |
\ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
156 |
name##Handle (const name##Handle &h); \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
157 |
name##Handle& operator=(const name##Handle &s); \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
158 |
\ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
159 |
/* Destructor */ \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
160 |
~name##Handle (); \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
161 |
void remove(); \ |
1 | 162 |
\ |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
163 |
/* Operators for ease of use */ \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
164 |
type* operator () () const { return obj(); } \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
165 |
type* operator -> () const { return non_null_obj(); } \ |
1 | 166 |
\ |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
167 |
bool operator == (type* o) const { return obj() == o; } \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
168 |
bool operator == (const name##Handle& h) const { return obj() == h.obj(); } \ |
1 | 169 |
\ |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
170 |
/* Null checks */ \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
171 |
bool is_null() const { return _value == NULL; } \ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
172 |
bool not_null() const { return _value != NULL; } \ |
1 | 173 |
}; |
174 |
||
175 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
176 |
DEF_METADATA_HANDLE(method, Method) |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
177 |
DEF_METADATA_HANDLE(constantPool, ConstantPool) |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
178 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
179 |
// Writing this class explicitly, since DEF_METADATA_HANDLE(klass) doesn't |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
180 |
// provide the necessary Klass* <-> Klass* conversions. This Klass |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
181 |
// could be removed when we don't have the Klass* typedef anymore. |
20059
c26474fd5ac0
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents:
19696
diff
changeset
|
182 |
class KlassHandle : public StackObj { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
183 |
Klass* _value; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
184 |
protected: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
185 |
Klass* obj() const { return _value; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
186 |
Klass* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
187 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
188 |
public: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
189 |
KlassHandle() : _value(NULL) {} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
190 |
KlassHandle(const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
191 |
KlassHandle(Thread* thread, const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
192 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
193 |
Klass* operator () () const { return obj(); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
194 |
Klass* operator -> () const { return non_null_obj(); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
195 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
196 |
bool operator == (Klass* o) const { return obj() == o; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
197 |
bool operator == (const KlassHandle& h) const { return obj() == h.obj(); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
198 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
199 |
bool is_null() const { return _value == NULL; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
200 |
bool not_null() const { return _value != NULL; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
201 |
}; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
202 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
203 |
class instanceKlassHandle : public KlassHandle { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
204 |
public: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
205 |
/* Constructors */ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
206 |
instanceKlassHandle () : KlassHandle() {} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
207 |
instanceKlassHandle (const Klass* k) : KlassHandle(k) { |
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
208 |
assert(k == NULL || is_instanceKlass(k), "illegal type"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
209 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
210 |
instanceKlassHandle (Thread* thread, const Klass* k) : KlassHandle(thread, k) { |
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
211 |
assert(k == NULL || is_instanceKlass(k), "illegal type"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
212 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
213 |
/* Access to klass part */ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
214 |
InstanceKlass* operator () () const { return (InstanceKlass*)obj(); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
215 |
InstanceKlass* operator -> () const { return (InstanceKlass*)obj(); } |
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
216 |
|
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
29081
diff
changeset
|
217 |
debug_only(bool is_instanceKlass(const Klass* k)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
218 |
}; |
1 | 219 |
|
220 |
||
221 |
//------------------------------------------------------------------------------------------------------------------------ |
|
222 |
// Thread local handle area |
|
223 |
class HandleArea: public Arena { |
|
224 |
friend class HandleMark; |
|
225 |
friend class NoHandleMark; |
|
226 |
friend class ResetNoHandleMark; |
|
227 |
#ifdef ASSERT |
|
228 |
int _handle_mark_nesting; |
|
229 |
int _no_handle_mark_nesting; |
|
230 |
#endif |
|
231 |
HandleArea* _prev; // link to outer (older) area |
|
232 |
public: |
|
233 |
// Constructor |
|
25946 | 234 |
HandleArea(HandleArea* prev) : Arena(mtThread, Chunk::tiny_size) { |
1 | 235 |
debug_only(_handle_mark_nesting = 0); |
236 |
debug_only(_no_handle_mark_nesting = 0); |
|
237 |
_prev = prev; |
|
238 |
} |
|
239 |
||
240 |
// Handle allocation |
|
241 |
private: |
|
242 |
oop* real_allocate_handle(oop obj) { |
|
243 |
#ifdef ASSERT |
|
244 |
oop* handle = (oop*) (UseMallocOnly ? internal_malloc_4(oopSize) : Amalloc_4(oopSize)); |
|
245 |
#else |
|
246 |
oop* handle = (oop*) Amalloc_4(oopSize); |
|
247 |
#endif |
|
248 |
*handle = obj; |
|
249 |
return handle; |
|
250 |
} |
|
251 |
public: |
|
252 |
#ifdef ASSERT |
|
253 |
oop* allocate_handle(oop obj); |
|
254 |
#else |
|
255 |
oop* allocate_handle(oop obj) { return real_allocate_handle(obj); } |
|
256 |
#endif |
|
257 |
||
258 |
// Garbage collection support |
|
259 |
void oops_do(OopClosure* f); |
|
260 |
||
261 |
// Number of handles in use |
|
262 |
size_t used() const { return Arena::used() / oopSize; } |
|
263 |
||
264 |
debug_only(bool no_handle_mark_active() { return _no_handle_mark_nesting > 0; }) |
|
265 |
}; |
|
266 |
||
267 |
||
268 |
//------------------------------------------------------------------------------------------------------------------------ |
|
269 |
// Handles are allocated in a (growable) thread local handle area. Deallocation |
|
270 |
// is managed using a HandleMark. It should normally not be necessary to use |
|
271 |
// HandleMarks manually. |
|
272 |
// |
|
273 |
// A HandleMark constructor will record the current handle area top, and the |
|
22551 | 274 |
// destructor will reset the top, destroying all handles allocated in between. |
1 | 275 |
// The following code will therefore NOT work: |
276 |
// |
|
277 |
// Handle h; |
|
278 |
// { |
|
279 |
// HandleMark hm; |
|
280 |
// h = Handle(obj); |
|
281 |
// } |
|
282 |
// h()->print(); // WRONG, h destroyed by HandleMark destructor. |
|
283 |
// |
|
284 |
// If h has to be preserved, it can be converted to an oop or a local JNI handle |
|
285 |
// across the HandleMark boundary. |
|
286 |
||
17031 | 287 |
// The base class of HandleMark should have been StackObj but we also heap allocate |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
288 |
// a HandleMark when a thread is created. The operator new is for this special case. |
1 | 289 |
|
17031 | 290 |
class HandleMark { |
1 | 291 |
private: |
292 |
Thread *_thread; // thread that owns this mark |
|
293 |
HandleArea *_area; // saved handle area |
|
294 |
Chunk *_chunk; // saved arena chunk |
|
295 |
char *_hwm, *_max; // saved arena info |
|
13195 | 296 |
size_t _size_in_bytes; // size of handle area |
1 | 297 |
// Link to previous active HandleMark in thread |
298 |
HandleMark* _previous_handle_mark; |
|
299 |
||
17031 | 300 |
void initialize(Thread* thread); // common code for constructors |
1 | 301 |
void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; } |
302 |
HandleMark* previous_handle_mark() const { return _previous_handle_mark; } |
|
303 |
||
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
304 |
size_t size_in_bytes() const { return _size_in_bytes; } |
1 | 305 |
public: |
306 |
HandleMark(); // see handles_inline.hpp |
|
307 |
HandleMark(Thread* thread) { initialize(thread); } |
|
308 |
~HandleMark(); |
|
309 |
||
310 |
// Functions used by HandleMarkCleaner |
|
311 |
// called in the constructor of HandleMarkCleaner |
|
312 |
void push(); |
|
313 |
// called in the destructor of HandleMarkCleaner |
|
314 |
void pop_and_restore(); |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
315 |
// overloaded operators |
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
316 |
void* operator new(size_t size) throw(); |
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18686
diff
changeset
|
317 |
void* operator new [](size_t size) throw(); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
318 |
void operator delete(void* p); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
319 |
void operator delete[](void* p); |
1 | 320 |
}; |
321 |
||
322 |
//------------------------------------------------------------------------------------------------------------------------ |
|
323 |
// A NoHandleMark stack object will verify that no handles are allocated |
|
324 |
// in its scope. Enabled in debug mode only. |
|
325 |
||
326 |
class NoHandleMark: public StackObj { |
|
327 |
public: |
|
328 |
#ifdef ASSERT |
|
329 |
NoHandleMark(); |
|
330 |
~NoHandleMark(); |
|
331 |
#else |
|
332 |
NoHandleMark() {} |
|
333 |
~NoHandleMark() {} |
|
334 |
#endif |
|
335 |
}; |
|
336 |
||
337 |
||
338 |
class ResetNoHandleMark: public StackObj { |
|
339 |
int _no_handle_mark_nesting; |
|
340 |
public: |
|
341 |
#ifdef ASSERT |
|
342 |
ResetNoHandleMark(); |
|
343 |
~ResetNoHandleMark(); |
|
344 |
#else |
|
345 |
ResetNoHandleMark() {} |
|
346 |
~ResetNoHandleMark() {} |
|
347 |
#endif |
|
348 |
}; |
|
7397 | 349 |
|
350 |
#endif // SHARE_VM_RUNTIME_HANDLES_HPP |