< 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/symbolTable.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 "logging/log.hpp"
  48 #include "memory/allocation.inline.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/constantPool.inline.hpp"
  53 #include "oops/cpCache.inline.hpp"
  54 #include "oops/method.inline.hpp"
  55 #include "oops/methodData.hpp"


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


 438     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 439     MutexLocker ml(Compile_lock);
 440     Klass* kls;
 441     if (!require_local) {
 442       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
 443                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
 444     } else {
 445       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
 446                                                            KILL_COMPILE_ON_FATAL_(fail_type));
 447     }
 448     found_klass = kls;
 449   }
 450 
 451   // If we fail to find an array klass, look again for its element type.
 452   // The element type may be available either locally or via constraints.
 453   // In either case, if we can find the element type in the system dictionary,
 454   // we must build an array type around it.  The CI requires array klasses
 455   // to be loaded if their element klasses are loaded, except when memory
 456   // is exhausted.
 457   if (sym->char_at(0) == '[' &&
 458       (sym->char_at(1) == '[' || sym->char_at(1) == 'L')) {
 459     // We have an unloaded array.
 460     // Build it on the fly if the element class exists.
 461     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
 462                                                      sym->utf8_length()-1);
 463 
 464     // Get element ciKlass recursively.
 465     ciKlass* elem_klass =
 466       get_klass_by_name_impl(accessing_klass,
 467                              cpool,
 468                              get_symbol(elem_sym),
 469                              require_local);
 470     if (elem_klass != NULL && elem_klass->is_loaded()) {
 471       // Now make an array for it
 472       return ciObjArrayKlass::make_impl(elem_klass);
 473     }
 474   }
 475 
 476   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 477     // Look inside the constant pool for pre-resolved class entries.
 478     for (int i = cpool->length() - 1; i >= 1; i--) {
 479       if (cpool->tag_at(i).is_klass()) {
 480         Klass* kls = cpool->resolved_klass_at(i);
 481         if (kls->name() == sym) {
 482           found_klass = kls;
 483           break;
 484         }
 485       }
 486     }
 487   }
 488 
 489   if (found_klass != NULL) {
 490     // Found it.  Build a CI handle.
 491     return get_klass(found_klass);
 492   }
 493 
 494   if (require_local)  return NULL;
 495 
 496   // Not yet loaded into the VM, or not governed by loader constraints.
 497   // Make a CI representative for it.















 498   return get_unloaded_klass(accessing_klass, name);
 499 }
 500 
 501 // ------------------------------------------------------------------
 502 // ciEnv::get_klass_by_name
 503 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 504                                   ciSymbol* klass_name,
 505                                   bool require_local) {
 506   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 507                                                  constantPoolHandle(),
 508                                                  klass_name,
 509                                                  require_local);)
 510 }
 511 
 512 // ------------------------------------------------------------------
 513 // ciEnv::get_klass_by_index_impl
 514 //
 515 // Implementation of get_klass_by_index.
 516 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 517                                         int index,
 518                                         bool& is_accessible,
 519                                         ciInstanceKlass* accessor) {
 520   EXCEPTION_CONTEXT;
 521   Klass* klass = NULL;
 522   Symbol* klass_name = NULL;
 523 
 524   if (cpool->tag_at(index).is_symbol()) {
 525     klass_name = cpool->symbol_at(index);
 526   } else {
 527     // Check if it's resolved if it's not a symbol constant pool entry.
 528     klass =  ConstantPool::klass_at_if_loaded(cpool, index);
 529     // Try to look it up by name.
 530     if (klass == NULL) {
 531       klass_name = cpool->klass_name_at(index);
 532     }
 533   }
 534 
 535   if (klass == NULL) {
 536     // Not found in constant pool.  Use the name to do the lookup.
 537     ciKlass* k = get_klass_by_name_impl(accessor,
 538                                         cpool,
 539                                         get_symbol(klass_name),
 540                                         false);
 541     // Calculate accessibility the hard way.
 542     if (!k->is_loaded()) {
 543       is_accessible = false;
 544     } else if (!oopDesc::equals(k->loader(), accessor->loader()) &&
 545                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
 546       // Loaded only remotely.  Not linked yet.
 547       is_accessible = false;
 548     } else {


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








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




  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/symbolTable.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/codeCache.hpp"
  41 #include "code/scopeDesc.hpp"
  42 #include "compiler/compileBroker.hpp"
  43 #include "compiler/compileLog.hpp"
  44 #include "compiler/disassembler.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "interpreter/linkResolver.hpp"
  47 #include "jfr/jfrEvents.hpp"
  48 #include "logging/log.hpp"
  49 #include "memory/allocation.inline.hpp"
  50 #include "memory/oopFactory.hpp"
  51 #include "memory/resourceArea.hpp"
  52 #include "memory/universe.hpp"
  53 #include "oops/constantPool.inline.hpp"
  54 #include "oops/cpCache.inline.hpp"
  55 #include "oops/method.inline.hpp"
  56 #include "oops/methodData.hpp"


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


 439     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 440     MutexLocker ml(Compile_lock);
 441     Klass* kls;
 442     if (!require_local) {
 443       kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
 444                                                                        KILL_COMPILE_ON_FATAL_(fail_type));
 445     } else {
 446       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
 447                                                            KILL_COMPILE_ON_FATAL_(fail_type));
 448     }
 449     found_klass = kls;
 450   }
 451 
 452   // If we fail to find an array klass, look again for its element type.
 453   // The element type may be available either locally or via constraints.
 454   // In either case, if we can find the element type in the system dictionary,
 455   // we must build an array type around it.  The CI requires array klasses
 456   // to be loaded if their element klasses are loaded, except when memory
 457   // is exhausted.
 458   if (sym->char_at(0) == '[' &&
 459       (sym->char_at(1) == '[' || sym->char_at(1) == 'L' || sym->char_at(1) == 'Q')) {
 460     // We have an unloaded array.
 461     // Build it on the fly if the element class exists.
 462     TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
 463                                                      sym->utf8_length()-1);
 464 
 465     // Get element ciKlass recursively.
 466     ciKlass* elem_klass =
 467       get_klass_by_name_impl(accessing_klass,
 468                              cpool,
 469                              get_symbol(elem_sym),
 470                              require_local);
 471     if (elem_klass != NULL && elem_klass->is_loaded()) {
 472       // Now make an array for it
 473       return ciArrayKlass::make(elem_klass, sym->char_at(1) == 'Q');
 474     }
 475   }
 476 
 477   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 478     // Look inside the constant pool for pre-resolved class entries.
 479     for (int i = cpool->length() - 1; i >= 1; i--) {
 480       if (cpool->tag_at(i).is_klass()) {
 481         Klass* kls = cpool->resolved_klass_at(i);
 482         if (kls->name() == sym) {
 483           found_klass = kls;
 484           break;
 485         }
 486       }
 487     }
 488   }
 489 
 490   if (found_klass != NULL) {
 491     // Found it.  Build a CI handle.
 492     return get_klass(found_klass);
 493   }
 494 
 495   if (require_local)  return NULL;
 496 
 497   // Not yet loaded into the VM, or not governed by loader constraints.
 498   // Make a CI representative for it.
 499   int i = 0;
 500   while (sym->char_at(i) == '[') {
 501     i++;
 502   }
 503   if (i > 0 && sym->char_at(i) == 'Q') {
 504     // An unloaded array class of value types is an ObjArrayKlass, an
 505     // unloaded value type class is an InstanceKlass. For consistency,
 506     // make the signature of the unloaded array of value type use L
 507     // rather than Q.
 508     char *new_name = CURRENT_THREAD_ENV->name_buffer(sym->utf8_length()+1);
 509     strncpy(new_name, (char*)sym->base(), sym->utf8_length());
 510     new_name[i] = 'L';
 511     new_name[sym->utf8_length()] = '\0';
 512     return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
 513   }
 514   return get_unloaded_klass(accessing_klass, name);
 515 }
 516 
 517 // ------------------------------------------------------------------
 518 // ciEnv::get_klass_by_name
 519 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 520                                   ciSymbol* klass_name,
 521                                   bool require_local) {
 522   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 523                                                  constantPoolHandle(),
 524                                                  klass_name,
 525                                                  require_local);)
 526 }
 527 
 528 // ------------------------------------------------------------------
 529 // ciEnv::get_klass_by_index_impl
 530 //
 531 // Implementation of get_klass_by_index.
 532 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 533                                         int index,
 534                                         bool& is_accessible,
 535                                         ciInstanceKlass* accessor) {
 536   EXCEPTION_CONTEXT;
 537   Klass* klass = NULL;
 538   Symbol* klass_name = NULL;
 539 
 540   if (cpool->tag_at(index).is_symbol()) {
 541     klass_name = cpool->symbol_at(index);
 542   } else {
 543     // Check if it's resolved if it's not a symbol constant pool entry.
 544     klass = ConstantPool::klass_at_if_loaded(cpool, index);
 545     // Try to look it up by name.
 546     if (klass == NULL) {
 547       klass_name = cpool->klass_name_at(index);
 548     }
 549   }
 550 
 551   if (klass == NULL) {
 552     // Not found in constant pool.  Use the name to do the lookup.
 553     ciKlass* k = get_klass_by_name_impl(accessor,
 554                                         cpool,
 555                                         get_symbol(klass_name),
 556                                         false);
 557     // Calculate accessibility the hard way.
 558     if (!k->is_loaded()) {
 559       is_accessible = false;
 560     } else if (!oopDesc::equals(k->loader(), accessor->loader()) &&
 561                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
 562       // Loaded only remotely.  Not linked yet.
 563       is_accessible = false;
 564     } else {


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


< prev index next >