src/share/vm/classfile/classLoaderData.hpp

Thu, 20 Dec 2012 14:17:52 -0800

author
kvn
date
Thu, 20 Dec 2012 14:17:52 -0800
changeset 4365
a46457045d66
parent 4304
90273fc0a981
child 4345
30866cd626b0
child 4376
79f492f184d0
permissions
-rw-r--r--

8004330: Add missing Unsafe entry points for addAndGet() family
Summary: Fix java names for getAndSet intrinsics
Reviewed-by: kvn
Contributed-by: aleksey.shipilev@oracle.com

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     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
     7  * published by the Free Software Foundation.
     8  *
     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  */
    25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
    26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
    28 #include "memory/allocation.hpp"
    29 #include "memory/memRegion.hpp"
    30 #include "memory/metaspace.hpp"
    31 #include "memory/metaspaceCounters.hpp"
    32 #include "runtime/mutex.hpp"
    33 #include "utilities/growableArray.hpp"
    35 //
    36 // A class loader represents a linkset. Conceptually, a linkset identifies
    37 // the complete transitive closure of resolved links that a dynamic linker can
    38 // produce.
    39 //
    40 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
    41 // used by the dynamic linker to allocate the runtime representation of all
    42 // the types it defines.
    43 //
    44 // ClassLoaderData are stored in the runtime representation of classes and the
    45 // system dictionary, are roots of garbage collection, and provides iterators
    46 // for root tracing and other GC operations.
    48 class ClassLoaderData;
    49 class JNIMethodBlock;
    50 class JNIHandleBlock;
    51 class Metadebug;
    52 // GC root for walking class loader data created
    54 class ClassLoaderDataGraph : public AllStatic {
    55   friend class ClassLoaderData;
    56   friend class ClassLoaderDataGraphMetaspaceIterator;
    57   friend class VMStructs;
    58  private:
    59   // All CLDs (except the null CLD) can be reached by walking _head->_next->...
    60   static ClassLoaderData* _head;
    61   static ClassLoaderData* _unloading;
    62   // CMS support.
    63   static ClassLoaderData* _saved_head;
    65   static ClassLoaderData* add(ClassLoaderData** loader_data_addr, Handle class_loader, TRAPS);
    66  public:
    67   static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
    68   static void purge();
    69   static void clear_claimed_marks();
    70   static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
    71   static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
    72   static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
    73   static void classes_do(KlassClosure* klass_closure);
    74   static bool do_unloading(BoolObjectClosure* is_alive);
    76   // CMS support.
    77   static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
    78   static GrowableArray<ClassLoaderData*>* new_clds();
    80   static void dump_on(outputStream * const out) PRODUCT_RETURN;
    81   static void dump() { dump_on(tty); }
    82   static void verify();
    84 #ifndef PRODUCT
    85   // expensive test for pointer in metaspace for debugging
    86   static bool contains(address x);
    87   static bool contains_loader_data(ClassLoaderData* loader_data);
    88 #endif
    89 };
    91 // ClassLoaderData class
    93 class ClassLoaderData : public CHeapObj<mtClass> {
    94   friend class VMStructs;
    95  private:
    96   friend class ClassLoaderDataGraph;
    97   friend class ClassLoaderDataGraphMetaspaceIterator;
    98   friend class MetaDataFactory;
    99   friend class Method;
   101   static ClassLoaderData * _the_null_class_loader_data;
   103   oop _class_loader;       // oop used to uniquely identify a class loader
   104                            // class loader or a canonical class path
   105   oop _dependencies;       // oop to hold dependencies from this class loader
   106                            // data to others.
   107   Metaspace * _metaspace;  // Meta-space where meta-data defined by the
   108                            // classes in the class loader are allocated.
   109   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
   110   bool _unloading;         // true if this class loader goes away
   111   bool _keep_alive;        // if this CLD can be unloaded for anonymous loaders
   112   volatile int _claimed;   // true if claimed, for example during GC traces.
   113                            // To avoid applying oop closure more than once.
   114                            // Has to be an int because we cas it.
   115   Klass* _klasses;         // The classes defined by the class loader.
   117   JNIHandleBlock* _handles; // Handles to constant pool arrays
   119   // These method IDs are created for the class loader and set to NULL when the
   120   // class loader is unloaded.  They are rarely freed, only for redefine classes
   121   // and if they lose a data race in InstanceKlass.
   122   JNIMethodBlock*                  _jmethod_ids;
   124   // Metadata to be deallocated when it's safe at class unloading, when
   125   // this class loader isn't unloaded itself.
   126   GrowableArray<Metadata*>*      _deallocate_list;
   128   // Support for walking class loader data objects
   129   ClassLoaderData* _next; /// Next loader_datas created
   131   // ReadOnly and ReadWrite metaspaces (static because only on the null
   132   // class loader for now).
   133   static Metaspace* _ro_metaspace;
   134   static Metaspace* _rw_metaspace;
   136   void add_dependency(Handle dependency, TRAPS);
   137   void locked_add_dependency(objArrayHandle last, objArrayHandle new_dependency);
   139   void set_next(ClassLoaderData* next) { _next = next; }
   140   ClassLoaderData* next() const        { return _next; }
   142   ClassLoaderData(Handle h_class_loader);
   143   ~ClassLoaderData();
   145   void set_metaspace(Metaspace* m) { _metaspace = m; }
   147   JNIHandleBlock* handles() const;
   148   void set_handles(JNIHandleBlock* handles);
   150   Mutex* metaspace_lock() const { return _metaspace_lock; }
   152   // GC interface.
   153   void clear_claimed()          { _claimed = 0; }
   154   bool claimed() const          { return _claimed == 1; }
   155   bool claim();
   157   void unload();
   158   bool keep_alive() const       { return _keep_alive; }
   159   bool is_alive(BoolObjectClosure* is_alive_closure) const;
   161   void classes_do(void f(InstanceKlass*));
   163   // Deallocate free list during class unloading.
   164   void free_deallocate_list();
   166   // Allocate out of this class loader data
   167   MetaWord* allocate(size_t size);
   169  public:
   170   // Accessors
   171   Metaspace* metaspace_or_null() const     { return _metaspace; }
   173   static ClassLoaderData* the_null_class_loader_data() {
   174     return _the_null_class_loader_data;
   175   }
   177   bool is_anonymous() const;
   179   static void init_null_class_loader_data() {
   180     assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
   181     assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
   182     _the_null_class_loader_data = new ClassLoaderData((oop)NULL);
   183     ClassLoaderDataGraph::_head = _the_null_class_loader_data;
   184     assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
   185     if (DumpSharedSpaces) {
   186       _the_null_class_loader_data->initialize_shared_metaspaces();
   187     }
   188   }
   190   bool is_the_null_class_loader_data() const {
   191     return this == _the_null_class_loader_data;
   192   }
   194   // The Metaspace is created lazily so may be NULL.  This
   195   // method will allocate a Metaspace if needed.
   196   Metaspace* metaspace_non_null();
   198   oop class_loader() const      { return _class_loader; }
   200   // Returns true if this class loader data is for a loader going away.
   201   bool is_unloading() const     {
   202     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
   203     return _unloading;
   204   }
   205   // Anonymous class loader data doesn't have anything to keep them from
   206   // being unloaded during parsing the anonymous class.
   207   void set_keep_alive(bool value) { _keep_alive = value; }
   209   unsigned int identity_hash() {
   210     return _class_loader == NULL ? 0 : _class_loader->identity_hash();
   211   }
   213   // Used when tracing from klasses.
   214   void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
   216   void classes_do(KlassClosure* klass_closure);
   218   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
   219   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
   221   void print_value() { print_value_on(tty); }
   222   void print_value_on(outputStream* out) const PRODUCT_RETURN;
   223   void dump(outputStream * const out) PRODUCT_RETURN;
   224   void verify();
   225   const char* loader_name();
   227   jobject add_handle(Handle h);
   228   void add_class(Klass* k);
   229   void remove_class(Klass* k);
   230   void record_dependency(Klass* to, TRAPS);
   231   void init_dependencies(TRAPS);
   233   void add_to_deallocate_list(Metadata* m);
   235   static ClassLoaderData* class_loader_data(oop loader);
   236   static ClassLoaderData* anonymous_class_loader_data(oop loader, TRAPS);
   237   static void print_loader(ClassLoaderData *loader_data, outputStream *out);
   239   // CDS support
   240   Metaspace* ro_metaspace();
   241   Metaspace* rw_metaspace();
   242   void initialize_shared_metaspaces();
   243 };
   245 class ClassLoaderDataGraphMetaspaceIterator : public StackObj {
   246   ClassLoaderData* _data;
   247  public:
   248   ClassLoaderDataGraphMetaspaceIterator();
   249   ~ClassLoaderDataGraphMetaspaceIterator();
   250   bool repeat() { return _data != NULL; }
   251   Metaspace* get_next() {
   252     assert(_data != NULL, "Should not be NULL in call to the iterator");
   253     Metaspace* result = _data->metaspace_or_null();
   254     _data = _data->next();
   255     // This result might be NULL for class loaders without metaspace
   256     // yet.  It would be nice to return only non-null results but
   257     // there is no guarantee that there will be a non-null result
   258     // down the list so the caller is going to have to check.
   259     return result;
   260   }
   261 };
   262 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP

mercurial