31 #include "utilities/exceptions.hpp"
32 #include "utilities/globalDefinitions.hpp"
33 #include <type_traits>
34
35 class MetadataFactory : AllStatic {
36 public:
37 template <typename T>
38 static Array<T>* new_array(ClassLoaderData* loader_data, int length, TRAPS) {
39 return new (loader_data, length, THREAD) Array<T>(length);
40 }
41
42 template <typename T>
43 static Array<T>* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
44 Array<T>* array = new_array<T>(loader_data, length, CHECK_NULL);
45 for (int i = 0; i < length; i++) {
46 array->at_put(i, value);
47 }
48 return array;
49 }
50
51 template <typename T>
52 static void free_array(ClassLoaderData* loader_data, Array<T>* data) {
53 if (data != nullptr) {
54 assert(loader_data != nullptr, "shouldn't pass null");
55 assert(!data->is_shared(), "cannot deallocate array in shared spaces");
56 int size = data->size();
57 loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size);
58 }
59 }
60
61 // Deallocation method for metadata
62 template <class T>
63 static void free_metadata(ClassLoaderData* loader_data, T* md) {
64 if (md != nullptr) {
65 assert(loader_data != nullptr, "shouldn't pass null");
66 int size = md->size();
67 // Call metadata's deallocate function which will deallocate fields and release_C_heap_structures
68 assert(!md->on_stack(), "can't deallocate things on stack");
69 assert(!md->is_shared(), "cannot deallocate if in shared spaces");
70 md->deallocate_contents(loader_data);
|
31 #include "utilities/exceptions.hpp"
32 #include "utilities/globalDefinitions.hpp"
33 #include <type_traits>
34
35 class MetadataFactory : AllStatic {
36 public:
37 template <typename T>
38 static Array<T>* new_array(ClassLoaderData* loader_data, int length, TRAPS) {
39 return new (loader_data, length, THREAD) Array<T>(length);
40 }
41
42 template <typename T>
43 static Array<T>* new_array(ClassLoaderData* loader_data, int length, T value, TRAPS) {
44 Array<T>* array = new_array<T>(loader_data, length, CHECK_NULL);
45 for (int i = 0; i < length; i++) {
46 array->at_put(i, value);
47 }
48 return array;
49 }
50
51 // Work-around -- see JDK-8331086.
52 // This API should be used for TrainingData only.
53 template <typename T>
54 static Array<T>* new_array_from_c_heap(int length, MemTag flags) {
55 return new (length, flags) Array<T>(length);
56 }
57
58 template <typename T>
59 static void free_array(ClassLoaderData* loader_data, Array<T>* data) {
60 if (data != nullptr) {
61 assert(loader_data != nullptr, "shouldn't pass null");
62 assert(!data->is_shared(), "cannot deallocate array in shared spaces");
63 int size = data->size();
64 loader_data->metaspace_non_null()->deallocate((MetaWord*)data, size);
65 }
66 }
67
68 // Deallocation method for metadata
69 template <class T>
70 static void free_metadata(ClassLoaderData* loader_data, T* md) {
71 if (md != nullptr) {
72 assert(loader_data != nullptr, "shouldn't pass null");
73 int size = md->size();
74 // Call metadata's deallocate function which will deallocate fields and release_C_heap_structures
75 assert(!md->on_stack(), "can't deallocate things on stack");
76 assert(!md->is_shared(), "cannot deallocate if in shared spaces");
77 md->deallocate_contents(loader_data);
|