Loading... (original) (raw)

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.