src/share/vm/ci/ciEnv.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 7288
9dc314de223d
child 7535
7ae4e26cb1e0
child 9858
b985cbb00e68
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial