Mercurial > hg > truffle
annotate src/share/vm/ci/ciObjectFactory.cpp @ 2645:b2c1e959be46
Clean up around BlockBegin / StdEntry.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 11 May 2011 14:34:29 +0200 |
parents | 0654ee04b214 |
children | 0e8a2a629afb |
rev | line source |
---|---|
0 | 1 /* |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2177
diff
changeset
|
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
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:
1507
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciCPCache.hpp" | |
27 #include "ci/ciCallSite.hpp" | |
28 #include "ci/ciInstance.hpp" | |
29 #include "ci/ciInstanceKlass.hpp" | |
30 #include "ci/ciInstanceKlassKlass.hpp" | |
31 #include "ci/ciMethod.hpp" | |
32 #include "ci/ciMethodData.hpp" | |
33 #include "ci/ciMethodHandle.hpp" | |
34 #include "ci/ciMethodKlass.hpp" | |
35 #include "ci/ciNullObject.hpp" | |
36 #include "ci/ciObjArray.hpp" | |
37 #include "ci/ciObjArrayKlass.hpp" | |
38 #include "ci/ciObjArrayKlassKlass.hpp" | |
39 #include "ci/ciObjectFactory.hpp" | |
40 #include "ci/ciSymbol.hpp" | |
41 #include "ci/ciTypeArray.hpp" | |
42 #include "ci/ciTypeArrayKlass.hpp" | |
43 #include "ci/ciTypeArrayKlassKlass.hpp" | |
44 #include "ci/ciUtilities.hpp" | |
45 #include "classfile/systemDictionary.hpp" | |
46 #include "gc_interface/collectedHeap.inline.hpp" | |
47 #include "memory/allocation.inline.hpp" | |
48 #include "oops/oop.inline.hpp" | |
49 #include "oops/oop.inline2.hpp" | |
50 #include "runtime/fieldType.hpp" | |
0 | 51 |
52 // ciObjectFactory | |
53 // | |
54 // This class handles requests for the creation of new instances | |
55 // of ciObject and its subclasses. It contains a caching mechanism | |
56 // which ensures that for each oop, at most one ciObject is created. | |
57 // This invariant allows more efficient implementation of ciObject. | |
58 // | |
59 // Implementation note: the oop->ciObject mapping is represented as | |
60 // a table stored in an array. Even though objects are moved | |
61 // by the garbage collector, the compactor preserves their relative | |
62 // order; address comparison of oops (in perm space) is safe so long | |
63 // as we prohibit GC during our comparisons. We currently use binary | |
64 // search to find the oop in the table, and inserting a new oop | |
65 // into the table may be costly. If this cost ends up being | |
66 // problematic the underlying data structure can be switched to some | |
67 // sort of balanced binary tree. | |
68 | |
69 GrowableArray<ciObject*>* ciObjectFactory::_shared_ci_objects = NULL; | |
70 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; | |
71 int ciObjectFactory::_shared_ident_limit = 0; | |
72 volatile bool ciObjectFactory::_initialized = false; | |
73 | |
74 | |
75 // ------------------------------------------------------------------ | |
76 // ciObjectFactory::ciObjectFactory | |
77 ciObjectFactory::ciObjectFactory(Arena* arena, | |
78 int expected_size) { | |
79 | |
80 for (int i = 0; i < NON_PERM_BUCKETS; i++) { | |
81 _non_perm_bucket[i] = NULL; | |
82 } | |
83 _non_perm_count = 0; | |
84 | |
85 _next_ident = _shared_ident_limit; | |
86 _arena = arena; | |
87 _ci_objects = new (arena) GrowableArray<ciObject*>(arena, expected_size, 0, NULL); | |
88 | |
89 // If the shared ci objects exist append them to this factory's objects | |
90 | |
91 if (_shared_ci_objects != NULL) { | |
92 _ci_objects->appendAll(_shared_ci_objects); | |
93 } | |
94 | |
95 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL); | |
96 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL); | |
1602 | 97 _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL); |
0 | 98 _return_addresses = |
99 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
100 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
101 _symbols = new (arena) GrowableArray<ciSymbol*>(arena, 100, 0, NULL); |
0 | 102 } |
103 | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
104 void ciObjectFactory::cleanup() { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
105 int start = 0; |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
106 if (_shared_ci_objects != NULL) start = _shared_ci_objects->length(); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
107 for (int i = start; i < _ci_objects->length(); ++i) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
108 _ci_objects->at(i)->cleanup(); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
109 } |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
110 } |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
111 |
0 | 112 // ------------------------------------------------------------------ |
113 // ciObjectFactory::ciObjectFactory | |
114 void ciObjectFactory::initialize() { | |
115 ASSERT_IN_VM; | |
116 JavaThread* thread = JavaThread::current(); | |
117 HandleMark handle_mark(thread); | |
118 | |
119 // This Arena is long lived and exists in the resource mark of the | |
120 // compiler thread that initializes the initial ciObjectFactory which | |
121 // creates the shared ciObjects that all later ciObjectFactories use. | |
122 Arena* arena = new Arena(); | |
123 ciEnv initial(arena); | |
124 ciEnv* env = ciEnv::current(); | |
125 env->_factory->init_shared_objects(); | |
126 | |
127 _initialized = true; | |
128 | |
129 } | |
130 | |
131 void ciObjectFactory::init_shared_objects() { | |
132 | |
133 _next_ident = 1; // start numbering CI objects at 1 | |
134 | |
135 { | |
136 // Create the shared symbols, but not in _shared_ci_objects. | |
137 int i; | |
138 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
139 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
140 assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
141 ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i); |
0 | 142 init_ident_of(sym); |
143 _shared_ci_symbols[i] = sym; | |
144 } | |
145 #ifdef ASSERT | |
146 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
147 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i); |
0 | 148 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
149 assert(sym->get_symbol() == vmsym, "oop must match"); |
0 | 150 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
151 assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check"); |
0 | 152 #endif |
153 } | |
154 | |
155 _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL); | |
156 | |
157 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { | |
158 BasicType t = (BasicType)i; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
159 if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP) { |
0 | 160 ciType::_basic_types[t] = new (_arena) ciType(t); |
161 init_ident_of(ciType::_basic_types[t]); | |
162 } | |
163 } | |
164 | |
165 ciEnv::_null_object_instance = new (_arena) ciNullObject(); | |
166 init_ident_of(ciEnv::_null_object_instance); | |
167 ciEnv::_method_klass_instance = | |
168 get(Universe::methodKlassObj())->as_method_klass(); | |
169 ciEnv::_klass_klass_instance = | |
170 get(Universe::klassKlassObj())->as_klass_klass(); | |
171 ciEnv::_instance_klass_klass_instance = | |
172 get(Universe::instanceKlassKlassObj()) | |
173 ->as_instance_klass_klass(); | |
174 ciEnv::_type_array_klass_klass_instance = | |
175 get(Universe::typeArrayKlassKlassObj()) | |
176 ->as_type_array_klass_klass(); | |
177 ciEnv::_obj_array_klass_klass_instance = | |
178 get(Universe::objArrayKlassKlassObj()) | |
179 ->as_obj_array_klass_klass(); | |
1142 | 180 |
181 #define WK_KLASS_DEFN(name, ignore_s, opt) \ | |
182 if (SystemDictionary::name() != NULL) \ | |
183 ciEnv::_##name = get(SystemDictionary::name())->as_instance_klass(); | |
184 | |
185 WK_KLASSES_DO(WK_KLASS_DEFN) | |
186 #undef WK_KLASS_DEFN | |
0 | 187 |
188 for (int len = -1; len != _ci_objects->length(); ) { | |
189 len = _ci_objects->length(); | |
190 for (int i2 = 0; i2 < len; i2++) { | |
191 ciObject* obj = _ci_objects->at(i2); | |
192 if (obj->is_loaded() && obj->is_instance_klass()) { | |
193 obj->as_instance_klass()->compute_nonstatic_fields(); | |
194 } | |
195 } | |
196 } | |
197 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
198 ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol()); |
0 | 199 // Create dummy instanceKlass and objArrayKlass object and assign them idents |
200 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); | |
201 init_ident_of(ciEnv::_unloaded_ciinstance_klass); | |
202 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); | |
203 init_ident_of(ciEnv::_unloaded_ciobjarrayklass); | |
204 assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking"); | |
205 | |
206 get(Universe::boolArrayKlassObj()); | |
207 get(Universe::charArrayKlassObj()); | |
208 get(Universe::singleArrayKlassObj()); | |
209 get(Universe::doubleArrayKlassObj()); | |
210 get(Universe::byteArrayKlassObj()); | |
211 get(Universe::shortArrayKlassObj()); | |
212 get(Universe::intArrayKlassObj()); | |
213 get(Universe::longArrayKlassObj()); | |
214 | |
215 | |
216 | |
217 assert(_non_perm_count == 0, "no shared non-perm objects"); | |
218 | |
219 // The shared_ident_limit is the first ident number that will | |
220 // be used for non-shared objects. That is, numbers less than | |
221 // this limit are permanently assigned to shared CI objects, | |
222 // while the higher numbers are recycled afresh by each new ciEnv. | |
223 | |
224 _shared_ident_limit = _next_ident; | |
225 _shared_ci_objects = _ci_objects; | |
226 } | |
227 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
228 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
229 ciSymbol* ciObjectFactory::get_symbol(Symbol* key) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
230 vmSymbols::SID sid = vmSymbols::find_sid(key); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
231 if (sid != vmSymbols::NO_SID) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
232 // do not pollute the main cache with it |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
233 return vm_symbol_at(sid); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
234 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
235 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
236 assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, ""); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
237 ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
238 _symbols->push(s); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
239 return s; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
240 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
241 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
242 // Decrement the refcount when done on symbols referenced by this compilation. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
243 void ciObjectFactory::remove_symbols() { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
244 for (int i = 0; i < _symbols->length(); i++) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
245 ciSymbol* s = _symbols->at(i); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
246 s->get_symbol()->decrement_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
247 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
248 // Since _symbols is resource allocated we're not allowed to delete it |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
249 // but it'll go away just the same. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
250 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
251 |
0 | 252 // ------------------------------------------------------------------ |
253 // ciObjectFactory::get | |
254 // | |
255 // Get the ciObject corresponding to some oop. If the ciObject has | |
256 // already been created, it is returned. Otherwise, a new ciObject | |
257 // is created. | |
258 ciObject* ciObjectFactory::get(oop key) { | |
259 ASSERT_IN_VM; | |
260 | |
261 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
262 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
263 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
264 for (int j = 0; j< _ci_objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
265 oop o = _ci_objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
266 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
267 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
268 } |
0 | 269 } |
270 #endif // ASSERT | |
271 int len = _ci_objects->length(); | |
272 int index = find(key, _ci_objects); | |
273 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
274 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
275 for (int i=0; i<_ci_objects->length(); i++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
276 if (_ci_objects->at(i)->get_oop() == key) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
277 assert(index == i, " bad lookup"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
278 } |
0 | 279 } |
280 } | |
281 #endif | |
282 if (!is_found_at(index, key, _ci_objects)) { | |
283 // Check in the non-perm area before putting it in the list. | |
284 NonPermObject* &bucket = find_non_perm(key); | |
285 if (bucket != NULL) { | |
286 return bucket->object(); | |
287 } | |
288 | |
289 // The ciObject does not yet exist. Create it and insert it | |
290 // into the cache. | |
291 Handle keyHandle(key); | |
292 ciObject* new_object = create_new_object(keyHandle()); | |
293 assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); | |
294 init_ident_of(new_object); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
909
diff
changeset
|
295 if (!new_object->is_perm()) { |
0 | 296 // Not a perm-space object. |
297 insert_non_perm(bucket, keyHandle(), new_object); | |
298 return new_object; | |
299 } | |
300 if (len != _ci_objects->length()) { | |
301 // creating the new object has recursively entered new objects | |
302 // into the table. We need to recompute our index. | |
303 index = find(keyHandle(), _ci_objects); | |
304 } | |
305 assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert"); | |
306 insert(index, new_object, _ci_objects); | |
307 return new_object; | |
308 } | |
309 return _ci_objects->at(index); | |
310 } | |
311 | |
312 // ------------------------------------------------------------------ | |
313 // ciObjectFactory::create_new_object | |
314 // | |
315 // Create a new ciObject from an oop. | |
316 // | |
317 // Implementation note: this functionality could be virtual behavior | |
318 // of the oop itself. For now, we explicitly marshal the object. | |
319 ciObject* ciObjectFactory::create_new_object(oop o) { | |
320 EXCEPTION_CONTEXT; | |
321 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
322 if (o->is_klass()) { |
0 | 323 KlassHandle h_k(THREAD, (klassOop)o); |
324 Klass* k = ((klassOop)o)->klass_part(); | |
325 if (k->oop_is_instance()) { | |
326 return new (arena()) ciInstanceKlass(h_k); | |
327 } else if (k->oop_is_objArray()) { | |
328 return new (arena()) ciObjArrayKlass(h_k); | |
329 } else if (k->oop_is_typeArray()) { | |
330 return new (arena()) ciTypeArrayKlass(h_k); | |
331 } else if (k->oop_is_method()) { | |
332 return new (arena()) ciMethodKlass(h_k); | |
333 } else if (k->oop_is_klass()) { | |
334 if (k->oop_is_objArrayKlass()) { | |
335 return new (arena()) ciObjArrayKlassKlass(h_k); | |
336 } else if (k->oop_is_typeArrayKlass()) { | |
337 return new (arena()) ciTypeArrayKlassKlass(h_k); | |
338 } else if (k->oop_is_instanceKlass()) { | |
339 return new (arena()) ciInstanceKlassKlass(h_k); | |
340 } else { | |
341 assert(o == Universe::klassKlassObj(), "bad klassKlass"); | |
342 return new (arena()) ciKlassKlass(h_k); | |
343 } | |
344 } | |
345 } else if (o->is_method()) { | |
346 methodHandle h_m(THREAD, (methodOop)o); | |
347 return new (arena()) ciMethod(h_m); | |
348 } else if (o->is_methodData()) { | |
349 methodDataHandle h_md(THREAD, (methodDataOop)o); | |
350 return new (arena()) ciMethodData(h_md); | |
351 } else if (o->is_instance()) { | |
352 instanceHandle h_i(THREAD, (instanceOop)o); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2177
diff
changeset
|
353 if (java_lang_invoke_CallSite::is_instance(o)) |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
354 return new (arena()) ciCallSite(h_i); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2177
diff
changeset
|
355 else if (java_lang_invoke_MethodHandle::is_instance(o)) |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
356 return new (arena()) ciMethodHandle(h_i); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
357 else |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
358 return new (arena()) ciInstance(h_i); |
0 | 359 } else if (o->is_objArray()) { |
360 objArrayHandle h_oa(THREAD, (objArrayOop)o); | |
361 return new (arena()) ciObjArray(h_oa); | |
362 } else if (o->is_typeArray()) { | |
363 typeArrayHandle h_ta(THREAD, (typeArrayOop)o); | |
364 return new (arena()) ciTypeArray(h_ta); | |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
365 } else if (o->is_constantPoolCache()) { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
366 constantPoolCacheHandle h_cpc(THREAD, (constantPoolCacheOop) o); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
367 return new (arena()) ciCPCache(h_cpc); |
0 | 368 } |
369 | |
370 // The oop is of some type not supported by the compiler interface. | |
371 ShouldNotReachHere(); | |
372 return NULL; | |
373 } | |
374 | |
375 //------------------------------------------------------------------ | |
376 // ciObjectFactory::get_unloaded_method | |
377 // | |
378 // Get the ciMethod representing an unloaded/unfound method. | |
379 // | |
380 // Implementation note: unloaded methods are currently stored in | |
381 // an unordered array, requiring a linear-time lookup for each | |
382 // unloaded method. This may need to change. | |
383 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, | |
384 ciSymbol* name, | |
385 ciSymbol* signature) { | |
386 for (int i=0; i<_unloaded_methods->length(); i++) { | |
387 ciMethod* entry = _unloaded_methods->at(i); | |
388 if (entry->holder()->equals(holder) && | |
389 entry->name()->equals(name) && | |
390 entry->signature()->as_symbol()->equals(signature)) { | |
391 // We've found a match. | |
392 return entry; | |
393 } | |
394 } | |
395 | |
396 // This is a new unloaded method. Create it and stick it in | |
397 // the cache. | |
398 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature); | |
399 | |
400 init_ident_of(new_method); | |
401 _unloaded_methods->append(new_method); | |
402 | |
403 return new_method; | |
404 } | |
405 | |
406 //------------------------------------------------------------------ | |
407 // ciObjectFactory::get_unloaded_klass | |
408 // | |
409 // Get a ciKlass representing an unloaded klass. | |
410 // | |
411 // Implementation note: unloaded klasses are currently stored in | |
412 // an unordered array, requiring a linear-time lookup for each | |
413 // unloaded klass. This may need to change. | |
414 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, | |
415 ciSymbol* name, | |
416 bool create_if_not_found) { | |
417 EXCEPTION_CONTEXT; | |
418 oop loader = NULL; | |
419 oop domain = NULL; | |
420 if (accessing_klass != NULL) { | |
421 loader = accessing_klass->loader(); | |
422 domain = accessing_klass->protection_domain(); | |
423 } | |
424 for (int i=0; i<_unloaded_klasses->length(); i++) { | |
425 ciKlass* entry = _unloaded_klasses->at(i); | |
426 if (entry->name()->equals(name) && | |
427 entry->loader() == loader && | |
428 entry->protection_domain() == domain) { | |
429 // We've found a match. | |
430 return entry; | |
431 } | |
432 } | |
433 | |
434 if (!create_if_not_found) | |
435 return NULL; | |
436 | |
437 // This is a new unloaded klass. Create it and stick it in | |
438 // the cache. | |
439 ciKlass* new_klass = NULL; | |
440 | |
441 // Two cases: this is an unloaded objArrayKlass or an | |
442 // unloaded instanceKlass. Deal with both. | |
443 if (name->byte_at(0) == '[') { | |
444 // Decompose the name.' | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
445 FieldArrayInfo fd; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
446 BasicType element_type = FieldType::get_array_info(name->get_symbol(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
447 fd, THREAD); |
0 | 448 if (HAS_PENDING_EXCEPTION) { |
449 CLEAR_PENDING_EXCEPTION; | |
450 CURRENT_THREAD_ENV->record_out_of_memory_failure(); | |
451 return ciEnv::_unloaded_ciobjarrayklass; | |
452 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
453 int dimension = fd.dimension(); |
0 | 454 assert(element_type != T_ARRAY, "unsuccessful decomposition"); |
455 ciKlass* element_klass = NULL; | |
456 if (element_type == T_OBJECT) { | |
457 ciEnv *env = CURRENT_THREAD_ENV; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
458 ciSymbol* ci_name = env->get_symbol(fd.object_key()); |
0 | 459 element_klass = |
460 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); | |
461 } else { | |
462 assert(dimension > 1, "one dimensional type arrays are always loaded."); | |
463 | |
464 // The type array itself takes care of one of the dimensions. | |
465 dimension--; | |
466 | |
467 // The element klass is a typeArrayKlass. | |
468 element_klass = ciTypeArrayKlass::make(element_type); | |
469 } | |
470 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); | |
471 } else { | |
472 jobject loader_handle = NULL; | |
473 jobject domain_handle = NULL; | |
474 if (accessing_klass != NULL) { | |
475 loader_handle = accessing_klass->loader_handle(); | |
476 domain_handle = accessing_klass->protection_domain_handle(); | |
477 } | |
478 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); | |
479 } | |
480 init_ident_of(new_klass); | |
481 _unloaded_klasses->append(new_klass); | |
482 | |
483 return new_klass; | |
484 } | |
485 | |
1602 | 486 |
487 //------------------------------------------------------------------ | |
488 // ciObjectFactory::get_unloaded_instance | |
489 // | |
490 // Get a ciInstance representing an as-yet undetermined instance of a given class. | |
491 // | |
492 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) { | |
493 for (int i=0; i<_unloaded_instances->length(); i++) { | |
494 ciInstance* entry = _unloaded_instances->at(i); | |
495 if (entry->klass()->equals(instance_klass)) { | |
496 // We've found a match. | |
497 return entry; | |
498 } | |
499 } | |
500 | |
501 // This is a new unloaded instance. Create it and stick it in | |
502 // the cache. | |
503 ciInstance* new_instance = new (arena()) ciInstance(instance_klass); | |
504 | |
505 init_ident_of(new_instance); | |
506 _unloaded_instances->append(new_instance); | |
507 | |
508 // make sure it looks the way we want: | |
509 assert(!new_instance->is_loaded(), ""); | |
510 assert(new_instance->klass() == instance_klass, ""); | |
511 | |
512 return new_instance; | |
513 } | |
514 | |
515 | |
516 //------------------------------------------------------------------ | |
517 // ciObjectFactory::get_unloaded_klass_mirror | |
518 // | |
519 // Get a ciInstance representing an unresolved klass mirror. | |
520 // | |
521 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
522 ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) { | |
523 assert(ciEnv::_Class_klass != NULL, ""); | |
524 return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass()); | |
525 } | |
526 | |
527 //------------------------------------------------------------------ | |
528 // ciObjectFactory::get_unloaded_method_handle_constant | |
529 // | |
530 // Get a ciInstance representing an unresolved method handle constant. | |
531 // | |
532 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
533 ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder, | |
534 ciSymbol* name, | |
535 ciSymbol* signature, | |
536 int ref_kind) { | |
537 if (ciEnv::_MethodHandle_klass == NULL) return NULL; | |
538 return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass()); | |
539 } | |
540 | |
541 //------------------------------------------------------------------ | |
542 // ciObjectFactory::get_unloaded_method_type_constant | |
543 // | |
544 // Get a ciInstance representing an unresolved method type constant. | |
545 // | |
546 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
547 ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) { | |
548 if (ciEnv::_MethodType_klass == NULL) return NULL; | |
549 return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass()); | |
550 } | |
551 | |
552 | |
553 | |
0 | 554 //------------------------------------------------------------------ |
555 // ciObjectFactory::get_empty_methodData | |
556 // | |
557 // Get the ciMethodData representing the methodData for a method with | |
558 // none. | |
559 ciMethodData* ciObjectFactory::get_empty_methodData() { | |
560 ciMethodData* new_methodData = new (arena()) ciMethodData(); | |
561 init_ident_of(new_methodData); | |
562 return new_methodData; | |
563 } | |
564 | |
565 //------------------------------------------------------------------ | |
566 // ciObjectFactory::get_return_address | |
567 // | |
568 // Get a ciReturnAddress for a specified bci. | |
569 ciReturnAddress* ciObjectFactory::get_return_address(int bci) { | |
570 for (int i=0; i<_return_addresses->length(); i++) { | |
571 ciReturnAddress* entry = _return_addresses->at(i); | |
572 if (entry->bci() == bci) { | |
573 // We've found a match. | |
574 return entry; | |
575 } | |
576 } | |
577 | |
578 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); | |
579 init_ident_of(new_ret_addr); | |
580 _return_addresses->append(new_ret_addr); | |
581 return new_ret_addr; | |
582 } | |
583 | |
584 // ------------------------------------------------------------------ | |
585 // ciObjectFactory::init_ident_of | |
586 void ciObjectFactory::init_ident_of(ciObject* obj) { | |
587 obj->set_ident(_next_ident++); | |
588 } | |
589 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
590 void ciObjectFactory::init_ident_of(ciSymbol* obj) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
591 obj->set_ident(_next_ident++); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
592 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
593 |
0 | 594 |
595 // ------------------------------------------------------------------ | |
596 // ciObjectFactory::find | |
597 // | |
598 // Use binary search to find the position of this oop in the cache. | |
599 // If there is no entry in the cache corresponding to this oop, return | |
600 // the position at which the oop should be inserted. | |
601 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) { | |
602 int min = 0; | |
603 int max = objects->length()-1; | |
604 | |
605 // print_contents(); | |
606 | |
607 while (max >= min) { | |
608 int mid = (max + min) / 2; | |
609 oop value = objects->at(mid)->get_oop(); | |
610 if (value < key) { | |
611 min = mid + 1; | |
612 } else if (value > key) { | |
613 max = mid - 1; | |
614 } else { | |
615 return mid; | |
616 } | |
617 } | |
618 return min; | |
619 } | |
620 | |
621 // ------------------------------------------------------------------ | |
622 // ciObjectFactory::is_found_at | |
623 // | |
624 // Verify that the binary seach found the given key. | |
625 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) { | |
626 return (index < objects->length() && | |
627 objects->at(index)->get_oop() == key); | |
628 } | |
629 | |
630 | |
631 // ------------------------------------------------------------------ | |
632 // ciObjectFactory::insert | |
633 // | |
634 // Insert a ciObject into the table at some index. | |
635 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) { | |
636 int len = objects->length(); | |
637 if (len == index) { | |
638 objects->append(obj); | |
639 } else { | |
640 objects->append(objects->at(len-1)); | |
641 int pos; | |
642 for (pos = len-2; pos >= index; pos--) { | |
643 objects->at_put(pos+1,objects->at(pos)); | |
644 } | |
645 objects->at_put(index, obj); | |
646 } | |
647 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
648 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
649 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
650 for (int j = 0; j< objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
651 oop o = objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
652 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
653 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
654 } |
0 | 655 } |
656 #endif // ASSERT | |
657 } | |
658 | |
659 static ciObjectFactory::NonPermObject* emptyBucket = NULL; | |
660 | |
661 // ------------------------------------------------------------------ | |
662 // ciObjectFactory::find_non_perm | |
663 // | |
664 // Use a small hash table, hashed on the klass of the key. | |
665 // If there is no entry in the cache corresponding to this oop, return | |
666 // the null tail of the bucket into which the oop should be inserted. | |
667 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { | |
668 // Be careful: is_perm might change from false to true. | |
669 // Thus, there might be a matching perm object in the table. | |
670 // If there is, this probe must find it. | |
671 if (key->is_perm() && _non_perm_count == 0) { | |
672 return emptyBucket; | |
673 } else if (key->is_instance()) { | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
674 if (key->klass() == SystemDictionary::Class_klass() && JavaObjectsInPerm) { |
0 | 675 // class mirror instances are always perm |
676 return emptyBucket; | |
677 } | |
678 // fall through to probe | |
679 } else if (key->is_array()) { | |
680 // fall through to probe | |
681 } else { | |
682 // not an array or instance | |
683 return emptyBucket; | |
684 } | |
685 | |
686 ciObject* klass = get(key->klass()); | |
687 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; | |
688 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { | |
689 if (is_equal(p, key)) break; | |
690 } | |
691 return (*bp); | |
692 } | |
693 | |
694 | |
695 | |
696 // ------------------------------------------------------------------ | |
697 // Code for for NonPermObject | |
698 // | |
699 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { | |
700 assert(ciObjectFactory::is_initialized(), ""); | |
701 _object = object; | |
702 _next = bucket; | |
703 bucket = this; | |
704 } | |
705 | |
706 | |
707 | |
708 // ------------------------------------------------------------------ | |
709 // ciObjectFactory::insert_non_perm | |
710 // | |
711 // Insert a ciObject into the non-perm table. | |
712 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { | |
713 assert(&where != &emptyBucket, "must not try to fill empty bucket"); | |
714 NonPermObject* p = new (arena()) NonPermObject(where, key, obj); | |
715 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); | |
716 assert(find_non_perm(key) == p, "must find the same spot"); | |
717 ++_non_perm_count; | |
718 } | |
719 | |
720 // ------------------------------------------------------------------ | |
721 // ciObjectFactory::vm_symbol_at | |
722 // Get the ciSymbol corresponding to some index in vmSymbols. | |
723 ciSymbol* ciObjectFactory::vm_symbol_at(int index) { | |
724 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); | |
725 return _shared_ci_symbols[index]; | |
726 } | |
727 | |
728 // ------------------------------------------------------------------ | |
729 // ciObjectFactory::print_contents_impl | |
730 void ciObjectFactory::print_contents_impl() { | |
731 int len = _ci_objects->length(); | |
732 tty->print_cr("ciObjectFactory (%d) oop contents:", len); | |
733 for (int i=0; i<len; i++) { | |
734 _ci_objects->at(i)->print(); | |
735 tty->cr(); | |
736 } | |
737 } | |
738 | |
739 // ------------------------------------------------------------------ | |
740 // ciObjectFactory::print_contents | |
741 void ciObjectFactory::print_contents() { | |
742 print(); | |
743 tty->cr(); | |
744 GUARDED_VM_ENTRY(print_contents_impl();) | |
745 } | |
746 | |
747 // ------------------------------------------------------------------ | |
748 // ciObjectFactory::print | |
749 // | |
750 // Print debugging information about the object factory | |
751 void ciObjectFactory::print() { | |
1602 | 752 tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>", |
0 | 753 _ci_objects->length(), _unloaded_methods->length(), |
1602 | 754 _unloaded_instances->length(), |
0 | 755 _unloaded_klasses->length()); |
756 } |