Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of .java file affects compiling.

 
khushal malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a .java file whose size is more than 1 GB. Please dont curse me for this as this file is automatically generated by the existing system based on some inputs.

As of now this 1 GB java file is giving errors while compiling. It is not able to compile.

I want to ask does java has such restrictions. Is there a way to compile such file. Other way around is change the code which generates 1GB file.

If you guys have anything related to this please let me know.

regards
khushal
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Offhand I don't remember what if any intrinsic limits there may be in the process. But I'm not surprised that a 1 GB file causes problems. Perhaps you could tell us what is the text of the first few compile errors you get? That may well give important clues as to what, exactly, the problem is.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have problems with the JVM that runs javac running out of heap. You can fix these by passing arguments to that JVM using the -J option of javac.

For example, -J-Xms48m sets the initial heap to 48 megabytes.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler will not accept any sourcefile that has more than 64K lines in any single method.
I'm pretty certain there are similar restrictions to the number of methods per class, data members per class, and classes per file.

Any class that big is a monster that needs serious refactoring anyway
Or if it's generated, kill the generator.
 
khushal malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. I will get more details on it. Killing the generator is a nice idea
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen T Wenting:
The compiler will not accept any sourcefile that has more than 64K lines in any single method.


Another limit is 64k bytes of emitted code in a method; sometimes less, as a jump instruction takes a 16-bit signed offset as an argument.

A 1GB emitted file is extremely impressive (or inauspicious, depending on how you look at it.)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's definitely something extreme, anyway.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen T Wenting:
Any class that big is a monster that needs serious refactoring anyway
Or if it's generated, kill the generator.
Or combine the two ideas and refactor the generator.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am curious where is the bulk in this generated Java source? If it is in String constants perhaps they can be stored elsewhere.

In any case, please let us know the solution you come up with.

Bill
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with you Bill, I'd love to know how you end up with a 1 GB source file. I can't think of a project that I've worked on that had anywhere near 1 GB of source total.

Just for reference I downloaded "Moby Dick" by Herman Melville from Project Gutenberg, unzipped it is 1.15 MB.
 
Murali Mohan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I faced a similar problem in my project. We use one propertory IDE for development which generates the java code. I found two generated files of size 5 MB. And these files failed to compile because of the large size of methods. Then I manually edited the file and replaced the large methods with a set of small methods and written some logic to integrate these small methods. So that from out side it appeared the same but internally it calls these small methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic