Mercurial > hg > graal-compiler
annotate src/share/vm/ci/ciEnv.cpp @ 1039:987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
Summary: correctly raise exceptions, support safe bitwise "raw" conversions, fix bugs revealed by VerifyMethodHandles, remove dead code, improve debugging support
Reviewed-by: never, twisti
author | jrose |
---|---|
date | Sat, 17 Oct 2009 19:51:05 -0700 |
parents | 148e5441d916 |
children | 389049f3f393 0c3f888b7636 |
rev | line source |
---|---|
0 | 1 /* |
844 | 2 * Copyright 1999-2009 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_ciEnv.cpp.incl" | |
27 | |
28 // ciEnv | |
29 // | |
30 // This class is the top level broker for requests from the compiler | |
31 // to the VM. | |
32 | |
33 ciObject* ciEnv::_null_object_instance; | |
34 ciMethodKlass* ciEnv::_method_klass_instance; | |
35 ciSymbolKlass* ciEnv::_symbol_klass_instance; | |
36 ciKlassKlass* ciEnv::_klass_klass_instance; | |
37 ciInstanceKlassKlass* ciEnv::_instance_klass_klass_instance; | |
38 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance; | |
39 ciObjArrayKlassKlass* ciEnv::_obj_array_klass_klass_instance; | |
40 | |
41 ciInstanceKlass* ciEnv::_ArrayStoreException; | |
42 ciInstanceKlass* ciEnv::_Class; | |
43 ciInstanceKlass* ciEnv::_ClassCastException; | |
44 ciInstanceKlass* ciEnv::_Object; | |
45 ciInstanceKlass* ciEnv::_Throwable; | |
46 ciInstanceKlass* ciEnv::_Thread; | |
47 ciInstanceKlass* ciEnv::_OutOfMemoryError; | |
48 ciInstanceKlass* ciEnv::_String; | |
49 | |
50 ciSymbol* ciEnv::_unloaded_cisymbol = NULL; | |
51 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; | |
52 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; | |
53 | |
54 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; | |
55 jobject ciEnv::_ArrayStoreException_handle = NULL; | |
56 jobject ciEnv::_ClassCastException_handle = NULL; | |
57 | |
58 #ifndef PRODUCT | |
59 static bool firstEnv = true; | |
60 #endif /* PRODUCT */ | |
61 | |
62 // ------------------------------------------------------------------ | |
63 // ciEnv::ciEnv | |
64 ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter) { | |
65 VM_ENTRY_MARK; | |
66 | |
67 // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. | |
68 thread->set_env(this); | |
69 assert(ciEnv::current() == this, "sanity"); | |
70 | |
71 _oop_recorder = NULL; | |
72 _debug_info = NULL; | |
73 _dependencies = NULL; | |
74 _failure_reason = NULL; | |
75 _compilable = MethodCompilable; | |
76 _break_at_compile = false; | |
77 _compiler_data = NULL; | |
78 #ifndef PRODUCT | |
79 assert(!firstEnv, "not initialized properly"); | |
80 #endif /* !PRODUCT */ | |
81 | |
82 _system_dictionary_modification_counter = system_dictionary_modification_counter; | |
83 _num_inlined_bytecodes = 0; | |
84 assert(task == NULL || thread->task() == task, "sanity"); | |
85 _task = task; | |
86 _log = NULL; | |
87 | |
88 // Temporary buffer for creating symbols and such. | |
89 _name_buffer = NULL; | |
90 _name_buffer_len = 0; | |
91 | |
92 _arena = &_ciEnv_arena; | |
93 _factory = new (_arena) ciObjectFactory(_arena, 128); | |
94 | |
95 // Preload commonly referenced system ciObjects. | |
96 | |
97 // During VM initialization, these instances have not yet been created. | |
98 // Assertions ensure that these instances are not accessed before | |
99 // their initialization. | |
100 | |
101 assert(Universe::is_fully_initialized(), "should be complete"); | |
102 | |
103 oop o = Universe::null_ptr_exception_instance(); | |
104 assert(o != NULL, "should have been initialized"); | |
105 _NullPointerException_instance = get_object(o)->as_instance(); | |
106 o = Universe::arithmetic_exception_instance(); | |
107 assert(o != NULL, "should have been initialized"); | |
108 _ArithmeticException_instance = get_object(o)->as_instance(); | |
109 | |
110 _ArrayIndexOutOfBoundsException_instance = NULL; | |
111 _ArrayStoreException_instance = NULL; | |
112 _ClassCastException_instance = NULL; | |
113 } | |
114 | |
115 ciEnv::ciEnv(Arena* arena) { | |
116 ASSERT_IN_VM; | |
117 | |
118 // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. | |
119 CompilerThread* current_thread = CompilerThread::current(); | |
120 assert(current_thread->env() == NULL, "must be"); | |
121 current_thread->set_env(this); | |
122 assert(ciEnv::current() == this, "sanity"); | |
123 | |
124 _oop_recorder = NULL; | |
125 _debug_info = NULL; | |
126 _dependencies = NULL; | |
127 _failure_reason = NULL; | |
128 _compilable = MethodCompilable_never; | |
129 _break_at_compile = false; | |
130 _compiler_data = NULL; | |
131 #ifndef PRODUCT | |
132 assert(firstEnv, "must be first"); | |
133 firstEnv = false; | |
134 #endif /* !PRODUCT */ | |
135 | |
136 _system_dictionary_modification_counter = 0; | |
137 _num_inlined_bytecodes = 0; | |
138 _task = NULL; | |
139 _log = NULL; | |
140 | |
141 // Temporary buffer for creating symbols and such. | |
142 _name_buffer = NULL; | |
143 _name_buffer_len = 0; | |
144 | |
145 _arena = arena; | |
146 _factory = new (_arena) ciObjectFactory(_arena, 128); | |
147 | |
148 // Preload commonly referenced system ciObjects. | |
149 | |
150 // During VM initialization, these instances have not yet been created. | |
151 // Assertions ensure that these instances are not accessed before | |
152 // their initialization. | |
153 | |
154 assert(Universe::is_fully_initialized(), "must be"); | |
155 | |
156 oop o = Universe::null_ptr_exception_instance(); | |
157 assert(o != NULL, "should have been initialized"); | |
158 _NullPointerException_instance = get_object(o)->as_instance(); | |
159 o = Universe::arithmetic_exception_instance(); | |
160 assert(o != NULL, "should have been initialized"); | |
161 _ArithmeticException_instance = get_object(o)->as_instance(); | |
162 | |
163 _ArrayIndexOutOfBoundsException_instance = NULL; | |
164 _ArrayStoreException_instance = NULL; | |
165 _ClassCastException_instance = NULL; | |
166 } | |
167 | |
168 ciEnv::~ciEnv() { | |
169 CompilerThread* current_thread = CompilerThread::current(); | |
170 current_thread->set_env(NULL); | |
171 } | |
172 | |
173 // ------------------------------------------------------------------ | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
174 // Cache Jvmti state |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
175 void ciEnv::cache_jvmti_state() { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
176 VM_ENTRY_MARK; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
177 // Get Jvmti capabilities under lock to get consistant values. |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
178 MutexLocker mu(JvmtiThreadState_lock); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
179 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
180 _jvmti_can_examine_or_deopt_anywhere = JvmtiExport::can_examine_or_deopt_anywhere(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
181 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
182 _jvmti_can_post_exceptions = JvmtiExport::can_post_exceptions(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
183 } |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
184 |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
185 // ------------------------------------------------------------------ |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
186 // Cache DTrace flags |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
187 void ciEnv::cache_dtrace_flags() { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
188 // Need lock? |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
189 _dtrace_extended_probes = ExtendedDTraceProbes; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
190 if (_dtrace_extended_probes) { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
191 _dtrace_monitor_probes = true; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
192 _dtrace_method_probes = true; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
193 _dtrace_alloc_probes = true; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
194 } else { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
195 _dtrace_monitor_probes = DTraceMonitorProbes; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
196 _dtrace_method_probes = DTraceMethodProbes; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
197 _dtrace_alloc_probes = DTraceAllocProbes; |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
198 } |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
199 } |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
200 |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
201 // ------------------------------------------------------------------ |
0 | 202 // helper for lazy exception creation |
203 ciInstance* ciEnv::get_or_create_exception(jobject& handle, symbolHandle name) { | |
204 VM_ENTRY_MARK; | |
205 if (handle == NULL) { | |
206 // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. | |
207 klassOop k = SystemDictionary::find(name, Handle(), Handle(), THREAD); | |
208 jobject objh = NULL; | |
209 if (!HAS_PENDING_EXCEPTION && k != NULL) { | |
210 oop obj = instanceKlass::cast(k)->allocate_permanent_instance(THREAD); | |
211 if (!HAS_PENDING_EXCEPTION) | |
212 objh = JNIHandles::make_global(obj); | |
213 } | |
214 if (HAS_PENDING_EXCEPTION) { | |
215 CLEAR_PENDING_EXCEPTION; | |
216 } else { | |
217 handle = objh; | |
218 } | |
219 } | |
220 oop obj = JNIHandles::resolve(handle); | |
221 return obj == NULL? NULL: get_object(obj)->as_instance(); | |
222 } | |
223 | |
224 // ------------------------------------------------------------------ | |
225 // ciEnv::ArrayIndexOutOfBoundsException_instance, etc. | |
226 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { | |
227 if (_ArrayIndexOutOfBoundsException_instance == NULL) { | |
228 _ArrayIndexOutOfBoundsException_instance | |
229 = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, | |
230 vmSymbolHandles::java_lang_ArrayIndexOutOfBoundsException()); | |
231 } | |
232 return _ArrayIndexOutOfBoundsException_instance; | |
233 } | |
234 ciInstance* ciEnv::ArrayStoreException_instance() { | |
235 if (_ArrayStoreException_instance == NULL) { | |
236 _ArrayStoreException_instance | |
237 = get_or_create_exception(_ArrayStoreException_handle, | |
238 vmSymbolHandles::java_lang_ArrayStoreException()); | |
239 } | |
240 return _ArrayStoreException_instance; | |
241 } | |
242 ciInstance* ciEnv::ClassCastException_instance() { | |
243 if (_ClassCastException_instance == NULL) { | |
244 _ClassCastException_instance | |
245 = get_or_create_exception(_ClassCastException_handle, | |
246 vmSymbolHandles::java_lang_ClassCastException()); | |
247 } | |
248 return _ClassCastException_instance; | |
249 } | |
250 | |
251 // ------------------------------------------------------------------ | |
252 // ciEnv::get_method_from_handle | |
253 ciMethod* ciEnv::get_method_from_handle(jobject method) { | |
254 VM_ENTRY_MARK; | |
255 return get_object(JNIHandles::resolve(method))->as_method(); | |
256 } | |
257 | |
258 // ------------------------------------------------------------------ | |
259 // ciEnv::make_array | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
260 ciArray* ciEnv::make_system_array(GrowableArray<ciObject*>* objects) { |
0 | 261 VM_ENTRY_MARK; |
262 int length = objects->length(); | |
263 objArrayOop a = oopFactory::new_system_objArray(length, THREAD); | |
264 if (HAS_PENDING_EXCEPTION) { | |
265 CLEAR_PENDING_EXCEPTION; | |
266 record_out_of_memory_failure(); | |
267 return NULL; | |
268 } | |
269 for (int i = 0; i < length; i++) { | |
270 a->obj_at_put(i, objects->at(i)->get_oop()); | |
271 } | |
272 assert(a->is_perm(), ""); | |
273 return get_object(a)->as_array(); | |
274 } | |
275 | |
276 | |
277 // ------------------------------------------------------------------ | |
278 // ciEnv::array_element_offset_in_bytes | |
279 int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) { | |
280 VM_ENTRY_MARK; | |
281 objArrayOop a = (objArrayOop)a_h->get_oop(); | |
282 assert(a->is_objArray(), ""); | |
283 int length = a->length(); | |
284 oop o = o_h->get_oop(); | |
285 for (int i = 0; i < length; i++) { | |
286 if (a->obj_at(i) == o) return i; | |
287 } | |
288 return -1; | |
289 } | |
290 | |
291 | |
292 // ------------------------------------------------------------------ | |
293 // ciEnv::check_klass_accessiblity | |
294 // | |
295 // Note: the logic of this method should mirror the logic of | |
296 // constantPoolOopDesc::verify_constant_pool_resolve. | |
297 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, | |
298 klassOop resolved_klass) { | |
299 if (accessing_klass == NULL || !accessing_klass->is_loaded()) { | |
300 return true; | |
301 } | |
302 if (accessing_klass->is_obj_array()) { | |
303 accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass(); | |
304 } | |
305 if (!accessing_klass->is_instance_klass()) { | |
306 return true; | |
307 } | |
308 | |
309 if (resolved_klass->klass_part()->oop_is_objArray()) { | |
310 // Find the element klass, if this is an array. | |
311 resolved_klass = objArrayKlass::cast(resolved_klass)->bottom_klass(); | |
312 } | |
313 if (resolved_klass->klass_part()->oop_is_instance()) { | |
314 return Reflection::verify_class_access(accessing_klass->get_klassOop(), | |
315 resolved_klass, | |
316 true); | |
317 } | |
318 return true; | |
319 } | |
320 | |
321 // ------------------------------------------------------------------ | |
322 // ciEnv::get_klass_by_name_impl | |
323 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass, | |
324 ciSymbol* name, | |
325 bool require_local) { | |
326 ASSERT_IN_VM; | |
327 EXCEPTION_CONTEXT; | |
328 | |
329 // Now we need to check the SystemDictionary | |
330 symbolHandle sym(THREAD, name->get_symbolOop()); | |
331 if (sym->byte_at(0) == 'L' && | |
332 sym->byte_at(sym->utf8_length()-1) == ';') { | |
333 // This is a name from a signature. Strip off the trimmings. | |
334 sym = oopFactory::new_symbol_handle(sym->as_utf8()+1, | |
335 sym->utf8_length()-2, | |
336 KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); | |
337 name = get_object(sym())->as_symbol(); | |
338 } | |
339 | |
340 // Check for prior unloaded klass. The SystemDictionary's answers | |
341 // can vary over time but the compiler needs consistency. | |
342 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); | |
343 if (unloaded_klass != NULL) { | |
344 if (require_local) return NULL; | |
345 return unloaded_klass; | |
346 } | |
347 | |
348 Handle loader(THREAD, (oop)NULL); | |
349 Handle domain(THREAD, (oop)NULL); | |
350 if (accessing_klass != NULL) { | |
351 loader = Handle(THREAD, accessing_klass->loader()); | |
352 domain = Handle(THREAD, accessing_klass->protection_domain()); | |
353 } | |
354 | |
355 // setup up the proper type to return on OOM | |
356 ciKlass* fail_type; | |
357 if (sym->byte_at(0) == '[') { | |
358 fail_type = _unloaded_ciobjarrayklass; | |
359 } else { | |
360 fail_type = _unloaded_ciinstance_klass; | |
361 } | |
362 klassOop found_klass; | |
363 if (!require_local) { | |
364 found_klass = | |
365 SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, | |
366 KILL_COMPILE_ON_FATAL_(fail_type)); | |
367 } else { | |
368 found_klass = | |
369 SystemDictionary::find_instance_or_array_klass(sym, loader, domain, | |
370 KILL_COMPILE_ON_FATAL_(fail_type)); | |
371 } | |
372 | |
373 if (found_klass != NULL) { | |
374 // Found it. Build a CI handle. | |
375 return get_object(found_klass)->as_klass(); | |
376 } | |
377 | |
378 // If we fail to find an array klass, look again for its element type. | |
379 // The element type may be available either locally or via constraints. | |
380 // In either case, if we can find the element type in the system dictionary, | |
381 // we must build an array type around it. The CI requires array klasses | |
382 // to be loaded if their element klasses are loaded, except when memory | |
383 // is exhausted. | |
384 if (sym->byte_at(0) == '[' && | |
385 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { | |
386 // We have an unloaded array. | |
387 // Build it on the fly if the element class exists. | |
388 symbolOop elem_sym = oopFactory::new_symbol(sym->as_utf8()+1, | |
389 sym->utf8_length()-1, | |
390 KILL_COMPILE_ON_FATAL_(fail_type)); | |
391 // Get element ciKlass recursively. | |
392 ciKlass* elem_klass = | |
393 get_klass_by_name_impl(accessing_klass, | |
394 get_object(elem_sym)->as_symbol(), | |
395 require_local); | |
396 if (elem_klass != NULL && elem_klass->is_loaded()) { | |
397 // Now make an array for it | |
398 return ciObjArrayKlass::make_impl(elem_klass); | |
399 } | |
400 } | |
401 | |
402 if (require_local) return NULL; | |
403 // Not yet loaded into the VM, or not governed by loader constraints. | |
404 // Make a CI representative for it. | |
405 return get_unloaded_klass(accessing_klass, name); | |
406 } | |
407 | |
408 // ------------------------------------------------------------------ | |
409 // ciEnv::get_klass_by_name | |
410 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, | |
411 ciSymbol* klass_name, | |
412 bool require_local) { | |
413 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, | |
414 klass_name, | |
415 require_local);) | |
416 } | |
417 | |
418 // ------------------------------------------------------------------ | |
419 // ciEnv::get_klass_by_index_impl | |
420 // | |
421 // Implementation of get_klass_by_index. | |
422 ciKlass* ciEnv::get_klass_by_index_impl(ciInstanceKlass* accessor, | |
423 int index, | |
424 bool& is_accessible) { | |
425 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool"); | |
426 EXCEPTION_CONTEXT; | |
427 constantPoolHandle cpool(THREAD, accessor->get_instanceKlass()->constants()); | |
428 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index)); | |
429 symbolHandle klass_name; | |
430 if (klass.is_null()) { | |
431 // The klass has not been inserted into the constant pool. | |
432 // Try to look it up by name. | |
433 { | |
434 // We have to lock the cpool to keep the oop from being resolved | |
435 // while we are accessing it. | |
436 ObjectLocker ol(cpool, THREAD); | |
437 | |
438 constantTag tag = cpool->tag_at(index); | |
439 if (tag.is_klass()) { | |
440 // The klass has been inserted into the constant pool | |
441 // very recently. | |
442 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); | |
443 } else if (tag.is_symbol()) { | |
444 klass_name = symbolHandle(THREAD, cpool->symbol_at(index)); | |
445 } else { | |
446 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); | |
447 klass_name = symbolHandle(THREAD, cpool->unresolved_klass_at(index)); | |
448 } | |
449 } | |
450 } | |
451 | |
452 if (klass.is_null()) { | |
453 // Not found in constant pool. Use the name to do the lookup. | |
454 ciKlass* k = get_klass_by_name_impl(accessor, | |
455 get_object(klass_name())->as_symbol(), | |
456 false); | |
457 // Calculate accessibility the hard way. | |
458 if (!k->is_loaded()) { | |
459 is_accessible = false; | |
460 } else if (k->loader() != accessor->loader() && | |
461 get_klass_by_name_impl(accessor, k->name(), true) == NULL) { | |
462 // Loaded only remotely. Not linked yet. | |
463 is_accessible = false; | |
464 } else { | |
465 // Linked locally, and we must also check public/private, etc. | |
466 is_accessible = check_klass_accessibility(accessor, k->get_klassOop()); | |
467 } | |
468 return k; | |
469 } | |
470 | |
471 // Check for prior unloaded klass. The SystemDictionary's answers | |
472 // can vary over time but the compiler needs consistency. | |
473 ciSymbol* name = get_object(klass()->klass_part()->name())->as_symbol(); | |
474 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); | |
475 if (unloaded_klass != NULL) { | |
476 is_accessible = false; | |
477 return unloaded_klass; | |
478 } | |
479 | |
480 // It is known to be accessible, since it was found in the constant pool. | |
481 is_accessible = true; | |
482 return get_object(klass())->as_klass(); | |
483 } | |
484 | |
485 // ------------------------------------------------------------------ | |
486 // ciEnv::get_klass_by_index | |
487 // | |
488 // Get a klass from the constant pool. | |
489 ciKlass* ciEnv::get_klass_by_index(ciInstanceKlass* accessor, | |
490 int index, | |
491 bool& is_accessible) { | |
492 GUARDED_VM_ENTRY(return get_klass_by_index_impl(accessor, index, is_accessible);) | |
493 } | |
494 | |
495 // ------------------------------------------------------------------ | |
496 // ciEnv::get_constant_by_index_impl | |
497 // | |
498 // Implementation of get_constant_by_index(). | |
499 ciConstant ciEnv::get_constant_by_index_impl(ciInstanceKlass* accessor, | |
500 int index) { | |
501 EXCEPTION_CONTEXT; | |
502 instanceKlass* ik_accessor = accessor->get_instanceKlass(); | |
503 assert(ik_accessor->is_linked(), "must be linked before accessing constant pool"); | |
504 constantPoolOop cpool = ik_accessor->constants(); | |
505 constantTag tag = cpool->tag_at(index); | |
506 if (tag.is_int()) { | |
507 return ciConstant(T_INT, (jint)cpool->int_at(index)); | |
508 } else if (tag.is_long()) { | |
509 return ciConstant((jlong)cpool->long_at(index)); | |
510 } else if (tag.is_float()) { | |
511 return ciConstant((jfloat)cpool->float_at(index)); | |
512 } else if (tag.is_double()) { | |
513 return ciConstant((jdouble)cpool->double_at(index)); | |
514 } else if (tag.is_string() || tag.is_unresolved_string()) { | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
515 oop string = NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
516 if (cpool->is_pseudo_string_at(index)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
517 string = cpool->pseudo_string_at(index); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
518 } else { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
519 string = cpool->string_at(index, THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
520 if (HAS_PENDING_EXCEPTION) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
521 CLEAR_PENDING_EXCEPTION; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
522 record_out_of_memory_failure(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
523 return ciConstant(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
524 } |
0 | 525 } |
526 ciObject* constant = get_object(string); | |
527 assert (constant->is_instance(), "must be an instance, or not? "); | |
528 return ciConstant(T_OBJECT, constant); | |
529 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | |
530 // 4881222: allow ldc to take a class type | |
531 bool ignore; | |
532 ciKlass* klass = get_klass_by_index_impl(accessor, index, ignore); | |
533 if (HAS_PENDING_EXCEPTION) { | |
534 CLEAR_PENDING_EXCEPTION; | |
535 record_out_of_memory_failure(); | |
536 return ciConstant(); | |
537 } | |
538 assert (klass->is_instance_klass() || klass->is_array_klass(), | |
539 "must be an instance or array klass "); | |
540 return ciConstant(T_OBJECT, klass); | |
541 } else { | |
542 ShouldNotReachHere(); | |
543 return ciConstant(); | |
544 } | |
545 } | |
546 | |
547 // ------------------------------------------------------------------ | |
548 // ciEnv::is_unresolved_string_impl | |
549 // | |
550 // Implementation of is_unresolved_string(). | |
551 bool ciEnv::is_unresolved_string_impl(instanceKlass* accessor, int index) const { | |
552 EXCEPTION_CONTEXT; | |
553 assert(accessor->is_linked(), "must be linked before accessing constant pool"); | |
554 constantPoolOop cpool = accessor->constants(); | |
555 constantTag tag = cpool->tag_at(index); | |
556 return tag.is_unresolved_string(); | |
557 } | |
558 | |
559 // ------------------------------------------------------------------ | |
560 // ciEnv::is_unresolved_klass_impl | |
561 // | |
562 // Implementation of is_unresolved_klass(). | |
563 bool ciEnv::is_unresolved_klass_impl(instanceKlass* accessor, int index) const { | |
564 EXCEPTION_CONTEXT; | |
565 assert(accessor->is_linked(), "must be linked before accessing constant pool"); | |
566 constantPoolOop cpool = accessor->constants(); | |
567 constantTag tag = cpool->tag_at(index); | |
568 return tag.is_unresolved_klass(); | |
569 } | |
570 | |
571 // ------------------------------------------------------------------ | |
572 // ciEnv::get_constant_by_index | |
573 // | |
574 // Pull a constant out of the constant pool. How appropriate. | |
575 // | |
576 // Implementation note: this query is currently in no way cached. | |
577 ciConstant ciEnv::get_constant_by_index(ciInstanceKlass* accessor, | |
578 int index) { | |
579 GUARDED_VM_ENTRY(return get_constant_by_index_impl(accessor, index); ) | |
580 } | |
581 | |
582 // ------------------------------------------------------------------ | |
583 // ciEnv::is_unresolved_string | |
584 // | |
585 // Check constant pool | |
586 // | |
587 // Implementation note: this query is currently in no way cached. | |
588 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor, | |
589 int index) const { | |
590 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); ) | |
591 } | |
592 | |
593 // ------------------------------------------------------------------ | |
594 // ciEnv::is_unresolved_klass | |
595 // | |
596 // Check constant pool | |
597 // | |
598 // Implementation note: this query is currently in no way cached. | |
599 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor, | |
600 int index) const { | |
601 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); ) | |
602 } | |
603 | |
604 // ------------------------------------------------------------------ | |
605 // ciEnv::get_field_by_index_impl | |
606 // | |
607 // Implementation of get_field_by_index. | |
608 // | |
609 // Implementation note: the results of field lookups are cached | |
610 // in the accessor klass. | |
611 ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, | |
612 int index) { | |
613 ciConstantPoolCache* cache = accessor->field_cache(); | |
614 if (cache == NULL) { | |
615 ciField* field = new (arena()) ciField(accessor, index); | |
616 return field; | |
617 } else { | |
618 ciField* field = (ciField*)cache->get(index); | |
619 if (field == NULL) { | |
620 field = new (arena()) ciField(accessor, index); | |
621 cache->insert(index, field); | |
622 } | |
623 return field; | |
624 } | |
625 } | |
626 | |
627 // ------------------------------------------------------------------ | |
628 // ciEnv::get_field_by_index | |
629 // | |
630 // Get a field by index from a klass's constant pool. | |
631 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, | |
632 int index) { | |
633 GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) | |
634 } | |
635 | |
636 // ------------------------------------------------------------------ | |
637 // ciEnv::lookup_method | |
638 // | |
639 // Perform an appropriate method lookup based on accessor, holder, | |
640 // name, signature, and bytecode. | |
641 methodOop ciEnv::lookup_method(instanceKlass* accessor, | |
642 instanceKlass* holder, | |
643 symbolOop name, | |
644 symbolOop sig, | |
645 Bytecodes::Code bc) { | |
646 EXCEPTION_CONTEXT; | |
647 KlassHandle h_accessor(THREAD, accessor); | |
648 KlassHandle h_holder(THREAD, holder); | |
649 symbolHandle h_name(THREAD, name); | |
650 symbolHandle h_sig(THREAD, sig); | |
651 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); | |
652 methodHandle dest_method; | |
653 switch (bc) { | |
654 case Bytecodes::_invokestatic: | |
655 dest_method = | |
656 LinkResolver::resolve_static_call_or_null(h_holder, h_name, h_sig, h_accessor); | |
657 break; | |
658 case Bytecodes::_invokespecial: | |
659 dest_method = | |
660 LinkResolver::resolve_special_call_or_null(h_holder, h_name, h_sig, h_accessor); | |
661 break; | |
662 case Bytecodes::_invokeinterface: | |
663 dest_method = | |
664 LinkResolver::linktime_resolve_interface_method_or_null(h_holder, h_name, h_sig, | |
665 h_accessor, true); | |
666 break; | |
667 case Bytecodes::_invokevirtual: | |
668 dest_method = | |
669 LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, h_name, h_sig, | |
670 h_accessor, true); | |
671 break; | |
672 default: ShouldNotReachHere(); | |
673 } | |
674 | |
675 return dest_method(); | |
676 } | |
677 | |
678 | |
679 // ------------------------------------------------------------------ | |
680 // ciEnv::get_method_by_index_impl | |
681 ciMethod* ciEnv::get_method_by_index_impl(ciInstanceKlass* accessor, | |
682 int index, Bytecodes::Code bc) { | |
683 // Get the method's declared holder. | |
684 | |
685 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool"); | |
686 constantPoolHandle cpool = accessor->get_instanceKlass()->constants(); | |
687 int holder_index = cpool->klass_ref_index_at(index); | |
688 bool holder_is_accessible; | |
689 ciKlass* holder = get_klass_by_index_impl(accessor, holder_index, holder_is_accessible); | |
690 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); | |
691 | |
692 // Get the method's name and signature. | |
693 int nt_index = cpool->name_and_type_ref_index_at(index); | |
694 int sig_index = cpool->signature_ref_index_at(nt_index); | |
695 symbolOop name_sym = cpool->name_ref_at(index); | |
696 symbolOop sig_sym = cpool->symbol_at(sig_index); | |
697 | |
698 if (holder_is_accessible) { // Our declared holder is loaded. | |
699 instanceKlass* lookup = declared_holder->get_instanceKlass(); | |
700 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); | |
701 if (m != NULL) { | |
702 // We found the method. | |
703 return get_object(m)->as_method(); | |
704 } | |
705 } | |
706 | |
707 // Either the declared holder was not loaded, or the method could | |
708 // not be found. Create a dummy ciMethod to represent the failed | |
709 // lookup. | |
710 | |
711 return get_unloaded_method(declared_holder, | |
712 get_object(name_sym)->as_symbol(), | |
713 get_object(sig_sym)->as_symbol()); | |
714 } | |
715 | |
716 | |
717 // ------------------------------------------------------------------ | |
718 // ciEnv::get_instance_klass_for_declared_method_holder | |
719 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) { | |
720 // For the case of <array>.clone(), the method holder can be a ciArrayKlass | |
721 // instead of a ciInstanceKlass. For that case simply pretend that the | |
722 // declared holder is Object.clone since that's where the call will bottom out. | |
723 // A more correct fix would trickle out through many interfaces in CI, | |
724 // requiring ciInstanceKlass* to become ciKlass* and many more places would | |
725 // require checks to make sure the expected type was found. Given that this | |
726 // only occurs for clone() the more extensive fix seems like overkill so | |
727 // instead we simply smear the array type into Object. | |
728 if (method_holder->is_instance_klass()) { | |
729 return method_holder->as_instance_klass(); | |
730 } else if (method_holder->is_array_klass()) { | |
731 return current()->Object_klass(); | |
732 } else { | |
733 ShouldNotReachHere(); | |
734 } | |
735 return NULL; | |
736 } | |
737 | |
738 | |
739 | |
740 | |
741 // ------------------------------------------------------------------ | |
742 // ciEnv::get_method_by_index | |
743 ciMethod* ciEnv::get_method_by_index(ciInstanceKlass* accessor, | |
744 int index, Bytecodes::Code bc) { | |
745 GUARDED_VM_ENTRY(return get_method_by_index_impl(accessor, index, bc);) | |
746 } | |
747 | |
748 // ------------------------------------------------------------------ | |
749 // ciEnv::name_buffer | |
750 char *ciEnv::name_buffer(int req_len) { | |
751 if (_name_buffer_len < req_len) { | |
752 if (_name_buffer == NULL) { | |
753 _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len); | |
754 _name_buffer_len = req_len; | |
755 } else { | |
756 _name_buffer = | |
757 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len); | |
758 _name_buffer_len = req_len; | |
759 } | |
760 } | |
761 return _name_buffer; | |
762 } | |
763 | |
764 // ------------------------------------------------------------------ | |
765 // ciEnv::is_in_vm | |
766 bool ciEnv::is_in_vm() { | |
767 return JavaThread::current()->thread_state() == _thread_in_vm; | |
768 } | |
769 | |
770 bool ciEnv::system_dictionary_modification_counter_changed() { | |
771 return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); | |
772 } | |
773 | |
774 // ------------------------------------------------------------------ | |
775 // ciEnv::check_for_system_dictionary_modification | |
776 // Check for changes to the system dictionary during compilation | |
777 // class loads, evolution, breakpoints | |
778 void ciEnv::check_for_system_dictionary_modification(ciMethod* target) { | |
779 if (failing()) return; // no need for further checks | |
780 | |
781 // Dependencies must be checked when the system dictionary changes. | |
782 // If logging is enabled all violated dependences will be recorded in | |
783 // the log. In debug mode check dependencies even if the system | |
784 // dictionary hasn't changed to verify that no invalid dependencies | |
785 // were inserted. Any violated dependences in this case are dumped to | |
786 // the tty. | |
787 | |
788 bool counter_changed = system_dictionary_modification_counter_changed(); | |
789 bool test_deps = counter_changed; | |
790 DEBUG_ONLY(test_deps = true); | |
791 if (!test_deps) return; | |
792 | |
793 bool print_failures = false; | |
794 DEBUG_ONLY(print_failures = !counter_changed); | |
795 | |
796 bool keep_going = (print_failures || xtty != NULL); | |
797 | |
798 int violated = 0; | |
799 | |
800 for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { | |
801 klassOop witness = deps.check_dependency(); | |
802 if (witness != NULL) { | |
803 ++violated; | |
804 if (print_failures) deps.print_dependency(witness, /*verbose=*/ true); | |
805 // If there's no log and we're not sanity-checking, we're done. | |
806 if (!keep_going) break; | |
807 } | |
808 } | |
809 | |
810 if (violated != 0) { | |
811 assert(counter_changed, "failed dependencies, but counter didn't change"); | |
812 record_failure("concurrent class loading"); | |
813 } | |
814 } | |
815 | |
816 // ------------------------------------------------------------------ | |
817 // ciEnv::register_method | |
818 void ciEnv::register_method(ciMethod* target, | |
819 int entry_bci, | |
820 CodeOffsets* offsets, | |
821 int orig_pc_offset, | |
822 CodeBuffer* code_buffer, | |
823 int frame_words, | |
824 OopMapSet* oop_map_set, | |
825 ExceptionHandlerTable* handler_table, | |
826 ImplicitExceptionTable* inc_table, | |
827 AbstractCompiler* compiler, | |
828 int comp_level, | |
829 bool has_debug_info, | |
830 bool has_unsafe_access) { | |
831 VM_ENTRY_MARK; | |
832 nmethod* nm = NULL; | |
833 { | |
834 // To prevent compile queue updates. | |
835 MutexLocker locker(MethodCompileQueue_lock, THREAD); | |
836 | |
837 // Prevent SystemDictionary::add_to_hierarchy from running | |
838 // and invalidating our dependencies until we install this method. | |
839 MutexLocker ml(Compile_lock); | |
840 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
841 // Change in Jvmti state may invalidate compilation. |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
842 if (!failing() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
843 ( (!jvmti_can_hotswap_or_post_breakpoint() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
844 JvmtiExport::can_hotswap_or_post_breakpoint()) || |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
845 (!jvmti_can_examine_or_deopt_anywhere() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
846 JvmtiExport::can_examine_or_deopt_anywhere()) || |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
847 (!jvmti_can_access_local_variables() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
848 JvmtiExport::can_access_local_variables()) || |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
849 (!jvmti_can_post_exceptions() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
850 JvmtiExport::can_post_exceptions()) )) { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
851 record_failure("Jvmti state change invalidated dependencies"); |
0 | 852 } |
853 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
854 // Change in DTrace flags may invalidate compilation. |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
855 if (!failing() && |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
856 ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
857 (!dtrace_method_probes() && DTraceMethodProbes) || |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
858 (!dtrace_alloc_probes() && DTraceAllocProbes) )) { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
859 record_failure("DTrace flags change invalidated dependencies"); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
860 } |
0 | 861 |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
862 if (!failing()) { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
863 if (log() != NULL) { |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
864 // Log the dependencies which this compilation declares. |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
865 dependencies()->log_all_dependencies(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
866 } |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
867 |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
868 // Encode the dependencies now, so we can check them right away. |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
869 dependencies()->encode_content_bytes(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
870 |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
871 // Check for {class loads, evolution, breakpoints} during compilation |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
872 check_for_system_dictionary_modification(target); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
470
diff
changeset
|
873 } |
0 | 874 |
875 methodHandle method(THREAD, target->get_methodOop()); | |
876 | |
877 if (failing()) { | |
878 // While not a true deoptimization, it is a preemptive decompile. | |
879 methodDataOop mdo = method()->method_data(); | |
880 if (mdo != NULL) { | |
881 mdo->inc_decompile_count(); | |
882 } | |
883 | |
884 // All buffers in the CodeBuffer are allocated in the CodeCache. | |
885 // If the code buffer is created on each compile attempt | |
886 // as in C2, then it must be freed. | |
887 code_buffer->free_blob(); | |
888 return; | |
889 } | |
890 | |
891 assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); | |
892 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); | |
893 | |
894 nm = nmethod::new_nmethod(method, | |
895 compile_id(), | |
896 entry_bci, | |
897 offsets, | |
898 orig_pc_offset, | |
899 debug_info(), dependencies(), code_buffer, | |
900 frame_words, oop_map_set, | |
901 handler_table, inc_table, | |
902 compiler, comp_level); | |
903 | |
904 // Free codeBlobs | |
905 code_buffer->free_blob(); | |
906 | |
907 // stress test 6243940 by immediately making the method | |
908 // non-entrant behind the system's back. This has serious | |
909 // side effects on the code cache and is not meant for | |
910 // general stress testing | |
911 if (nm != NULL && StressNonEntrant) { | |
912 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); | |
913 NativeJump::patch_verified_entry(nm->entry_point(), nm->verified_entry_point(), | |
914 SharedRuntime::get_handle_wrong_method_stub()); | |
915 } | |
916 | |
917 if (nm == NULL) { | |
918 // The CodeCache is full. Print out warning and disable compilation. | |
919 record_failure("code cache is full"); | |
920 UseInterpreter = true; | |
921 if (UseCompiler || AlwaysCompileLoopMethods ) { | |
922 #ifndef PRODUCT | |
923 warning("CodeCache is full. Compiler has been disabled"); | |
924 if (CompileTheWorld || ExitOnFullCodeCache) { | |
925 before_exit(JavaThread::current()); | |
926 exit_globals(); // will delete tty | |
927 vm_direct_exit(CompileTheWorld ? 0 : 1); | |
928 } | |
929 #endif | |
930 UseCompiler = false; | |
931 AlwaysCompileLoopMethods = false; | |
932 } | |
933 } else { | |
934 NOT_PRODUCT(nm->set_has_debug_info(has_debug_info); ) | |
935 nm->set_has_unsafe_access(has_unsafe_access); | |
936 | |
937 // Record successful registration. | |
938 // (Put nm into the task handle *before* publishing to the Java heap.) | |
939 if (task() != NULL) task()->set_code(nm); | |
940 | |
941 if (entry_bci == InvocationEntryBci) { | |
942 #ifdef TIERED | |
943 // If there is an old version we're done with it | |
944 nmethod* old = method->code(); | |
945 if (TraceMethodReplacement && old != NULL) { | |
946 ResourceMark rm; | |
947 char *method_name = method->name_and_sig_as_C_string(); | |
948 tty->print_cr("Replacing method %s", method_name); | |
949 } | |
950 if (old != NULL ) { | |
951 old->make_not_entrant(); | |
952 } | |
953 #endif // TIERED | |
954 if (TraceNMethodInstalls ) { | |
955 ResourceMark rm; | |
956 char *method_name = method->name_and_sig_as_C_string(); | |
957 ttyLocker ttyl; | |
958 tty->print_cr("Installing method (%d) %s ", | |
959 comp_level, | |
960 method_name); | |
961 } | |
962 // Allow the code to be executed | |
963 method->set_code(method, nm); | |
964 } else { | |
965 if (TraceNMethodInstalls ) { | |
966 ResourceMark rm; | |
967 char *method_name = method->name_and_sig_as_C_string(); | |
968 ttyLocker ttyl; | |
969 tty->print_cr("Installing osr method (%d) %s @ %d", | |
970 comp_level, | |
971 method_name, | |
972 entry_bci); | |
973 } | |
974 instanceKlass::cast(method->method_holder())->add_osr_nmethod(nm); | |
975 | |
976 } | |
977 } | |
978 } | |
979 // JVMTI -- compiled method notification (must be done outside lock) | |
980 if (nm != NULL) { | |
981 nm->post_compiled_method_load_event(); | |
982 } | |
983 | |
984 } | |
985 | |
986 | |
987 // ------------------------------------------------------------------ | |
988 // ciEnv::find_system_klass | |
989 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { | |
990 VM_ENTRY_MARK; | |
991 return get_klass_by_name_impl(NULL, klass_name, false); | |
992 } | |
993 | |
994 // ------------------------------------------------------------------ | |
995 // ciEnv::comp_level | |
996 int ciEnv::comp_level() { | |
997 if (task() == NULL) return CompLevel_full_optimization; | |
998 return task()->comp_level(); | |
999 } | |
1000 | |
1001 // ------------------------------------------------------------------ | |
1002 // ciEnv::compile_id | |
1003 uint ciEnv::compile_id() { | |
1004 if (task() == NULL) return 0; | |
1005 return task()->compile_id(); | |
1006 } | |
1007 | |
1008 // ------------------------------------------------------------------ | |
1009 // ciEnv::notice_inlined_method() | |
1010 void ciEnv::notice_inlined_method(ciMethod* method) { | |
1011 _num_inlined_bytecodes += method->code_size(); | |
1012 } | |
1013 | |
1014 // ------------------------------------------------------------------ | |
1015 // ciEnv::num_inlined_bytecodes() | |
1016 int ciEnv::num_inlined_bytecodes() const { | |
1017 return _num_inlined_bytecodes; | |
1018 } | |
1019 | |
1020 // ------------------------------------------------------------------ | |
1021 // ciEnv::record_failure() | |
1022 void ciEnv::record_failure(const char* reason) { | |
1023 if (log() != NULL) { | |
1024 log()->elem("failure reason='%s'", reason); | |
1025 } | |
1026 if (_failure_reason == NULL) { | |
1027 // Record the first failure reason. | |
1028 _failure_reason = reason; | |
1029 } | |
1030 } | |
1031 | |
1032 // ------------------------------------------------------------------ | |
1033 // ciEnv::record_method_not_compilable() | |
1034 void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { | |
1035 int new_compilable = | |
1036 all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; | |
1037 | |
1038 // Only note transitions to a worse state | |
1039 if (new_compilable > _compilable) { | |
1040 if (log() != NULL) { | |
1041 if (all_tiers) { | |
1042 log()->elem("method_not_compilable"); | |
1043 } else { | |
1044 log()->elem("method_not_compilable_at_tier"); | |
1045 } | |
1046 } | |
1047 _compilable = new_compilable; | |
1048 | |
1049 // Reset failure reason; this one is more important. | |
1050 _failure_reason = NULL; | |
1051 record_failure(reason); | |
1052 } | |
1053 } | |
1054 | |
1055 // ------------------------------------------------------------------ | |
1056 // ciEnv::record_out_of_memory_failure() | |
1057 void ciEnv::record_out_of_memory_failure() { | |
1058 // If memory is low, we stop compiling methods. | |
1059 record_method_not_compilable("out of memory"); | |
1060 } |