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

Autosplitter for big generated java methods #10367

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/google/protobuf/compiler/java/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <google/protobuf/compiler/java/helpers.h>

#include "message.h"

#include <algorithm>
#include <cstdint>
#include <limits>
Expand Down Expand Up @@ -1120,6 +1122,22 @@ void EscapeUtf16ToString(uint16_t code, std::string* output) {
}
}

void MaybeSplitJavaMethod(io::Printer *printer, int* fields_in_function, int* method_num,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we MaybeSplitJavaMethod? Can't we know ahead of time (by the number of fields) how we need to split the top-level method?

const char *chain_statement, const char *method_decl,
std::map<std::string, std::string>& variables) {

if ((*fields_in_function) > kMaxFieldsInMethod) {
variables["method_num"] = StrCat(*method_num);
printer->Print(variables, chain_statement);
printer->Outdent();
printer->Print("}\n");
printer->Print(variables, method_decl);
printer->Indent();
*fields_in_function = 0;
++(*method_num);
}
}

} // namespace java
} // namespace compiler
} // namespace protobuf
Expand Down
7 changes: 7 additions & 0 deletions src/google/protobuf/compiler/java/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@ void EscapeUtf16ToString(uint16_t code, std::string* output);
// bits 4-7: unused
int GetExperimentalJavaFieldType(const FieldDescriptor* field);

// Split method if fields count > kMaxFields
// JIT compile only 8k bytes of bytecode with default settings
// variables - changes inside method
void MaybeSplitJavaMethod(io::Printer *printer, int* fields_in_function, int* method_num,
const char *chain_statement, const char *method_decl,
std::map<std::string, std::string>& variables);

// To get the total number of entries need to be built for experimental runtime
// and the first field number that are not in the table part
std::pair<int, int> GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber(
Expand Down
Loading