changeset 4676:6b4f3fb8e218

7124089: (launcher) refactor the launcher code for macosx Reviewed-by: anthony, darcy, dholmes, ohair
author ksrini
date Tue, 24 Jan 2012 10:42:17 -0800
parents 61c4a65004c1
children 9d6057281172
files make/common/Program.gmk make/common/Release.gmk make/java/jli/Makefile src/macosx/bin/java_md_macosx.c src/macosx/bin/java_md_macosx.h src/macosx/bin/jexec.c src/macosx/bin/universal/jvm.cfg src/macosx/lib/Info-cmdline.plist src/macosx/lib/Info-privileged.plist src/share/bin/java.c src/share/bin/java.h src/solaris/bin/ergo.c src/solaris/bin/ergo.h src/solaris/bin/ergo_i586.c src/solaris/bin/java_md.c src/solaris/bin/java_md.h src/solaris/bin/java_md_common.c src/solaris/bin/java_md_solinux.c src/solaris/bin/java_md_solinux.h src/solaris/bin/universal/jvm.cfg src/solaris/lib/Info-cmdline.plist src/solaris/lib/Info-privileged.plist src/windows/bin/java_md.c test/tools/launcher/Test7029048.java test/tools/launcher/TestSpecialArgs.java
diffstat 25 files changed, 3462 insertions(+), 2489 deletions(-) [+]
line wrap: on
line diff
--- a/make/common/Program.gmk	Tue Jan 24 16:18:59 2012 +0000
+++ b/make/common/Program.gmk	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1995, 2012, 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
@@ -38,12 +38,18 @@
   override COMPILE_APPROACH = normal
 endif
 
-ifndef LAUNCHER_PLATFORM_SRC
-LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)
-endif
+# set the platform specific directory for macosx, also this platform shares
+# substantial family ties with its siblings (solaris and linux), thus we add
+# solaris src path to its compilation dependencies.
+ifeq ($(PLATFORM), macosx)
+  LAUNCHER_PLATFORM_SRC = $(BUILDDIR)/../src/macosx
+  LAUNCHER_SOLARIS_PLATFORM_SRC  = $(BUILDDIR)/../src/solaris
+else # ! MACOSX
+  LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)
+endif # MACOSX  
 
 ifndef LAUNCHER_SHARE_SRC
-LAUNCHER_SHARE_SRC = $(SHARE_SRC)
+  LAUNCHER_SHARE_SRC = $(SHARE_SRC)
 endif
 
 ACTUAL_PROGRAM_NAME = $(PROGRAM)$(EXE_SUFFIX)
@@ -66,7 +72,7 @@
 include $(JDK_TOPDIR)/make/common/Rules.gmk
 
 ifdef NEVER_ACT_AS_SERVER_CLASS_MACHINE
-OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE
+  OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE
 endif
 
 #
@@ -81,48 +87,48 @@
 ifeq ($(PLATFORM), macosx)
   ifneq ($(ARCH), universal)
     LDFLAGS += -Wl,-all_load
-  endif
+  endif # ARCH
   LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
 
   ifeq ($(SYSTEM_ZLIB),true)
     OTHER_LDLIBS += -lz
-  endif
-endif
+  endif # SYSTEM_ZLIB
+endif # PLATFORM
 
-ifneq (,$(findstring $(PLATFORM), linux solaris))	# UNIX systems
-    LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
-    OTHER_LDLIBS += -ljli
-    ifeq ($(PLATFORM), solaris)
-	ifeq ($(ARCH_DATA_MODEL), 32)
-		LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
-		LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
-	else
-		LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
-		LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
-	endif
-    endif
-    ifeq ($(PLATFORM), linux)
-	LDFLAGS += $(LDFLAG_Z_ORIGIN)
-	LDFLAGS += -Wl,--allow-shlib-undefined
-	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
-	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
-    endif
-endif
+ifneq (,$(findstring $(PLATFORM), linux solaris)) # UNIX systems
+  LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
+  OTHER_LDLIBS += -ljli
+  ifeq ($(PLATFORM), solaris)
+    ifeq ($(ARCH_DATA_MODEL), 32)
+      LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
+      LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
+    else # ! ARCH_DATA_MODEL 64-bit
+      LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
+      LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
+    endif # ARCH_DATA_MODEL
+  endif # PLATFORM SOLARIS
+  ifeq ($(PLATFORM), linux)
+    LDFLAGS += $(LDFLAG_Z_ORIGIN)
+    LDFLAGS += -Wl,--allow-shlib-undefined
+    LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
+    LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
+  endif # PLATFORM LINUX
+endif # PLATFORM linux solaris
+
 ifeq ($(PLATFORM), windows)
-	JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
-	ifdef STATIC_JLI
-	    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
-	else
-	    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
-	endif
-	OTHER_LDLIBS += jli.lib
-endif
+  JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
+  ifdef STATIC_JLI
+    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
+  else # !STATIC_JLI
+    LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
+  endif # STATIC_JLI
+  OTHER_LDLIBS += jli.lib
+endif # PLATFORM
 
 #
 # Launcher specific files.
 #
-FILES_o = \
-	$(OBJDIR)/main.$(OBJECT_SUFFIX)
+FILES_o = $(OBJDIR)/main.$(OBJECT_SUFFIX)
 
 $(ACTUAL_PROGRAM):: classes $(INIT) 
 
@@ -130,101 +136,98 @@
 # Windows only
 #
 ifeq ($(PLATFORM), windows)
+  # JDK name required here
+  RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
+              /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
+              /D "JDK_FTYPE=0x1L"
 
