Bug 23500 - Optimization: Skip _Jv_InitClass for intra-class static method calls
Summary: Optimization: Skip _Jv_InitClass for intra-class static method calls
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.2
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2005-08-20 20:00 UTC by Robin Green
Modified: 2006-03-05 03:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-05 03:49:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Green 2005-08-20 20:00:46 UTC
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.
Comment 1 Andrew Pinski 2005-08-20 20:10:23 UTC
Confirmed.