为什么这样都无法消除掉呢

chenjingbo 2013-11-11

     最近怀疑某一个性能测试报告有问题.所以我自己大概看了一下.模拟的代码如下

 

import java.util.HashMap;
import java.util.Map;

public class Test {

    static Map<Long, String> categoryMap = new HashMap<Long, String>();


    public static void main(String[] args){
        while (true){
            categoryMap.get(14000l);
        }
    }

}

 main 方法里的无限循环就模拟性能的调用了.然后我通过

 

写道
java -Xcomp -XX:+UnlockDia
gnosticVMOptions -XX:+PrintAssembly Test > log8.txt

 查看,.还是发现了

写道
Decoding compiled method 0x0275eec8:
Code:
[Disassembling for mach='i386']
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'main' '([Ljava/lang/String;)V' in 'Test'
# parm0: ecx = '[Ljava/lang/String;'
# [sp+0x20] (sp of caller)
;; block B1 [0, 0]

0x0275efe0: mov %eax,-0x8000(%esp)
0x0275efe7: push %ebp
0x0275efe8: sub $0x18,%esp
;; block B2 [0, 0]

0x0275efeb: nop
;; block B0 [0, 15]

0x0275efec: mov $0x2024e8e8,%esi ; {oop('Test')}
0x0275eff1: mov 0x150(%esi),%esi ;*getstatic categoryMap
; - Test::main@0 (line 16)
0x0275eff7: movl $0x0,0x4(%esp)
0x0275efff: movl $0x36b0,(%esp) ;*invokestatic valueOf
; - Test::main@6 (line 16)
0x0275f006: mov %esi,0x10(%esp)
0x0275f00a: nop
0x0275f00b: call 0x0269b450 ; OopMap{[16]=Oop off=48}
;*invokestatic valueOf
; - Test::main@6 (line 16)
; {static_call}
0x0275f010: mov %eax,%edx
0x0275f012: mov 0x10(%esp),%ecx ;*invokeinterface get
; - Test::main@9 (line 16)
0x0275f016: mov $0xffffffff,%eax ; {oop(NULL)}
0x0275f01b: call 0x0269b210 ; OopMap{off=64}
;*invokeinterface get
; - Test::main@9 (line 16)
; {virtual_call}
0x0275f020: nop ; OopMap{off=65}
;*goto
; - Test::main@15 (line 16)
0x0275f021: test %eax,0x200100 ; {poll}
;; 34 branch [AL] [B0]
0x0275f027: jmp 0x0275efec
0x0275f029: nop
0x0275f02a: nop
;; Unwind handler
0x0275f02b: mov %fs:0x0(,%eiz,1),%esi
0x0275f033: mov -0xc(%esi),%esi
0x0275f036: mov 0x198(%esi),%eax
0x0275f03c: movl $0x0,0x198(%esi)
0x0275f046: movl $0x0,0x19c(%esi)
0x0275f050: add $0x18,%esp
0x0275f053: pop %ebp
0x0275f054: jmp 0x026d7be0 ; {runtime_call}
0x0275f059: hlt
0x0275f05a: hlt
0x0275f05b: hlt
0x0275f05c: hlt
0x0275f05d: hlt
0x0275f05e: hlt
0x0275f05f: hlt
[Stub Code]
0x0275f060: nop ; {no_reloc}
0x0275f061: nop
0x0275f062: mov $0x0,%ebx ; {static_stub}
0x0275f067: jmp 0x0275f067 ; {runtime_call}
0x0275f06c: nop
0x0275f06d: nop
0x0275f06e: mov $0x0,%ebx ; {static_stub}
0x0275f073: jmp 0x0275f073 ; {runtime_call}
[Exception Handler]
0x0275f078: mov $0xdead,%ebx
0x0275f07d: mov $0xdead,%ecx
0x0275f082: mov $0xdead,%esi
0x0275f087: mov $0xdead,%edi
0x0275f08c: call 0x026d9c40 ; {runtime_call}
0x0275f091: push $0x83c8bc0 ; {external_word}
0x0275f096: call 0x0275f09b
0x0275f09b: pusha
0x0275f09c: call 0x0822c2e0 ; {runtime_call}
0x0275f0a1: hlt
[Deopt Handler Code]
0x0275f0a2: push $0x275f0a2 ; {section_word}
0x0275f0a7: jmp 0x0269bac0 ; {runtime_call}

可以看到, ,Assembly code里确实调用了 getstatic valueof get 等操作

我初步的结论是,编辑器并没有把 

 

categoryMap.get(14000l);

 这段代码给优化消除掉..

 

 

所以请教一下,是不是真的就没有消除掉,还是说我的分析有问题.

另外,顺便请教一下,为什么我用 

写道
java version "1.6.0_25-ea-fastdebug"
Java(TM) SE Runtime Environment (build 1.6.0_25-ea-fastdebug-b01)
Java HotSpot(TM) Client VM (build 20.0-b08-fastdebug, mixed mode)

 这个版本,无法使用 

写道
D:\software\jdk6_fastdebug\jdk1.6.0_25\fastdebug\bin>java -Xcomp -XX:+UnlockDia
gnosticVMOptions -XX:+PrintOptoAssembly Test > log8.txt
Unrecognized VM option '+PrintOptoAssembly'
Could not create the Java virtual machine.

 PrintOptoAssembly  参数.

谢谢.

Global site tag (gtag.js) - Google Analytics