diff --git a/src/hotspot/share/classfile/modules.cpp b/src/hotspot/share/classfile/modules.cpp index 7e26febda89f2..a63fbc1eb747e 100644 --- a/src/hotspot/share/classfile/modules.cpp +++ b/src/hotspot/share/classfile/modules.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -628,12 +628,14 @@ void Modules::serialize(SerializeClosure* soc) { } void Modules::dump_native_access_flag() { + ResourceMark rm; const char* native_access_names = get_native_access_flags_as_sorted_string(); if (native_access_names != nullptr) { _archived_native_access_flags = ArchiveBuilder::current()->ro_strdup(native_access_names); } } +// Caller needs ResourceMark const char* Modules::get_native_access_flags_as_sorted_string() { return get_numbered_property_as_sorted_string("jdk.module.enable.native.access"); } @@ -641,6 +643,7 @@ const char* Modules::get_native_access_flags_as_sorted_string() { void Modules::serialize_native_access_flags(SerializeClosure* soc) { soc->do_ptr(&_archived_native_access_flags); if (soc->reading()) { + ResourceMark rm; check_archived_flag_consistency(_archived_native_access_flags, get_native_access_flags_as_sorted_string(), "jdk.module.enable.native.access"); // Don't hold onto the pointer, in case we might decide to unmap the archive. @@ -649,12 +652,14 @@ void Modules::serialize_native_access_flags(SerializeClosure* soc) { } void Modules::dump_addmods_names() { + ResourceMark rm; const char* addmods_names = get_addmods_names_as_sorted_string(); if (addmods_names != nullptr) { _archived_addmods_names = ArchiveBuilder::current()->ro_strdup(addmods_names); } } +// Caller needs ResourceMark const char* Modules::get_addmods_names_as_sorted_string() { return get_numbered_property_as_sorted_string("jdk.module.addmods"); } @@ -662,6 +667,7 @@ const char* Modules::get_addmods_names_as_sorted_string() { void Modules::serialize_addmods_names(SerializeClosure* soc) { soc->do_ptr(&_archived_addmods_names); if (soc->reading()) { + ResourceMark rm; check_archived_flag_consistency(_archived_addmods_names, get_addmods_names_as_sorted_string(), "jdk.module.addmods"); // Don't hold onto the pointer, in case we might decide to unmap the archive. @@ -669,8 +675,8 @@ void Modules::serialize_addmods_names(SerializeClosure* soc) { } } +// Caller needs ResourceMark const char* Modules::get_numbered_property_as_sorted_string(const char* property) { - ResourceMark rm; // theoretical string size limit for decimal int, but the following loop will end much sooner due to // OS command-line size limit. const int max_digits = 10; @@ -723,7 +729,7 @@ const char* Modules::get_numbered_property_as_sorted_string(const char* property } } - return (st.size() > 0) ? os::strdup(st.as_string()) : nullptr; // Example: "java.base,java.compiler" + return (st.size() > 0) ? st.as_string() : nullptr; // Example: "java.base,java.compiler" } void Modules::define_archived_modules(Handle h_platform_loader, Handle h_system_loader, TRAPS) {