< prev index next >

src/hotspot/share/ci/ciEnv.cpp

Print this page

   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 "ci/ciConstant.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciField.hpp"

  29 #include "ci/ciInstance.hpp"
  30 #include "ci/ciInstanceKlass.hpp"
  31 #include "ci/ciMethod.hpp"
  32 #include "ci/ciNullObject.hpp"
  33 #include "ci/ciReplay.hpp"
  34 #include "ci/ciSymbols.hpp"
  35 #include "ci/ciUtilities.inline.hpp"
  36 #include "classfile/javaClasses.hpp"
  37 #include "classfile/javaClasses.inline.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #include "classfile/vmClasses.hpp"
  40 #include "classfile/vmSymbols.hpp"
  41 #include "code/codeCache.hpp"
  42 #include "code/scopeDesc.hpp"
  43 #include "compiler/compilationLog.hpp"
  44 #include "compiler/compilationPolicy.hpp"
  45 #include "compiler/compileBroker.hpp"
  46 #include "compiler/compilerEvent.hpp"
  47 #include "compiler/compileLog.hpp"
  48 #include "compiler/compileTask.hpp"

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


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

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















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

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








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

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




 760   } else if (tag.is_method_type() || tag.is_method_type_in_error()) {
 761     // must execute Java code to link this CP entry into cache[i].f1
 762     assert(obj_index >= 0, "should have an object index");
 763     ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
 764     ciObject* ciobj = get_unloaded_method_type_constant(signature);
 765     return ciConstant(T_OBJECT, ciobj);
 766   } else if (tag.is_method_handle() || tag.is_method_handle_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     bool ignore_will_link;
 770     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 771     int callee_index    = cpool->method_handle_klass_index_at(index);
 772     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 773     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 774     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 775     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 776     return ciConstant(T_OBJECT, ciobj);
 777   } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 778     assert(obj_index >= 0, "should have an object index");
 779     return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant

   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 "ci/ciConstant.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciField.hpp"
  29 #include "ci/ciInlineKlass.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"

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

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

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