src/share/vm/memory/metadataFactory.hpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 5896
d37a0525c0fe
child 7089
6e0cb14ce59b
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

     1 /*
     2  * Copyright (c) 2010, 2013, 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_MEMORY_METADATAFACTORY_HPP
    26 #define SHARE_VM_MEMORY_METADATAFACTORY_HPP
    28 #include "classfile/classLoaderData.hpp"
    29 #include "utilities/array.hpp"
    30 #include "utilities/exceptions.hpp"
    31 #include "utilities/globalDefinitions.hpp"
    33 class MetadataFactory : AllStatic {
    34  public:
    35   template <typename T>
    36   static Array<T>* new_array(ClassLoaderData* loader_data, int length, TRAPS) {
    37     // The "true" argument is because all metadata arrays are read only when
    38     // dumped to the shared archive
    39     return new (loader_data, length, /*read_only*/true, THREAD) Array<T>(length);
    40   }
    42   template <typename T>
    43   static Array<T>* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
    44     Array<T>* array = new_array<T>(loader_data, length, CHECK_NULL);
    45     for (int i = 0; i < length; i++) {
    46       array->at_put(i, value);
    47     }
    48     return array;
    49   }
    51   template <typename T>
    52   static Array<T>* new_writeable_array(ClassLoaderData* loader_data, int length, TRAPS) {
    53     return new (loader_data, length, /*read_only*/false, THREAD) Array<T>(length);
    54   }
    56   template <typename T>
    57   static Array<T>* new_writeable_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
    58     Array<T>* array = new_writeable_array<T>(loader_data, length, CHECK_NULL);
    59     for (int i = 0; i < length; i++) {
    60       array->at_put(i, value);
    61     }
    62     return array;
    63   }
    65   template <typename T>
    66   static void free_array(ClassLoaderData* loader_data, Array<T>* data) {
    67     if (data != NULL) {
    68       assert(loader_data != NULL, "shouldn't pass null");
    69       assert(!data->is_shared(), "cannot deallocate array in shared spaces");
    70       int size = data->size();
    71       if (DumpSharedSpaces) {
    72         loader_data->ro_metaspace()->deallocate((MetaWord*)data, size, false);
    73       } else {
    74         loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size, false);
    75       }
    76     }
    77   }
    79   // Deallocation method for metadata
    80   template <class T>
    81   static void free_metadata(ClassLoaderData* loader_data, T md) {
    82     if (md != NULL) {
    83       assert(loader_data != NULL, "shouldn't pass null");
    84       int size = md->size();
    85       // Call metadata's deallocate function which will call deallocate fields
    86       assert(!DumpSharedSpaces, "cannot deallocate metadata when dumping CDS archive");
    87       assert(!md->on_stack(), "can't deallocate things on stack");
    88       assert(!md->is_shared(), "cannot deallocate if in shared spaces");
    89       md->deallocate_contents(loader_data);
    90       loader_data->metaspace_non_null()->deallocate((MetaWord*)md, size, md->is_klass());
    91     }
    92   }
    93 };
    95 #endif // SHARE_VM_MEMORY_METADATAFACTORY_HPP

mercurial