-# JDK name required here
-RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
-	    /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
-	    /D "JDK_FTYPE=0x1L"
+  $(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
+	@$(prep-target)
+  ifndef LOCAL_RESOURCE_FILE
+	$(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
+  endif # LOCAL_RESOURCE_FILE
 
-$(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
-	@$(prep-target)
-ifndef LOCAL_RESOURCE_FILE
-	$(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
-endif
-
-$(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
+  $(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
 	@$(prep-target)
 	@$(ECHO) $(FILES_o) > $@ 
   ifndef LOCAL_RESOURCE_FILE
 	@$(ECHO) $(OBJDIR)/$(PROGRAM).res >> $@
-  endif
+  endif # LOCAL_RESOURCE_FILE
 	@$(ECHO) setargv.obj >> $@
 	@$(ECHO) Created $@ 
 
-$(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
+  $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 	@$(install-file)
 
-ifeq ($(ARCH_DATA_MODEL), 32)
-  STACK_SIZE=327680
-else
-# We need more Stack for Windows 64bit
-  STACK_SIZE=1048576
-endif
+  ifeq ($(ARCH_DATA_MODEL), 32)
+    STACK_SIZE=327680
+  else # !32 BIT
+    # We need more Stack for Windows 64bit
+    STACK_SIZE=1048576
+  endif # ARCH_DATA_MODEL
 
-IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
-$(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
+  IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
+  $(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
 	@$(prep-target)
 	$(SED) 's%IMVERSION%$(IMVERSION)%g;s%PROGRAM%$(PROGRAM)%g' $< > $@
 
-# We used a hand-crafted manifest file for all executables.
-# It is tweaked to embed the build number and executable name.
-# Use ";#2" for .dll and ";#1" for .exe in the MT command below:
-$(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
+  # We used a hand-crafted manifest file for all executables.
+  # It is tweaked to embed the build number and executable name.
+  # Use ";#2" for .dll and ";#1" for .exe in the MT command below:
+  $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
 	@$(prep-target)
 	@set -- $?; \
 	    $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 	$(LINK) -out:$@ /STACK:$(STACK_SIZE) \
 	    -map:$(OBJDIR)/$(PROGRAM).map $(LFLAGS) $(LDFLAGS) \
 	    @$(OBJDIR)/$(PROGRAM).lcf $(LDLIBS)
-ifdef MT
+  ifdef MT
 	$(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1
-endif
+  endif # MT
 	@$(call binary_file_verification,$@)
+else # *NIXES
+  #
+  # Note that we have to link -lthread even when USE_PTHREADS is true.
+  # This is becuase checkForCorrectLibthread() croaks otherwise.
+  #
+  LIBTHREAD = -lthread
+  ifeq ($(USE_PTHREADS),true)
+    THREADLIBS = -lpthread $(LIBTHREAD)
+  else # !USE_PTHREADS
+    THREADLIBS = $(LIBTHREAD)
+  endif # USE_PTHREADS
 
-else # PLATFORM
+  ifeq ($(PLATFORM), macosx)
+    THREADLIBS = -pthread
+    # Needed for linking the various launchers
+    LDFLAGS += -framework Cocoa -framework Security \
+               -framework ApplicationServices
+    OTHER_CPPFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"'
 
-#
-# Note that we have to link -lthread even when USE_PTHREADS is true.
-# This is becuase checkForCorrectLibthread() croaks otherwise.
-#
-LIBTHREAD = -lthread
-ifeq ($(USE_PTHREADS),true)
-  THREADLIBS = -lpthread $(LIBTHREAD)
-else # USE_PTHREADS
-  THREADLIBS = $(LIBTHREAD)
-endif # USE_PTHREADS
+    # Default Info.plist file for the command line tools. This gets overridden by
+    # some of the jvmstat tools so that they have task_for_pid() privileges
+    ifndef INFO_PLIST_FILE
+      INFO_PLIST_FILE = Info-cmdline.plist
+    endif # INFO_PLIST_FILE 
+    LDFLAGS += -sectcreate __TEXT __info_plist $(LAUNCHER_PLATFORM_SRC)/lib/$(INFO_PLIST_FILE)
+  else # SOLARIS/LINUX
+    INFO_PLIST_FILE=
+  endif # MACOSX
 
-ifeq ($(PLATFORM), macosx)
-THREADLIBS = -pthread
-# Needed for linking the various launchers
-LDFLAGS += -framework Cocoa -framework Security -framework ApplicationServices
-
-# Default Info.plist file for the command line tools. This gets overridden by
-# some of the jvmstat tools so that they have task_for_pid() privileges
-ifndef INFO_PLIST_FILE
-    INFO_PLIST_FILE=Info-cmdline.plist
-endif
-
-LDFLAGS += -sectcreate __TEXT __info_plist $(LAUNCHER_PLATFORM_SRC)/lib/$(INFO_PLIST_FILE)
-else # macosx
-INFO_PLIST_FILE=
-endif # macosx
-
-#
-# This rule only applies on unix.  It supports quantify and its ilk.
-#
-$(ACTUAL_PROGRAM):: $(FILES_o)
+  #
+  # This rule only applies on unix.  It supports quantify and its ilk.
+  #
+  $(ACTUAL_PROGRAM):: $(FILES_o)
 	@$(prep-target)
 	@set -- $?; \
-	    $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
+	$(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 	@$(MKDIR) -p $(TEMPDIR)
 	$(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \
-	    $(FILES_o) $(THREADLIBS) $(LDLIBS)
-ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged)
+	$(FILES_o) $(THREADLIBS) $(LDLIBS)
+  ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged)
 	-codesign -s openjdk_codesign $@
-endif
+  endif # INFO_PLIST_FILE
 	@$(call binary_file_verification,$@)
-
 endif # PLATFORM
 
 clean:: 
@@ -248,48 +251,49 @@
 # Now include make dependencies (created during compilation, see Rules.gmk)
 #
 ifeq ($(INCREMENTAL_BUILD),true)
-# Workaround: gnumake sometimes says files is empty when it shouldn't
-#    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
-files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
-ifneq ($(strip $(files)),)
-include $(files)
-endif # files
+  # Workaround: gnumake sometimes says files is empty when it shouldn't
+  #    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
+  files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
+  ifneq ($(strip $(files)),)
+    include $(files)
+  endif # files
 endif # INCREMENTAL_BUILD
 
 ifdef JAVA_ARGS
-OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
-OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
-endif
+  OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
+  OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
+endif # JAVA_ARGS
 
 ifeq ($(PLATFORM), windows)
-ifdef RELEASE
-OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
-endif
-endif
+  ifdef RELEASE
+    OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
+  endif #RELEASE
+endif #PLATFORM
 
 
 ifneq ($(PLATFORM), windows)
-HAVE_GETHRTIME=true
-endif
+  HAVE_GETHRTIME=true
+endif #PLATFORM
 
 ifeq ($(HAVE_GETHRTIME),true)
-OTHER_CPPFLAGS += -DHAVE_GETHRTIME
+  OTHER_CPPFLAGS += -DHAVE_GETHRTIME
 endif
 
 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
 ifeq ($(PLATFORM), macosx)
+  OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)/bin
   ifneq ($(SYSTEM_ZLIB), true)
     OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
-  endif
-else 
+  endif # SYSTEM_ZLIB
+else # PLATFORM !MACOSX
   OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
 endif
 
-OTHER_CPPFLAGS += -DPROGNAME='"$(PROGRAM)"'
+OTHER_CPPFLAGS  += -DPROGNAME='"$(PROGRAM)"'
 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
 
 VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
-		   -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
+                   -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
 
 
 
--- a/make/common/Release.gmk	Tue Jan 24 16:18:59 2012 +0000
+++ b/make/common/Release.gmk	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1997, 2012, 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
@@ -940,6 +940,10 @@
 	$(RM) $(JDK_IMAGE_DIR)/db/index.html $(JDK_IMAGE_DIR)/db/register.html
 endif
 
+# The launcher source files we need for src.zip
+FILES_launcher = $(wildcard $(SHARE_SRC)/bin/*) \
+                 $(wildcard $(PLATFORM_SRC)/bin/java_md*)
+
 # Standard jdk image
 initial-image-jdk:: initial-image-jdk-setup \
 		    initial-image-jdk-db \
@@ -1065,20 +1069,7 @@
 	$(RM) $(ABS_TEMPDIR)/src-files.list
 	$(CHMOD) -R +w $(JDK_IMAGE_DIR)/src
 	$(MKDIR) -p $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/java.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/java.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/manifest_info.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/parse_manifest.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/version_comp.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/version_comp.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/wildcard.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/wildcard.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/jli_util.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/jli_util.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/splashscreen_stubs.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(SHARE_SRC)/bin/splashscreen.h $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(PLATFORM_SRC)/bin/java_md.c $(JDK_IMAGE_DIR)/src/launcher
-	$(CP) $(PLATFORM_SRC)/bin/java_md.h $(JDK_IMAGE_DIR)/src/launcher
+	$(CP) $(FILES_launcher) $(JDK_IMAGE_DIR)/src/launcher
 	$(CD) $(JDK_IMAGE_DIR)/src && $(ZIPEXE) -qr ../src.zip *
 	$(RM) -r $(JDK_IMAGE_DIR)/src
 	@#
--- a/make/java/jli/Makefile	Tue Jan 24 16:18:59 2012 +0000
+++ b/make/java/jli/Makefile	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2005, 2012, 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
@@ -45,111 +45,120 @@
 include $(BUILDDIR)/common/Defs.gmk
 
 ifneq ($(SYSTEM_ZLIB),true)
-ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
-endif
+  ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
+endif #SYSTEM_ZLIB
 LAUNCHER_SHARE_SRC = $(SHARE_SRC)/bin
-LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
+
+# set the platform specific directory for macosx, also this platform shares
+# substantial family ties with its siblings (solaris and linux), thus we add
+# solaris src path to its compilation dependencies.
+ifeq ($(PLATFORM), macosx)
+ LAUNCHER_PLATFORM_SRC = $(BUILDDIR)/../src/macosx/bin
+ LAUNCHER_SOLARIS_PLATFORM_SRC  = $(BUILDDIR)/../src/solaris/bin
+else # !MACOSX
+ LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
+endif #PLATFORM
 
 ifeq ($(ZERO_BUILD), true)
-ERGO_FAMILY=zero
-else
-ifneq (,$(findstring $(ARCH_FAMILY), amd64 x86_64))
-ERGO_FAMILY=i586
-else
-ERGO_FAMILY=$(ARCH_FAMILY)
-endif
-endif
-
+  ERGO_FAMILY=zero
+else # !ZERO_BUILD
+  ifneq (,$(findstring $(ARCH_FAMILY), amd64 x86_64))
+    ERGO_FAMILY=i586
+  else # !X86 FAMILY
+    ERGO_FAMILY=$(ARCH_FAMILY)
+  endif #ARCH_FAMILY
+endif # ZERO_BUILD
 
 #
 # Files to compile.
 #
-FILES_c = \
-	java.c \
-	splashscreen_stubs.c \
-	java_md.c \
-	parse_manifest.c \
-	version_comp.c \
-	wildcard.c \
-	jli_util.c
+FILES_c = java.c \
+          splashscreen_stubs.c \
+          parse_manifest.c \
+          version_comp.c \
+          wildcard.c \
+          jli_util.c
 
 ifneq ($(SYSTEM_ZLIB),true)
-FILES_c += \
-	inflate.c \
-	inftrees.c \
-	inffast.c \
-	zadler32.c \
-	zcrc32.c \
-	zutil.c
-endif
+  FILES_c += inflate.c \
+             inftrees.c \
+             inffast.c \
+             zadler32.c \
+             zcrc32.c \
+             zutil.c
+endif # SYSTEM_ZLIB
 
-ifneq ($(PLATFORM), windows)
-  FILES_c += ergo.c 
-  ERGO_ARCH_FILE = ergo_$(ERGO_FAMILY).c
-  # if the architecture specific ergo file exists then
-  # use it, else use the generic definitions from ergo.c
-  ifneq ($(wildcard $(LAUNCHER_PLATFORM_SRC)/$(ERGO_ARCH_FILE)),)
-    FILES_c += $(ERGO_ARCH_FILE)
-  else
-    OTHER_CPPFLAGS += -DUSE_GENERIC_ERGO
-  endif
-endif
+# add platform specific files
+ifeq ($(PLATFORM), windows)
+  FILES_c += java_md.c
+else # NIXES
+  FILES_c += java_md_common.c
+  ifeq ($(PLATFORM), macosx)
+    FILES_c += java_md_macosx.c
+  else # SOLARIS/LINUX
+    FILES_c += java_md_solinux.c
+    FILES_c += ergo.c 
+    ERGO_ARCH_FILE = ergo_$(ERGO_FAMILY).c
+    # if the architecture specific ergo file exists then
+    # use it, else use the generic definitions from ergo.c
+    ifneq ($(wildcard $(LAUNCHER_PLATFORM_SRC)/$(ERGO_ARCH_FILE)),)
+      FILES_c += $(ERGO_ARCH_FILE)
+    else # !ERGO_ARCH_FILE
+      OTHER_CPPFLAGS += -DUSE_GENERIC_ERGO
+    endif # ERGO_ARCH_FILE
+  endif #MACOSX
+endif #WINDOWS
 
 # Names of arch directories
 LIBARCH_DEFINES = -DLIBARCHNAME='"$(LIBARCH)"'
 ifeq ($(PLATFORM), solaris)
   LIBARCH_DEFINES += -DLIBARCH32NAME='"$(LIBARCH32)"'
   LIBARCH_DEFINES += -DLIBARCH64NAME='"$(LIBARCH64)"'
-endif
+endif # PLATFORM
 
 ifeq ($(PLATFORM), macosx)
   OTHER_CPPFLAGS += $(LIBARCH_DEFINES) -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
-else
+else # ! MACOSX
   OTHER_CPPFLAGS += $(LIBARCH_DEFINES)
-endif
-
+endif #PLATFORM
 
 ifneq ($(PLATFORM), windows)	# UNIX systems
-ifneq ($(PLATFORM), macosx)
-        LD_RUNPATH_EXTRAS += ..
-	LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/jli
-	# Note: its important to keep this order meaning -lc is the
-	# last library otherwise it could cause compatibility issues
-	# by pulling in SUNW_private symbols from libc
-	LDLIBS = -ldl -lc
-ifeq ($(USE_PTHREADS),true)
-	LDLIBS += -lpthread
-endif # USE_PTHREADS 
-endif # PLATFORM
+  ifeq ($(PLATFORM), macosx)
+    LIB_LOCATION = $(LIBDIR)/jli
+  else # SOLARIS/LINUX
+    LD_RUNPATH_EXTRAS += ..
+    LIB_LOCATION = $(LIBDIR)/$(LIBARCH)/jli
+    # Note: it is important to keep this order, meaning -lc as the
+    # last library, otherwise it could cause compatibility issues
+    # by pulling in SUNW_private symbols from libc
+    LDLIBS = -ldl -lc
+    ifeq ($(USE_PTHREADS),true)
+      LDLIBS += -lpthread
+    endif # USE_PTHREADS 
+  endif # PLATFORM
 endif # PLATFORM
 
-ifeq ($(PLATFORM), macosx)
-	LIB_LOCATION = $(LIBDIR)/jli
-endif
-
 ifeq ($(PLATFORM), windows)
-	EXTRA_LIBS = advapi32.lib \
-		     comctl32.lib \
-		     user32.lib
-
-	JAVALIB =
-	OTHER_LCF =  -export:JLI_Launch \
-		     -export:JLI_ManifestIterate \
-		     -export:JLI_SetTraceLauncher \
-		     -export:JLI_ReportErrorMessage \
-		     -export:JLI_ReportErrorMessageSys \
-		     -export:JLI_ReportMessage \
-		     -export:JLI_ReportExceptionDescription
-
-endif
+  EXTRA_LIBS = advapi32.lib \
+               comctl32.lib \
+               user32.lib
+  JAVALIB =
+  OTHER_LCF = -export:JLI_Launch \
+              -export:JLI_ManifestIterate \
+              -export:JLI_SetTraceLauncher \
+              -export:JLI_ReportErrorMessage \
+              -export:JLI_ReportErrorMessageSys \
+              -export:JLI_ReportMessage \
+              -export:JLI_ReportExceptionDescription
+endif # PLATFORM
 
 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)
 OTHER_INCLUDES += -I$(LAUNCHER_PLATFORM_SRC)
 ifneq ($(SYSTEM_ZLIB),true)
   OTHER_INCLUDES += -I$(ZIP_SRC)
-else
+else # !SYSTEM_ZLIB
   LDLIBS += -lz
-endif
+endif # SYSTEM_ZLIB
 
 #
 # Library to compile.
@@ -170,23 +179,26 @@
 # library.
 #
 ifeq ($(PLATFORM), windows)
+  STATIC_LIBRARY = $(OBJDIR)/static/$(LIBPREFIX)$(LIBRARY).lib
 
-STATIC_LIBRARY = $(OBJDIR)/static/$(LIBPREFIX)$(LIBRARY).lib
-
-$(STATIC_LIBRARY): $(FILES_o)
+  $(STATIC_LIBRARY): $(FILES_o)
 	@$(prep-target)
 	$(LIBEXE) -nologo -out:$@ $(FILES_o)
 
-library:: $(STATIC_LIBRARY)
-
-endif	# PLATFORM
+  library:: $(STATIC_LIBRARY)
+endif # PLATFORM
 
 ifeq ($(PLATFORM), macosx)
-# Some Obj-C code is embedded in java_md.c, so need to inform compiler
-CFLAGS_$(VARIANT)/java_md.o = -Os -x objective-c
-# Needed for linking the various launchers
-LDFLAGS += -framework Cocoa -framework Security -framework ApplicationServices
-endif
+  # Some Obj-C code is embedded in java_md_macosx.c, we stipulate so, using
+  # "-x" option. Not doing so will cause the compiler to choose the language
+  # based on the filename suffix, also "-Os" optimizes the file for size.
+  CFLAGS_$(VARIANT)/java_md_macosx.o = -Os -x objective-c
+  # Needed for linking the various launchers
+  LDFLAGS += -framework Cocoa -framework Security \
+             -framework ApplicationServices
+  # Add solaris sources containing common logic to the header path
+  OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)
+endif # PLATFORM
 
 STATIC_LIBRARY_DIR = $(OBJDIR)/static
 STATIC_LIBRARY_NAME = lib$(LIBRARY).a
@@ -204,10 +216,15 @@
 vpath %.c $(LAUNCHER_SHARE_SRC) $(LAUNCHER_PLATFORM_SRC)
 ifneq ($(SYSTEM_ZLIB),true)
   vpath %.c $(ZIP_SRC)
-
-else 
-#
-# Add to ambient vpath so we pick up the library files
-#
-vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC)
-endif
+else # !SYSTEM_ZLIB
+  #
+  # Add to ambient vpath so we pick up the library files, for macos we add 
+  # solaris sources which contains the common logic for all nixes
+  #
+  ifeq ($(PLATFORM), macosx)
+    vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC) \
+          $(LAUNCHER_SOLARIS_PLATFORM_SRC)
+  else # !MACOSX
+    vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC) $(LAUNCHER_PLATFORM_SRC)
+  endif # MACOSX
+endif # SYSTEM_LIB
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/bin/java_md_macosx.c	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,1021 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "java.h"
+#include "jvm_md.h"
+#include <dirent.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "manifest_info.h"
+#include "version_comp.h"
+
+/* Support Cocoa event loop on the main thread */
+#include <Cocoa/Cocoa.h>
+#include <objc/objc-runtime.h>
+#include <objc/objc-auto.h>
+#include <dispatch/dispatch.h>
+
+#include <errno.h>
+#include <spawn.h>
+
+struct NSAppArgs {
+    int argc;
+    char **argv;
+};
+
+#define JVM_DLL "libjvm.dylib"
+#define JAVA_DLL "libjava.dylib"
+/* FALLBACK avoids naming conflicts with system libraries
+ * (eg, ImageIO's libJPEG.dylib) */
+#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH"
+
+/*
+ * If a processor / os combination has the ability to run binaries of
+ * two data models and cohabitation of jre/jdk bits with both data
+ * models is supported, then DUAL_MODE is defined. MacOSX is a hybrid
+ * system in that, the universal library can contain all types of libraries
+ * 32/64 and client/server, thus the spawn is capable of linking with the
+ * appropriate library as requested.
+ *
+ * Notes:
+ * 1. VM. DUAL_MODE is disabled, and not supported, however, it is left here in
+ *    for experimentation and perhaps enable it in the future.
+ * 2. At the time of this writing, the universal library contains only
+ *    a server 64-bit server JVM.
+ * 3. "-client" command line option is supported merely as a command line flag,
+ *    for, compatibility reasons, however, a server VM will be launched.
+ */
+
+/*
+ * Flowchart of launcher execs and options processing on unix
+ *
+ * The selection of the proper vm shared library to open depends on
+ * several classes of command line options, including vm "flavor"
+ * options (-client, -server) and the data model options, -d32  and
+ * -d64, as well as a version specification which may have come from
+ * the command line or from the manifest of an executable jar file.
+ * The vm selection options are not passed to the running
+ * virtual machine; they must be screened out by the launcher.
+ *
+ * The version specification (if any) is processed first by the
+ * platform independent routine SelectVersion.  This may result in
+ * the exec of the specified launcher version.
+ *
+ * Now, in most cases,the launcher will dlopen the target libjvm.so. All
+ * required libraries are loaded by the runtime linker, using the known paths
+ * baked into the shared libraries at compile time. Therefore,
+ * in most cases, the launcher will only exec, if the data models are
+ * mismatched, and will not set any environment variables, regardless of the
+ * data models.
+ *
+ *
+ *
+ *  Main
+ *  (incoming argv)
+ *  |
+ * \|/
+ * SelectVersion
+ * (selects the JRE version, note: not data model)
+ *  |
+ * \|/
+ * CreateExecutionEnvironment
+ * (determines desired data model)
+ *  |
+ *  |
+ * \|/
+ *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                         YES
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                CheckJvmType
+ *  |                               (removes -client, -server etc.)
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * YES                             Find the desired executable/library
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * CheckJvmType                             POINT A
+ * (removes -client, -server, etc.)
+ *  |
+ *  |
+ * \|/
+ * TranslateDashJArgs...
+ * (Prepare to pass args to vm)
+ *  |
+ *  |
+ * \|/
+ * ParseArguments
+ * (removes -d32 and -d64 if any,
+ *  processes version options,
+ *  creates argument list for vm,
+ *  etc.)
+ *   |
+ *   |
+ *  \|/
+ * POINT A
+ *   |
+ *   |
+ *  \|/
+ * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
+ *  NO                               YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Paths have well known
+ * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Does libjvm.so exist
+ *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *   YES                             YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Re-exec / Spawn
+ *   |
+ *   |
+ *  \|/
+ * Main
+ */
+
+#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
+
+/* Store the name of the executable once computed */
+static char *execname = NULL;
+
+/*
+ * execname accessor from other parts of platform dependent logic
+ */
+const char *
+GetExecName() {
+    return execname;
+}
+
+const char *
+GetArchPath(int nbits)
+{
+    switch(nbits) {
+        default:
+            return LIBARCHNAME;
+    }
+}
+
+
+/*
+ * Exports the JNI interface from libjli
+ *
+ * This allows client code to link against the .jre/.jdk bundles,
+ * and not worry about trying to pick a HotSpot to link against.
+ *
+ * Switching architectures is unsupported, since client code has
+ * made that choice before the JVM was requested.
+ */
+
+static InvocationFunctions *sExportedJNIFunctions = NULL;
+static char *sPreferredJVMType = NULL;
+
+static InvocationFunctions *GetExportedJNIFunctions() {
+    if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions;
+
+    char jrePath[PATH_MAX];
+    jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE);
+    if (!gotJREPath) {
+        JLI_ReportErrorMessage("Failed to GetJREPath()");
+        return NULL;
+    }
+
+    char *preferredJVM = sPreferredJVMType;
+    if (preferredJVM == NULL) {
+#if defined(__i386__)
+        preferredJVM = "client";
+#elif defined(__x86_64__)
+        preferredJVM = "server";
+#else
+#error "Unknown architecture - needs definition"
+#endif
+    }
+
+    char jvmPath[PATH_MAX];
+    jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath), GetArch(), CURRENT_DATA_MODEL);
+    if (!gotJVMPath) {
+        JLI_ReportErrorMessage("Failed to GetJVMPath()");
+        return NULL;
+    }
+
+    InvocationFunctions *fxns = malloc(sizeof(InvocationFunctions));
+    jboolean vmLoaded = LoadJavaVM(jvmPath, fxns);
+    if (!vmLoaded) {
+        JLI_ReportErrorMessage("Failed to LoadJavaVM()");
+        return NULL;
+    }
+
+    return sExportedJNIFunctions = fxns;
+}
+
+JNIEXPORT jint JNICALL
+JNI_GetDefaultJavaVMInitArgs(void *args) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->GetDefaultJavaVMInitArgs(args);
+}
+
+JNIEXPORT jint JNICALL
+JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->CreateJavaVM(pvm, penv, args);
+}
+
+JNIEXPORT jint JNICALL
+JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs) {
+    InvocationFunctions *ifn = GetExportedJNIFunctions();
+    if (ifn == NULL) return JNI_ERR;
+    return ifn->GetCreatedJavaVMs(vmBuf, bufLen, nVMs);
+}
+
+/*
+ * Allow JLI-aware launchers to specify a client/server preference
+ */
+JNIEXPORT void JNICALL
+JLI_SetPreferredJVM(const char *prefJVM) {
+    if (sPreferredJVMType != NULL) {
+        free(sPreferredJVMType);
+        sPreferredJVMType = NULL;
+    }
+
+    if (prefJVM == NULL) return;
+    sPreferredJVMType = strdup(prefJVM);
+}
+
+static BOOL awtLoaded = NO;
+static pthread_mutex_t awtLoaded_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  awtLoaded_cv = PTHREAD_COND_INITIALIZER;
+
+JNIEXPORT void JNICALL
+JLI_NotifyAWTLoaded()
+{
+    pthread_mutex_lock(&awtLoaded_mutex);
+    awtLoaded = YES;
+    pthread_cond_signal(&awtLoaded_cv);
+    pthread_mutex_unlock(&awtLoaded_mutex);
+}
+
+static int (*main_fptr)(int argc, char **argv) = NULL;
+
+/*
+ * Unwrap the arguments and re-run main()
+ */
+static void *apple_main (void *arg)
+{
+    objc_registerThreadWithCollector();
+
+    if (main_fptr == NULL) {
+        main_fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (main_fptr == NULL) {
+            JLI_ReportErrorMessageSys("error locating main entrypoint\n");
+            exit(1);
+        }
+    }
+
+    struct NSAppArgs *args = (struct NSAppArgs *) arg;
+    exit(main_fptr(args->argc, args->argv));
+}
+
+static void dummyTimer(CFRunLoopTimerRef timer, void *info) {}
+
+static void ParkEventLoop() {
+    // RunLoop needs at least one source, and 1e20 is pretty far into the future
+    CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL);
+    CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
+    CFRelease(t);
+
+    // Park this thread in the main run loop.
+    int32_t result;
+    do {
+        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false);
+    } while (result != kCFRunLoopRunFinished);
+}
+
+/*
+ * Mac OS X mandates that the GUI event loop run on very first thread of
+ * an application. This requires that we re-call Java's main() on a new
+ * thread, reserving the 'main' thread for Cocoa.
+ */
+static void MacOSXStartup(int argc, char *argv[]) {
+    // Thread already started?
+    static jboolean started = false;
+    if (started) {
+        return;
+    }
+    started = true;
+
+    // Hand off arguments
+    struct NSAppArgs args;
+    args.argc = argc;
+    args.argv = argv;
+
+    // Fire up the main thread
+    pthread_t main_thr;
+    if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
+        JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
+        exit(1);
+    }
+    if (pthread_detach(main_thr)) {
+        JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
+        exit(1);
+    }
+
+    ParkEventLoop();
+}
+
+void
+CreateExecutionEnvironment(int *pargc, char ***pargv,
+                           char jrepath[], jint so_jrepath,
+                           char jvmpath[], jint so_jvmpath,
+                           char jvmcfg[],  jint so_jvmcfg) {
+  /*
+   * First, determine if we are running the desired data model.  If we
+   * are running the desired data model, all the error messages
+   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
+   * output.  However, if we are not running the desired data model,
+   * some of the errors should be suppressed since it is more
+   * informative to issue an error message based on whether or not the
+   * os/processor combination has dual mode capabilities.
+   */
+    jboolean jvmpathExists;
+
+    /* Compute/set the name of the executable */
+    SetExecname(*pargv);
+
+    /* Check data model flags, and exec process, if needed */
+    {
+      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
+      char * jvmtype    = NULL;
+      int  argc         = *pargc;
+      char **argv       = *pargv;
+      int running       = CURRENT_DATA_MODEL;
+
+      int wanted        = running;      /* What data mode is being
+                                           asked for? Current model is
+                                           fine unless another model
+                                           is asked for */
+
+      char** newargv    = NULL;
+      int    newargc    = 0;
+
+      /*
+       * Starting in 1.5, all unix platforms accept the -d32 and -d64
+       * options.  On platforms where only one data-model is supported
+       * (e.g. ia-64 Linux), using the flag for the other data model is
+       * an error and will terminate the program.
+       */
+
+      { /* open new scope to declare local variables */
+        int i;
+
+        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
+        newargv[newargc++] = argv[0];
+
+        /* scan for data model arguments and remove from argument list;
+           last occurrence determines desired data model */
+        for (i=1; i < argc; i++) {
+
+          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
+            wanted = 64;
+            continue;
+          }
+          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
+            wanted = 32;
+            continue;
+          }
+          newargv[newargc++] = argv[i];
+
+          if (IsJavaArgs()) {
+            if (argv[i][0] != '-') continue;
+          } else {
+            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
+              i++;
+              if (i >= argc) break;
+              newargv[newargc++] = argv[i];
+              continue;
+            }
+            if (argv[i][0] != '-') { i++; break; }
+          }
+        }
+
+        /* copy rest of args [i .. argc) */
+        while (i < argc) {
+          newargv[newargc++] = argv[i++];
+        }
+        newargv[newargc] = NULL;
+
+        /*
+         * newargv has all proper arguments here
+         */
+
+        argc = newargc;
+        argv = newargv;
+      }
+
+      /* If the data model is not changing, it is an error if the
+         jvmpath does not exist */
+      if (wanted == running) {
+        /* Find out where the JRE is that we will be using. */
+        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
+          JLI_ReportErrorMessage(JRE_ERROR1);
+          exit(2);
+        }
+        JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+          jrepath, FILESEP, FILESEP,  "", "");
+        /* Find the specified JVM type */
+        if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
+          JLI_ReportErrorMessage(CFG_ERROR7);
+          exit(1);
+        }
+
+        jvmpath[0] = '\0';
+        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
+        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+        }
+
+        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, wanted)) {
+          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
+          exit(4);
+        }
+
+        /*
+         * Mac OS X requires the Cocoa event loop to be run on the "main"
+         * thread. Spawn off a new thread to run main() and pass
+         * this thread off to the Cocoa event loop.
+         */
+        MacOSXStartup(argc, argv);
+
+        /*
+         * we seem to have everything we need, so without further ado
+         * we return back, otherwise proceed to set the environment.
+         */
+        return;
+      } else {  /* do the same speculatively or exit */
+#if defined(DUAL_MODE)
+        if (running != wanted) {
+          /* Find out where the JRE is that we will be using. */
+          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+            jrepath, FILESEP, FILESEP,  "", "");
+          /*
+           * Read in jvm.cfg for target data model and process vm
+           * selection options.
+           */
+          if (ReadKnownVMs(jvmcfg, JNI_TRUE) < 1) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          jvmpath[0] = '\0';
+          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
+          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+          }
+
+          /* exec child can do error checking on the existence of the path */
+          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), wanted);
+        }
+#else /* ! DUAL_MODE */
+        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+        exit(1);
+#endif /* DUAL_MODE */
+        }
+        {
+            char *newexec = execname;
+            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+            (void) fflush(stdout);
+            (void) fflush(stderr);
+            /*
+            * Use posix_spawn() instead of execv() on Mac OS X.
+            * This allows us to choose which architecture the child process
+            * should run as.
+            */
+            {
+                posix_spawnattr_t attr;
+                size_t unused_size;
+                pid_t  unused_pid;
+
+#if defined(__i386__) || defined(__x86_64__)
+                cpu_type_t cpu_type[] = { (wanted == 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86,
+                                    (running== 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86 };
+#else
+                cpu_type_t cpu_type[] = { CPU_TYPE_ANY };
+#endif /* __i386 .. */
+
+                posix_spawnattr_init(&attr);
+                posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
+                posix_spawnattr_setbinpref_np(&attr, sizeof(cpu_type) / sizeof(cpu_type_t),
+                                            cpu_type, &unused_size);
+
+                posix_spawn(&unused_pid, newexec, NULL, &attr, argv, environ);
+            }
+            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
+
+#if defined(DUAL_MODE)
+            if (running != wanted) {
+                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
+            }
+#endif /* DUAL_MODE */
+        }
+        exit(1);
+    }
+}
+
+/*
+ * VM choosing is done by the launcher (java.c).
+ */
+static jboolean
+GetJVMPath(const char *jrepath, const char *jvmtype,
+           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted)
+{
+    struct stat s;
+
+    if (JLI_StrChr(jvmtype, '/')) {
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
+    } else {
+        /*
+         * macosx client library is built thin, i386 only.
+         * 64 bit client requests must load server library
+         */
+        const char *jvmtypeUsed = ((bitsWanted == 64) && (strcmp(jvmtype, "client") == 0)) ? "server" : jvmtype;
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jrepath, jvmtypeUsed);
+    }
+
+    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
+
+    if (stat(jvmpath, &s) == 0) {
+        JLI_TraceLauncher("yes.\n");
+        return JNI_TRUE;
+    } else {
+        JLI_TraceLauncher("no.\n");
+        return JNI_FALSE;
+    }
+}
+
+/*
+ * Find path to JRE based on .exe's location or registry settings.
+ */
+static jboolean
+GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
+{
+    char libjava[MAXPATHLEN];
+
+    if (GetApplicationHome(path, pathsize)) {
+        /* Is JRE co-located with the application? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
+        if (access(libjava, F_OK) == 0) {
+            return JNI_TRUE;
+        }
+
+        /* Does the app ship a private JRE in <apphome>/jre directory? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
+        if (access(libjava, F_OK) == 0) {
+            JLI_StrCat(path, "/jre");
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+    }
+
+    /* try to find ourselves instead */
+    Dl_info selfInfo;
+    dladdr(&GetJREPath, &selfInfo);
+
+    char *realPathToSelf = realpath(selfInfo.dli_fname, path);
+    if (realPathToSelf != path) {
+        return JNI_FALSE;
+    }
+
+    size_t pathLen = strlen(realPathToSelf);
+    if (pathLen == 0) {
+        return JNI_FALSE;
+    }
+
+    const char lastPathComponent[] = "/lib/jli/libjli.dylib";
+    size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
+    if (pathLen < sizeOfLastPathComponent) {
+        return JNI_FALSE;
+    }
+
+    size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
+    if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
+        realPathToSelf[indexOfLastPathComponent + 1] = '\0';
+        return JNI_TRUE;
+    }
+
+    if (!speculative)
+      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
+    return JNI_FALSE;
+}
+
+jboolean
+LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
+{
+    Dl_info dlinfo;
+    void *libjvm;
+
+    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
+
+    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
+    if (libjvm == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->CreateJavaVM = (CreateJavaVM_t)
+        dlsym(libjvm, "JNI_CreateJavaVM");
+    if (ifn->CreateJavaVM == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
+        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
+    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t)
+    dlsym(libjvm, "JNI_GetCreatedJavaVMs");
+    if (ifn->GetCreatedJavaVMs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    return JNI_TRUE;
+}
+
+/*
+ * Compute the name of the executable
+ *
+ * In order to re-exec securely we need the absolute path of the
+ * executable. On Solaris getexecname(3c) may not return an absolute
+ * path so we use dladdr to get the filename of the executable and
+ * then use realpath to derive an absolute path. From Solaris 9
+ * onwards the filename returned in DL_info structure from dladdr is
+ * an absolute pathname so technically realpath isn't required.
+ * On Linux we read the executable name from /proc/self/exe.
+ * As a fallback, and for platforms other than Solaris and Linux,
+ * we use FindExecName to compute the executable name.
+ */
+const char*
+SetExecname(char **argv)
+{
+    char* exec_path = NULL;
+    {
+        Dl_info dlinfo;
+        int (*fptr)();
+
+        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (fptr == NULL) {
+            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
+            return JNI_FALSE;
+        }
+
+        if (dladdr((void*)fptr, &dlinfo)) {
+            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
+            if (resolved != NULL) {
+                exec_path = realpath(dlinfo.dli_fname, resolved);
+                if (exec_path == NULL) {
+                    JLI_MemFree(resolved);
+                }
+            }
+        }
+    }
+    if (exec_path == NULL) {
+        exec_path = FindExecName(argv[0]);
+    }
+    execname = exec_path;
+    return exec_path;
+}
+
+/*
+ * BSD's implementation of CounterGet()
+ */
+int64_t
+CounterGet()
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return (tv.tv_sec * 1000) + tv.tv_usec;
+}
+
+
+/* --- Splash Screen shared library support --- */
+
+static JavaVM* SetJavaVMValue()
+{
+    JavaVM * jvm = NULL;
+
+    // The handle is good for both the launcher and the libosxapp.dylib
+    void * handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
+    if (handle) {
+        typedef JavaVM* (*JLI_GetJavaVMInstance_t)();
+
+        JLI_GetJavaVMInstance_t JLI_GetJavaVMInstance =
+            (JLI_GetJavaVMInstance_t)dlsym(handle,
+                    "JLI_GetJavaVMInstance");
+        if (JLI_GetJavaVMInstance) {
+            jvm = JLI_GetJavaVMInstance();
+        }
+
+        if (jvm) {
+            typedef void (*OSXAPP_SetJavaVM_t)(JavaVM*);
+
+            OSXAPP_SetJavaVM_t OSXAPP_SetJavaVM =
+                (OSXAPP_SetJavaVM_t)dlsym(handle, "OSXAPP_SetJavaVM");
+            if (OSXAPP_SetJavaVM) {
+                OSXAPP_SetJavaVM(jvm);
+            } else {
+                jvm = NULL;
+            }
+        }
+
+        dlclose(handle);
+    }
+
+    return jvm;
+}
+
+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
+
+static void* hSplashLib = NULL;
+
+void* SplashProcAddress(const char* name) {
+    if (!hSplashLib) {
+        const char * splashLibPath;
+        char path[PATH_MAX];
+        Dl_info dli;
+
+        path[0] = 0;
+        if (dladdr(&SplashProcAddress, &dli)) {
+            // This is always reported as <path>/bin/java* (java or javaw, whatever)
+            char * realPath = realpath(dli.dli_fname, path);
+
+            if (realPath != path) {
+                path[0] = 0;
+            } else {
+                // chop off the "/bin/java*" part...
+                char * c = strrchr(path, '/');
+
+                if (!c) {
+                    path[0] = 0;
+                } else {
+                    *c = 0;
+                    c = strrchr(path, '/');
+
+                    if (!c) {
+                        path[0] = 0;
+                    } else {
+                        *c = 0;
+                        // ...and add the lib path instead
+                        snprintf(c, sizeof(path)-strlen(path), "/lib/%s", SPLASHSCREEN_SO);
+                    }
+                }
+            }
+        }
+
+        if (path[0]) {
+            splashLibPath = path;
+        } else {
+            // try our best, but most probably this will fail to load
+            splashLibPath = SPLASHSCREEN_SO;
+        }
+        hSplashLib = dlopen(splashLibPath, RTLD_LAZY | RTLD_GLOBAL);
+        if (hSplashLib) {
+            if (!SetJavaVMValue()) {
+                dlclose(hSplashLib);
+                hSplashLib = NULL;
+            }
+        }
+    }
+    if (hSplashLib) {
+        void* sym = dlsym(hSplashLib, name);
+        return sym;
+    } else {
+        return NULL;
+    }
+}
+
+void SplashFreeLibrary() {
+    if (hSplashLib) {
+        dlclose(hSplashLib);
+        hSplashLib = NULL;
+    }
+}
+
+/*
+ * Block current thread and continue execution in a new thread
+ */
+int
+ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
+    int rslt;
+    pthread_t tid;
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+    if (stack_size > 0) {
+      pthread_attr_setstacksize(&attr, stack_size);
+    }
+
+    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
+      void * tmp;
+      pthread_join(tid, &tmp);
+      rslt = (int)tmp;
+    } else {
+     /*
+      * Continue execution in current thread if for some reason (e.g. out of
+      * memory/LWP)  a new thread can't be created. This will likely fail
+      * later in continuation as JNI_CreateJavaVM needs to create quite a
+      * few new threads, anyway, just give it a try..
+      */
+      rslt = continuation(args);
+    }
+
+    pthread_attr_destroy(&attr);
+    return rslt;
+}
+
+void SetJavaLauncherPlatformProps() {
+   /* Linux only */
+}
+
+jboolean
+ServerClassMachine(void) {
+    return JNI_TRUE;
+}
+
+static JavaVM* jvmInstance = NULL;
+static jboolean sameThread = JNI_FALSE; /* start VM in current thread */
+
+/*
+ * Note there is a callback on this function from the splashscreen logic,
+ * this as well SetJavaVMValue() needs to be simplified.
+ */
+JavaVM*
+JLI_GetJavaVMInstance()
+{
+    return jvmInstance;
+}
+
+void
+RegisterThread()
+{
+    objc_registerThreadWithCollector();
+}
+
+static void
+SetXDockArgForAWT(const char *arg)
+{
+    char envVar[80];
+    if (strstr(arg, "-Xdock:name=") == arg) {
+        snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
+        setenv(envVar, (arg + 12), 1);
+    }
+
+    if (strstr(arg, "-Xdock:icon=") == arg) {
+        snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
+        setenv(envVar, (arg + 12), 1);
+    }
+}
+
+static void
+SetMainClassForAWT(JNIEnv *env, jclass mainClass) {
+    jclass classClass = NULL;
+    NULL_CHECK(classClass = FindBootStrapClass(env, "java/lang/Class"));
+
+    jmethodID getCanonicalNameMID = NULL;
+    NULL_CHECK(getCanonicalNameMID = (*env)->GetMethodID(env, classClass, "getCanonicalName", "()Ljava/lang/String;"));
+
+    jstring mainClassString = NULL;
+    NULL_CHECK(mainClassString = (*env)->CallObjectMethod(env, mainClass, getCanonicalNameMID));
+
+    const char *mainClassName = NULL;
+    NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL));
+
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid());
+    setenv(envVar, mainClassName, 1);
+
+    (*env)->ReleaseStringUTFChars(env, mainClassString, mainClassName);
+}
+
+void
+SetXStartOnFirstThreadArg()
+{
+    // XXX: BEGIN HACK
+    // short circuit hack for <https://bugs.eclipse.org/bugs/show_bug.cgi?id=211625>
+    // need a way to get AWT/Swing apps launched when spawned from Eclipse,
+    // which currently has no UI to not pass the -XstartOnFirstThread option
+    if (getenv("HACK_IGNORE_START_ON_FIRST_THREAD") != NULL) return;
+    // XXX: END HACK
+
+    sameThread = JNI_TRUE;
+    // Set a variable that tells us we started on the main thread.
+    // This is used by the AWT during startup. (See awt.m)
+    char envVar[80];
+    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
+    setenv(envVar, "1", 1);
+}
+
+// MacOSX we may continue in the same thread
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+                 int argc, char **argv,
+                 int mode, char *what, int ret) {
+    if (sameThread) {
+        JLI_TraceLauncher("In same thread\n");
+        // need to block this thread against the main thread
+        // so signals get caught correctly
+        __block int rslt;
+        dispatch_sync(dispatch_get_main_queue(), ^(void) {
+            JavaMainArgs args;
+            args.argc = argc;
+            args.argv = argv;
+            args.mode = mode;
+            args.what = what;
+            args.ifn  = *ifn;
+            rslt = JavaMain((void*)&args);
+        });
+        return rslt;
+    } else {
+        return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+    }
+}
+
+/*
+ * Note the jvmInstance must be initialized first before entering into
+ * ShowSplashScreen, as there is a callback into the JLI_GetJavaVMInstance.
+ */
+void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm) {
+    jvmInstance = vm;
+    SetMainClassForAWT(env, mainClass);
+    ShowSplashScreen();
+}
+
+jboolean
+ProcessPlatformOption(const char* arg)
+{
+    if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
+       SetXStartOnFirstThreadArg();
+       return JNI_TRUE;
+    } else if (JLI_StrCCmp(arg, "-Xdock:") == 0) {
+       SetXDockArgForAWT(arg);
+       return JNI_TRUE;
+    }
+    // arguments we know not
+    return JNI_FALSE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/bin/java_md_macosx.h	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef JAVA_MD_MACOSX_H
+#define JAVA_MD_MACOSX_H
+
+/* CounterGet() is implemented in java_md.c */
+int64_t CounterGet(void);
+#define Counter2Micros(counts)    (counts)
+
+/* pointer to environment */
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+
+/*
+ *      A collection of useful strings. One should think of these as #define
+ *      entries, but actual strings can be more efficient (with many compilers).
+ */
+static const char *system_dir  = PACKAGE_PATH "/openjdk7";
+static const char *user_dir    = "/java";
+
+#include <dlfcn.h>
+#include <pthread.h>
+
+#endif /* JAVA_MD_MACOSX_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/bin/jexec.c	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 1999, 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * jexec for J2SE
+ *
+ * jexec is used by the system to allow execution of JAR files.
+ *    Essentially jexec needs to run java and
+ *    needs to be a native ISA executable (not a shell script), although
+ *    this native ISA executable requirement was a mistake that will be fixed.
+ *    (<ISA> is sparc or i386 or amd64).
+ *
+ *    When you execute a jar file, jexec is executed by the system as follows:
+ *      /usr/java/jre/lib/<ISA>/jexec -jar JARFILENAME
+ *    so this just needs to be turned into:
+ *      /usr/java/jre/bin/java -jar JARFILENAME
+ *
+ * Solaris systems (new 7's and all 8's) will be looking for jexec at:
+ *      /usr/java/jre/lib/<ISA>/jexec
+ * Older systems may need to add this to their /etc/system file:
+ *      set javaexec:jexec="/usr/java/jre/lib/<ISA>/jexec"
+ *     and reboot the machine for this to work.
+ *
+ * This source should be compiled as:
+ *      cc -o jexec jexec.c
+ *
+ * And jexec should be placed at the following location of the installation:
+ *      <INSTALLATIONDIR>/jre/lib/<ISA>/jexec  (for Solaris)
+ *      <INSTALLATIONDIR>/lib/jexec            (for Linux)
+ *
+ * NOTE: Unless <INSTALLATIONDIR> is the "default" JDK on the system
+ *       (i.e. /usr/java -> <INSTALLATIONDIR>), this jexec will not be
+ *       found.  The 1.2 java is only the default on Solaris 8 and
+ *       on systems where the 1.2 packages were installed and no 1.1
+ *       java was found.
+ *
+ * NOTE: You must use 1.2 jar to build your jar files. The system
+ *       doesn't seem to pick up 1.1 jar files.
+ *
+ * NOTE: We don't need to set LD_LIBRARY_PATH here, even though we
+ *       are running the actual java binary because the java binary will
+ *       look for it's libraries through it's own runpath, which uses
+ *       $ORIGIN.
+ *
+ * NOTE: This jexec should NOT have any special .so library needs because
+ *       it appears that this executable will NOT get the $ORIGIN of jexec
+ *       but the $ORIGIN of the jar file being executed. Be careful to keep
+ *       this program simple and with no .so dependencies.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+
+static const int CRAZY_EXEC = ENOEXEC;
+static const int BAD_MAGIC  = ENOEXEC;
+
+static const char * BAD_EXEC_MSG     = "jexec failed";
+static const char * CRAZY_EXEC_MSG   = "missing args";
+static const char * MISSING_JAVA_MSG = "can't locate java";
+static const char * UNKNOWN_ERROR    = "unknown error";
+
+/* Define a constant that represents the number of directories to pop off the
+ * current location to find the java binary */
+static const int RELATIVE_DEPTH = 3;
+
+/* path to java after popping */
+static const char * BIN_PATH = "/bin/java";
+
+/* flag used when running JAR files */
+static const char * JAR_FLAG = "-jar";
+
+int main(int argc, const char * argv[]);
+void errorExit(int error, const char * message);
+int getJavaPath(const char * path, char * buf, int depth);
+
+/*
+ * This is the main entry point.  This program (jexec) will attempt to execute
+ * a JAR file by finding the Java program (java), relative to its own location.
+ * The exact location of the Java program depends on the platform, i.e.
+ *
+ *      <INSTALLATIONDIR>/jre/lib/<ISA>/jexec  (for Solaris)
+ *      <INSTALLATIONDIR>/lib/jexec            (for Linux JDK)
+ *
+ * Once the Java program is found, this program copies any remaining arguments
+ * into another array, which is then used to exec the Java program.
+ *
+ * On Linux this program does some additional steps.  When copying the array of
+ * args, it is necessary to insert the "-jar" flag between arg[0], the program
+ * name, and the original arg[1], which is presumed to be a path to a JAR file.
+ * It is also necessary to verify that the original arg[1] really is a JAR file.
+ * (These steps are unnecessary on Solaris because they are taken care of by
+ * the kernel.)
+ */
+int main(int argc, const char * argv[]) {
+    /* We need to exec the original arguments using java, instead of jexec.
+     * Also, for Linux, it is necessary to add the "-jar" argument between
+     * the new arg[0], and the old arg[1].  To do this we will create a new
+     * args array. */
+    char          java[PATH_MAX + 1];    /* path to java binary  */
+    const char ** nargv = NULL;          /* new args array       */
+    int           nargc = 0;             /* new args array count */
+    int           argi  = 0;             /* index into old array */
+
+    /* Make sure we have something to work with */
+    if ((argc < 1) || (argv == NULL)) {
+        /* Shouldn't happen... */
+        errorExit(CRAZY_EXEC, CRAZY_EXEC_MSG);
+    }
+
+    /* Get the path to the java binary, which is in a known position relative
+     * to our current position, which is in argv[0]. */
+    if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
+        errorExit(errno, MISSING_JAVA_MSG);
+    }
+
+    nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
+    nargv[nargc++] = java;
+
+    if (argc >= 2) {
+        const char * jarfile = argv[argi++];
+        const char * message = NULL;
+
+        /* the next argument is the path to the JAR file */
+        nargv[nargc++] = jarfile;
+    }
+
+    /* finally copy any remaining arguments */
+    while (argi < argc) {
+        nargv[nargc++] = argv[argi++];
+    }
+
+    /* finally add one last terminating null */
+    nargv[nargc++] = NULL;
+
+    /* It's time to exec the java binary with the new arguments.  It
+     * is possible that we've reached this point without actually
+     * having a JAR file argument (i.e. if argc < 2), but we still
+     * want to exec the java binary, since that will take care of
+     * displaying the correct usage. */
+    execv(java, (char * const *) nargv);
+
+    /* If the exec worked, this process would have been replaced
+     * by the new process.  So any code reached beyond this point
+     * implies an error in the exec. */
+    free(nargv);
+    errorExit(errno, BAD_EXEC_MSG);
+    return 0; // keep the compiler happy
+}
+
+
+/*
+ * Exit the application by setting errno, and writing a message.
+ *
+ * Parameters:
+ *     error   - errno is set to this value, and it is used to exit.
+ *     message - the message to write.
+ */
+void errorExit(int error, const char * message) {
+    if (error != 0) {
+        errno = error;
+        perror((message != NULL) ? message : UNKNOWN_ERROR);
+    }
+
+    exit((error == 0) ? 0 : 1);
+}
+
+
+/*
+ * Get the path to the java binary that should be relative to the current path.
+ *
+ * Parameters:
+ *     path  - the input path that the java binary that should be relative to.
+ *     buf   - a buffer of size PATH_MAX or greater that the java path is
+ *             copied to.
+ *     depth - the number of names to trim off the current path, including the
+ *             name of this program.
+ *
+ * Returns:
+ *     This function returns 0 on success; otherwise it returns the value of
+ *     errno.
+ */
+int getJavaPath(const char * path, char * buf, int depth) {
+    int result = 0;
+
+    /* Get the full path to this program.  Depending on whether this is Solaris
+     * or Linux, this will be something like,
+     *
+     *     <FOO>/jre/lib/<ISA>/jexec  (for Solaris)
+     *     <FOO>/lib/jexec            (for Linux)
+     */
+    if (realpath(path, buf) != NULL) {
+        int count = 0;
+
+        /* Pop off the filename, and then subdirectories for each level of
+         * depth */
+        for (count = 0; count < depth; count++) {
+            *(strrchr(buf, '/')) = '\0';
+        }
+
+        /* Append the relative location of java, creating something like,
+         *
+         *     <FOO>/jre/bin/java  (for Solaris)
+         *     <FOO>/bin/java      (for Linux)
+         */
+        strcat(buf, BIN_PATH);
+    }
+    else {
+        /* Failed to get the path */
+        result = errno;
+    }
+
+    return (result);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/bin/universal/jvm.cfg	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,38 @@
+# Copyright (c) 2012, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+# List of JVMs that can be used as an option to java, javac, etc.
+# Order is important -- first in this list is the default JVM.
+# NOTE that this both this file and its format are UNSUPPORTED and
+# WILL GO AWAY in a future release.
+#
+# You may also select a JVM in an arbitrary location with the
+# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
+# and may not be available in a future release.
+#
+-server KNOWN
+-client KNOWN
+-hotspot ERROR
+-classic WARN
+-native ERROR
+-green ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/lib/Info-cmdline.plist	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleIdentifier</key>
+        <string>net.java.openjdk.cmd</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleVersion</key>
+        <string>1.0</string>
+</dict>
+</plist>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/lib/Info-privileged.plist	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>CFBundleIdentifier</key>
+        <string>net.java.openjdk.cmd</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleName</key>
+        <string>OpenJDK 7 Command</string>
+        <key>CFBundleShortVersionString</key>
+        <string>1.0</string>
+        <key>CFBundleVersion</key>
+        <string>1.0</string>
+        <key>SecTaskAccess</key>
+        <string>allowed</string>
+</dict>
+</plist>
--- a/src/share/bin/java.c	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/share/bin/java.c	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2012, 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
@@ -70,12 +70,6 @@
 static jboolean printXUsage = JNI_FALSE;  /* print and exit*/
 static char     *showSettings = NULL;      /* print but continue */
 
-#ifdef MACOSX
-#include <objc/objc-auto.h>
-#include <dispatch/dispatch.h>
-static jboolean continueInSameThread = JNI_FALSE; /* start VM in current thread */
-#endif
-
 static const char *_program_name;
 static const char *_launcher_name;
 static jboolean _is_java_args = JNI_FALSE;
@@ -126,19 +120,6 @@
 static void DumpState();
 static jboolean RemovableOption(char *option);
 
-#ifdef MACOSX
-static void SetMainClassForAWT(JNIEnv *env, jclass mainClass);
-static void SetXDockArgForAWT(const char *arg);
-static void SetXStartOnFirstThreadArg();
-
-static JavaVM* jvmInstance = NULL;
-
-JavaVM* JLI_GetJavaVMInstance()
-{
-    return jvmInstance;
-}
-#endif
-
 /* Maximum supported entries from jvm.cfg. */
 #define INIT_MAX_KNOWN_VMS      10
 
@@ -166,7 +147,6 @@
 static void GrowKnownVMs();
 static int  KnownVMIndex(const char* name);
 static void FreeKnownVMs();
-static void ShowSplashScreen();
 static jboolean IsWildCardEnabled();
 
 #define ARG_CHECK(n, f, a) if (n < 1) { \
@@ -184,25 +164,6 @@
 static jlong maxHeapSize        = 0;  /* max heap size */
 static jlong initialHeapSize    = 0;  /* inital heap size */
 
-int JNICALL JavaMain(void * args); /* entry point                  */
-
-enum LaunchMode {               // cf. sun.launcher.LauncherHelper
-    LM_UNKNOWN = 0,
-    LM_CLASS,
-    LM_JAR
-};
-
-static const char *launchModeNames[]
-    = { "Unknown", "Main class", "JAR file" };
-
-typedef struct {
-    int    argc;
-    char **argv;
-    int    mode;
-    char  *what;
-    InvocationFunctions ifn;
-} JavaMainArgs;
-
 /*
  * Entry point.
  */
@@ -229,6 +190,7 @@
     jlong start, end;
     char jvmpath[MAXPATHLEN];
     char jrepath[MAXPATHLEN];
+    char jvmcfg[MAXPATHLEN];
 
     _fVersion = fullversion;
     _dVersion = dotversion;
@@ -271,7 +233,8 @@
 
     CreateExecutionEnvironment(&argc, &argv,
                                jrepath, sizeof(jrepath),
-                               jvmpath, sizeof(jvmpath));
+                               jvmpath, sizeof(jvmpath),
+                               jvmcfg,  sizeof(jvmcfg));
 
     ifn.CreateJavaVM = 0;
     ifn.GetDefaultJavaVMInitArgs = 0;
