RFC: JEP JDK-8208089: Implement C++14 Language Features
Thomas Stüfe
thomas.stuefe at gmail.com
Mon Oct 8 10:48:57 UTC 2018
Hi Kim,
is this JEP only about C++14 features or shall we discuss older
features too? The reason I am asking is that I would like us to
officially endorse namespaces. Not inline namespaces, just plain old
namespaces.
<quote>HotSpot makes very limited use of namespaces.</quote>
Not really true, we already use them. E.g. in metaspace coding, I used
them to keep the global name space clean and to keep internals
internal. This was met with positive reviews, and it works on all
toolchains, so compiler support should not be a problem. Using
namespaces, we could get slowly replace the "AllStatic" classes, which
are namespaces in all but name. In contrast to classes, namespaces can
be spread over multiple files and compilation units, and allow for
cleaner separation of internal and external coding.
It also would allow us to get rid the middle-of-header-platform-inclusions:
For example, today we have:
[os.hpp]
class os: AllStatic {
....
(platform independent, outward facing os:: functions)
#include "os_linux.hpp"
>> (Inner class "Linux" with platform specific os functions)
...
}
Not only is the inclusion in the middle of a class terrifying, it also
means the shared, outward facing os:: namespace contains class Linux
and lots of platform specific internals.
With namespaces one could:
[os.hpp]
namespace os {
....
(platform independent, outward facing os:: functions)
....
}
[os_linux.hpp]
namespace os {
namespace Linux {
(linux specific os functions)
}
}
I think this is way cleaner, and keeps platform specifics from
including files which only care for the shared os interface.
--
Note that I would prefer forbidding the "using" directive for callers
of namespace functions, but rather force them to spell out the
namespace:
So, instead of this:
using os;
jlong m = available_memory();
I would prefer this, which is our current practice with AllStatic childs:
jlong m = os::available_memory();
The latter form would keep the code grepable.
Best Regards, Thomas
On Wed, Oct 3, 2018 at 9:13 PM Kim Barrett <kim.barrett at oracle.com> wrote:
>
> I've submitted a JEP for
>
> (1) enabling the use of C++14 Language Features when building the JDK,
>
> (2) define a process for deciding and documenting which new features
> can be used or are forbidden in HotSpot code,
>
> (3) provide an initial list of permitted and forbidden new features.
>
> https://bugs.openjdk.java.net/browse/JDK-8208089
>
More information about the core-libs-dev
mailing list