annotate src/share/vm/ci/ciEnv.cpp @ 470:ad8c8ca4ab0f

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