@@ -331,32 +294,7 @@
     /* set the -Dsun.java.launcher.* platform properties */
     SetJavaLauncherPlatformProps();
 
-#ifndef MACOSX
-    // On MacOSX the splash screen is shown from JavaMain
-    // after the JVM is initialized.
-    /* Show the splash screen if needed */
-    ShowSplashScreen();
-#endif
-
-#ifdef MACOSX
-    if (continueInSameThread == JNI_TRUE) {
-        // need to block this thread against the main thread
-        // so signals get caught correctly
-        __block int rslt;
-        dispatch_sync(dispatch_get_main_queue(), ^(void){
-            JavaMainArgs args;
-            args.argc = argc;
-            args.argv = argv;
-            args.mode = mode;
-            args.what = what;
-            args.ifn = ifn;
-            rslt = JavaMain((void*)&args);
-        });
-        return rslt;
-    }
-#endif
-    return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);
-
+    return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
 }
 /*
  * Always detach the main thread so that it appears to have ended when
@@ -415,9 +353,7 @@
     int ret = 0;
     jlong start, end;
 
-#ifdef MACOSX
-    objc_registerThreadWithCollector();
-#endif
+    RegisterThread();
 
     /* Initialize the virtual machine */
     start = CounterGet();
@@ -487,13 +423,7 @@
      */
     mainClass = LoadMainClass(env, mode, what);
     CHECK_EXCEPTION_NULL_LEAVE(mainClass);
-#ifdef MACOSX
-    // if we got here, we know what the main class is, and it has been loaded
-    SetMainClassForAWT(env, mainClass);
-    jvmInstance = vm;
-    ShowSplashScreen();
-#endif
-
+    PostJVMInit(env, mainClass, vm);
     /*
      * The LoadMainClass not only loads the main class, it will also ensure
      * that the main method's signature is correct, therefore further checking
@@ -1056,12 +986,6 @@
         } else if (JLI_StrCmp(arg, "-X") == 0) {
             printXUsage = JNI_TRUE;
             return JNI_TRUE;
-#ifdef MACOSX
-        } else if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
-            SetXStartOnFirstThreadArg();
-        } else if (JLI_StrCCmp(arg, "-Xdock:") == 0) {
-            SetXDockArgForAWT(arg);
-#endif
 /*
  * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
  * In the latter case, any SUBOPT value not recognized will default to "all"
@@ -1122,7 +1046,9 @@
                    JLI_StrCmp(arg, "-jre-restrict-search") == 0 ||
                    JLI_StrCCmp(arg, "-splash:") == 0) {
             ; /* Ignore machine independent options already handled */
-        } else if (RemovableOption(arg) ) {
+        } else if (ProcessPlatformOption(arg)) {
+            ; /* Processing of platform dependent options */
+        } else if (RemovableOption(arg)) {
             ; /* Do not pass option to vm. */
         } else {
             AddOption(arg, NULL);
@@ -1184,17 +1110,6 @@
     return r == JNI_OK;
 }
 
-
-#define NULL_CHECK0(e) if ((e) == 0) { \
-    JLI_ReportErrorMessage(JNI_ERROR); \
-    return 0; \
-  }
-
-#define NULL_CHECK(e) if ((e) == 0) { \
-    JLI_ReportErrorMessage(JNI_ERROR); \
-    return; \
-  }
-
 static jclass helperClass = NULL;
 
 static jclass
@@ -1660,10 +1575,9 @@
  * mechanism.
  */
 jint
-ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative)
+ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
 {
     FILE *jvmCfg;
-    char jvmCfgName[MAXPATHLEN+20];
     char line[MAXPATHLEN+20];
     int cnt = 0;
     int lineno = 0;
@@ -1676,13 +1590,6 @@
     if (JLI_IsTraceLauncher()) {
         start = CounterGet();
     }
-    JLI_Snprintf(jvmCfgName, sizeof(jvmCfgName), "%s%slib%s%s%sjvm.cfg",
-        jrepath, FILESEP, FILESEP,
-#ifdef MACOSX
-        "", "");
-#else
-        arch, FILESEP);
-#endif
 
     jvmCfg = fopen(jvmCfgName, "r");
     if (jvmCfg == NULL) {
@@ -1842,7 +1749,7 @@
  * Displays the splash screen according to the jar file name
  * and image file names stored in environment variables
  */
-static void
+void
 ShowSplashScreen()
 {
     const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
@@ -1919,8 +1826,9 @@
     return _wc_enabled;
 }
 
-static int
-ContinueInNewThread(InvocationFunctions* ifn, int argc, char **argv,
+int
+ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
+                    int argc, char **argv,
                     int mode, char *what, int ret)
 {
 
@@ -1958,57 +1866,6 @@
     }
 }
 
