< 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"

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


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

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















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

 650 #ifndef PRODUCT
 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 #endif
 656   return ciKlass;
 657 }
 658 
 659 // ------------------------------------------------------------------
 660 // ciEnv::get_klass_by_index
 661 //
 662 // Get a klass from the constant pool.
 663 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
 664                                    int index,
 665                                    bool& is_accessible,
 666                                    ciInstanceKlass* accessor) {
 667   GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
 668 }
 669 








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

 745     return ciConstant((jlong)cpool->long_at(index));
 746   } else if (tag.is_float()) {
 747     return ciConstant((jfloat)cpool->float_at(index));
 748   } else if (tag.is_double()) {
 749     return ciConstant((jdouble)cpool->double_at(index));
 750   } else if (tag.is_string()) {
 751     EXCEPTION_CONTEXT;
 752     assert(obj_index >= 0, "should have an object index");
 753     oop string = cpool->string_at(index, obj_index, THREAD);
 754     if (HAS_PENDING_EXCEPTION) {
 755       CLEAR_PENDING_EXCEPTION;
 756       record_out_of_memory_failure();
 757       return ciConstant();
 758     }
 759     ciInstance* constant = get_object(string)->as_instance();
 760     return ciConstant(T_OBJECT, constant);
 761   } else if (tag.is_unresolved_klass_in_error()) {
 762     return ciConstant(T_OBJECT, get_unloaded_klass_mirror(NULL));
 763   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
 764     ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
 765     return ciConstant(T_OBJECT, klass->java_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     int ref_kind        = cpool->method_handle_ref_kind_at(index);
 776     int callee_index    = cpool->method_handle_klass_index_at(index);
 777     ciKlass* callee     = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
 778     ciSymbol* name      = get_symbol(cpool->method_handle_name_ref_at(index));
 779     ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
 780     ciObject* ciobj     = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
 781     return ciConstant(T_OBJECT, ciobj);
 782   } else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
 783     assert(obj_index >= 0, "should have an object index");
 784     return ciConstant(T_OBJECT, unloaded_ciinstance()); // unresolved dynamic constant
 785   } else {

  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"

 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(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 ||
 545        sym->char_at(1) == JVM_SIGNATURE_CLASS ||
 546        sym->char_at(1) == JVM_SIGNATURE_PRIMITIVE_OBJECT )) {
 547     // We have an unloaded array.
 548     // Build it on the fly if the element class exists.
 549     SignatureStream ss(sym, false);
 550     ss.skip_array_prefix(1);
 551     // Get element ciKlass recursively.
 552     ciKlass* elem_klass =
 553       get_klass_by_name_impl(accessing_klass,
 554                              cpool,
 555                              get_symbol(ss.as_symbol()),
 556                              require_local);
 557     if (elem_klass != NULL && elem_klass->is_loaded()) {
 558       // Now make an array for it
 559       bool null_free_array = sym->is_Q_array_signature() && sym->char_at(1) == JVM_SIGNATURE_PRIMITIVE_OBJECT;
 560       return ciArrayKlass::make(elem_klass, null_free_array);
 561     }
 562   }
 563 
 564   if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
 565     // Look inside the constant pool for pre-resolved class entries.
 566     for (int i = cpool->length() - 1; i >= 1; i--) {
 567       if (cpool->tag_at(i).is_klass()) {
 568         Klass* kls = cpool->resolved_klass_at(i);
 569         if (kls->name() == sym) {
 570           found_klass = kls;
 571           break;
 572         }
 573       }
 574     }
 575   }
 576 
 577   if (found_klass != NULL) {
 578     // Found it.  Build a CI handle.
 579     return get_klass(found_klass);
 580   }
 581 
 582   if (require_local)  return NULL;
 583 
 584   // Not yet loaded into the VM, or not governed by loader constraints.
 585   // Make a CI representative for it.
 586   int i = 0;
 587   while (sym->char_at(i) == JVM_SIGNATURE_ARRAY) {
 588     i++;
 589   }
 590   if (i > 0 && sym->char_at(i) == JVM_SIGNATURE_PRIMITIVE_OBJECT) {
 591     // An unloaded array class of inline types is an ObjArrayKlass, an
 592     // unloaded inline type class is an InstanceKlass. For consistency,
 593     // make the signature of the unloaded array of inline type use L
 594     // rather than Q.
 595     char* new_name = name_buffer(sym->utf8_length()+1);
 596     strncpy(new_name, (char*)sym->base(), sym->utf8_length());
 597     new_name[i] = JVM_SIGNATURE_CLASS;
 598     new_name[sym->utf8_length()] = '\0';
 599     return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
 600   }
 601   return get_unloaded_klass(accessing_klass, name);
 602 }
 603 
 604 // ------------------------------------------------------------------
 605 // ciEnv::get_klass_by_name
 606 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
 607                                   ciSymbol* klass_name,
 608                                   bool require_local) {
 609   GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
 610                                                  constantPoolHandle(),
 611                                                  klass_name,
 612                                                  require_local);)
 613 }
 614 
 615 // ------------------------------------------------------------------
 616 // ciEnv::get_klass_by_index_impl
 617 //
 618 // Implementation of get_klass_by_index.
 619 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
 620                                         int index,

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

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