aspose file tools*
The moose likes Java in General and the fly likes Size of .java file affects compiling. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Size of .java file affects compiling." Watch "Size of .java file affects compiling." New topic
Author

Size of .java file affects compiling.

khushal malik
Greenhorn

Joined: Jul 08, 2005
Posts: 19
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
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.


42
khushal malik
Greenhorn

Joined: Jul 08, 2005
Posts: 19
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It's definitely something extreme, anyway.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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

Joined: Mar 22, 2000
Posts: 12805
    
    5
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

Joined: Aug 31, 2006
Posts: 226
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

Joined: Jan 09, 2006
Posts: 66
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.


Thanks,<br />Murali...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Size of .java file affects compiling.