forked from JavaTX/JavaCompilerCore
Write tx signature to constant pool
This commit is contained in:
parent
cf2d612870
commit
b9f19cc105
@ -999,8 +999,8 @@ public class Codegen {
|
|||||||
|
|
||||||
private void generateConstructor(TargetConstructor constructor) {
|
private void generateConstructor(TargetConstructor constructor) {
|
||||||
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||||
if (!constructor.txGenerics().isEmpty())
|
if (constructor.txGenerics() != null)
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(constructor.getTXSignature())));
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(null, mv, 1);
|
var state = new State(null, mv, 1);
|
||||||
@ -1026,8 +1026,9 @@ public class Codegen {
|
|||||||
private void generateMethod(TargetMethod method) {
|
private void generateMethod(TargetMethod method) {
|
||||||
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
||||||
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
||||||
if (method.txSignature() != null)
|
if (method.txSignature() != null) {
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(method.getTXSignature())));
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println(method.getDescriptor());
|
System.out.println(method.getDescriptor());
|
||||||
System.out.println(method.getSignature());
|
System.out.println(method.getSignature());
|
||||||
@ -1058,8 +1059,8 @@ public class Codegen {
|
|||||||
generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
|
generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
|
||||||
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
||||||
);
|
);
|
||||||
if (!clazz.txGenerics().isEmpty())
|
if (clazz.txGenerics() != null)
|
||||||
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));
|
cw.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(generateSignature(clazz, clazz.txGenerics()))));
|
||||||
|
|
||||||
clazz.fields().forEach(this::generateField);
|
clazz.fields().forEach(this::generateField);
|
||||||
clazz.constructors().forEach(this::generateConstructor);
|
clazz.constructors().forEach(this::generateConstructor);
|
||||||
|
@ -2,13 +2,10 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class JavaTXSignatureAttribute extends Attribute {
|
public class JavaTXSignatureAttribute extends Attribute {
|
||||||
final String signature;
|
final int signature;
|
||||||
|
|
||||||
protected JavaTXSignatureAttribute(String signature) {
|
protected JavaTXSignatureAttribute(int signature) {
|
||||||
super("JavaTXSignature");
|
super("JavaTXSignature");
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
@ -17,13 +14,13 @@ public class JavaTXSignatureAttribute extends Attribute {
|
|||||||
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
||||||
var data = new byte[length];
|
var data = new byte[length];
|
||||||
System.arraycopy(classReader.b, offset, data, 0, length);
|
System.arraycopy(classReader.b, offset, data, 0, length);
|
||||||
return new JavaTXSignatureAttribute(new String(data, StandardCharsets.UTF_8));
|
return new JavaTXSignatureAttribute(data[0] << 8 | data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
||||||
var data = new ByteVector();
|
var data = new ByteVector();
|
||||||
data.putUTF8(this.signature);
|
data.putShort(this.signature);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user