Mon, 12 Aug 2019 18:30:40 +0300
8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1999, 2014, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "ci/ciConstant.hpp" |
stefank@2314 | 27 | #include "ci/ciEnv.hpp" |
stefank@2314 | 28 | #include "ci/ciField.hpp" |
stefank@2314 | 29 | #include "ci/ciInstance.hpp" |
stefank@2314 | 30 | #include "ci/ciInstanceKlass.hpp" |
stefank@2314 | 31 | #include "ci/ciMethod.hpp" |
stefank@2314 | 32 | #include "ci/ciNullObject.hpp" |
minqi@4267 | 33 | #include "ci/ciReplay.hpp" |
stefank@2314 | 34 | #include "ci/ciUtilities.hpp" |
stefank@2314 | 35 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 36 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 37 | #include "code/scopeDesc.hpp" |
stefank@2314 | 38 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 39 | #include "compiler/compileLog.hpp" |
stefank@2314 | 40 | #include "compiler/compilerOracle.hpp" |
stefank@2314 | 41 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 42 | #include "interpreter/linkResolver.hpp" |
apetushkov@9858 | 43 | #include "jfr/jfrEvents.hpp" |
stefank@2314 | 44 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 45 | #include "memory/oopFactory.hpp" |
stefank@2314 | 46 | #include "memory/universe.inline.hpp" |
coleenp@4037 | 47 | #include "oops/methodData.hpp" |
stefank@2314 | 48 | #include "oops/objArrayKlass.hpp" |
stefank@2314 | 49 | #include "oops/oop.inline.hpp" |
stefank@2314 | 50 | #include "oops/oop.inline2.hpp" |
stefank@2314 | 51 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 52 | #include "runtime/init.hpp" |
stefank@2314 | 53 | #include "runtime/reflection.hpp" |
stefank@2314 | 54 | #include "runtime/sharedRuntime.hpp" |
goetz@6911 | 55 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 56 | #include "utilities/dtrace.hpp" |
jprovino@4542 | 57 | #include "utilities/macros.hpp" |
stefank@2314 | 58 | #ifdef COMPILER1 |
stefank@2314 | 59 | #include "c1/c1_Runtime1.hpp" |
stefank@2314 | 60 | #endif |
stefank@2314 | 61 | #ifdef COMPILER2 |
stefank@2314 | 62 | #include "opto/runtime.hpp" |
stefank@2314 | 63 | #endif |
duke@435 | 64 | |
duke@435 | 65 | // ciEnv |
duke@435 | 66 | // |
duke@435 | 67 | // This class is the top level broker for requests from the compiler |
duke@435 | 68 | // to the VM. |
duke@435 | 69 | |
duke@435 | 70 | ciObject* ciEnv::_null_object_instance; |
duke@435 | 71 | |
never@1577 | 72 | #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL; |
never@1577 | 73 | WK_KLASSES_DO(WK_KLASS_DEFN) |
never@1577 | 74 | #undef WK_KLASS_DEFN |
duke@435 | 75 | |
duke@435 | 76 | ciSymbol* ciEnv::_unloaded_cisymbol = NULL; |
duke@435 | 77 | ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; |
duke@435 | 78 | ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; |
duke@435 | 79 | |
duke@435 | 80 | jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL; |
duke@435 | 81 | jobject ciEnv::_ArrayStoreException_handle = NULL; |
duke@435 | 82 | jobject ciEnv::_ClassCastException_handle = NULL; |
duke@435 | 83 | |
duke@435 | 84 | #ifndef PRODUCT |
duke@435 | 85 | static bool firstEnv = true; |
duke@435 | 86 | #endif /* PRODUCT */ |
duke@435 | 87 | |
duke@435 | 88 | // ------------------------------------------------------------------ |
duke@435 | 89 | // ciEnv::ciEnv |
zgu@7074 | 90 | ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter) |
zgu@7074 | 91 | : _ciEnv_arena(mtCompiler) { |
duke@435 | 92 | VM_ENTRY_MARK; |
duke@435 | 93 | |
duke@435 | 94 | // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. |
duke@435 | 95 | thread->set_env(this); |
duke@435 | 96 | assert(ciEnv::current() == this, "sanity"); |
duke@435 | 97 | |
duke@435 | 98 | _oop_recorder = NULL; |
duke@435 | 99 | _debug_info = NULL; |
duke@435 | 100 | _dependencies = NULL; |
duke@435 | 101 | _failure_reason = NULL; |
duke@435 | 102 | _compilable = MethodCompilable; |
duke@435 | 103 | _break_at_compile = false; |
duke@435 | 104 | _compiler_data = NULL; |
duke@435 | 105 | #ifndef PRODUCT |
duke@435 | 106 | assert(!firstEnv, "not initialized properly"); |
duke@435 | 107 | #endif /* !PRODUCT */ |
duke@435 | 108 | |
duke@435 | 109 | _system_dictionary_modification_counter = system_dictionary_modification_counter; |
duke@435 | 110 | _num_inlined_bytecodes = 0; |
duke@435 | 111 | assert(task == NULL || thread->task() == task, "sanity"); |
duke@435 | 112 | _task = task; |
duke@435 | 113 | _log = NULL; |
duke@435 | 114 | |
duke@435 | 115 | // Temporary buffer for creating symbols and such. |
duke@435 | 116 | _name_buffer = NULL; |
duke@435 | 117 | _name_buffer_len = 0; |
duke@435 | 118 | |
duke@435 | 119 | _arena = &_ciEnv_arena; |
duke@435 | 120 | _factory = new (_arena) ciObjectFactory(_arena, 128); |
duke@435 | 121 | |
duke@435 | 122 | // Preload commonly referenced system ciObjects. |
duke@435 | 123 | |
duke@435 | 124 | // During VM initialization, these instances have not yet been created. |
duke@435 | 125 | // Assertions ensure that these instances are not accessed before |
duke@435 | 126 | // their initialization. |
duke@435 | 127 | |
duke@435 | 128 | assert(Universe::is_fully_initialized(), "should be complete"); |
duke@435 | 129 | |
duke@435 | 130 | oop o = Universe::null_ptr_exception_instance(); |
duke@435 | 131 | assert(o != NULL, "should have been initialized"); |
duke@435 | 132 | _NullPointerException_instance = get_object(o)->as_instance(); |
duke@435 | 133 | o = Universe::arithmetic_exception_instance(); |
duke@435 | 134 | assert(o != NULL, "should have been initialized"); |
duke@435 | 135 | _ArithmeticException_instance = get_object(o)->as_instance(); |
duke@435 | 136 | |
duke@435 | 137 | _ArrayIndexOutOfBoundsException_instance = NULL; |
duke@435 | 138 | _ArrayStoreException_instance = NULL; |
duke@435 | 139 | _ClassCastException_instance = NULL; |
never@1515 | 140 | _the_null_string = NULL; |
never@1515 | 141 | _the_min_jint_string = NULL; |
duke@435 | 142 | } |
duke@435 | 143 | |
zgu@7074 | 144 | ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) { |
duke@435 | 145 | ASSERT_IN_VM; |
duke@435 | 146 | |
duke@435 | 147 | // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc. |
duke@435 | 148 | CompilerThread* current_thread = CompilerThread::current(); |
duke@435 | 149 | assert(current_thread->env() == NULL, "must be"); |
duke@435 | 150 | current_thread->set_env(this); |
duke@435 | 151 | assert(ciEnv::current() == this, "sanity"); |
duke@435 | 152 | |
duke@435 | 153 | _oop_recorder = NULL; |
duke@435 | 154 | _debug_info = NULL; |
duke@435 | 155 | _dependencies = NULL; |
duke@435 | 156 | _failure_reason = NULL; |
duke@435 | 157 | _compilable = MethodCompilable_never; |
duke@435 | 158 | _break_at_compile = false; |
duke@435 | 159 | _compiler_data = NULL; |
duke@435 | 160 | #ifndef PRODUCT |
duke@435 | 161 | assert(firstEnv, "must be first"); |
duke@435 | 162 | firstEnv = false; |
duke@435 | 163 | #endif /* !PRODUCT */ |
duke@435 | 164 | |
duke@435 | 165 | _system_dictionary_modification_counter = 0; |
duke@435 | 166 | _num_inlined_bytecodes = 0; |
duke@435 | 167 | _task = NULL; |
duke@435 | 168 | _log = NULL; |
duke@435 | 169 | |
duke@435 | 170 | // Temporary buffer for creating symbols and such. |
duke@435 | 171 | _name_buffer = NULL; |
duke@435 | 172 | _name_buffer_len = 0; |
duke@435 | 173 | |
duke@435 | 174 | _arena = arena; |
duke@435 | 175 | _factory = new (_arena) ciObjectFactory(_arena, 128); |
duke@435 | 176 | |
duke@435 | 177 | // Preload commonly referenced system ciObjects. |
duke@435 | 178 | |
duke@435 | 179 | // During VM initialization, these instances have not yet been created. |
duke@435 | 180 | // Assertions ensure that these instances are not accessed before |
duke@435 | 181 | // their initialization. |
duke@435 | 182 | |
duke@435 | 183 | assert(Universe::is_fully_initialized(), "must be"); |
duke@435 | 184 | |
coleenp@4037 | 185 | _NullPointerException_instance = NULL; |
coleenp@4037 | 186 | _ArithmeticException_instance = NULL; |
duke@435 | 187 | _ArrayIndexOutOfBoundsException_instance = NULL; |
duke@435 | 188 | _ArrayStoreException_instance = NULL; |
duke@435 | 189 | _ClassCastException_instance = NULL; |
never@1515 | 190 | _the_null_string = NULL; |
never@1515 | 191 | _the_min_jint_string = NULL; |
duke@435 | 192 | } |
duke@435 | 193 | |
duke@435 | 194 | ciEnv::~ciEnv() { |
duke@435 | 195 | CompilerThread* current_thread = CompilerThread::current(); |
coleenp@2497 | 196 | _factory->remove_symbols(); |
coleenp@4037 | 197 | // Need safepoint to clear the env on the thread. RedefineClasses might |
coleenp@4037 | 198 | // be reading it. |
coleenp@4037 | 199 | GUARDED_VM_ENTRY(current_thread->set_env(NULL);) |
duke@435 | 200 | } |
duke@435 | 201 | |
duke@435 | 202 | // ------------------------------------------------------------------ |
kvn@1215 | 203 | // Cache Jvmti state |
kvn@1215 | 204 | void ciEnv::cache_jvmti_state() { |
kvn@1215 | 205 | VM_ENTRY_MARK; |
kvn@1215 | 206 | // Get Jvmti capabilities under lock to get consistant values. |
kvn@1215 | 207 | MutexLocker mu(JvmtiThreadState_lock); |
kvn@1215 | 208 | _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); |
kvn@1215 | 209 | _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); |
dcubed@1648 | 210 | _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); |
kvn@1215 | 211 | } |
kvn@1215 | 212 | |
kvn@1215 | 213 | // ------------------------------------------------------------------ |
kvn@1215 | 214 | // Cache DTrace flags |
kvn@1215 | 215 | void ciEnv::cache_dtrace_flags() { |
kvn@1215 | 216 | // Need lock? |
kvn@1215 | 217 | _dtrace_extended_probes = ExtendedDTraceProbes; |
kvn@1215 | 218 | if (_dtrace_extended_probes) { |
kvn@1215 | 219 | _dtrace_monitor_probes = true; |
kvn@1215 | 220 | _dtrace_method_probes = true; |
kvn@1215 | 221 | _dtrace_alloc_probes = true; |
kvn@1215 | 222 | } else { |
kvn@1215 | 223 | _dtrace_monitor_probes = DTraceMonitorProbes; |
kvn@1215 | 224 | _dtrace_method_probes = DTraceMethodProbes; |
kvn@1215 | 225 | _dtrace_alloc_probes = DTraceAllocProbes; |
kvn@1215 | 226 | } |
kvn@1215 | 227 | } |
kvn@1215 | 228 | |
kvn@1215 | 229 | // ------------------------------------------------------------------ |
duke@435 | 230 | // helper for lazy exception creation |
coleenp@2497 | 231 | ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) { |
duke@435 | 232 | VM_ENTRY_MARK; |
duke@435 | 233 | if (handle == NULL) { |
duke@435 | 234 | // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. |
coleenp@4037 | 235 | Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD); |
duke@435 | 236 | jobject objh = NULL; |
duke@435 | 237 | if (!HAS_PENDING_EXCEPTION && k != NULL) { |
coleenp@4037 | 238 | oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD); |
duke@435 | 239 | if (!HAS_PENDING_EXCEPTION) |
duke@435 | 240 | objh = JNIHandles::make_global(obj); |
duke@435 | 241 | } |
duke@435 | 242 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 243 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 244 | } else { |
duke@435 | 245 | handle = objh; |
duke@435 | 246 | } |
duke@435 | 247 | } |
duke@435 | 248 | oop obj = JNIHandles::resolve(handle); |
duke@435 | 249 | return obj == NULL? NULL: get_object(obj)->as_instance(); |
duke@435 | 250 | } |
duke@435 | 251 | |
duke@435 | 252 | ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { |
duke@435 | 253 | if (_ArrayIndexOutOfBoundsException_instance == NULL) { |
duke@435 | 254 | _ArrayIndexOutOfBoundsException_instance |
duke@435 | 255 | = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, |
coleenp@2497 | 256 | vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
duke@435 | 257 | } |
duke@435 | 258 | return _ArrayIndexOutOfBoundsException_instance; |
duke@435 | 259 | } |
duke@435 | 260 | ciInstance* ciEnv::ArrayStoreException_instance() { |
duke@435 | 261 | if (_ArrayStoreException_instance == NULL) { |
duke@435 | 262 | _ArrayStoreException_instance |
duke@435 | 263 | = get_or_create_exception(_ArrayStoreException_handle, |
coleenp@2497 | 264 | vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 265 | } |
duke@435 | 266 | return _ArrayStoreException_instance; |
duke@435 | 267 | } |
duke@435 | 268 | ciInstance* ciEnv::ClassCastException_instance() { |
duke@435 | 269 | if (_ClassCastException_instance == NULL) { |
duke@435 | 270 | _ClassCastException_instance |
duke@435 | 271 | = get_or_create_exception(_ClassCastException_handle, |
coleenp@2497 | 272 | vmSymbols::java_lang_ClassCastException()); |
duke@435 | 273 | } |
duke@435 | 274 | return _ClassCastException_instance; |
duke@435 | 275 | } |
duke@435 | 276 | |
never@1515 | 277 | ciInstance* ciEnv::the_null_string() { |
never@1515 | 278 | if (_the_null_string == NULL) { |
never@1515 | 279 | VM_ENTRY_MARK; |
never@1515 | 280 | _the_null_string = get_object(Universe::the_null_string())->as_instance(); |
never@1515 | 281 | } |
never@1515 | 282 | return _the_null_string; |
never@1515 | 283 | } |
never@1515 | 284 | |
never@1515 | 285 | ciInstance* ciEnv::the_min_jint_string() { |
never@1515 | 286 | if (_the_min_jint_string == NULL) { |
never@1515 | 287 | VM_ENTRY_MARK; |
never@1515 | 288 | _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance(); |
never@1515 | 289 | } |
never@1515 | 290 | return _the_min_jint_string; |
never@1515 | 291 | } |
never@1515 | 292 | |
duke@435 | 293 | // ------------------------------------------------------------------ |
duke@435 | 294 | // ciEnv::get_method_from_handle |
coleenp@4037 | 295 | ciMethod* ciEnv::get_method_from_handle(Method* method) { |
duke@435 | 296 | VM_ENTRY_MARK; |
coleenp@4037 | 297 | return get_metadata(method)->as_method(); |
duke@435 | 298 | } |
duke@435 | 299 | |
duke@435 | 300 | // ------------------------------------------------------------------ |
duke@435 | 301 | // ciEnv::array_element_offset_in_bytes |
duke@435 | 302 | int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) { |
duke@435 | 303 | VM_ENTRY_MARK; |
duke@435 | 304 | objArrayOop a = (objArrayOop)a_h->get_oop(); |
duke@435 | 305 | assert(a->is_objArray(), ""); |
duke@435 | 306 | int length = a->length(); |
duke@435 | 307 | oop o = o_h->get_oop(); |
duke@435 | 308 | for (int i = 0; i < length; i++) { |
duke@435 | 309 | if (a->obj_at(i) == o) return i; |
duke@435 | 310 | } |
duke@435 | 311 | return -1; |
duke@435 | 312 | } |
duke@435 | 313 | |
duke@435 | 314 | |
duke@435 | 315 | // ------------------------------------------------------------------ |
duke@435 | 316 | // ciEnv::check_klass_accessiblity |
duke@435 | 317 | // |
duke@435 | 318 | // Note: the logic of this method should mirror the logic of |
coleenp@4037 | 319 | // ConstantPool::verify_constant_pool_resolve. |
duke@435 | 320 | bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, |
coleenp@4037 | 321 | Klass* resolved_klass) { |
duke@435 | 322 | if (accessing_klass == NULL || !accessing_klass->is_loaded()) { |
duke@435 | 323 | return true; |
duke@435 | 324 | } |
coleenp@4037 | 325 | if (accessing_klass->is_obj_array_klass()) { |
duke@435 | 326 | accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass(); |
duke@435 | 327 | } |
duke@435 | 328 | if (!accessing_klass->is_instance_klass()) { |
duke@435 | 329 | return true; |
duke@435 | 330 | } |
duke@435 | 331 | |
coleenp@4037 | 332 | if (resolved_klass->oop_is_objArray()) { |
duke@435 | 333 | // Find the element klass, if this is an array. |
coleenp@4142 | 334 | resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); |
duke@435 | 335 | } |
coleenp@4037 | 336 | if (resolved_klass->oop_is_instance()) { |
coleenp@4037 | 337 | return Reflection::verify_class_access(accessing_klass->get_Klass(), |
duke@435 | 338 | resolved_klass, |
duke@435 | 339 | true); |
duke@435 | 340 | } |
duke@435 | 341 | return true; |
duke@435 | 342 | } |
duke@435 | 343 | |
duke@435 | 344 | // ------------------------------------------------------------------ |
duke@435 | 345 | // ciEnv::get_klass_by_name_impl |
duke@435 | 346 | ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass, |
jrose@2982 | 347 | constantPoolHandle cpool, |
duke@435 | 348 | ciSymbol* name, |
duke@435 | 349 | bool require_local) { |
duke@435 | 350 | ASSERT_IN_VM; |
duke@435 | 351 | EXCEPTION_CONTEXT; |
duke@435 | 352 | |
duke@435 | 353 | // Now we need to check the SystemDictionary |
coleenp@2497 | 354 | Symbol* sym = name->get_symbol(); |
duke@435 | 355 | if (sym->byte_at(0) == 'L' && |
duke@435 | 356 | sym->byte_at(sym->utf8_length()-1) == ';') { |
duke@435 | 357 | // This is a name from a signature. Strip off the trimmings. |
coleenp@2497 | 358 | // Call recursive to keep scope of strippedsym. |
coleenp@2497 | 359 | TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, |
coleenp@2497 | 360 | sym->utf8_length()-2, |
coleenp@2497 | 361 | KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); |
coleenp@2497 | 362 | ciSymbol* strippedname = get_symbol(strippedsym); |
jrose@2982 | 363 | return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local); |
duke@435 | 364 | } |
duke@435 | 365 | |
duke@435 | 366 | // Check for prior unloaded klass. The SystemDictionary's answers |
duke@435 | 367 | // can vary over time but the compiler needs consistency. |
duke@435 | 368 | ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); |
duke@435 | 369 | if (unloaded_klass != NULL) { |
duke@435 | 370 | if (require_local) return NULL; |
duke@435 | 371 | return unloaded_klass; |
duke@435 | 372 | } |
duke@435 | 373 | |
duke@435 | 374 | Handle loader(THREAD, (oop)NULL); |
duke@435 | 375 | Handle domain(THREAD, (oop)NULL); |
duke@435 | 376 | if (accessing_klass != NULL) { |
duke@435 | 377 | loader = Handle(THREAD, accessing_klass->loader()); |
duke@435 | 378 | domain = Handle(THREAD, accessing_klass->protection_domain()); |
duke@435 | 379 | } |
duke@435 | 380 | |
duke@435 | 381 | // setup up the proper type to return on OOM |
duke@435 | 382 | ciKlass* fail_type; |
duke@435 | 383 | if (sym->byte_at(0) == '[') { |
duke@435 | 384 | fail_type = _unloaded_ciobjarrayklass; |
duke@435 | 385 | } else { |
duke@435 | 386 | fail_type = _unloaded_ciinstance_klass; |
duke@435 | 387 | } |
kamg@2467 | 388 | KlassHandle found_klass; |
never@2551 | 389 | { |
never@2570 | 390 | ttyUnlocker ttyul; // release tty lock to avoid ordering problems |
never@2551 | 391 | MutexLocker ml(Compile_lock); |
coleenp@4037 | 392 | Klass* kls; |
never@2551 | 393 | if (!require_local) { |
never@2551 | 394 | kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, |
never@2551 | 395 | KILL_COMPILE_ON_FATAL_(fail_type)); |
never@2551 | 396 | } else { |
never@2551 | 397 | kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, |
never@2551 | 398 | KILL_COMPILE_ON_FATAL_(fail_type)); |
never@2551 | 399 | } |
kamg@2467 | 400 | found_klass = KlassHandle(THREAD, kls); |
duke@435 | 401 | } |
duke@435 | 402 | |
duke@435 | 403 | // If we fail to find an array klass, look again for its element type. |
duke@435 | 404 | // The element type may be available either locally or via constraints. |
duke@435 | 405 | // In either case, if we can find the element type in the system dictionary, |
duke@435 | 406 | // we must build an array type around it. The CI requires array klasses |
duke@435 | 407 | // to be loaded if their element klasses are loaded, except when memory |
duke@435 | 408 | // is exhausted. |
duke@435 | 409 | if (sym->byte_at(0) == '[' && |
duke@435 | 410 | (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { |
duke@435 | 411 | // We have an unloaded array. |
duke@435 | 412 | // Build it on the fly if the element class exists. |
coleenp@2497 | 413 | TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, |
coleenp@2497 | 414 | sym->utf8_length()-1, |
coleenp@2497 | 415 | KILL_COMPILE_ON_FATAL_(fail_type)); |
coleenp@2497 | 416 | |
duke@435 | 417 | // Get element ciKlass recursively. |
duke@435 | 418 | ciKlass* elem_klass = |
duke@435 | 419 | get_klass_by_name_impl(accessing_klass, |
jrose@2982 | 420 | cpool, |
coleenp@2497 | 421 | get_symbol(elem_sym), |
duke@435 | 422 | require_local); |
duke@435 | 423 | if (elem_klass != NULL && elem_klass->is_loaded()) { |
duke@435 | 424 | // Now make an array for it |
duke@435 | 425 | return ciObjArrayKlass::make_impl(elem_klass); |
duke@435 | 426 | } |
duke@435 | 427 | } |
duke@435 | 428 | |
jrose@2982 | 429 | if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) { |
jrose@2982 | 430 | // Look inside the constant pool for pre-resolved class entries. |
jrose@2982 | 431 | for (int i = cpool->length() - 1; i >= 1; i--) { |
jrose@2982 | 432 | if (cpool->tag_at(i).is_klass()) { |
coleenp@4037 | 433 | Klass* kls = cpool->resolved_klass_at(i); |
hseigel@4278 | 434 | if (kls->name() == sym) { |
jrose@2982 | 435 | found_klass = KlassHandle(THREAD, kls); |
jrose@2982 | 436 | break; |
jrose@2982 | 437 | } |
jrose@2982 | 438 | } |
jrose@2982 | 439 | } |
jrose@2982 | 440 | } |
jrose@2982 | 441 | |
kamg@2467 | 442 | if (found_klass() != NULL) { |
jrose@1424 | 443 | // Found it. Build a CI handle. |
coleenp@4037 | 444 | return get_klass(found_klass()); |
jrose@1424 | 445 | } |
jrose@1424 | 446 | |
duke@435 | 447 | if (require_local) return NULL; |
twisti@3197 | 448 | |
duke@435 | 449 | // Not yet loaded into the VM, or not governed by loader constraints. |
duke@435 | 450 | // Make a CI representative for it. |
duke@435 | 451 | return get_unloaded_klass(accessing_klass, name); |
duke@435 | 452 | } |
duke@435 | 453 | |
duke@435 | 454 | // ------------------------------------------------------------------ |
duke@435 | 455 | // ciEnv::get_klass_by_name |
duke@435 | 456 | ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, |
duke@435 | 457 | ciSymbol* klass_name, |
duke@435 | 458 | bool require_local) { |
duke@435 | 459 | GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, |
jrose@2982 | 460 | constantPoolHandle(), |
duke@435 | 461 | klass_name, |
duke@435 | 462 | require_local);) |
duke@435 | 463 | } |
duke@435 | 464 | |
duke@435 | 465 | // ------------------------------------------------------------------ |
duke@435 | 466 | // ciEnv::get_klass_by_index_impl |
duke@435 | 467 | // |
duke@435 | 468 | // Implementation of get_klass_by_index. |
twisti@1573 | 469 | ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool, |
duke@435 | 470 | int index, |
twisti@1573 | 471 | bool& is_accessible, |
twisti@1573 | 472 | ciInstanceKlass* accessor) { |
duke@435 | 473 | EXCEPTION_CONTEXT; |
coleenp@4037 | 474 | KlassHandle klass; // = NULL; |
coleenp@2497 | 475 | Symbol* klass_name = NULL; |
coleenp@4037 | 476 | |
coleenp@4037 | 477 | if (cpool->tag_at(index).is_symbol()) { |
coleenp@4037 | 478 | klass_name = cpool->symbol_at(index); |
coleenp@4037 | 479 | } else { |
coleenp@4037 | 480 | // Check if it's resolved if it's not a symbol constant pool entry. |
coleenp@4037 | 481 | klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); |
coleenp@4037 | 482 | |
duke@435 | 483 | if (klass.is_null()) { |
duke@435 | 484 | // The klass has not been inserted into the constant pool. |
duke@435 | 485 | // Try to look it up by name. |
duke@435 | 486 | { |
duke@435 | 487 | // We have to lock the cpool to keep the oop from being resolved |
duke@435 | 488 | // while we are accessing it. |
iklam@5971 | 489 | MonitorLockerEx ml(cpool->lock()); |
duke@435 | 490 | constantTag tag = cpool->tag_at(index); |
duke@435 | 491 | if (tag.is_klass()) { |
duke@435 | 492 | // The klass has been inserted into the constant pool |
duke@435 | 493 | // very recently. |
duke@435 | 494 | klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); |
duke@435 | 495 | } else { |
duke@435 | 496 | assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); |
coleenp@2497 | 497 | klass_name = cpool->unresolved_klass_at(index); |
duke@435 | 498 | } |
duke@435 | 499 | } |
duke@435 | 500 | } |
coleenp@4037 | 501 | } |
duke@435 | 502 | |
duke@435 | 503 | if (klass.is_null()) { |
duke@435 | 504 | // Not found in constant pool. Use the name to do the lookup. |
duke@435 | 505 | ciKlass* k = get_klass_by_name_impl(accessor, |
jrose@2982 | 506 | cpool, |
coleenp@2497 | 507 | get_symbol(klass_name), |
duke@435 | 508 | false); |
duke@435 | 509 | // Calculate accessibility the hard way. |
duke@435 | 510 | if (!k->is_loaded()) { |
duke@435 | 511 | is_accessible = false; |
duke@435 | 512 | } else if (k->loader() != accessor->loader() && |
jrose@2982 | 513 | get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { |
duke@435 | 514 | // Loaded only remotely. Not linked yet. |
duke@435 | 515 | is_accessible = false; |
duke@435 | 516 | } else { |
duke@435 | 517 | // Linked locally, and we must also check public/private, etc. |
coleenp@4037 | 518 | is_accessible = check_klass_accessibility(accessor, k->get_Klass()); |
duke@435 | 519 | } |
duke@435 | 520 | return k; |
duke@435 | 521 | } |
duke@435 | 522 | |
duke@435 | 523 | // Check for prior unloaded klass. The SystemDictionary's answers |
duke@435 | 524 | // can vary over time but the compiler needs consistency. |
coleenp@4037 | 525 | ciSymbol* name = get_symbol(klass()->name()); |
duke@435 | 526 | ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); |
duke@435 | 527 | if (unloaded_klass != NULL) { |
duke@435 | 528 | is_accessible = false; |
duke@435 | 529 | return unloaded_klass; |
duke@435 | 530 | } |
duke@435 | 531 | |
duke@435 | 532 | // It is known to be accessible, since it was found in the constant pool. |
duke@435 | 533 | is_accessible = true; |
coleenp@4037 | 534 | return get_klass(klass()); |
duke@435 | 535 | } |
duke@435 | 536 | |
duke@435 | 537 | // ------------------------------------------------------------------ |
duke@435 | 538 | // ciEnv::get_klass_by_index |
duke@435 | 539 | // |
duke@435 | 540 | // Get a klass from the constant pool. |
twisti@1573 | 541 | ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool, |
duke@435 | 542 | int index, |
twisti@1573 | 543 | bool& is_accessible, |
twisti@1573 | 544 | ciInstanceKlass* accessor) { |
twisti@1573 | 545 | GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) |
duke@435 | 546 | } |
duke@435 | 547 | |
duke@435 | 548 | // ------------------------------------------------------------------ |
duke@435 | 549 | // ciEnv::get_constant_by_index_impl |
duke@435 | 550 | // |
duke@435 | 551 | // Implementation of get_constant_by_index(). |
twisti@1573 | 552 | ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, |
jrose@1957 | 553 | int pool_index, int cache_index, |
twisti@1573 | 554 | ciInstanceKlass* accessor) { |
jrose@1957 | 555 | bool ignore_will_link; |
duke@435 | 556 | EXCEPTION_CONTEXT; |
jrose@1957 | 557 | int index = pool_index; |
jrose@1957 | 558 | if (cache_index >= 0) { |
jrose@1957 | 559 | assert(index < 0, "only one kind of index at a time"); |
coleenp@4037 | 560 | oop obj = cpool->resolved_references()->obj_at(cache_index); |
jrose@1957 | 561 | if (obj != NULL) { |
jrose@1957 | 562 | ciObject* ciobj = get_object(obj); |
vlivanov@7288 | 563 | if (ciobj->is_array()) { |
vlivanov@7288 | 564 | return ciConstant(T_ARRAY, ciobj); |
vlivanov@7288 | 565 | } else { |
vlivanov@7288 | 566 | assert(ciobj->is_instance(), "should be an instance"); |
vlivanov@7288 | 567 | return ciConstant(T_OBJECT, ciobj); |
vlivanov@7288 | 568 | } |
jrose@1957 | 569 | } |
coleenp@4037 | 570 | index = cpool->object_to_cp_index(cache_index); |
jrose@1957 | 571 | } |
duke@435 | 572 | constantTag tag = cpool->tag_at(index); |
duke@435 | 573 | if (tag.is_int()) { |
duke@435 | 574 | return ciConstant(T_INT, (jint)cpool->int_at(index)); |
duke@435 | 575 | } else if (tag.is_long()) { |
duke@435 | 576 | return ciConstant((jlong)cpool->long_at(index)); |
duke@435 | 577 | } else if (tag.is_float()) { |
duke@435 | 578 | return ciConstant((jfloat)cpool->float_at(index)); |
duke@435 | 579 | } else if (tag.is_double()) { |
duke@435 | 580 | return ciConstant((jdouble)cpool->double_at(index)); |
coleenp@4037 | 581 | } else if (tag.is_string()) { |
jrose@866 | 582 | oop string = NULL; |
coleenp@4037 | 583 | assert(cache_index >= 0, "should have a cache index"); |
jrose@866 | 584 | if (cpool->is_pseudo_string_at(index)) { |
coleenp@4037 | 585 | string = cpool->pseudo_string_at(index, cache_index); |
jrose@866 | 586 | } else { |
coleenp@4037 | 587 | string = cpool->string_at(index, cache_index, THREAD); |
jrose@866 | 588 | if (HAS_PENDING_EXCEPTION) { |
jrose@866 | 589 | CLEAR_PENDING_EXCEPTION; |
jrose@866 | 590 | record_out_of_memory_failure(); |
jrose@866 | 591 | return ciConstant(); |
jrose@866 | 592 | } |
duke@435 | 593 | } |
duke@435 | 594 | ciObject* constant = get_object(string); |
vlivanov@7288 | 595 | if (constant->is_array()) { |
vlivanov@7288 | 596 | return ciConstant(T_ARRAY, constant); |
vlivanov@7288 | 597 | } else { |
vlivanov@7288 | 598 | assert (constant->is_instance(), "must be an instance, or not? "); |
vlivanov@7288 | 599 | return ciConstant(T_OBJECT, constant); |
vlivanov@7288 | 600 | } |
duke@435 | 601 | } else if (tag.is_klass() || tag.is_unresolved_klass()) { |
duke@435 | 602 | // 4881222: allow ldc to take a class type |
jrose@1957 | 603 | ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor); |
duke@435 | 604 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 605 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 606 | record_out_of_memory_failure(); |
duke@435 | 607 | return ciConstant(); |
duke@435 | 608 | } |
duke@435 | 609 | assert (klass->is_instance_klass() || klass->is_array_klass(), |
duke@435 | 610 | "must be an instance or array klass "); |
jrose@1957 | 611 | return ciConstant(T_OBJECT, klass->java_mirror()); |
jrose@1957 | 612 | } else if (tag.is_method_type()) { |
jrose@1957 | 613 | // must execute Java code to link this CP entry into cache[i].f1 |
coleenp@2497 | 614 | ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index)); |
jrose@1957 | 615 | ciObject* ciobj = get_unloaded_method_type_constant(signature); |
jrose@1957 | 616 | return ciConstant(T_OBJECT, ciobj); |
jrose@1957 | 617 | } else if (tag.is_method_handle()) { |
jrose@1957 | 618 | // must execute Java code to link this CP entry into cache[i].f1 |
jrose@1957 | 619 | int ref_kind = cpool->method_handle_ref_kind_at(index); |
jrose@1957 | 620 | int callee_index = cpool->method_handle_klass_index_at(index); |
jrose@1957 | 621 | ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); |
coleenp@2497 | 622 | ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index)); |
coleenp@2497 | 623 | ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index)); |
jrose@1957 | 624 | ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); |
jrose@1957 | 625 | return ciConstant(T_OBJECT, ciobj); |
duke@435 | 626 | } else { |
duke@435 | 627 | ShouldNotReachHere(); |
duke@435 | 628 | return ciConstant(); |
duke@435 | 629 | } |
duke@435 | 630 | } |
duke@435 | 631 | |
duke@435 | 632 | // ------------------------------------------------------------------ |
duke@435 | 633 | // ciEnv::get_constant_by_index |
duke@435 | 634 | // |
duke@435 | 635 | // Pull a constant out of the constant pool. How appropriate. |
duke@435 | 636 | // |
duke@435 | 637 | // Implementation note: this query is currently in no way cached. |
twisti@1573 | 638 | ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, |
jrose@1957 | 639 | int pool_index, int cache_index, |
twisti@1573 | 640 | ciInstanceKlass* accessor) { |
jrose@1957 | 641 | GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);) |
duke@435 | 642 | } |
duke@435 | 643 | |
duke@435 | 644 | // ------------------------------------------------------------------ |
duke@435 | 645 | // ciEnv::get_field_by_index_impl |
duke@435 | 646 | // |
duke@435 | 647 | // Implementation of get_field_by_index. |
duke@435 | 648 | // |
duke@435 | 649 | // Implementation note: the results of field lookups are cached |
duke@435 | 650 | // in the accessor klass. |
duke@435 | 651 | ciField* ciEnv::get_field_by_index_impl(ciInstanceKlass* accessor, |
duke@435 | 652 | int index) { |
duke@435 | 653 | ciConstantPoolCache* cache = accessor->field_cache(); |
duke@435 | 654 | if (cache == NULL) { |
duke@435 | 655 | ciField* field = new (arena()) ciField(accessor, index); |
duke@435 | 656 | return field; |
duke@435 | 657 | } else { |
duke@435 | 658 | ciField* field = (ciField*)cache->get(index); |
duke@435 | 659 | if (field == NULL) { |
duke@435 | 660 | field = new (arena()) ciField(accessor, index); |
duke@435 | 661 | cache->insert(index, field); |
duke@435 | 662 | } |
duke@435 | 663 | return field; |
duke@435 | 664 | } |
duke@435 | 665 | } |
duke@435 | 666 | |
duke@435 | 667 | // ------------------------------------------------------------------ |
duke@435 | 668 | // ciEnv::get_field_by_index |
duke@435 | 669 | // |
duke@435 | 670 | // Get a field by index from a klass's constant pool. |
duke@435 | 671 | ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, |
duke@435 | 672 | int index) { |
duke@435 | 673 | GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) |
duke@435 | 674 | } |
duke@435 | 675 | |
duke@435 | 676 | // ------------------------------------------------------------------ |
duke@435 | 677 | // ciEnv::lookup_method |
duke@435 | 678 | // |
duke@435 | 679 | // Perform an appropriate method lookup based on accessor, holder, |
duke@435 | 680 | // name, signature, and bytecode. |
coleenp@4037 | 681 | Method* ciEnv::lookup_method(InstanceKlass* accessor, |
coleenp@4037 | 682 | InstanceKlass* holder, |
coleenp@2497 | 683 | Symbol* name, |
coleenp@2497 | 684 | Symbol* sig, |
duke@435 | 685 | Bytecodes::Code bc) { |
duke@435 | 686 | EXCEPTION_CONTEXT; |
duke@435 | 687 | KlassHandle h_accessor(THREAD, accessor); |
duke@435 | 688 | KlassHandle h_holder(THREAD, holder); |
duke@435 | 689 | LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); |
duke@435 | 690 | methodHandle dest_method; |
duke@435 | 691 | switch (bc) { |
duke@435 | 692 | case Bytecodes::_invokestatic: |
duke@435 | 693 | dest_method = |
coleenp@2497 | 694 | LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor); |
duke@435 | 695 | break; |
duke@435 | 696 | case Bytecodes::_invokespecial: |
duke@435 | 697 | dest_method = |
coleenp@2497 | 698 | LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor); |
duke@435 | 699 | break; |
duke@435 | 700 | case Bytecodes::_invokeinterface: |
duke@435 | 701 | dest_method = |
coleenp@2497 | 702 | LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig, |
duke@435 | 703 | h_accessor, true); |
duke@435 | 704 | break; |
duke@435 | 705 | case Bytecodes::_invokevirtual: |
duke@435 | 706 | dest_method = |
coleenp@2497 | 707 | LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig, |
duke@435 | 708 | h_accessor, true); |
duke@435 | 709 | break; |
duke@435 | 710 | default: ShouldNotReachHere(); |
duke@435 | 711 | } |
duke@435 | 712 | |
duke@435 | 713 | return dest_method(); |
duke@435 | 714 | } |
duke@435 | 715 | |
duke@435 | 716 | |
duke@435 | 717 | // ------------------------------------------------------------------ |
duke@435 | 718 | // ciEnv::get_method_by_index_impl |
twisti@1573 | 719 | ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool, |
twisti@1573 | 720 | int index, Bytecodes::Code bc, |
twisti@1573 | 721 | ciInstanceKlass* accessor) { |
twisti@4021 | 722 | if (bc == Bytecodes::_invokedynamic) { |
coleenp@4037 | 723 | ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); |
coleenp@4037 | 724 | bool is_resolved = !cpce->is_f1_null(); |
twisti@4021 | 725 | // FIXME: code generation could allow for null (unlinked) call site |
twisti@4021 | 726 | // The call site could be made patchable as follows: |
twisti@4021 | 727 | // Load the appendix argument from the constant pool. |
twisti@4021 | 728 | // Test the appendix argument and jump to a known deopt routine if it is null. |
twisti@4021 | 729 | // Jump through a patchable call site, which is initially a deopt routine. |
twisti@4021 | 730 | // Patch the call site to the nmethod entry point of the static compiled lambda form. |
twisti@4021 | 731 | // As with other two-component call sites, both values must be independently verified. |
duke@435 | 732 | |
twisti@4021 | 733 | if (is_resolved) { |
coleenp@4037 | 734 | // Get the invoker Method* from the constant pool. |
coleenp@4037 | 735 | // (The appendix argument, if any, will be noted in the method's signature.) |
coleenp@4037 | 736 | Method* adapter = cpce->f1_as_method(); |
coleenp@4037 | 737 | return get_method(adapter); |
twisti@4021 | 738 | } |
duke@435 | 739 | |
twisti@4021 | 740 | // Fake a method that is equivalent to a declared method. |
coleenp@4037 | 741 | ciInstanceKlass* holder = get_instance_klass(SystemDictionary::MethodHandle_klass()); |
twisti@3969 | 742 | ciSymbol* name = ciSymbol::invokeBasic_name(); |
twisti@3197 | 743 | ciSymbol* signature = get_symbol(cpool->signature_ref_at(index)); |
twisti@3197 | 744 | return get_unloaded_method(holder, name, signature, accessor); |
twisti@4021 | 745 | } else { |
twisti@4021 | 746 | const int holder_index = cpool->klass_ref_index_at(index); |
twisti@4021 | 747 | bool holder_is_accessible; |
twisti@4021 | 748 | ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); |
twisti@4021 | 749 | ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); |
twisti@4021 | 750 | |
twisti@4021 | 751 | // Get the method's name and signature. |
twisti@4021 | 752 | Symbol* name_sym = cpool->name_ref_at(index); |
twisti@4021 | 753 | Symbol* sig_sym = cpool->signature_ref_at(index); |
twisti@4021 | 754 | |
twisti@4021 | 755 | if (cpool->has_preresolution() |
twisti@4021 | 756 | || (holder == ciEnv::MethodHandle_klass() && |
coleenp@4037 | 757 | MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) { |
twisti@4021 | 758 | // Short-circuit lookups for JSR 292-related call sites. |
twisti@4021 | 759 | // That is, do not rely only on name-based lookups, because they may fail |
twisti@4021 | 760 | // if the names are not resolvable in the boot class loader (7056328). |
twisti@4021 | 761 | switch (bc) { |
twisti@4021 | 762 | case Bytecodes::_invokevirtual: |
twisti@4021 | 763 | case Bytecodes::_invokeinterface: |
twisti@4021 | 764 | case Bytecodes::_invokespecial: |
twisti@4021 | 765 | case Bytecodes::_invokestatic: |
twisti@4021 | 766 | { |
coleenp@4037 | 767 | Method* m = ConstantPool::method_at_if_loaded(cpool, index); |
twisti@4021 | 768 | if (m != NULL) { |
coleenp@4037 | 769 | return get_method(m); |
twisti@4021 | 770 | } |
twisti@4021 | 771 | } |
twisti@4021 | 772 | break; |
twisti@4021 | 773 | } |
twisti@4021 | 774 | } |
twisti@4021 | 775 | |
twisti@4021 | 776 | if (holder_is_accessible) { // Our declared holder is loaded. |
coleenp@4037 | 777 | InstanceKlass* lookup = declared_holder->get_instanceKlass(); |
coleenp@4037 | 778 | Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); |
twisti@4021 | 779 | if (m != NULL && |
twisti@4021 | 780 | (bc == Bytecodes::_invokestatic |
coleenp@4251 | 781 | ? m->method_holder()->is_not_initialized() |
coleenp@4251 | 782 | : !m->method_holder()->is_loaded())) { |
twisti@4021 | 783 | m = NULL; |
twisti@4021 | 784 | } |
minqi@4267 | 785 | #ifdef ASSERT |
minqi@4267 | 786 | if (m != NULL && ReplayCompiles && !ciReplay::is_loaded(m)) { |
minqi@4267 | 787 | m = NULL; |
minqi@4267 | 788 | } |
minqi@4267 | 789 | #endif |
twisti@4021 | 790 | if (m != NULL) { |
twisti@4021 | 791 | // We found the method. |
coleenp@4037 | 792 | return get_method(m); |
twisti@4021 | 793 | } |
twisti@4021 | 794 | } |
twisti@4021 | 795 | |
twisti@4021 | 796 | // Either the declared holder was not loaded, or the method could |
twisti@4021 | 797 | // not be found. Create a dummy ciMethod to represent the failed |
twisti@4021 | 798 | // lookup. |
twisti@4021 | 799 | ciSymbol* name = get_symbol(name_sym); |
twisti@4021 | 800 | ciSymbol* signature = get_symbol(sig_sym); |
twisti@4021 | 801 | return get_unloaded_method(declared_holder, name, signature, accessor); |
twisti@1572 | 802 | } |
twisti@1572 | 803 | } |
twisti@1572 | 804 | |
twisti@1572 | 805 | |
twisti@1572 | 806 | // ------------------------------------------------------------------ |
duke@435 | 807 | // ciEnv::get_instance_klass_for_declared_method_holder |
duke@435 | 808 | ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) { |
duke@435 | 809 | // For the case of <array>.clone(), the method holder can be a ciArrayKlass |
duke@435 | 810 | // instead of a ciInstanceKlass. For that case simply pretend that the |
duke@435 | 811 | // declared holder is Object.clone since that's where the call will bottom out. |
duke@435 | 812 | // A more correct fix would trickle out through many interfaces in CI, |
duke@435 | 813 | // requiring ciInstanceKlass* to become ciKlass* and many more places would |
duke@435 | 814 | // require checks to make sure the expected type was found. Given that this |
duke@435 | 815 | // only occurs for clone() the more extensive fix seems like overkill so |
duke@435 | 816 | // instead we simply smear the array type into Object. |
morris@4777 | 817 | guarantee(method_holder != NULL, "no method holder"); |
duke@435 | 818 | if (method_holder->is_instance_klass()) { |
duke@435 | 819 | return method_holder->as_instance_klass(); |
duke@435 | 820 | } else if (method_holder->is_array_klass()) { |
duke@435 | 821 | return current()->Object_klass(); |
duke@435 | 822 | } else { |
duke@435 | 823 | ShouldNotReachHere(); |
duke@435 | 824 | } |
duke@435 | 825 | return NULL; |
duke@435 | 826 | } |
duke@435 | 827 | |
duke@435 | 828 | |
duke@435 | 829 | // ------------------------------------------------------------------ |
duke@435 | 830 | // ciEnv::get_method_by_index |
twisti@1573 | 831 | ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool, |
twisti@1573 | 832 | int index, Bytecodes::Code bc, |
twisti@1573 | 833 | ciInstanceKlass* accessor) { |
twisti@4021 | 834 | GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);) |
duke@435 | 835 | } |
duke@435 | 836 | |
twisti@1572 | 837 | |
duke@435 | 838 | // ------------------------------------------------------------------ |
duke@435 | 839 | // ciEnv::name_buffer |
duke@435 | 840 | char *ciEnv::name_buffer(int req_len) { |
duke@435 | 841 | if (_name_buffer_len < req_len) { |
duke@435 | 842 | if (_name_buffer == NULL) { |
duke@435 | 843 | _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len); |
duke@435 | 844 | _name_buffer_len = req_len; |
duke@435 | 845 | } else { |
duke@435 | 846 | _name_buffer = |
duke@435 | 847 | (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len); |
duke@435 | 848 | _name_buffer_len = req_len; |
duke@435 | 849 | } |
duke@435 | 850 | } |
duke@435 | 851 | return _name_buffer; |
duke@435 | 852 | } |
duke@435 | 853 | |
duke@435 | 854 | // ------------------------------------------------------------------ |
duke@435 | 855 | // ciEnv::is_in_vm |
duke@435 | 856 | bool ciEnv::is_in_vm() { |
duke@435 | 857 | return JavaThread::current()->thread_state() == _thread_in_vm; |
duke@435 | 858 | } |
duke@435 | 859 | |
duke@435 | 860 | bool ciEnv::system_dictionary_modification_counter_changed() { |
duke@435 | 861 | return _system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); |
duke@435 | 862 | } |
duke@435 | 863 | |
duke@435 | 864 | // ------------------------------------------------------------------ |
twisti@3094 | 865 | // ciEnv::validate_compile_task_dependencies |
twisti@3094 | 866 | // |
twisti@3094 | 867 | // Check for changes during compilation (e.g. class loads, evolution, |
twisti@3094 | 868 | // breakpoints, call site invalidation). |
twisti@3094 | 869 | void ciEnv::validate_compile_task_dependencies(ciMethod* target) { |
duke@435 | 870 | if (failing()) return; // no need for further checks |
duke@435 | 871 | |
twisti@3094 | 872 | // First, check non-klass dependencies as we might return early and |
twisti@3094 | 873 | // not check klass dependencies if the system dictionary |
twisti@3094 | 874 | // modification counter hasn't changed (see below). |
twisti@3094 | 875 | for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { |
twisti@3094 | 876 | if (deps.is_klass_type()) continue; // skip klass dependencies |
coleenp@4037 | 877 | Klass* witness = deps.check_dependency(); |
twisti@3094 | 878 | if (witness != NULL) { |
twisti@3094 | 879 | record_failure("invalid non-klass dependency"); |
twisti@3094 | 880 | return; |
twisti@3094 | 881 | } |
twisti@3094 | 882 | } |
duke@435 | 883 | |
twisti@3094 | 884 | // Klass dependencies must be checked when the system dictionary |
twisti@3094 | 885 | // changes. If logging is enabled all violated dependences will be |
twisti@3094 | 886 | // recorded in the log. In debug mode check dependencies even if |
twisti@3094 | 887 | // the system dictionary hasn't changed to verify that no invalid |
twisti@3094 | 888 | // dependencies were inserted. Any violated dependences in this |
twisti@3094 | 889 | // case are dumped to the tty. |
duke@435 | 890 | bool counter_changed = system_dictionary_modification_counter_changed(); |
duke@435 | 891 | |
never@3155 | 892 | bool verify_deps = trueInDebug; |
never@3155 | 893 | if (!counter_changed && !verify_deps) return; |
never@3155 | 894 | |
twisti@3094 | 895 | int klass_violations = 0; |
duke@435 | 896 | for (Dependencies::DepStream deps(dependencies()); deps.next(); ) { |
twisti@3094 | 897 | if (!deps.is_klass_type()) continue; // skip non-klass dependencies |
coleenp@4037 | 898 | Klass* witness = deps.check_dependency(); |
duke@435 | 899 | if (witness != NULL) { |
twisti@3094 | 900 | klass_violations++; |
never@3155 | 901 | if (!counter_changed) { |
never@3155 | 902 | // Dependence failed but counter didn't change. Log a message |
never@3155 | 903 | // describing what failed and allow the assert at the end to |
never@3155 | 904 | // trigger. |
never@3155 | 905 | deps.print_dependency(witness); |
never@3155 | 906 | } else if (xtty == NULL) { |
never@3155 | 907 | // If we're not logging then a single violation is sufficient, |
never@3155 | 908 | // otherwise we want to log all the dependences which were |
never@3155 | 909 | // violated. |
never@3155 | 910 | break; |
never@3155 | 911 | } |
duke@435 | 912 | } |
duke@435 | 913 | } |
duke@435 | 914 | |
twisti@3094 | 915 | if (klass_violations != 0) { |
never@3155 | 916 | #ifdef ASSERT |
never@3155 | 917 | if (!counter_changed && !PrintCompilation) { |
never@3155 | 918 | // Print out the compile task that failed |
never@3155 | 919 | _task->print_line(); |
never@3155 | 920 | } |
never@3155 | 921 | #endif |
duke@435 | 922 | assert(counter_changed, "failed dependencies, but counter didn't change"); |
duke@435 | 923 | record_failure("concurrent class loading"); |
duke@435 | 924 | } |
duke@435 | 925 | } |
duke@435 | 926 | |
duke@435 | 927 | // ------------------------------------------------------------------ |
duke@435 | 928 | // ciEnv::register_method |
duke@435 | 929 | void ciEnv::register_method(ciMethod* target, |
duke@435 | 930 | int entry_bci, |
duke@435 | 931 | CodeOffsets* offsets, |
duke@435 | 932 | int orig_pc_offset, |
duke@435 | 933 | CodeBuffer* code_buffer, |
duke@435 | 934 | int frame_words, |
duke@435 | 935 | OopMapSet* oop_map_set, |
duke@435 | 936 | ExceptionHandlerTable* handler_table, |
duke@435 | 937 | ImplicitExceptionTable* inc_table, |
duke@435 | 938 | AbstractCompiler* compiler, |
duke@435 | 939 | int comp_level, |
kvn@4103 | 940 | bool has_unsafe_access, |
kvn@6429 | 941 | bool has_wide_vectors, |
kvn@6429 | 942 | RTMState rtm_state) { |
duke@435 | 943 | VM_ENTRY_MARK; |
duke@435 | 944 | nmethod* nm = NULL; |
duke@435 | 945 | { |
duke@435 | 946 | // To prevent compile queue updates. |
duke@435 | 947 | MutexLocker locker(MethodCompileQueue_lock, THREAD); |
duke@435 | 948 | |
duke@435 | 949 | // Prevent SystemDictionary::add_to_hierarchy from running |
duke@435 | 950 | // and invalidating our dependencies until we install this method. |
vlivanov@6096 | 951 | // No safepoints are allowed. Otherwise, class redefinition can occur in between. |
duke@435 | 952 | MutexLocker ml(Compile_lock); |
vlivanov@6096 | 953 | No_Safepoint_Verifier nsv; |
duke@435 | 954 | |
kvn@1215 | 955 | // Change in Jvmti state may invalidate compilation. |
kvn@1215 | 956 | if (!failing() && |
kvn@1215 | 957 | ( (!jvmti_can_hotswap_or_post_breakpoint() && |
kvn@1215 | 958 | JvmtiExport::can_hotswap_or_post_breakpoint()) || |
kvn@1215 | 959 | (!jvmti_can_access_local_variables() && |
kvn@1215 | 960 | JvmtiExport::can_access_local_variables()) || |
dcubed@1648 | 961 | (!jvmti_can_post_on_exceptions() && |
dcubed@1648 | 962 | JvmtiExport::can_post_on_exceptions()) )) { |
kvn@1215 | 963 | record_failure("Jvmti state change invalidated dependencies"); |
duke@435 | 964 | } |
duke@435 | 965 | |
kvn@1215 | 966 | // Change in DTrace flags may invalidate compilation. |
kvn@1215 | 967 | if (!failing() && |
kvn@1215 | 968 | ( (!dtrace_extended_probes() && ExtendedDTraceProbes) || |
kvn@1215 | 969 | (!dtrace_method_probes() && DTraceMethodProbes) || |
kvn@1215 | 970 | (!dtrace_alloc_probes() && DTraceAllocProbes) )) { |
kvn@1215 | 971 | record_failure("DTrace flags change invalidated dependencies"); |
kvn@1215 | 972 | } |
duke@435 | 973 | |
kvn@1215 | 974 | if (!failing()) { |
kvn@1215 | 975 | if (log() != NULL) { |
kvn@1215 | 976 | // Log the dependencies which this compilation declares. |
kvn@1215 | 977 | dependencies()->log_all_dependencies(); |
kvn@1215 | 978 | } |
kvn@1215 | 979 | |
kvn@1215 | 980 | // Encode the dependencies now, so we can check them right away. |
kvn@1215 | 981 | dependencies()->encode_content_bytes(); |
kvn@1215 | 982 | |
twisti@3094 | 983 | // Check for {class loads, evolution, breakpoints, ...} during compilation |
twisti@3094 | 984 | validate_compile_task_dependencies(target); |
kvn@1215 | 985 | } |
duke@435 | 986 | |
coleenp@4037 | 987 | methodHandle method(THREAD, target->get_Method()); |
duke@435 | 988 | |
kvn@6429 | 989 | #if INCLUDE_RTM_OPT |
kvn@6429 | 990 | if (!failing() && (rtm_state != NoRTM) && |
kvn@6429 | 991 | (method()->method_data() != NULL) && |
kvn@6429 | 992 | (method()->method_data()->rtm_state() != rtm_state)) { |
kvn@6429 | 993 | // Preemptive decompile if rtm state was changed. |
kvn@6429 | 994 | record_failure("RTM state change invalidated rtm code"); |
kvn@6429 | 995 | } |
kvn@6429 | 996 | #endif |
kvn@6429 | 997 | |
duke@435 | 998 | if (failing()) { |
duke@435 | 999 | // While not a true deoptimization, it is a preemptive decompile. |
coleenp@4037 | 1000 | MethodData* mdo = method()->method_data(); |
duke@435 | 1001 | if (mdo != NULL) { |
duke@435 | 1002 | mdo->inc_decompile_count(); |
duke@435 | 1003 | } |
duke@435 | 1004 | |
duke@435 | 1005 | // All buffers in the CodeBuffer are allocated in the CodeCache. |
duke@435 | 1006 | // If the code buffer is created on each compile attempt |
duke@435 | 1007 | // as in C2, then it must be freed. |
duke@435 | 1008 | code_buffer->free_blob(); |
duke@435 | 1009 | return; |
duke@435 | 1010 | } |
duke@435 | 1011 | |
duke@435 | 1012 | assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry"); |
duke@435 | 1013 | assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry"); |
duke@435 | 1014 | |
duke@435 | 1015 | nm = nmethod::new_nmethod(method, |
duke@435 | 1016 | compile_id(), |
duke@435 | 1017 | entry_bci, |
duke@435 | 1018 | offsets, |
duke@435 | 1019 | orig_pc_offset, |
duke@435 | 1020 | debug_info(), dependencies(), code_buffer, |
duke@435 | 1021 | frame_words, oop_map_set, |
duke@435 | 1022 | handler_table, inc_table, |
duke@435 | 1023 | compiler, comp_level); |
duke@435 | 1024 | // Free codeBlobs |
duke@435 | 1025 | code_buffer->free_blob(); |
duke@435 | 1026 | |
anoll@6114 | 1027 | if (nm != NULL) { |
duke@435 | 1028 | nm->set_has_unsafe_access(has_unsafe_access); |
kvn@4103 | 1029 | nm->set_has_wide_vectors(has_wide_vectors); |
kvn@6431 | 1030 | #if INCLUDE_RTM_OPT |
kvn@6431 | 1031 | nm->set_rtm_state(rtm_state); |
kvn@6431 | 1032 | #endif |
duke@435 | 1033 | |
duke@435 | 1034 | // Record successful registration. |
duke@435 | 1035 | // (Put nm into the task handle *before* publishing to the Java heap.) |
anoll@6114 | 1036 | if (task() != NULL) { |
anoll@6114 | 1037 | task()->set_code(nm); |
anoll@6114 | 1038 | } |
duke@435 | 1039 | |
duke@435 | 1040 | if (entry_bci == InvocationEntryBci) { |
iveresov@2138 | 1041 | if (TieredCompilation) { |
iveresov@2138 | 1042 | // If there is an old version we're done with it |
iveresov@2138 | 1043 | nmethod* old = method->code(); |
iveresov@2138 | 1044 | if (TraceMethodReplacement && old != NULL) { |
iveresov@2138 | 1045 | ResourceMark rm; |
iveresov@2138 | 1046 | char *method_name = method->name_and_sig_as_C_string(); |
iveresov@2138 | 1047 | tty->print_cr("Replacing method %s", method_name); |
iveresov@2138 | 1048 | } |
vlivanov@6096 | 1049 | if (old != NULL) { |
iveresov@2138 | 1050 | old->make_not_entrant(); |
iveresov@2138 | 1051 | } |
duke@435 | 1052 | } |
vlivanov@6096 | 1053 | if (TraceNMethodInstalls) { |
duke@435 | 1054 | ResourceMark rm; |
duke@435 | 1055 | char *method_name = method->name_and_sig_as_C_string(); |
duke@435 | 1056 | ttyLocker ttyl; |
duke@435 | 1057 | tty->print_cr("Installing method (%d) %s ", |
duke@435 | 1058 | comp_level, |
duke@435 | 1059 | method_name); |
duke@435 | 1060 | } |
duke@435 | 1061 | // Allow the code to be executed |
duke@435 | 1062 | method->set_code(method, nm); |
duke@435 | 1063 | } else { |
vlivanov@6096 | 1064 | if (TraceNMethodInstalls) { |
duke@435 | 1065 | ResourceMark rm; |
duke@435 | 1066 | char *method_name = method->name_and_sig_as_C_string(); |
duke@435 | 1067 | ttyLocker ttyl; |
duke@435 | 1068 | tty->print_cr("Installing osr method (%d) %s @ %d", |
duke@435 | 1069 | comp_level, |
duke@435 | 1070 | method_name, |
duke@435 | 1071 | entry_bci); |
duke@435 | 1072 | } |
coleenp@4251 | 1073 | method->method_holder()->add_osr_nmethod(nm); |
duke@435 | 1074 | } |
duke@435 | 1075 | } |
anoll@6114 | 1076 | } // safepoints are allowed again |
anoll@6114 | 1077 | |
anoll@6114 | 1078 | if (nm != NULL) { |
anoll@6114 | 1079 | // JVMTI -- compiled method notification (must be done outside lock) |
anoll@6114 | 1080 | nm->post_compiled_method_load_event(); |
anoll@6114 | 1081 | } else { |
anoll@6114 | 1082 | // The CodeCache is full. Print out warning and disable compilation. |
anoll@6114 | 1083 | record_failure("code cache is full"); |
anoll@6114 | 1084 | CompileBroker::handle_full_code_cache(); |
duke@435 | 1085 | } |
duke@435 | 1086 | } |
duke@435 | 1087 | |
duke@435 | 1088 | |
duke@435 | 1089 | // ------------------------------------------------------------------ |
duke@435 | 1090 | // ciEnv::find_system_klass |
duke@435 | 1091 | ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) { |
duke@435 | 1092 | VM_ENTRY_MARK; |
jrose@2982 | 1093 | return get_klass_by_name_impl(NULL, constantPoolHandle(), klass_name, false); |
duke@435 | 1094 | } |
duke@435 | 1095 | |
duke@435 | 1096 | // ------------------------------------------------------------------ |
duke@435 | 1097 | // ciEnv::comp_level |
duke@435 | 1098 | int ciEnv::comp_level() { |
iveresov@2138 | 1099 | if (task() == NULL) return CompLevel_highest_tier; |
duke@435 | 1100 | return task()->comp_level(); |
duke@435 | 1101 | } |
duke@435 | 1102 | |
duke@435 | 1103 | // ------------------------------------------------------------------ |
duke@435 | 1104 | // ciEnv::compile_id |
duke@435 | 1105 | uint ciEnv::compile_id() { |
duke@435 | 1106 | if (task() == NULL) return 0; |
duke@435 | 1107 | return task()->compile_id(); |
duke@435 | 1108 | } |
duke@435 | 1109 | |
duke@435 | 1110 | // ------------------------------------------------------------------ |
duke@435 | 1111 | // ciEnv::notice_inlined_method() |
duke@435 | 1112 | void ciEnv::notice_inlined_method(ciMethod* method) { |
twisti@3969 | 1113 | _num_inlined_bytecodes += method->code_size_for_inlining(); |
duke@435 | 1114 | } |
duke@435 | 1115 | |
duke@435 | 1116 | // ------------------------------------------------------------------ |
duke@435 | 1117 | // ciEnv::num_inlined_bytecodes() |
duke@435 | 1118 | int ciEnv::num_inlined_bytecodes() const { |
duke@435 | 1119 | return _num_inlined_bytecodes; |
duke@435 | 1120 | } |
duke@435 | 1121 | |
duke@435 | 1122 | // ------------------------------------------------------------------ |
duke@435 | 1123 | // ciEnv::record_failure() |
duke@435 | 1124 | void ciEnv::record_failure(const char* reason) { |
duke@435 | 1125 | if (_failure_reason == NULL) { |
duke@435 | 1126 | // Record the first failure reason. |
duke@435 | 1127 | _failure_reason = reason; |
duke@435 | 1128 | } |
duke@435 | 1129 | } |
duke@435 | 1130 | |
duke@435 | 1131 | // ------------------------------------------------------------------ |
duke@435 | 1132 | // ciEnv::record_method_not_compilable() |
duke@435 | 1133 | void ciEnv::record_method_not_compilable(const char* reason, bool all_tiers) { |
duke@435 | 1134 | int new_compilable = |
duke@435 | 1135 | all_tiers ? MethodCompilable_never : MethodCompilable_not_at_tier ; |
duke@435 | 1136 | |
duke@435 | 1137 | // Only note transitions to a worse state |
duke@435 | 1138 | if (new_compilable > _compilable) { |
duke@435 | 1139 | if (log() != NULL) { |
duke@435 | 1140 | if (all_tiers) { |
duke@435 | 1141 | log()->elem("method_not_compilable"); |
duke@435 | 1142 | } else { |
vlivanov@4154 | 1143 | log()->elem("method_not_compilable_at_tier level='%d'", |
vlivanov@4154 | 1144 | current()->task()->comp_level()); |
duke@435 | 1145 | } |
duke@435 | 1146 | } |
duke@435 | 1147 | _compilable = new_compilable; |
duke@435 | 1148 | |
duke@435 | 1149 | // Reset failure reason; this one is more important. |
duke@435 | 1150 | _failure_reason = NULL; |
duke@435 | 1151 | record_failure(reason); |
duke@435 | 1152 | } |
duke@435 | 1153 | } |
duke@435 | 1154 | |
duke@435 | 1155 | // ------------------------------------------------------------------ |
duke@435 | 1156 | // ciEnv::record_out_of_memory_failure() |
duke@435 | 1157 | void ciEnv::record_out_of_memory_failure() { |
duke@435 | 1158 | // If memory is low, we stop compiling methods. |
duke@435 | 1159 | record_method_not_compilable("out of memory"); |
duke@435 | 1160 | } |
minqi@4267 | 1161 | |
roland@5628 | 1162 | ciInstance* ciEnv::unloaded_ciinstance() { |
roland@5628 | 1163 | GUARDED_VM_ENTRY(return _factory->get_unloaded_object_constant();) |
roland@5628 | 1164 | } |
roland@5628 | 1165 | |
vlivanov@5904 | 1166 | // ------------------------------------------------------------------ |
vlivanov@5904 | 1167 | // ciEnv::dump_replay_data* |
vlivanov@5904 | 1168 | |
vlivanov@5904 | 1169 | // Don't change thread state and acquire any locks. |
vlivanov@5904 | 1170 | // Safe to call from VM error reporter. |
kvn@6217 | 1171 | |
kvn@6217 | 1172 | void ciEnv::dump_compile_data(outputStream* out) { |
kvn@6217 | 1173 | CompileTask* task = this->task(); |
kvn@6217 | 1174 | Method* method = task->method(); |
kvn@6217 | 1175 | int entry_bci = task->osr_bci(); |
kvn@6217 | 1176 | int comp_level = task->comp_level(); |
kvn@6217 | 1177 | out->print("compile %s %s %s %d %d", |
kvn@6217 | 1178 | method->klass_name()->as_quoted_ascii(), |
kvn@6217 | 1179 | method->name()->as_quoted_ascii(), |
kvn@6217 | 1180 | method->signature()->as_quoted_ascii(), |
kvn@6217 | 1181 | entry_bci, comp_level); |
kvn@6217 | 1182 | if (compiler_data() != NULL) { |
kvn@6217 | 1183 | if (is_c2_compile(comp_level)) { // C2 or Shark |
kvn@6217 | 1184 | #ifdef COMPILER2 |
kvn@6217 | 1185 | // Dump C2 inlining data. |
kvn@6217 | 1186 | ((Compile*)compiler_data())->dump_inline_data(out); |
kvn@6217 | 1187 | #endif |
kvn@6217 | 1188 | } else if (is_c1_compile(comp_level)) { // C1 |
kvn@6217 | 1189 | #ifdef COMPILER1 |
kvn@6217 | 1190 | // Dump C1 inlining data. |
kvn@6217 | 1191 | ((Compilation*)compiler_data())->dump_inline_data(out); |
kvn@6217 | 1192 | #endif |
kvn@6217 | 1193 | } |
kvn@6217 | 1194 | } |
kvn@6217 | 1195 | out->cr(); |
kvn@6217 | 1196 | } |
kvn@6217 | 1197 | |
vlivanov@5904 | 1198 | void ciEnv::dump_replay_data_unsafe(outputStream* out) { |
vlivanov@4531 | 1199 | ResourceMark rm; |
minqi@4267 | 1200 | #if INCLUDE_JVMTI |
minqi@4267 | 1201 | out->print_cr("JvmtiExport can_access_local_variables %d", _jvmti_can_access_local_variables); |
minqi@4267 | 1202 | out->print_cr("JvmtiExport can_hotswap_or_post_breakpoint %d", _jvmti_can_hotswap_or_post_breakpoint); |
minqi@4267 | 1203 | out->print_cr("JvmtiExport can_post_on_exceptions %d", _jvmti_can_post_on_exceptions); |
minqi@4267 | 1204 | #endif // INCLUDE_JVMTI |
minqi@4267 | 1205 | |
minqi@4267 | 1206 | GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata(); |
minqi@4267 | 1207 | out->print_cr("# %d ciObject found", objects->length()); |
minqi@4267 | 1208 | for (int i = 0; i < objects->length(); i++) { |
minqi@4267 | 1209 | objects->at(i)->dump_replay_data(out); |
minqi@4267 | 1210 | } |
kvn@6217 | 1211 | dump_compile_data(out); |
minqi@4267 | 1212 | out->flush(); |
minqi@4267 | 1213 | } |
vlivanov@5904 | 1214 | |
vlivanov@5904 | 1215 | void ciEnv::dump_replay_data(outputStream* out) { |
vlivanov@5904 | 1216 | GUARDED_VM_ENTRY( |
vlivanov@5904 | 1217 | MutexLocker ml(Compile_lock); |
vlivanov@5904 | 1218 | dump_replay_data_unsafe(out); |
vlivanov@5904 | 1219 | ) |
vlivanov@5904 | 1220 | } |
kvn@6217 | 1221 | |
kvn@6217 | 1222 | void ciEnv::dump_replay_data(int compile_id) { |
kvn@6217 | 1223 | static char buffer[O_BUFLEN]; |
kvn@6217 | 1224 | int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id); |
kvn@6217 | 1225 | if (ret > 0) { |
kvn@6217 | 1226 | int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); |
kvn@6217 | 1227 | if (fd != -1) { |
kvn@6217 | 1228 | FILE* replay_data_file = os::open(fd, "w"); |
kvn@6217 | 1229 | if (replay_data_file != NULL) { |
kvn@6217 | 1230 | fileStream replay_data_stream(replay_data_file, /*need_close=*/true); |
kvn@6217 | 1231 | dump_replay_data(&replay_data_stream); |
drchase@6680 | 1232 | tty->print_cr("# Compiler replay data is saved as: %s", buffer); |
kvn@6217 | 1233 | } else { |
kvn@6217 | 1234 | tty->print_cr("# Can't open file to dump replay data."); |
kvn@6217 | 1235 | } |
kvn@6217 | 1236 | } |
kvn@6217 | 1237 | } |
kvn@6217 | 1238 | } |
kvn@6217 | 1239 | |
kvn@6217 | 1240 | void ciEnv::dump_inline_data(int compile_id) { |
kvn@6217 | 1241 | static char buffer[O_BUFLEN]; |
kvn@6217 | 1242 | int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id); |
kvn@6217 | 1243 | if (ret > 0) { |
kvn@6217 | 1244 | int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); |
kvn@6217 | 1245 | if (fd != -1) { |
kvn@6217 | 1246 | FILE* inline_data_file = os::open(fd, "w"); |
kvn@6217 | 1247 | if (inline_data_file != NULL) { |
kvn@6217 | 1248 | fileStream replay_data_stream(inline_data_file, /*need_close=*/true); |
kvn@6217 | 1249 | GUARDED_VM_ENTRY( |
kvn@6217 | 1250 | MutexLocker ml(Compile_lock); |
kvn@6217 | 1251 | dump_compile_data(&replay_data_stream); |
kvn@6217 | 1252 | ) |
kvn@6217 | 1253 | replay_data_stream.flush(); |
kvn@6217 | 1254 | tty->print("# Compiler inline data is saved as: "); |
drchase@6680 | 1255 | tty->print_cr("%s", buffer); |
kvn@6217 | 1256 | } else { |
kvn@6217 | 1257 | tty->print_cr("# Can't open file to dump inline data."); |
kvn@6217 | 1258 | } |
kvn@6217 | 1259 | } |
kvn@6217 | 1260 | } |
kvn@6217 | 1261 | } |