coleenp@4037: /* coleenp@4037: * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. coleenp@4037: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. coleenp@4037: * coleenp@4037: * This code is free software; you can redistribute it and/or modify it coleenp@4037: * under the terms of the GNU General Public License version 2 only, as coleenp@4037: * published by the Free Software Foundation. coleenp@4037: * coleenp@4037: * This code is distributed in the hope that it will be useful, but WITHOUT coleenp@4037: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or coleenp@4037: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License coleenp@4037: * version 2 for more details (a copy is included in the LICENSE file that coleenp@4037: * accompanied this code). coleenp@4037: * coleenp@4037: * You should have received a copy of the GNU General Public License version coleenp@4037: * 2 along with this work; if not, write to the Free Software Foundation, coleenp@4037: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. coleenp@4037: * coleenp@4037: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA coleenp@4037: * or visit www.oracle.com if you need additional information or have any coleenp@4037: * questions. coleenp@4037: * coleenp@4037: */ coleenp@4037: coleenp@4037: #ifndef SHARE_VM_MEMORY_METADATAFACTORY_HPP coleenp@4037: #define SHARE_VM_MEMORY_METADATAFACTORY_HPP coleenp@4037: coleenp@4037: #include "utilities/array.hpp" coleenp@4037: #include "utilities/exceptions.hpp" coleenp@4037: #include "utilities/globalDefinitions.hpp" coleenp@4037: coleenp@4037: class MetadataFactory : AllStatic { coleenp@4037: public: coleenp@4037: template coleenp@4037: static Array* new_array(ClassLoaderData* loader_data, int length, TRAPS) { coleenp@4037: // The "true" argument is because all metadata arrays are read only when coleenp@4037: // dumped to the shared archive coleenp@4037: return new (loader_data, length, /*read_only*/true, THREAD) Array(length); coleenp@4037: } coleenp@4037: coleenp@4037: template coleenp@4037: static Array* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) { coleenp@4037: Array* array = new_array(loader_data, length, CHECK_NULL); coleenp@4037: for (int i = 0; i < length; i++) { coleenp@4037: array->at_put(i, value); coleenp@4037: } coleenp@4037: return array; coleenp@4037: } coleenp@4037: coleenp@4037: template coleenp@4037: static Array* new_writeable_array(ClassLoaderData* loader_data, int length, TRAPS) { coleenp@4037: return new (loader_data, length, /*read_only*/false, THREAD) Array(length); coleenp@4037: } coleenp@4037: coleenp@4037: template coleenp@4037: static Array* new_writeable_array(ClassLoaderData* loader_data, int length, T value, TRAPS) { coleenp@4037: Array* array = new_writeable_array(loader_data, length, CHECK_NULL); coleenp@4037: for (int i = 0; i < length; i++) { coleenp@4037: array->at_put(i, value); coleenp@4037: } coleenp@4037: return array; coleenp@4037: } coleenp@4037: coleenp@4037: template coleenp@4037: static void free_array(ClassLoaderData* loader_data, Array* data) { coleenp@4037: if (data != NULL) { coleenp@4037: assert(loader_data != NULL, "shouldn't pass null"); coleenp@4037: int size = data->size(); jmasa@4457: if (DumpSharedSpaces) { jmasa@4457: loader_data->ro_metaspace()->deallocate((MetaWord*)data, size, false); jmasa@4457: } else { jmasa@4457: loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size, false); jmasa@4457: } coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: // Deallocation method for metadata coleenp@4037: template coleenp@4037: static void free_metadata(ClassLoaderData* loader_data, T md) { coleenp@4037: if (md != NULL) { coleenp@4037: assert(loader_data != NULL, "shouldn't pass null"); coleenp@4037: int size = md->size(); coleenp@4037: // Call metadata's deallocate function which will call deallocate fields jmasa@4457: assert(!DumpSharedSpaces, "cannot deallocate metadata when dumping CDS archive"); coleenp@4037: assert(!md->on_stack(), "can't deallocate things on stack"); coleenp@4037: md->deallocate_contents(loader_data); coleenp@4037: loader_data->metaspace_non_null()->deallocate((MetaWord*)md, size, md->is_klass()); coleenp@4037: } coleenp@4037: } coleenp@4037: }; coleenp@4037: coleenp@4037: #endif // SHARE_VM_MEMORY_METADATAFACTORY_HPP