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

coleenp@4037 1 /*
hseigel@5896 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
coleenp@4037 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@4037 4 *
coleenp@4037 5 * This code is free software; you can redistribute it and/or modify it
coleenp@4037 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@4037 7 * published by the Free Software Foundation.
coleenp@4037 8 *
coleenp@4037 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@4037 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@4037 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@4037 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@4037 13 * accompanied this code).
coleenp@4037 14 *
coleenp@4037 15 * You should have received a copy of the GNU General Public License version
coleenp@4037 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@4037 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@4037 18 *
coleenp@4037 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@4037 20 * or visit www.oracle.com if you need additional information or have any
coleenp@4037 21 * questions.
coleenp@4037 22 *
coleenp@4037 23 */
coleenp@4037 24
coleenp@4037 25 #ifndef SHARE_VM_MEMORY_METADATAFACTORY_HPP
coleenp@4037 26 #define SHARE_VM_MEMORY_METADATAFACTORY_HPP
coleenp@4037 27
stefank@6992 28 #include "classfile/classLoaderData.hpp"
coleenp@4037 29 #include "utilities/array.hpp"
coleenp@4037 30 #include "utilities/exceptions.hpp"
coleenp@4037 31 #include "utilities/globalDefinitions.hpp"
coleenp@4037 32
coleenp@4037 33 class MetadataFactory : AllStatic {
coleenp@4037 34 public:
coleenp@4037 35 template <typename T>
coleenp@4037 36 static Array<T>* new_array(ClassLoaderData* loader_data, int length, TRAPS) {
coleenp@4037 37 // The "true" argument is because all metadata arrays are read only when
coleenp@4037 38 // dumped to the shared archive
coleenp@4037 39 return new (loader_data, length, /*read_only*/true, THREAD) Array<T>(length);
coleenp@4037 40 }
coleenp@4037 41
coleenp@4037 42 template <typename T>
coleenp@4037 43 static Array<T>* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
coleenp@4037 44 Array<T>* array = new_array<T>(loader_data, length, CHECK_NULL);
coleenp@4037 45 for (int i = 0; i < length; i++) {
coleenp@4037 46 array->at_put(i, value);
coleenp@4037 47 }
coleenp@4037 48 return array;
coleenp@4037 49 }
coleenp@4037 50
coleenp@4037 51 template <typename T>
coleenp@4037 52 static Array<T>* new_writeable_array(ClassLoaderData* loader_data, int length, TRAPS) {
coleenp@4037 53 return new (loader_data, length, /*read_only*/false, THREAD) Array<T>(length);
coleenp@4037 54 }
coleenp@4037 55
coleenp@4037 56 template <typename T>
coleenp@4037 57 static Array<T>* new_writeable_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
coleenp@4037 58 Array<T>* array = new_writeable_array<T>(loader_data, length, CHECK_NULL);
coleenp@4037 59 for (int i = 0; i < length; i++) {
coleenp@4037 60 array->at_put(i, value);
coleenp@4037 61 }
coleenp@4037 62 return array;
coleenp@4037 63 }
coleenp@4037 64
coleenp@4037 65 template <typename T>
coleenp@4037 66 static void free_array(ClassLoaderData* loader_data, Array<T>* data) {
coleenp@4037 67 if (data != NULL) {
coleenp@4037 68 assert(loader_data != NULL, "shouldn't pass null");
hseigel@5896 69 assert(!data->is_shared(), "cannot deallocate array in shared spaces");
coleenp@4037 70 int size = data->size();
jmasa@4457 71 if (DumpSharedSpaces) {
jmasa@4457 72 loader_data->ro_metaspace()->deallocate((MetaWord*)data, size, false);
jmasa@4457 73 } else {
jmasa@4457 74 loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size, false);
jmasa@4457 75 }
coleenp@4037 76 }
coleenp@4037 77 }
coleenp@4037 78
coleenp@4037 79 // Deallocation method for metadata
coleenp@4037 80 template <class T>
coleenp@4037 81 static void free_metadata(ClassLoaderData* loader_data, T md) {
coleenp@4037 82 if (md != NULL) {
coleenp@4037 83 assert(loader_data != NULL, "shouldn't pass null");
coleenp@4037 84 int size = md->size();
coleenp@4037 85 // Call metadata's deallocate function which will call deallocate fields
jmasa@4457 86 assert(!DumpSharedSpaces, "cannot deallocate metadata when dumping CDS archive");
coleenp@4037 87 assert(!md->on_stack(), "can't deallocate things on stack");
hseigel@5896 88 assert(!md->is_shared(), "cannot deallocate if in shared spaces");
coleenp@4037 89 md->deallocate_contents(loader_data);
coleenp@4037 90 loader_data->metaspace_non_null()->deallocate((MetaWord*)md, size, md->is_klass());
coleenp@4037 91 }
coleenp@4037 92 }
coleenp@4037 93 };
coleenp@4037 94
coleenp@4037 95 #endif // SHARE_VM_MEMORY_METADATAFACTORY_HPP

mercurial