1 #
  2 # Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 ###############################################################################
 27 # Terminology used in this file:
 28 #
 29 # Valid features      == All possible features that the JVM knows about.
 30 # Deprecated features == Previously known features (not considered valid).
 31 # Available features  == Features that are possible to use in this configuration.
 32 # Default features    == Features that are on by default in this configuration.
 33 # Enabled features    == Features requested by the user to be present.
 34 # Disabled features   == Features excluded from being used by the user.
 35 # Active features     == The exact set of features to be used for a JVM variant.
 36 #
 37 # All valid features are considered available, unless listed as unavailable.
 38 # All available features will be turned on as default, unless listed in a filter.
 39 ###############################################################################
 40 
 41 # We need these as m4 defines to be able to loop over them using m4 later on.
 42 
 43 # All valid JVM features, regardless of platform
 44 m4_define(jvm_features_valid, m4_normalize( \
 45     ifdef([custom_jvm_features_valid], custom_jvm_features_valid) \
 46     \
 47     cds compiler1 compiler2 dtrace epsilongc g1gc jfr jni-check \
 48     jvmci jvmti link-time-opt management minimal nmt opt-size parallelgc \
 49     serialgc services shenandoahgc static-build vm-structs zero zgc \
 50 ))
 51 
 52 # Deprecated JVM features (these are ignored, but with a warning)
 53 m4_define(jvm_features_deprecated, m4_normalize(
 54     cmsgc trace \
 55 ))
 56 
 57 # Feature descriptions
 58 m4_define(jvm_feature_desc_cds, [enable class data sharing (CDS)])
 59 m4_define(jvm_feature_desc_compiler1, [enable hotspot compiler C1])
 60 m4_define(jvm_feature_desc_compiler2, [enable hotspot compiler C2])
 61 m4_define(jvm_feature_desc_dtrace, [enable dtrace support])
 62 m4_define(jvm_feature_desc_epsilongc, [include the epsilon (no-op) garbage collector])
 63 m4_define(jvm_feature_desc_g1gc, [include the G1 garbage collector])
 64 m4_define(jvm_feature_desc_jfr, [enable JDK Flight Recorder (JFR)])
 65 m4_define(jvm_feature_desc_jni_check, [enable -Xcheck:jni support])
 66 m4_define(jvm_feature_desc_jvmci, [enable JVM Compiler Interface (JVMCI)])
 67 m4_define(jvm_feature_desc_jvmti, [enable Java Virtual Machine Tool Interface (JVM TI)])
 68 m4_define(jvm_feature_desc_link_time_opt, [enable link time optimization])
 69 m4_define(jvm_feature_desc_management, [enable java.lang.management API support])
 70 m4_define(jvm_feature_desc_minimal, [support building variant 'minimal'])
 71 m4_define(jvm_feature_desc_nmt, [include native memory tracking (NMT)])
 72 m4_define(jvm_feature_desc_opt_size, [optimize the JVM library for size])
 73 m4_define(jvm_feature_desc_parallelgc, [include the parallel garbage collector])
 74 m4_define(jvm_feature_desc_serialgc, [include the serial garbage collector])
 75 m4_define(jvm_feature_desc_services, [enable diagnostic services and client attaching])
 76 m4_define(jvm_feature_desc_shenandoahgc, [include the Shenandoah garbage collector])
 77 m4_define(jvm_feature_desc_static_build, [build static library instead of dynamic])
 78 m4_define(jvm_feature_desc_vm_structs, [export JVM structures to the Serviceablility Agent])
 79 m4_define(jvm_feature_desc_zero, [support building variant 'zero'])
 80 m4_define(jvm_feature_desc_zgc, [include the Z garbage collector])
 81 
 82 ###############################################################################
 83 # Parse command line options for JVM feature selection. After this function
 84 # has run $JVM_FEATURES_ENABLED, $JVM_FEATURES_DISABLED and $JVM_FEATURES_VALID
 85 # can be used.
 86 #
 87 AC_DEFUN_ONCE([JVM_FEATURES_PARSE_OPTIONS],
 88 [
 89   # Setup shell variables from the m4 lists
 90   UTIL_SORT_LIST(JVM_FEATURES_VALID, "jvm_features_valid")
 91   UTIL_SORT_LIST(JVM_FEATURES_DEPRECATED, "jvm_features_deprecated")
 92 
 93   # For historical reasons, some jvm features have their own, shorter names.
 94   # Keep those as aliases for the --enable-jvm-feature-* style arguments.
 95   UTIL_ALIASED_ARG_ENABLE(cds, --enable-jvm-feature-cds)
 96   UTIL_ALIASED_ARG_ENABLE(dtrace, --enable-jvm-feature-dtrace)
 97 
 98   # First check for features using the
 99   # --with-jvm-features="<[-]feature>[,<[-]feature> ...]" syntax.
100   AC_ARG_WITH([jvm-features], [AS_HELP_STRING([--with-jvm-features],
101       [JVM features to enable (foo) or disable (-foo), separated by comma. Use
102       '--help' to show possible values @<:@none@:>@])])
103   if test "x$with_jvm_features" != x; then
104     # Replace ","  with " ".
105     user_jvm_feature_list=${with_jvm_features//,/ }
106     JVM_FEATURES_ENABLED=`$ECHO $user_jvm_feature_list | \
107         $AWK '{ for (i=1; i<=NF; i++) if (!match($i, /^-.*/)) printf("%s ", $i) }'`
108     JVM_FEATURES_DISABLED=`$ECHO $user_jvm_feature_list | \
109         $AWK '{ for (i=1; i<=NF; i++) if (match($i, /^-.*/)) printf("%s ", substr($i, 2))}'`
110 
111     # Verify that the user has provided only valid (or deprecated) features
112     UTIL_GET_NON_MATCHING_VALUES(invalid_features, $JVM_FEATURES_ENABLED \
113         $JVM_FEATURES_DISABLED, $JVM_FEATURES_VALID $JVM_FEATURES_DEPRECATED)
114     if test "x$invalid_features" != x; then
115       AC_MSG_NOTICE([Unknown JVM features specified: '$invalid_features'])
116       AC_MSG_NOTICE([The available JVM features are: '$JVM_FEATURES_VALID'])
117       AC_MSG_ERROR([Cannot continue])
118     fi
119 
120     # Check if the user has provided deprecated features
121     UTIL_GET_MATCHING_VALUES(deprecated_features, $JVM_FEATURES_ENABLED \
122         $JVM_FEATURES_DISABLED, $JVM_FEATURES_DEPRECATED)
123     if test "x$deprecated_features" != x; then
124       AC_MSG_WARN([Deprecated JVM features specified (will be ignored): '$deprecated_features'])
125       # Filter out deprecated features
126       UTIL_GET_NON_MATCHING_VALUES(JVM_FEATURES_ENABLED, \
127           $JVM_FEATURES_ENABLED, $deprecated_features)
128       UTIL_GET_NON_MATCHING_VALUES(JVM_FEATURES_DISABLED, \
129           $JVM_FEATURES_DISABLED, $deprecated_features)
130     fi
131   fi
132 
133   # Then check for features using the "--enable-jvm-feature-<feature>" syntax.
134   # Using m4, loop over all features with the variable FEATURE.
135   m4_foreach(FEATURE, m4_split(jvm_features_valid), [
136     # Create an m4 variable containing a shell variable name (like
137     # "enable_jvm_feature_static_build"), and the description.
138     m4_define(FEATURE_SHELL, [enable_jvm_feature_]m4_translit(FEATURE, -, _))
139     m4_define(FEATURE_DESCRIPTION, [jvm_feature_desc_]m4_translit(FEATURE, -, _))
140 
141     AC_ARG_ENABLE(jvm-feature-FEATURE, AS_HELP_STRING(
142         [--enable-jvm-feature-FEATURE], [enable jvm feature 'FEATURE' (FEATURE_DESCRIPTION)]))
143 
144     if test "x$FEATURE_SHELL" = xyes; then
145       JVM_FEATURES_ENABLED="$JVM_FEATURES_ENABLED FEATURE"
146     elif test "x$FEATURE_SHELL" = xno; then
147       JVM_FEATURES_DISABLED="$JVM_FEATURES_DISABLED FEATURE"
148     elif test "x$FEATURE_SHELL" != x; then
149       AC_MSG_ERROR([Invalid value for --enable-jvm-feature-FEATURE: '$FEATURE_SHELL'])
150     fi
151 
152     m4_undefine([FEATURE_SHELL])
153     m4_undefine([FEATURE_DESCRIPTION])
154   ])
155 
156   # Likewise, check for deprecated arguments.
157   m4_foreach(FEATURE, m4_split(jvm_features_deprecated), [
158     AC_ARG_ENABLE(jvm-feature-FEATURE, AS_HELP_STRING(
159         [--enable-jvm-feature-FEATURE],
160         [Deprecated. Option is kept for backwards compatibility and is ignored]))
161 
162     m4_define(FEATURE_SHELL, [enable_jvm_feature_]m4_translit(FEATURE, -, _))
163 
164     if test "x$FEATURE_SHELL" != x; then
165       AC_MSG_WARN([Deprecated JVM feature, will be ignored: --enable-jvm-feature-FEATURE])
166     fi
167 
168     m4_undefine([FEATURE_SHELL])
169   ])
170 
171   # Check if the user has both enabled and disabled a feature
172   UTIL_GET_MATCHING_VALUES(enabled_and_disabled, $JVM_FEATURES_ENABLED, \
173       $JVM_FEATURES_DISABLED)
174   if test "x$enabled_and_disabled" != x; then
175     AC_MSG_NOTICE([These feature are both enabled and disabled: '$enabled_and_disabled'])
176     AC_MSG_NOTICE([This can happen if you mix --with-jvm-features and --enable-jvm-feature-*])
177     AC_MSG_NOTICE([The recommendation is to only use --enable-jvm-feature-*])
178     AC_MSG_ERROR([Cannot continue])
179   fi
180 
181   # Clean up lists and announce results to user
182   UTIL_SORT_LIST(JVM_FEATURES_ENABLED, $JVM_FEATURES_ENABLED)
183   AC_MSG_CHECKING([for JVM features enabled by the user])
184   if test "x$JVM_FEATURES_ENABLED" != x; then
185     AC_MSG_RESULT(['$JVM_FEATURES_ENABLED'])
186   else
187     AC_MSG_RESULT([none])
188   fi
189 
190   UTIL_SORT_LIST(JVM_FEATURES_DISABLED, $JVM_FEATURES_DISABLED)
191   AC_MSG_CHECKING([for JVM features disabled by the user])
192   if test "x$JVM_FEATURES_DISABLED" != x; then
193     AC_MSG_RESULT(['$JVM_FEATURES_DISABLED'])
194   else
195     AC_MSG_RESULT([none])
196   fi
197 
198   # Makefiles use VALID_JVM_FEATURES in check-jvm-feature to verify correctness.
199   VALID_JVM_FEATURES="$JVM_FEATURES_VALID"
200   AC_SUBST(VALID_JVM_FEATURES)
201 ])
202 
203 ###############################################################################
204 # Helper function for the JVM_FEATURES_CHECK_* suite.
205 # The code in the code block should assign 'false' to the variable AVAILABLE
206 # if the feature is not available, and this function will handle everything
207 # else that is needed.
208 #
209 # arg 1: The name of the feature to test
210 # arg 2: The code block to execute
211 #
212 AC_DEFUN([JVM_FEATURES_CHECK_AVAILABILITY],
213 [
214   # Assume that feature is available
215   AVAILABLE=true
216 
217   # Execute feature test block
218   $2
219 
220   AC_MSG_CHECKING([if JVM feature '$1' is available])
221   if test "x$AVAILABLE" = "xtrue"; then
222     AC_MSG_RESULT([yes])
223   else
224     AC_MSG_RESULT([no])
225     JVM_FEATURES_PLATFORM_UNAVAILABLE="$JVM_FEATURES_PLATFORM_UNAVAILABLE $1"
226   fi
227 ])
228 
229 ###############################################################################
230 # Check if the feature 'cds' is available on this platform.
231 #
232 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_CDS],
233 [
234   JVM_FEATURES_CHECK_AVAILABILITY(cds, [
235     AC_MSG_CHECKING([if platform is supported by CDS])
236     if test "x$OPENJDK_TARGET_OS" = xaix; then
237       AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
238       AVAILABLE=false
239     else
240       AC_MSG_RESULT([yes])
241     fi
242   ])
243 ])
244 
245 ###############################################################################
246 # Check if the feature 'dtrace' is available on this platform.
247 #
248 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_DTRACE],
249 [
250   JVM_FEATURES_CHECK_AVAILABILITY(dtrace, [
251     AC_MSG_CHECKING([for dtrace tool])
252     if test "x$DTRACE" != "x" && test -x "$DTRACE"; then
253       AC_MSG_RESULT([$DTRACE])
254     else
255       AC_MSG_RESULT([no])
256       AVAILABLE=false
257     fi
258 
259     AC_CHECK_HEADERS([sys/sdt.h], [dtrace_headers_ok=true])
260     if test "x$dtrace_headers_ok" != "xtrue"; then
261       HELP_MSG_MISSING_DEPENDENCY([dtrace])
262       AC_MSG_NOTICE([Cannot enable dtrace with missing dependencies. See above.])
263       AVAILABLE=false
264     fi
265   ])
266 ])
267 
268 ###############################################################################
269 # Check if the feature 'jfr' is available on this platform.
270 #
271 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_JFR],
272 [
273   JVM_FEATURES_CHECK_AVAILABILITY(jfr, [
274     AC_MSG_CHECKING([if platform is supported by JFR])
275     if test "x$OPENJDK_TARGET_OS" = xaix; then
276       AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
277       AVAILABLE=false
278     else
279       AC_MSG_RESULT([yes])
280     fi
281   ])
282 ])
283 
284 ###############################################################################
285 # Check if the feature 'jvmci' is available on this platform.
286 #
287 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_JVMCI],
288 [
289   JVM_FEATURES_CHECK_AVAILABILITY(jvmci, [
290     AC_MSG_CHECKING([if platform is supported by JVMCI])
291     if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
292       AC_MSG_RESULT([yes])
293     elif test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
294       AC_MSG_RESULT([yes])
295     else
296       AC_MSG_RESULT([no, $OPENJDK_TARGET_CPU])
297       AVAILABLE=false
298     fi
299   ])
300 ])
301 
302 ###############################################################################
303 # Check if the feature 'shenandoahgc' is available on this platform.
304 #
305 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_SHENANDOAHGC],
306 [
307   JVM_FEATURES_CHECK_AVAILABILITY(shenandoahgc, [
308     AC_MSG_CHECKING([if platform is supported by Shenandoah])
309     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86" || \
310         test "x$OPENJDK_TARGET_CPU" = "xaarch64" || \
311         test "x$OPENJDK_TARGET_CPU" = "xppc64le" || \
312         test "x$OPENJDK_TARGET_CPU" = "xriscv64"; then
313       AC_MSG_RESULT([yes])
314     else
315       AC_MSG_RESULT([no, $OPENJDK_TARGET_CPU])
316       AVAILABLE=false
317     fi
318   ])
319 ])
320 
321 ###############################################################################
322 # Check if the feature 'static-build' is available on this platform.
323 #
324 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_STATIC_BUILD],
325 [
326   JVM_FEATURES_CHECK_AVAILABILITY(static-build, [
327     AC_MSG_CHECKING([if static-build is enabled in configure])
328     if test "x$STATIC_BUILD" = "xtrue"; then
329       AC_MSG_RESULT([yes])
330     else
331       AC_MSG_RESULT([no, use --enable-static-build to enable static build.])
332       AVAILABLE=false
333     fi
334   ])
335 ])
336 
337 ###############################################################################
338 # Check if the feature 'zgc' is available on this platform.
339 #
340 AC_DEFUN_ONCE([JVM_FEATURES_CHECK_ZGC],
341 [
342   JVM_FEATURES_CHECK_AVAILABILITY(zgc, [
343     AC_MSG_CHECKING([if platform is supported by ZGC])
344     if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
345       if test "x$OPENJDK_TARGET_OS" = "xlinux" || \
346           test "x$OPENJDK_TARGET_OS" = "xwindows" || \
347           test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
348         AC_MSG_RESULT([yes])
349       else
350         AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
351         AVAILABLE=false
352       fi
353     elif test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
354       if test "x$OPENJDK_TARGET_OS" = "xlinux" || \
355           test "x$OPENJDK_TARGET_OS" = "xwindows" || \
356           test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
357         AC_MSG_RESULT([yes])
358       else
359         AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
360         AVAILABLE=false
361       fi
362     elif test "x$OPENJDK_TARGET_CPU" = "xppc64le" || \
363         test "x$OPENJDK_TARGET_CPU" = "xriscv64"; then
364       if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
365         AC_MSG_RESULT([yes])
366       else
367         AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
368         AVAILABLE=false
369       fi
370     else
371       AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
372       AVAILABLE=false
373     fi
374 
375     if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
376       AC_MSG_CHECKING([if Windows APIs required for ZGC is present])
377       AC_COMPILE_IFELSE(
378         [AC_LANG_PROGRAM([[#include <windows.h>]],
379           [[struct MEM_EXTENDED_PARAMETER x;]])
380         ],
381         [
382           AC_MSG_RESULT([yes])
383         ],
384         [
385           AC_MSG_RESULT([no, missing required APIs])
386           AVAILABLE=false
387         ]
388       )
389     fi
390   ])
391 ])
392 
393 ###############################################################################
394 # Setup JVM_FEATURES_PLATFORM_UNAVAILABLE and JVM_FEATURES_PLATFORM_FILTER
395 # to contain those features that are unavailable, or should be off by default,
396 # for this platform, regardless of JVM variant.
397 #
398 AC_DEFUN_ONCE([JVM_FEATURES_PREPARE_PLATFORM],
399 [
400   # The checks below should add unavailable features to
401   # JVM_FEATURES_PLATFORM_UNAVAILABLE.
402 
403   JVM_FEATURES_CHECK_CDS
404   JVM_FEATURES_CHECK_DTRACE
405   JVM_FEATURES_CHECK_JFR
406   JVM_FEATURES_CHECK_JVMCI
407   JVM_FEATURES_CHECK_SHENANDOAHGC
408   JVM_FEATURES_CHECK_STATIC_BUILD
409   JVM_FEATURES_CHECK_ZGC
410 
411   # Filter out features by default for all variants on certain platforms.
412   # Make sure to just add to JVM_FEATURES_PLATFORM_FILTER, since it could
413   # have a value already from custom extensions.
414   if test "x$OPENJDK_TARGET_OS" = xaix; then
415     JVM_FEATURES_PLATFORM_FILTER="$JVM_FEATURES_PLATFORM_FILTER jfr"
416   fi
417 ])
418 
419 ###############################################################################
420 # Setup JVM_FEATURES_VARIANT_UNAVAILABLE and JVM_FEATURES_VARIANT_FILTER
421 # to contain those features that are unavailable, or should be off by default,
422 # for this particular JVM variant.
423 #
424 # arg 1: JVM variant
425 #
426 AC_DEFUN([JVM_FEATURES_PREPARE_VARIANT],
427 [
428   variant=$1
429 
430   # Check which features are unavailable for this JVM variant.
431   # This means that is not possible to build these features for this variant.
432   if test "x$variant" = "xminimal"; then
433     JVM_FEATURES_VARIANT_UNAVAILABLE="cds zero"
434   elif test "x$variant" = "xcore"; then
435     JVM_FEATURES_VARIANT_UNAVAILABLE="cds minimal zero"
436   elif test "x$variant" = "xzero"; then
437     JVM_FEATURES_VARIANT_UNAVAILABLE="cds compiler1 compiler2 \
438         jvmci minimal zgc"
439   else
440     JVM_FEATURES_VARIANT_UNAVAILABLE="minimal zero"
441   fi
442 
443   # Check which features should be off by default for this JVM variant.
444   if test "x$variant" = "xclient"; then
445     JVM_FEATURES_VARIANT_FILTER="compiler2 jvmci link-time-opt opt-size"
446   elif test "x$variant" = "xminimal"; then
447     JVM_FEATURES_VARIANT_FILTER="cds compiler2 dtrace epsilongc g1gc \
448         jfr jni-check jvmci jvmti management nmt parallelgc services \
449         shenandoahgc vm-structs zgc"
450     if test "x$OPENJDK_TARGET_CPU" = xarm ; then
451       JVM_FEATURES_VARIANT_FILTER="$JVM_FEATURES_VARIANT_FILTER opt-size"
452     else
453       # Only arm-32 should have link-time-opt enabled as default.
454       JVM_FEATURES_VARIANT_FILTER="$JVM_FEATURES_VARIANT_FILTER \
455           link-time-opt"
456     fi
457   elif test "x$variant" = "xcore"; then
458     JVM_FEATURES_VARIANT_FILTER="compiler1 compiler2 jvmci \
459         link-time-opt opt-size"
460   elif test "x$variant" = "xzero"; then
461     JVM_FEATURES_VARIANT_FILTER="jfr link-time-opt opt-size"
462   else
463     JVM_FEATURES_VARIANT_FILTER="link-time-opt opt-size"
464   fi
465 ])
466 
467 ###############################################################################
468 # Calculate the actual set of active JVM features for this JVM variant. Store
469 # the result in JVM_FEATURES_ACTIVE.
470 #
471 # arg 1: JVM variant
472 #
473 AC_DEFUN([JVM_FEATURES_CALCULATE_ACTIVE],
474 [
475   variant=$1
476 
477   # The default is set to all valid features except those unavailable or listed
478   # in a filter.
479   if test "x$variant" != xcustom; then
480     UTIL_GET_NON_MATCHING_VALUES(default_for_variant, $JVM_FEATURES_VALID, \
481         $JVM_FEATURES_PLATFORM_UNAVAILABLE $JVM_FEATURES_VARIANT_UNAVAILABLE \
482         $JVM_FEATURES_PLATFORM_FILTER $JVM_FEATURES_VARIANT_FILTER)
483   else
484     # Except for the 'custom' variant, where the default is to start with an
485     # empty set.
486     default_for_variant=""
487   fi
488 
489   # Verify that explicitly enabled features are available
490   UTIL_GET_MATCHING_VALUES(enabled_but_unavailable, $JVM_FEATURES_ENABLED, \
491       $JVM_FEATURES_PLATFORM_UNAVAILABLE $JVM_FEATURES_VARIANT_UNAVAILABLE)
492   if test "x$enabled_but_unavailable" != x; then
493     AC_MSG_NOTICE([ERROR: Unavailable JVM features explicitly enabled for '$variant': '$enabled_but_unavailable'])
494     AC_MSG_ERROR([Cannot continue])
495   fi
496 
497   # Notify the user if their command line options has no real effect
498   UTIL_GET_MATCHING_VALUES(enabled_but_default, $JVM_FEATURES_ENABLED, \
499       $default_for_variant)
500   if test "x$enabled_but_default" != x; then
501     AC_MSG_NOTICE([Default JVM features explicitly enabled for '$variant': '$enabled_but_default'])
502   fi
503   UTIL_GET_MATCHING_VALUES(disabled_but_unavailable, $JVM_FEATURES_DISABLED, \
504       $JVM_FEATURES_PLATFORM_UNAVAILABLE $JVM_FEATURES_VARIANT_UNAVAILABLE)
505   if test "x$disabled_but_unavailable" != x; then
506     AC_MSG_NOTICE([Unavailable JVM features explicitly disabled for '$variant': '$disabled_but_unavailable'])
507   fi
508 
509   # JVM_FEATURES_ACTIVE is the set of all default features and all explicitly
510   # enabled features, with the explicitly disabled features filtered out.
511   UTIL_GET_NON_MATCHING_VALUES(JVM_FEATURES_ACTIVE, $default_for_variant \
512       $JVM_FEATURES_ENABLED, $JVM_FEATURES_DISABLED)
513 ])
514 
515 ###############################################################################
516 # Helper function for JVM_FEATURES_VERIFY. Check if the specified JVM
517 # feature is active. To be used in shell if constructs, like this:
518 # 'if JVM_FEATURES_IS_ACTIVE(jvmti); then'
519 #
520 # Definition kept in one line to allow inlining in if statements.
521 # Additional [] needed to keep m4 from mangling shell constructs.
522 AC_DEFUN([JVM_FEATURES_IS_ACTIVE],
523 [ [ [[ " $JVM_FEATURES_ACTIVE " =~ ' '$1' ' ]] ] ])
524 
525 ###############################################################################
526 # Verify that the resulting set of features is consistent and legal.
527 #
528 # arg 1: JVM variant
529 #
530 AC_DEFUN([JVM_FEATURES_VERIFY],
531 [
532   variant=$1
533 
534   if JVM_FEATURES_IS_ACTIVE(jvmci) && ! (JVM_FEATURES_IS_ACTIVE(compiler1) || \
535       JVM_FEATURES_IS_ACTIVE(compiler2)); then
536     AC_MSG_ERROR([Specified JVM feature 'jvmci' requires feature 'compiler2' or 'compiler1' for variant '$variant'])
537   fi
538 
539   if JVM_FEATURES_IS_ACTIVE(jvmti) && ! JVM_FEATURES_IS_ACTIVE(services); then
540     AC_MSG_ERROR([Specified JVM feature 'jvmti' requires feature 'services' for variant '$variant'])
541   fi
542 
543   if JVM_FEATURES_IS_ACTIVE(management) && ! JVM_FEATURES_IS_ACTIVE(nmt); then
544     AC_MSG_ERROR([Specified JVM feature 'management' requires feature 'nmt' for variant '$variant'])
545   fi
546 
547   # For backwards compatibility, disable a feature "globally" if one variant
548   # is missing the feature.
549   if ! JVM_FEATURES_IS_ACTIVE(cds); then
550     ENABLE_CDS="false"
551   fi
552   if ! JVM_FEATURES_IS_ACTIVE(jvmci); then
553     INCLUDE_JVMCI="false"
554   fi
555   if JVM_FEATURES_IS_ACTIVE(compiler2); then
556     INCLUDE_COMPILER2="true"
557   fi
558 
559   # Verify that we have at least one gc selected (i.e., feature named "*gc").
560   if ! JVM_FEATURES_IS_ACTIVE(.*gc); then
561       AC_MSG_NOTICE([At least one gc needed for variant '$variant'.])
562       AC_MSG_NOTICE([Specified features: '$JVM_FEATURES_ACTIVE'])
563       AC_MSG_ERROR([Cannot continue])
564   fi
565 ])
566 
567 ###############################################################################
568 # Set up all JVM features for each enabled JVM variant. Requires that
569 # JVM_FEATURES_PARSE_OPTIONS has been called.
570 #
571 AC_DEFUN_ONCE([JVM_FEATURES_SETUP],
572 [
573   # Set up variant-independent factors
574   JVM_FEATURES_PREPARE_PLATFORM
575 
576   # For backwards compatibility, tentatively enable these features "globally",
577   # and disable them in JVM_FEATURES_VERIFY if a variant is found that are
578   # missing any of them.
579   ENABLE_CDS="true"
580   INCLUDE_JVMCI="true"
581   INCLUDE_COMPILER2="false"
582 
583   for variant in $JVM_VARIANTS; do
584     # Figure out if any features are unavailable, or should be filtered out
585     # by default, for this variant.
586     # Store the result in JVM_FEATURES_VARIANT_UNAVAILABLE and
587     # JVM_FEATURES_VARIANT_FILTER.
588     JVM_FEATURES_PREPARE_VARIANT($variant)
589 
590     # Calculate the resulting set of enabled features for this variant.
591     # The result is stored in JVM_FEATURES_ACTIVE.
592     JVM_FEATURES_CALCULATE_ACTIVE($variant)
593 
594     # Verify consistency for JVM_FEATURES_ACTIVE.
595     JVM_FEATURES_VERIFY($variant)
596 
597     # Keep feature list sorted and free of duplicates
598     UTIL_SORT_LIST(JVM_FEATURES_ACTIVE, $JVM_FEATURES_ACTIVE)
599     AC_MSG_CHECKING([JVM features to use for variant '$variant'])
600     AC_MSG_RESULT(['$JVM_FEATURES_ACTIVE'])
601 
602     # Save this as e.g. JVM_FEATURES_server, using indirect variable
603     # referencing.
604     features_var_name=JVM_FEATURES_$variant
605     eval $features_var_name=\"$JVM_FEATURES_ACTIVE\"
606   done
607 
608   # Unfortunately AC_SUBST does not work with non-literally named variables,
609   # so list all variants here.
610   AC_SUBST(JVM_FEATURES_server)
611   AC_SUBST(JVM_FEATURES_client)
612   AC_SUBST(JVM_FEATURES_minimal)
613   AC_SUBST(JVM_FEATURES_core)
614   AC_SUBST(JVM_FEATURES_zero)
615   AC_SUBST(JVM_FEATURES_custom)
616 
617   AC_SUBST(INCLUDE_JVMCI)
618   AC_SUBST(INCLUDE_COMPILER2)
619 
620 ])