Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8238999

Remove MemRegion custom new/delete operator overloads

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 15
    • 15
    • hotspot
    • gc
    • b11

    Description

      In the review for JDK-8238854 we found that the MemRegion class uses custom overloaded new/delete operators.

      These operators have been introduced in JDK-8021954 for clang compatibility to avoid a SIGSEGV in a test case:

      "This seems to be a change in behavior between llvm-g++ and clang++. Specifically how the clang++ compiler handles a user defined ::operator new() in the situation where that ::operator new() can return NULL. The test's purpose is to test for OutOfMemoryError obtained from filling memory with classes. Thus Metaspace::allocate should and does throw an OOM and return NULL to Klass::operator new(). Unlike llvm-g++, clang++ continues to construct the object with a NULL "this" pointer. Thus, why we are receiving a SIGSEGV in Metadata::Metadata() constructor. If we want clang++ to detect the NULL and not continue construction according to this article 'noexcept' specifications are needed.

      This article provides a good explanation: http://comments.gmane.org/gmane.comp.compilers.clang.devel/30992."

      With the summary:

      "Summary of fix:
          On MacOS, currently Hotspot is built specifying the -fcheck-new command line option to the llvm-g++ compiler.
          The -fcheck-new option directs the compiler to "check that the pointer returned by operator new is non-null before attempting to modify the storage allocated." The clang++ compiler does not support the -fcheck-new option. To obtain similiar functionality when building Hotspot with clang++, empty exception throw() specifications must be added to all user-defined operator new()'s."

      I.e. some clang compatibility problem.

      However, in the review thread the following points came up:
      - the code that had the wrong behavior has been removed
      - all existing users need to care about a NULL return value
      - the overloaded new/delete are declared throw() which is strange for hotspot
      - there may actually no point in using -fcheck-new, which caused the issue

      Mentioned review thread starts at http://mail.openjdk.java.net/pipermail/hotspot-gc-dev/2020-February/028544.html

      Attachments

        Issue Links

          Activity

            People

              tschatzl Thomas Schatzl
              tschatzl Thomas Schatzl
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: