src/share/vm/code/dependencies.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File JDK-7194669 Sdiff src/share/vm/code

src/share/vm/code/dependencies.cpp

Print this page




 663 inline oop Dependencies::DepStream::recorded_oop_at(int i) {
 664   return (_code != NULL)
 665          ? _code->oop_at(i)
 666     : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i));
 667 }
 668 
 669 Metadata* Dependencies::DepStream::argument(int i) {
 670   Metadata* result = recorded_metadata_at(argument_index(i));
 671 
 672   if (result == NULL) { // Explicit context argument can be compressed
 673     int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
 674     if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) {
 675       result = ctxk_encoded_as_null(type(), argument(ctxkj+1));
 676     }
 677   }
 678 
 679   assert(result == NULL || result->is_klass() || result->is_method(), "must be");
 680   return result;
 681 }
 682 








 683 oop Dependencies::DepStream::argument_oop(int i) {
 684   oop result = recorded_oop_at(argument_index(i));
 685   assert(result == NULL || result->is_oop(), "must be");
 686   return result;
 687 }
 688 
 689 Klass* Dependencies::DepStream::context_type() {
 690   assert(must_be_in_vm(), "raw oops here");
 691 
 692   // Most dependencies have an explicit context type argument.
 693   {
 694     int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
 695     if (ctxkj >= 0) {
 696       Metadata* k = argument(ctxkj);
 697       assert(k != NULL && k->is_klass(), "type check");
 698       return (Klass*)k;
 699     }
 700   }
 701 
 702   // Some dependencies are using the klass of the first object
 703   // argument as implicit context type (e.g. call_site_target_value).
 704   {
 705     int ctxkj = dep_implicit_context_arg(type());
 706     if (ctxkj >= 0) {
 707       Klass* k = argument_oop(ctxkj)->klass();
 708       assert(k != NULL && k->is_klass(), "type check");
 709       return (Klass*) k;
 710     }
 711   }
 712 
 713   // And some dependencies don't have a context type at all,
 714   // e.g. evol_method.
 715   return NULL;
 716 }


















































































































 717 
 718 /// Checking dependencies:
 719 
 720 // This hierarchy walker inspects subtypes of a given type,
 721 // trying to find a "bad" class which breaks a dependency.
 722 // Such a class is called a "witness" to the broken dependency.
 723 // While searching around, we ignore "participants", which
 724 // are already known to the dependency.
 725 class ClassHierarchyWalker {
 726  public:
 727   enum { PARTICIPANT_LIMIT = 3 };
 728 
 729  private:
 730   // optional method descriptor to check for:
 731   Symbol* _name;
 732   Symbol* _signature;
 733 
 734   // special classes which are not allowed to be witnesses:
 735   Klass*    _participants[PARTICIPANT_LIMIT+1];
 736   int       _num_participants;




 663 inline oop Dependencies::DepStream::recorded_oop_at(int i) {
 664   return (_code != NULL)
 665          ? _code->oop_at(i)
 666     : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i));
 667 }
 668 
 669 Metadata* Dependencies::DepStream::argument(int i) {
 670   Metadata* result = recorded_metadata_at(argument_index(i));
 671 
 672   if (result == NULL) { // Explicit context argument can be compressed
 673     int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
 674     if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) {
 675       result = ctxk_encoded_as_null(type(), argument(ctxkj+1));
 676     }
 677   }
 678 
 679   assert(result == NULL || result->is_klass() || result->is_method(), "must be");
 680   return result;
 681 }
 682 
 683 uintptr_t Dependencies::DepStream::get_identity_hash(int i) {
 684   if (has_oop_argument()) {
 685     return argument_oop(i)->identity_hash();
 686   } else {
 687     return argument(i)->identity_hash();
 688   }
 689 }
 690 
 691 oop Dependencies::DepStream::argument_oop(int i) {
 692   oop result = recorded_oop_at(argument_index(i));
 693   assert(result == NULL || result->is_oop(), "must be");
 694   return result;
 695 }
 696 
 697 Klass* Dependencies::DepStream::context_type() {
 698   assert(must_be_in_vm(), "raw oops here");
 699 
 700   // Most dependencies have an explicit context type argument.
 701   {
 702     int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
 703     if (ctxkj >= 0) {
 704       Metadata* k = argument(ctxkj);
 705       assert(k != NULL && k->is_klass(), "type check");
 706       return (Klass*)k;
 707     }
 708   }
 709 
 710   // Some dependencies are using the klass of the first object
 711   // argument as implicit context type (e.g. call_site_target_value).
 712   {
 713     int ctxkj = dep_implicit_context_arg(type());
 714     if (ctxkj >= 0) {
 715       Klass* k = argument_oop(ctxkj)->klass();
 716       assert(k != NULL && k->is_klass(), "type check");
 717       return (Klass*) k;
 718     }
 719   }
 720 
 721   // And some dependencies don't have a context type at all,
 722   // e.g. evol_method.
 723   return NULL;
 724 }
 725 
 726 // ----------------- DependencySignatureBuffer --------------------------------------
 727 DependencySignatureBuffer::DependencySignatureBuffer(Dependencies::DepType type) {
 728   _type = type;
 729   _root =  NULL;
 730 }
 731 
 732 /**
 733  * Search binary tree recursively. The key is the identity hash of the first or the second dependency
 734  * argument.
 735  */
 736 DependencySignature* DependencySignatureBuffer::tree_search(DependencySignature* current_node, uintptr_t key) {
 737   if (current_node == NULL || key == current_node->key()) {
 738     return current_node;
 739   }
 740   if (key < current_node->key()) {
 741     return tree_search(current_node->left(), key);
 742   } else {
 743     return tree_search(current_node->right(), key);
 744   }
 745 }
 746 
 747 /**
 748  * Returns a buffer that contains the dependency signatures of a particular dependency type.
 749  */
 750 DependencySignatureBuffer* DependencySignatureBuffer::buffer(GrowableArray<DependencySignatureBuffer*>* signature_buffers,
 751                                                              Dependencies::DepType type) {
 752   for (int i = 0; i < signature_buffers->length(); i++) {
 753     DependencySignatureBuffer* current = signature_buffers->at(i);
 754     if (current->type() == type) {
 755       return current;
 756     }
 757   }
 758 
 759   DependencySignatureBuffer* new_buffer = new DependencySignatureBuffer(type);
 760   signature_buffers->append(new_buffer);
 761   return new_buffer;
 762 }
 763 
 764 /**
 765  * To remember already checked dependencies, dependencies are represented as dependency
 766  * signatures. A dependency signature consists (i) a type and (ii) the identity hashes
 767  * of all arguments.
 768  * There is a DependencySignatureBuffer object for each dependency type. As a result,
 769  * the lookup that is performed by this function does not have to consider the dependency
 770  * type.
 771  * Dependency signatures are stored in a binary tree where the key is either the identity hash
 772  * of the first argument or the identity hash of the second argument of the dependency. Since
 773  * dependencies can have more than one argument, each element of the tree (DependencySignature)
 774  * maintains a linked list in which dependency signatures that have the same key but different
 775  * argument identity hashes are stored.
 776  */
 777 bool DependencySignatureBuffer::contains(DependencySignature* sig) {
 778   // Search binary tree
 779   DependencySignature* found = tree_search(_root, sig->key());
 780   // Search linked list
 781   while (found != NULL) {
 782     // Check if arguments are identical. Two dependency signatures are considered
 783     // identical, if the type as well as all identity hashes of all arguments are
 784     // identical.
 785     const int args_count = sig->args_count();
 786     int identical_args = 0;
 787      for (int i = 0; i < sig->args_count(); i++) {
 788        if (sig->arg(i) == found->arg(i)) {
 789          identical_args++;
 790        }
 791      }
 792      if (identical_args == args_count) {
 793        return true;
 794      }
 795      found = found->next();
 796    }
 797    return false;
 798 }
 799 
 800 /**
 801  * Adds element to the binary tree if the binary tree does not contain an element with the specified
 802  * key. If the binary tree contains an element of the same key as the element that will be added, the
 803  * new dependency signature is appended to the end of a linked list.
 804  */
 805 void DependencySignatureBuffer::add(DependencySignature* to_add) {
 806   DependencySignature* y = NULL;
 807   DependencySignature* x = _root;
 808   DependencySignature* z = new DependencySignature(to_add);
 809 
 810   // Insert into binary search tree
 811   while (x != NULL) {
 812     y = x;
 813     // Found key; add to linked list
 814     if (z->key() == x->key()) {
 815       // Append to end of linked list
 816       while (x->next() != NULL) {
 817         x = x->next();
 818       }
 819       x->set_next(z);
 820       return;
 821     } else if (z->key() < x->key()) {
 822       x = x->left();
 823     } else {
 824       x = x->right();
 825     }
 826   }
 827   // The dependency signature was not found in the tree. Set links of new element.
 828   z->set_parent(y);
 829 
 830   if (y == NULL) {
 831     _root = z; // tree was empty
 832   } else if (z->key() < y->key()) {
 833     y->set_left(z);
 834   } else {
 835     y->set_right(z);
 836   }
 837 }
 838 
 839 
 840 /// Checking dependencies:
 841 
 842 // This hierarchy walker inspects subtypes of a given type,
 843 // trying to find a "bad" class which breaks a dependency.
 844 // Such a class is called a "witness" to the broken dependency.
 845 // While searching around, we ignore "participants", which
 846 // are already known to the dependency.
 847 class ClassHierarchyWalker {
 848  public:
 849   enum { PARTICIPANT_LIMIT = 3 };
 850 
 851  private:
 852   // optional method descriptor to check for:
 853   Symbol* _name;
 854   Symbol* _signature;
 855 
 856   // special classes which are not allowed to be witnesses:
 857   Klass*    _participants[PARTICIPANT_LIMIT+1];
 858   int       _num_participants;


src/share/vm/code/dependencies.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File