src/share/vm/ci/ciEnv.cpp

Thu, 13 Jan 2011 22:15:41 -0800

author
never
date
Thu, 13 Jan 2011 22:15:41 -0800
changeset 2462
8012aa3ccede
parent 2314
f95d63e2154a
child 2467
9afee0b9fc1d
permissions
-rw-r--r--

4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed

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

mercurial