-#ifdef MACOSX
-static void SetMainClassForAWT(JNIEnv *env, jclass mainClass) {
-    jclass classClass = NULL;
-    NULL_CHECK(classClass = FindBootStrapClass(env, "java/lang/Class"));
-
-    jmethodID getCanonicalNameMID = NULL;
-    NULL_CHECK(getCanonicalNameMID = (*env)->GetMethodID(env, classClass, "getCanonicalName", "()Ljava/lang/String;"));
-
-    jstring mainClassString = NULL;
-    NULL_CHECK(mainClassString = (*env)->CallObjectMethod(env, mainClass, getCanonicalNameMID));
-
-    const char *mainClassName = NULL;
-    NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL));
-
-    char envVar[80];
-    snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid());
-    setenv(envVar, mainClassName, 1);
-
-    (*env)->ReleaseStringUTFChars(env, mainClassString, mainClassName);
-}
-
-static void SetXDockArgForAWT(const char *arg) {
-    char envVar[80];
-    if (strstr(arg, "-Xdock:name=") == arg) {
-        snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
-        setenv(envVar, (arg + 12), 1);
-    }
-
-    if (strstr(arg, "-Xdock:icon=") == arg) {
-        snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
-        setenv(envVar, (arg + 12), 1);
-    }
-}
-
-static void SetXStartOnFirstThreadArg() {
-// XXX: BEGIN HACK
-    // short circuit hack for <https://bugs.eclipse.org/bugs/show_bug.cgi?id=211625>
-    // need a way to get AWT/Swing apps launched when spawned from Eclipse,
-    // which currently has no UI to not pass the -XstartOnFirstThread option
-    if (getenv("HACK_IGNORE_START_ON_FIRST_THREAD") != NULL) return;
-// XXX: END HACK
-
-    continueInSameThread = JNI_TRUE;
-    // Set a variable that tells us we started on the main thread.
-    // This is used by the AWT during startup. (See awt.m)
-    char envVar[80];
-    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
-    setenv(envVar, "1", 1);
-}
-#endif
-
 static void
 DumpState()
 {
--- a/src/share/bin/java.h	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/share/bin/java.h	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
@@ -127,7 +127,8 @@
  */
 void CreateExecutionEnvironment(int *argc, char ***argv,
                                 char *jrepath, jint so_jrepath,
-                                char *jvmpath, jint so_jvmpath);
+                                char *jvmpath, jint so_jvmpath,
+                                char *jvmcfg,  jint so_jvmcfg);
 
 /* Reports an error message to stderr or a window as appropriate. */
 void JLI_ReportErrorMessage(const char * message, ...);
@@ -161,7 +162,7 @@
 /*
  * Functions defined in java.c and used in java_md.c.
  */
-jint ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative);
+jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);
 char *CheckJvmType(int *argc, char ***argv, jboolean speculative);
 void AddOption(char *str, void *info);
 
@@ -180,9 +181,13 @@
 
 jboolean ServerClassMachine();
 
-static int ContinueInNewThread(InvocationFunctions* ifn,
-                               int argc, char** argv,
-                               int mode, char *what, int ret);
+int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
+                   int argc, char** argv,
+                   int mode, char *what, int ret);
+
+int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+                   int argc, char** argv,
+                   int mode, char *what, int ret);
 
 /*
  * Initialize platform specific settings
@@ -190,6 +195,21 @@
 void InitLauncher(jboolean javaw);
 
 /*
+ * For MacOSX and Windows/Unix compatibility we require these
+ * entry points, some of them may be stubbed out on Windows/Unixes.
+ */
+void     PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm);
+void     ShowSplashScreen();
+void     RegisterThread();
+/*
+ * this method performs additional platform specific processing and
+ * should return JNI_TRUE to indicate the argument has been consumed,
+ * otherwise returns JNI_FALSE to allow the calling logic to further
+ * process the option.
+ */
+jboolean ProcessPlatformOption(const char *arg);
+
+/*
  * This allows for finding classes from the VM's bootstrap class loader directly,
  * FindClass uses the application class loader internally, this will cause
  * unnecessary searching of the classpath for the required classes.
@@ -198,4 +218,34 @@
 typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,
                                                   const char *name));
 jclass FindBootStrapClass(JNIEnv *env, const char *classname);
+
+int JNICALL JavaMain(void * args); /* entry point                  */
+
+enum LaunchMode {               // cf. sun.launcher.LauncherHelper
+    LM_UNKNOWN = 0,
+    LM_CLASS,
+    LM_JAR
+};
+
+static const char *launchModeNames[]
+    = { "Unknown", "Main class", "JAR file" };
+
+typedef struct {
+    int    argc;
+    char **argv;
+    int    mode;
+    char  *what;
+    InvocationFunctions ifn;
+} JavaMainArgs;
+
+#define NULL_CHECK0(e) if ((e) == 0) { \
+    JLI_ReportErrorMessage(JNI_ERROR); \
+    return 0; \
+  }
+
+#define NULL_CHECK(e) if ((e) == 0) { \
+    JLI_ReportErrorMessage(JNI_ERROR); \
+    return; \
+  }
+
 #endif /* _JAVA_H_ */
--- a/src/solaris/bin/ergo.c	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/solaris/bin/ergo.c	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
@@ -100,39 +100,14 @@
 /* Compute physical memory by asking the OS */
 uint64_t
 physical_memory(void) {
-  uint64_t result;
-
-# define UINT64_FORMAT "%" PRIu64
-
-#if defined(_ALLBSD_SOURCE)
-#ifdef HW_PHYSMEM64
-  int64_t physmem;
-  int name[2] = { CTL_HW, HW_PHYSMEM64 };
-#else
-  unsigned long physmem;
-  int name[2] = { CTL_HW, HW_PHYSMEM };
-#endif
-  size_t physmem_len = sizeof(physmem);
-
-  if (sysctl(name, 2, &physmem, &physmem_len, NULL, 0) == -1)
-        physmem = 256 * MB;
-
-  result = (uint64_t)physmem;
-
-  JLI_TraceLauncher("physical memory: " UINT64_FORMAT " (%.3fGB)\n",
-           result, result / (double) GB);
-  return result;
-
-#else /* !_ALLBSD_SOURCE */
-
   const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
   const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
-  result    = pages * page_size;
+  const uint64_t result    = pages * page_size;
+# define UINT64_FORMAT "%" PRIu64
 
   JLI_TraceLauncher("pages: " UINT64_FORMAT
           "  page_size: " UINT64_FORMAT
           "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
            pages, page_size, result, result / (double) GB);
   return result;
-#endif /* _ALLBSD_SOURCE */
 }
--- a/src/solaris/bin/ergo.h	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/solaris/bin/ergo.h	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
@@ -33,10 +33,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/types.h>
-#ifdef _ALLBSD_SOURCE
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#endif
 
 #include "java.h"
 
--- a/src/solaris/bin/ergo_i586.c	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/solaris/bin/ergo_i586.c	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
@@ -106,7 +106,7 @@
 
 #endif /* __solaris__ */
 
-#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+#ifdef __linux__
 
 /*
  * A utility method for asking the CPU about itself.
@@ -170,9 +170,7 @@
   *edxp = value_of_edx;
 #endif /* _LP64 */
 }
-#endif /* __linux__ || _ALLBSD_SOURCE */
 
-#ifdef __linux__
 /* The definition of a server-class machine for linux-i586 */
 jboolean
 ServerClassMachineImpl(void) {
@@ -201,37 +199,6 @@
 }
 #endif /* __linux__ */
 
-#if defined(_ALLBSD_SOURCE)
-
-/* The definition of a server-class machine for bsd-i586 */
-jboolean
-ServerClassMachineImpl(void) {
-  jboolean            result            = JNI_FALSE;
-  /* How big is a server class machine? */
-  const unsigned long server_processors = 2UL;
-  const uint64_t      server_memory     = 2UL * GB;
-  /*
-   * We seem not to get our full complement of memory.
-   *     We allow some part (1/8?) of the memory to be "missing",
-   *     based on the sizes of DIMMs, and maybe graphics cards.
-   */
-  const uint64_t      missing_memory    = 256UL * MB;
-  const uint64_t      actual_memory     = physical_memory();
-
-  /* Is this a server class machine? */
-  if (actual_memory >= (server_memory - missing_memory)) {
-    const unsigned long actual_processors = physical_processors();
-    if (actual_processors >= server_processors) {
-      result = JNI_TRUE;
-    }
-  }
-  JLI_TraceLauncher("bsd_" LIBARCHNAME "_ServerClassMachine: %s\n",
-           (result == JNI_TRUE ? "true" : "false"));
-  return result;
-}
-
-#endif /* _ALLBSD_SOURCE */
-
 /*
  * Routines shared by solaris-i586 and linux-i586.
  */
@@ -341,14 +308,6 @@
 /* Compute the number of physical processors, not logical processors */
 static unsigned long
 physical_processors(void) {
-#if defined(_ALLBSD_SOURCE)
-  unsigned long result;
-  int name[2] = { CTL_HW, HW_NCPU };
-  size_t rlen = sizeof(result);
-
-  if (sysctl(name, 2, &result, &rlen, NULL, 0) == -1)
-        result = 1;
-#else /* !_ALLBSD_SOURCE */
   const long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
   unsigned long result      = sys_processors;
 
@@ -359,7 +318,6 @@
       result = (unsigned long) sys_processors / logical_processors;
     }
   }
-#endif /* _ALLBSD_SOURCE */
   JLI_TraceLauncher("physical processors: %lu\n", result);
   return result;
 }
