hotspot/src/share/vm/ci/ciEnv.cpp
changeset 13728 882756847a04
parent 13522 5ad4627e792a
child 13883 6979b9850feb
equal deleted inserted replaced
13727:caf5eb7dd4a7 13728:882756847a04
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    26 #include "ci/ciConstant.hpp"
    26 #include "ci/ciConstant.hpp"
    27 #include "ci/ciEnv.hpp"
    27 #include "ci/ciEnv.hpp"
    28 #include "ci/ciField.hpp"
    28 #include "ci/ciField.hpp"
    29 #include "ci/ciInstance.hpp"
    29 #include "ci/ciInstance.hpp"
    30 #include "ci/ciInstanceKlass.hpp"
    30 #include "ci/ciInstanceKlass.hpp"
    31 #include "ci/ciInstanceKlassKlass.hpp"
       
    32 #include "ci/ciMethod.hpp"
    31 #include "ci/ciMethod.hpp"
    33 #include "ci/ciNullObject.hpp"
    32 #include "ci/ciNullObject.hpp"
    34 #include "ci/ciObjArrayKlassKlass.hpp"
       
    35 #include "ci/ciTypeArrayKlassKlass.hpp"
       
    36 #include "ci/ciUtilities.hpp"
    33 #include "ci/ciUtilities.hpp"
    37 #include "classfile/systemDictionary.hpp"
    34 #include "classfile/systemDictionary.hpp"
    38 #include "classfile/vmSymbols.hpp"
    35 #include "classfile/vmSymbols.hpp"
    39 #include "code/scopeDesc.hpp"
    36 #include "code/scopeDesc.hpp"
    40 #include "compiler/compileBroker.hpp"
    37 #include "compiler/compileBroker.hpp"
    43 #include "gc_interface/collectedHeap.inline.hpp"
    40 #include "gc_interface/collectedHeap.inline.hpp"
    44 #include "interpreter/linkResolver.hpp"
    41 #include "interpreter/linkResolver.hpp"
    45 #include "memory/allocation.inline.hpp"
    42 #include "memory/allocation.inline.hpp"
    46 #include "memory/oopFactory.hpp"
    43 #include "memory/oopFactory.hpp"
    47 #include "memory/universe.inline.hpp"
    44 #include "memory/universe.inline.hpp"
    48 #include "oops/methodDataOop.hpp"
    45 #include "oops/methodData.hpp"
    49 #include "oops/objArrayKlass.hpp"
    46 #include "oops/objArrayKlass.hpp"
    50 #include "oops/oop.inline.hpp"
    47 #include "oops/oop.inline.hpp"
    51 #include "oops/oop.inline2.hpp"
    48 #include "oops/oop.inline2.hpp"
    52 #include "prims/jvmtiExport.hpp"
    49 #include "prims/jvmtiExport.hpp"
    53 #include "runtime/init.hpp"
    50 #include "runtime/init.hpp"
    65 //
    62 //
    66 // This class is the top level broker for requests from the compiler
    63 // This class is the top level broker for requests from the compiler
    67 // to the VM.
    64 // to the VM.
    68 
    65 
    69 ciObject*              ciEnv::_null_object_instance;
    66 ciObject*              ciEnv::_null_object_instance;
    70 ciMethodKlass*         ciEnv::_method_klass_instance;
       
    71 ciKlassKlass*          ciEnv::_klass_klass_instance;
       
    72 ciInstanceKlassKlass*  ciEnv::_instance_klass_klass_instance;
       
    73 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance;
       
    74 ciObjArrayKlassKlass*  ciEnv::_obj_array_klass_klass_instance;
       
    75 
    67 
    76 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
    68 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
    77 WK_KLASSES_DO(WK_KLASS_DEFN)
    69 WK_KLASSES_DO(WK_KLASS_DEFN)
    78 #undef WK_KLASS_DEFN
    70 #undef WK_KLASS_DEFN
    79 
    71 
   183   // Assertions ensure that these instances are not accessed before
   175   // Assertions ensure that these instances are not accessed before
   184   // their initialization.
   176   // their initialization.
   185 
   177 
   186   assert(Universe::is_fully_initialized(), "must be");
   178   assert(Universe::is_fully_initialized(), "must be");
   187 
   179 
   188   oop o = Universe::null_ptr_exception_instance();
   180   _NullPointerException_instance = NULL;
   189   assert(o != NULL, "should have been initialized");
   181   _ArithmeticException_instance = NULL;
   190   _NullPointerException_instance = get_object(o)->as_instance();
       
   191   o = Universe::arithmetic_exception_instance();
       
   192   assert(o != NULL, "should have been initialized");
       
   193   _ArithmeticException_instance = get_object(o)->as_instance();
       
   194 
       
   195   _ArrayIndexOutOfBoundsException_instance = NULL;
   182   _ArrayIndexOutOfBoundsException_instance = NULL;
   196   _ArrayStoreException_instance = NULL;
   183   _ArrayStoreException_instance = NULL;
   197   _ClassCastException_instance = NULL;
   184   _ClassCastException_instance = NULL;
   198   _the_null_string = NULL;
   185   _the_null_string = NULL;
   199   _the_min_jint_string = NULL;
   186   _the_min_jint_string = NULL;
   200 }
   187 }
   201 
   188 
   202 ciEnv::~ciEnv() {
   189 ciEnv::~ciEnv() {
   203   CompilerThread* current_thread = CompilerThread::current();
   190   CompilerThread* current_thread = CompilerThread::current();
   204   _factory->remove_symbols();
   191   _factory->remove_symbols();
   205   current_thread->set_env(NULL);
   192   // Need safepoint to clear the env on the thread.  RedefineClasses might
       
   193   // be reading it.
       
   194   GUARDED_VM_ENTRY(current_thread->set_env(NULL);)
   206 }
   195 }
   207 
   196 
   208 // ------------------------------------------------------------------
   197 // ------------------------------------------------------------------
   209 // Cache Jvmti state
   198 // Cache Jvmti state
   210 void ciEnv::cache_jvmti_state() {
   199 void ciEnv::cache_jvmti_state() {
   236 // helper for lazy exception creation
   225 // helper for lazy exception creation
   237 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
   226 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
   238   VM_ENTRY_MARK;
   227   VM_ENTRY_MARK;
   239   if (handle == NULL) {
   228   if (handle == NULL) {
   240     // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
   229     // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
   241     klassOop k = SystemDictionary::find(name, Handle(), Handle(), THREAD);
   230     Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD);
   242     jobject objh = NULL;
   231     jobject objh = NULL;
   243     if (!HAS_PENDING_EXCEPTION && k != NULL) {
   232     if (!HAS_PENDING_EXCEPTION && k != NULL) {
   244       oop obj = instanceKlass::cast(k)->allocate_permanent_instance(THREAD);
   233       oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD);
   245       if (!HAS_PENDING_EXCEPTION)
   234       if (!HAS_PENDING_EXCEPTION)
   246         objh = JNIHandles::make_global(obj);
   235         objh = JNIHandles::make_global(obj);
   247     }
   236     }
   248     if (HAS_PENDING_EXCEPTION) {
   237     if (HAS_PENDING_EXCEPTION) {
   249       CLEAR_PENDING_EXCEPTION;
   238       CLEAR_PENDING_EXCEPTION;
   253   }
   242   }
   254   oop obj = JNIHandles::resolve(handle);
   243   oop obj = JNIHandles::resolve(handle);
   255   return obj == NULL? NULL: get_object(obj)->as_instance();
   244   return obj == NULL? NULL: get_object(obj)->as_instance();
   256 }
   245 }
   257 
   246 
   258 // ------------------------------------------------------------------
       
   259 // ciEnv::ArrayIndexOutOfBoundsException_instance, etc.
       
   260 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
   247 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
   261   if (_ArrayIndexOutOfBoundsException_instance == NULL) {
   248   if (_ArrayIndexOutOfBoundsException_instance == NULL) {
   262     _ArrayIndexOutOfBoundsException_instance
   249     _ArrayIndexOutOfBoundsException_instance
   263           = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
   250           = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
   264           vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
   251           vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
   298   return _the_min_jint_string;
   285   return _the_min_jint_string;
   299 }
   286 }
   300 
   287 
   301 // ------------------------------------------------------------------
   288 // ------------------------------------------------------------------
   302 // ciEnv::get_method_from_handle
   289 // ciEnv::get_method_from_handle
   303 ciMethod* ciEnv::get_method_from_handle(jobject method) {
   290 ciMethod* ciEnv::get_method_from_handle(Method* method) {
   304   VM_ENTRY_MARK;
   291   VM_ENTRY_MARK;
   305   return get_object(JNIHandles::resolve(method))->as_method();
   292   return get_metadata(method)->as_method();
   306 }
   293 }
   307 
       
   308 // ------------------------------------------------------------------
       
   309 // ciEnv::make_array
       
   310 ciArray* ciEnv::make_system_array(GrowableArray<ciObject*>* objects) {
       
   311   VM_ENTRY_MARK;
       
   312   int length = objects->length();
       
   313   objArrayOop a = oopFactory::new_system_objArray(length, THREAD);
       
   314   if (HAS_PENDING_EXCEPTION) {
       
   315     CLEAR_PENDING_EXCEPTION;
       
   316     record_out_of_memory_failure();
       
   317     return NULL;
       
   318   }
       
   319   for (int i = 0; i < length; i++) {
       
   320     a->obj_at_put(i, objects->at(i)->get_oop());
       
   321   }
       
   322   assert(a->is_perm(), "");
       
   323   return get_object(a)->as_array();
       
   324 }
       
   325 
       
   326 
   294 
   327 // ------------------------------------------------------------------
   295 // ------------------------------------------------------------------
   328 // ciEnv::array_element_offset_in_bytes
   296 // ciEnv::array_element_offset_in_bytes
   329 int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) {
   297 int ciEnv::array_element_offset_in_bytes(ciArray* a_h, ciObject* o_h) {
   330   VM_ENTRY_MARK;
   298   VM_ENTRY_MARK;
   341 
   309 
   342 // ------------------------------------------------------------------
   310 // ------------------------------------------------------------------
   343 // ciEnv::check_klass_accessiblity
   311 // ciEnv::check_klass_accessiblity
   344 //
   312 //
   345 // Note: the logic of this method should mirror the logic of
   313 // Note: the logic of this method should mirror the logic of
   346 // constantPoolOopDesc::verify_constant_pool_resolve.
   314 // ConstantPool::verify_constant_pool_resolve.
   347 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass,
   315 bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass,
   348                                       klassOop resolved_klass) {
   316                                       Klass* resolved_klass) {
   349   if (accessing_klass == NULL || !accessing_klass->is_loaded()) {
   317   if (accessing_klass == NULL || !accessing_klass->is_loaded()) {
   350     return true;
   318     return true;
   351   }
   319   }
   352   if (accessing_klass->is_obj_array()) {
   320   if (accessing_klass->is_obj_array_klass()) {
   353     accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass();
   321     accessing_klass = accessing_klass->as_obj_array_klass()->base_element_klass();
   354   }
   322   }
   355   if (!accessing_klass->is_instance_klass()) {
   323   if (!accessing_klass->is_instance_klass()) {
   356     return true;
   324     return true;
   357   }
   325   }
   358 
   326 
   359   if (resolved_klass->klass_part()->oop_is_objArray()) {
   327   if (resolved_klass->oop_is_objArray()) {
   360     // Find the element klass, if this is an array.
   328     // Find the element klass, if this is an array.
   361     resolved_klass = objArrayKlass::cast(resolved_klass)->bottom_klass();
   329     resolved_klass = objArrayKlass::cast(resolved_klass)->bottom_klass();
   362   }
   330   }
   363   if (resolved_klass->klass_part()->oop_is_instance()) {
   331   if (resolved_klass->oop_is_instance()) {
   364     return Reflection::verify_class_access(accessing_klass->get_klassOop(),
   332     return Reflection::verify_class_access(accessing_klass->get_Klass(),
   365                                            resolved_klass,
   333                                            resolved_klass,
   366                                            true);
   334                                            true);
   367   }
   335   }
   368   return true;
   336   return true;
   369 }
   337 }
   414   }
   382   }
   415   KlassHandle found_klass;
   383   KlassHandle found_klass;
   416   {
   384   {
   417     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
   385     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
   418     MutexLocker ml(Compile_lock);
   386     MutexLocker ml(Compile_lock);
   419     klassOop kls;
   387     Klass* kls;
   420     if (!require_local) {
   388     if (!require_local) {
   421       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
   389       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
   422                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
   390                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
   423     } else {
   391     } else {
   424       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
   392       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
   455 
   423 
   456   if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
   424   if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
   457     // Look inside the constant pool for pre-resolved class entries.
   425     // Look inside the constant pool for pre-resolved class entries.
   458     for (int i = cpool->length() - 1; i >= 1; i--) {
   426     for (int i = cpool->length() - 1; i >= 1; i--) {
   459       if (cpool->tag_at(i).is_klass()) {
   427       if (cpool->tag_at(i).is_klass()) {
   460         klassOop kls = cpool->resolved_klass_at(i);
   428         Klass* kls = cpool->resolved_klass_at(i);
   461         if (Klass::cast(kls)->name() == sym) {
   429         if (Klass::cast(kls)->name() == sym) {
   462           found_klass = KlassHandle(THREAD, kls);
   430           found_klass = KlassHandle(THREAD, kls);
   463           break;
   431           break;
   464         }
   432         }
   465       }
   433       }
   466     }
   434     }
   467   }
   435   }
   468 
   436 
   469   if (found_klass() != NULL) {
   437   if (found_klass() != NULL) {
   470     // Found it.  Build a CI handle.
   438     // Found it.  Build a CI handle.
   471     return get_object(found_klass())->as_klass();
   439     return get_klass(found_klass());
   472   }
   440   }
   473 
   441 
   474   if (require_local)  return NULL;
   442   if (require_local)  return NULL;
   475 
   443 
   476   // Not yet loaded into the VM, or not governed by loader constraints.
   444   // Not yet loaded into the VM, or not governed by loader constraints.
   496 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
   464 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
   497                                         int index,
   465                                         int index,
   498                                         bool& is_accessible,
   466                                         bool& is_accessible,
   499                                         ciInstanceKlass* accessor) {
   467                                         ciInstanceKlass* accessor) {
   500   EXCEPTION_CONTEXT;
   468   EXCEPTION_CONTEXT;
   501   KlassHandle klass(THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
   469   KlassHandle klass; // = NULL;
   502   Symbol* klass_name = NULL;
   470   Symbol* klass_name = NULL;
       
   471 
       
   472   if (cpool->tag_at(index).is_symbol()) {
       
   473     klass_name = cpool->symbol_at(index);
       
   474   } else {
       
   475     // Check if it's resolved if it's not a symbol constant pool entry.
       
   476     klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index));
       
   477 
   503   if (klass.is_null()) {
   478   if (klass.is_null()) {
   504     // The klass has not been inserted into the constant pool.
   479     // The klass has not been inserted into the constant pool.
   505     // Try to look it up by name.
   480     // Try to look it up by name.
   506     {
   481     {
   507       // We have to lock the cpool to keep the oop from being resolved
   482       // We have to lock the cpool to keep the oop from being resolved
   508       // while we are accessing it.
   483       // while we are accessing it.
   509       ObjectLocker ol(cpool, THREAD);
   484         MonitorLockerEx ml(cpool->lock());
   510 
       
   511       constantTag tag = cpool->tag_at(index);
   485       constantTag tag = cpool->tag_at(index);
   512       if (tag.is_klass()) {
   486       if (tag.is_klass()) {
   513         // The klass has been inserted into the constant pool
   487         // The klass has been inserted into the constant pool
   514         // very recently.
   488         // very recently.
   515         klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
   489         klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
   516       } else if (tag.is_symbol()) {
       
   517         klass_name = cpool->symbol_at(index);
       
   518       } else {
   490       } else {
   519         assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
   491         assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
   520         klass_name = cpool->unresolved_klass_at(index);
   492         klass_name = cpool->unresolved_klass_at(index);
   521       }
   493       }
   522     }
   494     }
       
   495   }
   523   }
   496   }
   524 
   497 
   525   if (klass.is_null()) {
   498   if (klass.is_null()) {
   526     // Not found in constant pool.  Use the name to do the lookup.
   499     // Not found in constant pool.  Use the name to do the lookup.
   527     ciKlass* k = get_klass_by_name_impl(accessor,
   500     ciKlass* k = get_klass_by_name_impl(accessor,
   535                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
   508                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
   536       // Loaded only remotely.  Not linked yet.
   509       // Loaded only remotely.  Not linked yet.
   537       is_accessible = false;
   510       is_accessible = false;
   538     } else {
   511     } else {
   539       // Linked locally, and we must also check public/private, etc.
   512       // Linked locally, and we must also check public/private, etc.
   540       is_accessible = check_klass_accessibility(accessor, k->get_klassOop());
   513       is_accessible = check_klass_accessibility(accessor, k->get_Klass());
   541     }
   514     }
   542     return k;
   515     return k;
   543   }
   516   }
   544 
   517 
   545   // Check for prior unloaded klass.  The SystemDictionary's answers
   518   // Check for prior unloaded klass.  The SystemDictionary's answers
   546   // can vary over time but the compiler needs consistency.
   519   // can vary over time but the compiler needs consistency.
   547   ciSymbol* name = get_symbol(klass()->klass_part()->name());
   520   ciSymbol* name = get_symbol(klass()->name());
   548   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
   521   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
   549   if (unloaded_klass != NULL) {
   522   if (unloaded_klass != NULL) {
   550     is_accessible = false;
   523     is_accessible = false;
   551     return unloaded_klass;
   524     return unloaded_klass;
   552   }
   525   }
   553 
   526 
   554   // It is known to be accessible, since it was found in the constant pool.
   527   // It is known to be accessible, since it was found in the constant pool.
   555   is_accessible = true;
   528   is_accessible = true;
   556   return get_object(klass())->as_klass();
   529   return get_klass(klass());
   557 }
   530 }
   558 
   531 
   559 // ------------------------------------------------------------------
   532 // ------------------------------------------------------------------
   560 // ciEnv::get_klass_by_index
   533 // ciEnv::get_klass_by_index
   561 //
   534 //
   577   bool ignore_will_link;
   550   bool ignore_will_link;
   578   EXCEPTION_CONTEXT;
   551   EXCEPTION_CONTEXT;
   579   int index = pool_index;
   552   int index = pool_index;
   580   if (cache_index >= 0) {
   553   if (cache_index >= 0) {
   581     assert(index < 0, "only one kind of index at a time");
   554     assert(index < 0, "only one kind of index at a time");
   582     ConstantPoolCacheEntry* cpc_entry = cpool->cache()->entry_at(cache_index);
   555     oop obj = cpool->resolved_references()->obj_at(cache_index);
   583     index = cpc_entry->constant_pool_index();
       
   584     oop obj = cpc_entry->f1_as_instance();
       
   585     if (obj != NULL) {
   556     if (obj != NULL) {
   586       assert(obj->is_instance() || obj->is_array(), "must be a Java reference");
       
   587       ciObject* ciobj = get_object(obj);
   557       ciObject* ciobj = get_object(obj);
   588       return ciConstant(T_OBJECT, ciobj);
   558       return ciConstant(T_OBJECT, ciobj);
   589     }
   559     }
       
   560     index = cpool->object_to_cp_index(cache_index);
   590   }
   561   }
   591   constantTag tag = cpool->tag_at(index);
   562   constantTag tag = cpool->tag_at(index);
   592   if (tag.is_int()) {
   563   if (tag.is_int()) {
   593     return ciConstant(T_INT, (jint)cpool->int_at(index));
   564     return ciConstant(T_INT, (jint)cpool->int_at(index));
   594   } else if (tag.is_long()) {
   565   } else if (tag.is_long()) {
   595     return ciConstant((jlong)cpool->long_at(index));
   566     return ciConstant((jlong)cpool->long_at(index));
   596   } else if (tag.is_float()) {
   567   } else if (tag.is_float()) {
   597     return ciConstant((jfloat)cpool->float_at(index));
   568     return ciConstant((jfloat)cpool->float_at(index));
   598   } else if (tag.is_double()) {
   569   } else if (tag.is_double()) {
   599     return ciConstant((jdouble)cpool->double_at(index));
   570     return ciConstant((jdouble)cpool->double_at(index));
   600   } else if (tag.is_string() || tag.is_unresolved_string()) {
   571   } else if (tag.is_string()) {
   601     oop string = NULL;
   572     oop string = NULL;
       
   573     assert(cache_index >= 0, "should have a cache index");
   602     if (cpool->is_pseudo_string_at(index)) {
   574     if (cpool->is_pseudo_string_at(index)) {
   603       string = cpool->pseudo_string_at(index);
   575       string = cpool->pseudo_string_at(index, cache_index);
   604     } else {
   576     } else {
   605       string = cpool->string_at(index, THREAD);
   577       string = cpool->string_at(index, cache_index, THREAD);
   606       if (HAS_PENDING_EXCEPTION) {
   578       if (HAS_PENDING_EXCEPTION) {
   607         CLEAR_PENDING_EXCEPTION;
   579         CLEAR_PENDING_EXCEPTION;
   608         record_out_of_memory_failure();
   580         record_out_of_memory_failure();
   609         return ciConstant();
   581         return ciConstant();
   610       }
   582       }
   623     assert (klass->is_instance_klass() || klass->is_array_klass(),
   595     assert (klass->is_instance_klass() || klass->is_array_klass(),
   624             "must be an instance or array klass ");
   596             "must be an instance or array klass ");
   625     return ciConstant(T_OBJECT, klass->java_mirror());
   597     return ciConstant(T_OBJECT, klass->java_mirror());
   626   } else if (tag.is_object()) {
   598   } else if (tag.is_object()) {
   627     oop obj = cpool->object_at(index);
   599     oop obj = cpool->object_at(index);
   628     assert(obj->is_instance() || obj->is_array(), "must be a Java reference");
       
   629     ciObject* ciobj = get_object(obj);
   600     ciObject* ciobj = get_object(obj);
   630     return ciConstant(T_OBJECT, ciobj);
   601     return ciConstant(T_OBJECT, ciobj);
   631   } else if (tag.is_method_type()) {
   602   } else if (tag.is_method_type()) {
   632     // must execute Java code to link this CP entry into cache[i].f1
   603     // must execute Java code to link this CP entry into cache[i].f1
   633     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
   604     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
   695 // ------------------------------------------------------------------
   666 // ------------------------------------------------------------------
   696 // ciEnv::lookup_method
   667 // ciEnv::lookup_method
   697 //
   668 //
   698 // Perform an appropriate method lookup based on accessor, holder,
   669 // Perform an appropriate method lookup based on accessor, holder,
   699 // name, signature, and bytecode.
   670 // name, signature, and bytecode.
   700 methodOop ciEnv::lookup_method(instanceKlass*  accessor,
   671 Method* ciEnv::lookup_method(InstanceKlass*  accessor,
   701                                instanceKlass*  holder,
   672                                InstanceKlass*  holder,
   702                                Symbol*       name,
   673                                Symbol*       name,
   703                                Symbol*       sig,
   674                                Symbol*       sig,
   704                                Bytecodes::Code bc) {
   675                                Bytecodes::Code bc) {
   705   EXCEPTION_CONTEXT;
   676   EXCEPTION_CONTEXT;
   706   KlassHandle h_accessor(THREAD, accessor);
   677   KlassHandle h_accessor(THREAD, accessor);
   737 // ciEnv::get_method_by_index_impl
   708 // ciEnv::get_method_by_index_impl
   738 ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool,
   709 ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool,
   739                                           int index, Bytecodes::Code bc,
   710                                           int index, Bytecodes::Code bc,
   740                                           ciInstanceKlass* accessor) {
   711                                           ciInstanceKlass* accessor) {
   741   if (bc == Bytecodes::_invokedynamic) {
   712   if (bc == Bytecodes::_invokedynamic) {
   742     ConstantPoolCacheEntry* secondary_entry = cpool->cache()->secondary_entry_at(index);
   713     ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index);
   743     const bool is_resolved = !secondary_entry->is_f1_null();
   714     bool is_resolved = !cpce->is_f1_null();
   744     // FIXME: code generation could allow for null (unlinked) call site
   715     // FIXME: code generation could allow for null (unlinked) call site
   745     // The call site could be made patchable as follows:
   716     // The call site could be made patchable as follows:
   746     // Load the appendix argument from the constant pool.
   717     // Load the appendix argument from the constant pool.
   747     // Test the appendix argument and jump to a known deopt routine if it is null.
   718     // Test the appendix argument and jump to a known deopt routine if it is null.
   748     // Jump through a patchable call site, which is initially a deopt routine.
   719     // Jump through a patchable call site, which is initially a deopt routine.
   749     // Patch the call site to the nmethod entry point of the static compiled lambda form.
   720     // Patch the call site to the nmethod entry point of the static compiled lambda form.
   750     // As with other two-component call sites, both values must be independently verified.
   721     // As with other two-component call sites, both values must be independently verified.
   751 
   722 
   752     if (is_resolved) {
   723     if (is_resolved) {
   753       // Get the invoker methodOop and the extra argument from the constant pool.
   724       // Get the invoker Method* from the constant pool.
   754       methodOop adapter = secondary_entry->f2_as_vfinal_method();
   725       // (The appendix argument, if any, will be noted in the method's signature.)
   755       return get_object(adapter)->as_method();
   726       Method* adapter = cpce->f1_as_method();
       
   727       return get_method(adapter);
   756     }
   728     }
   757 
   729 
   758     // Fake a method that is equivalent to a declared method.
   730     // Fake a method that is equivalent to a declared method.
   759     ciInstanceKlass* holder    = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
   731     ciInstanceKlass* holder    = get_instance_klass(SystemDictionary::MethodHandle_klass());
   760     ciSymbol*        name      = ciSymbol::invokeBasic_name();
   732     ciSymbol*        name      = ciSymbol::invokeBasic_name();
   761     ciSymbol*        signature = get_symbol(cpool->signature_ref_at(index));
   733     ciSymbol*        signature = get_symbol(cpool->signature_ref_at(index));
   762     return get_unloaded_method(holder, name, signature, accessor);
   734     return get_unloaded_method(holder, name, signature, accessor);
   763   } else {
   735   } else {
   764     const int holder_index = cpool->klass_ref_index_at(index);
   736     const int holder_index = cpool->klass_ref_index_at(index);
   770     Symbol* name_sym = cpool->name_ref_at(index);
   742     Symbol* name_sym = cpool->name_ref_at(index);
   771     Symbol* sig_sym  = cpool->signature_ref_at(index);
   743     Symbol* sig_sym  = cpool->signature_ref_at(index);
   772 
   744 
   773     if (cpool->has_preresolution()
   745     if (cpool->has_preresolution()
   774         || (holder == ciEnv::MethodHandle_klass() &&
   746         || (holder == ciEnv::MethodHandle_klass() &&
   775             MethodHandles::is_signature_polymorphic_name(holder->get_klassOop(), name_sym))) {
   747             MethodHandles::is_signature_polymorphic_name(holder->get_Klass(), name_sym))) {
   776       // Short-circuit lookups for JSR 292-related call sites.
   748       // Short-circuit lookups for JSR 292-related call sites.
   777       // That is, do not rely only on name-based lookups, because they may fail
   749       // That is, do not rely only on name-based lookups, because they may fail
   778       // if the names are not resolvable in the boot class loader (7056328).
   750       // if the names are not resolvable in the boot class loader (7056328).
   779       switch (bc) {
   751       switch (bc) {
   780       case Bytecodes::_invokevirtual:
   752       case Bytecodes::_invokevirtual:
   781       case Bytecodes::_invokeinterface:
   753       case Bytecodes::_invokeinterface:
   782       case Bytecodes::_invokespecial:
   754       case Bytecodes::_invokespecial:
   783       case Bytecodes::_invokestatic:
   755       case Bytecodes::_invokestatic:
   784         {
   756         {
   785           methodOop m = constantPoolOopDesc::method_at_if_loaded(cpool, index);
   757           Method* m = ConstantPool::method_at_if_loaded(cpool, index);
   786           if (m != NULL) {
   758           if (m != NULL) {
   787             return get_object(m)->as_method();
   759             return get_method(m);
   788           }
   760           }
   789         }
   761         }
   790         break;
   762         break;
   791       }
   763       }
   792     }
   764     }
   793 
   765 
   794     if (holder_is_accessible) {  // Our declared holder is loaded.
   766     if (holder_is_accessible) {  // Our declared holder is loaded.
   795       instanceKlass* lookup = declared_holder->get_instanceKlass();
   767       InstanceKlass* lookup = declared_holder->get_instanceKlass();
   796       methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
   768       Method* m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
   797       if (m != NULL &&
   769       if (m != NULL &&
   798           (bc == Bytecodes::_invokestatic
   770           (bc == Bytecodes::_invokestatic
   799            ?  instanceKlass::cast(m->method_holder())->is_not_initialized()
   771            ?  InstanceKlass::cast(m->method_holder())->is_not_initialized()
   800            : !instanceKlass::cast(m->method_holder())->is_loaded())) {
   772            : !InstanceKlass::cast(m->method_holder())->is_loaded())) {
   801         m = NULL;
   773         m = NULL;
   802       }
   774       }
   803       if (m != NULL) {
   775       if (m != NULL) {
   804         // We found the method.
   776         // We found the method.
   805         return get_object(m)->as_method();
   777         return get_method(m);
   806       }
   778       }
   807     }
   779     }
   808 
   780 
   809     // Either the declared holder was not loaded, or the method could
   781     // Either the declared holder was not loaded, or the method could
   810     // not be found.  Create a dummy ciMethod to represent the failed
   782     // not be found.  Create a dummy ciMethod to represent the failed
   884   // First, check non-klass dependencies as we might return early and
   856   // First, check non-klass dependencies as we might return early and
   885   // not check klass dependencies if the system dictionary
   857   // not check klass dependencies if the system dictionary
   886   // modification counter hasn't changed (see below).
   858   // modification counter hasn't changed (see below).
   887   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   859   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   888     if (deps.is_klass_type())  continue;  // skip klass dependencies
   860     if (deps.is_klass_type())  continue;  // skip klass dependencies
   889     klassOop witness = deps.check_dependency();
   861     Klass* witness = deps.check_dependency();
   890     if (witness != NULL) {
   862     if (witness != NULL) {
   891       record_failure("invalid non-klass dependency");
   863       record_failure("invalid non-klass dependency");
   892       return;
   864       return;
   893     }
   865     }
   894   }
   866   }
   905   if (!counter_changed && !verify_deps)  return;
   877   if (!counter_changed && !verify_deps)  return;
   906 
   878 
   907   int klass_violations = 0;
   879   int klass_violations = 0;
   908   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   880   for (Dependencies::DepStream deps(dependencies()); deps.next(); ) {
   909     if (!deps.is_klass_type())  continue;  // skip non-klass dependencies
   881     if (!deps.is_klass_type())  continue;  // skip non-klass dependencies
   910     klassOop witness = deps.check_dependency();
   882     Klass* witness = deps.check_dependency();
   911     if (witness != NULL) {
   883     if (witness != NULL) {
   912       klass_violations++;
   884       klass_violations++;
   913       if (!counter_changed) {
   885       if (!counter_changed) {
   914         // Dependence failed but counter didn't change.  Log a message
   886         // Dependence failed but counter didn't change.  Log a message
   915         // describing what failed and allow the assert at the end to
   887         // describing what failed and allow the assert at the end to
   990 
   962 
   991       // Check for {class loads, evolution, breakpoints, ...} during compilation
   963       // Check for {class loads, evolution, breakpoints, ...} during compilation
   992       validate_compile_task_dependencies(target);
   964       validate_compile_task_dependencies(target);
   993     }
   965     }
   994 
   966 
   995     methodHandle method(THREAD, target->get_methodOop());
   967     methodHandle method(THREAD, target->get_Method());
   996 
   968 
   997     if (failing()) {
   969     if (failing()) {
   998       // While not a true deoptimization, it is a preemptive decompile.
   970       // While not a true deoptimization, it is a preemptive decompile.
   999       methodDataOop mdo = method()->method_data();
   971       MethodData* mdo = method()->method_data();
  1000       if (mdo != NULL) {
   972       if (mdo != NULL) {
  1001         mdo->inc_decompile_count();
   973         mdo->inc_decompile_count();
  1002       }
   974       }
  1003 
   975 
  1004       // All buffers in the CodeBuffer are allocated in the CodeCache.
   976       // All buffers in the CodeBuffer are allocated in the CodeCache.
  1080           tty->print_cr("Installing osr method (%d) %s @ %d",
  1052           tty->print_cr("Installing osr method (%d) %s @ %d",
  1081                         comp_level,
  1053                         comp_level,
  1082                         method_name,
  1054                         method_name,
  1083                         entry_bci);
  1055                         entry_bci);
  1084         }
  1056         }
  1085         instanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
  1057         InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
  1086 
  1058 
  1087       }
  1059       }
  1088     }
  1060     }
  1089   }
  1061   }
  1090   // JVMTI -- compiled method notification (must be done outside lock)
  1062   // JVMTI -- compiled method notification (must be done outside lock)