Mercurial > hg > truffle
comparison src/share/vm/runtime/handles.hpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | d2a62e0f25eb |
children | bdb5f8c9978b |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
24 | 24 |
25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP | 25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP |
26 #define SHARE_VM_RUNTIME_HANDLES_HPP | 26 #define SHARE_VM_RUNTIME_HANDLES_HPP |
27 | 27 |
28 #include "oops/klass.hpp" | 28 #include "oops/klass.hpp" |
29 #include "oops/klassOop.hpp" | |
30 #include "utilities/top.hpp" | |
31 | 29 |
32 //------------------------------------------------------------------------------------------------------------------------ | 30 //------------------------------------------------------------------------------------------------------------------------ |
33 // In order to preserve oops during garbage collection, they should be | 31 // In order to preserve oops during garbage collection, they should be |
34 // allocated and passed around via Handles within the VM. A handle is | 32 // allocated and passed around via Handles within the VM. A handle is |
35 // simply an extra indirection allocated in a thread local handle area. | 33 // simply an extra indirection allocated in a thread local handle area. |
54 // Handles are specialized for different oop types to provide extra type | 52 // Handles are specialized for different oop types to provide extra type |
55 // information and avoid unnecessary casting. For each oop type xxxOop | 53 // information and avoid unnecessary casting. For each oop type xxxOop |
56 // there is a corresponding handle called xxxHandle, e.g. | 54 // there is a corresponding handle called xxxHandle, e.g. |
57 // | 55 // |
58 // oop Handle | 56 // oop Handle |
59 // methodOop methodHandle | 57 // Method* methodHandle |
60 // instanceOop instanceHandle | 58 // instanceOop instanceHandle |
61 // | |
62 // For klassOops, it is often useful to model the Klass hierarchy in order | |
63 // to get access to the klass_part without casting. For each xxxKlass there | |
64 // is a corresponding handle called xxxKlassHandle, e.g. | |
65 // | |
66 // klassOop Klass KlassHandle | |
67 // klassOop methodKlass methodKlassHandle | |
68 // klassOop instanceKlass instanceKlassHandle | |
69 // | |
70 | 59 |
71 //------------------------------------------------------------------------------------------------------------------------ | 60 //------------------------------------------------------------------------------------------------------------------------ |
72 // Base class for all handles. Provides overloading of frequently | 61 // Base class for all handles. Provides overloading of frequently |
73 // used operators for ease of use. | 62 // used operators for ease of use. |
74 | 63 |
82 | 71 |
83 public: | 72 public: |
84 // Constructors | 73 // Constructors |
85 Handle() { _handle = NULL; } | 74 Handle() { _handle = NULL; } |
86 Handle(oop obj); | 75 Handle(oop obj); |
87 #ifndef ASSERT | |
88 Handle(Thread* thread, oop obj); | 76 Handle(Thread* thread, oop obj); |
89 #else | |
90 // Don't inline body with assert for current thread | |
91 Handle(Thread* thread, oop obj); | |
92 #endif // ASSERT | |
93 | 77 |
94 // General access | 78 // General access |
95 oop operator () () const { return obj(); } | 79 oop operator () () const { return obj(); } |
96 oop operator -> () const { return non_null_obj(); } | 80 oop operator -> () const { return non_null_obj(); } |
97 bool operator == (oop o) const { return obj() == o; } | 81 bool operator == (oop o) const { return obj() == o; } |
113 // since duplicates is only valid as long as original handle is alive. | 97 // since duplicates is only valid as long as original handle is alive. |
114 oop* raw_value() { return _handle; } | 98 oop* raw_value() { return _handle; } |
115 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; } | 99 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; } |
116 }; | 100 }; |
117 | 101 |
118 | |
119 //------------------------------------------------------------------------------------------------------------------------ | |
120 // Base class for Handles containing klassOops. Provides overloading of frequently | |
121 // used operators for ease of use and typed access to the Klass part. | |
122 class KlassHandle: public Handle { | |
123 protected: | |
124 klassOop obj() const { return (klassOop)Handle::obj(); } | |
125 klassOop non_null_obj() const { return (klassOop)Handle::non_null_obj(); } | |
126 Klass* as_klass() const { return non_null_obj()->klass_part(); } | |
127 | |
128 public: | |
129 // Constructors | |
130 KlassHandle () : Handle() {} | |
131 KlassHandle (oop obj) : Handle(obj) { | |
132 assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop"); | |
133 } | |
134 KlassHandle (Klass* kl) : Handle(kl ? kl->as_klassOop() : (klassOop)NULL) { | |
135 assert(SharedSkipVerify || is_null() || obj()->is_klass(), "not a klassOop"); | |
136 } | |
137 | |
138 // Faster versions passing Thread | |
139 KlassHandle (Thread* thread, oop obj) : Handle(thread, obj) { | |
140 assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop"); | |
141 } | |
142 KlassHandle (Thread *thread, Klass* kl) | |
143 : Handle(thread, kl ? kl->as_klassOop() : (klassOop)NULL) { | |
144 assert(is_null() || obj()->is_klass(), "not a klassOop"); | |
145 } | |
146 | |
147 // Direct interface, use very sparingly. | |
148 // Used by SystemDictionaryHandles to create handles on existing WKKs. | |
149 // The obj of such a klass handle may be null, because the handle is formed | |
150 // during system bootstrapping. | |
151 KlassHandle(klassOop *handle, bool dummy) : Handle((oop*)handle, dummy) { | |
152 assert(SharedSkipVerify || is_null() || obj() == NULL || obj()->is_klass(), "not a klassOop"); | |
153 } | |
154 | |
155 // General access | |
156 klassOop operator () () const { return obj(); } | |
157 Klass* operator -> () const { return as_klass(); } | |
158 }; | |
159 | |
160 | |
161 //------------------------------------------------------------------------------------------------------------------------ | |
162 // Specific Handles for different oop types | 102 // Specific Handles for different oop types |
163 #define DEF_HANDLE(type, is_a) \ | 103 #define DEF_HANDLE(type, is_a) \ |
164 class type##Handle; \ | |
165 class type##Handle: public Handle { \ | 104 class type##Handle: public Handle { \ |
166 protected: \ | 105 protected: \ |
167 type##Oop obj() const { return (type##Oop)Handle::obj(); } \ | 106 type##Oop obj() const { return (type##Oop)Handle::obj(); } \ |
168 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \ | 107 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \ |
169 \ | 108 \ |
176 } \ | 115 } \ |
177 type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \ | 116 type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \ |
178 assert(SharedSkipVerify || is_null() || ((oop)obj)->is_a(), "illegal type"); \ | 117 assert(SharedSkipVerify || is_null() || ((oop)obj)->is_a(), "illegal type"); \ |
179 } \ | 118 } \ |
180 \ | 119 \ |
181 /* Special constructor, use sparingly */ \ | |
182 type##Handle (type##Oop *handle, bool dummy) : Handle((oop*)handle, dummy) {} \ | |
183 \ | |
184 /* Operators for ease of use */ \ | 120 /* Operators for ease of use */ \ |
185 type##Oop operator () () const { return obj(); } \ | 121 type##Oop operator () () const { return obj(); } \ |
186 type##Oop operator -> () const { return non_null_obj(); } \ | 122 type##Oop operator -> () const { return non_null_obj(); } \ |
187 }; | 123 }; |
188 | 124 |
189 | 125 |
190 DEF_HANDLE(instance , is_instance ) | 126 DEF_HANDLE(instance , is_instance ) |
191 DEF_HANDLE(method , is_method ) | |
192 DEF_HANDLE(constMethod , is_constMethod ) | |
193 DEF_HANDLE(methodData , is_methodData ) | |
194 DEF_HANDLE(array , is_array ) | 127 DEF_HANDLE(array , is_array ) |
195 DEF_HANDLE(constantPool , is_constantPool ) | |
196 DEF_HANDLE(constantPoolCache, is_constantPoolCache) | |
197 DEF_HANDLE(objArray , is_objArray ) | 128 DEF_HANDLE(objArray , is_objArray ) |
198 DEF_HANDLE(typeArray , is_typeArray ) | 129 DEF_HANDLE(typeArray , is_typeArray ) |
199 | 130 |
200 //------------------------------------------------------------------------------------------------------------------------ | 131 //------------------------------------------------------------------------------------------------------------------------ |
201 // Specific KlassHandles for different Klass types | 132 |
202 | 133 // Metadata Handles. Unlike oop Handles these are needed to prevent metadata |
203 #define DEF_KLASS_HANDLE(type, is_a) \ | 134 // from being reclaimed by RedefineClasses. |
204 class type##Handle : public KlassHandle { \ | 135 |
136 // Specific Handles for different oop types | |
137 #define DEF_METADATA_HANDLE(name, type) \ | |
138 class name##Handle; \ | |
139 class name##Handle { \ | |
140 type* _value; \ | |
141 Thread* _thread; \ | |
142 protected: \ | |
143 type* obj() const { return _value; } \ | |
144 type* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } \ | |
145 \ | |
205 public: \ | 146 public: \ |
206 /* Constructors */ \ | 147 /* Constructors */ \ |
207 type##Handle () : KlassHandle() {} \ | 148 name##Handle () : _value(NULL), _thread(NULL) {} \ |
208 type##Handle (klassOop obj) : KlassHandle(obj) { \ | 149 name##Handle (type* obj); \ |
209 assert(SharedSkipVerify || is_null() || obj->klass_part()->is_a(), \ | 150 name##Handle (Thread* thread, type* obj); \ |
210 "illegal type"); \ | 151 \ |
211 } \ | 152 name##Handle (const name##Handle &h); \ |
212 type##Handle (Thread* thread, klassOop obj) : KlassHandle(thread, obj) { \ | 153 name##Handle& operator=(const name##Handle &s); \ |
213 assert(SharedSkipVerify || is_null() || obj->klass_part()->is_a(), \ | 154 \ |
214 "illegal type"); \ | 155 /* Destructor */ \ |
215 } \ | 156 ~name##Handle (); \ |
216 \ | 157 void remove(); \ |
217 /* Access to klass part */ \ | 158 \ |
218 type* operator -> () const { return (type*)obj()->klass_part(); } \ | 159 /* Operators for ease of use */ \ |
219 \ | 160 type* operator () () const { return obj(); } \ |
220 static type##Handle cast(KlassHandle h) { return type##Handle(h()); } \ | 161 type* operator -> () const { return non_null_obj(); } \ |
221 \ | 162 \ |
163 bool operator == (type* o) const { return obj() == o; } \ | |
164 bool operator == (const name##Handle& h) const { return obj() == h.obj(); } \ | |
165 \ | |
166 /* Null checks */ \ | |
167 bool is_null() const { return _value == NULL; } \ | |
168 bool not_null() const { return _value != NULL; } \ | |
222 }; | 169 }; |
223 | 170 |
224 | 171 |
225 DEF_KLASS_HANDLE(instanceKlass , oop_is_instance_slow ) | 172 DEF_METADATA_HANDLE(method, Method) |
226 DEF_KLASS_HANDLE(methodKlass , oop_is_method ) | 173 DEF_METADATA_HANDLE(constantPool, ConstantPool) |
227 DEF_KLASS_HANDLE(constMethodKlass , oop_is_constMethod ) | 174 |
228 DEF_KLASS_HANDLE(klassKlass , oop_is_klass ) | 175 // Writing this class explicitly, since DEF_METADATA_HANDLE(klass) doesn't |
229 DEF_KLASS_HANDLE(arrayKlassKlass , oop_is_arrayKlass ) | 176 // provide the necessary Klass* <-> Klass* conversions. This Klass |
230 DEF_KLASS_HANDLE(objArrayKlassKlass , oop_is_objArrayKlass ) | 177 // could be removed when we don't have the Klass* typedef anymore. |
231 DEF_KLASS_HANDLE(typeArrayKlassKlass , oop_is_typeArrayKlass) | 178 class KlassHandle { |
232 DEF_KLASS_HANDLE(arrayKlass , oop_is_array ) | 179 Klass* _value; |
233 DEF_KLASS_HANDLE(typeArrayKlass , oop_is_typeArray_slow) | 180 protected: |
234 DEF_KLASS_HANDLE(objArrayKlass , oop_is_objArray_slow ) | 181 Klass* obj() const { return _value; } |
235 DEF_KLASS_HANDLE(constantPoolKlass , oop_is_constantPool ) | 182 Klass* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } |
236 DEF_KLASS_HANDLE(constantPoolCacheKlass, oop_is_constantPool ) | 183 |
184 public: | |
185 KlassHandle() : _value(NULL) {} | |
186 KlassHandle(const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; | |
187 KlassHandle(Thread* thread, const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; | |
188 | |
189 Klass* operator () () const { return obj(); } | |
190 Klass* operator -> () const { return non_null_obj(); } | |
191 | |
192 bool operator == (Klass* o) const { return obj() == o; } | |
193 bool operator == (const KlassHandle& h) const { return obj() == h.obj(); } | |
194 | |
195 bool is_null() const { return _value == NULL; } | |
196 bool not_null() const { return _value != NULL; } | |
197 }; | |
198 | |
199 class instanceKlassHandle : public KlassHandle { | |
200 public: | |
201 /* Constructors */ | |
202 instanceKlassHandle () : KlassHandle() {} | |
203 instanceKlassHandle (const Klass* k) : KlassHandle(k) { | |
204 assert(SharedSkipVerify || k == NULL || k->oop_is_instance(), | |
205 "illegal type"); | |
206 } | |
207 instanceKlassHandle (Thread* thread, const Klass* k) : KlassHandle(thread, k) { | |
208 assert(SharedSkipVerify || k == NULL || k->oop_is_instance(), | |
209 "illegal type"); | |
210 } | |
211 /* Access to klass part */ | |
212 InstanceKlass* operator () () const { return (InstanceKlass*)obj(); } | |
213 InstanceKlass* operator -> () const { return (InstanceKlass*)obj(); } | |
214 }; | |
237 | 215 |
238 | 216 |
239 //------------------------------------------------------------------------------------------------------------------------ | 217 //------------------------------------------------------------------------------------------------------------------------ |
240 // Thread local handle area | 218 // Thread local handle area |
241 class HandleArea: public Arena { | 219 class HandleArea: public Arena { |