size limitation to a .java file?

F

Flip

Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?
If it is, what is it? Have people commonly run into this type of thing?

Thanks
 
J

Jim Cochrane

Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?
If it is, what is it? Have people commonly run into this type of thing?

I haven't memorized the spec., so I could be wrong, but I strongly doubt
there is any such limit - to source file-size, method-size, or
whatever-size.

The only limit would be the inherent rules of good design, which
essentially dictate that methods, files., etc. never get large enough to
risk breaking a (either implementation-dependent or specified) limit.

Are you asking this out of curiosity, or are you actually (foolishly)
considering coding a system with one or more gigantic files or methods?
 
F

Flip

Are you asking this out of curiosity, or are you actually (foolishly)
considering coding a system with one or more gigantic files or methods?
Curiosity. :> No, I haven't run into this situation (yet, and I hope I
won't in the future :>). I've been thinking in the back of my mind for the
past few months, that's all. I've used systems in the past that had these
types of limits and I thought we ran into something like that here at my
work. I seem to remeber there being a problem with the size of the compiled
class having a limit of 64K or something like that?

But to answer your question, it's more of an academic question. Thanks for
the info. :>
 
R

Roedy Green

Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?
If it is, what is it? Have people commonly run into this type of thing?

not in human written code. In machine generated code you might run
into problems with 16 bit offsets in the JVM byte code. That limits a
method to 64K of JMV byte codes, one rather fat method.
 
F

Flip

not in human written code. In machine generated code you might run
into problems with 16 bit offsets in the JVM byte code. That limits a
method to 64K of JMV byte codes, one rather fat method.
Do you mean in one .class file it's limited to 64K or rather the size of one
method inside of the class file is limited to that size?

PS Thanks for the info! :>
 
T

Thomas Schodt

Flip said:
Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?
If it is, what is it? Have people commonly run into this type of thing?

IIRC A method can only be 64k bytes of bytecode.

You can have any number of methods in a class, so you can just refactor.
 
C

Carl Howells

Flip said:
Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?
If it is, what is it? Have people commonly run into this type of thing?

Thanks

The bytecode generated for any method needs to be under 64k in .class
file format.

That's really only an issue if you're using a tool to generate code.
This can happen using parser tools like jFlex and CUP, or when a very
large JSP file is being converted into java source as a servlet.
 
T

Tor Iver Wilhelmsen

Flip said:
Is there a maximum size limitation to the size of a java file? I seem to
remember hearing/reading there is a method size limitation. Is that true?

Yes, methods must be less that about 64k of bytecode. Keep in mind
that String constants, field names etc. aren't part of that - they go
elsewhere.
If it is, what is it? Have people commonly run into this type of thing?

You can risk running in to it in several ways; I know of the following
at least:

1) Having a too big JSP. All code in the JSP (except declarations in
<%! %>) ends up in one method called _jsp_init().

2) Initializing huge arrays. Since Java classes do not have COFF's
data segments (yet :) ), arrays are initialized element by element.
 
S

Steve Horsley

Flip said:
Do you mean in one .class file it's limited to 64K or rather the size of one
method inside of the class file is limited to that size?

PS Thanks for the info! :>
I think he meant 64K for one method. But there are other limits. I can't
remember the details (they are all too big to be of practical
significance), but there may be limits like 64K methods per class,
64K variables per class etc.

Steve
 
R

Roedy Green

Do you mean in one .class file it's limited to 64K or rather the size of one
method inside of the class file is limited to that size?

I meant one method, but it could be a class file limit too. Look at
where 16 bit numbers are used in the class file format, and you will
be able to figure it out.

see http://mindprod.com/jgloss/jasm.html
 
F

Flip

large JSP file is being converted into java source as a servlet.
I believe this is where I heard about this the first time now that you
mention it!
 
S

Scott Ellsworth

Roedy Green said:
not in human written code. In machine generated code you might run
into problems with 16 bit offsets in the JVM byte code. That limits a
method to 64K of JMV byte codes, one rather fat method.

Amazingly enough, human written code can get close to this. PCGen had
some truly monster classes that were pushing the limit until they were
refactored a bit. The project still has some classes that go over the
line when instrumented with Clover.

Scatt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top