@@ -93,6 +93,7 @@ void verifiesReadWriteLockBehavior(CompilerHelper.CompilerConfig config) throws
9393 Path srcRoot = distDir .resolve ("ReadWriteLockTestApp-src" );
9494 CleanTargetIntegrationTest .patchCn1Globals (srcRoot );
9595 CleanTargetIntegrationTest .patchFileHeader (srcRoot );
96+ patchHashMapNativeSupport (srcRoot );
9697 writeRuntimeStubs (srcRoot );
9798
9899 replaceLibraryWithExecutableTarget (cmakeLists , srcRoot .getFileName ().toString ());
@@ -836,4 +837,57 @@ private void writeRuntimeStubs(Path srcRoot) throws java.io.IOException {
836837
837838 Files .write (stubs , content .getBytes (StandardCharsets .UTF_8 ));
838839 }
840+
841+ private void patchHashMapNativeSupport (Path srcRoot ) throws java .io .IOException {
842+ Path hashMapHeader = srcRoot .resolve ("java_util_HashMap.h" );
843+ if (Files .exists (hashMapHeader )) {
844+ String content = new String (Files .readAllBytes (hashMapHeader ), StandardCharsets .UTF_8 );
845+ if (!content .contains ("java_util_HashMap_elementData" )) {
846+ String structDef = "struct obj__java_util_HashMap {\n " +
847+ " DEBUG_GC_VARIABLES\n " +
848+ " struct clazz *__codenameOneParentClsReference;\n " +
849+ " int __codenameOneReferenceCount;\n " +
850+ " void* __codenameOneThreadData;\n " +
851+ " int __codenameOneGcMark;\n " +
852+ " void* __ownerThread;\n " +
853+ " int __heapPosition;\n " +
854+ " JAVA_OBJECT java_util_HashMap_elementData;\n " +
855+ "};" ;
856+ content = content .replace ("struct obj__java_util_HashMap {\n " +
857+ " DEBUG_GC_VARIABLES\n " +
858+ " struct clazz *__codenameOneParentClsReference;\n " +
859+ " int __codenameOneReferenceCount;\n " +
860+ " void* __codenameOneThreadData;\n " +
861+ " int __codenameOneGcMark;\n " +
862+ " void* __ownerThread;\n " +
863+ " int __heapPosition;\n " +
864+ "};" , structDef );
865+ Files .write (hashMapHeader , content .getBytes (StandardCharsets .UTF_8 ));
866+ }
867+ }
868+
869+ Path entryHeader = srcRoot .resolve ("java_util_HashMap_Entry.h" );
870+ if (!Files .exists (entryHeader )) {
871+ String entryContent = "#ifndef __JAVA_UTIL_HASHMAP_ENTRY__\n " +
872+ "#define __JAVA_UTIL_HASHMAP_ENTRY__\n \n " +
873+ "#include \" cn1_globals.h\" \n " +
874+ "#include \" java_lang_Object.h\" \n \n " +
875+ "extern struct clazz class__java_util_HashMap_Entry;\n \n " +
876+ "struct obj__java_util_HashMap_Entry {\n " +
877+ " DEBUG_GC_VARIABLES\n " +
878+ " struct clazz *__codenameOneParentClsReference;\n " +
879+ " int __codenameOneReferenceCount;\n " +
880+ " void* __codenameOneThreadData;\n " +
881+ " int __codenameOneGcMark;\n " +
882+ " void* __ownerThread;\n " +
883+ " int __heapPosition;\n " +
884+ " JAVA_OBJECT java_util_MapEntry_key;\n " +
885+ " JAVA_OBJECT java_util_MapEntry_value;\n " +
886+ " JAVA_INT java_util_HashMap_Entry_origKeyHash;\n " +
887+ " JAVA_OBJECT java_util_HashMap_Entry_next;\n " +
888+ "};\n \n " +
889+ "#endif\n " ;
890+ Files .write (entryHeader , entryContent .getBytes (StandardCharsets .UTF_8 ));
891+ }
892+ }
839893}
0 commit comments