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