Contribute towards native code which override to OpenJDK

Erik Joelsson erik.joelsson at oracle.com
Mon Jan 22 17:13:00 UTC 2018


Hello Archana,

Before attempting this change, did you actually try overriding native 
source files? The support for this has been in NativeCompilation.gmk 
since a very long time (well before the support for overriding java 
source files was added) using this piece of logic further up the file:

   # Generate the .o (.obj) file name and place it in the bin dir.
   $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2))
   # Only continue if this object file hasn't been processed already. 
This lets the first found
   # source file override any other with the same name.
   ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
     $1_OBJS_SO_FAR+=$$($1_$2_OBJ)

This also relies on the line from your patch below:

    # Find all files in the source trees. Preserve order.
    $1_SRCS := $$(foreach s, $$($1_SRC), $$(call CacheFind,$$(s)))


By preserving order of source dirs, we let the first listed source 
location override any later location.

We use this both for overriding shared code with platform specific as 
well as closed overriding open. If this is not working for you, I would 
be interested to know how your use case differs from ours.

/Erik

On 2018-01-19 05:07, Archana Nogriya wrote:
> Hi,
>
> Why this contribution is required
>
> These changes are to support the override of native C/C++ source by the
> SetupNativeCompilation macro in a similar way to how java classes can be
> overridden in SetupJavaCompilation. This will enable extension/closed
> source providers to easily override native implementations.
>
> Changes were made in:
>
> make/common/NativeCompilation.gmk
> diff -r 3a52333a5e57 make/common/NativeCompilation.gmk
> --- a/make/common/NativeCompilation.gmk Tue Jan 02 16:35:04 2018 -0500
> +++ b/make/common/NativeCompilation.gmk Tue Jan 16 13:42:54 2018 +0000
> @@ -511,8 +511,14 @@
>         $$(error SRC specified to SetupNativeCompilation $1 contains
> missing directory $$d)))
>   
>     # Find all files in the source trees. Preserve order.
> -  $1_SRCS := $$(foreach s, $$($1_SRC), $$(call CacheFind,$$(s)))
> +  $1_SRCS := $$(call uniq, $$(foreach s, $$($1_SRC), $$(call
> CacheFind,$$(s))))
>     $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
> +  $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \
> +       $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC),
> $$(s))) \
> +    $$(if $$($1_$$(relative_src)), \
> +      $$(eval $1_NATIVE_EXCLUDE_FILES += $$(s)), \
> +      $$(eval $1_$$(relative_src) := 1) $$(s))))
> +  $1_SRCS := $$(filter-out $$($1_NATIVE_EXCLUDE_FILES), $$($1_SRCS))
>     # Extract the C/C++ files.
>     ifneq ($$($1_EXCLUDE_PATTERNS), )
>       # We must not match the exclude pattern against the src root(s).
>
>
>
> This new code has been tested by building with latest JDK11. Build has
> been successful.
> Please let me know what is your view on these changes and if we can
> contribute to openJDK.
>
>
> Thanks and Regards
> Archana Nogriya
> IBM Java Runtime, Open Java Developer
> IBM Hursley
> Tel: Internal - 247073, External - +44 (0) 1962 81 7073
> Office Mobile: 07500095480
> Email: archana.nogriya at uk.ibm.com
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU



More information about the build-dev mailing list