--- a/src/solaris/bin/java_md.c	Tue Jan 24 16:18:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1926 +0,0 @@
-/*
- * Copyright (c) 1998, 2011, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "java.h"
-#include "jvm_md.h"
-#include <dirent.h>
-#include <dlfcn.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#if defined(_ALLBSD_SOURCE)
-#include <sys/time.h>
-#endif
-
-#include "manifest_info.h"
-#include "version_comp.h"
-
-#if defined(__linux__) || defined(_ALLBSD_SOURCE)
-#include <pthread.h>
-#else
-#include <thread.h>
-#endif
-
-#ifdef MACOSX
-/* Support Cocoa event loop on the main thread */
-#include <Cocoa/Cocoa.h>
-#include <objc/objc-runtime.h>
-#include <objc/objc-auto.h>
-#include <errno.h>
-#include <spawn.h>
-
-struct NSAppArgs {
-    int argc;
-    char **argv;
-};
-#endif
-
-#ifdef MACOSX
-#define JVM_DLL "libjvm.dylib"
-#define JAVA_DLL "libjava.dylib"
-/* FALLBACK avoids naming conflicts with system libraries
- * (eg, ImageIO's libJPEG.dylib) */
-#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH"
-#else
-#define JVM_DLL "libjvm.so"
-#define JAVA_DLL "libjava.so"
-#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
-#endif
-
-/* help jettison the LD_LIBRARY_PATH settings in the future */
-#if !defined(SETENV_REQUIRED) && !defined(MACOSX)
-#define SETENV_REQUIRED
-#endif
-/*
- * If a processor / os combination has the ability to run binaries of
- * two data models and cohabitation of jre/jdk bits with both data
- * models is supported, then DUAL_MODE is defined.  When DUAL_MODE is
- * defined, the architecture names for the narrow and wide version of
- * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME.
- * Currently  only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE;
- * linux i586/amd64 could be defined as DUAL_MODE but that is not the
- * current policy.
- */
-
-#ifdef __solaris__
-#  define DUAL_MODE
-#  ifndef LIBARCH32NAME
-#    error "The macro LIBARCH32NAME was not defined on the compile line"
-#  endif
-#  ifndef LIBARCH64NAME
-#    error "The macro LIBARCH64NAME was not defined on the compile line"
-#  endif
-#  include <sys/systeminfo.h>
-#  include <sys/elf.h>
-#  include <stdio.h>
-#endif
-
-/* pointer to environment */
-#ifdef MACOSX
-#include <crt_externs.h>
-#define environ (*_NSGetEnviron())
-#else
-extern char **environ;
-#endif
-
-/*
- *      A collection of useful strings. One should think of these as #define
- *      entries, but actual strings can be more efficient (with many compilers).
- */
-#if defined(__linux__)
-static const char *system_dir   = "/usr/java";
-static const char *user_dir     = "/java";
-#elif defined (__solaris__)
-static const char *system_dir   = "/usr/jdk";
-static const char *user_dir     = "/jdk";
-#elif defined(__APPLE__)
-static const char *system_dir  = PACKAGE_PATH "/openjdk7";
-static const char *user_dir    = "/java";
-#endif
-
-/* Store the name of the executable once computed */
-static char *execname = NULL;
-
-/*
- * Flowchart of launcher execs and options processing on unix
- *
- * The selection of the proper vm shared library to open depends on
- * several classes of command line options, including vm "flavor"
- * options (-client, -server) and the data model options, -d32  and
- * -d64, as well as a version specification which may have come from
- * the command line or from the manifest of an executable jar file.
- * The vm selection options are not passed to the running
- * virtual machine; they must be screened out by the launcher.
- *
- * The version specification (if any) is processed first by the
- * platform independent routine SelectVersion.  This may result in
- * the exec of the specified launcher version.
- *
- * Previously the launcher modified the LD_LIBRARY_PATH appropriately for the
- * desired data model path, regardless if data models matched or not. The
- * launcher subsequently exec'ed the desired executable, in order to make the
- * LD_LIBRARY_PATH path available, for the runtime linker.
- *
- * Now, in most cases,the launcher will dlopen the target libjvm.so. All
- * required libraries are loaded by the runtime linker, using the
- * $RPATH/$ORIGIN baked into the shared libraries at compile time. Therefore,
- * in most cases, the launcher will only exec, if the data models are
- * mismatched, and will not set any environment variables, regardless of the
- * data models.
- *
- * However, if the environment contains a LD_LIBRARY_PATH, this will cause the
- * launcher to inspect the LD_LIBRARY_PATH. The launcher will check
- *  a. if the LD_LIBRARY_PATH's first component is the the path to the desired
- *     libjvm.so
- *  b. if any other libjvm.so is found in any of the paths.
- * If case b is true, then the launcher will set the LD_LIBRARY_PATH to the
- * desired JRE and reexec, in order to propagate the environment.
- *
- *  Main
- *  (incoming argv)
- *  |
- * \|/
- * SelectVersion
- * (selects the JRE version, note: not data model)
- *  |
- * \|/
- * CreateExecutionEnvironment
- * (determines desired data model)
- *  |
- *  |
- * \|/
- *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
- *  |                                          |
- *  |                                          |
- *  |                                         \|/
- *  |                                         YES
- *  |                                          |
- *  |                                          |
- *  |                                         \|/
- *  |                                CheckJvmType
- *  |                               (removes -client, -server etc.)
- *  |                                          |
- *  |                                          |
- * \|/                                        \|/
- * YES                             Find the desired executable/library
- *  |                                          |
- *  |                                          |
- * \|/                                        \|/
- * CheckJvmType                          RequiresSetenv
- * (removes -client, -server, etc.)
- *  |
- *  |
- * \|/
- * TranslateDashJArgs...
- * (Prepare to pass args to vm)
- *  |
- *  |
- * \|/
- * ParseArguments
- * (removes -d32 and -d64 if any,
- *  processes version options,
- *  creates argument list for vm,
- *  etc.)
- *   |
- *   |
- *  \|/
- * RequiresSetenv
- * Is LD_LIBRARY_PATH
- * and friends set ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
- *  YES                              YES --> Continue
- *   |
- *   |
- *  \|/
- * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
- *  NO                               YES --> Continue
- *   |
- *   |
- *  \|/
- * Paths have well known
- * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
- *  YES                              YES --> Continue
- *   |
- *   |
- *  \|/
- *  Does libjvm.so exit
- *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
- *   YES                             YES --> Continue
- *   |
- *   |
- *  \|/
- *  Set the LD_LIBRARY_PATH
- *   |
- *   |
- *  \|/
- * Re-exec
- *   |
- *   |
- *  \|/
- * Main
- */
-
-static const char * SetExecname(char **argv);
-static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
-                           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted);
-static jboolean GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative);
-
-
-#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
-
-const char *
-GetArchPath(int nbits)
-{
-    switch(nbits) {
-#ifdef DUAL_MODE
-        case 32:
-            return LIBARCH32NAME;
-        case 64:
-            return LIBARCH64NAME;
-#endif /* DUAL_MODE */
-        default:
-            return LIBARCHNAME;
-    }
-}
-
-#ifdef MACOSX
-
-/*
- * Exports the JNI interface from libjli
- *
- * This allows client code to link against the .jre/.jdk bundles,
- * and not worry about trying to pick a HotSpot to link against.
- *
- * Switching architectures is unsupported, since client code has
- * made that choice before the JVM was requested.
- */
-
-static InvocationFunctions *sExportedJNIFunctions = NULL;
-static char *sPreferredJVMType = NULL;
-
-static InvocationFunctions *GetExportedJNIFunctions() {
-    if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions;
-
-    char jrePath[PATH_MAX];
-    jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE);
-    if (!gotJREPath) {
-        JLI_ReportErrorMessage("Failed to GetJREPath()");
-        return NULL;
-    }
-
-    char *preferredJVM = sPreferredJVMType;
-    if (preferredJVM == NULL) {
-#if defined(__i386__)
-        preferredJVM = "client";
-#elif defined(__x86_64__)
-        preferredJVM = "server";
-#else
-#error "Unknown architecture - needs definition"
-#endif
-    }
-
-    char jvmPath[PATH_MAX];
-    jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath), GetArch(), CURRENT_DATA_MODEL);
-    if (!gotJVMPath) {
-        JLI_ReportErrorMessage("Failed to GetJVMPath()");
-        return NULL;
-    }
-
-    InvocationFunctions *fxns = malloc(sizeof(InvocationFunctions));
-    jboolean vmLoaded = LoadJavaVM(jvmPath, fxns);
-    if (!vmLoaded) {
-        JLI_ReportErrorMessage("Failed to LoadJavaVM()");
-        return NULL;
-    }
-
-    return sExportedJNIFunctions = fxns;
-}
-
-JNIEXPORT jint JNICALL
-JNI_GetDefaultJavaVMInitArgs(void *args) {
-    InvocationFunctions *ifn = GetExportedJNIFunctions();
-    if (ifn == NULL) return JNI_ERR;
-    return ifn->GetDefaultJavaVMInitArgs(args);
-}
-
-JNIEXPORT jint JNICALL
-JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) {
-    InvocationFunctions *ifn = GetExportedJNIFunctions();
-    if (ifn == NULL) return JNI_ERR;
-    return ifn->CreateJavaVM(pvm, penv, args);
-}
-
-JNIEXPORT jint JNICALL
-JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs) {
-    InvocationFunctions *ifn = GetExportedJNIFunctions();
-    if (ifn == NULL) return JNI_ERR;
-    return ifn->GetCreatedJavaVMs(vmBuf, bufLen, nVMs);
-}
-
-/*
- * Allow JLI-aware launchers to specify a client/server preference
- */
-JNIEXPORT void JNICALL
-JLI_SetPreferredJVM(const char *prefJVM) {
-    if (sPreferredJVMType != NULL) {
-        free(sPreferredJVMType);
-        sPreferredJVMType = NULL;
-    }
-
-    if (prefJVM == NULL) return;
-    sPreferredJVMType = strdup(prefJVM);
-}
-
-static BOOL awtLoaded = NO;
-static pthread_mutex_t awtLoaded_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t  awtLoaded_cv = PTHREAD_COND_INITIALIZER;
-
-JNIEXPORT void JNICALL
-JLI_NotifyAWTLoaded()
-{
-    pthread_mutex_lock(&awtLoaded_mutex);
-    awtLoaded = YES;
-    pthread_cond_signal(&awtLoaded_cv);
-    pthread_mutex_unlock(&awtLoaded_mutex);
-}
-
-static int (*main_fptr)(int argc, char **argv) = NULL;
-
-/*
- * Unwrap the arguments and re-run main()
- */
-static void *apple_main (void *arg)
-{
-    objc_registerThreadWithCollector();
-
-    if (main_fptr == NULL) {
-        main_fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
-        if (main_fptr == NULL) {
-            JLI_ReportErrorMessageSys("error locating main entrypoint\n");
-            exit(1);
-        }
-    }
-
-    struct NSAppArgs *args = (struct NSAppArgs *) arg;
-    exit(main_fptr(args->argc, args->argv));
-}
-
-static void dummyTimer(CFRunLoopTimerRef timer, void *info) {}
-
-static void ParkEventLoop() {
-    // RunLoop needs at least one source, and 1e20 is pretty far into the future
-    CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL);
-    CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
-    CFRelease(t);
-
-    // Park this thread in the main run loop.
-    int32_t result;
-    do {
-        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false);
-    } while (result != kCFRunLoopRunFinished);
-}
-
-/*
- * Mac OS X mandates that the GUI event loop run on very first thread of
- * an application. This requires that we re-call Java's main() on a new
- * thread, reserving the 'main' thread for Cocoa.
- */
-static void MacOSXStartup(int argc, char *argv[]) {
-    // Thread already started?
-    static jboolean started = false;
-    if (started) {
-        return;
-    }
-    started = true;
-
-    // Hand off arguments
-    struct NSAppArgs args;
-    args.argc = argc;
-    args.argv = argv;
-
-    // Fire up the main thread
-    pthread_t main_thr;
-    if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
-        JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
-        exit(1);
-    }
-    if (pthread_detach(main_thr)) {
-        JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
-        exit(1);
-    }
-
-    ParkEventLoop();
-}
-
-#endif
-#ifdef SETENV_REQUIRED
-static jboolean
-JvmExists(const char *path) {
-    char tmp[PATH_MAX + 1];
-    struct stat statbuf;
-    JLI_Snprintf(tmp, PATH_MAX, "%s/%s", path, JVM_DLL);
-    if (stat(tmp, &statbuf) == 0) {
-        return JNI_TRUE;
-    }
-    return JNI_FALSE;
-}
-/*
- * contains a lib/$LIBARCH/{server,client}/libjvm.so ?
- */
-static jboolean
-ContainsLibJVM(int wanted, const char *env) {
-    char clientPattern[PATH_MAX + 1];
-    char serverPattern[PATH_MAX + 1];
-    char *envpath;
-    char *path;
-    jboolean clientPatternFound;
-    jboolean serverPatternFound;
-
-    /* fastest path */
-    if (env == NULL) {
-        return JNI_FALSE;
-    }
-
-    /* the usual suspects */
-    JLI_Snprintf(clientPattern, PATH_MAX, "lib/%s/client", GetArchPath(wanted));
-    JLI_Snprintf(serverPattern, PATH_MAX, "lib/%s/server", GetArchPath(wanted));
-
-    /* to optimize for time, test if any of our usual suspects are present. */
-    clientPatternFound = JLI_StrStr(env, clientPattern) != NULL;
-    serverPatternFound = JLI_StrStr(env, serverPattern) != NULL;
-    if (clientPatternFound == JNI_FALSE && serverPatternFound == JNI_FALSE) {
-        return JNI_FALSE;
-    }
-
-    /*
-     * we have a suspicious path component, check if it contains a libjvm.so
-     */
-    envpath = JLI_StringDup(env);
-    for (path = JLI_StrTok(envpath, ":"); path != NULL; path = JLI_StrTok(NULL, ":")) {
-        if (clientPatternFound && JLI_StrStr(path, clientPattern) != NULL) {
-            if (JvmExists(path)) {
-                JLI_MemFree(envpath);
-                return JNI_TRUE;
-            }
-        }
-        if (serverPatternFound && JLI_StrStr(path, serverPattern)  != NULL) {
-            if (JvmExists(path)) {
-                JLI_MemFree(envpath);
-                return JNI_TRUE;
-            }
-        }
-    }
-    JLI_MemFree(envpath);
-    return JNI_FALSE;
-}
-
-/*
- * Test whether the environment variable needs to be set, see flowchart.
- */
-static jboolean
-RequiresSetenv(int wanted, const char *jvmpath) {
-    char jpath[PATH_MAX + 1];
-    char *llp;
-    char *dmllp = NULL;
-    char *p; /* a utility pointer */
-
-    llp = getenv("LD_LIBRARY_PATH");
-#ifdef __solaris__
-    dmllp = (CURRENT_DATA_MODEL == 32)
-            ? getenv("LD_LIBRARY_PATH_32")
-            : getenv("LD_LIBRARY_PATH_64");
-#endif /* __solaris__ */
-    /* no environment variable is a good environment variable */
-    if (llp == NULL && dmllp == NULL) {
-        return JNI_FALSE;
-    }
-#ifdef __linux
-    /*
-     * On linux, if a binary is running as sgid or suid, glibc sets
-     * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
-     * on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
-     * lose its settings; but the dynamic linker does apply more scrutiny to the
-     * path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec
-     * loop, here and further downstream. Therefore, if we are running sgid or
-     * suid, this function's setting of LD_LIBRARY_PATH will be ineffective and
-     * we should case a return from the calling function.  Getting the right
-     * libraries will be handled by the RPATH. In reality, this check is
-     * redundant, as the previous check for a non-null LD_LIBRARY_PATH will
-     * return back to the calling function forthwith, it is left here to safe
-     * guard against any changes, in the glibc's existing security policy.
-     */
-    if ((getgid() != getegid()) || (getuid() != geteuid())) {
-        return JNI_FALSE;
-    }
-#endif /* __linux */
-
-    /*
-     * Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
-     * previous versions of the JRE, thus it is the only path that matters here.
-     * So we check to see if the desired JRE is set.
-     */
-    JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
-    p = JLI_StrRChr(jpath, '/');
-    *p = '\0';
-    if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) {
-        return JNI_FALSE;
-    }
-
-    /* scrutinize all the paths further */
-    if (llp != NULL &&  ContainsLibJVM(wanted, llp)) {
-        return JNI_TRUE;
-    }
-    if (dmllp != NULL && ContainsLibJVM(wanted, dmllp)) {
-        return JNI_TRUE;
-    }
-    return JNI_FALSE;
-}
-#endif /* SETENV_REQUIRED */
-
-void
-CreateExecutionEnvironment(int *pargc, char ***pargv,
-                           char jrepath[], jint so_jrepath,
-                           char jvmpath[], jint so_jvmpath) {
-  /*
-   * First, determine if we are running the desired data model.  If we
-   * are running the desired data model, all the error messages
-   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
-   * output.  However, if we are not running the desired data model,
-   * some of the errors should be suppressed since it is more
-   * informative to issue an error message based on whether or not the
-   * os/processor combination has dual mode capabilities.
-   */
-    jboolean jvmpathExists;
-
-    /* Compute/set the name of the executable */
-    SetExecname(*pargv);
-
-    /* Check data model flags, and exec process, if needed */
-    {
-      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
-      char * jvmtype    = NULL;
-      int  argc         = *pargc;
-      char **argv       = *pargv;
-      int running       = CURRENT_DATA_MODEL;
-
-      int wanted        = running;      /* What data mode is being
-                                           asked for? Current model is
-                                           fine unless another model
-                                           is asked for */
-#ifdef SETENV_REQUIRED
-      jboolean mustsetenv = JNI_FALSE;
-      char *runpath     = NULL; /* existing effective LD_LIBRARY_PATH setting */
-      char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
-      char* newpath     = NULL; /* path on new LD_LIBRARY_PATH */
-      char* lastslash   = NULL;
-      char** newenvp    = NULL; /* current environment */
-#ifdef __solaris__
-      char*  dmpath     = NULL;  /* data model specific LD_LIBRARY_PATH,
-                                    Solaris only */
-#endif /* __solaris__ */
-#endif  /* SETENV_REQUIRED */
-
-      char** newargv    = NULL;
-      int    newargc    = 0;
-
-      /*
-       * Starting in 1.5, all unix platforms accept the -d32 and -d64
-       * options.  On platforms where only one data-model is supported
-       * (e.g. ia-64 Linux), using the flag for the other data model is
-       * an error and will terminate the program.
-       */
-
-      { /* open new scope to declare local variables */
-        int i;
-
-        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
-        newargv[newargc++] = argv[0];
-
-        /* scan for data model arguments and remove from argument list;
-           last occurrence determines desired data model */
-        for (i=1; i < argc; i++) {
-
-          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
-            wanted = 64;
-            continue;
-          }
-          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
-            wanted = 32;
-            continue;
-          }
-          newargv[newargc++] = argv[i];
-
-          if (IsJavaArgs()) {
-            if (argv[i][0] != '-') continue;
-          } else {
-            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
-              i++;
-              if (i >= argc) break;
-              newargv[newargc++] = argv[i];
-              continue;
-            }
-            if (argv[i][0] != '-') { i++; break; }
-          }
-        }
-
-        /* copy rest of args [i .. argc) */
-        while (i < argc) {
-          newargv[newargc++] = argv[i++];
-        }
-        newargv[newargc] = NULL;
-
-        /*
-         * newargv has all proper arguments here
-         */
-
-        argc = newargc;
-        argv = newargv;
-      }
-
-      /* If the data model is not changing, it is an error if the
-         jvmpath does not exist */
-      if (wanted == running) {
-        /* Find out where the JRE is that we will be using. */
-        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
-          JLI_ReportErrorMessage(JRE_ERROR1);
-          exit(2);
-        }
-
-        /* Find the specified JVM type */
-        if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) {
-          JLI_ReportErrorMessage(CFG_ERROR7);
-          exit(1);
-        }
-
-        jvmpath[0] = '\0';
-        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
-        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
-            JLI_ReportErrorMessage(CFG_ERROR9);
-            exit(4);
-        }
-
-        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, wanted)) {
-          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
-          exit(4);
-        }
-
-#ifdef MACOSX
-        /*
-         * Mac OS X requires the Cocoa event loop to be run on the "main"
-         * thread. Spawn off a new thread to run main() and pass
-         * this thread off to the Cocoa event loop.
-         */
-        MacOSXStartup(argc, argv);
-#endif
-        /*
-         * we seem to have everything we need, so without further ado
-         * we return back, otherwise proceed to set the environment.
-         */
-#ifdef SETENV_REQUIRED
-        mustsetenv = RequiresSetenv(wanted, jvmpath);
-        JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE");
-
-        if (mustsetenv == JNI_FALSE) {
-            return;
-        }
-#else
-        return;
-#endif /* SETENV_REQUIRED */
-      } else {  /* do the same speculatively or exit */
-#if defined(DUAL_MODE) || defined(MACOSX)
-        if (running != wanted) {
-          /* Find out where the JRE is that we will be using. */
-          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
-            /* give up and let other code report error message */
-            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
-            exit(1);
-          }
-
-          /*
-           * Read in jvm.cfg for target data model and process vm
-           * selection options.
-           */
-          if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) {
-            /* give up and let other code report error message */
-            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
-            exit(1);
-          }
-          jvmpath[0] = '\0';
-          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
-          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
-            JLI_ReportErrorMessage(CFG_ERROR9);
-            exit(4);
-          }
-
-          /* exec child can do error checking on the existence of the path */
-          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), wanted);
-#ifdef SETENV_REQUIRED
-          mustsetenv = RequiresSetenv(wanted, jvmpath);
-#endif /* SETENV_REQUIRED */
-        }
-#else
-        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
-        exit(1);
-#endif
-        }
-#ifdef SETENV_REQUIRED
-        if (mustsetenv) {
-            /*
-             * We will set the LD_LIBRARY_PATH as follows:
-             *
-             *     o          $JVMPATH (directory portion only)
-             *     o          $JRE/lib/$LIBARCHNAME
-             *     o          $JRE/../lib/$LIBARCHNAME
-             *
-             * followed by the user's previous effective LD_LIBRARY_PATH, if
-             * any.
-             */
-
-#ifdef __solaris__
-            /*
-             * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH
-             * variables:
-             *
-             * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if
-             * data-model specific variables are not set.
-             *
-             * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH
-             * for 64-bit binaries.
-             *
-             * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH
-             * for 32-bit binaries.
-             *
-             * The vm uses LD_LIBRARY_PATH to set the java.library.path system
-             * property.  To shield the vm from the complication of multiple
-             * LD_LIBRARY_PATH variables, if the appropriate data model
-             * specific variable is set, we will act as if LD_LIBRARY_PATH had
-             * the value of the data model specific variant and the data model
-             * specific variant will be unset.  Note that the variable for the
-             * *wanted* data model must be used (if it is set), not simply the
-             * current running data model.
-             */
-
-            switch (wanted) {
-                case 0:
-                    if (running == 32) {
-                        dmpath = getenv("LD_LIBRARY_PATH_32");
-                        wanted = 32;
-                    } else {
-                        dmpath = getenv("LD_LIBRARY_PATH_64");
-                        wanted = 64;
-                    }
-                    break;
-
-                case 32:
-                    dmpath = getenv("LD_LIBRARY_PATH_32");
-                    break;
-
-                case 64:
-                    dmpath = getenv("LD_LIBRARY_PATH_64");
-                    break;
-
-                default:
-                    JLI_ReportErrorMessage(JRE_ERROR3, __LINE__);
-                    exit(1); /* unknown value in wanted */
-                    break;
-            }
-
-            /*
-             * If dmpath is NULL, the relevant data model specific variable is
-             * not set and normal LD_LIBRARY_PATH should be used.
-             */
-            if (dmpath == NULL) {
-                runpath = getenv("LD_LIBRARY_PATH");
-            } else {
-                runpath = dmpath;
-            }
-#else
-            /*
-             * If not on Solaris, assume only a single LD_LIBRARY_PATH
-             * variable.
-             */
-            runpath = getenv("LD_LIBRARY_PATH");
-#endif /* __solaris__ */
-
-            /* runpath contains current effective LD_LIBRARY_PATH setting */
-
-            jvmpath = JLI_StringDup(jvmpath);
-            new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
-                    2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
-                    JLI_StrLen(jvmpath) + 52);
-            newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH=");
-
-
-            /*
-             * Create desired LD_LIBRARY_PATH value for target data model.
-             */
-            {
-                /* remove the name of the .so from the JVM path */
-                lastslash = JLI_StrRChr(jvmpath, '/');
-                if (lastslash)
-                    *lastslash = '\0';
-
-                sprintf(new_runpath, "LD_LIBRARY_PATH="
-                        "%s:"
-                        "%s/lib/%s:"
-                        "%s/../lib/%s",
-                        jvmpath,
-#ifdef DUAL_MODE
-                        jrepath, GetArchPath(wanted),
-                        jrepath, GetArchPath(wanted)
-#else
-                        jrepath, arch,
-                        jrepath, arch
-#endif
-                        );
-
-
-                /*
-                 * Check to make sure that the prefix of the current path is the
-                 * desired environment variable setting, though the RequiresSetenv
-                 * checks if the desired runpath exists, this logic does a more
-                 * comprehensive check.
-                 */
-                if (runpath != NULL &&
-                        JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
-                        (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
-                        (running == wanted) /* data model does not have to be changed */
-#ifdef __solaris__
-                        && (dmpath == NULL) /* data model specific variables not set  */
-#endif
-                        ) {
-
-                    return;
-
-                }
-            }
-
-            /*
-             * Place the desired environment setting onto the prefix of
-             * LD_LIBRARY_PATH.  Note that this prevents any possible infinite
-             * loop of execv() because we test for the prefix, above.
-             */
-            if (runpath != 0) {
-                JLI_StrCat(new_runpath, ":");
-                JLI_StrCat(new_runpath, runpath);
-            }
-
-            if (putenv(new_runpath) != 0) {
-                exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
-                    properly */
-            }
-
-            /*
-             * Unix systems document that they look at LD_LIBRARY_PATH only
-             * once at startup, so we have to re-exec the current executable
-             * to get the changed environment variable to have an effect.
-             */
-
-#ifdef __solaris__
-            /*
-             * If dmpath is not NULL, remove the data model specific string
-             * in the environment for the exec'ed child.
-             */
-            if (dmpath != NULL)
-                (void)UnsetEnv((wanted == 32) ? "LD_LIBRARY_PATH_32" : "LD_LIBRARY_PATH_64");
-#endif
-
-            newenvp = environ;
-        }
-#endif /* SETENV_REQUIRED */
-        {
-            char *newexec = execname;
-#ifdef DUAL_MODE
-            /*
-             * If the data model is being changed, the path to the
-             * executable must be updated accordingly; the executable name
-             * and directory the executable resides in are separate.  In the
-             * case of 32 => 64, the new bits are assumed to reside in, e.g.
-             * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32,
-             * the bits are assumed to be in "olddir/../execname".  For example,
-             *
-             * olddir/sparcv9/execname
-             * olddir/amd64/execname
-             *
-             * for Solaris SPARC and Linux amd64, respectively.
-             */
-
-            if (running != wanted) {
-                char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname);
-                char *olddir = oldexec;
-                char *oldbase = JLI_StrRChr(oldexec, '/');
-
-
-                newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20);
-                *oldbase++ = 0;
-                sprintf(newexec, "%s/%s/%s", olddir,
-                        ((wanted == 64) ? LIBARCH64NAME : ".."), oldbase);
-                argv[0] = newexec;
-            }
-#endif /* DUAL_MODE */
-            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
-            (void) fflush(stdout);
-            (void) fflush(stderr);
-#ifdef SETENV_REQUIRED
-            if (mustsetenv) {
-                execve(newexec, argv, newenvp);
-            } else {
-                execv(newexec, argv);
-            }
-#else
-#ifdef MACOSX
-            /*
-            * Use posix_spawn() instead of execv() on Mac OS X.
-            * This allows us to choose which architecture the child process
-            * should run as.
-            */
-            {
-                posix_spawnattr_t attr;
-                size_t unused_size;
-                pid_t  unused_pid;
-
-#if defined(__i386__) || defined(__x86_64__)
-                cpu_type_t cpu_type[] = { (wanted == 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86,
-                                    (running== 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86 };
-#else
-                cpu_type_t cpu_type[] = { CPU_TYPE_ANY };
-#endif
-
-                posix_spawnattr_init(&attr);
-                posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC);
-                posix_spawnattr_setbinpref_np(&attr, sizeof(cpu_type) / sizeof(cpu_type_t),
-                                            cpu_type, &unused_size);
-
-                posix_spawn(&unused_pid, newexec, NULL, &attr, argv, environ);
-            }
-#else
-            execv(newexec, argv);
-#endif
-#endif /* SETENV_REQUIRED */
-            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
-
-#if defined(DUAL_MODE) || defined(MACOSX)
-            if (running != wanted) {
-                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
-#ifdef __solaris__
-#ifdef __sparc
-                JLI_ReportErrorMessage(JRE_ERROR6);
-#else
-                JLI_ReportErrorMessage(JRE_ERROR7);
-#endif  /* __sparc */
-#endif /* __solaris__ */
-            }
-#endif /* DUAL_MODE */
-
-        }
-        exit(1);
-    }
-}
-
-/*
- * On Solaris VM choosing is done by the launcher (java.c).
- */
-static jboolean
-GetJVMPath(const char *jrepath, const char *jvmtype,
-           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted)
-{
-    struct stat s;
-
-    if (JLI_StrChr(jvmtype, '/')) {
-        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
-    } else {
-#ifdef MACOSX
-        // macosx client library is built thin, i386 only.  64 bit client requests must load server library
-        const char *jvmtypeUsed = ((bitsWanted == 64) && (strcmp(jvmtype, "client") == 0)) ? "server" : jvmtype;
-        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jrepath, jvmtypeUsed);
-#else
-        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
-#endif
-    }
-
-    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
-
-    if (stat(jvmpath, &s) == 0) {
-        JLI_TraceLauncher("yes.\n");
-        return JNI_TRUE;
-    } else {
-        JLI_TraceLauncher("no.\n");
-        return JNI_FALSE;
-    }
-}
-
-/*
- * Find path to JRE based on .exe's location or registry settings.
- */
-static jboolean
-GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
-{
-    char libjava[MAXPATHLEN];
-
-    if (GetApplicationHome(path, pathsize)) {
-
-#ifdef MACOSX
-        /* Is JRE co-located with the application? */
-        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
-        if (access(libjava, F_OK) == 0) {
-            return JNI_TRUE;
-        }
-
-        /* Does the app ship a private JRE in <apphome>/jre directory? */
-        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
-        if (access(libjava, F_OK) == 0) {
-            JLI_StrCat(path, "/jre");
-            JLI_TraceLauncher("JRE path is %s\n", path);
-            return JNI_TRUE;
-        }
-#else
-        /* Is JRE co-located with the application? */
-        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
-        if (access(libjava, F_OK) == 0) {
-            JLI_TraceLauncher("JRE path is %s\n", path);
-            return JNI_TRUE;
-        }
-
-        /* Does the app ship a private JRE in <apphome>/jre directory? */
-        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
-        if (access(libjava, F_OK) == 0) {
-            JLI_StrCat(path, "/jre");
-            JLI_TraceLauncher("JRE path is %s\n", path);
-            return JNI_TRUE;
-        }
-#endif
-    }
-
-#ifdef MACOSX
-
-    /* try to find ourselves instead */
-    Dl_info selfInfo;
-    dladdr(&GetJREPath, &selfInfo);
-
-    char *realPathToSelf = realpath(selfInfo.dli_fname, path);
-    if (realPathToSelf != path) {
-        return JNI_FALSE;
-    }
-
-    size_t pathLen = strlen(realPathToSelf);
-    if (pathLen == 0) {
-        return JNI_FALSE;
-    }
-
-    const char lastPathComponent[] = "/lib/jli/libjli.dylib";
-    size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
-    if (pathLen < sizeOfLastPathComponent) {
-        return JNI_FALSE;
-    }
-
-    size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
-    if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
-        realPathToSelf[indexOfLastPathComponent + 1] = '\0';
-        return JNI_TRUE;
-    }
-
-#endif
-
-    if (!speculative)
-      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
-    return JNI_FALSE;
-}
-
-jboolean
-LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
-{
-    Dl_info dlinfo;
-    void *libjvm;
-
-    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
-
-    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
-    if (libjvm == NULL) {
-#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */
-      FILE * fp;
-      Elf32_Ehdr elf_head;
-      int count;
-      int location;
-
-      fp = fopen(jvmpath, "r");
-      if (fp == NULL) {
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-      }
-
-      /* read in elf header */
-      count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
-      fclose(fp);
-      if (count < 1) {
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-      }
-
-      /*
-       * Check for running a server vm (compiled with -xarch=v8plus)
-       * on a stock v8 processor.  In this case, the machine type in
-       * the elf header would not be included the architecture list
-       * provided by the isalist command, which is turn is gotten from
-       * sysinfo.  This case cannot occur on 64-bit hardware and thus
-       * does not have to be checked for in binaries with an LP64 data
-       * model.
-       */
-      if (elf_head.e_machine == EM_SPARC32PLUS) {
-        char buf[257];  /* recommended buffer size from sysinfo man
-                           page */
-        long length;
-        char* location;
-
-        length = sysinfo(SI_ISALIST, buf, 257);
-        if (length > 0) {
-            location = JLI_StrStr(buf, "sparcv8plus ");
-          if (location == NULL) {
-            JLI_ReportErrorMessage(JVM_ERROR3);
-            return JNI_FALSE;
-          }
-        }
-      }
-#endif
-        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-    }
-
-    ifn->CreateJavaVM = (CreateJavaVM_t)
-        dlsym(libjvm, "JNI_CreateJavaVM");
-    if (ifn->CreateJavaVM == NULL) {
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-    }
-
-    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
-        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
-    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-    }
-
-    ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t)
-    dlsym(libjvm, "JNI_GetCreatedJavaVMs");
-    if (ifn->GetCreatedJavaVMs == NULL) {
-        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
-        return JNI_FALSE;
-    }
-
-    return JNI_TRUE;
-}
-
-/*
- * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
- * "/foo" into buf.
- */
-jboolean
-GetApplicationHome(char *buf, jint bufsize)
-{
-    if (execname != NULL) {
-        JLI_Snprintf(buf, bufsize, "%s", execname);
-        buf[bufsize-1] = '\0';
-    } else {
-        return JNI_FALSE;
-    }
-
-    if (JLI_StrRChr(buf, '/') == 0) {
-        buf[0] = '\0';
-        return JNI_FALSE;
-    }
-    *(JLI_StrRChr(buf, '/')) = '\0';    /* executable file      */
-    if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) {
-        buf[0] = '\0';
-        return JNI_FALSE;
-    }
-    if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0)
-        *(JLI_StrRChr(buf, '/')) = '\0';        /* sparcv9 or amd64     */
-    if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) {
-        buf[0] = '\0';
-        return JNI_FALSE;
-    }
-    *(JLI_StrRChr(buf, '/')) = '\0';    /* bin                  */
-
-    return JNI_TRUE;
-}
-
-
-/*
- * Return true if the named program exists
- */
-static int
-ProgramExists(char *name)
-{
-    struct stat sb;
-    if (stat(name, &sb) != 0) return 0;
-    if (S_ISDIR(sb.st_mode)) return 0;
-    return (sb.st_mode & S_IEXEC) != 0;
-}
-
-
-/*
- * Find a command in a directory, returning the path.
- */
-static char *
-Resolve(char *indir, char *cmd)
-{
-    char name[PATH_MAX + 2], *real;
-
-    if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1)  > PATH_MAX) return 0;
-    JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
-    if (!ProgramExists(name)) return 0;
-    real = JLI_MemAlloc(PATH_MAX + 2);
-    if (!realpath(name, real))
-        JLI_StrCpy(real, name);
-    return real;
-}
-
-
-/*
- * Find a path for the executable
- */
-static char *
-FindExecName(char *program)
-{
-    char cwdbuf[PATH_MAX+2];
-    char *path;
-    char *tmp_path;
-    char *f;
-    char *result = NULL;
-
-    /* absolute path? */
-    if (*program == FILE_SEPARATOR ||
-        (FILE_SEPARATOR=='\\' && JLI_StrRChr(program, ':')))
-        return Resolve("", program+1);
-
-    /* relative path? */
-    if (JLI_StrRChr(program, FILE_SEPARATOR) != 0) {
-        char buf[PATH_MAX+2];
-        return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program);
-    }
-
-    /* from search path? */
-    path = getenv("PATH");
-    if (!path || !*path) path = ".";
-    tmp_path = JLI_MemAlloc(JLI_StrLen(path) + 2);
-    JLI_StrCpy(tmp_path, path);
-
-    for (f=tmp_path; *f && result==0; ) {
-        char *s = f;
-        while (*f && (*f != PATH_SEPARATOR)) ++f;
-        if (*f) *f++ = 0;
-        if (*s == FILE_SEPARATOR)
-            result = Resolve(s, program);
-        else {
-            /* relative path element */
-            char dir[2*PATH_MAX];
-            JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
-                    FILE_SEPARATOR, s);
-            result = Resolve(dir, program);
-        }
-        if (result != 0) break;
-    }
-
-    JLI_MemFree(tmp_path);
-    return result;
-}
-
-
-
-/*
- * Compute the name of the executable
- *
- * In order to re-exec securely we need the absolute path of the
- * executable. On Solaris getexecname(3c) may not return an absolute
- * path so we use dladdr to get the filename of the executable and
- * then use realpath to derive an absolute path. From Solaris 9
- * onwards the filename returned in DL_info structure from dladdr is
- * an absolute pathname so technically realpath isn't required.
- * On Linux we read the executable name from /proc/self/exe.
- * As a fallback, and for platforms other than Solaris and Linux,
- * we use FindExecName to compute the executable name.
- */
-static const char*
-SetExecname(char **argv)
-{
-    char* exec_path = NULL;
-#if defined(__solaris__) || defined(__APPLE__)
-    {
-        Dl_info dlinfo;
-        int (*fptr)();
-
-        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
-        if (fptr == NULL) {
-            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
-            return JNI_FALSE;
-        }
-
-        if (dladdr((void*)fptr, &dlinfo)) {
-            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
-            if (resolved != NULL) {
-                exec_path = realpath(dlinfo.dli_fname, resolved);
-                if (exec_path == NULL) {
-                    JLI_MemFree(resolved);
-                }
-            }
-        }
-    }
-#elif defined(__linux__)
-    {
-        const char* self = "/proc/self/exe";
-        char buf[PATH_MAX+1];
-        int len = readlink(self, buf, PATH_MAX);
-        if (len >= 0) {
-            buf[len] = '\0';            /* readlink doesn't nul terminate */
-            exec_path = JLI_StringDup(buf);
-        }
-    }
-#else /* !__solaris__ && !__APPLE__ && !__linux__ */
-    {
-        /* Not implemented */
-    }
-#endif
-
-    if (exec_path == NULL) {
-        exec_path = FindExecName(argv[0]);
-    }
-    execname = exec_path;
-    return exec_path;
-}
-
-void JLI_ReportErrorMessage(const char* fmt, ...) {
-    va_list vl;
-    va_start(vl, fmt);
-    vfprintf(stderr, fmt, vl);
-    fprintf(stderr, "\n");
-    va_end(vl);
-}
-
-void JLI_ReportErrorMessageSys(const char* fmt, ...) {
-    va_list vl;
-    char *emsg;
-
-    /*
-     * TODO: its safer to use strerror_r but is not available on
-     * Solaris 8. Until then....
-     */
-    emsg = strerror(errno);
-    if (emsg != NULL) {
-        fprintf(stderr, "%s\n", emsg);
-    }
-
-    va_start(vl, fmt);
-    vfprintf(stderr, fmt, vl);
-    fprintf(stderr, "\n");
-    va_end(vl);
-}
-
-void  JLI_ReportExceptionDescription(JNIEnv * env) {
-  (*env)->ExceptionDescribe(env);
-}
-
-/*
- *      Since using the file system as a registry is a bit risky, perform
- *      additional sanity checks on the identified directory to validate
- *      it as a valid jre/sdk.
- *
- *      Return 0 if the tests fail; otherwise return non-zero (true).
- *
- *      Note that checking for anything more than the existence of an
- *      executable object at bin/java relative to the path being checked
- *      will break the regression tests.
- */
-static int
-CheckSanity(char *path, char *dir)
-{
-    char    buffer[PATH_MAX];
-
-    if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
-        return (0);     /* Silently reject "impossibly" long paths */
-
-    JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
-    return ((access(buffer, X_OK) == 0) ? 1 : 0);
-}
-
-/*
- *      Determine if there is an acceptable JRE in the directory dirname.
- *      Upon locating the "best" one, return a fully qualified path to
- *      it. "Best" is defined as the most advanced JRE meeting the
- *      constraints contained in the manifest_info. If no JRE in this
- *      directory meets the constraints, return NULL.
- *
- *      Note that we don't check for errors in reading the directory
- *      (which would be done by checking errno).  This is because it
- *      doesn't matter if we get an error reading the directory, or
- *      we just don't find anything interesting in the directory.  We
- *      just return NULL in either case.
- *
- *      The historical names of j2sdk and j2re were changed to jdk and
- *      jre respecively as part of the 1.5 rebranding effort.  Since the
- *      former names are legacy on Linux, they must be recognized for
- *      all time.  Fortunately, this is a minor cost.
- */
-static char
-*ProcessDir(manifest_info *info, char *dirname)
-{
-    DIR     *dirp;
-    struct dirent *dp;
-    char    *best = NULL;
-    int     offset;
-    int     best_offset = 0;
-    char    *ret_str = NULL;
-    char    buffer[PATH_MAX];
-
-    if ((dirp = opendir(dirname)) == NULL)
-        return (NULL);
-
-    do {
-        if ((dp = readdir(dirp)) != NULL) {
-            offset = 0;
-            if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
-                (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
-                offset = 3;
-            else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
-                offset = 4;
-            else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
-                offset = 5;
-            if (offset > 0) {
-                if ((JLI_AcceptableRelease(dp->d_name + offset,
-                    info->jre_version)) && CheckSanity(dirname, dp->d_name))
-                    if ((best == NULL) || (JLI_ExactVersionId(
-                      dp->d_name + offset, best + best_offset) > 0)) {
-                        if (best != NULL)
-                            JLI_MemFree(best);
-                        best = JLI_StringDup(dp->d_name);
-                        best_offset = offset;
-                    }
-            }
-        }
-    } while (dp != NULL);
-    (void) closedir(dirp);
-    if (best == NULL)
-        return (NULL);
-    else {
-        ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
-        sprintf(ret_str, "%s/%s", dirname, best);
-        JLI_MemFree(best);
-        return (ret_str);
-    }
-}
-
-/*
- *      This is the global entry point. It examines the host for the optimal
- *      JRE to be used by scanning a set of directories.  The set of directories
- *      is platform dependent and can be overridden by the environment
- *      variable JAVA_VERSION_PATH.
- *
- *      This routine itself simply determines the set of appropriate
- *      directories before passing control onto ProcessDir().
- */
-char*
-LocateJRE(manifest_info* info)
-{
-    char        *path;
-    char        *home;
-    char        *target = NULL;
-    char        *dp;
-    char        *cp;
-
-    /*
-     * Start by getting JAVA_VERSION_PATH
-     */
-    if (info->jre_restrict_search) {
-        path = JLI_StringDup(system_dir);
-    } else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) {
-        path = JLI_StringDup(path);
-    } else {
-        if ((home = getenv("HOME")) != NULL) {
-            path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \
-                        JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2);
-            sprintf(path, "%s%s:%s", home, user_dir, system_dir);
-        } else {
-            path = JLI_StringDup(system_dir);
-        }
-    }
-
-    /*
-     * Step through each directory on the path. Terminate the scan with
-     * the first directory with an acceptable JRE.
-     */
-    cp = dp = path;
-    while (dp != NULL) {
-        cp = JLI_StrChr(dp, (int)':');
-        if (cp != NULL)
-            *cp = '\0';
-        if ((target = ProcessDir(info, dp)) != NULL)
-            break;
-        dp = cp;
-        if (dp != NULL)
-            dp++;
-    }
-    JLI_MemFree(path);
-    return (target);
-}
-
-/*
- * Given a path to a jre to execute, this routine checks if this process
- * is indeed that jre.  If not, it exec's that jre.
- *
- * We want to actually check the paths rather than just the version string
- * built into the executable, so that given version specification (and
- * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless
- * of the version of the arbitrary launcher we start with.
- */
-void
-ExecJRE(char *jre, char **argv)
-{
-    char    wanted[PATH_MAX];
-    const char* progname = GetProgramName();
-
-    /*
-     * Resolve the real path to the directory containing the selected JRE.
-     */
-    if (realpath(jre, wanted) == NULL) {
-        JLI_ReportErrorMessage(JRE_ERROR9, jre);
-        exit(1);
-    }
-
-    /*
-     * Resolve the real path to the currently running launcher.
-     */
-    SetExecname(argv);
-    if (execname == NULL) {
-        JLI_ReportErrorMessage(JRE_ERROR10);
-        exit(1);
-    }
-
-    /*
-     * If the path to the selected JRE directory is a match to the initial
-     * portion of the path to the currently executing JRE, we have a winner!
-     * If so, just return.
-     */
-    if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0)
-        return;                 /* I am the droid you were looking for */
-
-
-    /*
-     * This should never happen (because of the selection code in SelectJRE),
-     * but check for "impossibly" long path names just because buffer overruns
-     * can be so deadly.
-     */
-    if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) {
-        JLI_ReportErrorMessage(JRE_ERROR11);
-        exit(1);
-    }
-
-    /*
-     * Construct the path and exec it.
-     */
-    (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname);
-    argv[0] = JLI_StringDup(progname);
-    if (JLI_IsTraceLauncher()) {
-        int i;
-        printf("ReExec Command: %s (%s)\n", wanted, argv[0]);
-        printf("ReExec Args:");
-        for (i = 1; argv[i] != NULL; i++)
-            printf(" %s", argv[i]);
-        printf("\n");
-    }
-    JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
-    (void)fflush(stdout);
-    (void)fflush(stderr);
-    execv(wanted, argv);
-    JLI_ReportErrorMessageSys(JRE_ERROR12, wanted);
-    exit(1);
-}
-
-/*
- * "Borrowed" from Solaris 10 where the unsetenv() function is being added
- * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As
- * such, in the fullness of time this will appear in libc on all relevant
- * Solaris/Linux platforms and maybe even the Windows platform.  At that
- * time, this stub can be removed.
- *
- * This implementation removes the environment locking for multithreaded
- * applications.  (We don't have access to these mutexes within libc and
- * the launcher isn't multithreaded.)  Note that what remains is platform
- * independent, because it only relies on attributes that a POSIX environment
- * defines.
- *
- * Returns 0 on success, -1 on failure.
- *
- * Also removed was the setting of errno.  The only value of errno set
- * was EINVAL ("Invalid Argument").
- */
-
-/*
- * s1(environ) is name=value
- * s2(name) is name(not the form of name=value).
- * if names match, return value of 1, else return 0
- */
-static int
-match_noeq(const char *s1, const char *s2)
-{
-        while (*s1 == *s2++) {
-                if (*s1++ == '=')
-                        return (1);
-        }
-        if (*s1 == '=' && s2[-1] == '\0')
-                return (1);
-        return (0);
-}
-
-/*
- * added for SUSv3 standard
- *
- * Delete entry from environ.
- * Do not free() memory!  Other threads may be using it.
- * Keep it around forever.
- */
-static int
-borrowed_unsetenv(const char *name)
-{
-        long    idx;            /* index into environ */
-
-        if (name == NULL || *name == '\0' ||
-            JLI_StrChr(name, '=') != NULL) {
-                return (-1);
-        }
-
-        for (idx = 0; environ[idx] != NULL; idx++) {
-                if (match_noeq(environ[idx], name))
-                        break;
-        }
-        if (environ[idx] == NULL) {
-                /* name not found but still a success */
-                return (0);
-        }
-        /* squeeze up one entry */
-        do {
-                environ[idx] = environ[idx+1];
-        } while (environ[++idx] != NULL);
-
-        return (0);
-}
-/* --- End of "borrowed" code --- */
-
-/*
- * Wrapper for unsetenv() function.
- */
-int
-UnsetEnv(char *name)
-{
-    return(borrowed_unsetenv(name));
-}
-
-#if defined(_ALLBSD_SOURCE)
-/*
- * BSD's implementation of CounterGet()
- */
-int64_t
-CounterGet()
-{
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return (tv.tv_sec * 1000) + tv.tv_usec;
-}
-#endif
-
-
-/* --- Splash Screen shared library support --- */
-
-#ifdef MACOSX
-static JavaVM* SetJavaVMValue()
-{
-    JavaVM * jvm = NULL;
-
-    // The handle is good for both the launcher and the libosxapp.dylib
-    void * handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
-    if (handle) {
-        typedef JavaVM* (*JLI_GetJavaVMInstance_t)();
-
-        JLI_GetJavaVMInstance_t JLI_GetJavaVMInstance =
-            (JLI_GetJavaVMInstance_t)dlsym(handle,
-                    "JLI_GetJavaVMInstance");
-        if (JLI_GetJavaVMInstance) {
-            jvm = JLI_GetJavaVMInstance();
-        }
-
-        if (jvm) {
-            typedef void (*OSXAPP_SetJavaVM_t)(JavaVM*);
-
-            OSXAPP_SetJavaVM_t OSXAPP_SetJavaVM =
-                (OSXAPP_SetJavaVM_t)dlsym(handle, "OSXAPP_SetJavaVM");
-            if (OSXAPP_SetJavaVM) {
-                OSXAPP_SetJavaVM(jvm);
-            } else {
-                jvm = NULL;
-            }
-        }
-
-        dlclose(handle);
-    }
-
-    return jvm;
-}
-#endif
-
-static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
-
-static void* hSplashLib = NULL;
-
-void* SplashProcAddress(const char* name) {
-    if (!hSplashLib) {
-        const char * splashLibPath;
-
-#ifndef MACOSX
-        splashLibPath = SPLASHSCREEN_SO;
-#else
-        char path[PATH_MAX];
-        Dl_info dli;
-
-        path[0] = 0;
-        if (dladdr(&SplashProcAddress, &dli)) {
-            // This is always reported as <path>/bin/java* (java or javaw, whatever)
-            char * realPath = realpath(dli.dli_fname, path);
-
-            if (realPath != path) {
-                path[0] = 0;
-            } else {
-                // chop off the "/bin/java*" part...
-                char * c = strrchr(path, '/');
-
-                if (!c) {
-                    path[0] = 0;
-                } else {
-                    *c = 0;
-                    c = strrchr(path, '/');
-
-                    if (!c) {
-                        path[0] = 0;
-                    } else {
-                        *c = 0;
-                        // ...and add the lib path instead
-                        snprintf(c, sizeof(path)-strlen(path), "/lib/%s", SPLASHSCREEN_SO);
-                    }
-                }
-            }
-        }
-
-        if (path[0]) {
-            splashLibPath = path;
-        } else {
-            // try our best, but most probably this will fail to load
-            splashLibPath = SPLASHSCREEN_SO;
-        }
-#endif
-        hSplashLib = dlopen(splashLibPath, RTLD_LAZY | RTLD_GLOBAL);
-#ifdef MACOSX
-        if (hSplashLib) {
-            if (!SetJavaVMValue()) {
-                dlclose(hSplashLib);
-                hSplashLib = NULL;
-            }
-        }
-#endif
-    }
-    if (hSplashLib) {
-        void* sym = dlsym(hSplashLib, name);
-        return sym;
-    } else {
-        return NULL;
-    }
-}
-
-void SplashFreeLibrary() {
-    if (hSplashLib) {
-        dlclose(hSplashLib);
-        hSplashLib = NULL;
-    }
-}
-
-const char *
-jlong_format_specifier() {
-    return "%lld";
-}
-
-
-
-/*
- * Block current thread and continue execution in a new thread
- */
-int
-ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
-    int rslt;
-#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(__APPLE__)
-    pthread_t tid;
-    pthread_attr_t attr;
-    pthread_attr_init(&attr);
-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-
-    if (stack_size > 0) {
-      pthread_attr_setstacksize(&attr, stack_size);
-    }
-
-    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
-      void * tmp;
-      pthread_join(tid, &tmp);
-      rslt = (int)tmp;
-    } else {
-     /*
-      * Continue execution in current thread if for some reason (e.g. out of
-      * memory/LWP)  a new thread can't be created. This will likely fail
-      * later in continuation as JNI_CreateJavaVM needs to create quite a
-      * few new threads, anyway, just give it a try..
-      */
-      rslt = continuation(args);
-    }
-
-    pthread_attr_destroy(&attr);
-#else
-    thread_t tid;
-    long flags = 0;
-    if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
-      void * tmp;
-      thr_join(tid, NULL, &tmp);
-      rslt = (int)tmp;
-    } else {
-      /* See above. Continue in current thread if thr_create() failed */
-      rslt = continuation(args);
-    }
-#endif
-    return rslt;
-}
-
-/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
-#define MAX_PID_STR_SZ   20
-
-void SetJavaLauncherPlatformProps() {
-   /* Linux only */
-#ifdef __linux__
-    const char *substr = "-Dsun.java.launcher.pid=";
-    char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
-    sprintf(pid_prop_str, "%s%d", substr, getpid());
-    AddOption(pid_prop_str, NULL);
-#endif
-}
-
-jboolean
-IsJavaw()
-{
-    /* noop on UNIX */
-    return JNI_FALSE;
-}
-
-void
-InitLauncher(jboolean javaw)
-{
-    JLI_SetTraceLauncher();
-}
-
-/*
- * The implementation for finding classes from the bootstrap
- * class loader, refer to java.h
- */
-static FindClassFromBootLoader_t *findBootClass = NULL;
-
-jclass
-FindBootStrapClass(JNIEnv *env, const char* classname)
-{
-   if (findBootClass == NULL) {
-       findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
-          "JVM_FindClassFromBootLoader");
-       if (findBootClass == NULL) {
-           JLI_ReportErrorMessage(DLL_ERROR4,
-               "JVM_FindClassFromBootLoader");
-           return NULL;
-       }
-   }
-   return findBootClass(env, classname);
-}
--- a/src/solaris/bin/java_md.h	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/solaris/bin/java_md.h	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
@@ -26,6 +26,9 @@
 #ifndef JAVA_MD_H
 #define JAVA_MD_H
 
