annotate src/share/vm/ci/ciEnv.cpp @ 1164:359445e739ac

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