annotate src/share/vm/ci/ciEnv.cpp @ 12967:c031bb257839

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