Going on a Warning Hunt

Like the children's story "Going on a Bear Hunt" it's time for a "Going on a Warning Hunt" in the OpenJDK sources.

You'll probably see a set of bugs/rfes being filed and fixed over the next few months related to reducing the warning messages in the OpenJDK builds.

As the warnings get fixed, we also may want to dial up the warnings found with compiler options that ask for more warning diagnostics. We could even include the use of tools like pscan and findbugs, but that's beyond the scope of this hunt. Compiler options to get more warning diagnostics, treat warnings as fatal, and suppress specific warnings:

Compiler Warnings Requested Make Warnings Fatal Disable Specific Warnings
gcc/g++ -W -Wall -Wno-unused -Wno-parentheses -Werror -Wno-option
Sun Studio C++ +w (Added recently in jdk Makefiles) -errwarn=%all -erroff=tag (Use -errtags to get tags)
Sun Studio C -v -errwarn=%all -erroff=tag (Use -errtags to get tags)
Visual Studio -W3 -WX -wdnumber
Java Compiler -Xlint:all -Werror In the source: @SuppressWarnings("warning")

Making warnings fatal can be problematic. Each compiler version or release can introduce new warnings and it's a bit frustrating to get a build failure because you used a slightly different compiler. So we may need to make sure the compiler is a specific version or release before making the warnings fatal. The Java Compiler may be the exception, but it may be a while before we get to the point where we can turn this on.

Fixing warnings in native code can be more risky than fixing them in Java code. Some common things to watch out for:

  • Casting pointers to and from integers can be tricky, it shouldn't happen very often and when it does great care needs to be taken in making sure the complete pointer is contained in the integer type. Pointers will be 64 bits in some situations and will require a integer big enough to hold the full 64 bits. The type void\* is the so called generic pointer and you may find it necessary to cast a pointer to the generic pointer type before casting it to anything else. Some people will use size_t as a guaranteed integer type that can hold a pointer, others use intptr_t which is the integral type result for pointer subtracts.
  • Casts to long. Windows compilers may define long to be 32 bits even in 64 bit mode, so be careful casting any kind of pointer to a long.
  • Functions like strlen() return the type size_t which may be a 64 bit integral type. It's not unusual to always cast this type to an int but be careful to consider if it ever makes sense that you might need a larger result than what can be held in a 32 bit integer.
  • It's a good idea to always be explicit when you are downsizing an integral value. Passing an int to a function that expects a short probably warrants an explicit cast to int. Many compiler warnings relate to the implicit downsizing conversion the compiler will perform on assignments or arguments passed into function calls.
  • No consequence statement warnings happen when the expression statement makes no assignments or function calls. This can happen with debug statements that result in (0). Macros like assert(expression) should result in nothing when not generating debug code.
  • Suppressing warnings with options or #pragma directives should probably be a last resort.

So far the bugs I have included for this warning hunt are:

  • 6255702: Need to clean up remaining var-args related warnings.
  • 6214406: MS VC++ compiler warning at jni.h when using fastcall, enable optimization
  • 6323942: jvmti.h causes C compiler warning
  • 6375033: Hotspot build warnings need cleanup
  • 6496269: Many warnings generated from com/sun/java/util/jar/pack/\*.cpp when compiled on Linux
  • 6712344: Add -errwarn=%all to Solaris Sun Studio compiles (all warnings being fatal)
  • 6722802: Code improvement and warnings removing from the javax.swing.text pa ckage
  • 6725543: Compiler warnings in serviceability native code
  • 6725625: Compiler warnings in awt code
  • 6725818: Compiler warnings in OpenGL code
  • 6725819: Compiler warnings in gtk2 glue code
  • 6725821: Compiler warnings in medialib code
  • 6726309: Eliminate warnings from NIO code
  • 6727661: Code improvement and warnings removing from the swing/plaf packages
  • 6727662: Code improvement and warnings removing from swing packages
  • 6727683: Cleanup use of COMPILER_WARNINGS_FATAL in makefiles

And the hunt is on. Lock and load. :\^)



Post a Comment:
Comments are closed for this entry.

Various blogs on JDK development procedures, including building, build infrastructure, testing, and source maintenance.


« July 2016