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

8340710: Optimize DirectClassBuilder::build #21118

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import jdk.internal.access.SharedSecrets;
import jdk.internal.vm.annotation.ForceInline;

import static java.lang.classfile.ClassFile.MAGIC_NUMBER;

public final class BufWriterImpl implements BufWriter {
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();

Expand Down Expand Up @@ -94,6 +96,10 @@ public ClassFileImpl context() {
return context;
}

void writeMagic(int minorVersion, int majorVersion) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we call this writeHeader as this writes both the magic and the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, through the local variable constantPool, codeSize < 325 can be achieved without extracting a separate method.

writeLong((((long) MAGIC_NUMBER) << 32) | ((minorVersion & 0xFFFFL) << 16) | majorVersion);
}

@Override
public void writeU1(int x) {
reserveSpace(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ else if ((flags & ClassFile.ACC_MODULE) == 0 && !"java/lang/Object".equals(thisC
}

// Now we can make the head
head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | minorVersion << 16 | majorVersion);
head.writeMagic(minorVersion, majorVersion);
constantPool.writeTo(head);
head.writeU2(flags);
head.writeIndex(thisClassEntry);
Expand Down