]> source.dussan.org Git - aspectj.git/commitdiff
Improve condy (constant dynamic) support
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 13 Aug 2022 20:46:45 +0000 (22:46 +0200)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 13 Aug 2022 21:07:49 +0000 (23:07 +0200)
Relates to #170. Fixes the "Unknown constant type 17" problem.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/ConstantPool.java
bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java
bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java

index 3c1c12daf4ae6df509dc870d54c5987c59054e41..6c2240b9de938ef7af9b4c3bd7819f8cab3348bb 100644 (file)
@@ -185,7 +185,7 @@ public interface Constants {
 
        String[] CONSTANT_NAMES = { "", "CONSTANT_Utf8", "", "CONSTANT_Integer", "CONSTANT_Float", "CONSTANT_Long",
                        "CONSTANT_Double", "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref", "CONSTANT_Methodref",
-                       "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType","","","CONSTANT_MethodHandle","CONSTANT_MethodType","","CONSTANT_InvokeDynamic",
+                       "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType","","","CONSTANT_MethodHandle","CONSTANT_MethodType","CONSTANT_Dynamic","CONSTANT_InvokeDynamic",
                        // J9:
                        "CONSTANT_Module", "CONSTANT_Package"};
 
index 2066b4569467962cb8d3525306467af68d63f610..f8894def4c749fe17ac11078a81f8e1fa386c3c9 100644 (file)
@@ -212,6 +212,10 @@ public class ConstantPool implements Node {
                        ConstantInvokeDynamic cID = ((ConstantInvokeDynamic)c);
                        return "#"+cID.getBootstrapMethodAttrIndex()+"."+constantToString(cID.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType);
 
+               case Constants.CONSTANT_Dynamic:
+                       ConstantDynamic cD = ((ConstantDynamic)c);
+                       return "#"+cD.getBootstrapMethodAttrIndex()+"."+constantToString(cD.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType);
+
                case Constants.CONSTANT_MethodHandle:
                        ConstantMethodHandle cMH = ((ConstantMethodHandle)c);
                        return cMH.getReferenceKind()+":"+constantToString(cMH.getReferenceIndex(),Constants.CONSTANT_Methodref);
@@ -326,7 +330,7 @@ public class ConstantPool implements Node {
                StringBuilder buf = new StringBuilder();
 
                for (int i = 1; i < poolSize; i++)
-                       buf.append(i + ")" + pool[i] + "\n");
+                       buf.append(i).append(") ").append(pool[i]).append("\n");
 
                return buf.toString();
        }
@@ -632,6 +636,16 @@ public class ConstantPool implements Node {
                        return addInvokeDynamic(index1,index2);
                }
 
+               case Constants.CONSTANT_Dynamic: {
+                       ConstantDynamic cd = (ConstantDynamic)c;
+                       int index1 = cd.getBootstrapMethodAttrIndex();
+                       ConstantNameAndType cnat = (ConstantNameAndType)constants[cd.getNameAndTypeIndex()];
+                       ConstantUtf8 name = (ConstantUtf8) constants[cnat.getNameIndex()];
+                       ConstantUtf8 signature = (ConstantUtf8) constants[cnat.getSignatureIndex()];
+                       int index2 = addNameAndType(name.getValue(), signature.getValue());
+                       return addConstantDynamic(index1,index2);
+               }
+
                case Constants.CONSTANT_MethodHandle:
                        ConstantMethodHandle cmh = (ConstantMethodHandle)c;
                        return addMethodHandle(cmh.getReferenceKind(),addConstant(constants[cmh.getReferenceIndex()],cp));
@@ -725,6 +739,12 @@ public class ConstantPool implements Node {
                pool[poolSize++] = new ConstantInvokeDynamic(bootstrapMethodIndex, constantNameAndTypeIndex);
                return ret;
        }
+       public int addConstantDynamic(int bootstrapMethodIndex, int constantNameAndTypeIndex) {
+               adjustSize();
+               int ret = poolSize;
+               pool[poolSize++] = new ConstantDynamic(bootstrapMethodIndex, constantNameAndTypeIndex);
+               return ret;
+       }
 
        public int addInterfaceMethodref(String class_name, String method_name, String signature) {
                int ret = lookupInterfaceMethodref(class_name, method_name, signature);
index 3335f1ea83b03b10858a1ae38d1e8151984eca6e..531af4d05a729ef88a6b5919087712a3243f3ca2 100644 (file)
@@ -381,13 +381,17 @@ public class DescendingVisitor implements ClassVisitor {
        }
 
        @Override
-       public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) {
-               throw new IllegalStateException("nyi");
+       public void visitConstantInvokeDynamic(ConstantInvokeDynamic constant) {
+               stack.push(constant);
+               constant.accept(visitor);
+               stack.pop();
        }
 
        @Override
        public void visitConstantDynamic(ConstantDynamic obj) {
-               throw new IllegalStateException("nyi");
+               stack.push(obj);
+               obj.accept(visitor);
+               stack.pop();
        }
 
        @Override
index 1ca9016508ef6435a4aa523c060048a1f18288d3..0873dee5c1263763434522a69996e1983873cb10 100644 (file)
@@ -117,7 +117,7 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisTypeAnnos;
  *
  * @see DescendingVisitor
  * @version $Id: EmptyClassVisitor.java,v 1.3 2009/09/15 19:40:22 aclement Exp $
- * 
+ *
  */
 public class EmptyClassVisitor implements ClassVisitor {
   protected EmptyClassVisitor() { }
@@ -149,6 +149,8 @@ public void visitConstantMethodType(ConstantMethodType obj) {}
   @Override
 public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) {}
   @Override
+public void visitConstantDynamic(ConstantDynamic obj) {}
+  @Override
 public void visitConstantNameAndType(ConstantNameAndType obj) {}
   @Override
 public void visitConstantPool(ConstantPool obj) {}
@@ -214,7 +216,7 @@ public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisParamAnnos att
 public void visitAnnotationDefault(AnnotationDefault attribute) {}
   @Override
 public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {}
-        
+
   // J8:
   @Override
 public void visitRuntimeVisibleTypeAnnotations(RuntimeVisTypeAnnos attribute) {}
@@ -235,5 +237,5 @@ public void visitModuleMainClass(ModuleMainClass attribute) {}
   @Override public void visitConstantDynamic(ConstantDynamic attribute) {}
   @Override public void visitNestHost(NestHost attribute) { }
   @Override public void visitNestMembers(NestMembers attribute) { }
+
 }