[SPARK-2104] Fix task serializing issues when sort with Java non serializable class

Details can be see in [SPARK-2104](https://issues.apache.org/jira/browse/SPARK-2104). This work is based on Reynold's work, add some unit tests to validate the issue.

@rxin , would you please take a look at this PR, thanks a lot.


Hi Reynold, thanks for your comments, will this field `partitions` be used in executor side, I think this field can be transient according to my knowledge, am I miss something?