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

Change ShouldNotReachHere() to never return

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 10
    • Component/s: hotspot
    • Labels:
      None

      Description

      Today the it's possible to return out from ShouldNotReachHere(). This sometimes force us to add return statement and assignments that don't make sense. By telling the compiler that ShouldNotReachHere is a dead end, then we can get rid of these unnecessary constructs.

      We could get rid of return statements after ShouldNotReachHere():
      bool is_marked() {
        // actual code here

        // Execution path that "should not" happen.
        ShouldNotReachHere();
        return false;
      }

      The following will actually use an uninitialized value if we direct the JVM to return out from ShouldNotReachHere(). The compiler will find this if we turn on -Wuninitialized. But if we make ShouldNotReachHere() a dead end, then the compiler will be happy with this construct.

      int type;
      switch (value) {
        case TYPE_OOP: type = 0; break;
        case TYPE_KLASS: type = 1; break;
        default: ShouldNotReachHere();
      }
      report(type)

      This also applies to other error reporting macros in debug.hpp.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              stefank Stefan Karlsson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: