Mercurial > hg > truffle
annotate src/share/vm/ci/ciObjectFactory.cpp @ 3662:e0bbc6b1c4a1
Fixed wrong type transition.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 17 Nov 2011 18:02:12 +0100 |
parents | 0e8a2a629afb |
children | 53636e2c9d03 |
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 |
3650
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2491
diff
changeset
|
233 ciSymbol* result = vm_symbol_at(sid); |
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2491
diff
changeset
|
234 assert(result != NULL, ""); |
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2491
diff
changeset
|
235 return result; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
236 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
237 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
238 assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, ""); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
239 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
|
240 _symbols->push(s); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
241 return s; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
242 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
243 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
244 // 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
|
245 void ciObjectFactory::remove_symbols() { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
246 for (int i = 0; i < _symbols->length(); i++) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
247 ciSymbol* s = _symbols->at(i); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
248 s->get_symbol()->decrement_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
249 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
250 // 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
|
251 // but it'll go away just the same. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
252 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
253 |
0 | 254 // ------------------------------------------------------------------ |
255 // ciObjectFactory::get | |
256 // | |
257 // Get the ciObject corresponding to some oop. If the ciObject has | |
258 // already been created, it is returned. Otherwise, a new ciObject | |
259 // is created. | |
260 ciObject* ciObjectFactory::get(oop key) { | |
261 ASSERT_IN_VM; | |
262 | |
263 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
264 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
265 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
266 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
|
267 oop o = _ci_objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
268 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
269 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
270 } |
0 | 271 } |
272 #endif // ASSERT | |
273 int len = _ci_objects->length(); | |
274 int index = find(key, _ci_objects); | |
275 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
276 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
277 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
|
278 if (_ci_objects->at(i)->get_oop() == key) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
279 assert(index == i, " bad lookup"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
280 } |
0 | 281 } |
282 } | |
283 #endif | |
284 if (!is_found_at(index, key, _ci_objects)) { | |
285 // Check in the non-perm area before putting it in the list. | |
286 NonPermObject* &bucket = find_non_perm(key); | |
287 if (bucket != NULL) { | |
288 return bucket->object(); | |
289 } | |
290 | |
291 // The ciObject does not yet exist. Create it and insert it | |
292 // into the cache. | |
293 Handle keyHandle(key); | |
294 ciObject* new_object = create_new_object(keyHandle()); | |
295 assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); | |
296 init_ident_of(new_object); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
909
diff
changeset
|
297 if (!new_object->is_perm()) { |
0 | 298 // Not a perm-space object. |
299 insert_non_perm(bucket, keyHandle(), new_object); | |
300 return new_object; | |
301 } | |
302 if (len != _ci_objects->length()) { | |
303 // creating the new object has recursively entered new objects | |
304 // into the table. We need to recompute our index. | |
305 index = find(keyHandle(), _ci_objects); | |
306 } | |
307 assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert"); | |
308 insert(index, new_object, _ci_objects); | |
309 return new_object; | |
310 } | |
311 return _ci_objects->at(index); | |
312 } | |
313 | |
314 // ------------------------------------------------------------------ | |
315 // ciObjectFactory::create_new_object | |
316 // | |
317 // Create a new ciObject from an oop. | |
318 // | |
319 // Implementation note: this functionality could be virtual behavior | |
320 // of the oop itself. For now, we explicitly marshal the object. | |
321 ciObject* ciObjectFactory::create_new_object(oop o) { | |
322 EXCEPTION_CONTEXT; | |
323 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
324 if (o->is_klass()) { |
0 | 325 KlassHandle h_k(THREAD, (klassOop)o); |
326 Klass* k = ((klassOop)o)->klass_part(); | |
327 if (k->oop_is_instance()) { | |
328 return new (arena()) ciInstanceKlass(h_k); | |
329 } else if (k->oop_is_objArray()) { | |
330 return new (arena()) ciObjArrayKlass(h_k); | |
331 } else if (k->oop_is_typeArray()) { | |
332 return new (arena()) ciTypeArrayKlass(h_k); | |
333 } else if (k->oop_is_method()) { | |
334 return new (arena()) ciMethodKlass(h_k); | |
335 } else if (k->oop_is_klass()) { | |
336 if (k->oop_is_objArrayKlass()) { | |
337 return new (arena()) ciObjArrayKlassKlass(h_k); | |
338 } else if (k->oop_is_typeArrayKlass()) { | |
339 return new (arena()) ciTypeArrayKlassKlass(h_k); | |
340 } else if (k->oop_is_instanceKlass()) { | |
341 return new (arena()) ciInstanceKlassKlass(h_k); | |
342 } else { | |
343 assert(o == Universe::klassKlassObj(), "bad klassKlass"); | |
344 return new (arena()) ciKlassKlass(h_k); | |
345 } | |
346 } | |
347 } else if (o->is_method()) { | |
348 methodHandle h_m(THREAD, (methodOop)o); | |
349 return new (arena()) ciMethod(h_m); | |
350 } else if (o->is_methodData()) { | |
351 methodDataHandle h_md(THREAD, (methodDataOop)o); | |
352 return new (arena()) ciMethodData(h_md); | |
353 } else if (o->is_instance()) { | |
354 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
|
355 if (java_lang_invoke_CallSite::is_instance(o)) |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
356 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
|
357 else if (java_lang_invoke_MethodHandle::is_instance(o)) |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
358 return new (arena()) ciMethodHandle(h_i); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
359 else |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
360 return new (arena()) ciInstance(h_i); |
0 | 361 } else if (o->is_objArray()) { |
362 objArrayHandle h_oa(THREAD, (objArrayOop)o); | |
363 return new (arena()) ciObjArray(h_oa); | |
364 } else if (o->is_typeArray()) { | |
365 typeArrayHandle h_ta(THREAD, (typeArrayOop)o); | |
366 return new (arena()) ciTypeArray(h_ta); | |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
367 } else if (o->is_constantPoolCache()) { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
368 constantPoolCacheHandle h_cpc(THREAD, (constantPoolCacheOop) o); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
369 return new (arena()) ciCPCache(h_cpc); |
0 | 370 } |
371 | |
372 // The oop is of some type not supported by the compiler interface. | |
373 ShouldNotReachHere(); | |
374 return NULL; | |
375 } | |
376 | |
377 //------------------------------------------------------------------ | |
378 // ciObjectFactory::get_unloaded_method | |
379 // | |
380 // Get the ciMethod representing an unloaded/unfound method. | |
381 // | |
382 // Implementation note: unloaded methods are currently stored in | |
383 // an unordered array, requiring a linear-time lookup for each | |
384 // unloaded method. This may need to change. | |
385 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, | |
386 ciSymbol* name, | |
387 ciSymbol* signature) { | |
388 for (int i=0; i<_unloaded_methods->length(); i++) { | |
389 ciMethod* entry = _unloaded_methods->at(i); | |
390 if (entry->holder()->equals(holder) && | |
391 entry->name()->equals(name) && | |
392 entry->signature()->as_symbol()->equals(signature)) { | |
393 // We've found a match. | |
394 return entry; | |
395 } | |
396 } | |
397 | |
398 // This is a new unloaded method. Create it and stick it in | |
399 // the cache. | |
400 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature); | |
401 | |
402 init_ident_of(new_method); | |
403 _unloaded_methods->append(new_method); | |
404 | |
405 return new_method; | |
406 } | |
407 | |
408 //------------------------------------------------------------------ | |
409 // ciObjectFactory::get_unloaded_klass | |
410 // | |
411 // Get a ciKlass representing an unloaded klass. | |
412 // | |
413 // Implementation note: unloaded klasses are currently stored in | |
414 // an unordered array, requiring a linear-time lookup for each | |
415 // unloaded klass. This may need to change. | |
416 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, | |
417 ciSymbol* name, | |
418 bool create_if_not_found) { | |
419 EXCEPTION_CONTEXT; | |
420 oop loader = NULL; | |
421 oop domain = NULL; | |
422 if (accessing_klass != NULL) { | |
423 loader = accessing_klass->loader(); | |
424 domain = accessing_klass->protection_domain(); | |
425 } | |
426 for (int i=0; i<_unloaded_klasses->length(); i++) { | |
427 ciKlass* entry = _unloaded_klasses->at(i); | |
428 if (entry->name()->equals(name) && | |
429 entry->loader() == loader && | |
430 entry->protection_domain() == domain) { | |
431 // We've found a match. | |
432 return entry; | |
433 } | |
434 } | |
435 | |
436 if (!create_if_not_found) | |
437 return NULL; | |
438 | |
439 // This is a new unloaded klass. Create it and stick it in | |
440 // the cache. | |
441 ciKlass* new_klass = NULL; | |
442 | |
443 // Two cases: this is an unloaded objArrayKlass or an | |
444 // unloaded instanceKlass. Deal with both. | |
445 if (name->byte_at(0) == '[') { | |
446 // Decompose the name.' | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
447 FieldArrayInfo fd; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
448 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
|
449 fd, THREAD); |
0 | 450 if (HAS_PENDING_EXCEPTION) { |
451 CLEAR_PENDING_EXCEPTION; | |
452 CURRENT_THREAD_ENV->record_out_of_memory_failure(); | |
453 return ciEnv::_unloaded_ciobjarrayklass; | |
454 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
455 int dimension = fd.dimension(); |
0 | 456 assert(element_type != T_ARRAY, "unsuccessful decomposition"); |
457 ciKlass* element_klass = NULL; | |
458 if (element_type == T_OBJECT) { | |
459 ciEnv *env = CURRENT_THREAD_ENV; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
460 ciSymbol* ci_name = env->get_symbol(fd.object_key()); |
0 | 461 element_klass = |
462 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); | |
463 } else { | |
464 assert(dimension > 1, "one dimensional type arrays are always loaded."); | |
465 | |
466 // The type array itself takes care of one of the dimensions. | |
467 dimension--; | |
468 | |
469 // The element klass is a typeArrayKlass. | |
470 element_klass = ciTypeArrayKlass::make(element_type); | |
471 } | |
472 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); | |
473 } else { | |
474 jobject loader_handle = NULL; | |
475 jobject domain_handle = NULL; | |
476 if (accessing_klass != NULL) { | |
477 loader_handle = accessing_klass->loader_handle(); | |
478 domain_handle = accessing_klass->protection_domain_handle(); | |
479 } | |
480 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); | |
481 } | |
482 init_ident_of(new_klass); | |
483 _unloaded_klasses->append(new_klass); | |
484 | |
485 return new_klass; | |
486 } | |
487 | |
1602 | 488 |
489 //------------------------------------------------------------------ | |
490 // ciObjectFactory::get_unloaded_instance | |
491 // | |
492 // Get a ciInstance representing an as-yet undetermined instance of a given class. | |
493 // | |
494 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) { | |
495 for (int i=0; i<_unloaded_instances->length(); i++) { | |
496 ciInstance* entry = _unloaded_instances->at(i); | |
497 if (entry->klass()->equals(instance_klass)) { | |
498 // We've found a match. | |
499 return entry; | |
500 } | |
501 } | |
502 | |
503 // This is a new unloaded instance. Create it and stick it in | |
504 // the cache. | |
505 ciInstance* new_instance = new (arena()) ciInstance(instance_klass); | |
506 | |
507 init_ident_of(new_instance); | |
508 _unloaded_instances->append(new_instance); | |
509 | |
510 // make sure it looks the way we want: | |
511 assert(!new_instance->is_loaded(), ""); | |
512 assert(new_instance->klass() == instance_klass, ""); | |
513 | |
514 return new_instance; | |
515 } | |
516 | |
517 | |
518 //------------------------------------------------------------------ | |
519 // ciObjectFactory::get_unloaded_klass_mirror | |
520 // | |
521 // Get a ciInstance representing an unresolved klass mirror. | |
522 // | |
523 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
524 ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) { | |
525 assert(ciEnv::_Class_klass != NULL, ""); | |
526 return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass()); | |
527 } | |
528 | |
529 //------------------------------------------------------------------ | |
530 // ciObjectFactory::get_unloaded_method_handle_constant | |
531 // | |
532 // Get a ciInstance representing an unresolved method handle constant. | |
533 // | |
534 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
535 ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder, | |
536 ciSymbol* name, | |
537 ciSymbol* signature, | |
538 int ref_kind) { | |
539 if (ciEnv::_MethodHandle_klass == NULL) return NULL; | |
540 return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass()); | |
541 } | |
542 | |
543 //------------------------------------------------------------------ | |
544 // ciObjectFactory::get_unloaded_method_type_constant | |
545 // | |
546 // Get a ciInstance representing an unresolved method type constant. | |
547 // | |
548 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
549 ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) { | |
550 if (ciEnv::_MethodType_klass == NULL) return NULL; | |
551 return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass()); | |
552 } | |
553 | |
554 | |
555 | |
0 | 556 //------------------------------------------------------------------ |
557 // ciObjectFactory::get_empty_methodData | |
558 // | |
559 // Get the ciMethodData representing the methodData for a method with | |
560 // none. | |
561 ciMethodData* ciObjectFactory::get_empty_methodData() { | |
562 ciMethodData* new_methodData = new (arena()) ciMethodData(); | |
563 init_ident_of(new_methodData); | |
564 return new_methodData; | |
565 } | |
566 | |
567 //------------------------------------------------------------------ | |
568 // ciObjectFactory::get_return_address | |
569 // | |
570 // Get a ciReturnAddress for a specified bci. | |
571 ciReturnAddress* ciObjectFactory::get_return_address(int bci) { | |
572 for (int i=0; i<_return_addresses->length(); i++) { | |
573 ciReturnAddress* entry = _return_addresses->at(i); | |
574 if (entry->bci() == bci) { | |
575 // We've found a match. | |
576 return entry; | |
577 } | |
578 } | |
579 | |
580 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); | |
581 init_ident_of(new_ret_addr); | |
582 _return_addresses->append(new_ret_addr); | |
583 return new_ret_addr; | |
584 } | |
585 | |
586 // ------------------------------------------------------------------ | |
587 // ciObjectFactory::init_ident_of | |
588 void ciObjectFactory::init_ident_of(ciObject* obj) { | |
589 obj->set_ident(_next_ident++); | |
590 } | |
591 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
592 void ciObjectFactory::init_ident_of(ciSymbol* obj) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
593 obj->set_ident(_next_ident++); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
594 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
595 |
0 | 596 |
597 // ------------------------------------------------------------------ | |
598 // ciObjectFactory::find | |
599 // | |
600 // Use binary search to find the position of this oop in the cache. | |
601 // If there is no entry in the cache corresponding to this oop, return | |
602 // the position at which the oop should be inserted. | |
603 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) { | |
604 int min = 0; | |
605 int max = objects->length()-1; | |
606 | |
607 // print_contents(); | |
608 | |
609 while (max >= min) { | |
610 int mid = (max + min) / 2; | |
611 oop value = objects->at(mid)->get_oop(); | |
612 if (value < key) { | |
613 min = mid + 1; | |
614 } else if (value > key) { | |
615 max = mid - 1; | |
616 } else { | |
617 return mid; | |
618 } | |
619 } | |
620 return min; | |
621 } | |
622 | |
623 // ------------------------------------------------------------------ | |
624 // ciObjectFactory::is_found_at | |
625 // | |
626 // Verify that the binary seach found the given key. | |
627 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) { | |
628 return (index < objects->length() && | |
629 objects->at(index)->get_oop() == key); | |
630 } | |
631 | |
632 | |
633 // ------------------------------------------------------------------ | |
634 // ciObjectFactory::insert | |
635 // | |
636 // Insert a ciObject into the table at some index. | |
637 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) { | |
638 int len = objects->length(); | |
639 if (len == index) { | |
640 objects->append(obj); | |
641 } else { | |
642 objects->append(objects->at(len-1)); | |
643 int pos; | |
644 for (pos = len-2; pos >= index; pos--) { | |
645 objects->at_put(pos+1,objects->at(pos)); | |
646 } | |
647 objects->at_put(index, obj); | |
648 } | |
649 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
650 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
651 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
652 for (int j = 0; j< objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
653 oop o = objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
654 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
655 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
656 } |
0 | 657 } |
658 #endif // ASSERT | |
659 } | |
660 | |
661 static ciObjectFactory::NonPermObject* emptyBucket = NULL; | |
662 | |
663 // ------------------------------------------------------------------ | |
664 // ciObjectFactory::find_non_perm | |
665 // | |
666 // Use a small hash table, hashed on the klass of the key. | |
667 // If there is no entry in the cache corresponding to this oop, return | |
668 // the null tail of the bucket into which the oop should be inserted. | |
669 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { | |
670 // Be careful: is_perm might change from false to true. | |
671 // Thus, there might be a matching perm object in the table. | |
672 // If there is, this probe must find it. | |
673 if (key->is_perm() && _non_perm_count == 0) { | |
674 return emptyBucket; | |
675 } else if (key->is_instance()) { | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
676 if (key->klass() == SystemDictionary::Class_klass() && JavaObjectsInPerm) { |
0 | 677 // class mirror instances are always perm |
678 return emptyBucket; | |
679 } | |
680 // fall through to probe | |
681 } else if (key->is_array()) { | |
682 // fall through to probe | |
683 } else { | |
684 // not an array or instance | |
685 return emptyBucket; | |
686 } | |
687 | |
688 ciObject* klass = get(key->klass()); | |
689 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; | |
690 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { | |
691 if (is_equal(p, key)) break; | |
692 } | |
693 return (*bp); | |
694 } | |
695 | |
696 | |
697 | |
698 // ------------------------------------------------------------------ | |
699 // Code for for NonPermObject | |
700 // | |
701 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { | |
702 assert(ciObjectFactory::is_initialized(), ""); | |
703 _object = object; | |
704 _next = bucket; | |
705 bucket = this; | |
706 } | |
707 | |
708 | |
709 | |
710 // ------------------------------------------------------------------ | |
711 // ciObjectFactory::insert_non_perm | |
712 // | |
713 // Insert a ciObject into the non-perm table. | |
714 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { | |
715 assert(&where != &emptyBucket, "must not try to fill empty bucket"); | |
716 NonPermObject* p = new (arena()) NonPermObject(where, key, obj); | |
717 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); | |
718 assert(find_non_perm(key) == p, "must find the same spot"); | |
719 ++_non_perm_count; | |
720 } | |
721 | |
722 // ------------------------------------------------------------------ | |
723 // ciObjectFactory::vm_symbol_at | |
724 // Get the ciSymbol corresponding to some index in vmSymbols. | |
725 ciSymbol* ciObjectFactory::vm_symbol_at(int index) { | |
726 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); | |
727 return _shared_ci_symbols[index]; | |
728 } | |
729 | |
730 // ------------------------------------------------------------------ | |
731 // ciObjectFactory::print_contents_impl | |
732 void ciObjectFactory::print_contents_impl() { | |
733 int len = _ci_objects->length(); | |
734 tty->print_cr("ciObjectFactory (%d) oop contents:", len); | |
735 for (int i=0; i<len; i++) { | |
736 _ci_objects->at(i)->print(); | |
737 tty->cr(); | |
738 } | |
739 } | |
740 | |
741 // ------------------------------------------------------------------ | |
742 // ciObjectFactory::print_contents | |
743 void ciObjectFactory::print_contents() { | |
744 print(); | |
745 tty->cr(); | |
746 GUARDED_VM_ENTRY(print_contents_impl();) | |
747 } | |
748 | |
749 // ------------------------------------------------------------------ | |
750 // ciObjectFactory::print | |
751 // | |
752 // Print debugging information about the object factory | |
753 void ciObjectFactory::print() { | |
1602 | 754 tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>", |
0 | 755 _ci_objects->length(), _unloaded_methods->length(), |
1602 | 756 _unloaded_instances->length(), |
0 | 757 _unloaded_klasses->length()); |
758 } |