+/*
+ * This file contains common defines and includes for Solaris, Linux and MacOSX.
+ */
 #include <limits.h>
 #include <unistd.h>
 #include <sys/param.h>
@@ -40,27 +43,25 @@
 #define MAXNAMELEN              PATH_MAX
 #endif
 
-#ifdef HAVE_GETHRTIME
 /*
- * Support for doing cheap, accurate interval timing.
- */
-#include <sys/time.h>
-#define CounterGet()              (gethrtime()/1000)
-#define Counter2Micros(counts)    (counts)
-#elif defined(_ALLBSD_SOURCE)
-/* CounterGet() is implemented in java_md.c */
-int64_t CounterGet(void);
-#define Counter2Micros(counts)    (counts)
-#else
-#define CounterGet()              (0)
-#define Counter2Micros(counts)    (1)
-#endif /* HAVE_GETHRTIME || _ALLBSD_SOURCE */
-
-/*
- * Function prototypes.
+ * Common function prototypes and sundries.
  */
 char *LocateJRE(manifest_info *info);
 void ExecJRE(char *jre, char **argv);
 int UnsetEnv(char *name);
+char *FindExecName(char *program);
+const char *SetExecname(char **argv);
+const char *GetExecName();
+static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
+                           char *jvmpath, jint jvmpathsize, const char * arch,
+                           int bitsWanted);
+static jboolean GetJREPath(char *path, jint pathsize, const char * arch,
+                           jboolean speculative);
 
