src/share/vm/ci/ciEnv.cpp

Mon, 31 Jan 2011 17:48:21 -0800

author
never
date
Mon, 31 Jan 2011 17:48:21 -0800
changeset 2551
4f26f535a225
parent 2497
3582bf76420e
child 2570
5841dc1964f0
permissions
-rw-r--r--

6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
Reviewed-by: jrose, acorn

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

mercurial