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