src/share/vm/oops/instanceKlass.hpp

changeset 3701
49036505ab5f
parent 3670
f7c4174b33ba
child 3709
0105f367a14c
     1.1 --- a/src/share/vm/oops/instanceKlass.hpp	Sun Mar 25 18:08:52 2012 -0400
     1.2 +++ b/src/share/vm/oops/instanceKlass.hpp	Thu Mar 29 22:18:56 2012 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -56,8 +56,6 @@
    1.11  //    [methods                    ]
    1.12  //    [local interfaces           ]
    1.13  //    [transitive interfaces      ]
    1.14 -//    [number of implementors     ]
    1.15 -//    [implementors               ] klassOop[2]
    1.16  //    [fields                     ]
    1.17  //    [constants                  ]
    1.18  //    [class loader               ]
    1.19 @@ -77,9 +75,9 @@
    1.20  //    [oop map cache (stack maps) ]
    1.21  //    [EMBEDDED Java vtable             ] size in words = vtable_len
    1.22  //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
    1.23 -//
    1.24 -//    The embedded nonstatic oop-map blocks are short pairs (offset, length) indicating
    1.25 -//    where oops are located in instances of this klass.
    1.26 +//      The embedded nonstatic oop-map blocks are short pairs (offset, length)
    1.27 +//      indicating where oops are located in instances of this klass.
    1.28 +//    [EMBEDDED implementor of the interface] only exist for interface
    1.29  
    1.30  
    1.31  // forward declaration for class -- see below for definition
    1.32 @@ -153,10 +151,6 @@
    1.33    oop* oop_block_beg() const { return adr_array_klasses(); }
    1.34    oop* oop_block_end() const { return adr_methods_default_annotations() + 1; }
    1.35  
    1.36 -  enum {
    1.37 -    implementors_limit = 2              // how many implems can we track?
    1.38 -  };
    1.39 -
    1.40   protected:
    1.41    //
    1.42    // The oop block.  See comment in klass.hpp before making changes.
    1.43 @@ -200,8 +194,6 @@
    1.44    // and EnclosingMethod attributes the _inner_classes array length is
    1.45    // number_of_inner_classes * 4 + enclosing_method_attribute_size.
    1.46    typeArrayOop    _inner_classes;
    1.47 -  // Implementors of this interface (not valid if it overflows)
    1.48 -  klassOop        _implementors[implementors_limit];
    1.49    // Annotations for this class, or null if none.
    1.50    typeArrayOop    _class_annotations;
    1.51    // Annotation objects (byte arrays) for fields, or null if no annotations.
    1.52 @@ -257,7 +249,6 @@
    1.53    nmethodBucket*  _dependencies;         // list of dependent nmethods
    1.54    nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
    1.55    BreakpointInfo* _breakpoints;          // bpt lists, managed by methodOop
    1.56 -  int             _nof_implementors;     // No of implementors of this interface (zero if not an interface)
    1.57    // Array of interesting part(s) of the previous version(s) of this
    1.58    // instanceKlass. See PreviousVersionWalker below.
    1.59    GrowableArray<PreviousVersionNode *>* _previous_versions;
    1.60 @@ -278,6 +269,13 @@
    1.61    // embedded Java itables follows here
    1.62    // embedded static fields follows here
    1.63    // embedded nonstatic oop-map blocks follows here
    1.64 +  // embedded implementor of this interface follows here
    1.65 +  //   The embedded implementor only exists if the current klass is an
    1.66 +  //   iterface. The possible values of the implementor fall into following
    1.67 +  //   three cases:
    1.68 +  //     NULL: no implementor.
    1.69 +  //     A klassOop that's not itself: one implementor.
    1.70 +  //     Itsef: more than one implementors.
    1.71  
    1.72    friend class instanceKlassKlass;
    1.73    friend class SystemDictionary;
    1.74 @@ -649,14 +647,34 @@
    1.75    // subclass/subinterface checks
    1.76    bool implements_interface(klassOop k) const;
    1.77  
    1.78 -  // Access to implementors of an interface. We only store the count
    1.79 -  // of implementors, and in case, there are only a few
    1.80 -  // implementors, we store them in a short list.
    1.81 -  // This accessor returns NULL if we walk off the end of the list.
    1.82 -  klassOop implementor(int i) const {
    1.83 -    return (i < implementors_limit)? _implementors[i]: (klassOop) NULL;
    1.84 +  // Access to the implementor of an interface.
    1.85 +  klassOop implementor() const
    1.86 +  {
    1.87 +    klassOop* k = start_of_implementor();
    1.88 +    if (k == NULL) {
    1.89 +      return NULL;
    1.90 +    } else {
    1.91 +      return *k;
    1.92 +    }
    1.93    }
    1.94 -  int  nof_implementors() const       { return _nof_implementors; }
    1.95 +
    1.96 +  void set_implementor(klassOop k) {
    1.97 +    assert(is_interface(), "not interface");
    1.98 +    oop* addr = (oop*)start_of_implementor();
    1.99 +    oop_store_without_check(addr, k);
   1.100 +  }
   1.101 +
   1.102 +  int  nof_implementors() const       {
   1.103 +    klassOop k = implementor();
   1.104 +    if (k == NULL) {
   1.105 +      return 0;
   1.106 +    } else if (k != this->as_klassOop()) {
   1.107 +      return 1;
   1.108 +    } else {
   1.109 +      return 2;
   1.110 +    }
   1.111 +  }
   1.112 +
   1.113    void add_implementor(klassOop k);  // k is a new class that implements this interface
   1.114    void init_implementor();           // initialize
   1.115  
   1.116 @@ -693,7 +711,15 @@
   1.117  
   1.118    // Sizing (in words)
   1.119    static int header_size()            { return align_object_offset(oopDesc::header_size() + sizeof(instanceKlass)/HeapWordSize); }
   1.120 -  int object_size() const             { return object_size(align_object_offset(vtable_length()) + align_object_offset(itable_length()) + nonstatic_oop_map_size()); }
   1.121 +
   1.122 +  int object_size() const
   1.123 +  {
   1.124 +    return object_size(align_object_offset(vtable_length()) +
   1.125 +                       align_object_offset(itable_length()) +
   1.126 +                       (is_interface() ?
   1.127 +                        (align_object_offset(nonstatic_oop_map_size()) + (int)sizeof(klassOop)/HeapWordSize) :
   1.128 +                        nonstatic_oop_map_size()));
   1.129 +  }
   1.130    static int vtable_start_offset()    { return header_size(); }
   1.131    static int vtable_length_offset()   { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
   1.132    static int object_size(int extra)   { return align_object_size(header_size() + extra); }
   1.133 @@ -710,6 +736,15 @@
   1.134      return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length()));
   1.135    }
   1.136  
   1.137 +  klassOop* start_of_implementor() const {
   1.138 +    if (is_interface()) {
   1.139 +      return (klassOop*)(start_of_nonstatic_oop_maps() +
   1.140 +                         nonstatic_oop_map_count());
   1.141 +    } else {
   1.142 +      return NULL;
   1.143 +    }
   1.144 +  };
   1.145 +
   1.146    // Allocation profiling support
   1.147    juint alloc_size() const            { return _alloc_count * size_helper(); }
   1.148    void set_alloc_size(juint n)        {}
   1.149 @@ -819,7 +854,7 @@
   1.150    oop* adr_host_klass() const        { return (oop*)&this->_host_klass;}
   1.151    oop* adr_signers() const           { return (oop*)&this->_signers;}
   1.152    oop* adr_inner_classes() const     { return (oop*)&this->_inner_classes;}
   1.153 -  oop* adr_implementors() const      { return (oop*)&this->_implementors[0];}
   1.154 +  oop* adr_implementor() const       { return (oop*)start_of_implementor(); }
   1.155    oop* adr_methods_jmethod_ids() const             { return (oop*)&this->_methods_jmethod_ids;}
   1.156    oop* adr_methods_cached_itable_indices() const   { return (oop*)&this->_methods_cached_itable_indices;}
   1.157    oop* adr_class_annotations() const   { return (oop*)&this->_class_annotations;}

mercurial