< 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/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/codeCache.hpp"
  43 #include "code/scopeDesc.hpp"
  44 #include "compiler/compilationLog.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"

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


 545     // We have an unloaded array.
 546     // Build it on the fly if the element class exists.
 547     SignatureStream ss(sym, false);
 548     ss.skip_array_prefix(1);
 549     // Get element ciKlass recursively.
 550     ciKlass* elem_klass =
 551       get_klass_by_name_impl(accessing_klass,
 552                              cpool,
 553                              get_symbol(ss.as_symbol()),
 554                              require_local);
 555     if (elem_klass != NULL && elem_klass->is_loaded()) {
 556       // Now make an array for it
 557       return ciObjArrayKlass::make_impl(elem_klass);

 558     }
 559   }
 560 
 561   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 562     // Look inside the constant pool for pre-resolved class entries.
 563     for (int i = cpool->length() - 1; i >= 1; i--) {
 564       if (cpool->tag_at(i).is_klass()) {
 565         Klass* kls = cpool->resolved_klass_at(i);
 566         if (kls->name() == sym) {
 567           found_klass = kls;
 568           break;
 569         }
 570       }
 571     }
 572   }
 573 
 574   if (found_klass != NULL) {
 575     // Found it.  Build a CI handle.
 576     return get_klass(found_klass);
 577   }
 578 
 579   if (require_local)  return NULL;
 580 
 581   // Not yet loaded into the VM, or not governed by loader constraints.
 582   // Make a CI representative for it.















 583   return get_unloaded_klass(accessing_klass, name);
 584 }
 585 
 586 // ------------------------------------------------------------------
 587 // ciEnv::get_klass_by_name
 588 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 589                                   ciSymbol* klass_name,
 590                                   bool require_local) {
 591   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 592                                                  constantPoolHandle(),
 593                                                  klass_name,
 594                                                  require_local);)
 595 }
 596 
 597 // ------------------------------------------------------------------
 598 // ciEnv::get_klass_by_index_impl
 599 //
 600 // Implementation of get_klass_by_index.
 601 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 602                                         int index,

 649   ciKlass* ciKlass = get_klass(klass);
 650   is_accessible = true;
 651   if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
 652     // Klass was unresolved at replay dump time and therefore not accessible.
 653     is_accessible = false;
 654   }
 655   return ciKlass;
 656 }
 657 
 658 // ------------------------------------------------------------------
 659 // ciEnv::get_klass_by_index
 660 //
 661 // Get a klass from the constant pool.
 662 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 663                                    int index,
 664                                    bool& is_accessible,
 665                                    ciInstanceKlass* accessor) {
 666   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 667 }
 668 








 669 // ------------------------------------------------------------------
 670 // ciEnv::unbox_primitive_value
 671 //
 672 // Unbox a primitive and return it as a ciConstant.
 673 ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt) {
 674   jvalue value;
 675   BasicType bt = java_lang_boxing_object::get_value(cibox->get_oop(), &value);
 676   if (bt != expected_bt && expected_bt != T_ILLEGAL) {
 677     assert(false, "type mismatch: %s vs %s", type2name(expected_bt), cibox->klass()->name()->as_klass_external_name());
 678     return ciConstant();
 679   }
 680   switch (bt) {
 681     case T_BOOLEAN: return ciConstant(bt, value.z);
 682     case T_BYTE:    return ciConstant(bt, value.b);
 683     case T_SHORT:   return ciConstant(bt, value.s);
 684     case T_CHAR:    return ciConstant(bt, value.c);
 685     case T_INT:     return ciConstant(bt, value.i);
 686     case T_LONG:    return ciConstant(value.j);
 687     case T_FLOAT:   return ciConstant(value.f);
 688     case T_DOUBLE:  return ciConstant(value.d);

 745     return ciConstant((jfloat)cpool->float_at(index));
 746   } else if (tag.is_double()) {
 747     return ciConstant((jdouble)cpool->double_at(index));
 748   } else if (tag.is_string()) {
 749     EXCEPTION_CONTEXT;
 750     assert(obj_index >= 0, "should have an object index");
 751     oop string = cpool->string_at(index, obj_index, THREAD);
 752     if (HAS_PENDING_EXCEPTION) {
 753       CLEAR_PENDING_EXCEPTION;
 754       record_out_of_memory_failure();
 755       return ciConstant();
 756     }
 757     ciInstance* constant = get_object(string)->as_instance();
 758     return ciConstant(T_OBJECT, constant);
 759   } else if (tag.is_unresolved_klass_in_error()) {
 760     return ciConstant(T_OBJECT, get_unloaded_klass_mirror(NULL));
 761   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 762     bool will_link;
 763     ciKlass* klass = get_klass_by_index_impl(cpool, index, will_link, accessor);
 764     ciInstance* mirror = (will_link ? klass->java_mirror() : get_unloaded_klass_mirror(klass));
 765     return ciConstant(T_OBJECT, mirror);




 766   } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
 767     // must execute Java code to link this CP entry into cache[i].f1
 768     assert(obj_index >= 0, "should have an object index");
 769     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 770     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 771     return ciConstant(T_OBJECT, ciobj);
 772   } else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
 773     // must execute Java code to link this CP entry into cache[i].f1
 774     assert(obj_index >= 0, "should have an object index");
 775     bool ignore_will_link;
 776     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 777     int callee_index    = cpool->method_handle_klass_index_at(index);
 778     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 779     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 780     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 781     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 782     return ciConstant(T_OBJECT, ciobj);
 783   } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 784     assert(obj_index >= 0, "should have an object index");
 785     return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant

  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/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/compilationLog.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"

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

 668   ciKlass* ciKlass = get_klass(klass);
 669   is_accessible = true;
 670   if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
 671     // Klass was unresolved at replay dump time and therefore not accessible.
 672     is_accessible = false;
 673   }
 674   return ciKlass;
 675 }
 676 
 677 // ------------------------------------------------------------------
 678 // ciEnv::get_klass_by_index
 679 //
 680 // Get a klass from the constant pool.
 681 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 682                                    int index,
 683                                    bool& is_accessible,
 684                                    ciInstanceKlass* accessor) {
 685   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 686 }
 687 
 688 // ------------------------------------------------------------------
 689 // ciEnv::is_inline_klass
 690 //
 691 // Check if the klass is an inline klass.
 692 bool ciEnv::has_Q_signature(const constantPoolHandle& cpool, int index) {
 693   GUARDED_VM_ENTRY(return cpool->klass_name_at(index)->is_Q_signature();)
 694 }
 695 
 696 // ------------------------------------------------------------------
 697 // ciEnv::unbox_primitive_value
 698 //
 699 // Unbox a primitive and return it as a ciConstant.
 700 ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt) {
 701   jvalue value;
 702   BasicType bt = java_lang_boxing_object::get_value(cibox->get_oop(), &value);
 703   if (bt != expected_bt && expected_bt != T_ILLEGAL) {
 704     assert(false, "type mismatch: %s vs %s", type2name(expected_bt), cibox->klass()->name()->as_klass_external_name());
 705     return ciConstant();
 706   }
 707   switch (bt) {
 708     case T_BOOLEAN: return ciConstant(bt, value.z);
 709     case T_BYTE:    return ciConstant(bt, value.b);
 710     case T_SHORT:   return ciConstant(bt, value.s);
 711     case T_CHAR:    return ciConstant(bt, value.c);
 712     case T_INT:     return ciConstant(bt, value.i);
 713     case T_LONG:    return ciConstant(value.j);
 714     case T_FLOAT:   return ciConstant(value.f);
 715     case T_DOUBLE:  return ciConstant(value.d);

 772     return ciConstant((jfloat)cpool->float_at(index));
 773   } else if (tag.is_double()) {
 774     return ciConstant((jdouble)cpool->double_at(index));
 775   } else if (tag.is_string()) {
 776     EXCEPTION_CONTEXT;
 777     assert(obj_index >= 0, "should have an object index");
 778     oop string = cpool->string_at(index, obj_index, THREAD);
 779     if (HAS_PENDING_EXCEPTION) {
 780       CLEAR_PENDING_EXCEPTION;
 781       record_out_of_memory_failure();
 782       return ciConstant();
 783     }
 784     ciInstance* constant = get_object(string)->as_instance();
 785     return ciConstant(T_OBJECT, constant);
 786   } else if (tag.is_unresolved_klass_in_error()) {
 787     return ciConstant(T_OBJECT, get_unloaded_klass_mirror(NULL));
 788   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 789     bool will_link;
 790     ciKlass* klass = get_klass_by_index_impl(cpool, index, will_link, accessor);
 791     ciInstance* mirror = (will_link ? klass->java_mirror() : get_unloaded_klass_mirror(klass));
 792     if (klass->is_loaded() && tag.is_Qdescriptor_klass()) {
 793       return ciConstant(T_OBJECT, klass->as_inline_klass()->val_mirror());
 794     } else {
 795       return ciConstant(T_OBJECT, mirror);
 796     }
 797   } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
 798     // must execute Java code to link this CP entry into cache[i].f1
 799     assert(obj_index >= 0, "should have an object index");
 800     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 801     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 802     return ciConstant(T_OBJECT, ciobj);
 803   } else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
 804     // must execute Java code to link this CP entry into cache[i].f1
 805     assert(obj_index >= 0, "should have an object index");
 806     bool ignore_will_link;
 807     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 808     int callee_index    = cpool->method_handle_klass_index_at(index);
 809     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 810     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 811     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 812     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 813     return ciConstant(T_OBJECT, ciobj);
 814   } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 815     assert(obj_index >= 0, "should have an object index");
 816     return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant
< prev index next >