netty/netty — pull request #3227 by normanmaurer (2014-12-10 05:49:07+00:00)
Title: Throw exception from outside of JNI / throw pre-instanced exceptions

Motivation:

Currently IOException and ClosedChannelException are thrown from inside the JNI methods. This means we create a new IOException / ClosedChannelException everytime we need to throw one. This is quite expensive because of fillStackTrace() that is invoked automatically in the constructor. For a few exceptions it would be better to throw pre-instanced exceptions (with an empty stacktrace) as the stacktrace is not helpful anyway, because these exceptions only signal some state and nothing "bad". This is is true for example for "connection reset".
Moving the throwing of exeptions outside of JNI allows us to handle some exceptions in a special way (like throw pre-instanced exceptions).

Modification:
Change most JNI methods to return a negative value on exception which is basically just '-errno'. This way we can check the return value and see what kind of exception needs to get thrown or if the return value just signals something expected. These modifications are made for all methods that not need to return a POJO.

Result:
Performance gain when exception is thrown because of connection reset or closed channels.