< prev index next >

src/hotspot/share/ci/ciEnv.cpp

Print this page

  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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/ciSymbols.hpp"
  36 #include "ci/ciUtilities.inline.hpp"
  37 #include "classfile/javaClasses.hpp"
  38 #include "classfile/javaClasses.inline.hpp"
  39 #include "classfile/symbolTable.hpp"
  40 #include "classfile/systemDictionary.hpp"
  41 #include "classfile/vmClasses.hpp"
  42 #include "classfile/vmSymbols.hpp"
  43 #include "code/codeCache.hpp"
  44 #include "code/scopeDesc.hpp"
  45 #include "compiler/compilationPolicy.hpp"
  46 #include "compiler/compileBroker.hpp"
  47 #include "compiler/compilerEvent.hpp"
  48 #include "compiler/compileLog.hpp"
  49 #include "compiler/compileTask.hpp"

 513   Klass* found_klass;
 514   {
 515     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 516     MutexLocker ml(current, Compile_lock);
 517     Klass* kls;
 518     if (!require_local) {
 519       kls = SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
 520     } else {
 521       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
 522     }
 523     found_klass = kls;
 524   }
 525 
 526   // If we fail to find an array klass, look again for its element type.
 527   // The element type may be available either locally or via constraints.
 528   // In either case, if we can find the element type in the system dictionary,
 529   // we must build an array type around it.  The CI requires array klasses
 530   // to be loaded if their element klasses are loaded, except when memory
 531   // is exhausted.
 532   if (Signature::is_array(sym) &&
 533       (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {


 534     // We have an unloaded array.
 535     // Build it on the fly if the element class exists.
 536     SignatureStream ss(sym, false);
 537     ss.skip_array_prefix(1);
 538     // Get element ciKlass recursively.
 539     ciKlass* elem_klass =
 540       get_klass_by_name_impl(accessing_klass,
 541                              cpool,
 542                              get_symbol(ss.as_symbol()),
 543                              require_local);
 544     if (elem_klass != NULL && elem_klass->is_loaded()) {
 545       // Now make an array for it
 546       return ciObjArrayKlass::make_impl(elem_klass);

 547     }
 548   }
 549 
 550   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 551     // Look inside the constant pool for pre-resolved class entries.
 552     for (int i = cpool->length() - 1; i >= 1; i--) {
 553       if (cpool->tag_at(i).is_klass()) {
 554         Klass* kls = cpool->resolved_klass_at(i);
 555         if (kls->name() == sym) {
 556           found_klass = kls;
 557           break;
 558         }
 559       }
 560     }
 561   }
 562 
 563   if (found_klass != NULL) {
 564     // Found it.  Build a CI handle.
 565     return get_klass(found_klass);
 566   }
 567 
 568   if (require_local)  return NULL;
 569 
 570   // Not yet loaded into the VM, or not governed by loader constraints.
 571   // Make a CI representative for it.















 572   return get_unloaded_klass(accessing_klass, name);
 573 }
 574 
 575 // ------------------------------------------------------------------
 576 // ciEnv::get_klass_by_name
 577 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 578                                   ciSymbol* klass_name,
 579                                   bool require_local) {
 580   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 581                                                  constantPoolHandle(),
 582                                                  klass_name,
 583                                                  require_local);)
 584 }
 585 
 586 // ------------------------------------------------------------------
 587 // ciEnv::get_klass_by_index_impl
 588 //
 589 // Implementation of get_klass_by_index.
 590 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 591                                         int index,
 592                                         bool& is_accessible,
 593                                         ciInstanceKlass* accessor) {
 594   EXCEPTION_CONTEXT;
 595   Klass* klass = NULL;
 596   Symbol* klass_name = NULL;
 597 
 598   if (cpool->tag_at(index).is_symbol()) {
 599     klass_name = cpool->symbol_at(index);
 600   } else {
 601     // Check if it's resolved if it's not a symbol constant pool entry.
 602     klass =  ConstantPool::klass_at_if_loaded(cpool, index);
 603     // Try to look it up by name.
 604     if (klass == NULL) {
 605       klass_name = cpool->klass_name_at(index);
 606     }
 607   }
 608 
 609   if (klass == NULL) {
 610     // Not found in constant pool.  Use the name to do the lookup.
 611     ciKlass* k = get_klass_by_name_impl(accessor,
 612                                         cpool,
 613                                         get_symbol(klass_name),
 614                                         false);
 615     // Calculate accessibility the hard way.
 616     if (!k->is_loaded()) {
 617       is_accessible = false;
 618     } else if (k->loader() != accessor->loader() &&
 619                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
 620       // Loaded only remotely.  Not linked yet.
 621       is_accessible = false;
 622     } else {

 634     is_accessible = false;
 635     return unloaded_klass;
 636   }
 637 
 638   // It is known to be accessible, since it was found in the constant pool.
 639   is_accessible = true;
 640   return get_klass(klass);
 641 }
 642 
 643 // ------------------------------------------------------------------
 644 // ciEnv::get_klass_by_index
 645 //
 646 // Get a klass from the constant pool.
 647 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 648                                    int index,
 649                                    bool& is_accessible,
 650                                    ciInstanceKlass* accessor) {
 651   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 652 }
 653 








 654 // ------------------------------------------------------------------
 655 // ciEnv::get_constant_by_index_impl
 656 //
 657 // Implementation of get_constant_by_index().
 658 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
 659                                              int pool_index, int cache_index,
 660                                              ciInstanceKlass* accessor) {
 661   bool ignore_will_link;
 662   EXCEPTION_CONTEXT;
 663   int index = pool_index;
 664   if (cache_index >= 0) {
 665     assert(index < 0, "only one kind of index at a time");
 666     index = cpool->object_to_cp_index(cache_index);
 667     oop obj = cpool->resolved_references()->obj_at(cache_index);
 668     if (obj != NULL) {
 669       if (obj == Universe::the_null_sentinel()) {
 670         return ciConstant(T_OBJECT, get_object(NULL));
 671       }
 672       BasicType bt = T_OBJECT;
 673       if (cpool->tag_at(index).is_dynamic_constant())

 720     }
 721     ciObject* constant = get_object(string);
 722     if (constant->is_array()) {
 723       return ciConstant(T_ARRAY, constant);
 724     } else {
 725       assert (constant->is_instance(), "must be an instance, or not? ");
 726       return ciConstant(T_OBJECT, constant);
 727     }
 728   } else if (tag.is_unresolved_klass_in_error()) {
 729     return ciConstant();
 730   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 731     // 4881222: allow ldc to take a class type
 732     ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
 733     if (HAS_PENDING_EXCEPTION) {
 734       CLEAR_PENDING_EXCEPTION;
 735       record_out_of_memory_failure();
 736       return ciConstant();
 737     }
 738     assert (klass->is_instance_klass() || klass->is_array_klass(),
 739             "must be an instance or array klass ");
 740     return ciConstant(T_OBJECT, klass->java_mirror());








 741   } else if (tag.is_method_type()) {
 742     // must execute Java code to link this CP entry into cache[i].f1
 743     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 744     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 745     return ciConstant(T_OBJECT, ciobj);
 746   } else if (tag.is_method_handle()) {
 747     // must execute Java code to link this CP entry into cache[i].f1
 748     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 749     int callee_index    = cpool->method_handle_klass_index_at(index);
 750     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 751     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 752     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 753     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 754     return ciConstant(T_OBJECT, ciobj);
 755   } else if (tag.is_dynamic_constant()) {
 756     return ciConstant();
 757   } else {
 758     ShouldNotReachHere();
 759     return ciConstant();
 760   }

  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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/ciInlineKlass.hpp"
  31 #include "ci/ciInstance.hpp"
  32 #include "ci/ciInstanceKlass.hpp"
  33 #include "ci/ciMethod.hpp"
  34 #include "ci/ciNullObject.hpp"
  35 #include "ci/ciReplay.hpp"
  36 #include "ci/ciSymbols.hpp"
  37 #include "ci/ciUtilities.inline.hpp"
  38 #include "classfile/javaClasses.hpp"
  39 #include "classfile/javaClasses.inline.hpp"
  40 #include "classfile/symbolTable.hpp"
  41 #include "classfile/systemDictionary.hpp"
  42 #include "classfile/vmClasses.hpp"
  43 #include "classfile/vmSymbols.hpp"
  44 #include "code/codeCache.hpp"
  45 #include "code/scopeDesc.hpp"
  46 #include "compiler/compilationPolicy.hpp"
  47 #include "compiler/compileBroker.hpp"
  48 #include "compiler/compilerEvent.hpp"
  49 #include "compiler/compileLog.hpp"
  50 #include "compiler/compileTask.hpp"

 514   Klass* found_klass;
 515   {
 516     ttyUnlocker ttyul;  // release tty lock to avoid ordering problems
 517     MutexLocker ml(current, Compile_lock);
 518     Klass* kls;
 519     if (!require_local) {
 520       kls = SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
 521     } else {
 522       kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
 523     }
 524     found_klass = kls;
 525   }
 526 
 527   // If we fail to find an array klass, look again for its element type.
 528   // The element type may be available either locally or via constraints.
 529   // In either case, if we can find the element type in the system dictionary,
 530   // we must build an array type around it.  The CI requires array klasses
 531   // to be loaded if their element klasses are loaded, except when memory
 532   // is exhausted.
 533   if (Signature::is_array(sym) &&
 534       (sym->char_at(1) == JVM_SIGNATURE_ARRAY ||
 535        sym->char_at(1) == JVM_SIGNATURE_CLASS ||
 536        sym->char_at(1) == JVM_SIGNATURE_INLINE_TYPE )) {
 537     // We have an unloaded array.
 538     // Build it on the fly if the element class exists.
 539     SignatureStream ss(sym, false);
 540     ss.skip_array_prefix(1);
 541     // Get element ciKlass recursively.
 542     ciKlass* elem_klass =
 543       get_klass_by_name_impl(accessing_klass,
 544                              cpool,
 545                              get_symbol(ss.as_symbol()),
 546                              require_local);
 547     if (elem_klass != NULL && elem_klass->is_loaded()) {
 548       // Now make an array for it
 549       bool null_free_array = sym->is_Q_array_signature() && sym->char_at(1) == JVM_SIGNATURE_INLINE_TYPE;
 550       return ciArrayKlass::make(elem_klass, null_free_array);
 551     }
 552   }
 553 
 554   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 555     // Look inside the constant pool for pre-resolved class entries.
 556     for (int i = cpool->length() - 1; i >= 1; i--) {
 557       if (cpool->tag_at(i).is_klass()) {
 558         Klass* kls = cpool->resolved_klass_at(i);
 559         if (kls->name() == sym) {
 560           found_klass = kls;
 561           break;
 562         }
 563       }
 564     }
 565   }
 566 
 567   if (found_klass != NULL) {
 568     // Found it.  Build a CI handle.
 569     return get_klass(found_klass);
 570   }
 571 
 572   if (require_local)  return NULL;
 573 
 574   // Not yet loaded into the VM, or not governed by loader constraints.
 575   // Make a CI representative for it.
 576   int i = 0;
 577   while (sym->char_at(i) == JVM_SIGNATURE_ARRAY) {
 578     i++;
 579   }
 580   if (i > 0 && sym->char_at(i) == JVM_SIGNATURE_INLINE_TYPE) {
 581     // An unloaded array class of inline types is an ObjArrayKlass, an
 582     // unloaded inline type class is an InstanceKlass. For consistency,
 583     // make the signature of the unloaded array of inline type use L
 584     // rather than Q.
 585     char* new_name = name_buffer(sym->utf8_length()+1);
 586     strncpy(new_name, (char*)sym->base(), sym->utf8_length());
 587     new_name[i] = JVM_SIGNATURE_CLASS;
 588     new_name[sym->utf8_length()] = '\0';
 589     return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
 590   }
 591   return get_unloaded_klass(accessing_klass, name);
 592 }
 593 
 594 // ------------------------------------------------------------------
 595 // ciEnv::get_klass_by_name
 596 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 597                                   ciSymbol* klass_name,
 598                                   bool require_local) {
 599   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 600                                                  constantPoolHandle(),
 601                                                  klass_name,
 602                                                  require_local);)
 603 }
 604 
 605 // ------------------------------------------------------------------
 606 // ciEnv::get_klass_by_index_impl
 607 //
 608 // Implementation of get_klass_by_index.
 609 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 610                                         int index,
 611                                         bool& is_accessible,
 612                                         ciInstanceKlass* accessor) {
 613   EXCEPTION_CONTEXT;
 614   Klass* klass = NULL;
 615   Symbol* klass_name = NULL;
 616 
 617   if (cpool->tag_at(index).is_symbol()) {
 618     klass_name = cpool->symbol_at(index);
 619   } else {
 620     // Check if it's resolved if it's not a symbol constant pool entry.
 621     klass = ConstantPool::klass_at_if_loaded(cpool, index);
 622     // Try to look it up by name.
 623     if (klass == NULL) {
 624       klass_name = cpool->klass_name_at(index);
 625     }
 626   }
 627 
 628   if (klass == NULL) {
 629     // Not found in constant pool.  Use the name to do the lookup.
 630     ciKlass* k = get_klass_by_name_impl(accessor,
 631                                         cpool,
 632                                         get_symbol(klass_name),
 633                                         false);
 634     // Calculate accessibility the hard way.
 635     if (!k->is_loaded()) {
 636       is_accessible = false;
 637     } else if (k->loader() != accessor->loader() &&
 638                get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) {
 639       // Loaded only remotely.  Not linked yet.
 640       is_accessible = false;
 641     } else {

 653     is_accessible = false;
 654     return unloaded_klass;
 655   }
 656 
 657   // It is known to be accessible, since it was found in the constant pool.
 658   is_accessible = true;
 659   return get_klass(klass);
 660 }
 661 
 662 // ------------------------------------------------------------------
 663 // ciEnv::get_klass_by_index
 664 //
 665 // Get a klass from the constant pool.
 666 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 667                                    int index,
 668                                    bool& is_accessible,
 669                                    ciInstanceKlass* accessor) {
 670   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 671 }
 672 
 673 // ------------------------------------------------------------------
 674 // ciEnv::is_inline_klass
 675 //
 676 // Check if the klass is an inline klass.
 677 bool ciEnv::has_Q_signature(const constantPoolHandle& cpool, int index) {
 678   GUARDED_VM_ENTRY(return cpool->klass_name_at(index)->is_Q_signature();)
 679 }
 680 
 681 // ------------------------------------------------------------------
 682 // ciEnv::get_constant_by_index_impl
 683 //
 684 // Implementation of get_constant_by_index().
 685 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
 686                                              int pool_index, int cache_index,
 687                                              ciInstanceKlass* accessor) {
 688   bool ignore_will_link;
 689   EXCEPTION_CONTEXT;
 690   int index = pool_index;
 691   if (cache_index >= 0) {
 692     assert(index < 0, "only one kind of index at a time");
 693     index = cpool->object_to_cp_index(cache_index);
 694     oop obj = cpool->resolved_references()->obj_at(cache_index);
 695     if (obj != NULL) {
 696       if (obj == Universe::the_null_sentinel()) {
 697         return ciConstant(T_OBJECT, get_object(NULL));
 698       }
 699       BasicType bt = T_OBJECT;
 700       if (cpool->tag_at(index).is_dynamic_constant())

 747     }
 748     ciObject* constant = get_object(string);
 749     if (constant->is_array()) {
 750       return ciConstant(T_ARRAY, constant);
 751     } else {
 752       assert (constant->is_instance(), "must be an instance, or not? ");
 753       return ciConstant(T_OBJECT, constant);
 754     }
 755   } else if (tag.is_unresolved_klass_in_error()) {
 756     return ciConstant();
 757   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 758     // 4881222: allow ldc to take a class type
 759     ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
 760     if (HAS_PENDING_EXCEPTION) {
 761       CLEAR_PENDING_EXCEPTION;
 762       record_out_of_memory_failure();
 763       return ciConstant();
 764     }
 765     assert (klass->is_instance_klass() || klass->is_array_klass(),
 766             "must be an instance or array klass ");
 767     if (!klass->is_loaded()) {
 768       return ciConstant(T_OBJECT, get_unloaded_klass_mirror(klass));
 769     } else {
 770       if (tag.is_Qdescriptor_klass()) {
 771         return ciConstant(T_OBJECT, klass->as_inline_klass()->val_mirror());
 772       } else {
 773         return ciConstant(T_OBJECT, klass->java_mirror());
 774       }
 775     }
 776   } else if (tag.is_method_type()) {
 777     // must execute Java code to link this CP entry into cache[i].f1
 778     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 779     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 780     return ciConstant(T_OBJECT, ciobj);
 781   } else if (tag.is_method_handle()) {
 782     // must execute Java code to link this CP entry into cache[i].f1
 783     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 784     int callee_index    = cpool->method_handle_klass_index_at(index);
 785     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 786     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 787     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 788     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 789     return ciConstant(T_OBJECT, ciobj);
 790   } else if (tag.is_dynamic_constant()) {
 791     return ciConstant();
 792   } else {
 793     ShouldNotReachHere();
 794     return ciConstant();
 795   }
< prev index next >