-#endif
+#ifdef MACOSX
+#include "java_md_macosx.h"
+#else  /* !MACOSX */
+#include "java_md_solinux.h"
+#endif /* MACOSX */
+
+#endif /* JAVA_MD_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/bin/java_md_common.c	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,504 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include "java.h"
+
+/*
+ * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
+ * "/foo" into buf.
+ */
+jboolean
+GetApplicationHome(char *buf, jint bufsize)
+{
+    const char *execname = GetExecName();
+    if (execname != NULL) {
+        JLI_Snprintf(buf, bufsize, "%s", execname);
+        buf[bufsize-1] = '\0';
+    } else {
+        return JNI_FALSE;
+    }
+
+    if (JLI_StrRChr(buf, '/') == 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    *(JLI_StrRChr(buf, '/')) = '\0';    /* executable file      */
+    if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0)
+        *(JLI_StrRChr(buf, '/')) = '\0';        /* sparcv9 or amd64     */
+    if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) {
+        buf[0] = '\0';
+        return JNI_FALSE;
+    }
+    *(JLI_StrRChr(buf, '/')) = '\0';    /* bin                  */
+
+    return JNI_TRUE;
+}
+/*
+ * Return true if the named program exists
+ */
+static int
+ProgramExists(char *name)
+{
+    struct stat sb;
+    if (stat(name, &sb) != 0) return 0;
+    if (S_ISDIR(sb.st_mode)) return 0;
+    return (sb.st_mode & S_IEXEC) != 0;
+}
+
+/*
+ * Find a command in a directory, returning the path.
+ */
+static char *
+Resolve(char *indir, char *cmd)
+{
+    char name[PATH_MAX + 2], *real;
+
+    if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1)  > PATH_MAX) return 0;
+    JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
+    if (!ProgramExists(name)) return 0;
+    real = JLI_MemAlloc(PATH_MAX + 2);
+    if (!realpath(name, real))
+        JLI_StrCpy(real, name);
+    return real;
+}
+
+/*
+ * Find a path for the executable
+ */
+char *
+FindExecName(char *program)
+{
+    char cwdbuf[PATH_MAX+2];
+    char *path;
+    char *tmp_path;
+    char *f;
+    char *result = NULL;
+
+    /* absolute path? */
+    if (*program == FILE_SEPARATOR ||
+        (FILE_SEPARATOR=='\\' && JLI_StrRChr(program, ':')))
+        return Resolve("", program+1);
+
+    /* relative path? */
+    if (JLI_StrRChr(program, FILE_SEPARATOR) != 0) {
+        char buf[PATH_MAX+2];
+        return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program);
+    }
+
+    /* from search path? */
+    path = getenv("PATH");
+    if (!path || !*path) path = ".";
+    tmp_path = JLI_MemAlloc(JLI_StrLen(path) + 2);
+    JLI_StrCpy(tmp_path, path);
+
+    for (f=tmp_path; *f && result==0; ) {
+        char *s = f;
+        while (*f && (*f != PATH_SEPARATOR)) ++f;
+        if (*f) *f++ = 0;
+        if (*s == FILE_SEPARATOR)
+            result = Resolve(s, program);
+        else {
+            /* relative path element */
+            char dir[2*PATH_MAX];
+            JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
+                    FILE_SEPARATOR, s);
+            result = Resolve(dir, program);
+        }
+        if (result != 0) break;
+    }
+
+    JLI_MemFree(tmp_path);
+    return result;
+}
+
+void JLI_ReportErrorMessage(const char* fmt, ...) {
+    va_list vl;
+    va_start(vl, fmt);
+    vfprintf(stderr, fmt, vl);
+    fprintf(stderr, "\n");
+    va_end(vl);
+}
+
+void JLI_ReportErrorMessageSys(const char* fmt, ...) {
+    va_list vl;
+    char *emsg;
+
+    /*
+     * TODO: its safer to use strerror_r but is not available on
+     * Solaris 8. Until then....
+     */
+    emsg = strerror(errno);
+    if (emsg != NULL) {
+        fprintf(stderr, "%s\n", emsg);
+    }
+
+    va_start(vl, fmt);
+    vfprintf(stderr, fmt, vl);
+    fprintf(stderr, "\n");
+    va_end(vl);
+}
+
+void  JLI_ReportExceptionDescription(JNIEnv * env) {
+  (*env)->ExceptionDescribe(env);
+}
+
+/*
+ *      Since using the file system as a registry is a bit risky, perform
+ *      additional sanity checks on the identified directory to validate
+ *      it as a valid jre/sdk.
+ *
+ *      Return 0 if the tests fail; otherwise return non-zero (true).
+ *
+ *      Note that checking for anything more than the existence of an
+ *      executable object at bin/java relative to the path being checked
+ *      will break the regression tests.
+ */
+static int
+CheckSanity(char *path, char *dir)
+{
+    char    buffer[PATH_MAX];
+
+    if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
+        return (0);     /* Silently reject "impossibly" long paths */
+
+    JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
+    return ((access(buffer, X_OK) == 0) ? 1 : 0);
+}
+
+/*
+ *      Determine if there is an acceptable JRE in the directory dirname.
+ *      Upon locating the "best" one, return a fully qualified path to
+ *      it. "Best" is defined as the most advanced JRE meeting the
+ *      constraints contained in the manifest_info. If no JRE in this
+ *      directory meets the constraints, return NULL.
+ *
+ *      Note that we don't check for errors in reading the directory
+ *      (which would be done by checking errno).  This is because it
+ *      doesn't matter if we get an error reading the directory, or
+ *      we just don't find anything interesting in the directory.  We
+ *      just return NULL in either case.
+ *
+ *      The historical names of j2sdk and j2re were changed to jdk and
+ *      jre respecively as part of the 1.5 rebranding effort.  Since the
+ *      former names are legacy on Linux, they must be recognized for
+ *      all time.  Fortunately, this is a minor cost.
+ */
+static char
+*ProcessDir(manifest_info *info, char *dirname)
+{
+    DIR     *dirp;
+    struct dirent *dp;
+    char    *best = NULL;
+    int     offset;
+    int     best_offset = 0;
+    char    *ret_str = NULL;
+    char    buffer[PATH_MAX];
+
+    if ((dirp = opendir(dirname)) == NULL)
+        return (NULL);
+
+    do {
+        if ((dp = readdir(dirp)) != NULL) {
+            offset = 0;
+            if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
+                (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
+                offset = 3;
+            else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
+                offset = 4;
+            else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
+                offset = 5;
+            if (offset > 0) {
+                if ((JLI_AcceptableRelease(dp->d_name + offset,
+                    info->jre_version)) && CheckSanity(dirname, dp->d_name))
+                    if ((best == NULL) || (JLI_ExactVersionId(
+                      dp->d_name + offset, best + best_offset) > 0)) {
+                        if (best != NULL)
+                            JLI_MemFree(best);
+                        best = JLI_StringDup(dp->d_name);
+                        best_offset = offset;
+                    }
+            }
+        }
+    } while (dp != NULL);
+    (void) closedir(dirp);
+    if (best == NULL)
+        return (NULL);
+    else {
+        ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
+        sprintf(ret_str, "%s/%s", dirname, best);
+        JLI_MemFree(best);
+        return (ret_str);
+    }
+}
+
+/*
+ *      This is the global entry point. It examines the host for the optimal
+ *      JRE to be used by scanning a set of directories.  The set of directories
+ *      is platform dependent and can be overridden by the environment
+ *      variable JAVA_VERSION_PATH.
+ *
+ *      This routine itself simply determines the set of appropriate
+ *      directories before passing control onto ProcessDir().
+ */
+char*
+LocateJRE(manifest_info* info)
+{
+    char        *path;
+    char        *home;
+    char        *target = NULL;
+    char        *dp;
+    char        *cp;
+
+    /*
+     * Start by getting JAVA_VERSION_PATH
+     */
+    if (info->jre_restrict_search) {
+        path = JLI_StringDup(system_dir);
+    } else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) {
+        path = JLI_StringDup(path);
+    } else {
+        if ((home = getenv("HOME")) != NULL) {
+            path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \
+                        JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2);
+            sprintf(path, "%s%s:%s", home, user_dir, system_dir);
+        } else {
+            path = JLI_StringDup(system_dir);
+        }
+    }
+
+    /*
+     * Step through each directory on the path. Terminate the scan with
+     * the first directory with an acceptable JRE.
+     */
+    cp = dp = path;
+    while (dp != NULL) {
+        cp = JLI_StrChr(dp, (int)':');
+        if (cp != NULL)
+            *cp = '\0';
+        if ((target = ProcessDir(info, dp)) != NULL)
+            break;
+        dp = cp;
+        if (dp != NULL)
+            dp++;
+    }
+    JLI_MemFree(path);
+    return (target);
+}
+
+/*
+ * Given a path to a jre to execute, this routine checks if this process
+ * is indeed that jre.  If not, it exec's that jre.
+ *
+ * We want to actually check the paths rather than just the version string
+ * built into the executable, so that given version specification (and
+ * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless
+ * of the version of the arbitrary launcher we start with.
+ */
+void
+ExecJRE(char *jre, char **argv)
+{
+    char    wanted[PATH_MAX];
+    const char* progname = GetProgramName();
+    const char* execname = NULL;
+
+    /*
+     * Resolve the real path to the directory containing the selected JRE.
+     */
+    if (realpath(jre, wanted) == NULL) {
+        JLI_ReportErrorMessage(JRE_ERROR9, jre);
+        exit(1);
+    }
+
+    /*
+     * Resolve the real path to the currently running launcher.
+     */
+    SetExecname(argv);
+    execname = GetExecName();
+    if (execname == NULL) {
+        JLI_ReportErrorMessage(JRE_ERROR10);
+        exit(1);
+    }
+
+    /*
+     * If the path to the selected JRE directory is a match to the initial
+     * portion of the path to the currently executing JRE, we have a winner!
+     * If so, just return.
+     */
+    if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0)
+        return;                 /* I am the droid you were looking for */
+
+
+    /*
+     * This should never happen (because of the selection code in SelectJRE),
+     * but check for "impossibly" long path names just because buffer overruns
+     * can be so deadly.
+     */
+    if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) {
+        JLI_ReportErrorMessage(JRE_ERROR11);
+        exit(1);
+    }
+
+    /*
+     * Construct the path and exec it.
+     */
+    (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname);
+    argv[0] = JLI_StringDup(progname);
+    if (JLI_IsTraceLauncher()) {
+        int i;
+        printf("ReExec Command: %s (%s)\n", wanted, argv[0]);
+        printf("ReExec Args:");
+        for (i = 1; argv[i] != NULL; i++)
+            printf(" %s", argv[i]);
+        printf("\n");
+    }
+    JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+    (void)fflush(stdout);
+    (void)fflush(stderr);
+    execv(wanted, argv);
+    JLI_ReportErrorMessageSys(JRE_ERROR12, wanted);
+    exit(1);
+}
+
+/*
+ * "Borrowed" from Solaris 10 where the unsetenv() function is being added
+ * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As
+ * such, in the fullness of time this will appear in libc on all relevant
+ * Solaris/Linux platforms and maybe even the Windows platform.  At that
+ * time, this stub can be removed.
+ *
+ * This implementation removes the environment locking for multithreaded
+ * applications.  (We don't have access to these mutexes within libc and
+ * the launcher isn't multithreaded.)  Note that what remains is platform
+ * independent, because it only relies on attributes that a POSIX environment
+ * defines.
+ *
+ * Returns 0 on success, -1 on failure.
+ *
+ * Also removed was the setting of errno.  The only value of errno set
+ * was EINVAL ("Invalid Argument").
+ */
+
+/*
+ * s1(environ) is name=value
+ * s2(name) is name(not the form of name=value).
+ * if names match, return value of 1, else return 0
+ */
+static int
+match_noeq(const char *s1, const char *s2)
+{
+        while (*s1 == *s2++) {
+                if (*s1++ == '=')
+                        return (1);
+        }
+        if (*s1 == '=' && s2[-1] == '\0')
+                return (1);
+        return (0);
+}
+
+/*
+ * added for SUSv3 standard
+ *
+ * Delete entry from environ.
+ * Do not free() memory!  Other threads may be using it.
+ * Keep it around forever.
+ */
+static int
+borrowed_unsetenv(const char *name)
+{
+        long    idx;            /* index into environ */
+
+        if (name == NULL || *name == '\0' ||
+            JLI_StrChr(name, '=') != NULL) {
+                return (-1);
+        }
+
+        for (idx = 0; environ[idx] != NULL; idx++) {
+                if (match_noeq(environ[idx], name))
+                        break;
+        }
+        if (environ[idx] == NULL) {
+                /* name not found but still a success */
+                return (0);
+        }
+        /* squeeze up one entry */
+        do {
+                environ[idx] = environ[idx+1];
+        } while (environ[++idx] != NULL);
+
+        return (0);
+}
+/* --- End of "borrowed" code --- */
+
+/*
+ * Wrapper for unsetenv() function.
+ */
+int
+UnsetEnv(char *name)
+{
+    return(borrowed_unsetenv(name));
+}
+
+const char *
+jlong_format_specifier() {
+    return "%lld";
+}
+
+jboolean
+IsJavaw()
+{
+    /* noop on UNIX */
+    return JNI_FALSE;
+}
+
+void
+InitLauncher(jboolean javaw)
+{
+    JLI_SetTraceLauncher();
+}
+
+/*
+ * The implementation for finding classes from the bootstrap
+ * class loader, refer to java.h
+ */
+static FindClassFromBootLoader_t *findBootClass = NULL;
+
+jclass
+FindBootStrapClass(JNIEnv *env, const char* classname)
+{
+   if (findBootClass == NULL) {
+       findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
+          "JVM_FindClassFromBootLoader");
+       if (findBootClass == NULL) {
+           JLI_ReportErrorMessage(DLL_ERROR4,
+               "JVM_FindClassFromBootLoader");
+           return NULL;
+       }
+   }
+   return findBootClass(env, classname);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/bin/java_md_solinux.c	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,1066 @@
+/*
+ * Copyright (c) 1998, 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "java.h"
+#include "jvm_md.h"
+#include <dirent.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "manifest_info.h"
+#include "version_comp.h"
+
+
+#define JVM_DLL "libjvm.so"
+#define JAVA_DLL "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+
+/* help jettison the LD_LIBRARY_PATH settings in the future */
+#ifndef SETENV_REQUIRED
+#define SETENV_REQUIRED
+#endif
+/*
+ * If a processor / os combination has the ability to run binaries of
+ * two data models and cohabitation of jre/jdk bits with both data
+ * models is supported, then DUAL_MODE is defined.  When DUAL_MODE is
+ * defined, the architecture names for the narrow and wide version of
+ * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME.
+ * Currently  only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE;
+ * linux i586/amd64 could be defined as DUAL_MODE but that is not the
+ * current policy.
+ */
+
+#ifdef __solaris__
+#  define DUAL_MODE
+#  ifndef LIBARCH32NAME
+#    error "The macro LIBARCH32NAME was not defined on the compile line"
+#  endif
+#  ifndef LIBARCH64NAME
+#    error "The macro LIBARCH64NAME was not defined on the compile line"
+#  endif
+#  include <sys/systeminfo.h>
+#  include <sys/elf.h>
+#  include <stdio.h>
+#endif
+
+/*
+ * Flowchart of launcher execs and options processing on unix
+ *
+ * The selection of the proper vm shared library to open depends on
+ * several classes of command line options, including vm "flavor"
+ * options (-client, -server) and the data model options, -d32  and
+ * -d64, as well as a version specification which may have come from
+ * the command line or from the manifest of an executable jar file.
+ * The vm selection options are not passed to the running
+ * virtual machine; they must be screened out by the launcher.
+ *
+ * The version specification (if any) is processed first by the
+ * platform independent routine SelectVersion.  This may result in
+ * the exec of the specified launcher version.
+ *
+ * Previously the launcher modified the LD_LIBRARY_PATH appropriately for the
+ * desired data model path, regardless if data models matched or not. The
+ * launcher subsequently exec'ed the desired executable, in order to make the
+ * LD_LIBRARY_PATH path available, for the runtime linker.
+ *
+ * Now, in most cases,the launcher will dlopen the target libjvm.so. All
+ * required libraries are loaded by the runtime linker, using the
+ * $RPATH/$ORIGIN baked into the shared libraries at compile time. Therefore,
+ * in most cases, the launcher will only exec, if the data models are
+ * mismatched, and will not set any environment variables, regardless of the
+ * data models.
+ *
+ * However, if the environment contains a LD_LIBRARY_PATH, this will cause the
+ * launcher to inspect the LD_LIBRARY_PATH. The launcher will check
+ *  a. if the LD_LIBRARY_PATH's first component is the the path to the desired
+ *     libjvm.so
+ *  b. if any other libjvm.so is found in any of the paths.
+ * If case b is true, then the launcher will set the LD_LIBRARY_PATH to the
+ * desired JRE and reexec, in order to propagate the environment.
+ *
+ *  Main
+ *  (incoming argv)
+ *  |
+ * \|/
+ * SelectVersion
+ * (selects the JRE version, note: not data model)
+ *  |
+ * \|/
+ * CreateExecutionEnvironment
+ * (determines desired data model)
+ *  |
+ *  |
+ * \|/
+ *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                         YES
+ *  |                                          |
+ *  |                                          |
+ *  |                                         \|/
+ *  |                                CheckJvmType
+ *  |                               (removes -client, -server etc.)
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * YES                             Find the desired executable/library
+ *  |                                          |
+ *  |                                          |
+ * \|/                                        \|/
+ * CheckJvmType                          RequiresSetenv
+ * (removes -client, -server, etc.)
+ *  |
+ *  |
+ * \|/
+ * TranslateDashJArgs...
+ * (Prepare to pass args to vm)
+ *  |
+ *  |
+ * \|/
+ * ParseArguments
+ * (removes -d32 and -d64 if any,
+ *  processes version options,
+ *  creates argument list for vm,
+ *  etc.)
+ *   |
+ *   |
+ *  \|/
+ * RequiresSetenv
+ * Is LD_LIBRARY_PATH
+ * and friends set ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
+ *  NO                               YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ * Paths have well known
+ * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *  YES                              YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Does libjvm.so exit
+ *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
+ *   YES                             YES --> Continue
+ *   |
+ *   |
+ *  \|/
+ *  Set the LD_LIBRARY_PATH
+ *   |
+ *   |
+ *  \|/
+ * Re-exec
+ *   |
+ *   |
+ *  \|/
+ * Main
+ */
+
+#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
+
+/* Store the name of the executable once computed */
+static char *execname = NULL;
+
+/*
+ * execname accessor from other parts of platform dependent logic
+ */
+const char *
+GetExecName() {
+    return execname;
+}
+
+const char *
+GetArchPath(int nbits)
+{
+    switch(nbits) {
+#ifdef DUAL_MODE
+        case 32:
+            return LIBARCH32NAME;
+        case 64:
+            return LIBARCH64NAME;
+#endif /* DUAL_MODE */
+        default:
+            return LIBARCHNAME;
+    }
+}
+
+#ifdef SETENV_REQUIRED
+static jboolean
+JvmExists(const char *path) {
+    char tmp[PATH_MAX + 1];
+    struct stat statbuf;
+    JLI_Snprintf(tmp, PATH_MAX, "%s/%s", path, JVM_DLL);
+    if (stat(tmp, &statbuf) == 0) {
+        return JNI_TRUE;
+    }
+    return JNI_FALSE;
+}
+/*
+ * contains a lib/$LIBARCH/{server,client}/libjvm.so ?
+ */
+static jboolean
+ContainsLibJVM(int wanted, const char *env) {
+    char clientPattern[PATH_MAX + 1];
+    char serverPattern[PATH_MAX + 1];
+    char *envpath;
+    char *path;
+    jboolean clientPatternFound;
+    jboolean serverPatternFound;
+
+    /* fastest path */
+    if (env == NULL) {
+        return JNI_FALSE;
+    }
+
+    /* the usual suspects */
+    JLI_Snprintf(clientPattern, PATH_MAX, "lib/%s/client", GetArchPath(wanted));
+    JLI_Snprintf(serverPattern, PATH_MAX, "lib/%s/server", GetArchPath(wanted));
+
+    /* to optimize for time, test if any of our usual suspects are present. */
+    clientPatternFound = JLI_StrStr(env, clientPattern) != NULL;
+    serverPatternFound = JLI_StrStr(env, serverPattern) != NULL;
+    if (clientPatternFound == JNI_FALSE && serverPatternFound == JNI_FALSE) {
+        return JNI_FALSE;
+    }
+
+    /*
+     * we have a suspicious path component, check if it contains a libjvm.so
+     */
+    envpath = JLI_StringDup(env);
+    for (path = JLI_StrTok(envpath, ":"); path != NULL; path = JLI_StrTok(NULL, ":")) {
+        if (clientPatternFound && JLI_StrStr(path, clientPattern) != NULL) {
+            if (JvmExists(path)) {
+                JLI_MemFree(envpath);
+                return JNI_TRUE;
+            }
+        }
+        if (serverPatternFound && JLI_StrStr(path, serverPattern)  != NULL) {
+            if (JvmExists(path)) {
+                JLI_MemFree(envpath);
+                return JNI_TRUE;
+            }
+        }
+    }
+    JLI_MemFree(envpath);
+    return JNI_FALSE;
+}
+
+/*
+ * Test whether the environment variable needs to be set, see flowchart.
+ */
+static jboolean
+RequiresSetenv(int wanted, const char *jvmpath) {
+    char jpath[PATH_MAX + 1];
+    char *llp;
+    char *dmllp = NULL;
+    char *p; /* a utility pointer */
+
+    llp = getenv("LD_LIBRARY_PATH");
+#ifdef __solaris__
+    dmllp = (CURRENT_DATA_MODEL == 32)
+            ? getenv("LD_LIBRARY_PATH_32")
+            : getenv("LD_LIBRARY_PATH_64");
+#endif /* __solaris__ */
+    /* no environment variable is a good environment variable */
+    if (llp == NULL && dmllp == NULL) {
+        return JNI_FALSE;
+    }
+#ifdef __linux
+    /*
+     * On linux, if a binary is running as sgid or suid, glibc sets
+     * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
+     * on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
+     * lose its settings; but the dynamic linker does apply more scrutiny to the
+     * path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec
+     * loop, here and further downstream. Therefore, if we are running sgid or
+     * suid, this function's setting of LD_LIBRARY_PATH will be ineffective and
+     * we should case a return from the calling function.  Getting the right
+     * libraries will be handled by the RPATH. In reality, this check is
+     * redundant, as the previous check for a non-null LD_LIBRARY_PATH will
+     * return back to the calling function forthwith, it is left here to safe
+     * guard against any changes, in the glibc's existing security policy.
+     */
+    if ((getgid() != getegid()) || (getuid() != geteuid())) {
+        return JNI_FALSE;
+    }
+#endif /* __linux */
+
+    /*
+     * Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
+     * previous versions of the JRE, thus it is the only path that matters here.
+     * So we check to see if the desired JRE is set.
+     */
+    JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
+    p = JLI_StrRChr(jpath, '/');
+    *p = '\0';
+    if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) {
+        return JNI_FALSE;
+    }
+
+    /* scrutinize all the paths further */
+    if (llp != NULL &&  ContainsLibJVM(wanted, llp)) {
+        return JNI_TRUE;
+    }
+    if (dmllp != NULL && ContainsLibJVM(wanted, dmllp)) {
+        return JNI_TRUE;
+    }
+    return JNI_FALSE;
+}
+#endif /* SETENV_REQUIRED */
+
+void
+CreateExecutionEnvironment(int *pargc, char ***pargv,
+                           char jrepath[], jint so_jrepath,
+                           char jvmpath[], jint so_jvmpath,
+                           char jvmcfg[],  jint so_jvmcfg) {
+  /*
+   * First, determine if we are running the desired data model.  If we
+   * are running the desired data model, all the error messages
+   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
+   * output.  However, if we are not running the desired data model,
+   * some of the errors should be suppressed since it is more
+   * informative to issue an error message based on whether or not the
+   * os/processor combination has dual mode capabilities.
+   */
+    jboolean jvmpathExists;
+
+    /* Compute/set the name of the executable */
+    SetExecname(*pargv);
+
+    /* Check data model flags, and exec process, if needed */
+    {
+      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
+      char * jvmtype    = NULL;
+      int  argc         = *pargc;
+      char **argv       = *pargv;
+      int running       = CURRENT_DATA_MODEL;
+
+      int wanted        = running;      /* What data mode is being
+                                           asked for? Current model is
+                                           fine unless another model
+                                           is asked for */
+#ifdef SETENV_REQUIRED
+      jboolean mustsetenv = JNI_FALSE;
+      char *runpath     = NULL; /* existing effective LD_LIBRARY_PATH setting */
+      char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
+      char* newpath     = NULL; /* path on new LD_LIBRARY_PATH */
+      char* lastslash   = NULL;
+      char** newenvp    = NULL; /* current environment */
+#ifdef __solaris__
+      char*  dmpath     = NULL;  /* data model specific LD_LIBRARY_PATH,
+                                    Solaris only */
+#endif /* __solaris__ */
+#endif  /* SETENV_REQUIRED */
+
+      char** newargv    = NULL;
+      int    newargc    = 0;
+
+      /*
+       * Starting in 1.5, all unix platforms accept the -d32 and -d64
+       * options.  On platforms where only one data-model is supported
+       * (e.g. ia-64 Linux), using the flag for the other data model is
+       * an error and will terminate the program.
+       */
+
+      { /* open new scope to declare local variables */
+        int i;
+
+        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
+        newargv[newargc++] = argv[0];
+
+        /* scan for data model arguments and remove from argument list;
+           last occurrence determines desired data model */
+        for (i=1; i < argc; i++) {
+
+          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
+            wanted = 64;
+            continue;
+          }
+          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
+            wanted = 32;
+            continue;
+          }
+          newargv[newargc++] = argv[i];
+
+          if (IsJavaArgs()) {
+            if (argv[i][0] != '-') continue;
+          } else {
+            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
+              i++;
+              if (i >= argc) break;
+              newargv[newargc++] = argv[i];
+              continue;
+            }
+            if (argv[i][0] != '-') { i++; break; }
+          }
+        }
+
+        /* copy rest of args [i .. argc) */
+        while (i < argc) {
+          newargv[newargc++] = argv[i++];
+        }
+        newargv[newargc] = NULL;
+
+        /*
+         * newargv has all proper arguments here
+         */
+
+        argc = newargc;
+        argv = newargv;
+      }
+
+      /* If the data model is not changing, it is an error if the
+         jvmpath does not exist */
+      if (wanted == running) {
+        /* Find out where the JRE is that we will be using. */
+        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
+          JLI_ReportErrorMessage(JRE_ERROR1);
+          exit(2);
+        }
+        JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+                     jrepath, FILESEP, FILESEP,  arch, FILESEP);
+        /* Find the specified JVM type */
+        if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
+          JLI_ReportErrorMessage(CFG_ERROR7);
+          exit(1);
+        }
+
+        jvmpath[0] = '\0';
+        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
+        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+        }
+
+        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, 0 )) {
+          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
+          exit(4);
+        }
+        /*
+         * we seem to have everything we need, so without further ado
+         * we return back, otherwise proceed to set the environment.
+         */
+#ifdef SETENV_REQUIRED
+        mustsetenv = RequiresSetenv(wanted, jvmpath);
+        JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE");
+
+        if (mustsetenv == JNI_FALSE) {
+            return;
+        }
+#else
+        return;
+#endif /* SETENV_REQUIRED */
+      } else {  /* do the same speculatively or exit */
+#ifdef DUAL_MODE
+        if (running != wanted) {
+          /* Find out where the JRE is that we will be using. */
+          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+                       jrepath, FILESEP, FILESEP, GetArchPath(wanted), FILESEP);
+          /*
+           * Read in jvm.cfg for target data model and process vm
+           * selection options.
+           */
+          if (ReadKnownVMs(jvmcfg, JNI_TRUE) < 1) {
+            /* give up and let other code report error message */
+            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+            exit(1);
+          }
+          jvmpath[0] = '\0';
+          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
+          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
+            JLI_ReportErrorMessage(CFG_ERROR9);
+            exit(4);
+          }
+
+          /* exec child can do error checking on the existence of the path */
+          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), 0);
+#ifdef SETENV_REQUIRED
+          mustsetenv = RequiresSetenv(wanted, jvmpath);
+#endif /* SETENV_REQUIRED */
+        }
+#else /* ! DUALMODE */
+        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
+        exit(1);
+#endif /* DUAL_MODE */
+        }
+#ifdef SETENV_REQUIRED
+        if (mustsetenv) {
+            /*
+             * We will set the LD_LIBRARY_PATH as follows:
+             *
+             *     o          $JVMPATH (directory portion only)
+             *     o          $JRE/lib/$LIBARCHNAME
+             *     o          $JRE/../lib/$LIBARCHNAME
+             *
+             * followed by the user's previous effective LD_LIBRARY_PATH, if
+             * any.
+             */
+
+#ifdef __solaris__
+            /*
+             * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH
+             * variables:
+             *
+             * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if
+             * data-model specific variables are not set.
+             *
+             * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH
+             * for 64-bit binaries.
+             *
+             * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH
+             * for 32-bit binaries.
+             *
+             * The vm uses LD_LIBRARY_PATH to set the java.library.path system
+             * property.  To shield the vm from the complication of multiple
+             * LD_LIBRARY_PATH variables, if the appropriate data model
+             * specific variable is set, we will act as if LD_LIBRARY_PATH had
+             * the value of the data model specific variant and the data model
+             * specific variant will be unset.  Note that the variable for the
+             * *wanted* data model must be used (if it is set), not simply the
+             * current running data model.
+             */
+
+            switch (wanted) {
+                case 0:
+                    if (running == 32) {
+                        dmpath = getenv("LD_LIBRARY_PATH_32");
+                        wanted = 32;
+                    } else {
+                        dmpath = getenv("LD_LIBRARY_PATH_64");
+                        wanted = 64;
+                    }
+                    break;
+
+                case 32:
+                    dmpath = getenv("LD_LIBRARY_PATH_32");
+                    break;
+
+                case 64:
+                    dmpath = getenv("LD_LIBRARY_PATH_64");
+                    break;
+
+                default:
+                    JLI_ReportErrorMessage(JRE_ERROR3, __LINE__);
+                    exit(1); /* unknown value in wanted */
+                    break;
+            }
+
+            /*
+             * If dmpath is NULL, the relevant data model specific variable is
+             * not set and normal LD_LIBRARY_PATH should be used.
+             */
+            if (dmpath == NULL) {
+                runpath = getenv("LD_LIBRARY_PATH");
+            } else {
+                runpath = dmpath;
+            }
+#else /* ! __solaris__ */
+            /*
+             * If not on Solaris, assume only a single LD_LIBRARY_PATH
+             * variable.
+             */
+            runpath = getenv("LD_LIBRARY_PATH");
+#endif /* __solaris__ */
+
+            /* runpath contains current effective LD_LIBRARY_PATH setting */
+
+            jvmpath = JLI_StringDup(jvmpath);
+            new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
+                    2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
+                    JLI_StrLen(jvmpath) + 52);
+            newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH=");
+
+
+            /*
+             * Create desired LD_LIBRARY_PATH value for target data model.
+             */
+            {
+                /* remove the name of the .so from the JVM path */
+                lastslash = JLI_StrRChr(jvmpath, '/');
+                if (lastslash)
+                    *lastslash = '\0';
+
+                sprintf(new_runpath, "LD_LIBRARY_PATH="
+                        "%s:"
+                        "%s/lib/%s:"
+                        "%s/../lib/%s",
+                        jvmpath,
+#ifdef DUAL_MODE
+                        jrepath, GetArchPath(wanted),
+                        jrepath, GetArchPath(wanted)
+#else /* !DUAL_MODE */
+                        jrepath, arch,
+                        jrepath, arch
+#endif /* DUAL_MODE */
+                        );
+
+
+                /*
+                 * Check to make sure that the prefix of the current path is the
+                 * desired environment variable setting, though the RequiresSetenv
+                 * checks if the desired runpath exists, this logic does a more
+                 * comprehensive check.
+                 */
+                if (runpath != NULL &&
+                        JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
+                        (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
+                        (running == wanted) /* data model does not have to be changed */
+#ifdef __solaris__
+                        && (dmpath == NULL) /* data model specific variables not set  */
+#endif /* __solaris__ */
+                        ) {
+
+                    return;
+
+                }
+            }
+
+            /*
+             * Place the desired environment setting onto the prefix of
+             * LD_LIBRARY_PATH.  Note that this prevents any possible infinite
+             * loop of execv() because we test for the prefix, above.
+             */
+            if (runpath != 0) {
+                JLI_StrCat(new_runpath, ":");
+                JLI_StrCat(new_runpath, runpath);
+            }
+
+            if (putenv(new_runpath) != 0) {
+                exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
+                    properly */
+            }
+
+            /*
+             * Unix systems document that they look at LD_LIBRARY_PATH only
+             * once at startup, so we have to re-exec the current executable
+             * to get the changed environment variable to have an effect.
+             */
+
+#ifdef __solaris__
+            /*
+             * If dmpath is not NULL, remove the data model specific string
+             * in the environment for the exec'ed child.
+             */
+            if (dmpath != NULL)
+                (void)UnsetEnv((wanted == 32) ? "LD_LIBRARY_PATH_32" : "LD_LIBRARY_PATH_64");
+#endif /* __solaris */
+
+            newenvp = environ;
+        }
+#endif /* SETENV_REQUIRED */
+        {
+            char *newexec = execname;
+#ifdef DUAL_MODE
+            /*
+             * If the data model is being changed, the path to the
+             * executable must be updated accordingly; the executable name
+             * and directory the executable resides in are separate.  In the
+             * case of 32 => 64, the new bits are assumed to reside in, e.g.
+             * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32,
+             * the bits are assumed to be in "olddir/../execname".  For example,
+             *
+             * olddir/sparcv9/execname
+             * olddir/amd64/execname
+             *
+             * for Solaris SPARC and Linux amd64, respectively.
+             */
+
+            if (running != wanted) {
+                char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname);
+                char *olddir = oldexec;
+                char *oldbase = JLI_StrRChr(oldexec, '/');
+
+
+                newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20);
+                *oldbase++ = 0;
+                sprintf(newexec, "%s/%s/%s", olddir,
+                        ((wanted == 64) ? LIBARCH64NAME : ".."), oldbase);
+                argv[0] = newexec;
+            }
+#endif /* DUAL_MODE */
+            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
+            (void) fflush(stdout);
+            (void) fflush(stderr);
+#ifdef SETENV_REQUIRED
+            if (mustsetenv) {
+                execve(newexec, argv, newenvp);
+            } else {
+                execv(newexec, argv);
+            }
+#else /* !SETENV_REQUIRED */
+            execv(newexec, argv);
+#endif /* SETENV_REQUIRED */
+            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
+
+#ifdef DUAL_MODE
+            if (running != wanted) {
+                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
+#ifdef __solaris__
+#ifdef __sparc
+                JLI_ReportErrorMessage(JRE_ERROR6);
+#else  /* ! __sparc__ */
+                JLI_ReportErrorMessage(JRE_ERROR7);
+#endif  /* __sparc */
+#endif /* __solaris__ */
+            }
+#endif /* DUAL_MODE */
+
+        }
+        exit(1);
+    }
+}
+
+/*
+ * On Solaris VM choosing is done by the launcher (java.c),
+ * bitsWanted is used by MacOSX,  on Solaris and Linux this.
+ * parameter is unused.
+ */
+static jboolean
+GetJVMPath(const char *jrepath, const char *jvmtype,
+           char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted)
+{
+    struct stat s;
+
+    if (JLI_StrChr(jvmtype, '/')) {
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
+    } else {
+        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
+    }
+
+    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
+
+    if (stat(jvmpath, &s) == 0) {
+        JLI_TraceLauncher("yes.\n");
+        return JNI_TRUE;
+    } else {
+        JLI_TraceLauncher("no.\n");
+        return JNI_FALSE;
+    }
+}
+
+/*
+ * Find path to JRE based on .exe's location or registry settings.
+ */
+static jboolean
+GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
+{
+    char libjava[MAXPATHLEN];
+
+    if (GetApplicationHome(path, pathsize)) {
+        /* Is JRE co-located with the application? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
+        if (access(libjava, F_OK) == 0) {
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+
+        /* Does the app ship a private JRE in <apphome>/jre directory? */
+        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
+        if (access(libjava, F_OK) == 0) {
+            JLI_StrCat(path, "/jre");
+            JLI_TraceLauncher("JRE path is %s\n", path);
+            return JNI_TRUE;
+        }
+    }
+
+    if (!speculative)
+      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
+    return JNI_FALSE;
+}
+
+jboolean
+LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
+{
+    Dl_info dlinfo;
+    void *libjvm;
+
+    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
+
+    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
+    if (libjvm == NULL) {
+#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */
+      FILE * fp;
+      Elf32_Ehdr elf_head;
+      int count;
+      int location;
+
+      fp = fopen(jvmpath, "r");
+      if (fp == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+      }
+
+      /* read in elf header */
+      count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
+      fclose(fp);
+      if (count < 1) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+      }
+
+      /*
+       * Check for running a server vm (compiled with -xarch=v8plus)
+       * on a stock v8 processor.  In this case, the machine type in
+       * the elf header would not be included the architecture list
+       * provided by the isalist command, which is turn is gotten from
+       * sysinfo.  This case cannot occur on 64-bit hardware and thus
+       * does not have to be checked for in binaries with an LP64 data
+       * model.
+       */
+      if (elf_head.e_machine == EM_SPARC32PLUS) {
+        char buf[257];  /* recommended buffer size from sysinfo man
+                           page */
+        long length;
+        char* location;
+
+        length = sysinfo(SI_ISALIST, buf, 257);
+        if (length > 0) {
+            location = JLI_StrStr(buf, "sparcv8plus ");
+          if (location == NULL) {
+            JLI_ReportErrorMessage(JVM_ERROR3);
+            return JNI_FALSE;
+          }
+        }
+      }
+#endif
+        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->CreateJavaVM = (CreateJavaVM_t)
+        dlsym(libjvm, "JNI_CreateJavaVM");
+    if (ifn->CreateJavaVM == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
+        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
+    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t)
+        dlsym(libjvm, "JNI_GetCreatedJavaVMs");
+    if (ifn->GetCreatedJavaVMs == NULL) {
+        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
+        return JNI_FALSE;
+    }
+
+    return JNI_TRUE;
+}
+
+/*
+ * Compute the name of the executable
+ *
+ * In order to re-exec securely we need the absolute path of the
+ * executable. On Solaris getexecname(3c) may not return an absolute
+ * path so we use dladdr to get the filename of the executable and
+ * then use realpath to derive an absolute path. From Solaris 9
+ * onwards the filename returned in DL_info structure from dladdr is
+ * an absolute pathname so technically realpath isn't required.
+ * On Linux we read the executable name from /proc/self/exe.
+ * As a fallback, and for platforms other than Solaris and Linux,
+ * we use FindExecName to compute the executable name.
+ */
+const char*
+SetExecname(char **argv)
+{
+    char* exec_path = NULL;
+#if defined(__solaris__)
+    {
+        Dl_info dlinfo;
+        int (*fptr)();
+
+        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
+        if (fptr == NULL) {
+            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
+            return JNI_FALSE;
+        }
+
+        if (dladdr((void*)fptr, &dlinfo)) {
+            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
+            if (resolved != NULL) {
+                exec_path = realpath(dlinfo.dli_fname, resolved);
+                if (exec_path == NULL) {
+                    JLI_MemFree(resolved);
+                }
+            }
+        }
+    }
+#elif defined(__linux__)
+    {
+        const char* self = "/proc/self/exe";
+        char buf[PATH_MAX+1];
+        int len = readlink(self, buf, PATH_MAX);
+        if (len >= 0) {
+            buf[len] = '\0';            /* readlink doesn't nul terminate */
+            exec_path = JLI_StringDup(buf);
+        }
+    }
+#else /* !__solaris__ && !__linux__ */
+    {
+        /* Not implemented */
+    }
+#endif
+
+    if (exec_path == NULL) {
+        exec_path = FindExecName(argv[0]);
+    }
+    execname = exec_path;
+    return exec_path;
+}
+
+/* --- Splash Screen shared library support --- */
+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
+static void* hSplashLib = NULL;
+
+void* SplashProcAddress(const char* name) {
+    if (!hSplashLib) {
+        const char * splashLibPath;
+        splashLibPath = SPLASHSCREEN_SO;
+        hSplashLib = dlopen(splashLibPath, RTLD_LAZY | RTLD_GLOBAL);
+    }
+    if (hSplashLib) {
+        void* sym = dlsym(hSplashLib, name);
+        return sym;
+    } else {
+        return NULL;
+    }
+}
+
+void SplashFreeLibrary() {
+    if (hSplashLib) {
+        dlclose(hSplashLib);
+        hSplashLib = NULL;
+    }
+}
+
+/*
+ * Block current thread and continue execution in a new thread
+ */
+int
+ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
+    int rslt;
+#ifdef __linux__
+    pthread_t tid;
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+    if (stack_size > 0) {
+      pthread_attr_setstacksize(&attr, stack_size);
+    }
+
+    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
+      void * tmp;
+      pthread_join(tid, &tmp);
+      rslt = (int)tmp;
+    } else {
+     /*
+      * Continue execution in current thread if for some reason (e.g. out of
+      * memory/LWP)  a new thread can't be created. This will likely fail
+      * later in continuation as JNI_CreateJavaVM needs to create quite a
+      * few new threads, anyway, just give it a try..
+      */
+      rslt = continuation(args);
+    }
+
+    pthread_attr_destroy(&attr);
+#else /* ! __linux__ */
+    thread_t tid;
+    long flags = 0;
+    if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
+      void * tmp;
+      thr_join(tid, NULL, &tmp);
+      rslt = (int)tmp;
+    } else {
+      /* See above. Continue in current thread if thr_create() failed */
+      rslt = continuation(args);
+    }
+#endif /* __linux__ */
+    return rslt;
+}
+
+/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
+#define MAX_PID_STR_SZ   20
+
+void SetJavaLauncherPlatformProps() {
+   /* Linux only */
+#ifdef __linux__
+    const char *substr = "-Dsun.java.launcher.pid=";
+    char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
+    sprintf(pid_prop_str, "%s%d", substr, getpid());
+    AddOption(pid_prop_str, NULL);
+#endif /* __linux__ */
+}
+
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+        int argc, char **argv,
+        int mode, char *what, int ret)
+{
+    ShowSplashScreen();
+    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+}
+
+void
+PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
+{
+    // stubbed out for windows and *nixes.
+}
+
+void
+RegisterThread()
+{
+    // stubbed out for windows and *nixes.
+}
+
+/*
+ * on unix, we return a false to indicate this option is not applicable
+ */
+jboolean
+ProcessPlatformOption(const char *arg)
+{
+    return JNI_FALSE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/bin/java_md_solinux.h	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef JAVA_MD_SOLINUX_H
+#define JAVA_MD_SOLINUX_H
+
+#ifdef HAVE_GETHRTIME
+/*
+ * Support for doing cheap, accurate interval timing.
+ */
+#include <sys/time.h>
+#define CounterGet()              (gethrtime()/1000)
+#define Counter2Micros(counts)    (counts)
+#else  /* ! HAVE_GETHRTIME */
+#define CounterGet()              (0)
+#define Counter2Micros(counts)    (1)
+#endif /* HAVE_GETHRTIME */
+
+/* pointer to environment */
+extern char **environ;
+
+/*
+ *      A collection of useful strings. One should think of these as #define
+ *      entries, but actual strings can be more efficient (with many compilers).
+ */
+#ifdef __linux__
+static const char *system_dir   = "/usr/java";
+static const char *user_dir     = "/java";
+#else /* Solaris */
+static const char *system_dir   = "/usr/jdk";
+static const char *user_dir     = "/jdk";
+#endif
+
+#include <dlfcn.h>
+#ifdef __linux__
+#include <pthread.h>
+#else
+#include <thread.h>
+#endif
+
+#define JVM_DLL         "libjvm.so"
+#define JAVA_DLL        "libjava.so"
+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
+
+#endif /* JAVA_MD_SOLINUX_H */
--- a/src/solaris/bin/universal/jvm.cfg	Tue Jan 24 16:18:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-# Copyright (c) 2011, 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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Oracle designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-# List of JVMs that can be used as an option to java, javac, etc.
-# Order is important -- first in this list is the default JVM.
-# NOTE that this both this file and its format are UNSUPPORTED and
-# WILL GO AWAY in a future release.
-#
-# You may also select a JVM in an arbitrary location with the
-# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
-# and may not be available in a future release.
-#
--server KNOWN
--client KNOWN
--hotspot ERROR
--classic WARN
--native ERROR
--green ERROR
--- a/src/solaris/lib/Info-cmdline.plist	Tue Jan 24 16:18:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-        <key>CFBundleIdentifier</key>
-        <string>net.java.openjdk.cmd</string>
-        <key>CFBundleInfoDictionaryVersion</key>
-        <string>6.0</string>
-        <key>CFBundleShortVersionString</key>
-        <string>1.0</string>
-        <key>CFBundleVersion</key>
-        <string>1.0</string>
-</dict>
-</plist>
--- a/src/solaris/lib/Info-privileged.plist	Tue Jan 24 16:18:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-        <key>CFBundleIdentifier</key>
-        <string>net.java.openjdk.cmd</string>
-        <key>CFBundleInfoDictionaryVersion</key>
-        <string>6.0</string>
-        <key>CFBundleName</key>
-        <string>OpenJDK 7 Command</string>
-        <key>CFBundleShortVersionString</key>
-        <string>1.0</string>
-        <key>CFBundleVersion</key>
-        <string>1.0</string>
-        <key>SecTaskAccess</key>
-        <string>allowed</string>
-</dict>
-</plist>
--- a/src/windows/bin/java_md.c	Tue Jan 24 16:18:59 2012 +0000
+++ b/src/windows/bin/java_md.c	Tue Jan 24 10:42:17 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, 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
@@ -171,7 +171,8 @@
 void
 CreateExecutionEnvironment(int *pargc, char ***pargv,
                            char *jrepath, jint so_jrepath,
-                           char *jvmpath, jint so_jvmpath) {
+                           char *jvmpath, jint so_jvmpath,
+                           char *jvmcfg,  jint so_jvmcfg) {
     char * jvmtype;
     int i = 0;
     int running = CURRENT_DATA_MODEL;
@@ -200,8 +201,11 @@
         exit(2);
     }
 
+    JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",
+        jrepath, FILESEP, FILESEP, (char*)GetArch(), FILESEP);
+
     /* Find the specified JVM type */
-    if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) {
+    if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
         JLI_ReportErrorMessage(CFG_ERROR7);
         exit(1);
     }
@@ -1323,3 +1327,33 @@
 }
 
 #endif /* ENABLE_AWT_PRELOAD */
+
+int
+JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
+        int argc, char **argv,
+        int mode, char *what, int ret)
+{
+    ShowSplashScreen();
+    return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
+}
+
+void
+PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
+{
+    // stubbed out for windows and *nixes.
+}
+
+void
+RegisterThread()
+{
+    // stubbed out for windows and *nixes.
+}
+
+/*
+ * on windows, we return a false to indicate this option is not applicable
+ */
+jboolean
+ProcessPlatformOption(const char *arg)
+{
+    return JNI_FALSE;
+}
--- a/test/tools/launcher/Test7029048.java	Tue Jan 24 16:18:59 2012 +0000
+++ b/test/tools/launcher/Test7029048.java	Tue Jan 24 10:42:17 2012 -0800
@@ -286,7 +286,7 @@
 
     public static void main(String... args) throws Exception {
         if (TestHelper.isWindows || TestHelper.isMacOSX) {
-            System.out.println("Note: not applicable on Windows and MacOSX");
+            System.out.println("Note: applicable on neither Windows nor MacOSX");
             return;
         }
         // create our test jar first
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/launcher/TestSpecialArgs.java	Tue Jan 24 10:42:17 2012 -0800
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7124089
+ * @summary Checks for MacOSX specific flags are accepted or rejected
+ * @compile -XDignore.symbol.file TestHelper.java TestSpecialArgs.java
+ * @run main TestSpecialArgs
+ */
+import java.util.HashMap;
+import java.util.Map;
+
+public class TestSpecialArgs {
+
+    public static void main(String... args) {
+        final Map<String, String> envMap = new HashMap<>();
+        envMap.put("_JAVA_LAUNCHER_DEBUG", "true");
+
+        TestHelper.TestResult tr = TestHelper.doExec(envMap,
+                TestHelper.javaCmd, "-XstartOnFirstThread", "-version");
+        if (TestHelper.isMacOSX) {
+            if (!tr.contains("In same thread")) {
+                System.out.println(tr);
+                throw new RuntimeException("Error: not running in the same thread ?");
+            }
+            if (!tr.isOK()) {
+                System.out.println(tr);
+                throw new RuntimeException("Error: arg was rejected ????");
+            }
+        } else {
+            if (tr.isOK()) {
+                System.out.println(tr);
+                throw new RuntimeException("Error: argument was accepted ????");
+            }
+        }
+
+        tr = TestHelper.doExec(TestHelper.javaCmd, "-Xdock:/tmp/not-available",
+                "-version");
+        if (TestHelper.isMacOSX) {
+            if (!tr.isOK()) {
+                System.out.println(tr);
+                throw new RuntimeException("Error: arg was rejected ????");
+            }
+        } else {
+            if (tr.isOK()) {
+                System.out.println(tr);
+                throw new RuntimeException("Error: argument was accepted ????");
+            }
+        }
+    }
+}