src/share/vm/memory/metadataFactory.hpp

Fri, 20 Sep 2013 10:53:28 +0200

author
stefank
date
Fri, 20 Sep 2013 10:53:28 +0200
changeset 5769
2c022e432e10
parent 4457
59a58e20dc60
child 5896
d37a0525c0fe
permissions
-rw-r--r--

8024974: Incorrect use of GC_locker::is_active()
Summary: SymbolTable and StringTable can make calls to GC_locker::is_active() outside a safepoint. This isn't safe because the GC_locker active state (lock count) is only updated at a safepoint and only remains valid as long as _needs_gc is true. However, outside a safepoint_needs_gc can change to false at any time, which makes it impossible to do a correct call to is_active() in that context. In this case these calls can just be removed since the input argument to basic_add() should never be on the heap and so there's no need to check the GC_locker state. This change also adjusts the assert() in is_active() to makes sure all calls to this function are always done under a safepoint.
Reviewed-by: brutisso, dcubed
Contributed-by: per.liden@oracle.com

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

mercurial