hotspot/src/share/vm/oops/instanceKlass.hpp
changeset 12369 48fd3da4025c
parent 12231 6a9cfc59a18a
child 12377 ae6def2813e0
equal deleted inserted replaced
12234:f3187578ddd3 12369:48fd3da4025c
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    54 //    [next sibling               ] Klass
    54 //    [next sibling               ] Klass
    55 //    [array klasses              ]
    55 //    [array klasses              ]
    56 //    [methods                    ]
    56 //    [methods                    ]
    57 //    [local interfaces           ]
    57 //    [local interfaces           ]
    58 //    [transitive interfaces      ]
    58 //    [transitive interfaces      ]
    59 //    [number of implementors     ]
       
    60 //    [implementors               ] klassOop[2]
       
    61 //    [fields                     ]
    59 //    [fields                     ]
    62 //    [constants                  ]
    60 //    [constants                  ]
    63 //    [class loader               ]
    61 //    [class loader               ]
    64 //    [protection domain          ]
    62 //    [protection domain          ]
    65 //    [signers                    ]
    63 //    [signers                    ]
    75 //    [initializing thread        ]
    73 //    [initializing thread        ]
    76 //    [Java vtable length         ]
    74 //    [Java vtable length         ]
    77 //    [oop map cache (stack maps) ]
    75 //    [oop map cache (stack maps) ]
    78 //    [EMBEDDED Java vtable             ] size in words = vtable_len
    76 //    [EMBEDDED Java vtable             ] size in words = vtable_len
    79 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
    77 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
    80 //
    78 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
    81 //    The embedded nonstatic oop-map blocks are short pairs (offset, length) indicating
    79 //      indicating where oops are located in instances of this klass.
    82 //    where oops are located in instances of this klass.
    80 //    [EMBEDDED implementor of the interface] only exist for interface
    83 
    81 
    84 
    82 
    85 // forward declaration for class -- see below for definition
    83 // forward declaration for class -- see below for definition
    86 class SuperTypeClosure;
    84 class SuperTypeClosure;
    87 class JNIid;
    85 class JNIid;
   150   };
   148   };
   151 
   149 
   152  public:
   150  public:
   153   oop* oop_block_beg() const { return adr_array_klasses(); }
   151   oop* oop_block_beg() const { return adr_array_klasses(); }
   154   oop* oop_block_end() const { return adr_methods_default_annotations() + 1; }
   152   oop* oop_block_end() const { return adr_methods_default_annotations() + 1; }
   155 
       
   156   enum {
       
   157     implementors_limit = 2              // how many implems can we track?
       
   158   };
       
   159 
   153 
   160  protected:
   154  protected:
   161   //
   155   //
   162   // The oop block.  See comment in klass.hpp before making changes.
   156   // The oop block.  See comment in klass.hpp before making changes.
   163   //
   157   //
   198   // the InnerClasses attribute exists, the _inner_classes array length is
   192   // the InnerClasses attribute exists, the _inner_classes array length is
   199   // number_of_inner_classes * 4. If the class has both InnerClasses
   193   // number_of_inner_classes * 4. If the class has both InnerClasses
   200   // and EnclosingMethod attributes the _inner_classes array length is
   194   // and EnclosingMethod attributes the _inner_classes array length is
   201   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
   195   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
   202   typeArrayOop    _inner_classes;
   196   typeArrayOop    _inner_classes;
   203   // Implementors of this interface (not valid if it overflows)
       
   204   klassOop        _implementors[implementors_limit];
       
   205   // Annotations for this class, or null if none.
   197   // Annotations for this class, or null if none.
   206   typeArrayOop    _class_annotations;
   198   typeArrayOop    _class_annotations;
   207   // Annotation objects (byte arrays) for fields, or null if no annotations.
   199   // Annotation objects (byte arrays) for fields, or null if no annotations.
   208   // Indices correspond to entries (not indices) in fields array.
   200   // Indices correspond to entries (not indices) in fields array.
   209   objArrayOop     _fields_annotations;
   201   objArrayOop     _fields_annotations;
   255   jmethodID*      _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
   247   jmethodID*      _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
   256   int*            _methods_cached_itable_indices;  // itable_index cache for JNI invoke corresponding to methods idnum, or NULL
   248   int*            _methods_cached_itable_indices;  // itable_index cache for JNI invoke corresponding to methods idnum, or NULL
   257   nmethodBucket*  _dependencies;         // list of dependent nmethods
   249   nmethodBucket*  _dependencies;         // list of dependent nmethods
   258   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
   250   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
   259   BreakpointInfo* _breakpoints;          // bpt lists, managed by methodOop
   251   BreakpointInfo* _breakpoints;          // bpt lists, managed by methodOop
   260   int             _nof_implementors;     // No of implementors of this interface (zero if not an interface)
       
   261   // Array of interesting part(s) of the previous version(s) of this
   252   // Array of interesting part(s) of the previous version(s) of this
   262   // instanceKlass. See PreviousVersionWalker below.
   253   // instanceKlass. See PreviousVersionWalker below.
   263   GrowableArray<PreviousVersionNode *>* _previous_versions;
   254   GrowableArray<PreviousVersionNode *>* _previous_versions;
   264   // JVMTI fields can be moved to their own structure - see 6315920
   255   // JVMTI fields can be moved to their own structure - see 6315920
   265   unsigned char * _cached_class_file_bytes;       // JVMTI: cached class file, before retransformable agent modified it in CFLH
   256   unsigned char * _cached_class_file_bytes;       // JVMTI: cached class file, before retransformable agent modified it in CFLH
   276 
   267 
   277   // embedded Java vtable follows here
   268   // embedded Java vtable follows here
   278   // embedded Java itables follows here
   269   // embedded Java itables follows here
   279   // embedded static fields follows here
   270   // embedded static fields follows here
   280   // embedded nonstatic oop-map blocks follows here
   271   // embedded nonstatic oop-map blocks follows here
       
   272   // embedded implementor of this interface follows here
       
   273   //   The embedded implementor only exists if the current klass is an
       
   274   //   iterface. The possible values of the implementor fall into following
       
   275   //   three cases:
       
   276   //     NULL: no implementor.
       
   277   //     A klassOop that's not itself: one implementor.
       
   278   //     Itsef: more than one implementors.
   281 
   279 
   282   friend class instanceKlassKlass;
   280   friend class instanceKlassKlass;
   283   friend class SystemDictionary;
   281   friend class SystemDictionary;
   284 
   282 
   285  public:
   283  public:
   647   static ByteSize init_thread_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(instanceKlass, _init_thread)); }
   645   static ByteSize init_thread_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(instanceKlass, _init_thread)); }
   648 
   646 
   649   // subclass/subinterface checks
   647   // subclass/subinterface checks
   650   bool implements_interface(klassOop k) const;
   648   bool implements_interface(klassOop k) const;
   651 
   649 
   652   // Access to implementors of an interface. We only store the count
   650   // Access to the implementor of an interface.
   653   // of implementors, and in case, there are only a few
   651   klassOop implementor() const
   654   // implementors, we store them in a short list.
   652   {
   655   // This accessor returns NULL if we walk off the end of the list.
   653     klassOop* k = start_of_implementor();
   656   klassOop implementor(int i) const {
   654     if (k == NULL) {
   657     return (i < implementors_limit)? _implementors[i]: (klassOop) NULL;
   655       return NULL;
   658   }
   656     } else {
   659   int  nof_implementors() const       { return _nof_implementors; }
   657       return *k;
       
   658     }
       
   659   }
       
   660 
       
   661   void set_implementor(klassOop k) {
       
   662     assert(is_interface(), "not interface");
       
   663     oop* addr = (oop*)start_of_implementor();
       
   664     oop_store_without_check(addr, k);
       
   665   }
       
   666 
       
   667   int  nof_implementors() const       {
       
   668     klassOop k = implementor();
       
   669     if (k == NULL) {
       
   670       return 0;
       
   671     } else if (k != this->as_klassOop()) {
       
   672       return 1;
       
   673     } else {
       
   674       return 2;
       
   675     }
       
   676   }
       
   677 
   660   void add_implementor(klassOop k);  // k is a new class that implements this interface
   678   void add_implementor(klassOop k);  // k is a new class that implements this interface
   661   void init_implementor();           // initialize
   679   void init_implementor();           // initialize
   662 
   680 
   663   // link this class into the implementors list of every interface it implements
   681   // link this class into the implementors list of every interface it implements
   664   void process_interfaces(Thread *thread);
   682   void process_interfaces(Thread *thread);
   691     return (instanceKlass*) kp;
   709     return (instanceKlass*) kp;
   692   }
   710   }
   693 
   711 
   694   // Sizing (in words)
   712   // Sizing (in words)
   695   static int header_size()            { return align_object_offset(oopDesc::header_size() + sizeof(instanceKlass)/HeapWordSize); }
   713   static int header_size()            { return align_object_offset(oopDesc::header_size() + sizeof(instanceKlass)/HeapWordSize); }
   696   int object_size() const             { return object_size(align_object_offset(vtable_length()) + align_object_offset(itable_length()) + nonstatic_oop_map_size()); }
   714 
       
   715   int object_size() const
       
   716   {
       
   717     return object_size(align_object_offset(vtable_length()) +
       
   718                        align_object_offset(itable_length()) +
       
   719                        (is_interface() ?
       
   720                         (align_object_offset(nonstatic_oop_map_size()) + (int)sizeof(klassOop)/HeapWordSize) :
       
   721                         nonstatic_oop_map_size()));
       
   722   }
   697   static int vtable_start_offset()    { return header_size(); }
   723   static int vtable_start_offset()    { return header_size(); }
   698   static int vtable_length_offset()   { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
   724   static int vtable_length_offset()   { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
   699   static int object_size(int extra)   { return align_object_size(header_size() + extra); }
   725   static int object_size(int extra)   { return align_object_size(header_size() + extra); }
   700 
   726 
   701   intptr_t* start_of_vtable() const        { return ((intptr_t*)as_klassOop()) + vtable_start_offset(); }
   727   intptr_t* start_of_vtable() const        { return ((intptr_t*)as_klassOop()) + vtable_start_offset(); }
   707   address static_field_addr(int offset);
   733   address static_field_addr(int offset);
   708 
   734 
   709   OopMapBlock* start_of_nonstatic_oop_maps() const {
   735   OopMapBlock* start_of_nonstatic_oop_maps() const {
   710     return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length()));
   736     return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length()));
   711   }
   737   }
       
   738 
       
   739   klassOop* start_of_implementor() const {
       
   740     if (is_interface()) {
       
   741       return (klassOop*)(start_of_nonstatic_oop_maps() +
       
   742                          nonstatic_oop_map_count());
       
   743     } else {
       
   744       return NULL;
       
   745     }
       
   746   };
   712 
   747 
   713   // Allocation profiling support
   748   // Allocation profiling support
   714   juint alloc_size() const            { return _alloc_count * size_helper(); }
   749   juint alloc_size() const            { return _alloc_count * size_helper(); }
   715   void set_alloc_size(juint n)        {}
   750   void set_alloc_size(juint n)        {}
   716 
   751 
   817   oop* adr_class_loader() const      { return (oop*)&this->_class_loader;}
   852   oop* adr_class_loader() const      { return (oop*)&this->_class_loader;}
   818   oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;}
   853   oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;}
   819   oop* adr_host_klass() const        { return (oop*)&this->_host_klass;}
   854   oop* adr_host_klass() const        { return (oop*)&this->_host_klass;}
   820   oop* adr_signers() const           { return (oop*)&this->_signers;}
   855   oop* adr_signers() const           { return (oop*)&this->_signers;}
   821   oop* adr_inner_classes() const     { return (oop*)&this->_inner_classes;}
   856   oop* adr_inner_classes() const     { return (oop*)&this->_inner_classes;}
   822   oop* adr_implementors() const      { return (oop*)&this->_implementors[0];}
   857   oop* adr_implementor() const       { return (oop*)start_of_implementor(); }
   823   oop* adr_methods_jmethod_ids() const             { return (oop*)&this->_methods_jmethod_ids;}
   858   oop* adr_methods_jmethod_ids() const             { return (oop*)&this->_methods_jmethod_ids;}
   824   oop* adr_methods_cached_itable_indices() const   { return (oop*)&this->_methods_cached_itable_indices;}
   859   oop* adr_methods_cached_itable_indices() const   { return (oop*)&this->_methods_cached_itable_indices;}
   825   oop* adr_class_annotations() const   { return (oop*)&this->_class_annotations;}
   860   oop* adr_class_annotations() const   { return (oop*)&this->_class_annotations;}
   826   oop* adr_fields_annotations() const  { return (oop*)&this->_fields_annotations;}
   861   oop* adr_fields_annotations() const  { return (oop*)&this->_fields_annotations;}
   827   oop* adr_methods_annotations() const { return (oop*)&this->_methods_annotations;}
   862   oop* adr_methods_annotations() const { return (oop*)&this->_methods_annotations;}