Index: /trunk/openjdk/jdk/make/common/Library.gmk
===================================================================
--- /trunk/openjdk/jdk/make/common/Library.gmk	(revision 273)
+++ /trunk/openjdk/jdk/make/common/Library.gmk	(revision 274)
@@ -340,4 +340,6 @@
 OTHER_INCLUDES += -I$(PLATFORM_SRC_OS2)/native/common
 OTHER_INCLUDES += -I$(PLATFORM_SRC_OS2)/native/$(PKGDIR)
+# path to common code used by many DLLs
+vpath %.cpp $(PLATFORM_SRC_OS2)/native/common
 endif
 
Index: /trunk/openjdk/jdk/make/javax/sound/FILES_c.gmk
===================================================================
--- /trunk/openjdk/jdk/make/javax/sound/FILES_c.gmk	(revision 273)
+++ /trunk/openjdk/jdk/make/javax/sound/FILES_c.gmk	(revision 274)
@@ -33,5 +33,5 @@
 	PLATFORM_API_SolarisOS_PCM.c
 
-FILES_linux = 
+FILES_linux =
 
 FILES_windows = \
@@ -46,5 +46,10 @@
 	PLATFORM_API_WinOS_Util.c \
 	PLATFORM_API_WinOS_Ports.c
-	
+
+ifeq ($(PLATFORM), os2)
+FILES_cpp += \
+	jdk_DllMain.cpp
+endif
+
 FILES_export = \
 	com/sun/media/sound/Platform.java
Index: /trunk/openjdk/jdk/make/javax/sound/jsoundds/Makefile
===================================================================
--- /trunk/openjdk/jdk/make/javax/sound/jsoundds/Makefile	(revision 273)
+++ /trunk/openjdk/jdk/make/javax/sound/jsoundds/Makefile	(revision 274)
@@ -47,4 +47,9 @@
 	PLATFORM_API_WinOS_DirectSound.cpp
 
+ifeq ($(PLATFORM), os2)
+FILES_cpp += \
+	jdk_DllMain.cpp
+endif
+
 FILES_export = \
 	$(DAUDIOFILES_export)
Index: /trunk/openjdk/jdk/make/sun/awt/Makefile
===================================================================
--- /trunk/openjdk/jdk/make/sun/awt/Makefile	(revision 273)
+++ /trunk/openjdk/jdk/make/sun/awt/Makefile	(revision 274)
@@ -94,5 +94,5 @@
 include FILES_export_windows.gmk
 
-FILES_c += awt_init.c
+FILES_cpp += jdk_DllMain.cpp
 
 #
Index: /trunk/openjdk/jdk/src/os2/native/common/jdk_DllMain.cpp
===================================================================
--- /trunk/openjdk/jdk/src/os2/native/common/jdk_DllMain.cpp	(revision 274)
+++ /trunk/openjdk/jdk/src/os2/native/common/jdk_DllMain.cpp	(revision 274)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2010-2011 netlabs.org. OS/2 Parts.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// This code performs C++ runtime termination to make sure that the
+// destructors of static objects are destroyed before Odin unloads itself
+// at program termination. This is achieved by registering the DLL with Odin
+// which makes sure it calls the supplied DllMain() routine at the right
+// time. Note that using DosExitList() for this purpose is not a good idea
+// because some Odin services still needed by the destructor code of some JDK
+// classes may already be down when exit list routines are run.
+
+#define INCL_DOSPROCESS
+#include <os2wrap.h> // Odin32 OS/2 api wrappers
+#include <odinlx.h>
+#include <misc.h>
+
+#include <emx/startup.h>
+
+static HMODULE dllHandle = 0;
+
+BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
+{
+    // call destructors when detaching the DLL from the process
+    if (reason == 0)
+        __ctordtorTerm();
+
+    return TRUE;
+}
+
+unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long ulFlag)
+{
+    // If ulFlag is zero then the DLL is being loaded so initialization should
+    // be performed.  If ulFlag is 1 then the DLL is being freed so termination
+    // should be performed. A non-zero value must be returned to indicate success.
+
+    // Note that we don't perform CRT initialization and things because this
+    // is done in os_os2_init.cpp of JVM.DLL that is always loaded first
+
+    switch (ulFlag) {
+        case 0 :
+            dllHandle = RegisterLxDll(hModule, DllMain, NULL,
+                                      ODINNT_MAJOR_VERSION,
+                                      ODINNT_MINOR_VERSION,
+                                      IMAGE_SUBSYSTEM_WINDOWS_CUI);
+            if (dllHandle == 0)
+                break;
+
+            __ctordtorInit();
+
+            return 1;
+
+        case 1 :
+            if (dllHandle)
+                UnregisterLxDll(dllHandle);
+            return 1;
+
+        default:
+            break;
+    }
+
+    // failure
+    return 0;
+}
Index: unk/openjdk/jdk/src/os2/native/sun/os2/awt_init.cpp
===================================================================
--- /trunk/openjdk/jdk/src/os2/native/sun/os2/awt_init.cpp	(revision 273)
+++ 	(revision )
@@ -1,94 +1,0 @@
-/*
- * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2010 netlabs.org. OS/2 Parts.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-// This code performs C++ runtime initialization and registers the DLL
-// with Odin
-
-#define INCL_DOSPROCESS
-#include <os2wrap.h> // Odin32 OS/2 api wrappers
-#include <odinlx.h>
-#include <misc.h>
-#include <exitlist.h>
-
-//#include <types.h>
-//#include <stdio.h>
-
-#include <emx/startup.h>
-
-static void APIENTRY cleanup(ULONG reason);
-
-static HMODULE dllHandle = 0;
-
-unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long ulFlag)
-{
-    APIRET rc;
-
-    // If ulFlag is zero then the DLL is being loaded so initialization should
-    // be performed.  If ulFlag is 1 then the DLL is being freed so termination
-    // should be performed. A non-zero value must be returned to indicate success.
-
-    // Note that we don't perform CRT initialization and things because this
-    // is done in os_os2_init.cpp of JVM.DLL that is already loaded
-
-    switch (ulFlag) {
-        case 0 :
-            dllHandle = RegisterLxDll(hModule, NULL, NULL,
-                                      ODINNT_MAJOR_VERSION,
-                                      ODINNT_MINOR_VERSION,
-                                      IMAGE_SUBSYSTEM_WINDOWS_CUI);
-            if (dllHandle == 0)
-                break;
-
-            __ctordtorInit();
-
-            rc = DosExitList(EXITLIST_APPDLL|EXLST_ADD, cleanup);
-            if (rc)
-                break;
-
-            return 1;
-
-        case 1 :
-            if (dllHandle) {
-                UnregisterLxDll(dllHandle);
-            }
-            return 1;
-
-        default:
-            break;
-    }
-
-    // failure
-    return 0;
-}
-
-static void APIENTRY cleanup(ULONG /*ulReason*/)
-{
-   __ctordtorTerm();
-   DosExitList(EXLST_EXIT, cleanup);
-   return ;
-}
-
