Results 1 to 5 of 5
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default How to tell if I'm nearing the 64K method size limit?

    Of course I would never write a method this large by hand, but I'm dealing with generated code here. I have a 600-line switch statement with about 180 cases in it, and it's only going to get larger. Is there a way to tell how large the compiled method currently is?
    Get in the habit of using standard Java naming conventions!

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to tell if I'm nearing the 64K method size limit?

    TIL about javap: http://www.javaranch.com/journal/200...ine-javap.html

    My giant switch is well under the 64K limit. However, it is over the 8K limit for JIT compilation. Apparently there is a command line switch to remove that limit. Its use is discouraged by some, though they don't seem to be considering generated code: -XX:-DontCompileHugeMethods | Blog of Jeroen Leenarts

    I haven't noticed any performance issues, so I'll just carry on for now.
    Get in the habit of using standard Java naming conventions!

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,916
    Rep Power
    5

    Default Re: How to tell if I'm nearing the 64K method size limit?

    I wonder what is used to determine if the method is too large? Clearly, the size of the local variable storage doesn't matter since i just tested it out. Also, I am curious as to what your code does to requires so many cases? Not a criticism, just curious. It almost sounds like the output from a Bison generated parser.

    Regards,
    Jim
    Last edited by jim829; 04-13-2013 at 06:58 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to tell if I'm nearing the 64K method size limit?

    If I understand correctly, it's just the number of bytecode instructions. It has nothing to do with the number or size of data allocations. The 64K limit is a hard limit of the JVM, so it's enforced by the compiler. The 8K limit for JIT is more of a performance tradeoff.

    My giant switch is part of the output of a rather weird lexer generator that I wrote. It identifies tokens using a conventional tableized automaton. But then instead of feeding the tokens to a single parser method, it calls a different method for each one. The big switch consists of ordered and consecutive integer cases, most of which just iterate over a set of observers and call some method on each of them with the arguments passed to the method that contains the switch. A few cases also manipulate the lexer state. None of them allocate any local variables, so the GC slowdowns associated with huge methods don't seem to apply.
    Get in the habit of using standard Java naming conventions!

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to tell if I'm nearing the 64K method size limit?

    One thing I learned while reading about all this is that the compiler synthesizes a method call for each element of an array initializer; i.e., int[] foo = new int[] { 0, 1, 2, ... n } generates n method calls. This is another example of something you'd never run into with hand-written code, but I've seen huge arrays initialized like this in generated code. This must be why JFlex was running into the 64K limit. My lexer generator serializes its state tables instead of outputting them as code.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Size limit
    By MiserAbleMan in forum Java Applets
    Replies: 4
    Last Post: 05-21-2012, 07:00 PM
  2. Formatter format method output limit?
    By rykeelty in forum New To Java
    Replies: 6
    Last Post: 04-19-2012, 07:18 PM
  3. Audio size limit?
    By AndroidAppNewbie in forum New To Java
    Replies: 2
    Last Post: 03-12-2011, 07:13 PM
  4. Replies: 4
    Last Post: 02-22-2009, 07:31 AM
  5. method size is deprecated
    By oregon in forum New To Java
    Replies: 4
    Last Post: 08-05-2007, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •