Reduce locking on the class cache

Backported performance patches from trunk which reduce locking on the class cache.

http://freemarker.svn.sourceforge.net/viewvc/freemarker/trunk/freemarker/src/freemarker/ext/beans/BeansWrapper.java?r1=944&r2=1117
http://freemarker.svn.sourceforge.net/viewvc/freemarker/trunk/freemarker/src/freemarker/ext/beans/BeansModelCache.java?view=log