src/share/vm/ci/ciEnv.cpp

Fri, 16 Nov 2012 09:19:12 -0500

author
coleenp
date
Fri, 16 Nov 2012 09:19:12 -0500
changeset 4280
80e866b1d053
parent 4267
bd7a7ce2e264
parent 4278
070d523b96a7
child 4531
fcc9e7681d63
child 4542
db9981fd3124
permissions
-rw-r--r--

Merge

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

mercurial