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