Skip to content

Commit 8537fb3

Browse files
authored
Merge pull request #2094 from SAP/pr-jdk-26+23
Merge to tag jdk-26+23
2 parents 015e3c1 + c754e3e commit 8537fb3

File tree

730 files changed

+37554
-27376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

730 files changed

+37554
-27376
lines changed

doc/hotspot-style.html

Lines changed: 153 additions & 46 deletions
Large diffs are not rendered by default.

doc/hotspot-style.md

Lines changed: 149 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ support for more recent Standards must of course stick with the
413413
original C++98/03 subset.)
414414

415415
This section describes that subset. Features from the C++98/03
416-
language may be used unless explicitly excluded here. Features from
417-
C++11, C++14, and C++17 may be explicitly permitted or explicitly excluded,
416+
language may be used unless explicitly forbidden here. Features from
417+
C++11, C++14, and C++17 may be explicitly permitted or explicitly forbidden,
418418
and discussed accordingly here. There is a third category, undecided
419419
features, about which HotSpot developers have not yet reached a
420420
consensus, or perhaps have not discussed at all. Use of these
421-
features is also excluded.
421+
features is also forbidden.
422422

423423
(The use of some features may not be immediately obvious and may slip
424424
in anyway, since the compiler will accept them. The code review
@@ -427,7 +427,7 @@ process is the main defense against this.)
427427
Some features are discussed in their own subsection, typically to provide
428428
more extensive discussion or rationale for limitations. Features that
429429
don't have their own subsection are listed in omnibus feature sections
430-
for permitted, excluded, and undecided features.
430+
for permitted, forbidden, and undecided features.
431431

432432
Lists of new features for C++11, C++14, and C++17, along with links to their
433433
descriptions, can be found in the online documentation for some of the
@@ -494,15 +494,16 @@ worthwhile, given the alternatives.
494494

495495
### Memory Allocation
496496

497-
Do not use the standard global allocation and deallocation functions
498-
(operator new and related functions). Use of these functions by HotSpot
499-
code is disabled for some platforms.
497+
Do not use the standard global allocation and deallocation functions (global
498+
`operator new` and related functions), other than the non-allocating forms of
499+
those functions. Use of these functions by HotSpot code is disabled for some
500+
platforms.
500501

501502
Rationale: HotSpot often uses "resource" or "arena" allocation. Even
502503
where heap allocation is used, the standard global functions are
503-
avoided in favor of wrappers around malloc and free that support the
504-
VM's Native Memory Tracking (NMT) feature. Typically, uses of the global
505-
operator new are inadvertent and therefore often associated with memory
504+
avoided in favor of wrappers around `malloc` and `free` that support the
505+
JVM's Native Memory Tracking (NMT) feature. Typically, uses of the global
506+
`operator new` are inadvertent and therefore often associated with memory
506507
leaks.
507508

508509
Native memory allocation failures are often treated as non-recoverable.
@@ -560,7 +561,39 @@ Bug for similar gdb problems.
560561

561562
### C++ Standard Library
562563

