Path: blob/master/src/hotspot/share/memory/metadataFactory.hpp
40949 views
/*1* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_MEMORY_METADATAFACTORY_HPP25#define SHARE_MEMORY_METADATAFACTORY_HPP2627#include "classfile/classLoaderData.hpp"28#include "memory/classLoaderMetaspace.hpp"29#include "oops/array.inline.hpp"30#include "utilities/exceptions.hpp"31#include "utilities/globalDefinitions.hpp"3233class MetadataFactory : AllStatic {34public:35template <typename T>36static Array<T>* new_array(ClassLoaderData* loader_data, int length, TRAPS) {37// The "true" argument is because all metadata arrays are read only when38// dumped to the shared archive39return new (loader_data, length, THREAD) Array<T>(length);40}4142template <typename T>43static Array<T>* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {44Array<T>* array = new_array<T>(loader_data, length, CHECK_NULL);45for (int i = 0; i < length; i++) {46array->at_put(i, value);47}48return array;49}5051template <typename T>52static void free_array(ClassLoaderData* loader_data, Array<T>* data) {53if (data != NULL) {54assert(loader_data != NULL, "shouldn't pass null");55assert(!data->is_shared(), "cannot deallocate array in shared spaces");56int size = data->size();57loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size, false);58}59}6061// Deallocation method for metadata62template <class T>63static void free_metadata(ClassLoaderData* loader_data, T md) {64if (md != NULL) {65assert(loader_data != NULL, "shouldn't pass null");66int size = md->size();67// Call metadata's deallocate function which will call deallocate fields68assert(!md->on_stack(), "can't deallocate things on stack");69assert(!md->is_shared(), "cannot deallocate if in shared spaces");70md->deallocate_contents(loader_data);71loader_data->metaspace_non_null()->deallocate((MetaWord*)md, size, md->is_klass());72}73}74};7576#endif // SHARE_MEMORY_METADATAFACTORY_HPP777879