Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java compilation issues when processing large .proto files #101

Merged
merged 3 commits into from May 7, 2015
Merged

Fix java compilation issues when processing large .proto files #101

merged 3 commits into from May 7, 2015

Conversation

fizbin
Copy link
Contributor

@fizbin fizbin commented Nov 25, 2014

Fix issues 579 and 501 on the code.google.com issues list.

Specifically, large .proto files lead to too much static code, leading to a
compilation error from javac: "code too large". This divides the code used
in static initialization into multiple methods to avoid that error. Also,
this incorporates the fix in issue 501 on the code.google.com issues list
to call registry.add only once per extension.

Fix issues 579 and 501 on the code.google.com issues list.

Specifically, large .proto files lead to too much static code, leading to a
compilation error from javac: "code too large". This divides the code used
in static initialization into multiple methods to avoid that error. Also,
this incorporates the fix in issue 501 on the code.google.com issues list
to call registry.add only once per extension.
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Nov 27, 2014

Is this patch originally from daniel.martin@crowdstrike.com? If yes, we'll need him to sign Google CLA as well before we can accept this patch.

@fizbin
Copy link
Contributor Author

fizbin commented Nov 27, 2014

Oh crud, I hadn't meant to update git with my work address. Yes, that's me too - I'll go sign the same CLA with my work account too.

@googlebot
Copy link

CLAs look good, thanks!

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Dec 12, 2014

@pherl , this patch makes protoc break down large Java methods so the generated code of some very large .proto files can now compile (whereas they previously fail with "code too large" errors"). Does this sound good to you? I'll look at the details of this patch if the general approach looks good to you.

@fizbin
Copy link
Contributor Author

fizbin commented Dec 16, 2014

@pherl - any thoughts?

@fizbin
Copy link
Contributor Author

fizbin commented Jan 12, 2015

@pherl - ping. Does this general approach seem sound?

The only bit I don't like much about this is that splitting up the gigantic static block necessitated turning some private final variables into non-final ones. However, as they're still private I don't believe that has any safety consequences. I believe that with modern JITs, it also has no measurable performance consequences.

@fizbin
Copy link
Contributor Author

fizbin commented Mar 16, 2015

@pherl - ping. Does this general approach seem sound? Do I need to revise it for changes that have happened since I initially made the pull request?

I wish to stress that this change addresses a real issue we actually have in the field - currently, we're reduced to taking the generated java code and post-processing it with a python script to get something that can compile.

@liujisi
Copy link
Contributor

liujisi commented Mar 16, 2015

Sorry for the delay. The general approach looks good to me. Do you have any idea what the threshold is for javac?

@@ -62,6 +63,19 @@ namespace java {

namespace {

struct FieldDescriptorCompare {
bool operator ()(const FieldDescriptor* f1, const FieldDescriptor* f2) {
if(f1== NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed a space

@fizbin
Copy link
Contributor Author

fizbin commented Mar 23, 2015

@pherl - The JVM spec. limits bytecode per method to 64K. (Note that all the static initialization inside a class happens inside a single method) This is why my patch does a new method at 32K - then, even if the bytecode estimates are off by a factor of two, the result will still compile.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@fizbin
Copy link
Contributor Author

fizbin commented Mar 23, 2015

Yes, both fizbin@gmail.com and daniel.martin@crowdstrike.com are me. I've signed CLAs under both google accounts, and pointed the CLAs at this same github account. Apologies for not keeping my usernames straight.

@tamird
Copy link
Contributor

tamird commented Apr 2, 2015

this good to merge? ping @xfxyjwf

@@ -67,8 +67,8 @@ class ExtensionGenerator {
virtual ~ExtensionGenerator() {}

virtual void Generate(io::Printer* printer) = 0;
virtual void GenerateNonNestedInitializationCode(io::Printer* printer) = 0;
virtual void GenerateRegistrationCode(io::Printer* printer) = 0;
virtual int GenerateNonNestedInitializationCode(io::Printer* printer) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the return value of these two methods.

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Apr 8, 2015
@tamird
Copy link
Contributor

tamird commented May 7, 2015

@fizbin maybe squash this? @xfxyjwf would be good to merge this

@xfxyjwf
Copy link
Contributor

xfxyjwf commented May 7, 2015

Thanks. Merging.

xfxyjwf added a commit that referenced this pull request May 7, 2015
Fix java compilation issues when processing large .proto files
@xfxyjwf xfxyjwf merged commit 03e1704 into protocolbuffers:master May 7, 2015
TeBoring added a commit to TeBoring/protobuf that referenced this pull request Jan 19, 2019
bithium pushed a commit to bithium/protobuf that referenced this pull request Sep 4, 2023
…va_code

Fix java compilation issues when processing large .proto files
bithium pushed a commit to bithium/protobuf that referenced this pull request Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants