• Post Reply Bookmark Topic Watch Topic
  • New Topic

java code too large  RSS feed

 
Andrew Cly
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am generating java code using javacc as a tool. The generated java source code can not compile using Sun javac because one of the method becomes too large.

I get a "code too large" error from Sun javac.

Is there a way to circumvent this problem except that I have to break the method generated by javacc?

Thanks,
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.

A single Java method can contain no more than 64KB of code.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would also have to wonder about the quality of the code if a single method contains that much code.
 
Aaron Hanson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that because "64K should be enough for anybody"?
Just an observation.

[ April 22, 2005: Message edited by: Aaron Hanson ]
[ April 22, 2005: Message edited by: Aaron Hanson ]
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the structure of one single method that somehow has managed to grow to 64 kilobytes in size. what is it doing, that can't be abstracted into some kind of loop? are there truly no stanzas or idioms in it of it that are being reused over and over, that might be broken out into methods in their own right? what sort of single task, suitable for inclusion all into one single method with no further syntactic or semantical abstraction, could take so much code to perform?

if you're writing such a method, are you really sure that no parts of it could be better off broken out to stand on their own? and if the answer to that is yes, how are you going to maintain this behemoth method in the future?

really, it's not so much that "64K should be enough for anybody"; it's more that "programs must be written for people to read, and only incidentally for machines to execute". i've no idea how i would go about reading, getting my head around, and arriving at some understanding of, a single method that would likely take up something like 25 printed pages just to get a hardcopy of. i'm not sure i would want to work with a programmer who could; such a person might start making assumptions that everyone else can, too.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the structure of one single method that somehow has managed to grow to 64 kilobytes in size.
what is it doing, that can't be abstracted into some kind of loop?


I ran into the same problem when my class had no methods at all. It had pretty a large static array of Strings though...

really, it's not so much that "64K should be enough for anybody"; it's more that "programs must be written for
people to read, and only incidentally for machines to execute".


Sometimes, Java code is being generated by another program. Are you sure people wanna read it?

i've no idea how i would go about reading, getting my head around, and arriving at some understanding of, a single
method that would likely take up something like 25 printed pages just to get a hardcopy of.


Think about upgrading your brain

i'm not sure i would want to work with a programmer who could;

Sigh... It's a typical cultural clash

such a person might start making assumptions that everyone else can, too.

You too have made quite a few assumptions here, have you not?
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dmitry Melnik:
I ran into the same problem when my class had no methods at all. It had pretty a large static array of Strings though...


ok, now that's a more reasonable complaint. static data should probably not be treated the same as code by the compiler. i wonder if this too is imposed by the JLS? if so, we might have a genuinely valid grievance against the standard, in my opinion.

Sometimes, Java code is being generated by another program. Are you sure people wanna read it?


how else are you going to debug the code-generating code, except by checking its output for correctness? i'll grant that a test case might not be so large as a production case, but even so i'd consider making my code-generating code smart enough to break out commonly repeated stanzas as separate methods. it would be more work, but the generated code would likely be that much better for it.

Think about upgrading your brain


oh, i do, every day! if only i could afford a newer version...

You too have made quite a few assumptions here, have you not?


true enough, but looking back at them, i genuinely think they're not unreasonable ones. not even comparatively unreasonable, i would say. you're free to disagree with me, but if you do, would you care to explain why?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that because "64K should be enough for anybody"?

No, it is because Java byte codes for branching use 2 byte offsets. Thus the 64K limit is set in concrete by the VM design, not an arbitrary decision.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!