563-
Avoid using the C++ Standard Library.
564+
Only curated parts of the C++ Standard Library may be used by HotSpot code.
565+
566+
Functions that may throw exceptions must not be used. This is in accordance
567+
with the HotSpot policy of [not using exceptions](#error-handling).
568+
569+
Also in accordance with HotSpot policy, the
570+
[standard global allocator must not be used](#memory-allocation). This means
571+
that uses of standard container classes cannot presently be used, as doing so
572+
requires specialization on some allocator type that is integrated with the
573+
existing HotSpot allocation mechanisms. (Such allocators may be provided in
574+
the future.)
575+
576+
Standard Library identifiers should usually be fully qualified; `using`
577+
directives must not be used to bring Standard Library identifiers into scope
578+
just to remove the need for namespace qualification. Requiring qualification
579+
makes it easy to distinguish between references to external libraries and code
580+
that is part of HotSpot.
581+
582+
As with language features, Standard Library facilities are either permitted,
583+
explicitly forbidden, or undecided (and so implicitly forbidden).
584+
585+
Most HotSpot code should not directly `#include` C++ Standard Library headers.
586+
HotSpot provides a set of wrapper headers for the Standard Library headers
587+
containing permitted definitions. These wrappers are in the `cppstdlib`
588+
directory, with the same name as the corresponding Standard Library header and
589+
a `.hpp` extension. These wrappers provide a place for any additional code
590+
(some of which may be platform-specific) needed to support HotSpot usage.
591+
592+
These wrappers also provide a place to document HotSpot usage, including any
593+
restrictions. The set of wrappers and the usage documentation should be
594+
considered part of HotSpot style. Any changes are subject to the same process
595+
as applies to this document. (For historical reasons, there may be many direct
596+
inclusions of some C++ Standard Library headers.)
564597

565598
Historically, HotSpot has mostly avoided use of the Standard
566599
Library.
@@ -577,43 +610,59 @@ Some reasons for this include
577610
Standard Library facilities is exceptions. HotSpot does not use
578611
exceptions and, for platforms which allow doing so, builds with them
579612
turned off. Many Standard Library facilities implicitly or explicitly
613+
use exceptions. On the other hand, many don't, and can be used without
614+
concern for this issue. Others may have a useful subset that doesn't
580615
use exceptions.
581616

582617
* `assert`. An issue that is quickly encountered is the `assert` macro name
583618
collision ([JDK-8007770](https://bugs.openjdk.org/browse/JDK-8007770)).
584-
Some mechanism for addressing this would be needed before much of the
585-
Standard Library could be used. (Not all Standard Library implementations
586-
use assert in header files, but some do.)
587-
588-
* Memory allocation. HotSpot requires explicit control over where
589-
allocations occur. The C++98/03 `std::allocator` class is too limited
590-
to support our usage. (Changes in more recent Standards may remove
591-
this limitation.)
619+
(Not all Standard Library implementations use `assert` in header files, but
620+
some do.) HotSpot provides a mechanism for addressing this, by establishing a
621+
scope around the include of a library header where the HotSpot `assert` macro
622+
is suppressed. One of the reasons for using wrapper headers rather than
623+
directly including standard headers is to provide a central place to deal with
624+
this issue for each header.
625+
626+
* Memory allocation. HotSpot requires explicit control over where allocations
627+
occur. The C++98/03 `std::allocator` class is too limited to support our
628+
usage. But changes to the allocator concept in more recent Standards removed
629+
some of the limitations, supporting stateful allocators. HotSpot may, in the
630+
future, provide standard-conforming allocators that are integrated with
631+
HotSpot's existing allocation mechanisms.
592632

593633
* Implementation vagaries. Bugs, or simply different implementation choices,
594634
can lead to different behaviors among the various Standard Libraries we need
595-
to deal with.
596-
597-
* Inconsistent naming conventions. HotSpot and the C++ Standard use
598-
different naming conventions. The coexistence of those different conventions
599-
might appear jarring and reduce readability.
600-
601-
There are a few exceptions to this rule.
602-
603-
* `#include <new>` to use placement `new`, `std::nothrow`, and `std::nothrow_t`.
604-
* `#include <limits>` to use `std::numeric_limits`.
605-
* `#include <type_traits>` with some restrictions, listed below.
606-
* `#include <cstddef>` to use `std::nullptr_t` and `std::max_align_t`.
607-
608-
Certain restrictions apply to the declarations provided by `<type_traits>`.
609-
610-
* The `alignof` operator should be used rather than `std::alignment_of<>`.
611-
612-
TODO: Rather than directly \#including (permitted) Standard Library
613-
headers, use a convention of \#including wrapper headers (in some
614-
location like hotspot/shared/stdcpp). This provides a single place
615-
for dealing with issues we might have for any given header, esp.
616-
platform-specific issues.
635+
to deal with. But only selected parts of the Standard Library are being
636+
permitted, and one of the selection criteria is maturity. Some of these
637+
facilities are among the most heavily tested and used C++ codes that exist.
638+
639+
* Inconsistent naming conventions. HotSpot and the C++ Standard use different
640+
naming conventions. The coexistence of those different conventions might
641+
appear jarring and reduce readability. However, experience in some other code
642+
bases suggests this isn't a significant problem, so long as Standard Library
643+
names are namespace-qualified. It is tempting to bring the Standard Library
644+
names into scope via a `using std;` directive. Doing so makes writing code
645+
using those names easier, since the qualifiers don't need to be included. But
646+
there are several reasons not to do that.
647+
648+
* There is a risk of future name collisions. Additional Standard Library
649+
headers may be included, adding to the list of names being used. Also,
650+
future versions of the Standard Library may add currently unknown names to
651+
the headers already being included.
652+
653+
* It may harm readability. Code where this is relevant is a mixture of the
654+
local HotSpot naming conventions and the Standard Library's (or other
655+
3rd-party library's) naming conventions. With only unqualified names, any
656+
distinctions from the naming conventions for the different code sources
657+
are lost. Instead one may end up with an undifferentiated mess, where it's
658+
not obvious whether an identifier is from local code that is inconsistent
659+
with HotSpot style (and there's a regretable amount of that for historical
660+
reasons), or is following some other convention. Having the qualifiers
661+
disambiguates that.
662+
663+
* It can be helpful to know, at a glance, whether the definition is in
664+
HotSpot or elsewhere, for purposes of looking up the definition or
665+
documentation.
617666

618667
### Type Deduction
619668

@@ -1529,9 +1578,9 @@ single-argument form are permitted.
15291578
* Allow `typename` in template template parameter
15301579
([n4051](http://wg21.link/n4051)) &mdash; template template parameters are
15311580
barely used (if at all) in HotSpot, but there's no reason to artificially
1532-
disallow this syntactic regularization in any such uses.
1581+
forbid this syntactic regularization in any such uses.
15331582
1534-
## Excluded Features
1583+
## Forbidden Features
15351584
15361585
### Structured Bindings
15371586
@@ -1581,7 +1630,32 @@ initialization for classes with base classes
15811630
aggregate classes, preferring explicit constructors even for very simple
15821631
classes.
15831632
1584-
### Additional Excluded Features
1633+
### Additional Forbidden Features
1634+
1635+
* `<algorithm>`, `<iterator>`, `<numeric>`<br>
1636+
Not useful without standard containers or similar classes in HotSpot.
1637+
1638+
* `<bitset>` - Overlap with HotSpot `BitMap`.
1639+
1640+
* `<cassert>`, `assert.h` - HotSpot has its own `assert` macro.
1641+
1642+
* `<exception>`, `<stdexcept>` - Use of [exceptions](#error-handling) is not
1643+
permitted.
1644+
1645+
* Thread support - `<thread>`, `<mutex>`, `<shared_mutex>`,
1646+
`<condition_varible>`, `<future>`<br>
1647+
HotSpot has its own threading support.
1648+
1649+
* Streams - HotSpot doesn't use the C++ I/O library.
1650+
1651+
* `<scoped_allocator>` - Not useful without specialized allocators.
1652+
1653+
* `<string>` - Requires allocator support, similar to standard containers.
1654+
1655+
* `<typeinfo>`, `<typeindex>`<br>
1656+
Use of [runtime type information](#runtime-type-information) is not permitted.
1657+
1658+
* `<valarray>` - May allocate, but is not allocator-aware.
15851659
15861660
* New string and character literals
15871661
* New character types
@@ -1880,9 +1954,40 @@ should need to know about this feature. But if someone does come up with a
18801954
good use-case, it's likely that the alternatives are significantly worse,
18811955
because pack manipulation without this can be complicated.
18821956
1957+
* [`<tuple>`](https://en.cppreference.com/w/cpp/header/tuple.html) &mdash;
1958+
Prefer named access to class objects, rather than indexed access
1959+
to anonymous heterogeneous sequences. In particular, a standard-layout
1960+
class is preferred to a tuple.
1961+
18831962
* `std::invoke<>()`
18841963
([n4169](http://wg21.link/n4169))
18851964
1965+
* [`<chrono>`](https://en.cppreference.com/w/cpp/header/chrono.html) &mdash;
1966+
The argument for chrono is that our existing APIs aren't serving us well.
1967+
chrono provides strong type safety. We've had multiple cases of mistakes like
1968+
a double seconds being treated as double milliseconds or vice versa, and other
1969+
similar errors. But it would be a large effort to adopt chrono. We'd also need
1970+
to decide whether to use the predefined clocks or hook up chrono to our
1971+
clocks. It may be that using the predefined clocks is fine, but it's a
1972+
question that needs careful study.
1973+
1974+
* [`<initializer_list>`](https://en.cppreference.com/w/cpp/header/initializer_list.html) &mdash;
1975+
The potential ambiguity between some forms of direct initialization and
1976+
initializer list initialization, and the resolution of that ambiguity, is
1977+
unfortunate.
1978+
1979+
* [`<ratio>`](https://en.cppreference.com/w/cpp/header/ratio.html) &mdash;
1980+
`<ratio>` is a *compile-time* rational arithmetic package. It's also fixed
1981+
(though parameterized) precision. It's not a general purpose rational
1982+
arithmetic facility. It appears to have started out as an implementation
1983+
detail of chrono, and was extracted and promoted to a public facility in the
1984+
belief that it has broader utility.
1985+
1986+
* [`<system_error>`](https://en.cppreference.com/w/cpp/header/system_error.html) &mdash;
1987+
We don't really have a generally agreed upon mechanism for managing
1988+
errors. Instead, we have a plethora of bespoke ad hoc mechanisms. Managing
1989+
errors is a topic of substantial discussion. `<system_error>` might end up
1990+
being a part of a result from that discussion.
18861991
18871992
18881993
[ADL]: https://en.cppreference.com/w/cpp/language/adl

make/Main.gmk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ $(eval $(call SetupTarget, symbols-image, \
461461
TARGET := symbols, \
462462
))
463463

464-
$(eval $(call SetupTarget, static-launcher, \
464+
$(eval $(call SetupTarget, static-launchers, \
465465
MAKEFILE := StaticLibs, \
466-
TARGET := static-launcher, \
466+
TARGET := static-launchers, \
467467
DEPS := hotspot-static-libs static-libs, \
468468
))
469469

@@ -1290,7 +1290,7 @@ ifeq ($(call isTargetOs, macosx), true)
12901290
legacy-images: mac-legacy-jre-bundle
12911291
endif
12921292

1293-
static-exploded-image: static-launcher exploded-image
1293+
static-exploded-image: static-launchers exploded-image
12941294

12951295
# These targets build the various documentation images
12961296
docs-jdk-image: docs-jdk

0 commit comments

Comments
 (0)