Java requires a class initialization check when any public static method is called. But when we are calling from another method in the _same_ class, we already know that the class has been initialized, so we can optimize away the call to _Jv_InitClass, even if we're not inlining. Here's how:
Reorder the call, so that this (on x86): .globl _ZN4Test10assertHackEb .type _ZN4Test10assertHackEb, @function _ZN4Test10assertHackEb: .LFB5: .file 1 "Test.java" .loc 1 43 0 .LVL0: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: pushl %ebx .LCFI2: subl $16, %esp .LCFI3: movb 8(%ebp), %bl .loc 1 43 0 pushl $_ZN4Test6class$E .LCFI4: call _Jv_InitClass becomes something like this: .globl _ZN4Test10assertHackEb .type _ZN4Test10assertHackEb, @function _ZN4Test10assertHackEb: .LFB5: .file 1 "Test.java" .loc 1 43 0 pushl $_ZN4Test6class$E .LCFI4: call _Jv_InitClass .LVL0: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: pushl %ebx .LCFI2: subl $16, %esp .LCFI3: movb 8(%ebp), %bl and intra-class method calls to that method, call to .LVL0 instead of _ZN4Test10assertHackEb. -- Summary: Optimization: Skip _Jv_InitClass for intra-class static method calls Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: greenrd at greenrd dot org CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23500