src/share/vm/memory/metadataFactory.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5896
d37a0525c0fe
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial