887fd98
diff --git openjdk.orig/jdk/make/CompileLaunchers.gmk openjdk/jdk/make/CompileLaunchers.gmk
887fd98
--- openjdk.orig/jdk/make/CompileLaunchers.gmk
887fd98
+++ openjdk/jdk/make/CompileLaunchers.gmk
887fd98
@@ -255,6 +255,33 @@
887fd98
   endif
887fd98
 endif
f40d118
 
887fd98
+# -Wno-error=cpp is present to allow commented warning in ifdef part of main.c
f40d118
+$(eval $(call SetupLauncher,alt-java, \
aa2fac5
+    -DEXPAND_CLASSPATH_WILDCARDS -DREDHAT_ALT_JAVA -Wno-error=cpp,,,user32.lib comctl32.lib, \
f40d118
+    $(JDK_OUTPUTDIR)/objs/jli_static.lib, $(JAVA_RC_FLAGS), \
f40d118
+    $(JDK_TOPDIR)/src/windows/resource/java.rc, $(JDK_OUTPUTDIR)/objs/java_objs,true))
f40d118
+
f40d118
+$(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX): $(BUILD_LAUNCHER_alt-java)
f40d118
+	$(MKDIR) -p $(@D)
f40d118
+	$(RM) $@
f40d118
+	$(CP) $(JDK_OUTPUTDIR)/objs/java_objs$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX) $@
f40d118
+
887fd98
+$(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT): $(BUILD_LAUNCHER_alt-java)
887fd98
+	$(MKDIR) -p $(@D)
887fd98
+	$(RM) $@
887fd98
+	$(CP) $(JDK_OUTPUTDIR)/objs/java_objs$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT) $@
887fd98
+
f40d118
+ifeq ($(OPENJDK_TARGET_OS), linux)
f40d118
+  BUILD_LAUNCHERS += $(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX)
887fd98
+  ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
887fd98
+    ifneq ($(POST_STRIP_CMD), )
887fd98
+      ifneq ($(STRIP_POLICY), no_strip)
887fd98
+        BUILD_LAUNCHERS += $(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT)
887fd98
+      endif
887fd98
+    endif
887fd98
+  endif
f40d118
+endif
f40d118
+
f40d118
 ifeq ($(OPENJDK_TARGET_OS), windows)
f40d118
   $(eval $(call SetupLauncher,javaw, \
f40d118
       -DJAVAW -DEXPAND_CLASSPATH_WILDCARDS,,,user32.lib comctl32.lib, \
887fd98
diff --git openjdk.orig/jdk/src/share/bin/alt_main.h openjdk/jdk/src/share/bin/alt_main.h
887fd98
new file mode 100644
887fd98
--- /dev/null
887fd98
+++ openjdk/jdk/src/share/bin/alt_main.h
f40d118
@@ -0,0 +1,73 @@
f40d118
+/*
f40d118
+ * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
f40d118
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f40d118
+ *
f40d118
+ * This code is free software; you can redistribute it and/or modify it
f40d118
+ * under the terms of the GNU General Public License version 2 only, as
f40d118
+ * published by the Free Software Foundation.  Oracle designates this
f40d118
+ * particular file as subject to the "Classpath" exception as provided
f40d118
+ * by Oracle in the LICENSE file that accompanied this code.
f40d118
+ *
f40d118
+ * This code is distributed in the hope that it will be useful, but WITHOUT
f40d118
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f40d118
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f40d118
+ * version 2 for more details (a copy is included in the LICENSE file that
f40d118
+ * accompanied this code).
f40d118
+ *
f40d118
+ * You should have received a copy of the GNU General Public License version
f40d118
+ * 2 along with this work; if not, write to the Free Software Foundation,
f40d118
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f40d118
+ *
f40d118
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f40d118
+ * or visit www.oracle.com if you need additional information or have any
f40d118
+ * questions.
f40d118
+ */
f40d118
+
f40d118
+#ifdef REDHAT_ALT_JAVA
f40d118
+
f40d118
+#include <sys/prctl.h>
f40d118
+
f40d118
+
f40d118
+/* Per task speculation control */
f40d118
+#ifndef PR_GET_SPECULATION_CTRL
f40d118
+# define PR_GET_SPECULATION_CTRL    52
f40d118
+#endif
f40d118
+#ifndef PR_SET_SPECULATION_CTRL
f40d118
+# define PR_SET_SPECULATION_CTRL    53
f40d118
+#endif
f40d118
+/* Speculation control variants */
f40d118
+#ifndef PR_SPEC_STORE_BYPASS
f40d118
+# define PR_SPEC_STORE_BYPASS          0
f40d118
+#endif
f40d118
+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
f40d118
+
f40d118
+#ifndef PR_SPEC_NOT_AFFECTED
f40d118
+# define PR_SPEC_NOT_AFFECTED          0
f40d118
+#endif
f40d118
+#ifndef PR_SPEC_PRCTL
f40d118
+# define PR_SPEC_PRCTL                 (1UL << 0)
f40d118
+#endif
f40d118
+#ifndef PR_SPEC_ENABLE
f40d118
+# define PR_SPEC_ENABLE                (1UL << 1)
f40d118
+#endif
f40d118
+#ifndef PR_SPEC_DISABLE
f40d118
+# define PR_SPEC_DISABLE               (1UL << 2)
f40d118
+#endif
f40d118
+#ifndef PR_SPEC_FORCE_DISABLE
f40d118
+# define PR_SPEC_FORCE_DISABLE         (1UL << 3)
f40d118
+#endif
f40d118
+#ifndef PR_SPEC_DISABLE_NOEXEC
f40d118
+# define PR_SPEC_DISABLE_NOEXEC        (1UL << 4)
f40d118
+#endif
f40d118
+
f40d118
+static void set_speculation() __attribute__((constructor));
f40d118
+static void set_speculation() {
f40d118
+  if ( prctl(PR_SET_SPECULATION_CTRL,
f40d118
+             PR_SPEC_STORE_BYPASS,
f40d118
+             PR_SPEC_DISABLE_NOEXEC, 0, 0) == 0 ) {
f40d118
+    return;
f40d118
+  }
f40d118
+  prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
f40d118
+}
f40d118
+
f40d118
+#endif // REDHAT_ALT_JAVA
887fd98
diff --git openjdk.orig/jdk/src/share/bin/main.c openjdk/jdk/src/share/bin/main.c
887fd98
--- openjdk.orig/jdk/src/share/bin/main.c
887fd98
+++ openjdk/jdk/src/share/bin/main.c
aa2fac5
@@ -32,6 +32,14 @@
f40d118
 
f40d118
 #include "defines.h"
f40d118
 
aa2fac5
+#ifdef REDHAT_ALT_JAVA
1175043
+#if defined(__linux__) && defined(__x86_64__)
f40d118
+#include "alt_main.h"
aa2fac5
+#else
aa2fac5
+#warning alt-java requested but SSB mitigation not available on this platform.
aa2fac5
+#endif
f40d118
+#endif
f40d118
+
f40d118
 #ifdef _MSC_VER
f40d118
 #if _MSC_VER > 1400 && _MSC_VER < 1600
f40d118