< prev index next > src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
Print this page
import java.lang.constant.MethodTypeDesc;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
+ import static java.lang.constant.ConstantDescs.INIT_NAME;
import static java.util.Objects.requireNonNull;
import static jdk.internal.classfile.impl.BytecodeHelpers.*;
import static jdk.internal.classfile.impl.RawBytecodeHelper.*;
public final class DirectCodeBuilder
codeLength,
dcb.methodInfo.methodName().stringValue(),
dcb.methodInfo.methodTypeSymbol().displayDescriptor()));
}
- boolean codeMatch = dcb.original != null && codeAndExceptionsMatch(codeLength);
+ boolean codeMatch = dcb.codeAndExceptionsMatch(codeLength, buf);
var context = dcb.context;
if (context.stackMapsWhenRequired()) {
if (codeMatch) {
dcb.attributes.withAttribute(dcb.original.findAttribute(Attributes.stackMapTable()).orElse(null));
writeCounters(true, buf);
public Utf8Entry attributeName() {
return buf.constantPool().utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE);
}
}
- private boolean codeAndExceptionsMatch(int codeLength) {
+ private boolean codeAndExceptionsMatch(int codeLength, BufWriterImpl buf) {
boolean codeAttributesMatch;
if (original instanceof CodeImpl cai && canWriteDirect(cai.constantPool())) {
codeAttributesMatch = cai.codeLength == curPc()
&& cai.compareCodeBytes(bytecodesBufWriter, 0, codeLength);
if (codeAttributesMatch) {
var bw = new BufWriterImpl(constantPool, context);
writeExceptionHandlers(bw);
codeAttributesMatch = cai.classReader.compare(bw, 0, cai.exceptionHandlerPos, bw.size());
}
+
+ if (codeAttributesMatch) {
+ var thisIsConstructor = methodInfo.methodName().equalsString(INIT_NAME);
+ var originalIsConstructor = cai.enclosingMethod.methodName().equalsString(INIT_NAME);
+ if (thisIsConstructor || originalIsConstructor) {
+ if (thisIsConstructor != originalIsConstructor) {
+ codeAttributesMatch = false;
+ }
+ }
+
+ if (codeAttributesMatch && thisIsConstructor) {
+ if (!buf.strictFieldsMatch(cai.classReader.getContainedClass())) {
+ codeAttributesMatch = false;
+ }
+ }
+ }
}
else
codeAttributesMatch = false;
return codeAttributesMatch;
}
< prev index next >