From 2cd0300a9febe0b837be3fb9362cc707cb8c773d Mon Sep 17 00:00:00 2001 From: Nathan Henderson Date: Tue, 3 Dec 2024 14:50:30 -0500 Subject: [PATCH] Change J9Module::moduleName from a j9object_t to a J9UTF8 pointer Signed-off-by: Nathan Henderson --- .../ddrinteractive/ModularityHelper.java | 2 +- .../DumpModuleDirectedExportsCommand.java | 4 +- .../commands/DumpModuleReadsCommand.java | 4 +- .../commands/FindAllModulesCommand.java | 4 +- .../commands/FindAllReadsCommand.java | 4 +- .../commands/FindModuleByNameCommand.java | 4 +- .../commands/FindModulesCommand.java | 5 +- .../J9ModuleStructureFormatter.java | 4 +- runtime/bcutil/dynload.c | 22 +-- runtime/gc_base/RootScanner.cpp | 3 - .../ConcurrentMarkingDelegate.cpp | 3 - runtime/gc_glue_java/MarkingDelegate.cpp | 3 - runtime/gc_glue_java/MetronomeDelegate.cpp | 1 - runtime/gc_vlhgc/CopyForwardScheme.cpp | 10 -- runtime/gc_vlhgc/GlobalMarkCardScrubber.cpp | 3 - runtime/gc_vlhgc/GlobalMarkingScheme.cpp | 4 - runtime/gc_vlhgc/WriteOnceCompactor.cpp | 9 - runtime/j9vm/java11vmi.c | 170 ++++++------------ runtime/jcl/common/jclexception.cpp | 2 +- runtime/oti/j9nonbuilder.h | 4 +- runtime/oti/vm_api.h | 41 +++++ runtime/util/cphelp.c | 16 +- runtime/verbose/verbose.c | 17 +- runtime/vm/JFRConstantPoolTypes.cpp | 2 +- runtime/vm/ModularityHashTables.c | 30 +--- runtime/vm/classsupport.c | 11 +- runtime/vm/createramclass.cpp | 23 +-- runtime/vm/exceptiondescribe.c | 12 +- runtime/vm/intfunc.c | 2 + runtime/vm/jvmfree.c | 17 +- runtime/vm/lookupmethod.c | 10 +- runtime/vm/stringhelpers.cpp | 74 ++++++++ 32 files changed, 255 insertions(+), 265 deletions(-) diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/ModularityHelper.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/ModularityHelper.java index f7668e77907..7357b52e4a1 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/ModularityHelper.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/ModularityHelper.java @@ -97,7 +97,7 @@ public static boolean moduleFilterMatchAll(J9ModulePointer modulePtr, String arg * be outputted to. */ public static void printJ9Module(J9ModulePointer modulePtr, PrintStream out) throws CorruptDataException { - String moduleName = J9ObjectHelper.stringValue(modulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(modulePtr.moduleName()); String hexAddress = modulePtr.getHexAddress(); out.printf("%-30s !j9module %s%n", moduleName, hexAddress); } diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleDirectedExportsCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleDirectedExportsCommand.java index 4c13e8b6c01..4077bf790d1 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleDirectedExportsCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleDirectedExportsCommand.java @@ -36,7 +36,7 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; import com.ibm.j9ddr.vm29.pointer.generated.J9PackagePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper; @@ -74,7 +74,7 @@ public void run(String command, String[] args, Context context, PrintStream out) while (slotIterator.hasNext()) { J9ModulePointer exportModulePtr = slotIterator.next(); hitCount++; - String moduleName = J9ObjectHelper.stringValue(exportModulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(exportModulePtr.moduleName()); String hexAddress = exportModulePtr.getHexAddress(); out.printf("%-30s !j9module %s%n", moduleName, hexAddress); } diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleReadsCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleReadsCommand.java index 484e4ca6a69..1a98aa85c66 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleReadsCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/DumpModuleReadsCommand.java @@ -35,7 +35,7 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer; import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper; @@ -72,7 +72,7 @@ public void run(String command, String[] args, Context context, PrintStream out) SlotIterator slotIterator = moduleHashTable.iterator(); while (slotIterator.hasNext()) { J9ModulePointer readModulePtr = slotIterator.next(); - String moduleName = J9ObjectHelper.stringValue(readModulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(readModulePtr.moduleName()); String hexAddress = readModulePtr.getHexAddress(); out.printf("%-30s !j9module %s%n", moduleName, hexAddress); } diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllModulesCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllModulesCommand.java index b38de251786..edf75c47869 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllModulesCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllModulesCommand.java @@ -35,7 +35,7 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper; @@ -70,7 +70,7 @@ public void run(String command, String[] args, Context context, PrintStream out) SlotIterator slotIterator = moduleHashTable.iterator(); while (slotIterator.hasNext()) { J9ModulePointer modulePtr = slotIterator.next(); - String moduleName = J9ObjectHelper.stringValue(modulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(modulePtr.moduleName()); String hexAddress = modulePtr.getHexAddress(); out.printf("%-30s !j9module %s%n", moduleName, hexAddress); } diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllReadsCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllReadsCommand.java index 899a0f7d3e8..1a63623c0d6 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllReadsCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindAllReadsCommand.java @@ -38,7 +38,7 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer; import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper; @@ -79,7 +79,7 @@ public void run(String command, String[] args, Context context, PrintStream out) SlotIterator slotIterator = moduleHashTable.iterator(); while (slotIterator.hasNext()) { J9ModulePointer modulePtr = slotIterator.next(); - String moduleName = J9ObjectHelper.stringValue(modulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(modulePtr.moduleName()); String hexAddress = modulePtr.getHexAddress(); J9HashTablePointer readTable = modulePtr.readAccessHashTable(); HashTable readModuleHashTable = ModuleHashTable.fromJ9HashTable(readTable); diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModuleByNameCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModuleByNameCommand.java index 81e109c80d1..f171c5e3243 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModuleByNameCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModuleByNameCommand.java @@ -36,7 +36,7 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.JavaVersionHelper; @@ -82,7 +82,7 @@ public void run(String command, String[] args, Context context, PrintStream out) SlotIterator slotIterator = moduleHashTable.iterator(); while (slotIterator.hasNext()) { J9ModulePointer modulePtr = slotIterator.next(); - String moduleName = J9ObjectHelper.stringValue(modulePtr.moduleName()); + String moduleName = J9UTF8Helper.stringValue(modulePtr.moduleName()); if (pattern.isMatch(moduleName)) { hitCount++; String hexAddress = modulePtr.getHexAddress(); diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModulesCommand.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModulesCommand.java index b94aa31824a..efaa1949e80 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModulesCommand.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/commands/FindModulesCommand.java @@ -39,7 +39,6 @@ import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; import com.ibm.j9ddr.vm29.pointer.generated.J9PackagePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; import com.ibm.j9ddr.vm29.pointer.helper.J9RASHelper; import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; import com.ibm.j9ddr.vm29.tools.ddrinteractive.ModularityHelper; @@ -157,7 +156,7 @@ private static void printModuleReads(J9ModulePointer modulePtr, PrintStream out) * @return true if the names are equal, false otherwise. */ private static boolean filterModuleName(J9ModulePointer modulePtr, String targetName) throws CorruptDataException { - return J9ObjectHelper.stringValue(modulePtr.moduleName()).equals(targetName); + return J9UTF8Helper.stringValue(modulePtr.moduleName()).equals(targetName); } @@ -168,7 +167,7 @@ private static boolean filterRequiresTargetModule(J9ModulePointer modulePtr, Str SlotIterator slotIterator = moduleHashTable.iterator(); while (slotIterator.hasNext()) { J9ModulePointer readModulePtr = slotIterator.next(); - if (J9ObjectHelper.stringValue(readModulePtr.moduleName()).equals(targetModule)) { + if (J9UTF8Helper.stringValue(readModulePtr.moduleName()).equals(targetModule)) { result = true; break; } diff --git a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/structureformat/extensions/J9ModuleStructureFormatter.java b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/structureformat/extensions/J9ModuleStructureFormatter.java index 184361f42f8..9a376a8832a 100644 --- a/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/structureformat/extensions/J9ModuleStructureFormatter.java +++ b/debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/tools/ddrinteractive/structureformat/extensions/J9ModuleStructureFormatter.java @@ -30,7 +30,7 @@ import com.ibm.j9ddr.tools.ddrinteractive.FormatWalkResult; import com.ibm.j9ddr.tools.ddrinteractive.IFieldFormatter; import com.ibm.j9ddr.vm29.pointer.generated.J9ModulePointer; -import com.ibm.j9ddr.vm29.pointer.helper.J9ObjectHelper; +import com.ibm.j9ddr.vm29.pointer.helper.J9UTF8Helper; /** * Structure Formatter that adds a suffix to the command "!j9module $moduleAddress$" output @@ -55,7 +55,7 @@ public FormatWalkResult postFormat(String type, long address, J9ModulePointer modulePtr = J9ModulePointer.cast(address); String moduleAddress = modulePtr.getHexAddress(); try { - out.println("Module name: " + J9ObjectHelper.stringValue(modulePtr.moduleName())); + out.println("Module name: " + J9UTF8Helper.stringValue(modulePtr.moduleName())); } catch (CorruptDataException e) { // Do nothing } diff --git a/runtime/bcutil/dynload.c b/runtime/bcutil/dynload.c index d78feb2e655..701fcdf5e5b 100644 --- a/runtime/bcutil/dynload.c +++ b/runtime/bcutil/dynload.c @@ -207,9 +207,7 @@ static IDATA searchClassInModule(J9VMThread * vmThread, J9Module * j9module, U_8 * className, UDATA classNameLength, BOOLEAN verbose, J9TranslationLocalBuffer *localBuffer) { J9JavaVM *javaVM = vmThread->javaVM; - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleName = NULL; - BOOLEAN freeModuleName = FALSE; + U_8 *moduleName = NULL; IDATA rc = 1; PORT_ACCESS_FROM_JAVAVM(javaVM); @@ -217,28 +215,18 @@ searchClassInModule(J9VMThread * vmThread, J9Module * j9module, U_8 * className, Trc_BCU_Assert_True(NULL != localBuffer); if (j9module == javaVM->javaBaseModule) { - moduleName = JAVA_BASE_MODULE; + moduleName = (U_8 *)JAVA_BASE_MODULE; } else { - moduleName = J9_VM_FUNCTION(vmThread, copyStringToUTF8WithMemAlloc)( - vmThread, j9module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL == moduleName) { - rc = -1; - goto _end; - } - if (moduleNameBuf != moduleName) { - freeModuleName = TRUE; + if (NULL != j9module->moduleName) { + moduleName = J9UTF8_DATA(j9module->moduleName); } } - rc = searchClassInCPEntry(vmThread, javaVM->modulesPathEntry, j9module, (U_8*)moduleName, className, classNameLength, verbose); + rc = searchClassInCPEntry(vmThread, javaVM->modulesPathEntry, j9module, moduleName, className, classNameLength, verbose); if (0 == rc) { localBuffer->loadLocationType = LOAD_LOCATION_MODULE; } - if (TRUE == freeModuleName) { - j9mem_free_memory(moduleName); - } -_end: return rc; } diff --git a/runtime/gc_base/RootScanner.cpp b/runtime/gc_base/RootScanner.cpp index 44e16ec5b90..bc26fb25188 100644 --- a/runtime/gc_base/RootScanner.cpp +++ b/runtime/gc_base/RootScanner.cpp @@ -92,9 +92,6 @@ MM_RootScanner::scanModularityObjects(J9ClassLoader * classLoader) J9Module * const module = *modulePtr; doSlot(&module->moduleObject); - if (NULL != module->moduleName) { - doSlot(&module->moduleName); - } if (NULL != module->version) { doSlot(&module->version); } diff --git a/runtime/gc_glue_java/ConcurrentMarkingDelegate.cpp b/runtime/gc_glue_java/ConcurrentMarkingDelegate.cpp index eb5e6bf39ba..c5b082fbc6f 100644 --- a/runtime/gc_glue_java/ConcurrentMarkingDelegate.cpp +++ b/runtime/gc_glue_java/ConcurrentMarkingDelegate.cpp @@ -426,9 +426,6 @@ MM_ConcurrentMarkingDelegate::concurrentClassMark(MM_EnvironmentBase *env, bool J9Module * const module = *modulePtr; _markingScheme->markObject(env, (j9object_t)module->moduleObject); - if (NULL != module->moduleName) { - _markingScheme->markObject(env, (j9object_t)module->moduleName); - } if (NULL != module->version) { _markingScheme->markObject(env, (j9object_t)module->version); } diff --git a/runtime/gc_glue_java/MarkingDelegate.cpp b/runtime/gc_glue_java/MarkingDelegate.cpp index e29f8719e55..ef1a8b44245 100644 --- a/runtime/gc_glue_java/MarkingDelegate.cpp +++ b/runtime/gc_glue_java/MarkingDelegate.cpp @@ -415,9 +415,6 @@ MM_MarkingDelegate::completeMarking(MM_EnvironmentBase *env) J9Module * const module = *modulePtr; _markingScheme->markObjectNoCheck(env, (omrobjectptr_t )module->moduleObject); - if (NULL != module->moduleName) { - _markingScheme->markObjectNoCheck(env, (omrobjectptr_t )module->moduleName); - } if (NULL != module->version) { _markingScheme->markObjectNoCheck(env, (omrobjectptr_t )module->version); } diff --git a/runtime/gc_glue_java/MetronomeDelegate.cpp b/runtime/gc_glue_java/MetronomeDelegate.cpp index d2d12f19955..b9cbe0f858b 100644 --- a/runtime/gc_glue_java/MetronomeDelegate.cpp +++ b/runtime/gc_glue_java/MetronomeDelegate.cpp @@ -1039,7 +1039,6 @@ MM_MetronomeDelegate::doClassTracing(MM_EnvironmentRealtime *env) J9Module * const module = *modulePtr; didWork |= _markingScheme->markObject(env, module->moduleObject); - didWork |= _markingScheme->markObject(env, module->moduleName); didWork |= _markingScheme->markObject(env, module->version); modulePtr = (J9Module**)hashTableNextDo(&walkState); } diff --git a/runtime/gc_vlhgc/CopyForwardScheme.cpp b/runtime/gc_vlhgc/CopyForwardScheme.cpp index f02666efc09..9158261f5bf 100644 --- a/runtime/gc_vlhgc/CopyForwardScheme.cpp +++ b/runtime/gc_vlhgc/CopyForwardScheme.cpp @@ -2691,11 +2691,6 @@ MM_CopyForwardScheme::scanClassLoaderObjectSlots(MM_EnvironmentVLHGC *env, MM_Al while (success && (NULL != modulePtr)) { J9Module * const module = *modulePtr; success = copyAndForward(env, reservingContext, classLoaderObject, (J9Object **)&(module->moduleObject)); - if (success) { - if (NULL != module->moduleName) { - success = copyAndForward(env, reservingContext, classLoaderObject, (J9Object **)&(module->moduleName)); - } - } if (success) { if (NULL != module->version) { success = copyAndForward(env, reservingContext, classLoaderObject, (J9Object **)&(module->version)); @@ -4441,11 +4436,6 @@ MM_CopyForwardScheme::scanRoots(MM_EnvironmentVLHGC* env) while (success && (NULL != modulePtr)) { J9Module * const module = *modulePtr; success = copyAndForward(env, getContextForHeapAddress(module->moduleObject), (J9Object **)&(module->moduleObject)); - if (success) { - if (NULL != module->moduleName) { - success = copyAndForward(env, getContextForHeapAddress(module->moduleName), (J9Object **)&(module->moduleName)); - } - } if (success) { if (NULL != module->version) { success = copyAndForward(env, getContextForHeapAddress(module->version), (J9Object **)&(module->version)); diff --git a/runtime/gc_vlhgc/GlobalMarkCardScrubber.cpp b/runtime/gc_vlhgc/GlobalMarkCardScrubber.cpp index f98c8ef1dd9..012456ab8f0 100644 --- a/runtime/gc_vlhgc/GlobalMarkCardScrubber.cpp +++ b/runtime/gc_vlhgc/GlobalMarkCardScrubber.cpp @@ -289,9 +289,6 @@ MM_GlobalMarkCardScrubber::scrubClassLoaderObject(MM_EnvironmentVLHGC *env, J9Ob J9Module * const module = *modulePtr; Assert_MM_true(NULL != module->moduleObject); doScrub = mayScrubReference(env, classLoaderObject, module->moduleObject); - if (doScrub) { - doScrub = mayScrubReference(env, classLoaderObject, module->moduleName); - } if (doScrub) { doScrub = mayScrubReference(env, classLoaderObject, module->version); } diff --git a/runtime/gc_vlhgc/GlobalMarkingScheme.cpp b/runtime/gc_vlhgc/GlobalMarkingScheme.cpp index d2ca59f11f0..718c3c5ddf5 100644 --- a/runtime/gc_vlhgc/GlobalMarkingScheme.cpp +++ b/runtime/gc_vlhgc/GlobalMarkingScheme.cpp @@ -896,10 +896,6 @@ MM_GlobalMarkingScheme::scanClassLoaderObject(MM_EnvironmentVLHGC *env, J9Object Assert_MM_true(NULL != module->moduleObject); markObject(env, module->moduleObject); rememberReferenceIfRequired(env, classLoaderObject, module->moduleObject); - if (NULL != module->moduleName) { - markObject(env, module->moduleName); - rememberReferenceIfRequired(env, classLoaderObject, module->moduleName); - } if (NULL != module->version) { markObject(env, module->version); rememberReferenceIfRequired(env, classLoaderObject, module->version); diff --git a/runtime/gc_vlhgc/WriteOnceCompactor.cpp b/runtime/gc_vlhgc/WriteOnceCompactor.cpp index 6ed44439d0e..123c9973b19 100644 --- a/runtime/gc_vlhgc/WriteOnceCompactor.cpp +++ b/runtime/gc_vlhgc/WriteOnceCompactor.cpp @@ -1337,15 +1337,6 @@ MM_WriteOnceCompactor::fixupClassLoaderObject(MM_EnvironmentVLHGC* env, J9Object *slotPtr = forwardedObject; _interRegionRememberedSet->rememberReferenceForCompact(env, classLoaderObject, forwardedObject); - slotPtr = &module->moduleName; - - originalObject = *slotPtr; - if (NULL != originalObject) { - J9Object* forwardedObject = getForwardWrapper(env, originalObject, cache); - *slotPtr = forwardedObject; - _interRegionRememberedSet->rememberReferenceForCompact(env, classLoaderObject, forwardedObject); - } - slotPtr = &module->version; originalObject = *slotPtr; diff --git a/runtime/j9vm/java11vmi.c b/runtime/j9vm/java11vmi.c index f888942fd47..182dbb0f94b 100644 --- a/runtime/j9vm/java11vmi.c +++ b/runtime/j9vm/java11vmi.c @@ -82,7 +82,7 @@ static UDATA hashTableAtPut(J9HashTable * table, void * value, BOOLEAN collision static void throwExceptionHelper(J9VMThread * currentThread, UDATA errCode); static void freePackage(J9VMThread * currentThread, J9Package * j9package); static J9ClassLoader * getModuleObjectClassLoader(J9VMThread * currentThread, j9object_t moduleObject); -static J9Module * createModule(J9VMThread * currentThread, j9object_t moduleObject, J9ClassLoader * classLoader, j9object_t moduleName); +static J9Module *createModule(J9VMThread *currentThread, j9object_t moduleObject, J9ClassLoader *classLoader, J9UTF8 *moduleName); static J9Module * getJ9Module(J9VMThread * currentThread, jobject module); static BOOLEAN isModuleNameValid(j9object_t moduleName); static BOOLEAN isModuleJavaBase(j9object_t moduleName); @@ -269,7 +269,7 @@ getModuleObjectClassLoader(J9VMThread * currentThread, j9object_t moduleObject) /** @throws OutOfMemory exception if memory cannot be allocated */ static J9Module * -createModule(J9VMThread * currentThread, j9object_t moduleObject, J9ClassLoader * classLoader, j9object_t moduleName) +createModule(J9VMThread *currentThread, j9object_t moduleObject, J9ClassLoader *classLoader, J9UTF8 *moduleName) { J9JavaVM * const vm = currentThread->javaVM; J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions; @@ -338,25 +338,12 @@ removePackageDefinition(J9VMThread * currentThread, J9Module * fromModule, const } static void -trcModulesCreationPackage(J9VMThread * currentThread, J9Module * fromModule, const char *package) +trcModulesCreationPackage(J9VMThread *currentThread, J9Module *fromModule, const char *package) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, fromModule->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - - if (NULL != moduleNameUTF) { - if (0 == strcmp(moduleNameUTF, JAVA_BASE_MODULE)) { - Trc_MODULE_createPackage(currentThread, package, "java.base", fromModule); - } else { - Trc_MODULE_createPackage(currentThread, package, moduleNameUTF, fromModule); - } - if (moduleNameBuf != moduleNameUTF) { - j9mem_free_memory(moduleNameUTF); - } - } else { - vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0); + J9UTF8 *moduleName = fromModule->moduleName; + if (NULL != moduleName) { + Trc_MODULE_createPackage(currentThread, package, (const char *)J9UTF8_DATA(moduleName), fromModule); } } @@ -517,15 +504,9 @@ static void trcModulesAddModuleExportsToAll(J9VMThread * currentThread, J9Module * fromModule, const char *package) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char fromModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *fromModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, fromModule->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, fromModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL != fromModuleNameUTF) { - Trc_MODULE_addModuleExportsToAll(currentThread, package, fromModuleNameUTF, fromModule); - if (fromModuleNameBuf != fromModuleNameUTF) { - j9mem_free_memory(fromModuleNameUTF); - } + J9UTF8 *moduleName = fromModule->moduleName; + if (NULL != moduleName) { + Trc_MODULE_addModuleExportsToAll(currentThread, package, (const char *)J9UTF8_DATA(moduleName), fromModule); } } @@ -545,18 +526,12 @@ exportPackageToAll(J9VMThread * currentThread, J9Module * fromModule, const char } static void -trcModulesAddModuleExportsToAllUnnamed(J9VMThread * currentThread, J9Module * fromModule, const char *package) +trcModulesAddModuleExportsToAllUnnamed(J9VMThread *currentThread, J9Module *fromModule, const char *package) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char fromModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *fromModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, fromModule->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, fromModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL != fromModuleNameUTF) { - Trc_MODULE_addModuleExportsToAllUnnamed(currentThread, package, fromModuleNameUTF, fromModule); - if (fromModuleNameBuf != fromModuleNameUTF) { - j9mem_free_memory(fromModuleNameUTF); - } + J9UTF8 *moduleName = fromModule->moduleName; + if (NULL != moduleName) { + Trc_MODULE_addModuleExportsToAllUnnamed(currentThread, package, (const char *)J9UTF8_DATA(moduleName), fromModule); } } @@ -620,21 +595,11 @@ static void trcModulesAddModuleExports(J9VMThread *currentThread, J9Module *fromModule, const char *package, J9Module *toModule) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char fromModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char toModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *fromModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, fromModule->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, fromModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - char *toModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, toModule->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, toModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if ((NULL != fromModuleNameUTF) && (NULL != toModuleNameUTF)) { - Trc_MODULE_addModuleExports(currentThread, package, fromModuleNameUTF, fromModule, toModuleNameUTF, toModule); - } - if (fromModuleNameBuf != fromModuleNameUTF) { - j9mem_free_memory(fromModuleNameUTF); - } - if (toModuleNameBuf != toModuleNameUTF) { - j9mem_free_memory(toModuleNameUTF); + J9UTF8 *fromModuleName = fromModule->moduleName; + J9UTF8 *toModuleName = toModule->moduleName; + if ((NULL != fromModuleName) && (NULL != toModuleName)) { + Trc_MODULE_addModuleExports( + currentThread, package, (const char *)J9UTF8_DATA(fromModuleName), fromModule, (const char *)J9UTF8_DATA(toModuleName), toModule); } } @@ -763,8 +728,8 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, jsize numPackages = 0; UDATA packagesNumBytes = 0; const char** packages = NULL; - PORT_ACCESS_FROM_ENV(env); #endif /* JAVA_SPEC_VERSION >= 15 */ + PORT_ACCESS_FROM_ENV(env); BOOLEAN firstModule = J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED); vmFuncs->internalEnterVMFromJNI(currentThread); @@ -820,7 +785,7 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, J9ClassLoader *systemClassLoader = vm->systemClassLoader; J9ClassLoader * const classLoader = getModuleObjectClassLoader(currentThread, modObj); - j9object_t moduleName = J9VMJAVALANGMODULE_NAME(currentThread, modObj); + j9object_t moduleNameObject = J9VMJAVALANGMODULE_NAME(currentThread, modObj); /* extensionClassLoader holds the platform class loader in Java 11+ */ if ((classLoader != systemClassLoader) && (classLoader != vm->extensionClassLoader)) { @@ -837,23 +802,22 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, } } - if (NULL == moduleName) { + if (NULL == moduleNameObject) { vmFuncs->setCurrentExceptionNLS(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, J9NLS_VM_MODULE_IS_UNNAMED); - } else if (!isModuleNameValid(moduleName)) { + } else if (!isModuleNameValid(moduleNameObject)) { vmFuncs->setCurrentExceptionNLS(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, J9NLS_VM_MODULE_NAME_IS_INVALID); } else if (NULL == classLoader) { /* An exception should be pending if classLoader is null */ Assert_SC_true(NULL != currentThread->currentException); } else { - char buf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *nameUTF = buf; - - PORT_ACCESS_FROM_VMC(currentThread); - nameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, buf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL == nameUTF) { + J9UTF8 *moduleName = vmFuncs->copyStringToJ9UTF8WithMemAlloc( + currentThread, moduleNameObject, J9_STR_NULL_TERMINATE_RESULT, "", 0, NULL, 0); + if (NULL == moduleName) { vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0); - } else if ((classLoader != systemClassLoader) && (0 == strcmp(nameUTF, JAVA_BASE_MODULE))) { + goto done; + } + const char *moduleNameData = (const char *)J9UTF8_DATA(moduleName); + if ((classLoader != systemClassLoader) && (0 == strcmp(moduleNameData, JAVA_BASE_MODULE))) { vmFuncs->setCurrentExceptionNLS(currentThread, J9VMCONSTANTPOOL_JAVALANGLAYERINSTANTIATIONEXCEPTION, J9NLS_VM_ONLY_BOOTCLASSLOADER_LOAD_MODULE_JAVABASE); } else { J9Module *j9mod = createModule(currentThread, modObj, classLoader, moduleName); @@ -865,21 +829,21 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, if (success) { /* For "java.base" module setting of jrt URL and patch paths is already done during startup. Avoid doing it here. */ if (!firstModule) { - Trc_MODULE_defineModule(currentThread, nameUTF, j9mod); + Trc_MODULE_defineModule(currentThread, moduleNameData, j9mod); if (classLoader == systemClassLoader) { - success = vmFuncs->setBootLoaderModulePatchPaths(vm, j9mod, (const char *)nameUTF); + success = vmFuncs->setBootLoaderModulePatchPaths(vm, j9mod, moduleNameData); if (FALSE == success) { vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0); } else { - const char* moduleName = "openj9.sharedclasses"; + const char* sharedClassesModuleName = "openj9.sharedclasses"; - if (0 == strcmp(nameUTF, moduleName)) { + if (0 == strcmp(moduleNameData, sharedClassesModuleName)) { J9VMDllLoadInfo *entry = FIND_DLL_TABLE_ENTRY(J9_SHARED_DLL_NAME); if ((NULL == entry) || (J9_ARE_ALL_BITS_SET(entry->loadFlags, FAILED_TO_LOAD)) ) { - j9nls_printf(PORTLIB, J9NLS_WARNING, J9NLS_VM_FAILED_TO_LOAD_MODULE_REQUIRED_DLL, J9_SHARED_DLL_NAME, moduleName); + j9nls_printf(PORTLIB, J9NLS_WARNING, J9NLS_VM_FAILED_TO_LOAD_MODULE_REQUIRED_DLL, J9_SHARED_DLL_NAME, sharedClassesModuleName); } } } @@ -889,7 +853,7 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, J9ClassWalkState classWalkState; J9Class* clazz = NULL; - Assert_SC_true(0 == strcmp(nameUTF, JAVA_BASE_MODULE)); + Assert_SC_true(0 == strcmp(moduleNameData, JAVA_BASE_MODULE)); clazz = vmFuncs->allClassesStartDo(&classWalkState, vm, systemClassLoader); while (NULL != clazz) { @@ -935,9 +899,6 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version, } } } - if (nameUTF != buf) { - j9mem_free_memory(nameUTF); - } } } @@ -1119,41 +1080,27 @@ static void trcModulesAddReadsModule(J9VMThread *currentThread, jobject toModule, J9Module *j9FromMod, J9Module *j9ToMod) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char fromModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char toModuleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *fromModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, j9FromMod->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, fromModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - char *toModuleNameUTF = NULL; - - if (NULL != j9ToMod) { - if (NULL != j9ToMod->moduleName) { - toModuleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, j9ToMod->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, toModuleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - } else { + const char *toModuleNameUTF = NULL; + J9UTF8 *fromModuleName = j9FromMod->moduleName; + if (NULL != fromModuleName) { + const char *fromModuleNameUTF = (const char *)J9UTF8_DATA(fromModuleName); + if (NULL != j9ToMod) { + J9UTF8 *toModuleName = j9ToMod->moduleName; + if (NULL != toModuleName) { + toModuleNameUTF = (const char *)J9UTF8_DATA(toModuleName); + } else { #define UNNAMED_MODULE "unnamed " - PORT_ACCESS_FROM_VMC(currentThread); - Assert_SC_true(J9VM_PACKAGE_NAME_BUFFER_LENGTH >= sizeof(UNNAMED_MODULE)); - memcpy(toModuleNameBuf, UNNAMED_MODULE, sizeof(UNNAMED_MODULE)); - toModuleNameUTF = toModuleNameBuf; + toModuleNameUTF = UNNAMED_MODULE; #undef UNNAMED_MODULE - } - } else { + } + } else { #define LOOSE_MODULE "loose " - PORT_ACCESS_FROM_VMC(currentThread); - Assert_SC_true(J9VM_PACKAGE_NAME_BUFFER_LENGTH >= sizeof(LOOSE_MODULE)); - memcpy(toModuleNameBuf, LOOSE_MODULE, sizeof(LOOSE_MODULE)); - toModuleNameUTF = toModuleNameBuf; + toModuleNameUTF = LOOSE_MODULE; #undef LOOSE_MODULE - } - if ((NULL != fromModuleNameUTF) && (NULL != toModuleNameUTF)) { - Trc_MODULE_addReadsModule(currentThread, fromModuleNameUTF, j9FromMod, toModuleNameUTF, toModule); - } - if (fromModuleNameBuf != fromModuleNameUTF) { - j9mem_free_memory(fromModuleNameUTF); - } - if (toModuleNameBuf != toModuleNameUTF) { - j9mem_free_memory(toModuleNameUTF); + } + if ((NULL != fromModuleNameUTF) && (NULL != toModuleNameUTF)) { + Trc_MODULE_addReadsModule(currentThread, fromModuleNameUTF, j9FromMod, toModuleNameUTF, toModule); + } } } @@ -1244,15 +1191,10 @@ static void trcModulesAddModulePackage(J9VMThread *currentThread, J9Module *j9mod, const char *package) { PORT_ACCESS_FROM_VMC(currentThread); - J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions; - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - currentThread, j9mod->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL != moduleNameUTF) { - Trc_MODULE_addModulePackage(currentThread, package, moduleNameUTF, j9mod); - if (moduleNameBuf != moduleNameUTF) { - j9mem_free_memory(moduleNameUTF); - } + J9InternalVMFunctions const *const vmFuncs = currentThread->javaVM->internalVMFunctions; + J9UTF8 *moduleName = j9mod->moduleName; + if (NULL != moduleName) { + Trc_MODULE_addModulePackage(currentThread, package, (const char *)J9UTF8_DATA(moduleName), j9mod); } } /** diff --git a/runtime/jcl/common/jclexception.cpp b/runtime/jcl/common/jclexception.cpp index 57958a737eb..334b4e5bfe3 100644 --- a/runtime/jcl/common/jclexception.cpp +++ b/runtime/jcl/common/jclexception.cpp @@ -185,7 +185,7 @@ getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecode omrthread_monitor_exit(vm->classLoaderModuleAndLocationMutex); } if (NULL != module) { - J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, module->moduleName); + J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, J9VMJAVALANGMODULE_NAME(vmThread, module->moduleObject)); J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULEVERSION(vmThread, element, module->version); } } diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index 5c562bbec62..0672c55e780 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -1843,7 +1843,7 @@ typedef struct J9AnnotationState { } J9AnnotationState; typedef struct J9Module { - j9object_t moduleName; + struct J9UTF8* moduleName; j9object_t moduleObject; j9object_t version; struct J9ClassLoader* classLoader; @@ -4850,6 +4850,8 @@ typedef struct J9InternalVMFunctions { IDATA ( *javaThreadProc)(void *entryarg) ; char* ( *copyStringToUTF8WithMemAlloc)(struct J9VMThread *currentThread, j9object_t string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength, UDATA *utf8Length) ; J9UTF8* ( *copyStringToJ9UTF8WithMemAlloc)(struct J9VMThread *vmThread, j9object_t string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength) ; + char* ( *copyJ9UTF8ToUTF8WithMemAlloc)(struct J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength) ; + J9UTF8* ( *copyJ9UTF8WithMemAlloc)(struct J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength) ; void ( *internalAcquireVMAccess)(struct J9VMThread * currentThread) ; void ( *internalAcquireVMAccessWithMask)(struct J9VMThread * currentThread, UDATA haltFlags) ; void ( *internalAcquireVMAccessNoMutexWithMask)(struct J9VMThread * vmThread, UDATA haltFlags) ; diff --git a/runtime/oti/vm_api.h b/runtime/oti/vm_api.h index 509008e9c3a..bea8ce5ed55 100644 --- a/runtime/oti/vm_api.h +++ b/runtime/oti/vm_api.h @@ -3577,6 +3577,47 @@ copyStringToUTF8WithMemAlloc(J9VMThread *vmThread, j9object_t string, UDATA stri J9UTF8* copyStringToJ9UTF8WithMemAlloc(J9VMThread *vmThread, j9object_t string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength); +/** + * Copy a J9UTF8 to a UTF8 data buffer, and optionally prepend a string before it. + * + * @note The caller must free the memory from this pointer if the return value is NOT the buffer argument. + * @note If the buffer is not large enough to encode the string this function will allocate. + * + * @param[in] currentThread the current J9VMThread + * @param[in] string a J9UTF8 pointer to the data to be copied + * it can't be NULL + * @param[in] stringFlags the flag to determine performing '.' --> '/' or NULL termination + * @param[in] prependStr the string to be prepended before the string object to be copied + * it can't be NULL but can be an empty string "" + * @param[in] prependStrLength The length of prependStr as computed by strlen. + * @param[in] buffer the buffer for the string + * @param[in] bufferLength the buffer length + * + * @return a char pointer to the string + */ +char * +copyJ9UTF8ToUTF8WithMemAlloc(J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength); + +/** + * Creates a fresh copy of a J9UTF8, and optionally prepend a string before it. + * + * @note The caller must free the memory from this pointer if the return value is NOT the buffer argument. + * @note If the buffer is not large enough to encode the string this function will allocate. + * + * @param[in] currentThread the current J9VMThread + * @param[in] string a J9UTF8 pointer to the data to be copied + * it can't be NULL + * @param[in] stringFlags the flag to determine performing '.' --> '/' or NULL termination + * @param[in] prependStr the string to be prepended before the string object to be copied + * it can't be NULL but can be an empty string "" + * @param[in] prependStrLength The length of prependStr as computed by strlen. + * @param[in] buffer the buffer for the string + * @param[in] bufferLength the buffer length + * + * @return a J9UTF8 pointer to the string + */ +J9UTF8 * +copyJ9UTF8WithMemAlloc(J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength); /** * Copy a Unicode String to a UTF8 data buffer. diff --git a/runtime/util/cphelp.c b/runtime/util/cphelp.c index 9b7c8e85cb8..ac9ec82056b 100644 --- a/runtime/util/cphelp.c +++ b/runtime/util/cphelp.c @@ -148,19 +148,23 @@ getModuleJRTURL(J9VMThread *currentThread, J9ClassLoader *classLoader, J9Module if (NULL == jrtURL) { if (J9_ARE_ALL_BITS_SET(javaVM->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED)) { - /* set jrt URL for the module */ - if (NULL != module->moduleName) { - jrtURL = vmFuncs->copyStringToJ9UTF8WithMemAlloc(currentThread, module->moduleName, J9_STR_NONE, "jrt:/", 5, NULL, 0); + if (NULL == module->moduleName) { + goto _exit; } - + /* Set jrt URL for the module. */ + const char *prependStr = "jrt:/"; + const size_t prependStrLen = strlen(prependStr); + jrtURL = vmFuncs->copyJ9UTF8WithMemAlloc( + currentThread, module->moduleName, J9_STR_NONE, prependStr, prependStrLen, NULL, 0); if (NULL == jrtURL) { goto _exit; } } else { - /* its java.base module */ + /* It is the java.base module. */ J9_DECLARE_CONSTANT_UTF8(jrtJavaBaseUrl, "jrt:/java.base"); const U_16 length = J9UTF8_LENGTH(&jrtJavaBaseUrl); - jrtURL = j9mem_allocate_memory(sizeof(J9UTF8) + length, OMRMEM_CATEGORY_VM); + const UDATA jrtURLSize = length + sizeof(J9UTF8); + jrtURL = (J9UTF8 *)j9mem_allocate_memory(jrtURLSize, OMRMEM_CATEGORY_VM); if (NULL == jrtURL) { goto _exit; } diff --git a/runtime/verbose/verbose.c b/runtime/verbose/verbose.c index 3881af85536..ea2fd0a7339 100644 --- a/runtime/verbose/verbose.c +++ b/runtime/verbose/verbose.c @@ -1393,24 +1393,19 @@ verboseStackMapFrameVerification(J9HookInterface** hook, UDATA eventNum, void* e static void printModule(J9VMThread* vmThread, char* message, J9Module* module) { - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleNameUTF = NULL; J9UTF8 *jrtURL = NULL; char* template = "%s: %s from: %.*s\n"; PORT_ACCESS_FROM_VMC(vmThread); - /* module name */ - moduleNameUTF = vmThread->javaVM->internalVMFunctions->copyStringToUTF8WithMemAlloc( - vmThread, module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - - /* module location */ + /* module location. */ jrtURL = getModuleJRTURL(vmThread, module->classLoader, module); - j9tty_printf(PORTLIB, template, message, moduleNameUTF, J9UTF8_LENGTH(jrtURL), J9UTF8_DATA(jrtURL)); - - if (moduleNameUTF != moduleNameBuf) { - j9mem_free_memory((void *)moduleNameUTF); + J9UTF8 *moduleName = module->moduleName; + if (NULL != moduleName) { + j9tty_printf( + PORTLIB, template, message, + (const char *)J9UTF8_DATA(moduleName), J9UTF8_LENGTH(jrtURL), J9UTF8_DATA(jrtURL)); } } diff --git a/runtime/vm/JFRConstantPoolTypes.cpp b/runtime/vm/JFRConstantPoolTypes.cpp index 5d3f6090a8a..d21b1777105 100644 --- a/runtime/vm/JFRConstantPoolTypes.cpp +++ b/runtime/vm/JFRConstantPoolTypes.cpp @@ -560,7 +560,7 @@ VM_JFRConstantPoolTypes::addModuleEntry(J9Module *module) entry = &entryBuffer; } - entry->nameStringIndex = addStringEntry(entry->module->moduleName); + entry->nameStringIndex = addStringUTF8Entry(entry->module->moduleName); if (isResultNotOKay()) goto done; entry->versionStringIndex = addStringEntry(entry->module->version); diff --git a/runtime/vm/ModularityHashTables.c b/runtime/vm/ModularityHashTables.c index 8267ac310a5..2e45c19a5ab 100644 --- a/runtime/vm/ModularityHashTables.c +++ b/runtime/vm/ModularityHashTables.c @@ -27,7 +27,6 @@ #include "j9protos.h" #include "ut_j9vm.h" -static j9object_t moduleHashGetName(const void *entry); static UDATA moduleNameHashFn(void *key, void *userData); static UDATA moduleNameHashEqualFn(void *leftKey, void *rightKey, void *userData); static UDATA modulePointerHashFn(void *key, void *userData); @@ -37,39 +36,22 @@ static UDATA packageHashEqualFn(void *leftKey, void *rightKey, void *userData); static UDATA moduleExtraInfoHashFn(void *key, void *userData); static UDATA moduleExtraInfoHashEqualFn(void *tableNode, void *queryNode, void *userData); -static j9object_t -moduleHashGetName(const void *entry) -{ - const J9Module **const modulePtr = (const J9Module **)entry; - const J9Module *const module = *modulePtr; - j9object_t moduleName = module->moduleName; - - return moduleName; -} - static UDATA moduleNameHashFn(void *key, void *userData) { - J9JavaVM *javaVM = (J9JavaVM *)userData; - j9object_t name = moduleHashGetName(key); + J9Module *entry = *(J9Module **)key; - return javaVM->memoryManagerFunctions->j9gc_stringHashFn(&name, userData); + return computeHashForUTF8(J9UTF8_DATA(entry->moduleName), J9UTF8_LENGTH(entry->moduleName)); } static UDATA moduleNameHashEqualFn(void *tableNode, void *queryNode, void *userData) { - J9JavaVM *javaVM = (J9JavaVM *)userData; - - const J9Module *const tableNodeModule = *(J9Module **)tableNode; - j9object_t tableNodeModuleName = tableNodeModule->moduleName; - - const J9Module *const queryNodeModule = *(J9Module **)queryNode; - j9object_t queryNodeModuleName = queryNodeModule->moduleName; - - Assert_VM_true(tableNodeModule->classLoader == queryNodeModule->classLoader); + const J9Module *const tableNodeModuleName = *(J9Module **)tableNode; + const J9Module *const queryNodeModuleName = *(J9Module **)queryNode; - return javaVM->memoryManagerFunctions->j9gc_stringHashEqualFn(&tableNodeModuleName, &queryNodeModuleName, userData); + return J9UTF8_EQUALS(tableNodeModuleName->moduleName, queryNodeModuleName->moduleName) + && (tableNodeModuleName->classLoader == queryNodeModuleName->classLoader); } static UDATA diff --git a/runtime/vm/classsupport.c b/runtime/vm/classsupport.c index e5ee014aaa6..c3f599617c0 100644 --- a/runtime/vm/classsupport.c +++ b/runtime/vm/classsupport.c @@ -343,6 +343,7 @@ internalFindClassString(J9VMThread* currentThread, j9object_t moduleName, j9obje U_8 *utf8Name = NULL; UDATA utf8Length = 0; UDATA stringFlags = J9_STR_NULL_TERMINATE_RESULT; + J9InternalVMFunctions const *const vmFuncs = vm->internalVMFunctions; PORT_ACCESS_FROM_JAVAVM(vm); if (CLASSNAME_INVALID == allowedBitsForClassName) { @@ -378,15 +379,23 @@ internalFindClassString(J9VMThread* currentThread, j9object_t moduleName, j9obje J9Module module = {0}; J9Module *modulePtr = &module; - modulePtr->moduleName = moduleName; + J9UTF8 *moduleNameJ9UTF8 = vmFuncs->copyStringToJ9UTF8WithMemAlloc( + currentThread, moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, NULL, 0); + if (NULL == moduleNameJ9UTF8) { + vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0); + goto done; + } + modulePtr->moduleName = moduleNameJ9UTF8; findResult = hashTableFind(classLoader->moduleHashTable, &modulePtr); if (NULL != findResult) { j9module = *findResult; } + j9mem_free_memory(moduleNameJ9UTF8); } result = internalFindClassInModule(currentThread, j9module, utf8Name, utf8Length, classLoader, options); } +done: if (utf8Name != localBuf) { j9mem_free_memory(utf8Name); } diff --git a/runtime/vm/createramclass.cpp b/runtime/vm/createramclass.cpp index 9a3bdec8b4a..389450d457e 100644 --- a/runtime/vm/createramclass.cpp +++ b/runtime/vm/createramclass.cpp @@ -2467,29 +2467,27 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader { J9JavaVM *javaVM = vmThread->javaVM; J9InternalVMFunctions const * const vmFuncs = javaVM->internalVMFunctions; - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleNameUTF = NULL; + const char *moduleNameUTF = NULL; char classLoaderNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; char *classLoaderNameUTF = NULL; + PORT_ACCESS_FROM_VMC(vmThread); if (javaVM->unnamedModuleForSystemLoader == ramClass->module) { #define SYSTEMLOADER_UNNAMED_NAMED_MODULE "unnamed module for system loader" - memcpy(moduleNameBuf, SYSTEMLOADER_UNNAMED_NAMED_MODULE, sizeof(SYSTEMLOADER_UNNAMED_NAMED_MODULE)); + moduleNameUTF = SYSTEMLOADER_UNNAMED_NAMED_MODULE; #undef SYSTEMLOADER_UNNAMED_NAMED_MODULE - moduleNameUTF = moduleNameBuf; } else if (javaVM->javaBaseModule == ramClass->module) { #define JAVABASE_MODULE "java.base module" - memcpy(moduleNameBuf, JAVABASE_MODULE, sizeof(JAVABASE_MODULE)); + moduleNameUTF = JAVABASE_MODULE; #undef JAVABASE_MODULE - moduleNameUTF = moduleNameBuf; } else if (NULL == ramClass->module) { #define UNNAMED_NAMED_MODULE "unnamed module" - memcpy(moduleNameBuf, UNNAMED_NAMED_MODULE, sizeof(UNNAMED_NAMED_MODULE)); + moduleNameUTF = UNNAMED_NAMED_MODULE; #undef UNNAMED_NAMED_MODULE - moduleNameUTF = moduleNameBuf; } else { - moduleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( - vmThread, ramClass->module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); + J9UTF8 *moduleName = ramClass->module->moduleName; + Assert_VM_true(NULL != moduleName); + moduleNameUTF = (const char *)J9UTF8_DATA(moduleName); } j9object_t classLoaderName = NULL; if (NULL != classLoader->classLoaderObject) { @@ -2507,12 +2505,7 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader if ((NULL != classLoaderNameUTF) && (NULL != moduleNameUTF)) { Trc_MODULE_setPackage(vmThread, J9UTF8_LENGTH(className), J9UTF8_DATA(className), classLoaderNameUTF, classLoader, moduleNameUTF, ramClass->module); } - if (moduleNameBuf != moduleNameUTF) { - PORT_ACCESS_FROM_VMC(vmThread); - j9mem_free_memory(moduleNameUTF); - } if (classLoaderNameBuf != classLoaderNameUTF) { - PORT_ACCESS_FROM_VMC(vmThread); j9mem_free_memory(classLoaderNameUTF); } } diff --git a/runtime/vm/exceptiondescribe.c b/runtime/vm/exceptiondescribe.c index 33882528afa..1ff39fd6412 100644 --- a/runtime/vm/exceptiondescribe.c +++ b/runtime/vm/exceptiondescribe.c @@ -121,9 +121,7 @@ printStackTraceEntry(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeO UDATA sourceFileNameLen = 0; char *moduleNameUTF = NULL; char *moduleVersionUTF = NULL; - char nameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; char versionBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - BOOLEAN freeModuleName = FALSE; BOOLEAN freeModuleVersion = FALSE; if (JAVA_SPEC_VERSION >= 11) { @@ -138,10 +136,9 @@ printStackTraceEntry(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeO if (NULL != module) { if (module != vm->javaBaseModule) { - moduleNameUTF = copyStringToUTF8WithMemAlloc( - vmThread, module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, nameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (nameBuf != moduleNameUTF) { - freeModuleName = TRUE; + J9UTF8 *moduleName = module->moduleName; + if (NULL != moduleName) { + moduleNameUTF = (char *)J9UTF8_DATA(moduleName); } } else { moduleNameUTF = JAVA_BASE_MODULE; @@ -212,9 +209,6 @@ printStackTraceEntry(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeO if (freeModuleVersion) { j9mem_free_memory(moduleVersionUTF); } - if (freeModuleName) { - j9mem_free_memory(moduleNameUTF); - } } return TRUE; diff --git a/runtime/vm/intfunc.c b/runtime/vm/intfunc.c index 5638082f8be..a83992522a8 100644 --- a/runtime/vm/intfunc.c +++ b/runtime/vm/intfunc.c @@ -64,6 +64,8 @@ J9InternalVMFunctions J9InternalFunctions = { javaThreadProc, copyStringToUTF8WithMemAlloc, copyStringToJ9UTF8WithMemAlloc, + copyJ9UTF8ToUTF8WithMemAlloc, + copyJ9UTF8WithMemAlloc, internalAcquireVMAccess, internalAcquireVMAccessWithMask, internalAcquireVMAccessNoMutexWithMask, diff --git a/runtime/vm/jvmfree.c b/runtime/vm/jvmfree.c index 560c2ecfcde..f6d30daabe6 100644 --- a/runtime/vm/jvmfree.c +++ b/runtime/vm/jvmfree.c @@ -322,15 +322,9 @@ static void trcModulesFreeJ9ModuleEntry(J9JavaVM *javaVM, J9Module *j9module) { J9VMThread *currentThread = javaVM->mainThread; - PORT_ACCESS_FROM_VMC(currentThread); - char moduleNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; - char *moduleNameUTF = copyStringToUTF8WithMemAlloc( - currentThread, j9module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, moduleNameBuf, J9VM_PACKAGE_NAME_BUFFER_LENGTH, NULL); - if (NULL != moduleNameUTF) { - Trc_MODULE_freeJ9ModuleV2_entry(currentThread, moduleNameUTF, j9module); - if (moduleNameBuf != moduleNameUTF) { - j9mem_free_memory(moduleNameUTF); - } + J9UTF8 *moduleName = j9module->moduleName; + if (NULL != moduleName) { + Trc_MODULE_freeJ9ModuleV2_entry(currentThread, (const char *)J9UTF8_DATA(moduleName), j9module); } } @@ -375,6 +369,11 @@ freeJ9Module(J9JavaVM *javaVM, J9Module *j9module) { hashTableFree(j9module->removeExportsHashTable); } + if (NULL != j9module->moduleName) { + PORT_ACCESS_FROM_JAVAVM(javaVM); + j9mem_free_memory((void *)j9module->moduleName); + } + pool_removeElement(javaVM->modularityPool, j9module); Trc_MODULE_freeJ9Module_exit(j9module); diff --git a/runtime/vm/lookupmethod.c b/runtime/vm/lookupmethod.c index e80ce48889d..58358cbdc73 100644 --- a/runtime/vm/lookupmethod.c +++ b/runtime/vm/lookupmethod.c @@ -997,9 +997,10 @@ defaultMethodConflictExceptionMessage(J9VMThread *currentThread, J9Class *target * @return a char pointer to the module name */ static char * -getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffer, UDATA bufferLength) +getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffer, UDATA bufferLength) { - J9JavaVM const * const vm = currentThread->javaVM; + J9JavaVM const *const vm = currentThread->javaVM; + J9InternalVMFunctions const *const vmFuncs = vm->internalVMFunctions; J9Module *module = J9OBJECT_ADDRESS_LOAD(currentThread, moduleObject, vm->modulePointerOffset); char *nameBuffer = NULL; @@ -1012,9 +1013,10 @@ getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffe nameBuffer = buffer; #undef UNNAMED_MODULE } else { - nameBuffer = copyStringToUTF8WithMemAlloc( - currentThread, module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, buffer, bufferLength, NULL); + nameBuffer = vmFuncs->copyJ9UTF8ToUTF8WithMemAlloc( + currentThread, module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0,buffer, bufferLength); } + return nameBuffer; } #endif /* JAVA_SPEC_VERSION >= 11 */ diff --git a/runtime/vm/stringhelpers.cpp b/runtime/vm/stringhelpers.cpp index 07471df634a..4d342f39edb 100644 --- a/runtime/vm/stringhelpers.cpp +++ b/runtime/vm/stringhelpers.cpp @@ -410,6 +410,80 @@ copyStringToJ9UTF8WithMemAlloc(J9VMThread *vmThread, j9object_t string, UDATA st return (J9UTF8 *)result; } +char * +copyJ9UTF8ToUTF8WithMemAlloc(J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength) +{ + Assert_VM_notNull(prependStr); + Assert_VM_notNull(string); + + U_8 *result = NULL; + PORT_ACCESS_FROM_VMC(vmThread); + + const U_8 *stringData = J9UTF8_DATA(string); + const UDATA stringLength = (UDATA)J9UTF8_LENGTH(string); + UDATA allocationSize = prependStrLength + stringLength; + + if (J9_ARE_ALL_BITS_SET(stringFlags, J9_STR_NULL_TERMINATE_RESULT)) { + allocationSize += 1; + } + + if (stringLength < bufferLength) { + result = (U_8 *)buffer; + } else { + result = (U_8 *)j9mem_allocate_memory(allocationSize, OMRMEM_CATEGORY_VM); + } + + if (NULL != result) { + if (prependStrLength > 0) { + memcpy(result, prependStr, prependStrLength); + } + memcpy(result + prependStrLength, stringData, stringLength); + if (J9_ARE_ALL_BITS_SET(stringFlags, J9_STR_NULL_TERMINATE_RESULT)) { + result[allocationSize - 1] = '\0'; + } + } + + return (char *)result; +} + +J9UTF8 * +copyJ9UTF8WithMemAlloc(J9VMThread *vmThread, J9UTF8 *string, UDATA stringFlags, const char *prependStr, UDATA prependStrLength, char *buffer, UDATA bufferLength) +{ + Assert_VM_notNull(prependStr); + Assert_VM_notNull(string); + + J9UTF8 *result = NULL; + PORT_ACCESS_FROM_VMC(vmThread); + + const U_8 *stringData = J9UTF8_DATA(string); + const UDATA stringLength = (UDATA)J9UTF8_LENGTH(string); + const UDATA totalStringLength = prependStrLength + stringLength; + UDATA allocationSize = totalStringLength + sizeof(J9UTF8); + + if (J9_ARE_ALL_BITS_SET(stringFlags, J9_STR_NULL_TERMINATE_RESULT)) { + allocationSize += 1; + } + + if (allocationSize <= bufferLength) { + result = (J9UTF8 *)buffer; + } else { + result = (J9UTF8 *)j9mem_allocate_memory(allocationSize, OMRMEM_CATEGORY_VM); + } + + if (NULL != result) { + if (prependStrLength > 0) { + memcpy(J9UTF8_DATA(result), prependStr, prependStrLength); + } + memcpy(J9UTF8_DATA(result) + prependStrLength, stringData, stringLength); + if (J9_ARE_ALL_BITS_SET(stringFlags, J9_STR_NULL_TERMINATE_RESULT)) { + J9UTF8_DATA(result)[totalStringLength] = '\0'; + } + J9UTF8_SET_LENGTH(result, totalStringLength); + } + + return result; +} + UDATA getStringUTF8Length(J9VMThread *vmThread, j9object_t string) {