< prev index next >

src/hotspot/share/ci/ciEnv.cpp

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "ci/ciConstant.hpp"
  28 #include "ci/ciEnv.hpp"
  29 #include "ci/ciField.hpp"
  30 #include "ci/ciInstance.hpp"
  31 #include "ci/ciInstanceKlass.hpp"
  32 #include "ci/ciMethod.hpp"
  33 #include "ci/ciNullObject.hpp"
  34 #include "ci/ciReplay.hpp"
  35 #include "ci/ciUtilities.inline.hpp"

  36 #include "classfile/systemDictionary.hpp"
  37 #include "classfile/vmSymbols.hpp"
  38 #include "code/codeCache.hpp"
  39 #include "code/scopeDesc.hpp"
  40 #include "compiler/compileBroker.hpp"
  41 #include "compiler/compileLog.hpp"
  42 #include "compiler/disassembler.hpp"
  43 #include "gc/shared/collectedHeap.inline.hpp"
  44 #include "interpreter/linkResolver.hpp"
  45 #include "jfr/jfrEvents.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "memory/oopFactory.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "memory/universe.hpp"
  50 #include "oops/constantPool.inline.hpp"
  51 #include "oops/cpCache.inline.hpp"
  52 #include "oops/method.inline.hpp"
  53 #include "oops/methodData.hpp"
  54 #include "oops/objArrayKlass.hpp"
  55 #include "oops/objArrayOop.inline.hpp"


 379   }
 380   if (resolved_klass->is_instance_klass()) {
 381     return (Reflection::verify_class_access(accessing_klass->get_Klass(),
 382                                             InstanceKlass::cast(resolved_klass),
 383                                             true) == Reflection::ACCESS_OK);
 384   }
 385   return true;
 386 }
 387 
 388 // ------------------------------------------------------------------
 389 // ciEnv::get_klass_by_name_impl
 390 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
 391                                        const constantPoolHandle& cpool,
 392                                        ciSymbol* name,
 393                                        bool require_local) {
 394   ASSERT_IN_VM;
 395   EXCEPTION_CONTEXT;
 396 
 397   // Now we need to check the SystemDictionary
 398   Symbol* sym = name->get_symbol();
 399   if (sym->char_at(0) == 'L' &&
 400     sym->char_at(sym->utf8_length()-1) == ';') {
 401     // This is a name from a signature.  Strip off the trimmings.
 402     // Call recursive to keep scope of strippedsym.
 403     TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
 404                     sym->utf8_length()-2,
 405                     KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass));
 406     ciSymbol* strippedname = get_symbol(strippedsym);
 407     return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
 408   }
 409 
 410   // Check for prior unloaded klass.  The SystemDictionary's answers
 411   // can vary over time but the compiler needs consistency.
 412   ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
 413   if (unloaded_klass != NULL) {
 414     if (require_local)  return NULL;
 415     return unloaded_klass;
 416   }
 417 
 418   Handle loader(THREAD, (oop)NULL);
 419   Handle domain(THREAD, (oop)NULL);


 434     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 435     MutexLocker ml(Compile_lock);
 436     Klass* kls;
 437     if (!require_local) {
 438       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
 439                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
 440     } else {
 441       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
 442                                                            KILL_COMPILE_ON_FATAL_(fail_type));
 443     }
 444     found_klass = kls;
 445   }
 446 
 447   // If we fail to find an array klass, look again for its element type.
 448   // The element type may be available either locally or via constraints.
 449   // In either case, if we can find the element type in the system dictionary,
 450   // we must build an array type around it.  The CI requires array klasses
 451   // to be loaded if their element klasses are loaded, except when memory
 452   // is exhausted.
 453   if (sym->char_at(0) == '[' &&
 454       (sym->char_at(1) == '[' || sym->char_at(1) == 'L')) {
 455     // We have an unloaded array.
 456     // Build it on the fly if the element class exists.
 457     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
 458                                                  sym->utf8_length()-1,
 459                                                  KILL_COMPILE_ON_FATAL_(fail_type));
 460 
 461     // Get element ciKlass recursively.
 462     ciKlass* elem_klass =
 463       get_klass_by_name_impl(accessing_klass,
 464                              cpool,
 465                              get_symbol(elem_sym),
 466                              require_local);
 467     if (elem_klass != NULL && elem_klass->is_loaded()) {
 468       // Now make an array for it



 469       return ciObjArrayKlass::make_impl(elem_klass);
 470     }
 471   }

 472 
 473   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 474     // Look inside the constant pool for pre-resolved class entries.
 475     for (int i = cpool->length() - 1; i >= 1; i--) {
 476       if (cpool->tag_at(i).is_klass()) {
 477         Klass* kls = cpool->resolved_klass_at(i);
 478         if (kls->name() == sym) {
 479           found_klass = kls;
 480           break;
 481         }
 482       }
 483     }
 484   }
 485 
 486   if (found_klass != NULL) {
 487     // Found it.  Build a CI handle.
 488     return get_klass(found_klass);
 489   }
 490 
 491   if (require_local)  return NULL;
 492 
 493   // Not yet loaded into the VM, or not governed by loader constraints.
 494   // Make a CI representative for it.















 495   return get_unloaded_klass(accessing_klass, name);
 496 }
 497 
 498 // ------------------------------------------------------------------
 499 // ciEnv::get_klass_by_name
 500 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 501                                   ciSymbol* klass_name,
 502                                   bool require_local) {
 503   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 504                                                  constantPoolHandle(),
 505                                                  klass_name,
 506                                                  require_local);)
 507 }
 508 
 509 // ------------------------------------------------------------------
 510 // ciEnv::get_klass_by_index_impl
 511 //
 512 // Implementation of get_klass_by_index.
 513 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 514                                         int index,


 555   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
 556   if (unloaded_klass != NULL) {
 557     is_accessible = false;
 558     return unloaded_klass;
 559   }
 560 
 561   // It is known to be accessible, since it was found in the constant pool.
 562   is_accessible = true;
 563   return get_klass(klass);
 564 }
 565 
 566 // ------------------------------------------------------------------
 567 // ciEnv::get_klass_by_index
 568 //
 569 // Get a klass from the constant pool.
 570 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 571                                    int index,
 572                                    bool& is_accessible,
 573                                    ciInstanceKlass* accessor) {
 574   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)

















 575 }
 576 
 577 // ------------------------------------------------------------------
 578 // ciEnv::get_constant_by_index_impl
 579 //
 580 // Implementation of get_constant_by_index().
 581 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
 582                                              int pool_index, int cache_index,
 583                                              ciInstanceKlass* accessor) {
 584   bool ignore_will_link;
 585   EXCEPTION_CONTEXT;
 586   int index = pool_index;
 587   if (cache_index >= 0) {
 588     assert(index < 0, "only one kind of index at a time");
 589     index = cpool->object_to_cp_index(cache_index);
 590     oop obj = cpool->resolved_references()->obj_at(cache_index);
 591     if (obj != NULL) {
 592       if (oopDesc::equals(obj, Universe::the_null_sentinel())) {
 593         return ciConstant(T_OBJECT, get_object(NULL));
 594       }




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "ci/ciConstant.hpp"
  28 #include "ci/ciEnv.hpp"
  29 #include "ci/ciField.hpp"
  30 #include "ci/ciInstance.hpp"
  31 #include "ci/ciInstanceKlass.hpp"
  32 #include "ci/ciMethod.hpp"
  33 #include "ci/ciNullObject.hpp"
  34 #include "ci/ciReplay.hpp"
  35 #include "ci/ciUtilities.inline.hpp"
  36 #include "ci/ciValueKlass.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "code/codeCache.hpp"
  40 #include "code/scopeDesc.hpp"
  41 #include "compiler/compileBroker.hpp"
  42 #include "compiler/compileLog.hpp"
  43 #include "compiler/disassembler.hpp"
  44 #include "gc/shared/collectedHeap.inline.hpp"
  45 #include "interpreter/linkResolver.hpp"
  46 #include "jfr/jfrEvents.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/constantPool.inline.hpp"
  52 #include "oops/cpCache.inline.hpp"
  53 #include "oops/method.inline.hpp"
  54 #include "oops/methodData.hpp"
  55 #include "oops/objArrayKlass.hpp"
  56 #include "oops/objArrayOop.inline.hpp"


 380   }
 381   if (resolved_klass->is_instance_klass()) {
 382     return (Reflection::verify_class_access(accessing_klass->get_Klass(),
 383                                             InstanceKlass::cast(resolved_klass),
 384                                             true) == Reflection::ACCESS_OK);
 385   }
 386   return true;
 387 }
 388 
 389 // ------------------------------------------------------------------
 390 // ciEnv::get_klass_by_name_impl
 391 ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
 392                                        const constantPoolHandle& cpool,
 393                                        ciSymbol* name,
 394                                        bool require_local) {
 395   ASSERT_IN_VM;
 396   EXCEPTION_CONTEXT;
 397 
 398   // Now we need to check the SystemDictionary
 399   Symbol* sym = name->get_symbol();
 400   if ((sym->char_at(0) == 'L' || sym->char_at(0) == 'Q') &&
 401       sym->char_at(sym->utf8_length()-1) == ';') {
 402     // This is a name from a signature.  Strip off the trimmings.
 403     // Call recursive to keep scope of strippedsym.
 404     TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
 405                     sym->utf8_length()-2,
 406                     KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass));
 407     ciSymbol* strippedname = get_symbol(strippedsym);
 408     return get_klass_by_name_impl(accessing_klass, cpool, strippedname, require_local);
 409   }
 410 
 411   // Check for prior unloaded klass.  The SystemDictionary's answers
 412   // can vary over time but the compiler needs consistency.
 413   ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
 414   if (unloaded_klass != NULL) {
 415     if (require_local)  return NULL;
 416     return unloaded_klass;
 417   }
 418 
 419   Handle loader(THREAD, (oop)NULL);
 420   Handle domain(THREAD, (oop)NULL);


 435     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 436     MutexLocker ml(Compile_lock);
 437     Klass* kls;
 438     if (!require_local) {
 439       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
 440                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
 441     } else {
 442       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
 443                                                            KILL_COMPILE_ON_FATAL_(fail_type));
 444     }
 445     found_klass = kls;
 446   }
 447 
 448   // If we fail to find an array klass, look again for its element type.
 449   // The element type may be available either locally or via constraints.
 450   // In either case, if we can find the element type in the system dictionary,
 451   // we must build an array type around it.  The CI requires array klasses
 452   // to be loaded if their element klasses are loaded, except when memory
 453   // is exhausted.
 454   if (sym->char_at(0) == '[' &&
 455       (sym->char_at(1) == '[' || sym->char_at(1) == 'L' || sym->char_at(1) == 'Q')) {
 456     // We have an unloaded array.
 457     // Build it on the fly if the element class exists.
 458     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
 459                                                  sym->utf8_length()-1,
 460                                                  KILL_COMPILE_ON_FATAL_(fail_type));
 461 
 462     // Get element ciKlass recursively.
 463     ciKlass* elem_klass =
 464       get_klass_by_name_impl(accessing_klass,
 465                              cpool,
 466                              get_symbol(elem_sym),
 467                              require_local);
 468     if (elem_klass != NULL && elem_klass->is_loaded()) {
 469       // Now make an array for it
 470       if (elem_klass->is_valuetype() && elem_klass->as_value_klass()->flatten_array()) {
 471         return ciValueArrayKlass::make_impl(elem_klass);
 472       } else {
 473         return ciObjArrayKlass::make_impl(elem_klass);
 474       }
 475     }
 476   }
 477 
 478   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 479     // Look inside the constant pool for pre-resolved class entries.
 480     for (int i = cpool->length() - 1; i >= 1; i--) {
 481       if (cpool->tag_at(i).is_klass()) {
 482         Klass* kls = cpool->resolved_klass_at(i);
 483         if (kls->name() == sym) {
 484           found_klass = kls;
 485           break;
 486         }
 487       }
 488     }
 489   }
 490 
 491   if (found_klass != NULL) {
 492     // Found it.  Build a CI handle.
 493     return get_klass(found_klass);
 494   }
 495 
 496   if (require_local)  return NULL;
 497 
 498   // Not yet loaded into the VM, or not governed by loader constraints.
 499   // Make a CI representative for it.
 500   int i = 0;
 501   while (sym->char_at(i) == '[') {
 502     i++;
 503   }
 504   if (i > 0 && sym->char_at(i) == 'Q') {
 505     // An unloaded array class of value types is an ObjArrayKlass, an
 506     // unloaded value type class is an InstanceKlass. For consistency,
 507     // make the signature of the unloaded array of value type use L
 508     // rather than Q.
 509     char *new_name = CURRENT_THREAD_ENV->name_buffer(sym->utf8_length()+1);
 510     strncpy(new_name, (char*)sym->base(), sym->utf8_length());
 511     new_name[i] = 'L';
 512     new_name[sym->utf8_length()] = '\0';
 513     return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
 514   }
 515   return get_unloaded_klass(accessing_klass, name);
 516 }
 517 
 518 // ------------------------------------------------------------------
 519 // ciEnv::get_klass_by_name
 520 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 521                                   ciSymbol* klass_name,
 522                                   bool require_local) {
 523   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 524                                                  constantPoolHandle(),
 525                                                  klass_name,
 526                                                  require_local);)
 527 }
 528 
 529 // ------------------------------------------------------------------
 530 // ciEnv::get_klass_by_index_impl
 531 //
 532 // Implementation of get_klass_by_index.
 533 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 534                                         int index,


 575   ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
 576   if (unloaded_klass != NULL) {
 577     is_accessible = false;
 578     return unloaded_klass;
 579   }
 580 
 581   // It is known to be accessible, since it was found in the constant pool.
 582   is_accessible = true;
 583   return get_klass(klass);
 584 }
 585 
 586 // ------------------------------------------------------------------
 587 // ciEnv::get_klass_by_index
 588 //
 589 // Get a klass from the constant pool.
 590 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 591                                    int index,
 592                                    bool& is_accessible,
 593                                    ciInstanceKlass* accessor) {
 594   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 595 }
 596 
 597 // ------------------------------------------------------------------
 598 // ciEnv::is_klass_never_null_impl
 599 //
 600 // Implementation of is_klass_never_null.
 601 bool ciEnv::is_klass_never_null_impl(const constantPoolHandle& cpool, int index) {
 602   Symbol* klass_name = cpool->klass_name_at(index);
 603   return klass_name->is_Q_signature();
 604 }
 605 
 606 // ------------------------------------------------------------------
 607 // ciEnv::is_klass_never_null
 608 //
 609 // Get information about nullability from the constant pool.
 610 bool ciEnv::is_klass_never_null(const constantPoolHandle& cpool, int index) {
 611   GUARDED_VM_ENTRY(return is_klass_never_null_impl(cpool, index);)
 612 }
 613 
 614 // ------------------------------------------------------------------
 615 // ciEnv::get_constant_by_index_impl
 616 //
 617 // Implementation of get_constant_by_index().
 618 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
 619                                              int pool_index, int cache_index,
 620                                              ciInstanceKlass* accessor) {
 621   bool ignore_will_link;
 622   EXCEPTION_CONTEXT;
 623   int index = pool_index;
 624   if (cache_index >= 0) {
 625     assert(index < 0, "only one kind of index at a time");
 626     index = cpool->object_to_cp_index(cache_index);
 627     oop obj = cpool->resolved_references()->obj_at(cache_index);
 628     if (obj != NULL) {
 629       if (oopDesc::equals(obj, Universe::the_null_sentinel())) {
 630         return ciConstant(T_OBJECT, get_object(NULL));
 631       }


< prev index next >