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

Commit

Permalink
Fixes JDK-8240567
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph <siedlerkiller@gmail.com>
  • Loading branch information
koppor and Siedlerchr committed Oct 13, 2022
1 parent f5f8df1 commit 44c00a6
Showing 1 changed file with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,47 @@ private void genIncubatorModules(ClassWriter cw) {
* Generate bytecode for moduleDescriptors method
*/
private void genModuleDescriptorsMethod(ClassWriter cw) {
int helperMethodCount = 0;
final String helperMethodNamePrefix = "moduleDescriptorsSub";

for (int index = 0; index < moduleInfos.size(); index++) {
if (index % 99 == 0) {
// start new child method each 99 module infos
// The number 99 is chosen "randomly" to be below the 64kb limit of a method

// finish last helper method
if (helperMethodCount > 0) {
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}

// create method with name suffix helperMethodCount
mv = cw.visitMethod(ACC_PUBLIC,
helperMethodNamePrefix + helperMethodCount,
"(" + MODULE_DESCRIPTOR_ARRAY_SIGNATURE + ")V",
"(" + MODULE_DESCRIPTOR_ARRAY_SIGNATURE + ")V",
null);

helperMethodCount++;
}

ModuleInfo minfo = moduleInfos.get(index);
// Here, the assignment to the array at position "index" is created
new ModuleDescriptorBuilder(
minfo.descriptor(),
minfo.packages(),
index).build();
}

// finish last helper method
// same code as above
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();

// now the content of the method calling the helper methods is generated

this.mv = cw.visitMethod(ACC_PUBLIC,
"moduleDescriptors",
"()" + MODULE_DESCRIPTOR_ARRAY_SIGNATURE,
Expand All @@ -706,12 +747,16 @@ private void genModuleDescriptorsMethod(ClassWriter cw) {
mv.visitTypeInsn(ANEWARRAY, "java/lang/module/ModuleDescriptor");
mv.visitVarInsn(ASTORE, MD_VAR);

for (int index = 0; index < moduleInfos.size(); index++) {
ModuleInfo minfo = moduleInfos.get(index);
new ModuleDescriptorBuilder(minfo.descriptor(),
minfo.packages(),
index).build();
for (int index = 0; index < helperMethodCount; index++) {
// create call to helperMethod{i}
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, MD_VAR);
mv.visitMethodInsn(INVOKEVIRTUAL, this.className,
helperMethodNamePrefix + index,
"(" + MODULE_DESCRIPTOR_ARRAY_SIGNATURE + ")V",
false);
}

mv.visitVarInsn(ALOAD, MD_VAR);
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
Expand Down

0 comments on commit 44c00a6

Please sign in to comment.