Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
Remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Jun 12, 2023
1 parent 7c48693 commit 79c338c
Showing 1 changed file with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ private void genIncubatorModules(ClassBuilder clb) {
*/
private void genModuleDescriptorsMethod(ClassBuilder clb) {
if (moduleInfos.size() <= 75) {
// In case there won't be a Method_Too_Large exception, we use the unsplit method to generate the method "moduleDescriptors"
clb.withMethodBody(
"moduleDescriptors",
MethodTypeDesc.of(CD_MODULE_DESCRIPTOR.arrayType()),
Expand All @@ -690,40 +689,30 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {
return;
}

// split up module infos in "consumable" packages
List<List<ModuleInfo>> splitModuleInfos = new ArrayList<>();
List<ModuleInfo> currentModuleInfos = null;
for (int index = 0; index < moduleInfos.size(); index++) {
// The method is "manually split" based on the heuristics that 90 ModuleDescriptors are smaller than 64kb
// The number 50 is chosen "randomly" to be below the 64kb limit of a method
if (index % 50 == 0) {
// Prepare new list
currentModuleInfos = new ArrayList<>();
splitModuleInfos.add(currentModuleInfos);
}
currentModuleInfos.add(moduleInfos.get(index));
}

final String helperMethodNamePrefix = "moduleDescriptorsSub";
// Variable holding List<Set>, which needs to be restored at each helper method
// This list grows at each call of each helper method
final ClassDesc arrayListClassDesc = ClassDesc.ofInternalName("java/util/ArrayList");

// dedupSetBuilder will (!) use this index for the first variable
final int firstVariableForDedup = nextLocalVar;

// generate call to first helper method
clb.withMethodBody(
"moduleDescriptors",
MethodTypeDesc.of(CD_MODULE_DESCRIPTOR.arrayType()),
ACC_PUBLIC,
cob -> {
cob.constantInstruction(moduleInfos.size())
.anewarray(CD_MODULE_DESCRIPTOR)
.dup() // storing for the return at the end
.dup()
.astore(MD_VAR);
// Generate List of Sets required by dedupSetBuilder
// We use slot "nextLocalVar" temporarily. We do net need the list later as the helper methods modify the list and pass it on.
cob.new_(arrayListClassDesc)
.dup()
.invokespecial(arrayListClassDesc, "<init>", MethodTypeDesc.of(CD_void))
Expand All @@ -739,7 +728,6 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {
.areturn();
});

// generate all helper methods
final int[] globalCount = {0};
for (final int[] index = {0}; index[0] < splitModuleInfos.size(); index[0]++) {
clb.withMethodBody(
Expand All @@ -749,9 +737,7 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {
cob -> {
List<ModuleInfo> moduleInfosPackage = splitModuleInfos.get(index[0]);

// Restore all (!) sets from parameter to local variables
if (nextLocalVar > firstVariableForDedup) {
// We need to go from the end to the beginning as we will probably overwrite position 2 (which holds the list at the beginning)
for (int i = nextLocalVar-1; i >= firstVariableForDedup; i--) {
cob.aload(2)
.constantInstruction(i-firstVariableForDedup)
Expand All @@ -762,7 +748,6 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {

for (int j = 0; j < moduleInfosPackage.size(); j++) {
ModuleInfo minfo = moduleInfosPackage.get(j);
// executed after the call, thus it is OK to overwrite index 0 (BUILDER_VAR)
new ModuleDescriptorBuilder(cob,
minfo.descriptor(),
minfo.packages(),
Expand All @@ -771,10 +756,6 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {
}

if (index[0] + 1 < (splitModuleInfos.size())) {
// We are not the last one of the calling chain of helper methods
// Prepare next call

// Store all new sets to List
if (nextLocalVar > firstVariableForDedup) {
cob.new_(arrayListClassDesc)
.dup()
Expand All @@ -784,12 +765,11 @@ private void genModuleDescriptorsMethod(ClassBuilder clb) {
cob.aload(nextLocalVar)
.aload(i)
.invokevirtual(arrayListClassDesc, "add", MethodTypeDesc.of(CD_boolean, CD_Object))
.pop(); // remove boolean result value
.pop();
}
}
// call to next helper method
cob.aload(0)
.aload(MD_VAR) // load first parameter, which is MD_VAR
.aload(MD_VAR)
.aload(nextLocalVar)
.invokevirtual(
this.classDesc,
Expand Down

0 comments on commit 79c338c

Please sign in to comment.