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

Change ShouldNotReachHere() to never return

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P3 P3
    • 10
    • None
    • hotspot
    • None

      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.

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

              Created:
              Updated:
              Resolved: