论坛首页 Java企业应用论坛

我也造了个轮子:BeanMapping(属性拷贝)

浏览 24750 次
该帖已经被评为良好帖
作者 正文
   发表时间:2011-07-12  
Fast array access
One area Java can be slower is array access. This is because it implicitly does bounds checking. The JVM is smart enough to optimise checks for loops by checking the first and last element, however this doesn’t always apply.

One work around is to use the Unsafe class (which is only available on some JVMs, OpenJDK JVMs do) This class has getXxxx() and setXxxx() for each primitive type and gives you direct access to an object, array or direct memory where you have to do the bounds checking. In native code, these are compiled to single machine code instruction. There is also a getObject(), setObject() methods however I suspect that they don’t provide as much of a performance improvement (by the time you access the Object as well)

You can check the native code generated for a method by downloading the debug version of the OpenJDK and getting it to print the compiled native code.

0 请登录后投票
   发表时间:2011-07-12  
http://blog.middleware123.com/2740.html
Unsafe的性能
0 请登录后投票
   发表时间:2011-07-12  
原理大概是可以通过Unsafe,来得到一个field距离它Object头的偏移,然后native方法来对其进行操作,直接操作内存的。
0 请登录后投票
   发表时间:2011-07-12  
wqq686 写道
原理大概是可以通过Unsafe,来得到一个field距离它Object头的偏移,然后native方法来对其进行操作,直接操作内存的。


以前看cocurrent代码时,大致指导Unsafe的几个方法:compareAndSwapInt,putXXXVolatile,还真没留意过其他的方法。

不过理论上不太会有明显提升,sun也不至于这么傻,高性能的好东西自然在自己的一些反射调用上会做相关优化。

可以看下java.lang.reflect.Field.getInt()等等方法底层实现已经全都是直接调用UnSafe进行处理,比如UnsafeIntegerFieldAccessorImpl.

还有针对java.lang.reflect.Method.invoke()的实现NativeMethodAccessorImpl,也设置了一个阀值,超过阀值进行静态编译生成字节码。

不过你提的针对Array Access倒是可以有一定的提升,有空我也测试一把

0 请登录后投票
   发表时间:2011-07-12  
讲的思路很清晰。多谢
0 请登录后投票
   发表时间:2011-11-15  
一定需要写配置?
0 请登录后投票
   发表时间:2011-11-15   最后修改:2011-11-15
depravedangel 写道
一定需要写配置?


不需要,可以和BeanUtils一样的使用,支持自动分析扫描,不过性能上优于BeanUtils而已
配置只是允许你自定义一些特定的映射逻辑,比如不同字段,不同转化等
0 请登录后投票
   发表时间:2011-11-23  
pengranxiang 写道
请问性能测试的部分,是用什么工具做的?

很像Highcharts
0 请登录后投票
   发表时间:2011-11-29  
性能测试是自己写上去的吧!
0 请登录后投票
   发表时间:2011-11-30  
frank_zeng 写道
性能测试是自己写上去的吧!


自己做的数据,性能测试结果是用google xls画的
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics